157 lines
4.1 KiB
Java
157 lines
4.1 KiB
Java
package com.tenwa.customer.controller.company;
|
|
|
|
import jbo.app.tenwa.customer.CUSTOMER_ATTRIBUTION;
|
|
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
import com.amarsoft.are.jbo.BizObjectManager;
|
|
import com.amarsoft.are.jbo.BizObjectQuery;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.tenwa.comm.util.date.DateAssistant;
|
|
|
|
public class CustomerAttributionController {
|
|
|
|
private String userId;
|
|
private String customerId;
|
|
private String status;
|
|
private String id;
|
|
private String isMain;
|
|
private String inputId;
|
|
private String orgId;
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(String id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getStatus() {
|
|
return status;
|
|
}
|
|
|
|
public void setStatus(String status) {
|
|
this.status = status;
|
|
}
|
|
public String getUserId() {
|
|
return userId;
|
|
}
|
|
|
|
public void setUserId(String userId) {
|
|
this.userId = userId;
|
|
}
|
|
|
|
public String getCustomerId() {
|
|
return customerId;
|
|
}
|
|
|
|
public void setCustomerId(String customerId) {
|
|
this.customerId = customerId;
|
|
}
|
|
|
|
public String getIsMain() {
|
|
return isMain;
|
|
}
|
|
|
|
public void setIsMain(String isMain) {
|
|
this.isMain = isMain;
|
|
}
|
|
|
|
public String getInputId() {
|
|
return inputId;
|
|
}
|
|
|
|
public void setInputId(String inputId) {
|
|
this.inputId = inputId;
|
|
}
|
|
|
|
public String getOrgId() {
|
|
return orgId;
|
|
}
|
|
|
|
public void setOrgId(String orgId) {
|
|
this.orgId = orgId;
|
|
}
|
|
|
|
/**
|
|
* 设置是否主归属人
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String setMainFlag(JBOTransaction tx) throws Exception{
|
|
String result = "true";
|
|
BizObjectManager attrManager = JBOFactory.getBizObjectManager(CUSTOMER_ATTRIBUTION.CLASS_NAME);
|
|
tx.join(attrManager);
|
|
BizObject attribution = attrManager.createQuery("id=:id").setParameter("id",id).getSingleResult(false);
|
|
//设置主归属人
|
|
if("yes".equals(isMain)){
|
|
if(attribution!=null){//检查是否已为主归属人
|
|
if(attribution.getAttribute("isMain").getString().equals("yes")){
|
|
return "false1";
|
|
}
|
|
}
|
|
}else{//取消主归属人
|
|
if(attribution!=null){//归属人是创建人员,不能取消
|
|
if(attribution.getAttribute("userid").getString().equals(attribution.getAttribute("inputuserid").getString())){
|
|
return "false3";
|
|
}else{//检查是否已不是主归属人
|
|
if(attribution.getAttribute("isMain").getString().equals("no")){
|
|
return "false2";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//更新主归属人
|
|
BizObjectQuery bq = attrManager.createQuery("update O set isMain=:isMain,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where id= :id ");
|
|
bq.setParameter("isMain",isMain);
|
|
bq.setParameter("id",id);
|
|
bq.setParameter("updateuserid", userId);
|
|
bq.setParameter("updatetime",DateAssistant.getTodayNow());
|
|
bq.setParameter("updateorgid",orgId);
|
|
bq.executeUpdate();
|
|
|
|
return result;
|
|
}
|
|
/**
|
|
* 更新生效失效
|
|
* @param tx
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String updateStatus(JBOTransaction tx) throws Exception{
|
|
String result = "true";
|
|
BizObjectManager attrManager = JBOFactory.getBizObjectManager(CUSTOMER_ATTRIBUTION.CLASS_NAME);
|
|
tx.join(attrManager);
|
|
BizObject attribution = attrManager.createQuery("id=:id").setParameter("id",id).getSingleResult(true);
|
|
//设置为生效
|
|
if("yes".equals(status)){
|
|
if(attribution!=null){//检查是否已生效
|
|
if(attribution.getAttribute("status").equals("yes")){
|
|
return "false1";
|
|
}
|
|
}
|
|
}else{//设置失效
|
|
if(attribution!=null){//归属人是创建人员,不能取消
|
|
if(attribution.getAttribute("userid").getString().equals(attribution.getAttribute("inputuserid").getString())){
|
|
return "false3";
|
|
}else{//已失效
|
|
if(attribution.getAttribute("status").getString().equals("no")){
|
|
return "false2";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//更新状态
|
|
BizObjectQuery bq = attrManager.createQuery("update O set status=:status,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where id= :id ");
|
|
bq.setParameter("status", status);
|
|
bq.setParameter("id",id);
|
|
bq.setParameter("updateuserid", userId);
|
|
bq.setParameter("updatetime",DateAssistant.getTodayNow());
|
|
bq.setParameter("updateorgid",orgId);
|
|
bq.executeUpdate();
|
|
|
|
return result;
|
|
}
|
|
}
|