2021-11-24 09:22:23 +08:00

320 lines
12 KiB
Java

package com.tenwa.apzl.saveunioncar;
import java.util.List;
import java.util.UUID;
import jbo.app.tenwa.customer.DISTRIBUTOR_INFO;
import jbo.app.tenwa.customer.LM_DISTRIBUTOR_TO_CAR;
import jbo.app.tenwa.customer.LM_DISTRIBUTOR_TO_PRODUCT;
import jbo.app.tenwa.customer.LM_PORTAL_TO_CAR;
import jbo.com.tenwa.entity.comm.own.DISTRICT_DISTRIBUTOR_RELATION;
import jbo.com.tenwa.entity.comm.own.LM_PRODUCT_DISTRIBUTOR_GROUP;
import jbo.com.tenwa.entity.comm.own.LM_PRODUCT_DISTRICT;
import jbo.com.tenwa.limit.LA_LIMIT_ELEMENT;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.awe.util.Transaction;
public class saveUnionCarUtil {
private String CarBrandId;
private String unionId;
public String getUnionId() {
return unionId;
}
public void setUnionId(String unionId) {
this.unionId = unionId;
}
public String getCarBrandId() {
return CarBrandId;
}
public void setCarBrandId(String carBrandId) {
CarBrandId = carBrandId;
}
/**
* 将选择对话框穿过来的id截取并存储到渠道车型关联表中
* @param tx
* @return
* @throws Exception
*/
public String saveLmPortalToCar(JBOTransaction tx)throws Exception {
String[] params = CarBrandId.split("@~");
String updateUserID = params[0];
String updateOrgId = params[1];
String updateTime = params[2];
String ordId = params[3];
int i;
int lle=0;
try{
for(i=4;i<params.length;i++){
String PortalToCarId=UUID.randomUUID().toString().replaceAll("-", "");
String brandid = params[i];
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_PORTAL_TO_CAR.CLASS_NAME,tx);
BizObject NewLmpc = Lmpc.newObject();
NewLmpc.setAttributeValue("id", PortalToCarId);
NewLmpc.setAttributeValue("carbrandseries_id", brandid);
NewLmpc.setAttributeValue("orgid", ordId);
NewLmpc.setAttributeValue("inputUserID", updateUserID);
NewLmpc.setAttributeValue("inputOrgId", updateOrgId);
NewLmpc.setAttributeValue("inputTime", updateTime);
NewLmpc.setAttributeValue("updateUserID", updateUserID);
NewLmpc.setAttributeValue("updateOrgId", updateOrgId);
NewLmpc.setAttributeValue("updateTime", updateTime);
Lmpc.saveObject(NewLmpc);
}
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}
if(lle>=0){
return "success";
}
return "error";
}
/**
* 将选择对话框穿过来的id截取并存储到经销商车型关联表中
* @param tx
* @return
* @throws Exception
*/
public String saveLmDistributorToCar(JBOTransaction tx)throws Exception {
/*
CarBrandId=admin@~
8009002@~
2018/06/12 15:03:50@~
7c7624a558594bff8387ca6949982b21@~
00303ba448074b0792bd465dd2359b7c@
*/
String[] params = CarBrandId.split("@~");
String updateUserID = params[0];
String updateOrgId = params[1];
String updateTime = params[2];
String distributorId = params[3];
int i;
int lle=0;
try{
for(i=4;i<params.length;i++){
String PortalToCarId=UUID.randomUUID().toString().replaceAll("-", "");
String brandid = params[i];
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_DISTRIBUTOR_TO_CAR.CLASS_NAME,tx);
BizObject NewLmpc = Lmpc.newObject();
NewLmpc.setAttributeValue("id", PortalToCarId);
NewLmpc.setAttributeValue("carbrandseries_id", brandid);
NewLmpc.setAttributeValue("distributor_id", distributorId);
NewLmpc.setAttributeValue("inputUserID", updateUserID);
NewLmpc.setAttributeValue("inputOrgId", updateOrgId);
NewLmpc.setAttributeValue("inputTime", updateTime);
NewLmpc.setAttributeValue("updateUserID", updateUserID);
NewLmpc.setAttributeValue("updateOrgId", updateOrgId);
NewLmpc.setAttributeValue("updateTime", updateTime);
Lmpc.saveObject(NewLmpc);
}
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}
if(lle>=0){
return "success";
}
return "error";
}
public String saveLmDistributorToProduct(JBOTransaction tx)throws Exception {
/*
CarBrandId=admin@~
8009002@~
2018/06/12 15:03:50@~
7c7624a558594bff8387ca6949982b21@~
00303ba448074b0792bd465dd2359b7c@
*/
String[] params = CarBrandId.split("@~");
String updateUserID = params[0];
String updateOrgId = params[1];
String updateTime = params[2];
String typeno = params[3];
String Message="";
int lle=0;
int i;
try{
BizObjectManager Lmcheck = JBOFactory.getBizObjectManager(LM_DISTRIBUTOR_TO_PRODUCT.CLASS_NAME,tx);
for(i=4;i<params.length;i++){
String brandid = params[i];
BizObject obcheck=Lmcheck.createQuery("DISTRIBUTOR_ID=:DISTRIBUTOR_ID and PRODUCT_ID=:PRODUCT_ID")
.setParameter("DISTRIBUTOR_ID", brandid).setParameter("PRODUCT_ID",typeno).getSingleResult(false);
if(obcheck!=null){
BizObjectManager diManager = JBOFactory.getBizObjectManager(DISTRIBUTOR_INFO.CLASS_NAME,tx);
BizObject di = diManager.createQuery("select distributor_name from O where O.id=:id").setParameter("id", brandid).getSingleResult(true);
Message = Message+di.getAttribute("distributor_name").getString()+":该经销商已绑定。<br>";
continue;
}
String PortalToCarId=UUID.randomUUID().toString().replaceAll("-", "");
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_DISTRIBUTOR_TO_PRODUCT.CLASS_NAME,tx);
BizObject NewLmpc = Lmpc.newObject();
NewLmpc.setAttributeValue("id", PortalToCarId);
NewLmpc.setAttributeValue("product_id", typeno);
NewLmpc.setAttributeValue("distributor_id", brandid);
NewLmpc.setAttributeValue("inputUserID", updateUserID);
NewLmpc.setAttributeValue("inputOrgId", updateOrgId);
NewLmpc.setAttributeValue("inputTime", updateTime);
NewLmpc.setAttributeValue("updateUserID", updateUserID);
NewLmpc.setAttributeValue("updateOrgId", updateOrgId);
NewLmpc.setAttributeValue("updateTime", updateTime);
Lmpc.saveObject(NewLmpc);
}
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}
// if(lle>0){
// return "success";
// }
return Message;
}
public String saveLmDistributorToDistrict(JBOTransaction tx)throws Exception {
/*
* 备注:之前的需求是区域和经销商关联,后来又改成区域不和经销商关联 而是和省份关联,
* 之前建的关联表不动,将省份的编号和名称分别存到关联表的经销商编号和经销商名称中
* */
String returnmess="";
String[] params = CarBrandId.split("@~");
String districtCode = params[0];
int lle=0;
int i;
try{
BizObjectManager Lmcheck = JBOFactory.getBizObjectManager(DISTRICT_DISTRIBUTOR_RELATION.CLASS_NAME,tx);
for(i=1;i<params.length;i++){
String provinceCode = params[i].split("@")[0];
String provinceName = params[i].split("@")[1];
BizObject obcheck=Lmcheck.createQuery("DISTRICT_CODE=:DISTRICT_CODE and DISTRIBUTOR_NO=:DISTRIBUTOR_NO")
.setParameter("DISTRICT_CODE", districtCode).setParameter("DISTRIBUTOR_NO",provinceCode).getSingleResult(false);
if(obcheck!=null){
returnmess +=provinceName+"已绑定该区域!";
continue;
}
String PortalToCarId=UUID.randomUUID().toString().replaceAll("-", "");
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(DISTRICT_DISTRIBUTOR_RELATION.CLASS_NAME,tx);
BizObject NewLmpc = Lmpc.newObject();
NewLmpc.setAttributeValue("ID", PortalToCarId);
NewLmpc.setAttributeValue("DISTRICT_CODE", districtCode);
NewLmpc.setAttributeValue("DISTRIBUTOR_NO", provinceCode);
NewLmpc.setAttributeValue("DISTRIBUTOR_NAME", provinceName);
Lmpc.saveObject(NewLmpc);
}
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}
if("".equals(returnmess))returnmess= "success";
return returnmess;
}
/**
* 删除经销商车型关联表的关联
* @param tx
* @return
* @throws Exception
*/
public String deleteLmDistributorToCar(JBOTransaction tx)throws Exception {
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_DISTRIBUTOR_TO_CAR.CLASS_NAME,tx);
Lmpc.createQuery("delete from o where id = :id").setParameter("id",unionId).executeUpdate();
return "success";
}
public String deleteLmDistributorToProduct(JBOTransaction tx)throws Exception {
Transaction sqlca = Transaction.createTransaction(tx);
sqlca.executeSQL("delete from LM_DISTRIBUTOR_TO_PRODUCT where id in ('"+unionId.replaceAll("@", "','")+"')");
return "success";
}
public String deleteLmDistributorToDistrict(JBOTransaction tx)throws Exception {
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(DISTRICT_DISTRIBUTOR_RELATION.CLASS_NAME,tx);
Lmpc.createQuery("delete from o where id = :id").setParameter("id",unionId).executeUpdate();
return "success";
}
/**
* 删除渠道机构车型关联表的关联
* @param tx
* @return
* @throws Exception
*/
public String deletePortalToCar(JBOTransaction tx)throws Exception {
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_PORTAL_TO_CAR.CLASS_NAME,tx);
Lmpc.createQuery("delete from o where id = :id").setParameter("id",unionId).executeUpdate();
return "success";
}
public String saveLmDistrictToProduct(JBOTransaction tx)throws Exception {
String[] params = CarBrandId.split("@~");
String typeno = params[0];
int lle=0;
int i;
try{
BizObjectManager Lmcheck = JBOFactory.getBizObjectManager(LM_PRODUCT_DISTRICT.CLASS_NAME,tx);
for(i=1;i<params.length;i++){
String areaid = params[i].split("@")[0];
String districtname = params[i].split("@")[1];
BizObject obcheck=Lmcheck.createQuery("productid=:productid and districtid=:districtid")
.setParameter("productid", typeno).setParameter("districtid",areaid).getSingleResult(false);
if(obcheck!=null){
return districtname+"已关联至该产品!";
}
String PortalToCarId=UUID.randomUUID().toString().replaceAll("-", "");
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_PRODUCT_DISTRICT.CLASS_NAME,tx);
BizObject NewLmpc = Lmpc.newObject();
NewLmpc.setAttributeValue("id", PortalToCarId);
NewLmpc.setAttributeValue("productid", typeno);
NewLmpc.setAttributeValue("districtid", areaid);
NewLmpc.setAttributeValue("districtname", districtname);
Lmpc.saveObject(NewLmpc);
}
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}
if(lle>0){
return "error";
}
return "success";
}
public String saveLmDistributorGroupToProduct(JBOTransaction tx)throws Exception {
String[] params = CarBrandId.split("@~");
String typeno = params[0];
int lle=0;
int i;
try{
BizObjectManager Lmcheck = JBOFactory.getBizObjectManager(LM_PRODUCT_DISTRIBUTOR_GROUP.CLASS_NAME,tx);
for(i=1;i<params.length;i++){
String distributgroupid = params[i].split("@")[0];
String distributgroupname = params[i].split("@")[1];
BizObject obcheck=Lmcheck.createQuery("productid=:productid and distributgroupid=:districtid")
.setParameter("productid", typeno).setParameter("districtid",distributgroupid).getSingleResult(false);
if(obcheck!=null){
return distributgroupname+"已关联至该产品!";
}
String PortalToCarId=UUID.randomUUID().toString().replaceAll("-", "");
BizObjectManager Lmpc = JBOFactory.getBizObjectManager(LM_PRODUCT_DISTRIBUTOR_GROUP.CLASS_NAME,tx);
BizObject NewLmpc = Lmpc.newObject();
NewLmpc.setAttributeValue("id", PortalToCarId);
NewLmpc.setAttributeValue("productid", typeno);
NewLmpc.setAttributeValue("distributgroupid", distributgroupid);
NewLmpc.setAttributeValue("distributgroupname", distributgroupname);
Lmpc.saveObject(NewLmpc);
}
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}
if(lle>0){
return "error";
}
return "success";
}
}