From a6e6575bc3d668e14009ed0e931a376f1a4d86ff Mon Sep 17 00:00:00 2001 From: yuxc <653031404@qq.com> Date: 星期六, 06 五月 2023 18:59:29 +0800 Subject: [PATCH] 编码管理代码上传 --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java | 779 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 779 insertions(+), 0 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java new file mode 100644 index 0000000..0f9d00c --- /dev/null +++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java @@ -0,0 +1,779 @@ +package com.vci.ubcs.code.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.common.utils.StringUtils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.sun.corba.se.impl.orbutil.ObjectUtility; +import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO; +import com.vci.ubcs.code.dto.CodeOrderDTO; +import com.vci.ubcs.code.dto.datapush.BaseModelDTO; +import com.vci.ubcs.code.entity.CodeAllCode; +import com.vci.ubcs.code.entity.CodeOsbtmtypeEntity; +import com.vci.ubcs.code.entity.CodeRule; +import com.vci.ubcs.code.entity.CodeWupinEntity; +import com.vci.ubcs.code.enumpack.CodeDefaultLC; +import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum; +import com.vci.ubcs.code.enumpack.CodeSecTypeEnum; +import com.vci.ubcs.code.mapper.CodeAllCodeMapper; +import com.vci.ubcs.code.mapper.CodeOsbtmtypeMapper; +import com.vci.ubcs.code.mapper.CodeRuleMapper; +import com.vci.ubcs.code.service.*; +import com.vci.ubcs.code.vo.CodeClstempattrVO; +import com.vci.ubcs.code.vo.CodeClstemplateVO; +import com.vci.ubcs.code.vo.CodeKeyattrrepeatVO; +import com.vci.ubcs.code.vo.pagemodel.CodeBasicSecVO; +import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO; +import com.vci.ubcs.code.vo.pagemodel.CodeRuleVO; +import com.vci.ubcs.omd.entity.Dict; +import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.revision.model.BaseModel; +import com.vci.ubcs.starter.web.enumpck.UserSecretEnum; +import com.vci.ubcs.starter.web.pagemodel.KeyValue; +import com.vci.ubcs.starter.web.toolmodel.DateConverter; +import com.vci.ubcs.starter.web.util.VciBaseUtil; +import com.vci.ubcs.starter.web.util.VciDateUtil; +import com.vci.ubcs.starter.web.util.VciQueryWrapperForDO; +import com.vci.ubcs.starter.web.util.WebUtil; +import com.vci.ubcs.system.entity.DictBiz; +import com.vci.ubcs.system.feign.IDictBizClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springblade.core.mp.support.Query; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.R; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.stream.Collectors; + +/** + * 涓绘暟鎹紩鎿庢湇鍔� + * + * @author weidy + * @date 2022-2-22 + */ +@Service +public class MdmEngineServiceImpl extends ServiceImpl<CodeAllCodeMapper, CodeAllCode> implements MdmEngineService { + + + /** + * 妯℃澘鐨勬湇鍔� + */ + @Resource + private CodeClstemplateServiceImpl templateService; + /** + * 妯℃澘鐨勬湇鍔� + */ + @Resource + private CodeOsbtmtypeMapper codeOsbtmtypeMapper; + /** + * 鐢熸垚缂栫爜鐨勬湇鍔� + */ + @Resource + private MdmProductCodeService productCodeService; + /** + * 瀛楀吀鐨勬湇鍔� + */ + @Resource + IDictBizClient iDictBizClient; + + /** + * 缂栫爜瑙勫垯鐨勬湇鍔� + */ + @Autowired + private ICodeRuleService ruleService; + + /** + * 鍒嗙被鐨勬湇鍔� + */ + @Resource + private ICodeClassifyService classifyService; + + /** + * 鍏抽敭灞炴�х殑閰嶇疆 + */ + @Autowired + private ICodeKeyattrrepeatService keyRuleService; + /** + * 鏃ュ織 + */ + private Logger logger = LoggerFactory.getLogger(getClass()); + +// @Autowired +// private CodeOsbtmtypeMapper codeOsbtmtypeMapper; + + + + /** + * 浣跨敤鍒嗙被鐨勪富閿幏鍙栧彲浠ヤ娇鐢ㄧ殑妯℃澘瀵硅薄 + * + * @param codeClassifyOid 鍒嗙被鐨勪富閿� + * @return 妯℃澘鐨勬樉绀哄璞� + */ + @Override + public CodeClstemplateVO getUsedTemplateByClassifyOid(String codeClassifyOid) { + return getUsedTemplateByClassifyOid(codeClassifyOid, true); + } + + /** + * 浣跨敤鍒嗙被鐨勪富閿幏鍙栧彲浠ヤ娇鐢ㄧ殑妯℃澘瀵硅薄 + * + * @param codeClassifyOid 鍒嗙被鐨勪富閿� + * @param hasAttr 鍖呭惈灞炴�� + * @return 妯℃澘鐨勬樉绀哄璞� + */ + @Override + public CodeClstemplateVO getUsedTemplateByClassifyOid(String codeClassifyOid, boolean hasAttr) { + List<CodeClstemplateVO> templateVOs = templateService.listReleaseTemplateByClassifyOid(codeClassifyOid, hasAttr); + return templateVOs.get(templateVOs.size() - 1); + } + + /** + * 鑾峰彇鏋氫妇鐨勪笅鎷夐�夐」 + * + * @param attrVO 妯℃澘灞炴�х殑瀵硅薄 + * @return 涓嬫媺閫夐」 + */ + @Override + public List<KeyValue> listComboboxItems(CodeClstempattrVO attrVO) { + List<KeyValue> comboboxKVs = null; + if (StringUtils.isNotBlank(attrVO.getEnumstring())) { + comboboxKVs = JSONObject.parseArray(attrVO.getEnumstring(), KeyValue.class); + } else { +// comboboxKVs = enumService.getEnum(attrVO.getEnumid()); +// Dict dict = new Dict(); +// dict.setParentId(Long.valueOf(attrVO.getEnumid())); + R<List<DictBiz>> list = iDictBizClient.getList(attrVO.getEnumid()); + if(list.isSuccess()){ + for (DictBiz datum : list.getData()) { + KeyValue keyValue = new KeyValue(); + keyValue.setKey(datum.getDictKey()); + keyValue.setValue(datum.getDictValue()); + comboboxKVs.add(keyValue); + } + } + } + return comboboxKVs; + } + /** + * 淇敼鐘舵�� + * + * @param baseModelDTO 鏁版嵁浼犺緭瀵硅薄 + */ + @Override + public void changeStatus(BaseModelDTO baseModelDTO) { + VciBaseUtil.alertNotNull(baseModelDTO, "鏁版嵁淇℃伅", baseModelDTO.getOid(), "涓婚敭", baseModelDTO.getBtmname(), "涓氬姟绫诲瀷", baseModelDTO.getLcStatus(), "鐩爣鐘舵��"); + List<String> oids = VciBaseUtil.str2List(baseModelDTO.getOid()); +// List<ClientBusinessObject> cboList = boService.selectCBOByOidCollection(oids, baseModelDTO.getBtmname()); + //鎻掍釜鐐� 涓氬姟绫诲瀷瀹屾垚鍚庨渶瑕佷慨鏀� + QueryWrapper<CodeOsbtmtypeEntity> wrapper = new QueryWrapper<>(); + wrapper.eq("BTMNAME",baseModelDTO.getBtmname()); + wrapper.in("OID",oids); + List<CodeOsbtmtypeEntity> cboList = codeOsbtmtypeMapper.selectList(wrapper); + //杩橀渶瑕佷慨鏀筧llCode鐨勭敓鍛藉懆鏈� +// Map<String, String> conditionMap = new HashMap<>(); + QueryWrapper<CodeAllCode> allCodeWrapper = new QueryWrapper<>(); + allCodeWrapper.eq("createcodebtm",baseModelDTO.getBtmname()); + allCodeWrapper.in("createcodeoid",oids); +// conditionMap.put("createcodeoid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")"); +// conditionMap.put("createcodebtm", baseModelDTO.getBtmname()); + List<CodeAllCode> codeCbos = baseMapper.selectList(allCodeWrapper); +// List<ClientBusinessObject> codeCbos = boService.queryCBO(MdmBtmTypeConstant.CODE_ALL_CODE, conditionMap); + // 鍥炴敹闇�瑕佷笟鍔℃暟鎹垹闄� +// if (CodeDefaultLC.TASK_BACK.getValue().equals(baseModelDTO.getLcStatus())) { +//// BatchCBO batchCBO = new BatchCBO(); +//// batchCBO.getDeleteCbos().addAll(cboList); +// codeOsbtmtypeMapper.deleteBatchIds(cboList); +//// boService.persistenceBatch(batchCBO); +// } else { +// lifeCycleService.transCboStatus(cboList, baseModelDTO.getLcStatus()); +// } +// lifeCycleService.transCboStatus(codeCbos, baseModelDTO.getLcStatus()); + } + + + /** + * 鐢宠鍗曚竴缂栫爜 + * + * @param orderDTO 鐢宠鐨勪俊鎭紝闇�瑕佸寘鍚睘鎬х殑鍐呭鍜岀爜娈电浉鍏崇殑鍐呭 + * @return 杩斿洖缂栫爜鐨勫唴瀹� + */ + @Override + public String addSaveCode(CodeOrderDTO orderDTO) { + VciBaseUtil.alertNotNull(orderDTO, "缂栫爜鐢宠鐩稿叧鐨勫睘鎬у拰鐮佹鐨勫唴瀹归兘涓虹┖", orderDTO.getCodeClassifyOid(), "涓婚搴撳垎绫荤殑涓婚敭", + orderDTO.getTemplateOid(), "妯℃澘鐨勪富閿�", orderDTO.getCodeRuleOid(), "缂栫爜瑙勫垯鐨勪富閿�"); + CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid()); + CodeClstemplateVO templateVO = templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid()); + CodeRuleVO ruleVO = ruleService.getObjectHasSecByOid(orderDTO.getCodeRuleOid()); + //1.鍒ゆ柇瑙勫垯涓櫎浜嗘祦姘寸爜娈碉紝鏄惁鏈夊叾浠栫爜娈� + checkSecValueOnOrder(ruleVO, orderDTO); + //2.鍒ゆ柇蹇呰緭椤� + checkRequiredAttrOnOrder(templateVO, orderDTO); + //3.鍏堟敞鍏ワ紝鍐嶇粍鍚堬紝鏈�鍚庢牎楠� + switchClassifyLevelOnOrder(templateVO, classifyFullInfo, orderDTO); + //4.澶勭悊缁勫悎瑙勫垯銆傜粍鍚堣鍒欎笉鑳戒娇鐢ㄧ紪鐮佺殑灞炴�э紝鍥犱负缂栫爜鐨勭敓鎴愬彲鑳芥槸闇�瑕佸睘鎬х殑 + switchComponentAttrOnOrder(templateVO, orderDTO); + //5.鏍¢獙瑙勫垯 + checkVerifyOnOrder(templateVO, orderDTO); + //6.鍏抽敭灞炴�� + checkKeyAttrOnOrder(classifyFullInfo, templateVO, orderDTO); + //7.鏋氫妇杞崲 + checkEnumOnOrder(templateVO, orderDTO); + //8.澶勭悊鏃堕棿鏍煎紡锛屽湪鏁版嵁搴撻噷闈笉璁烘槸瀛楃涓茶繕鏄棩鏈熸牸寮忥紝閮戒娇鐢ㄧ浉鍚岀殑鏍煎紡瀛樺偍 + switchDateAttrOnOrder(templateVO, orderDTO); + //9.鐢熸垚缂栫爜鐨勪俊鎭� +// ClientBusinessObject cbo = boService.createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()); +// CodeWupinEntity cbo = createCBOByBtmName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()); +// //榛樿鐨勫睘鎬ч兘涓嶇敤浠庡墠绔嫹璐� +// //璁剧疆缂栫爜闇�瑕佺殑榛樿灞炴�х殑鍐呭 +// copyValueToCBO(classifyFullInfo, cbo, orderDTO, templateVO, false); +// //TODO:鍥犱负榛樿鐨勫睘鎬ч兘涓嶆嫹璐濓紝鐩墠闆嗗洟鐮佸彨name锛屽苟娌℃湁浠嶥TO鎷疯礉鍒癱bo閲屻�傚鍔犱竴涓崟鐙鐞嗭紝浠ュ悗鍐嶇湅瑕佷笉瑕佽皟鏁� +// cbo.setName(orderDTO.getName() == null ? "" : orderDTO.getName()); +// //end -- modify by lihang @20220407 +// List<CodeWupinEntity> cboList = new ArrayList<>(); +// +// //澶囨敞 +// cbo.setDescription(orderDTO.getDescription()); +// +// cboList.add(cbo); +// List<String> codeList = productCodeService.productCodeAndSaveData(classifyFullInfo, templateVO, ruleVO, orderDTO.getSecDTOList(),cboList); +//// batchSaveSelectChar(templateVO, cboList); +// return codeList.size() > 0 ? codeList.get(0) : ""; + return null; + } + + /** + * 澶勭悊鍒嗙被娉ㄥ叆鐨勪俊鎭� + * + * @param templateVO 妯℃澘鐨勬樉绀哄璞★紝蹇呴』瑕佸悗妯℃澘鐨勫睘鎬� + * @param classifyFullInfoBO 鍒嗙被鐨勫叏璺緞 + * @param orderDTO 缂栫爜鐢宠鐨勪俊鎭� + */ + private void switchClassifyLevelOnOrder(CodeClstemplateVO templateVO, CodeClassifyFullInfoBO classifyFullInfoBO, CodeOrderDTO orderDTO) { + Map<String,CodeClstempattrVO> classifyAttrVOMap = templateVO.getAttributes().stream().filter( + s -> StringUtils.isNotBlank(s.getClassifyinvokeattr()) && StringUtils.isNotBlank(s.getClassifyinvokelevel()) + ).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + if (classifyFullInfoBO.getTopClassifyVO() == null) { + //闇�瑕侀噸鏂版煡璇竴涓嬶紝鍥犱负杩欎釜鏄寚瀹氱殑鍒嗙被杩涙潵鐨� + + } + if (!CollectionUtils.isEmpty(classifyAttrVOMap)) { + classifyAttrVOMap.forEach((attrId, attrVO) -> { + //鍒嗙被娉ㄥ叆鐨勭紪鍙锋垨鑰呭悕绉帮紝 + //灞傜骇鍖呭惈鎸囧畾灞傚拰鏈�灏忓眰 + CodeClassifyVO classifyVO = null; + if (!CodeLevelTypeEnum.MIN.getValue().equalsIgnoreCase(attrVO.getClassifyinvokelevel()) && !"min".equalsIgnoreCase(attrVO.getClassifyinvokelevel())) { + //鎸囧畾浜嗗眰绾х殑 + //娉ㄦ剰锛屽洜涓烘煡璇笂绾у垎绫诲嚭鏉ョ殑灞傜骇鏄�掑簭鐨勶紝鍗抽《灞傝妭鐐规槸鏈�澶х殑鍊� + List<CodeClassifyVO> classifyVOS = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> o2.getDataLevel().compareTo(o1.getDataLevel()))).collect(Collectors.toList()); + int level = VciBaseUtil.getInt(attrVO.getClassifyinvokelevel()); + if (classifyVOS.size() >= level && level > 0) { + classifyVO = classifyVOS.get(level - 1); + } + } else { + //褰撳墠鐨勫垎绫� + classifyVO = classifyFullInfoBO.getCurrentClassifyVO(); + } + if (classifyVO == null) { + //璇存槑灞傜骇鏈夎 + orderDTO.getData().put(attrId, "鍒嗙被鏍戜笂娌℃湁灞傜骇[" + attrVO.getClassifyinvokelevel() + "]"); + // classifyVO = classifyFullInfoBO.getCurrentClassifyVO(); + } else { + Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO); + String value = classifyDataMap.getOrDefault(attrVO.getClassifyinvokeattr(), ""); + orderDTO.getData().put(attrId, value); + } + }); + } + } + + + /** + * 鍒ゆ柇缂栫爜鐨勭爜娈垫槸鍚﹁緭鍏ユ垨鑰呴�夋嫨浜嗙爜鍊� + * + * @param ruleVO 瑙勫垯鐨勬樉绀哄璞� + * @param orderDTO 缂栫爜鐢宠鐨勫唴瀹� + */ + @Override + public void checkSecValueOnOrder(CodeRuleVO ruleVO, CodeOrderDTO orderDTO) { + List<String> unSerialSecOidList = ruleVO.getSecVOList().stream().filter( + s -> !(CodeSecTypeEnum.CODE_SERIAL_SEC.getValue().equalsIgnoreCase(s.getSecType()) + || CodeSecTypeEnum.CODE_ATTR_SEC.getValue().equalsIgnoreCase(s.getSecType()) + || CodeSecTypeEnum.CODE_DATE_SEC.getValue().equalsIgnoreCase(s.getSecType()) + || CodeSecTypeEnum.CODE_LEVEL_SEC.getValue().equalsIgnoreCase(s.getSecType()) + || VciBaseUtil.getBoolean(s.getNullableFlag())) + ).map(CodeBasicSecVO::getOid).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(unSerialSecOidList)) { + if (CollectionUtils.isEmpty(orderDTO.getSecDTOList())) { + throw new VciBaseException("闈炴祦姘寸爜娈�(鎴栬�呭繀杈撶爜娈碉級蹇呴』瑕佽緭鍏�(鎴栭�夋嫨)鐮佸��"); + } + if (orderDTO.getSecDTOList().stream().anyMatch(s -> !unSerialSecOidList.contains(s.getSecOid()) + && StringUtils.isBlank(s.getSecValue()))) { + throw new VciBaseException("闈炴祦姘寸爜娈�(鎴栬�呭繀杈撶爜娈碉級蹇呴』瑕佽緭鍏�(鎴栭�夋嫨)鐮佸��"); + } + } + } + + /** + * 鏍¢獙灞炴�ф槸鍚︿负蹇呰緭 + * + * @param templateVO 妯℃澘鐨勬樉绀哄璞★紝闇�瑕佸寘鍚ā鏉垮睘鎬� + * @param orderDTO 缂栫爜鐢宠鐨勪俊鎭� + */ + private void checkRequiredAttrOnOrder(CodeClstemplateVO templateVO, CodeOrderDTO orderDTO) { + Map<String, CodeClstempattrVO> requiredAttrMap = templateVO.getAttributes().stream().filter( + s -> VciBaseUtil.getBoolean(s.getRequireflag()) && StringUtils.isBlank(s.getComponentrule()) + && StringUtils.isBlank(s.getClassifyinvokeattr())) + .collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + if (!CollectionUtils.isEmpty(requiredAttrMap)) { + requiredAttrMap.forEach((attrId, attrVO) -> { + //鍙湁浼佷笟缂栫爜锛岀姸鎬侊紝澶囨敞锛屾ā鏉夸富閿紝鍒嗙被涓婚敭杩欏嚑涓槸鍥哄畾鐨勶紝鍏朵綑閮芥槸鑷閰嶇疆鐨� + if (StringUtils.isBlank(getValueFromOrderDTO(orderDTO, attrId))) { + throw new VciBaseException("灞炴�с�恵0}銆戝繀椤昏杈撳叆(閫夋嫨)鍐呭", new String[]{attrVO.getName()}); + } + }); + } + } + + /** + * 浠庣紪鐮佺敵璇蜂俊鎭璞′笂鑾峰彇鏌愪釜灞炴�х殑鍊� + * + * @param orderDTO 缂栫爜鐢宠瀵硅薄 + * @param attrId 灞炴�х殑缂栧彿 + * @return 鍊� + */ + private String getValueFromOrderDTO(CodeOrderDTO orderDTO, String attrId) { + attrId = attrId.toLowerCase(Locale.ROOT); + String value = null; + if (VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(attrId)) { + value = WebUtil.getStringValueFromObject(WebUtil.getValueFromField(WebUtil.getFieldForObject(attrId, orderDTO.getClass()).getName(), orderDTO)); + } else { + //璇存槑鏄嚜琛岄厤缃殑 + //鍓嶇蹇呴』瑕佷紶閫掑皬鍐欑殑灞炴�� + value = orderDTO.getData().getOrDefault(attrId, ""); + } + return value; + } + + /** + * 杞崲缁勫悎瑙勫垯鐨勫�� + * + * @param templateVO 妯℃澘鐨勬樉绀哄璞★紝闇�瑕佸寘鍚ā鏉垮睘鎬� + * @param orderDTO 缂栫爜鐢宠鐨勪俊鎭� + */ + private void switchComponentAttrOnOrder(CodeClstemplateVO templateVO, CodeOrderDTO orderDTO) { + Map<String, CodeClstempattrVO> compAttrVOMap = templateVO.getAttributes().stream().filter(s -> StringUtils.isNotBlank(s.getComponentrule())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + if (!CollectionUtils.isEmpty(compAttrVOMap)) { + Map<String, String> dataMap = WebUtil.objectToMapString(orderDTO); + + Map<String, String> dataLowMap = new HashMap<>(); + if (!CollectionUtils.isEmpty(dataMap)) { + dataMap.forEach((key, value) -> { + dataLowMap.put(key.toLowerCase(Locale.ROOT), value); + }); + } + dataLowMap.putAll(orderDTO.getData()); + compAttrVOMap.forEach((attrId, attrVO) -> { +// dataLowMap.put(attrId, formulaService.getValueByFormula(dataLowMap, attrVO.getComponentrule())); + }); + dataLowMap.forEach((key, value) -> { + setValueToOrderDTO(orderDTO, key, value); + }); + } + } + + + /** + * 璁剧疆鏂扮殑鍊煎埌鐢宠瀵硅薄涓� + * + * @param orderDTO 缂栫爜鐢宠瀵硅薄 + * @param attrId 灞炴�х殑缂栧彿 + * @param value 鍊� + */ + private void setValueToOrderDTO(CodeOrderDTO orderDTO, String attrId, String value) { + attrId = attrId.toLowerCase(Locale.ROOT); + if (VciQueryWrapperForDO.BASIC_FIELD_MAP.containsKey(attrId)) { + WebUtil.setValueToField(WebUtil.getFieldForObject(attrId, orderDTO.getClass()).getName(), orderDTO, value); + } else { + orderDTO.getData().put(attrId, value); + } + } + + /** + * 鏍¢獙姝e垯琛ㄨ揪寮忔槸鍚︽纭� + * + * @param templateVO 妯℃澘鐨勪俊鎭紝蹇呴』鍖呭惈灞炴�х殑鍐呭 + * @param orderDTO 缂栫爜鐢宠鐨勭浉鍏崇殑淇℃伅 + */ + private void checkVerifyOnOrder(CodeClstemplateVO templateVO, CodeOrderDTO orderDTO) { + Map<String, CodeClstempattrVO> verifyAttrVOMap = templateVO.getAttributes().stream().filter(s -> StringUtils.isNotBlank(s.getVerifyrule())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + if (!CollectionUtils.isEmpty(verifyAttrVOMap)) { + verifyAttrVOMap.forEach((attrId, attrVO) -> { + String value = getValueFromOrderDTO(orderDTO, attrId); + if (StringUtils.isNotBlank(value) && !value.matches(attrVO.getVerifyrule())) { + //鏍¢獙姝e垯琛ㄨ揪寮� + throw new VciBaseException("灞炴�{0}]鐨勫�间笉绗﹀悎鏍¢獙瑙勫垯鐨勮姹�", new String[]{attrVO.getName()}); + } + }); + } + } + + /** + * 鏍¢獙鍏抽敭灞炴�� + * + * @param classifyFullInfo 鍒嗙被鐨勫叏閮ㄤ俊鎭� + * @param templateVO 妯℃澘鐨勫唴瀹癸紝蹇呴』鍖呭惈妯℃澘灞炴�� + * @param orderDTO 缂栫爜鐢宠鐨勭浉鍏崇殑淇℃伅 + */ + private void checkKeyAttrOnOrder(CodeClassifyFullInfoBO classifyFullInfo, CodeClstemplateVO templateVO, CodeOrderDTO orderDTO) { + //鍏堣幏鍙栧叧閿睘鎬х殑瑙勫垯锛屼篃鍒╃敤缁ф壙鐨勬柟寮� + CodeKeyattrrepeatVO keyRuleVO = keyRuleService.getRuleByClassifyFullInfo(classifyFullInfo); + //娉ㄦ剰鐨勬槸keyRuleVO鍙兘涓虹┖锛岃〃绀轰笉浣跨敤瑙勫垯鎺у埗 + //鑾峰彇鎵�鏈夌殑鍏抽敭灞炴�� + Map<String, CodeClstempattrVO> ketAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyattrflag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + Map<String, String> conditionMap = new HashMap<>(); + boolean trimAll = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag()); + //鍏ㄩ儴鍘荤┖鐨勪紭鍏堢骇澶т簬鍘荤┖ + boolean trim = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorespaceflag()); + boolean ignoreCase = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorecaseflag()); + boolean ignoreWidth = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorewidthflag()); + ketAttrMap.forEach((attrId, attrVO) -> { + String value = getValueFromOrderDTO(orderDTO, attrId); + if (value == null) { + value = ""; + } +// wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap); + }); + + //娌℃湁闄愬埗鍒嗙被锛屼絾鏄竴涓ā鏉垮彧鍙兘鍦ㄤ竴涓笟鍔$被鍨嬮噷闈紝鎵�浠ョ洿鎺ユ煡璇㈣繖涓笟鍔$被鍨嬪嵆鍙� + +// if (!CollectionUtils.isEmpty(conditionMap)) { +// final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()) + " t where 1 = 1 "}; +// conditionMap.forEach((key, value) -> { +// sql[0] += " and " + key + " = " + value; +// }); +// if (StringUtils.isNotBlank(orderDTO.getOid())) { +// //淇敼鐨勬椂鍊欙紝闇�瑕佹帓闄よ嚜宸� +// sql[0] += " and oid != '" + orderDTO.getOid() + "'"; +// } else if (StringUtils.isNotBlank(orderDTO.getCopyFromVersion())) { +// sql[0] += " and oid != '" + orderDTO.getCopyFromVersion() + "'"; +// } +// sql[0] += " and islastR = '1' and islastV = '1' "; +// if (boService.queryCountBySql(sql[0], new HashMap<>()) > 0) { +// String ruleInfoMsg = keyRuleVO == null ? "" : "鏌ヨ瑙勫垯锛氬幓闄ょ┖鏍�--{0},蹇界暐澶у皬鍐�--{1},蹇界暐鍏ㄥ崐瑙�--{2},蹇界暐鍏ㄩ儴绌烘牸--{3}"; +// String[] objs = new String[]{trim ? "鏄�" : "鍚�", ignoreCase ? "鏄�" : "鍚�", ignoreWidth ? "鏄�" : "鍚�", trimAll ? "鏄�" : "鍚�"}; +// throw new VciBaseException("鏍规嵁鎮ㄥ~鍐欑殑鍏抽敭灞炴�х殑鍐呭锛岀粨鍚堝叧閿睘鎬ф煡璇㈣鍒欙紝鍙戠幇杩欎釜鏁版嵁宸茬粡鍦ㄧ郴缁熶腑瀛樺湪浜嗐�傝淇!銆�" + ruleInfoMsg, objs); +// } +// } + } + + /** + * 灏佽鍏抽敭灞炴�х殑鏌ヨ璇彞 + * + * @param value 褰撳墠鐨勫�� + * @param keyRuleVO 鍏抽敭灞炴�х殑鎺у埗瑙勫垯锛屽彲浠ヤ负绌� + * @param attrId 灞炴�х殑缂栧彿 + * @param trim 鏄惁鍘婚櫎绌烘牸 + * @param ignoreCase 鏄惁涓嶅尯鍒嗗ぇ灏忓啓 + * @param ignoreWidth 鏄惁蹇界暐鍏ㄥ崐瑙� + * @param trimAll 鏄惁蹇界暐鍏ㄩ儴绌烘牸 + * @param conditionMap 鏌ヨ鏉′欢 + */ +// @Override +// public void wrapperKeyAttrConditionMap(String value, CodeKeyattrrepeatVO keyRuleVO, String attrId, +// boolean trim, boolean ignoreCase, boolean ignoreWidth, +// boolean trimAll, Map<String, String> conditionMap) { +// boolean ignoreSpace = trim || trimAll; +// if (StringUtils.isBlank(value)) { +// //涓虹┖鐨勬椂鍊欙紝涓嶈兘鐢≦ueryOperation.ISNULL锛屽钩鍙颁笉鐭ラ亾鍟ユ椂鍊欎笉澶勭悊杩欑浜� +// conditionMap.put("t."+attrId, "null"); +// } else { +// if (keyRuleVO != null) { +// String queryKey = ""; +// String queryValue = ""; +// +// String temp = ""; +// if (ignoreCase && ignoreSpace && ignoreWidth) { +// //蹇界暐澶у皬鍐欙紝涓斿幓绌猴紝蹇界暐鍏ㄥ崐瑙� +// temp = (trimAll ? "REPLACE" : "TRIM") + "(UPPER(to_single_byte(%s)) " + (trimAll ? ",' ','')" : ")"); +// } else if (ignoreCase && ignoreSpace && !ignoreWidth) { +// //蹇界暐澶у皬鍐欍�佸幓绌恒�佷笉蹇界暐鍏ㄥ崐瑙� +// temp = (trimAll ? "REPLACE" : "TRIM") + "(UPPER(%s) " + (trimAll ? ",' ','')" : ")"); +// } else if (ignoreCase && !ignoreSpace && ignoreWidth) { +// //蹇界暐澶у皬鍐欍�佷笉鍘荤┖銆佸拷鐣ュ叏鍗婅 +// temp = "UPPER(to_single_byte(%s))"; +// } else if (!ignoreCase && ignoreSpace && ignoreWidth) { +// //涓嶅拷鐣ュぇ灏忓啓銆佸幓绌恒�佸拷鐣ュ叏鍗婅 +// temp = (trimAll ? "REPLACE" : "TRIM") + "(to_single_byte(%s) " + (trimAll ? ",' ','')" : ")"); +// } else if (ignoreCase && !ignoreSpace && !ignoreWidth) { +// //蹇界暐澶у皬鍐欍�佷笉鍘荤┖銆佷笉蹇界暐鍏ㄥ崐瑙� +// temp = "UPPER(%s)"; +// } else if (!ignoreCase && !ignoreCase && ignoreWidth) { +// //涓嶅拷鐣ュぇ灏忓啓銆佷笉鍘荤┖銆佸拷鐣ュ叏鍗婅 +// temp = "to_single_byte(%s)"; +// } else if (!ignoreCase && ignoreSpace && !ignoreWidth) { +// //涓嶅拷鐣ュぇ灏忓啓銆佸幓绌恒�佷笉蹇界暐鍏ㄥ崐瑙� +// temp = (trimAll ? "REPLACE" : "TRIM") + "(%s " + (trimAll ? ",' ','')" : ")"); +// } else if (!ignoreCase && !ignoreSpace && !ignoreWidth) { +// //涓嶅拷鐣ュぇ灏忓啓銆佷笉鍘荤┖銆佷笉蹇界暐鍏ㄥ崐瑙� +// temp = "%s"; +// } +// queryKey = String.format(temp, "t."+attrId); +// queryValue = String.format(temp, "'" + (trim ? value.trim() : value) + "'"); +// conditionMap.put(queryKey, queryValue); +// } else { +// //涓虹┖鐨勬椂鍊欎笉浠h〃涓嶆牎楠岋紝鍙槸涓嶅幓闄ょ浉鍏崇殑淇℃伅 +// conditionMap.put("t."+attrId, value); +// } +// } +// } + + /** + * 鏍¢獙鏋氫妇鐨勫唴瀹� + * + * @param templateVO 妯℃澘鐨勬樉绀哄璞★紝闇�瑕佸寘鍚睘鎬� + * @param orderDTO 缂栫爜鐢宠鐨勪俊鎭� + */ + private void checkEnumOnOrder(CodeClstemplateVO templateVO, CodeOrderDTO orderDTO) { + //濡傛灉鏋氫妇鍙互淇敼锛屽垯涓嶉渶瑕佹牎楠屾槸鍚︾鍚堟灇涓剧殑閫夐」 + + Map<String, CodeClstempattrVO> enumAttrVOMap = templateVO.getAttributes().stream().filter(s -> (StringUtils.isNotBlank(s.getEnumstring()) || StringUtils.isNotBlank(s.getEnumid())) && !VciBaseUtil.getBoolean(s.getEnumeditflag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + if (!CollectionUtils.isEmpty(enumAttrVOMap)) { + enumAttrVOMap.forEach((attrId, attrVO) -> { + String value = getValueFromOrderDTO(orderDTO, attrId); + if (StringUtils.isNotBlank(value)) { + //鏈夊�兼墠鑳芥牎楠� + List<KeyValue> comboboxKVs = listComboboxItems(attrVO); + if (!comboboxKVs.stream().anyMatch(s -> value.equalsIgnoreCase(s.getKey()))) { + throw new VciBaseException("灞炴�с�恵0}銆戠殑鍊间笉绗﹀悎鏋氫妇鐨勮姹�", new String[]{attrVO.getName()}); + } + } + }); + } + } + + /** + * 杞崲鏃堕棿鐨勬牸寮� + * + * @param templateVO 妯℃澘鐨勬樉绀哄璞★紝闇�瑕佸寘鍚睘鎬� + * @param orderDTO 缂栫爜鐢宠鐨勪俊鎭� + */ + private void switchDateAttrOnOrder(CodeClstemplateVO templateVO, CodeOrderDTO orderDTO) { + Map<String, CodeClstempattrVO> dateAttrVOMap = templateVO.getAttributes().stream().filter(s -> StringUtils.isNotBlank(s.getCodedateformat())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t)); + if (!CollectionUtils.isEmpty(dateAttrVOMap)) { + dateAttrVOMap.forEach((attrId, attrVO) -> { + String value = getValueFromOrderDTO(orderDTO, attrId); + if (StringUtils.isNotBlank(value)) { + DateConverter dateConverter = new DateConverter(); + dateConverter.setAsText(value); + value = VciDateUtil.date2Str(dateConverter.getValue(), VciDateUtil.DateTimeMillFormat); + setValueToOrderDTO(orderDTO, attrId, value); + } + }); + } + } + + /** + * 鎷疯礉鏁版嵁鍒癱bo瀵硅薄涓� + * + * @param classifyFullInfo 鍒嗙被鐨勫叏閮ㄤ俊鎭� + * @param cbo 涓氬姟鏁版嵁 + * @param orderDTO 缂栫爜鐢宠鐨勪俊鎭� + * @param templateVO 妯℃澘鐨勬樉绀哄璞� + * @param edit 鏄惁涓轰慨鏀� + */ + private void copyValueToCBO(CodeClassifyFullInfoBO classifyFullInfo, CodeWupinEntity cbo, + CodeOrderDTO orderDTO, CodeClstemplateVO templateVO, + boolean edit) { + String fullPath = ""; + if (!CollectionUtils.isEmpty(classifyFullInfo.getParentClassifyVOs())) { + fullPath = classifyFullInfo.getParentClassifyVOs().stream().sorted(((o1, o2) -> o2.getDataLevel().compareTo(o1.getDataLevel()))) + .map(CodeClassifyVO::getOid).collect(Collectors.joining("##")); + } else { + fullPath = classifyFullInfo.getCurrentClassifyVO().getOid(); + } + +// BeanUtils. + BeanUtils.copyProperties(orderDTO.getData(),cbo); + cbo.setMaterialtype(Short.valueOf("1001")); +// orderDTO.getData().forEach((key, value) -> { +// if (!edit || (!checkUnAttrUnEdit(key) && +// !VciQueryWrapperForDO.LC_STATUS_FIELD.equalsIgnoreCase(key))) { +// try { +// cbo.setAttributeValue(key, value); +// } catch (Exception e) { +// logger.error("璁剧疆灞炴�х殑鍊奸敊璇�", e); +// } +// } +// }); + try { + + cbo.setCodeclsfid(classifyFullInfo.getCurrentClassifyVO().getOid()); + cbo.setCodetemplateoid(templateVO.getOid()); + cbo.setCodeclsfpath(fullPath); +// cbo.setMaterialclassify("model_type"); +// cbo.setMaterialname(orderDTO.getData().get("materialname")); +// cbo.setShifoupihaoguanli("true"); +// cbo.setKucunwl("true"); +// cbo.setXiaoshouwl("false"); + if (!edit && StringUtils.isBlank(orderDTO.getLcStatus())) { + //鎵剧敓鍛藉懆鏈熺殑璧峰鐘舵�侊紝鎻掍釜鐐癸紝鐪嬬敓鍛藉懆鏈熸槸鍚﹂渶瑕佸垱寤� + if (StringUtils.isNotBlank(cbo.getLctid())) { +// OsLifeCycleVO lifeCycleVO = lifeCycleService.getLifeCycleById(cbo.getLctid()); +// if (lifeCycleVO != null) { +// cbo.setLcStatus("Editing"); +//// cbo.setLcStatus(lifeCycleVO.getStartStatus()); +// } else { + cbo.setLcStatus(CodeDefaultLC.EDITING.getValue()); +// } + } else { + cbo.setLcStatus(CodeDefaultLC.EDITING.getValue()); + } + + } + + int secret = VciBaseUtil.getInt(cbo.getSecretGrade().toString()); + //鎻掍釜鐐癸紝鍚庣画鐪嬪瘑绾ф湇鍔℃槸鍚﹀彲鐢� +// if (secret == 0 || !secretService.checkDataSecret(secret)) { + if (secret == 0 ) { + Integer userSecret = VciBaseUtil.getCurrentUserSecret(); +// cbo.setAttributeValue(SECRET_FIELD, String.valueOf((userSecret == null || userSecret == 0) ? UserSecretEnum.NONE.getValue() : userSecret)); + cbo.setSecretGrade(userSecret == null || userSecret == 0 ? UserSecretEnum.NONE.getValue() : userSecret); + } + } catch (Throwable e) { + logger.error("璁剧疆榛樿鐨勫睘鎬х殑鍊奸敊璇�", e); + } + } + + + /** + * 鍒濆鍖栦笟鍔$被鍨� + * --鍒涘缓浜洪粯璁や负褰撳墠鐢ㄦ埛锛屽鏋滈渶瑕佷慨鏀癸紝鍙互鍦ㄨ幏鍙栧悗鑷澶勭悊 + * @param btmName 涓氬姟绫诲瀷鐨勫悕绉帮紝浼氳嚜鍔ㄥ彉鎴愬皬鍐� + * @return CodeWupinEntity + * @throws VciBaseException 鍒濆鍖栧嚭閿欑殑鏄細鎶涘嚭寮傚父 + */ +// @Override +// public CodeWupinEntity createCBOByBtmName(String btmName) +// throws VciBaseException { +// if(btmName!=null){ +// btmName = btmName.trim().toLowerCase(); +// } +// String userid = AuthUtil.getUser().getUserName(); +//// if(!hasCreatedCbos.containsKey(btmName)){ +//// if(StringUtils.isEmpty(userid)){ +//// throw new VciBaseException(msgCodePrefix +"noHasUserid"); +//// } +//// try { +//// hasCreatedCbos.put(btmName, createBusinessObject(btmName)); +//// } catch (Exception e) { +//// logger.error("鍒涘缓涓氬姟绫诲瀷瀵硅薄",e); +//// throw new VciBaseException(msgCodePrefix + "initBoError",new String[]{btmName}); +//// } +//// } +//// ClientBusinessObject cbo = cloneClientBusinessObject(hasCreatedCbos.get(btmName)); +// +// QueryWrapper<CodeOsbtmtypeEntity> btmWrapper = new QueryWrapper<>(); +// btmWrapper.eq("ID",btmName); +// CodeOsbtmtypeEntity btmTypeVO = codeOsbtmtypeMapper.selectOne(btmWrapper); +//// OsBtmTypeVO btmTypeVO = btmService.getBtmById(boName); +// String userName = AuthUtil.getUser().getUserName(); +// CodeWupinEntity wupinEntity = new CodeWupinEntity(); +// wupinEntity.setOid(null); +//// bo.setRevisionid((new ObjectUtility()).getNewObjectID36()); +//// bo.setNameoid((new ObjectUtility()).getNewObjectID36()); +// wupinEntity.setBtmname(btmName); +// wupinEntity.setLastR(String.valueOf(1)); +// wupinEntity.setFirstR(String.valueOf(1)); +// wupinEntity.setFirstV(String.valueOf(1)); +// wupinEntity.setLastV(String.valueOf(1)); +// wupinEntity.setCreator(userName); +// wupinEntity.setCreateTime(new Date()); +// wupinEntity.setLastModifier(userName); +// wupinEntity.setLastModifyTime(new Date()); +// wupinEntity.setRevisionRule(btmTypeVO.getRevisionruleid()); +// wupinEntity.setVersionRule(String.valueOf(btmTypeVO.getVersionRule())); +// if(StringUtils.isNotBlank(btmTypeVO.getRevisionruleid())){ +// //鎻掍釜鐐癸紝闇�瑕侀棶鍕囧摜鐗堟湰闂锛屽睍绀洪粯璁や负1 +//// OsRevisionRuleVO revisionRuleVO = revisionRuleService.getRevisionRuleById(btmTypeVO.getRevisionruleid()); +// wupinEntity.setRevisionValue("1"); +// } +// +// wupinEntity.setRevisionSeq(1); +// wupinEntity.setVersionSeq(1); +// //鎻掍釜鐐癸紝闇�瑕侀棶鍕囧摜鐗堟湰闂锛屽睍绀洪粯璁や负1 +// wupinEntity.setVersionValue("1"); +// wupinEntity.setLctid("wupinLC"); +// wupinEntity.setLcStatus("Editing"); +// wupinEntity.setId(""); +// wupinEntity.setName(""); +// wupinEntity.setDescription(""); +// wupinEntity.setOwner(userName); +// wupinEntity.setCheckinby(userName); +// wupinEntity.setCopyFromVersion(""); +// wupinEntity.setMaterialtype((short) 1001); +// wupinEntity.setCaigouwl("true"); +// wupinEntity.setShifoupihaoguanli("true"); +// wupinEntity.setKucunwl("true"); +// wupinEntity.setXiaoshouwl("false"); +// wupinEntity.setPassing("true"); +// +//// this.initTypeAttributeValue(wupinEntity,btmTypeVO); +// return wupinEntity; +// +// +//// return cbo; +// } + + /** + * 鏄惁涓轰慨鏀瑰拷鐣ョ殑灞炴�� + * @param attrName 灞炴�х殑鍚嶅瓧 + * @return true 琛ㄧず搴旇蹇界暐 + */ + boolean checkUnAttrUnEdit(String attrName){ + return (VciQueryWrapperForDO.OID_FIELD.equalsIgnoreCase(attrName) + ||"ts".equalsIgnoreCase(attrName) + || "lastmodifier".equalsIgnoreCase(attrName) + || "lastmodifytime".equalsIgnoreCase(attrName) + || "createtime".equalsIgnoreCase(attrName) + || "checkintime".equalsIgnoreCase(attrName) + ||"checkouttime".equalsIgnoreCase(attrName)); + } + + /** + * 淇濆瓨鍙緭鍙�夌殑淇℃伅 + * + * @param templateVO 妯℃澘鐨勫璞� + * @param cboList 鏁版嵁鐨勫唴瀹� + */ +// @Override +// public void batchSaveSelectChar(CodeClstemplateVO templateVO, List<ClientBusinessObject> cboList) { +// if (templateVO != null && !CollectionUtils.isEmpty(cboList)) { +// //鏄紓姝ョ殑锛屾墍浠ョ洿鎺ュ惊鐜� +// List<CodeClstempattrVO> selectAttrVOs = templateVO.getAttributes().stream().filter(s -> StringUtils.isNotBlank(s.getLibraryidentification())).collect(Collectors.toList()); +// +// if (!CollectionUtils.isEmpty(selectAttrVOs)) { +//// SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); +// selectAttrVOs.parallelStream().forEach(attrVO -> { +// List<String> valuesList = new CopyOnWriteArrayList<>(); +// cboList.parallelStream().forEach(cbo -> { +// String value = cbo.getAttributeValue(attrVO.getId()); +// if (StringUtils.isNotBlank(value)) { +// valuesList.add(value); +// } +// }); +// if (!CollectionUtils.isEmpty(valuesList)) { +// charService.saveBySameNamespaceAndFlag(templateVO.getBtmTypeId(), attrVO.getLibraryIdentification(), valuesList, sessionInfo); +// } +// }); +// } +// } +// } +} -- Gitblit v1.9.3