|
@@ -0,0 +1,769 @@
|
|
|
|
+package bamp.basedata.webapi;
|
|
|
|
+
|
|
|
|
+import kd.bd.master.enums.EnableEnum;
|
|
|
|
+import kd.bd.master.enums.StatusEnum;
|
|
|
|
+import kd.bd.master.vo.OperationApiVo;
|
|
|
|
+import kd.bd.master.webapi.model.GenMTAndBizInfoRespModel;
|
|
|
|
+import kd.bos.dataentity.OperateOption;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.metadata.IMetadata;
|
|
|
|
+import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
|
|
+import kd.bos.db.DB;
|
|
|
|
+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.exception.KDBizException;
|
|
|
|
+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.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 kd.bos.util.ExceptionUtils;
|
|
|
|
+import bamp.basedata.util.WebApiUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+
|
|
|
|
+import javax.validation.constraints.NotEmpty;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author : libo_kd
|
|
|
|
+ * @description :
|
|
|
|
+ * @date : 2025.01.15 9:37:54
|
|
|
|
+ */
|
|
|
|
+@ApiController(
|
|
|
|
+ desc = "生成物料和物料业务信息OpenAPI",
|
|
|
|
+ value = "bd"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+public class MaterialAddNewApi {
|
|
|
|
+ private static final long serialVersionUID = 4434540944862847555L;
|
|
|
|
+ private static Log logger = LogFactory.getLog(MaterialAddNewApi.class);
|
|
|
|
+ private static final String ERR_CODE_OPERATE_FAILED = "777";
|
|
|
|
+ private static final String ERR_CODE_SYS_EX = "999";
|
|
|
|
+ private static final String BOM_VERSION_RULE = "bomversionrule";
|
|
|
|
+ private static final Long BOM_VERSION_RULE_DEFAULTVAL = 780605109909666816L;
|
|
|
|
+
|
|
|
|
+ int successCount = 0;
|
|
|
|
+ int failCount = 0;
|
|
|
|
+
|
|
|
|
+ @ApiPostMapping("/material_addnew")
|
|
|
|
+ public CustomApiResult<List<GenMTAndBizInfoRespModel>> doCustomService(@NotEmpty @ApiParam("物料参数,List表示支持传入多个物料,Map代表一个物料,key为物料元数据上的字段,value为字段值。") List<Map<String, Object>> data) {
|
|
|
|
+ CustomApiResult customApiResult = new CustomApiResult();
|
|
|
|
+ customApiResult.setStatus(false);
|
|
|
|
+ customApiResult.setErrorCode("400");
|
|
|
|
+ try {
|
|
|
|
+ Set<String> materialNums = data.stream().map(x -> (String) x.get("number")).collect(Collectors.toSet());
|
|
|
|
+ DynamicObject[] findMaterial = new DynamicObject[0];
|
|
|
|
+ if (materialNums.size() > 0) {
|
|
|
|
+ findMaterial = BusinessDataServiceHelper.load("bd_material", "id,number", new QFilter[]{new QFilter("number", QCP.in, materialNums)});
|
|
|
|
+ }
|
|
|
|
+ Map resultDatasMap = new HashMap();
|
|
|
|
+ List<Map> resultDatas = new ArrayList<Map>();
|
|
|
|
+ for (Map mst : data) {
|
|
|
|
+ Map resultData = new HashMap();
|
|
|
|
+ try {
|
|
|
|
+ String mstNum = (String) mst.get("number");
|
|
|
|
+ Long id = 0l;
|
|
|
|
+ if (findMaterial.length > 0) {
|
|
|
|
+ List<DynamicObject> finds = Arrays.stream(findMaterial).filter(x -> x.getString("number").equals(mstNum)).collect(Collectors.toList());
|
|
|
|
+ if (finds.size() > 0) id = finds.get(0).getLong("id");
|
|
|
|
+ }
|
|
|
|
+ if (id != null && id != 0L) {
|
|
|
|
+ mst.put("id", id);
|
|
|
|
+ forceSetStatusAndEnable(mst);
|
|
|
|
+ updateMasterData(id, mst, "bd_material", resultData);
|
|
|
|
+ successCount++;
|
|
|
|
+ } else {
|
|
|
|
+ forceSetStatusAndEnable(mst);
|
|
|
|
+ createMasterData(mst, "bd_material", resultData);
|
|
|
|
+ successCount++;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ resultData.put("id", "");
|
|
|
|
+ resultData.put("errors", e.getMessage());
|
|
|
|
+ resultData.put("billStatus", false);
|
|
|
|
+ logger.error(ExceptionUtils.getExceptionStackTraceMessage(e));
|
|
|
|
+ failCount++;
|
|
|
|
+ }
|
|
|
|
+ resultDatas.add(resultData);
|
|
|
|
+ }
|
|
|
|
+ resultDatasMap.put("failCount",failCount);
|
|
|
|
+ resultDatasMap.put("successCount",successCount);
|
|
|
|
+ resultDatasMap.put("result",resultDatas);
|
|
|
|
+ customApiResult.setData(resultDatasMap);
|
|
|
|
+ if(failCount>0) {
|
|
|
|
+ customApiResult.setStatus(false);
|
|
|
|
+ customApiResult.setErrorCode("603");
|
|
|
|
+ }else{
|
|
|
|
+ customApiResult.setStatus(true);
|
|
|
|
+ customApiResult.setErrorCode("0");
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ customApiResult.setStatus(false);
|
|
|
|
+ customApiResult.setMessage(e.getMessage());
|
|
|
|
+ customApiResult.setErrorCode("400");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return customApiResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void createMasterData(Map newDatas, String entityName, Map resultData) throws ParseException {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ long materialId = DB.genLongId("T_BD_MATERIAL");
|
|
|
|
+ Map<String, OperationApiVo> errorMap = null;
|
|
|
|
+ DynamicObject material = BusinessDataServiceHelper.newDynamicObject(entityName);
|
|
|
|
+ material.set("id", materialId);
|
|
|
|
+
|
|
|
|
+ setHeadValue(newDatas, material, resultData);
|
|
|
|
+ //数据状态
|
|
|
|
+ material.set("status", "A");
|
|
|
|
+ //使用状态
|
|
|
|
+ material.set("enable", "1");
|
|
|
|
+
|
|
|
|
+ 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 = material.getString("status");
|
|
|
|
+ if ("A".equals(status)) {//暂存,走正常逻辑
|
|
|
|
+ doAddNew(resultData, material);
|
|
|
|
+ if (resultData.get("errors") == null) {
|
|
|
|
+ generateMaterialBizInfo(material,newDatas,resultData);
|
|
|
|
+ if (resultData.get("errors") != null && !"".equals(resultData.get("errors"))) {
|
|
|
|
+ if(!((Boolean)resultData.get("billStatus"))) {
|
|
|
|
+ throw new KDBizException(resultData.get("errors").toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void generateMaterialBizInfo(DynamicObject material, Map newDatas, Map resultData) throws ParseException {
|
|
|
|
+ //采购信息
|
|
|
|
+ if (newDatas.get("bd_materialpurchaseinfo") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("bd_materialpurchaseinfo");
|
|
|
|
+ initMaterialBizInfoByMaterial(mapEntrys, resultData, material,"bd_materialpurchaseinfo");
|
|
|
|
+ } else {
|
|
|
|
+ resultData.put("errors", "参数【bd_materialpurchaseinfo】必填");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //销售信息
|
|
|
|
+ if (newDatas.get("bd_materialsalinfo") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("bd_materialsalinfo");
|
|
|
|
+ initMaterialBizInfoByMaterial(mapEntrys, resultData, material,"bd_materialsalinfo");
|
|
|
|
+ } else {
|
|
|
|
+ resultData.put("errors", "参数【bd_materialsalinfo】必填");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //库存信息
|
|
|
|
+ if (newDatas.get("bd_materialinventoryinfo") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("bd_materialinventoryinfo");
|
|
|
|
+ initMaterialBizInfoByMaterial(mapEntrys, resultData, material,"bd_materialinventoryinfo");
|
|
|
|
+ } else {
|
|
|
|
+ resultData.put("errors", "参数【bd_materialinventoryinfo】必填");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //子码信息
|
|
|
|
+ if (newDatas.get("pznm_materialzm") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("pznm_materialzm");
|
|
|
|
+ initMaterialZMByMaterial(mapEntrys, resultData, material);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void initMaterialBizInfoByMaterial(List<Map> mapEntrys, Map resultData,DynamicObject material,String bizInfoFormId) throws ParseException {
|
|
|
|
+ logger.info("initMaterialBizInfoByMaterial, materialList size:" + mapEntrys.size() + ",bizInfoFormId:" + bizInfoFormId);
|
|
|
|
+ List<String> createOrgs = (List)mapEntrys.stream().map((m) -> {
|
|
|
|
+ return m.get("createorg_number");
|
|
|
|
+ }).distinct().collect(Collectors.toList());
|
|
|
|
+ List<String> selectFields =BusinessDataServiceHelper.newDynamicObject(bizInfoFormId).getDataEntityType().getProperties().stream().map(IMetadata:: getName).collect(Collectors.toList());
|
|
|
|
+ QFilter materialfilter=new QFilter("masterid",QCP.equals,material.getPkValue());
|
|
|
|
+ QFilter orgfilter=new QFilter("createorg.number",QCP.in,createOrgs);
|
|
|
|
+ DynamicObject[] findbizInfoForm=BusinessDataServiceHelper.load(bizInfoFormId, StringUtils.join(selectFields.toArray(), ','),new QFilter[]{materialfilter,orgfilter});
|
|
|
|
+
|
|
|
|
+ //查询过滤条件,缓存存在的字码Map记录
|
|
|
|
+ Map isHaveOrgs_number = new HashMap();
|
|
|
|
+ for(DynamicObject obj : findbizInfoForm){
|
|
|
|
+ DynamicObject org = obj.getDynamicObject("createorg");
|
|
|
|
+ isHaveOrgs_number.put(org.getString("number"),obj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //区分并拼接需更新和新增的记录
|
|
|
|
+ DynamicObjectCollection add_entrys = new DynamicObjectCollection();
|
|
|
|
+ DynamicObjectCollection update_entrys = new DynamicObjectCollection();
|
|
|
|
+ for(Map mapEntry : mapEntrys){
|
|
|
|
+ String orgNum = mapEntry.get("createorg_number").toString();
|
|
|
|
+ if(isHaveOrgs_number.get(orgNum)!=null && !"".equals(isHaveOrgs_number.get(orgNum))) {
|
|
|
|
+ //已存在,缓存修改对象
|
|
|
|
+ DynamicObject materialBizInfo = (DynamicObject) isHaveOrgs_number.get(orgNum);
|
|
|
|
+ //管控方式
|
|
|
|
+ WebApiUtils.setTextField(true, "ctrlstrategy", "ctrlstrategy", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //创建人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "creator_number", "creator", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建时间
|
|
|
|
+ WebApiUtils.setDateField(true, "createtime", "createtime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "modifier_number", "modifier", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改时间
|
|
|
|
+ WebApiUtils.setDateField(true, "modifytime", "modifytime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //审核人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "auditor_number", "auditor", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核时间
|
|
|
|
+ WebApiUtils.setDateField(true, "audittime", "audittime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"modifier_number","pznm_modifier_xh","bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"auditor_number","pznm_auditor_xh","bos_user",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //使用状态
|
|
|
|
+ WebApiUtils.setTextField(true, "enable", "enable", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ if(null !=mapEntry.get("enable") && "0".equals(mapEntry.get("enable"))){
|
|
|
|
+ //禁用人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "modifier_number", "disabler", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //禁用时间
|
|
|
|
+ WebApiUtils.setDateField(true, "modifytime", "disabledate", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ("bd_materialinventoryinfo".equals(bizInfoFormId)) {
|
|
|
|
+ materialBizInfo.set("inventoryunit", material.get("baseunit"));
|
|
|
|
+ materialBizInfo.set("baseunit", material.get("baseunit"));
|
|
|
|
+
|
|
|
|
+ //允许负库存
|
|
|
|
+ WebApiUtils.setBooleanField(false, "isallowneginv", "isallowneginv", false, mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //启用批号管理
|
|
|
|
+ WebApiUtils.setBooleanField(true, "enablelot", "enablelot", true, mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //保质期管理
|
|
|
|
+ WebApiUtils.setBooleanField(true, "enableshelflifemgr", "enableshelflifemgr", true, mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //保质期单位
|
|
|
|
+ WebApiUtils.setTextField(true, "shelflifeunit", "shelflifeunit", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //提前期单位
|
|
|
|
+ WebApiUtils.setTextField(true, "shelflifeunit", "leadtimeunit", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //计算方向
|
|
|
|
+ materialBizInfo.set("caldirection","4");
|
|
|
|
+ //保质期
|
|
|
|
+ WebApiUtils.setTextField(true, "shelflife", "shelflife", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ } else if ("bd_materialpurchaseinfo".equals(bizInfoFormId)) {
|
|
|
|
+ materialBizInfo.set("purchaseunit", material.get("baseunit"));
|
|
|
|
+ } else if ("bd_materialsalinfo".equals(bizInfoFormId)) {
|
|
|
|
+ materialBizInfo.set("salesunit", material.get("baseunit"));
|
|
|
|
+ }
|
|
|
|
+ update_entrys.add(materialBizInfo);
|
|
|
|
+ }else{
|
|
|
|
+ //不存在,缓存新增对象
|
|
|
|
+ DynamicObject materialBizInfo = BusinessDataServiceHelper.newDynamicObject(bizInfoFormId);
|
|
|
|
+
|
|
|
|
+ materialBizInfo.set("masterid", material);
|
|
|
|
+ //管控方式
|
|
|
|
+ WebApiUtils.setTextField(true, "ctrlstrategy", "ctrlstrategy", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ materialBizInfo.set("status", StatusEnum.SAVE.getCode());
|
|
|
|
+ materialBizInfo.set("enable", EnableEnum.ENABLE.getCode());
|
|
|
|
+ //创建人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "creator_number", "creator", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建时间
|
|
|
|
+ WebApiUtils.setDateField(true, "createtime", "createtime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "modifier_number", "modifier", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改时间
|
|
|
|
+ WebApiUtils.setDateField(true, "modifytime", "modifytime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "auditor_number", "auditor", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核时间
|
|
|
|
+ WebApiUtils.setDateField(true, "audittime", "audittime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"modifier_number","pznm_modifier_xh","bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"auditor_number","pznm_auditor_xh","bos_user",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建组织
|
|
|
|
+ WebApiUtils.setDynamicField(true, "createorg_number", "createorg", "bos_org", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ if ("bd_materialinventoryinfo".equals(bizInfoFormId)) {
|
|
|
|
+ materialBizInfo.set("inventoryunit", material.get("baseunit"));
|
|
|
|
+ materialBizInfo.set("baseunit", material.get("baseunit"));
|
|
|
|
+
|
|
|
|
+ //允许负库存
|
|
|
|
+ WebApiUtils.setBooleanField(false, "isallowneginv", "isallowneginv", false, mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //启用批号管理
|
|
|
|
+ WebApiUtils.setBooleanField(true, "enablelot", "enablelot", true, mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //保质期管理
|
|
|
|
+ WebApiUtils.setBooleanField(true, "enableshelflifemgr", "enableshelflifemgr", true, mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //保质期单位
|
|
|
|
+ WebApiUtils.setTextField(true, "shelflifeunit", "shelflifeunit", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //提前期单位
|
|
|
|
+ WebApiUtils.setTextField(true, "shelflifeunit", "leadtimeunit", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //计算方向
|
|
|
|
+ materialBizInfo.set("caldirection","4");
|
|
|
|
+ //保质期
|
|
|
|
+ WebApiUtils.setTextField(true, "shelflife", "shelflife", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ } else if ("bd_materialpurchaseinfo".equals(bizInfoFormId)) {
|
|
|
|
+ materialBizInfo.set("purchaseunit", material.get("baseunit"));
|
|
|
|
+ } else if ("bd_materialsalinfo".equals(bizInfoFormId)) {
|
|
|
|
+ materialBizInfo.set("salesunit", material.get("baseunit"));
|
|
|
|
+ }
|
|
|
|
+ //数据状态
|
|
|
|
+ materialBizInfo.set("status","A");
|
|
|
|
+ //使用状态
|
|
|
|
+ materialBizInfo.set("enable","1");
|
|
|
|
+ add_entrys.add(materialBizInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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", bizInfoFormId,
|
|
|
|
+ real_add_entrys, OperateOption.create());
|
|
|
|
+ if (result_submit.isSuccess()) {
|
|
|
|
+ OperationResult result_audit = OperationServiceHelper.executeOperate("audit", bizInfoFormId,
|
|
|
|
+ real_add_entrys, OperateOption.create());
|
|
|
|
+ if (!result_audit.isSuccess()) {
|
|
|
|
+ resultData.put("errors", bizInfoFormId+"审核失败");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ resultData.put("errors", bizInfoFormId+"创建失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void initMaterialZMByMaterial(List<Map> mapEntrys, Map resultData,DynamicObject material) throws ParseException {
|
|
|
|
+ logger.info("initMaterialZMByMaterial, materialList size:" + mapEntrys.size());
|
|
|
|
+ //拼接组织+字码编码的过滤条件
|
|
|
|
+ List<String> zmnumbers = new ArrayList<String>();
|
|
|
|
+ List<String> orgnumbers = new ArrayList<String>();
|
|
|
|
+ for(Map mapEntry : mapEntrys){
|
|
|
|
+ zmnumbers.add(mapEntry.get("number").toString());
|
|
|
|
+ orgnumbers.add(mapEntry.get("pznm_zmet_org_number").toString());
|
|
|
|
+ }
|
|
|
|
+ List<String> selectFields =BusinessDataServiceHelper.newDynamicObject("pznm_materialzm").getDataEntityType().getProperties().stream().map(IMetadata:: getName).collect(Collectors.toList());
|
|
|
|
+ QFilter materialfilter=new QFilter("pznm_material",QCP.equals,material.getPkValue());
|
|
|
|
+ QFilter orgfilter=new QFilter("pznm_zmet_org.number",QCP.in,orgnumbers);
|
|
|
|
+ QFilter numberfilter=new QFilter("number",QCP.in,zmnumbers);
|
|
|
|
+ DynamicObject[] findbizInfoForm=BusinessDataServiceHelper.load("pznm_materialzm", StringUtils.join(selectFields.toArray(), ','),new QFilter[]{materialfilter,orgfilter,numberfilter});
|
|
|
|
+
|
|
|
|
+ //查询过滤条件,缓存存在的字码Map记录
|
|
|
|
+ Map isHaveOrgs_number = new HashMap();
|
|
|
|
+ for(DynamicObject obj : findbizInfoForm){
|
|
|
|
+ DynamicObject org = obj.getDynamicObject("pznm_zmet_org");
|
|
|
|
+ String org_zmnumber = org.getString("number")+"_"+obj.getString("number");
|
|
|
|
+ isHaveOrgs_number.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("number").toString();
|
|
|
|
+ if(isHaveOrgs_number.get(org_zmnumber)!=null && !"".equals(isHaveOrgs_number.get(org_zmnumber))){
|
|
|
|
+ //已存在,缓存修改对象
|
|
|
|
+ DynamicObject materialBizInfo = (DynamicObject) isHaveOrgs_number.get(org_zmnumber);
|
|
|
|
+ //子码编码
|
|
|
|
+ WebApiUtils.setTextField(true,"number","number",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //子码名称
|
|
|
|
+ WebApiUtils.setTextField(true,"name","name",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //老系统编码
|
|
|
|
+ WebApiUtils.setTextField(false,"pznm_oldnumber","pznm_oldnumber",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "creator_number", "creator", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建时间
|
|
|
|
+ WebApiUtils.setDateField(true, "createtime", "createtime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "modifier_number", "modifier", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改时间
|
|
|
|
+ WebApiUtils.setDateField(true, "modifytime", "modifytime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"modifier_number","pznm_modifier_xh","bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //审核人
|
|
|
|
+ //WebApiUtils.setDynamicField(true, "auditor_number", "auditor", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核时间
|
|
|
|
+ //WebApiUtils.setDateField(true, "audittime", "audittime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //使用状态
|
|
|
|
+ WebApiUtils.setTextField(true, "enable", "enable", mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ update_entrys.add(materialBizInfo);
|
|
|
|
+ }else{
|
|
|
|
+ //不存在,缓存新增对象
|
|
|
|
+ DynamicObject materialBizInfo = BusinessDataServiceHelper.newDynamicObject("pznm_materialzm");
|
|
|
|
+
|
|
|
|
+ //materialBizInfo.set("masterid", material);
|
|
|
|
+ materialBizInfo.set("pznm_material", material);
|
|
|
|
+
|
|
|
|
+ materialBizInfo.set("status", StatusEnum.SAVE.getCode());
|
|
|
|
+ materialBizInfo.set("enable", EnableEnum.ENABLE.getCode());
|
|
|
|
+ //子码编码
|
|
|
|
+ WebApiUtils.setTextField(true,"number","number",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //子码名称
|
|
|
|
+ WebApiUtils.setTextField(true,"name","name",mapEntry, resultData, materialBizInfo);
|
|
|
|
+
|
|
|
|
+ //老系统编码
|
|
|
|
+ WebApiUtils.setTextField(false,"pznm_oldnumber","pznm_oldnumber",mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "creator_number", "creator", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建时间
|
|
|
|
+ WebApiUtils.setDateField(true, "createtime", "createtime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "modifier_number", "modifier", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改时间
|
|
|
|
+ WebApiUtils.setDateField(true, "modifytime", "modifytime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"modifier_number","pznm_modifier_xh","bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核人
|
|
|
|
+ //WebApiUtils.setDynamicField(true, "auditor_number", "auditor", "bos_user", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //审核时间
|
|
|
|
+ // WebApiUtils.setDateField(true, "audittime", "audittime", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //创建组织
|
|
|
|
+ WebApiUtils.setDynamicField(true, "pznm_zmet_org_number", "pznm_zmet_org", "bos_org", mapEntry, resultData, materialBizInfo);
|
|
|
|
+ //数据状态
|
|
|
|
+ materialBizInfo.set("status","A");
|
|
|
|
+ //使用状态
|
|
|
|
+ materialBizInfo.set("enable","1");
|
|
|
|
+ add_entrys.add(materialBizInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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_materialzm",
|
|
|
|
+ real_add_entrys, OperateOption.create());
|
|
|
|
+ if (result_submit.isSuccess()) {
|
|
|
|
+ OperationResult result_audit = OperationServiceHelper.executeOperate("audit", "pznm_materialzm",
|
|
|
|
+ real_add_entrys, OperateOption.create());
|
|
|
|
+ if (!result_audit.isSuccess()) {
|
|
|
|
+ resultData.put("errors", "pznm_materialzm"+"审核失败");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ resultData.put("errors", "pznm_materialzm"+"创建失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void doAddNew(Map resultData, DynamicObject material) {
|
|
|
|
+ OperationResult result_submit = OperationServiceHelper.executeOperate("submit", "bd_customer",
|
|
|
|
+ new DynamicObject[]{material}, OperateOption.create());
|
|
|
|
+ if (result_submit.isSuccess()) {
|
|
|
|
+ OperationResult result_audit = OperationServiceHelper.executeOperate("audit", "bd_customer",
|
|
|
|
+ new DynamicObject[]{material}, OperateOption.create());
|
|
|
|
+ //执行客户对应组织分配
|
|
|
|
+ if (result_audit.isSuccess()) {//保存客户成功
|
|
|
|
+ resultData.put("errors", null);
|
|
|
|
+ resultData.put("id", result_audit.getSuccessPkIds().get(0));
|
|
|
|
+ resultData.put("billStatus", true);
|
|
|
|
+ } 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++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置单据头字段
|
|
|
|
+ *
|
|
|
|
+ * @param newDatas
|
|
|
|
+ * @param material
|
|
|
|
+ * @param resultData
|
|
|
|
+ */
|
|
|
|
+ private void setHeadValue(Map newDatas, DynamicObject material, Map resultData) throws ParseException {
|
|
|
|
+ //物料编码
|
|
|
|
+ WebApiUtils.setTextField(true, "number", "number", newDatas, resultData, material);
|
|
|
|
+ //物料名称
|
|
|
|
+ WebApiUtils.setTextField(true, "name", "name", newDatas, resultData, material);
|
|
|
|
+ //规格型号
|
|
|
|
+ WebApiUtils.setTextField(true, "modelnum", "modelnum", newDatas, resultData, material);
|
|
|
|
+ //基本单位.编码
|
|
|
|
+ WebApiUtils.setDynamicField(true, "baseunit_number", "baseunit", "bd_measureunits", newDatas, resultData, material);
|
|
|
|
+ //创建人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "creator_number", "creator", "bos_user", newDatas, resultData, material);
|
|
|
|
+ //创建时间
|
|
|
|
+ WebApiUtils.setDateField(true, "createtime", "createtime", newDatas, resultData, material);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "modifier_number", "modifier", "bos_user", newDatas, resultData, material);
|
|
|
|
+ //修改时间
|
|
|
|
+ WebApiUtils.setDateField(true, "modifytime", "modifytime", newDatas, resultData, material);
|
|
|
|
+ //审核人
|
|
|
|
+ WebApiUtils.setDynamicField(true, "auditor_number", "approverid", "bos_user", newDatas, resultData, material);
|
|
|
|
+ //审核时间
|
|
|
|
+ WebApiUtils.setDateField(true, "audittime", "approvedate", newDatas, resultData, material);
|
|
|
|
+ //修改人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"modifier_number","pznm_modifier_xh","bos_user", newDatas, resultData, material);
|
|
|
|
+ //审核人
|
|
|
|
+ WebApiUtils.setDynamicField(true,"auditor_number","pznm_auditor_xh","bos_user",newDatas, resultData, material);
|
|
|
|
+ //创建组织
|
|
|
|
+ WebApiUtils.setDynamicField(true, "createorg_number", "createorg", "bos_org", newDatas, resultData, material);
|
|
|
|
+ //控制策略
|
|
|
|
+ material.set("ctrlstrategy", 5);
|
|
|
|
+ //物料类型
|
|
|
|
+ //物资 1
|
|
|
|
+ // 费用 7
|
|
|
|
+ // 资产 8
|
|
|
|
+ // 服务 9
|
|
|
|
+ // 套件 3
|
|
|
|
+ // 虚拟件 2
|
|
|
|
+ // 可配置件 4
|
|
|
|
+ // 特征件 5
|
|
|
|
+ WebApiUtils.setTextField(true, "materialtype", "materialtype", newDatas, resultData, material);
|
|
|
|
+ //可采购
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enablepur", "enablepur", true, newDatas, resultData, material);
|
|
|
|
+ //可销售
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enablesale", "enablesale", true, newDatas, resultData, material);
|
|
|
|
+ //可库存
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enableinv", "enableinv", true, newDatas, resultData, material);
|
|
|
|
+ //可生产
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enableproduct", "enableproduct", true, newDatas, resultData, material);
|
|
|
|
+ //可资产
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enableasset", "enableasset", true, newDatas, resultData, material);
|
|
|
|
+ //可委外
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enableoutsource", "enableoutsource", true, newDatas, resultData, material);
|
|
|
|
+ //可受托
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enabletrustee", "enabletrustee", true, newDatas, resultData, material);
|
|
|
|
+ //可寄售
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enableconsign", "enableconsign", true, newDatas, resultData, material);
|
|
|
|
+ //可VMI
|
|
|
|
+ WebApiUtils.setBooleanField(false, "enablevmi", "enablevmi", true, newDatas, resultData, material);
|
|
|
|
+ //助记码
|
|
|
|
+ WebApiUtils.setTextField(false, "number", "number", newDatas, resultData, material);
|
|
|
|
+ //旧物料编码
|
|
|
|
+ WebApiUtils.setTextField(false, "oldnumber", "oldnumber", newDatas, resultData, material);
|
|
|
|
+ //描述
|
|
|
|
+ WebApiUtils.setTextField(false, "description", "description", newDatas, resultData, material);
|
|
|
|
+ //默认税率
|
|
|
|
+ WebApiUtils.setDynamicField(false, "taxrate_number", "taxrate", "bd_taxrate", newDatas, resultData, material);
|
|
|
|
+ //启用辅助属性
|
|
|
|
+ WebApiUtils.setBooleanField(true, "isuseauxpty", "isuseauxpty", true, newDatas, resultData, material);
|
|
|
|
+ //开启辅助属性
|
|
|
|
+ if (null != newDatas.get("isuseauxpty") && "1".equals(newDatas.get("isuseauxpty"))) {
|
|
|
|
+ //辅助属性
|
|
|
|
+ if (newDatas.get("auxptyentry") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("auxptyentry");
|
|
|
|
+ doSetAuxptyentryEntry(mapEntrys, resultData, material);
|
|
|
|
+ } else {
|
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
|
+ resultData.put("errors", errors+"参数【auxptyentry】必填");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //物料分类
|
|
|
|
+ if (newDatas.get("entry_groupstandard") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("entry_groupstandard");
|
|
|
|
+ doSetGroupEntry(mapEntrys, resultData, material);
|
|
|
|
+ } else {
|
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
|
+ resultData.put("errors", errors+"参数【entry_groupstandard】必填");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //业务属性
|
|
|
|
+ if (newDatas.get("serviceattribute") != null) {
|
|
|
|
+ List<Map> mapEntrys = (List<Map>) newDatas.get("serviceattribute");
|
|
|
|
+ doSetServiceattributeEntry(mapEntrys, resultData, material);
|
|
|
|
+ } else {
|
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
|
+ resultData.put("errors", errors+"参数【serviceattribute】必填");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 填充多选基础资料,业务属性
|
|
|
|
+ *
|
|
|
|
+ * @param mapEntrys
|
|
|
|
+ * @param resultData
|
|
|
|
+ * @param material
|
|
|
|
+ */
|
|
|
|
+ private void doSetServiceattributeEntry(List<Map> mapEntrys, Map resultData, DynamicObject material) {
|
|
|
|
+ DynamicObjectCollection serviceattributeCol = material.getDynamicObjectCollection("serviceattribute");
|
|
|
|
+ serviceattributeCol.clear();
|
|
|
|
+ for (Map mapEntry : mapEntrys) {
|
|
|
|
+ if (null != mapEntry.get("number") && null != mapEntry.get("entity_number")) {
|
|
|
|
+ QFilter qFilter_number = new QFilter("number", QCP.equals, mapEntry.get("number"));
|
|
|
|
+ QFilter qFilter_entity_number = new QFilter("entity.number", QCP.equals, mapEntry.get("entity_number"));
|
|
|
|
+ QFilter qFilter_enable = new QFilter("enable", QCP.equals, "1");
|
|
|
|
+ QFilter qFilter_status = new QFilter("status", QCP.equals, "C");
|
|
|
|
+ DynamicObject objCol = BusinessDataServiceHelper.loadSingleFromCache("bd_serviceattribute", "id,number,name,entity",
|
|
|
|
+ new QFilter[]{qFilter_number, qFilter_entity_number, qFilter_enable, qFilter_status});
|
|
|
|
+ if (objCol != null) {
|
|
|
|
+ DynamicObject serviceattributeObj = serviceattributeCol.addNew();
|
|
|
|
+ serviceattributeObj.set("fbasedataid", objCol);
|
|
|
|
+ } else {
|
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
|
+ resultData.put("errors", errors+"参数【serviceattribute】值匹配不成功,可能的原因是:1、编码不正确;2、不符合基础资料字段查询条件");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String errors = resultData.get("errors")!=null?resultData.get("errors").toString()+";":"";
|
|
|
|
+ resultData.put("errors", errors+"参数【serviceattribute】中 【number】【entity_number】必填");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 填充辅助属性
|
|
|
|
+ *
|
|
|
|
+ * @param mapEntrys
|
|
|
|
+ * @param resultData
|
|
|
|
+ * @param material
|
|
|
|
+ */
|
|
|
|
+ private void doSetAuxptyentryEntry(List<Map> mapEntrys, Map resultData, DynamicObject material) {
|
|
|
|
+ DynamicObjectCollection entrys = material.getDynamicObjectCollection("auxptyentry");
|
|
|
|
+ entrys.clear();
|
|
|
|
+ for (Map mapEntry : mapEntrys) {
|
|
|
|
+ DynamicObject newEntry = new DynamicObject(entrys.getDynamicObjectType());
|
|
|
|
+ //辅助属性.编码
|
|
|
|
+ WebApiUtils.setDynamicField(true, "auxpty_number", "auxpty", "bd_auxproperty",
|
|
|
|
+ mapEntry, resultData, newEntry);
|
|
|
|
+ entrys.add(newEntry);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 填充分类
|
|
|
|
+ *
|
|
|
|
+ * @param mapEntrys
|
|
|
|
+ * @param resultData
|
|
|
|
+ * @param material
|
|
|
|
+ */
|
|
|
|
+ private void doSetGroupEntry(List<Map> mapEntrys, Map resultData, DynamicObject material) {
|
|
|
|
+ DynamicObjectCollection entrys = material.getDynamicObjectCollection("entry_groupstandard");
|
|
|
|
+ entrys.clear();
|
|
|
|
+ for (Map mapEntry : mapEntrys) {
|
|
|
|
+ DynamicObject newEntry = new DynamicObject(entrys.getDynamicObjectType());
|
|
|
|
+ //分类标准.编码
|
|
|
|
+ WebApiUtils.setDynamicField(true, "standardid_number", "standardid", "bd_materialgroupstandard",
|
|
|
|
+ mapEntry, resultData, newEntry);
|
|
|
|
+ //分类.编码
|
|
|
|
+ WebApiUtils.setDynamicField(true, "groupid_number", "groupid", "bd_materialgroup",
|
|
|
|
+ mapEntry, resultData, newEntry);
|
|
|
|
+ entrys.add(newEntry);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void updateMasterData(Long id, Map updateData, String entityName, Map resultData) throws ParseException {
|
|
|
|
+ Map<String, OperationApiVo> resultMap = null;
|
|
|
|
+ DynamicObjectType dynamicObjectType = BusinessDataServiceHelper.newDynamicObject(entityName).getDynamicObjectType();
|
|
|
|
+ DynamicObject material = BusinessDataServiceHelper.loadSingle(id, dynamicObjectType);
|
|
|
|
+ setHeadValue(updateData, material, resultData);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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 = material.getString("status");
|
|
|
|
+ if ("A".equals(status)) {//暂存,走正常逻辑
|
|
|
|
+ doAddNew(resultData, material);
|
|
|
|
+ } else if ("C".equals(status)) {//审核
|
|
|
|
+ SaveServiceHelper.update(material);
|
|
|
|
+ resultData.put("errors", null);
|
|
|
|
+ resultData.put("id", material.getPkValue());
|
|
|
|
+ resultData.put("billStatus", true);
|
|
|
|
+ }
|
|
|
|
+ generateMaterialBizInfo(material,updateData,resultData);
|
|
|
|
+ if (resultData.get("errors") != null && !"".equals(resultData.get("errors"))) {
|
|
|
|
+ if(!((Boolean)resultData.get("billStatus"))) {
|
|
|
|
+ throw new KDBizException(resultData.get("errors").toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resultData.put("errors", null);
|
|
|
|
+ resultData.put("id", material.getPkValue());
|
|
|
|
+ resultData.put("billStatus", true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void forceSetStatusAndEnable(Map jsonObj) {
|
|
|
|
+ if (jsonObj != null) {
|
|
|
|
+ jsonObj.put("status", StatusEnum.SAVE.getCode());
|
|
|
|
+ jsonObj.put("enable", EnableEnum.ENABLE.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|