|
@@ -0,0 +1,657 @@
|
|
|
+package bamp.basedata.webapi;
|
|
|
+
|
|
|
+import kd.bos.algo.DataSet;
|
|
|
+import kd.bos.algo.Row;
|
|
|
+import kd.bos.bd.service.AssignService;
|
|
|
+import kd.bos.dataentity.OperateOption;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
+import kd.bos.db.DB;
|
|
|
+import kd.bos.db.DBRoute;
|
|
|
+import kd.bos.entity.AppInfo;
|
|
|
+import kd.bos.entity.AppMetadataCache;
|
|
|
+import kd.bos.entity.basedata.BaseDataResponse;
|
|
|
+import kd.bos.entity.operate.result.OperateErrorInfo;
|
|
|
+import kd.bos.entity.operate.result.OperationResult;
|
|
|
+import kd.bos.entity.validate.ValidateResult;
|
|
|
+import kd.bos.entity.validate.ValidateResultCollection;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiMapping;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
|
+import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
|
+import kd.bos.openapi.common.result.CustomApiResult;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/*
|
|
|
+ * 客户新增插件
|
|
|
+ * wangj 2025-01-15
|
|
|
+ * 主要功能:新增主数据客户并分配组织
|
|
|
+ */
|
|
|
+@SuppressWarnings("all")
|
|
|
+@ApiController(value = "open", desc = "客户新增接口插件")
|
|
|
+@ApiMapping(value = "/bd_customer")
|
|
|
+public class CustomerAddnewWebApiPlugin implements Serializable {
|
|
|
+ int successCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ private static final Log log = LogFactory.getLog(CustomerAddnewWebApiPlugin.class);
|
|
|
+ @ApiPostMapping(value = "customer_addnew", desc = "同步接口")
|
|
|
+ public CustomApiResult<Map<String, Object>> customer_addnew(@ApiParam(value = "提交参数") List<Map<String, Object>> data ) {
|
|
|
+ CustomApiResult customApiResult = new CustomApiResult();
|
|
|
+ customApiResult.setStatus(true);
|
|
|
+ customApiResult.setErrorCode("0");
|
|
|
+ try {
|
|
|
+ Map resultDatasMap = new HashMap();
|
|
|
+ List<Map> resultDatas = new ArrayList<Map>();
|
|
|
+ for(Map param : data){
|
|
|
+ Map resultData = new HashMap();
|
|
|
+ try {
|
|
|
+ doUpdateCustomer(param,resultData);
|
|
|
+ }catch (Exception e) {
|
|
|
+ resultData.put("id","");
|
|
|
+ resultData.put("errors",e.getMessage());
|
|
|
+ resultData.put("billStatus",false);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ resultDatas.add(resultData);
|
|
|
+ }
|
|
|
+ resultDatasMap.put("failCount",failCount);
|
|
|
+ if(failCount>0){
|
|
|
+ customApiResult.setStatus(false);
|
|
|
+ customApiResult.setErrorCode("603");
|
|
|
+ }
|
|
|
+ resultDatasMap.put("successCount",successCount);
|
|
|
+ resultDatasMap.put("result",resultDatas);
|
|
|
+ customApiResult.setData(resultDatasMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ customApiResult.setStatus(false);
|
|
|
+ customApiResult.setMessage(e.getMessage());
|
|
|
+ customApiResult.setErrorCode("400");
|
|
|
+ }
|
|
|
+
|
|
|
+ return customApiResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doUpdateCustomer(Map param, Map resultData) throws ParseException {
|
|
|
+ String errorMsg = "";
|
|
|
+ //创建新用户
|
|
|
+ DynamicObject customerObj = null;
|
|
|
+ if(param.get("number")!=null){
|
|
|
+ QFilter qFilter_number = new QFilter("number",QCP.equals,param.get("number"));
|
|
|
+ DynamicObject[] customer = BusinessDataServiceHelper.load("bd_customer","id",new QFilter[]{qFilter_number});
|
|
|
+ if(customer.length>0){//防止新增失败情况留存的历史数据
|
|
|
+ customerObj = BusinessDataServiceHelper.loadSingle(customer[0].getPkValue(),"bd_customer");
|
|
|
+ if(param.get("enable")!=null && !"".equals(param.get("enable")) && "0".equals(param.get("enable"))){//使用状态变为禁用
|
|
|
+ //禁用人
|
|
|
+ setDynamicField(true,"modifier_number","disabler","bos_user",param,resultData,customerObj);
|
|
|
+ //禁用时间
|
|
|
+ setDateField(true,"modifytime","disabledate",param,resultData,customerObj);
|
|
|
+ //使用状态
|
|
|
+ customerObj.set("enable","0");
|
|
|
+ }
|
|
|
+ //客户字码分录
|
|
|
+ if(param.get("pznm_zmentry")!=null){
|
|
|
+ List<Map> mapEntrys = (List<Map>) param.get("pznm_zmentry");
|
|
|
+ doSetEntry(mapEntrys,resultData,customerObj);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ customerObj = BusinessDataServiceHelper.newDynamicObject("bd_customer");
|
|
|
+ //数据状态
|
|
|
+ customerObj.set("status","A");
|
|
|
+ //使用状态
|
|
|
+ customerObj.set("enable","1");
|
|
|
+ }
|
|
|
+ resultData.put("number",param.get("number"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //客户编码
|
|
|
+ setTextField(true,"number","number",param,resultData,customerObj);
|
|
|
+ //客户名称
|
|
|
+ setTextField(true,"name","name",param,resultData,customerObj);
|
|
|
+ //创建人
|
|
|
+ setDynamicField(true,"creator_number","creator","bos_user",param,resultData,customerObj);
|
|
|
+ //创建时间
|
|
|
+ setDateField(true,"createtime","createtime",param,resultData,customerObj);
|
|
|
+ //修改人
|
|
|
+ setDynamicField(true,"modifier_number","pznm_modifier_xh","bos_user",param,resultData,customerObj);
|
|
|
+ //修改时间
|
|
|
+ setDateField(true,"modifytime","modifytime",param,resultData,customerObj);
|
|
|
+ //审核人
|
|
|
+ setDynamicField(true,"approverid_number","pznm_auditor_xh","bos_user",param,resultData,customerObj);
|
|
|
+ //审核日期
|
|
|
+ setDateField(true,"approvedate","approvedate",param,resultData,customerObj);
|
|
|
+ //创建组织
|
|
|
+ setDynamicField(true,"createorg_number","createorg","bos_org",param,resultData,customerObj);
|
|
|
+ //控制策略
|
|
|
+ customerObj.set("ctrlstrategy",1);
|
|
|
+ //详细地址
|
|
|
+ setTextField(false,"bizpartner_address","bizpartner_address",param,resultData,customerObj);
|
|
|
+ //统一社会信用代码
|
|
|
+ setTextField(false,"societycreditcode","societycreditcode",param,resultData,customerObj);
|
|
|
+ //是否关联单位
|
|
|
+ setTextField(false,"pznm_isrelateunit","pznm_isrelateunit",param,resultData,customerObj);
|
|
|
+ //内部业务单元
|
|
|
+ setDynamicField(false,"internal_company_number","internal_company","bos_org",param,resultData,customerObj);
|
|
|
+ //内部客户
|
|
|
+ setTextField(false,"chkisinternalcompany","chkisinternalcompany",param,resultData,customerObj);
|
|
|
+ //客户分类
|
|
|
+ if(param.get("entry_groupstandard")!=null){
|
|
|
+ List<Map> mapEntrys = (List<Map>) param.get("entry_groupstandard");
|
|
|
+ doSetGroupEntry(mapEntrys,resultData,customerObj);
|
|
|
+ }
|
|
|
+ //银行信息
|
|
|
+ if(param.get("entry_bank")!=null){
|
|
|
+ List<Map> mapEntrys = (List<Map>) param.get("entry_bank");
|
|
|
+ doSetBankEntry(mapEntrys,resultData,customerObj);
|
|
|
+ }
|
|
|
+ //委托人分录
|
|
|
+ if(param.get("pznm_wtrentry")!=null){
|
|
|
+ List<Map> mapEntrys = (List<Map>) param.get("pznm_wtrentry");
|
|
|
+ doSetWtrEntry(mapEntrys,resultData,customerObj);
|
|
|
+ }
|
|
|
+ //控制状态分录
|
|
|
+ if(param.get("pznm_kzztentry")!=null){
|
|
|
+ List<Map> mapEntrys = (List<Map>) param.get("pznm_kzztentry");
|
|
|
+ doSetKzztentry(mapEntrys,resultData,customerObj);
|
|
|
+ }
|
|
|
+ if(resultData.get("errors")!=null && !"".equals(resultData.get("errors"))){
|
|
|
+ List errors = new ArrayList();
|
|
|
+ errors.add(resultData.get("errors"));
|
|
|
+ resultData.put("id","");
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("billStatus",false);
|
|
|
+ }else{
|
|
|
+ //保存客户对象
|
|
|
+ String status = customerObj.getString("status");
|
|
|
+ if("A".equals(status)){//暂存,走正常逻辑
|
|
|
+ doAddNew(resultData,customerObj,param);
|
|
|
+ }else if("B".equals(status)){//已提交,走update和审核
|
|
|
+ doUpdateAndFP(resultData,customerObj);
|
|
|
+ }else if("C".equals(status)){//已审核,走分配逻辑
|
|
|
+ String error = doFP(customerObj);
|
|
|
+ if("".equals(error)){//分配成功
|
|
|
+ resultData.put("errors",new ArrayList());
|
|
|
+ resultData.put("id",customerObj.getPkValue());
|
|
|
+ resultData.put("billStatus", true);
|
|
|
+ successCount++;
|
|
|
+ }else{//分配失败
|
|
|
+ List errors = new ArrayList();
|
|
|
+ errors.add(error);
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id",customerObj.getPkValue());
|
|
|
+ resultData.put("billStatus", true);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doUpdateAndFP(Map resultData, DynamicObject customerObj) {
|
|
|
+ SaveServiceHelper.update(customerObj);
|
|
|
+ OperationResult result_audit = OperationServiceHelper.executeOperate("audit", "bd_customer",
|
|
|
+ new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
+ //执行客户对应组织分配
|
|
|
+ if(result_audit.isSuccess()){//保存客户成功
|
|
|
+ String error = doFP(customerObj);
|
|
|
+ if("".equals(error)){//分配成功
|
|
|
+ resultData.put("errors",new ArrayList());
|
|
|
+ resultData.put("id",result_audit.getSuccessPkIds().get(0));
|
|
|
+ resultData.put("billStatus", true);
|
|
|
+ successCount++;
|
|
|
+ }else{//分配失败
|
|
|
+ List errors = new ArrayList();
|
|
|
+ errors.add(error);
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id",result_audit.getSuccessPkIds().get(0));
|
|
|
+ resultData.put("billStatus", true);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ }else{//提交客户失败
|
|
|
+ List errors = new ArrayList();
|
|
|
+ ValidateResultCollection validateResults = result_audit.getValidateResult();
|
|
|
+ List<ValidateResult> validateResultList = validateResults.getValidateErrors();
|
|
|
+ for(ValidateResult validateResult : validateResultList){
|
|
|
+ List<OperateErrorInfo> allErrorInfos = validateResult.getAllErrorInfo();
|
|
|
+ for(OperateErrorInfo allErrorInfo : allErrorInfos){
|
|
|
+ errors.add(allErrorInfo.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id","");
|
|
|
+ resultData.put("billStatus", false);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doAddNew(Map resultData, DynamicObject customerObj, Map param) {
|
|
|
+ OperationResult result_submit = OperationServiceHelper.executeOperate("submit", "bd_customer",
|
|
|
+ new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
+ if(result_submit.isSuccess()){
|
|
|
+ OperationResult result_audit = OperationServiceHelper.executeOperate("audit", "bd_customer",
|
|
|
+ new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
+ //执行客户对应组织分配
|
|
|
+ if(result_audit.isSuccess()){//保存客户成功
|
|
|
+ String error = doFP(customerObj);
|
|
|
+ if("".equals(error)){//分配成功
|
|
|
+ //更新客户子码基础资料
|
|
|
+ if(param.get("pznm_zmentry")!=null){
|
|
|
+ List<Map> mapEntrys = (List<Map>) param.get("pznm_zmentry");
|
|
|
+ doSetEntry(mapEntrys,resultData,customerObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(resultData.get("errors")!=null && !"".equals(resultData.get("errors"))){
|
|
|
+ List errors = new ArrayList();
|
|
|
+ errors.add(resultData.get("errors"));
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id","");
|
|
|
+ resultData.put("billStatus", false);
|
|
|
+ failCount ++;
|
|
|
+ }else{
|
|
|
+ resultData.put("errors",new ArrayList());
|
|
|
+ resultData.put("id",result_audit.getSuccessPkIds().get(0));
|
|
|
+ resultData.put("billStatus", true);
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
+ }else{//分配失败
|
|
|
+ List errors = new ArrayList();
|
|
|
+ errors.add(error);
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id",result_audit.getSuccessPkIds().get(0));
|
|
|
+ resultData.put("billStatus", true);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ }else{//提交客户失败
|
|
|
+ List errors = new ArrayList();
|
|
|
+ ValidateResultCollection validateResults = result_audit.getValidateResult();
|
|
|
+ List<ValidateResult> validateResultList = validateResults.getValidateErrors();
|
|
|
+ for(ValidateResult validateResult : validateResultList){
|
|
|
+ List<OperateErrorInfo> allErrorInfos = validateResult.getAllErrorInfo();
|
|
|
+ for(OperateErrorInfo allErrorInfo : allErrorInfos){
|
|
|
+ errors.add(allErrorInfo.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id","");
|
|
|
+ resultData.put("billStatus", false);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ List errors = new ArrayList();
|
|
|
+ ValidateResultCollection validateResults = result_submit.getValidateResult();
|
|
|
+ List<ValidateResult> validateResultList = validateResults.getValidateErrors();
|
|
|
+ for(ValidateResult validateResult : validateResultList){
|
|
|
+ List<OperateErrorInfo> allErrorInfos = validateResult.getAllErrorInfo();
|
|
|
+ for(OperateErrorInfo allErrorInfo : allErrorInfos){
|
|
|
+ errors.add(allErrorInfo.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultData.put("errors",errors);
|
|
|
+ resultData.put("id","");
|
|
|
+ resultData.put("billStatus", false);
|
|
|
+ failCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSetGroupEntry(List<Map> mapEntrys, Map resultData, DynamicObject customerObj) {
|
|
|
+ DynamicObjectCollection entrys = customerObj.getDynamicObjectCollection("entry_groupstandard");
|
|
|
+ entrys.clear();
|
|
|
+ for(Map mapEntry : mapEntrys) {
|
|
|
+ DynamicObject newEntry = new DynamicObject(entrys.getDynamicObjectType());
|
|
|
+ //分类标准.编码
|
|
|
+ setDynamicField(true, "standardid_number", "standardid", "bd_customergroupstandard",
|
|
|
+ mapEntry, resultData, newEntry);
|
|
|
+ //分类.编码
|
|
|
+ setDynamicField(false,"groupid_number","groupid","bd_customergroup",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ entrys.add(newEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSetBankEntry(List<Map> mapEntrys, Map resultData, DynamicObject customerObj) {
|
|
|
+ DynamicObjectCollection entrys = customerObj.getDynamicObjectCollection("entry_bank");
|
|
|
+ entrys.clear();
|
|
|
+ for(Map mapEntry : mapEntrys) {
|
|
|
+ DynamicObject newEntry = new DynamicObject(entrys.getDynamicObjectType());
|
|
|
+ //所属组织
|
|
|
+ setDynamicField(true, "pznm_bket_org_number", "pznm_bket_org", "bos_org",
|
|
|
+ mapEntry, resultData, newEntry);
|
|
|
+ //银行账号
|
|
|
+ setTextField(true, "bankaccount", "bankaccount", mapEntry, resultData, newEntry);
|
|
|
+ //账户名称
|
|
|
+ setTextField(true, "accountname", "accountname", mapEntry, resultData, newEntry);
|
|
|
+ //开户银行
|
|
|
+ setDynamicField(true,"bank_number","bank","bd_bebank",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ //币别
|
|
|
+ setDynamicField(true,"currency_number","currency","bd_currency",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ //默认
|
|
|
+ setTextField(true, "isdefault_bank", "isdefault_bank", mapEntry, resultData, newEntry);
|
|
|
+ //账户性质
|
|
|
+ setTextField(false, "pznm_bket_account", "pznm_bket_account", mapEntry, resultData, newEntry);
|
|
|
+ entrys.add(newEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSetEntry(List<Map> mapEntrys, Map resultData, DynamicObject customerObj) {
|
|
|
+ //拼接组织+字码编码的过滤条件
|
|
|
+ List<String> zmnumbers = new ArrayList<String>();
|
|
|
+ List<String> orgnumbers = new ArrayList<String>();
|
|
|
+ for(Map mapEntry : mapEntrys){
|
|
|
+ zmnumbers.add(mapEntry.get("pznm_zmet_number").toString());
|
|
|
+ orgnumbers.add(mapEntry.get("pznm_zmet_org_number").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询过滤条件,缓存存在的字码Map记录
|
|
|
+ Map isHaveOrgs_zmnumber = new HashMap();
|
|
|
+ QFilter qFilter_customer = new QFilter("pznm_customer",QCP.equals,customerObj.getPkValue());
|
|
|
+ QFilter qFilter_org = new QFilter("pznm_zmet_org.number",QCP.in,orgnumbers);
|
|
|
+ QFilter qFilter_ztnumber = new QFilter("number",QCP.in,zmnumbers);
|
|
|
+ DynamicObject[] isHaveObjs = BusinessDataServiceHelper.load("pznm_customerzm",
|
|
|
+ "id,pznm_zmet_org,pznm_zmet_org.number,pznm_zmet_number,pznm_zmet_name,pznm_zmet_oldnumber,pznm_zmet_wtr,pznm_zmet_wtrphone," +
|
|
|
+ "pznm_zmet_lxr,pznm_zmet_lxrphone,pznm_shipaddress,pznm_shipperson,pznm_shipphone,pznm_zmet_setttype," +
|
|
|
+ "pznm_zmet_zqnotes,pznm_zmet_settday,pznm_zmet_zqrtype,pznm_zmet_zqptype,pznm_zmet_paytype,pznm_zmet_invoicetype",
|
|
|
+ new QFilter[]{qFilter_customer,qFilter_org,qFilter_ztnumber});
|
|
|
+ for(DynamicObject obj : isHaveObjs){
|
|
|
+ DynamicObject org = (DynamicObject) obj.getDynamicObject("pznm_zmet_org");
|
|
|
+ String org_zmnumber = org.getString("number")+"_"+obj.getString("number");
|
|
|
+ isHaveOrgs_zmnumber.put(org_zmnumber,obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ //区分并拼接需更新和新增的记录
|
|
|
+ DynamicObjectCollection add_entrys = new DynamicObjectCollection();
|
|
|
+ DynamicObjectCollection update_entrys = new DynamicObjectCollection();
|
|
|
+ for(Map mapEntry : mapEntrys){
|
|
|
+ String org_zmnumber = mapEntry.get("pznm_zmet_org_number").toString()+"_"+mapEntry.get("pznm_zmet_number").toString();
|
|
|
+ if(isHaveOrgs_zmnumber.get(org_zmnumber)!=null && !"".equals(isHaveOrgs_zmnumber.get(org_zmnumber))){
|
|
|
+ //已存在,缓存修改对象
|
|
|
+ DynamicObject update_entry = (DynamicObject) isHaveOrgs_zmnumber.get(org_zmnumber);
|
|
|
+
|
|
|
+ setDynamicField(true,"pznm_zmet_org_number","pznm_zmet_org","bos_org",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.子码编码
|
|
|
+ setTextField(true,"pznm_zmet_number","number",mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.子码名称
|
|
|
+ setTextField(true,"pznm_zmet_name","name",mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.老系统编号
|
|
|
+ setTextField(false,"pznm_zmet_oldnumber","pznm_zmet_oldnumber",mapEntry,resultData,update_entry);
|
|
|
+ //委托人.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_wtr_number","pznm_zmet_wtr","pznm_outcontacts",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //委托人信息.委托人电话
|
|
|
+ setTextField(false,"pznm_zmet_wtrphone","pznm_zmet_wtrphone",mapEntry,resultData,update_entry);
|
|
|
+ //联系人.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_lxr_number","pznm_zmet_lxr","pznm_outcontacts",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.联系人电话
|
|
|
+ setTextField(false,"pznm_zmet_lxrphone","pznm_zmet_lxrphone",mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.收货地址
|
|
|
+ setTextField(false,"pznm_shipaddress","pznm_shipaddress",mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.收货人
|
|
|
+ setTextField(false,"pznm_shipperson","pznm_shipperson",mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.收货人电话
|
|
|
+ setTextField(false,"pznm_shipphone","pznm_shipphone",mapEntry,resultData,update_entry);
|
|
|
+ //结算类型.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_setttype_number","pznm_zmet_setttype","pznm_settlementtype",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.账期摘要
|
|
|
+ setTextField(false,"pznm_zmet_zqnotes","pznm_zmet_zqnotes",mapEntry,resultData,update_entry);
|
|
|
+ //客户子码.实销实结结算日
|
|
|
+ setTextField(false,"pznm_zmet_settday","pznm_zmet_settday",mapEntry,resultData,update_entry);
|
|
|
+ //账期类型(收款).编码
|
|
|
+ setDynamicField(false,"pznm_zmet_zqrtype_number","pznm_zmet_zqrtype","bd_reccondition",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //账期类型(付款).编码
|
|
|
+ setDynamicField(false,"pznm_zmet_zqptype_number","pznm_zmet_zqptype","bd_paycondition",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //支付方式.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_paytype_number","pznm_zmet_paytype","bd_settlementtype",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ //发票类型.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_invoicetype_number","pznm_zmet_invoicetype","bd_invoicetype",
|
|
|
+ mapEntry,resultData,update_entry);
|
|
|
+ update_entrys.add(update_entry);
|
|
|
+ }else{
|
|
|
+ //不存在,缓存新增对象
|
|
|
+ DynamicObject add_entry = BusinessDataServiceHelper.newDynamicObject("pznm_customerzm");
|
|
|
+
|
|
|
+ setDynamicField(true,"pznm_zmet_org_number","pznm_zmet_org","bos_org",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.子码编码
|
|
|
+ setTextField(true,"pznm_zmet_number","number",mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.子码名称
|
|
|
+ setTextField(true,"pznm_zmet_name","name",mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.老系统编号
|
|
|
+ setTextField(false,"pznm_zmet_oldnumber","pznm_zmet_oldnumber",mapEntry,resultData,add_entry);
|
|
|
+ //委托人.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_wtr_number","pznm_zmet_wtr","pznm_outcontacts",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //委托人信息.委托人电话
|
|
|
+ setTextField(false,"pznm_zmet_wtrphone","pznm_zmet_wtrphone",mapEntry,resultData,add_entry);
|
|
|
+ //联系人.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_lxr_number","pznm_zmet_lxr","pznm_outcontacts",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.联系人电话
|
|
|
+ setTextField(false,"pznm_zmet_lxrphone","pznm_zmet_lxrphone",mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.收货地址
|
|
|
+ setTextField(false,"pznm_shipaddress","pznm_shipaddress",mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.收货人
|
|
|
+ setTextField(false,"pznm_shipperson","pznm_shipperson",mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.收货人电话
|
|
|
+ setTextField(false,"pznm_shipphone","pznm_shipphone",mapEntry,resultData,add_entry);
|
|
|
+ //结算类型.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_setttype_number","pznm_zmet_setttype","pznm_settlementtype",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.账期摘要
|
|
|
+ setTextField(false,"pznm_zmet_zqnotes","pznm_zmet_zqnotes",mapEntry,resultData,add_entry);
|
|
|
+ //客户子码.实销实结结算日
|
|
|
+ setTextField(false,"pznm_zmet_settday","pznm_zmet_settday",mapEntry,resultData,add_entry);
|
|
|
+ //账期类型(收款).编码
|
|
|
+ setDynamicField(false,"pznm_zmet_zqrtype_number","pznm_zmet_zqrtype","bd_reccondition",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //账期类型(付款).编码
|
|
|
+ setDynamicField(false,"pznm_zmet_zqptype_number","pznm_zmet_zqptype","bd_paycondition",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //支付方式.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_paytype_number","pznm_zmet_paytype","bd_settlementtype",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //发票类型.编码
|
|
|
+ setDynamicField(false,"pznm_zmet_invoicetype_number","pznm_zmet_invoicetype","bd_invoicetype",
|
|
|
+ mapEntry,resultData,add_entry);
|
|
|
+ //客户
|
|
|
+ add_entry.set("pznm_customer",customerObj);
|
|
|
+ //数据状态
|
|
|
+ add_entry.set("status","A");
|
|
|
+ //使用状态
|
|
|
+ add_entry.set("enable","1");
|
|
|
+ add_entrys.add(add_entry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicObject[] real_update_entrys = new DynamicObject[update_entrys.size()];
|
|
|
+ for(int i=0;i< update_entrys.size();i++){
|
|
|
+ real_update_entrys[i] = update_entrys.get(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicObject[] real_add_entrys = new DynamicObject[add_entrys.size()];
|
|
|
+ for(int i=0;i< add_entrys.size();i++){
|
|
|
+ real_add_entrys[i] = add_entrys.get(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(resultData.get("errors")==null || "".equals(resultData.get("errors"))){
|
|
|
+ //执行更新
|
|
|
+ if (real_update_entrys.length > 0) {
|
|
|
+ SaveServiceHelper.update(real_update_entrys);
|
|
|
+ }
|
|
|
+ //执行新增
|
|
|
+ if (real_add_entrys.length > 0) {
|
|
|
+ OperationResult result_submit = OperationServiceHelper.executeOperate("submit", "pznm_customerzm",
|
|
|
+ real_add_entrys, OperateOption.create());
|
|
|
+ if (result_submit.isSuccess() == true) {
|
|
|
+ OperationResult result_audit = OperationServiceHelper.executeOperate("audit", "pznm_customerzm",
|
|
|
+ real_add_entrys, OperateOption.create());
|
|
|
+ if (result_audit.isSuccess() == false) {
|
|
|
+ resultData.put("errors", "子码审核失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resultData.put("errors", "子码创建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSetWtrEntry(List<Map> mapEntrys, Map resultData, DynamicObject customerObj) {
|
|
|
+ DynamicObjectCollection entrys = customerObj.getDynamicObjectCollection("pznm_wtrentry");
|
|
|
+ entrys.clear();
|
|
|
+ for(Map mapEntry : mapEntrys){
|
|
|
+ DynamicObject newEntry = new DynamicObject(entrys.getDynamicObjectType());
|
|
|
+ //所属组织
|
|
|
+ setDynamicField(true,"pznm_wtret_org_number","pznm_wtret_org","bos_org",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ //委托人信息.委托人电话
|
|
|
+ setTextField(false,"pznm_wtret_userphone","pznm_wtret_userphone",mapEntry,resultData,newEntry);
|
|
|
+ //委托人.编码
|
|
|
+ setDynamicField(true,"pznm_wtret_user_number","pznm_wtret_user","pznm_outcontacts",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ entrys.add(newEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doSetKzztentry(List<Map> mapEntrys, Map resultData, DynamicObject customerObj) {
|
|
|
+ DynamicObjectCollection entrys = customerObj.getDynamicObjectCollection("pznm_kzztentry");
|
|
|
+ entrys.clear();
|
|
|
+ for(Map mapEntry : mapEntrys){
|
|
|
+ DynamicObject newEntry = new DynamicObject(entrys.getDynamicObjectType());
|
|
|
+ //所属组织
|
|
|
+ setDynamicField(true,"pznm_kzztet_org_number","pznm_kzztet_org","bos_org",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ //公司级状态
|
|
|
+ setTextField(true,"pznm_companystatus","pznm_companystatus",mapEntry,resultData,newEntry);
|
|
|
+ //开票需求
|
|
|
+ setDynamicField(false,"pznm_invoicdemand_number","pznm_invoicdemand","pznm_invoicdemand",
|
|
|
+ mapEntry,resultData,newEntry);
|
|
|
+ //月结开票日
|
|
|
+ setTextField(false,"pznm_invoicday","pznm_invoicday",mapEntry,resultData,newEntry);
|
|
|
+
|
|
|
+ entrys.add(newEntry);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 校验并设置F7字段
|
|
|
+ * @key 入参校验字段
|
|
|
+ * @fieldName 写入客户对象的字段名
|
|
|
+ * @entityNumber 字段对应基础资料实体名
|
|
|
+ * @param 接口入参对象
|
|
|
+ * @resultData 返回报文对象
|
|
|
+ * @customerObj 客户对象
|
|
|
+ */
|
|
|
+ private void setDynamicField(Boolean isMust,String key,String fieldName, String entityNumber, Map param, Map resultData, DynamicObject customerObj) {
|
|
|
+ if(param.get(key)==null || "".equals(param.get(key))){
|
|
|
+ if(isMust){
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
+ resultData.put("errors",errors+"参数【" + key + "】必填");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ QFilter qFilter_number = new QFilter("number",QCP.equals,param.get(key));
|
|
|
+ QFilter qFilter_enable = new QFilter("enable", QCP.equals,"1");
|
|
|
+ QFilter qFilter_status = new QFilter("status", QCP.equals, "C");
|
|
|
+ DynamicObject objCol = BusinessDataServiceHelper.loadSingleFromCache(entityNumber,"id,number,name",
|
|
|
+ new QFilter[]{qFilter_number,qFilter_enable,qFilter_status});
|
|
|
+ if(objCol!=null){
|
|
|
+ customerObj.set(fieldName,objCol);
|
|
|
+ }else{
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
+ resultData.put("errors",errors+"参数【" + key + "】值【"+param.get(key)+"】匹配不成功,可能的原因是:1、编码不正确 2、不符合基础资料字段查询条件");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 校验并设置文本字段
|
|
|
+ * @key 入参校验字段
|
|
|
+ * @fieldName 写入客户对象的字段名
|
|
|
+ * @param 接口入参对象
|
|
|
+ * @resultData 返回报文对象
|
|
|
+ * @customerObj 客户对象
|
|
|
+ */
|
|
|
+ private void setTextField(Boolean isMust,String key,String fieldName,Map param, Map resultData, DynamicObject customerObj) {
|
|
|
+ if(param.get(key)==null || "".equals(param.get(key))){
|
|
|
+ if(isMust){
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
+ resultData.put("errors",errors+"参数【" + key + "】必填");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ customerObj.set(fieldName,param.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 校验并设置日期字段
|
|
|
+ * @key 入参校验字段
|
|
|
+ * @fieldName 写入客户对象的字段名
|
|
|
+ * @param 接口入参对象
|
|
|
+ * @resultData 返回报文对象
|
|
|
+ * @customerObj 客户对象
|
|
|
+ */
|
|
|
+ private void setDateField(Boolean isMust,String key,String fieldName,Map param, Map resultData, DynamicObject customerObj) throws ParseException {
|
|
|
+ if(param.get(key)==null || "".equals(param.get(key))){
|
|
|
+ if(isMust){
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
+ resultData.put("errors",errors+"参数【" + key + "】必填");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ customerObj.set(fieldName,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(param.get(key).toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String doFP(DynamicObject customerObj) {
|
|
|
+ SaveServiceHelper.update(customerObj);
|
|
|
+ String error = "";
|
|
|
+ Map isHaveOrgIds = getIsHaveOrgIds(customerObj.getPkValue());
|
|
|
+
|
|
|
+ DynamicObjectCollection kzztentrys = customerObj.getDynamicObjectCollection("pznm_kzztentry");
|
|
|
+ Set<Long> orgIds = new HashSet(kzztentrys.size());
|
|
|
+ List<Long> orgIds_list = new ArrayList<Long>();
|
|
|
+ for(DynamicObject kzztentry : kzztentrys){
|
|
|
+ DynamicObject org = kzztentry.getDynamicObject("pznm_kzztet_org");
|
|
|
+ if(isHaveOrgIds.get(org.getString("id"))==null || "".equals(isHaveOrgIds.get(org.getString("id")))){
|
|
|
+ orgIds_list.add(org.getLong("id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orgIds = new HashSet<>(orgIds_list);
|
|
|
+ if(orgIds.size()>0){
|
|
|
+ AppInfo appInfo = AppMetadataCache.getAppInfo("basedata");
|
|
|
+ String appId = appInfo.getAppId();
|
|
|
+ Set<Long> dataIds = new HashSet<Long>();
|
|
|
+ dataIds.add(customerObj.getLong("id"));
|
|
|
+ QFilter qFilter_number = new QFilter("number", QCP.equals,"1");
|
|
|
+ DynamicObject useOrg = BusinessDataServiceHelper.loadSingle("bos_adminorg","id",new QFilter[]{qFilter_number});
|
|
|
+ long useOrgId = useOrg.getLong("id");
|
|
|
+ BaseDataResponse response = (new AssignService("bd_customer").assign(useOrgId, appId, dataIds, orgIds, true));
|
|
|
+ if (!response.isSuccess()) {
|
|
|
+ error = response.getErrorMsg();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map getIsHaveOrgIds(Object pkValue) {
|
|
|
+ Map isHaveOrgIds = new HashMap();
|
|
|
+ String sql = "SELECT fuseorgid FROM T_BD_CUSTOMER_U WHERE FDATAID="+pkValue;
|
|
|
+ DataSet ds = DB.queryDataSet(this.getClass().getName(), DBRoute.of("sys"), sql);
|
|
|
+ for (Row row : ds) {
|
|
|
+ String orgId = row.getString("fuseorgid");
|
|
|
+ isHaveOrgIds.put(orgId,orgId);
|
|
|
+ }
|
|
|
+ return isHaveOrgIds;
|
|
|
+ }
|
|
|
+}
|