From 367c66e0ab339e15d6ad881ace683cec7e11f2f7 Mon Sep 17 00:00:00 2001
From: yuxc <653031404@qq.com>
Date: 星期二, 30 五月 2023 17:34:36 +0800
Subject: [PATCH] 1、主要完成传入业务类型与basemodel进行插入。 2、完成传入业务类型、oid进行查询返回list<basemodel>

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java |  110 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 95 insertions(+), 15 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
index 9c28997..f199450 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
@@ -2,33 +2,40 @@
 
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
 import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
 import com.vci.ubcs.code.dto.CodeOrderSecDTO;
 import com.vci.ubcs.code.entity.CodeAllCode;
 import com.vci.ubcs.code.entity.CodeSerialValue;
-import com.vci.ubcs.code.entity.CodeWupinEntity;
 import com.vci.ubcs.code.enumpack.CodeCutTypeEnum;
 import com.vci.ubcs.code.enumpack.CodeGetValueTypeEnum;
 import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum;
 import com.vci.ubcs.code.enumpack.CodeSecTypeEnum;
+import com.vci.ubcs.code.lifecycle.CodeAllCodeLC;
 import com.vci.ubcs.code.mapper.CodeSerialValueMapper;
 import com.vci.ubcs.code.service.ICodeWupinService;
+import com.vci.ubcs.code.service.MdmEngineService;
 import com.vci.ubcs.code.service.MdmProductCodeService;
 import com.vci.ubcs.code.vo.pagemodel.CodeBasicSecVO;
 import com.vci.ubcs.code.vo.pagemodel.CodeClassifyTemplateVO;
 import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO;
 import com.vci.ubcs.code.vo.pagemodel.CodeRuleVO;
 import com.vci.ubcs.starter.exception.VciBaseException;
+import com.vci.ubcs.starter.revision.model.BaseModel;
+import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
 import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
 import com.vci.ubcs.starter.web.constant.RegExpConstant;
 import com.vci.ubcs.starter.web.enumpck.OsCodeFillTypeEnum;
 import com.vci.ubcs.starter.web.util.VciBaseUtil;
 import com.vci.ubcs.starter.web.util.VciDateUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 import static com.vci.ubcs.code.constant.MdmEngineConstant.*;
@@ -52,12 +59,24 @@
 	 */
 	@Resource
 	private ICodeWupinService iCodeWupinService;
+	/**
+	 * 鎵�鏈夌殑缂栫爜鐨勫唴瀹�
+	 */
+	@Resource
+	@Lazy
+	private MdmEngineService mdmEngineService;
+
+	/**
+	 * 鍏紡鐨勬湇鍔�
+	 */
+	@Autowired
+	private FormulaServiceImpl formulaService;
 
 	@Override
-	public List<String> productCodeAndSaveData(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<CodeWupinEntity> dataCBOList) {
+	public List<String> productCodeAndSaveData(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<BaseModel> dataCBOList) throws Exception {
 //		BatchCBO batchCBO = new BatchCBO();
 //		WebUtil.setPersistence(false);
-//		dataCBOList = dataCBOList.stream().sorted(((o1, o2) -> o1.getCreateTime().compareTo(o2.getCreateTime()))).collect(Collectors.toList());
+		dataCBOList = dataCBOList.stream().sorted(((o1, o2) -> o1.getCreateTime().compareTo(o2.getCreateTime()))).collect(Collectors.toList());
 //		batchCBO.getCreateCbos().addAll(dataCBOList);
 		List<String> codeList = new ArrayList<>();
 
@@ -79,7 +98,7 @@
 //				VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
 				String code = cbo.getId();
 				List<String> serialUnitList = new ArrayList<>();
-				String[] secLengths = cbo.getCodeSecLengthField().split("#");
+				String[] secLengths = cbo.getData().get(CODE_SEC_LENGTH_FIELD).split("#");
 				List<CodeBasicSecVO> secVOList = ruleVO.getSecVOList().stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList());
 				Map<String/**鐮佹鐨勪富閿�**/,String/**鐮佹鐨勫��**/> serialValueMap = new HashMap<>();
 				Map<String, CodeBasicSecVO> secVOMap = secVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t));
@@ -263,7 +282,7 @@
 			Map<String/**鐮佹鐨勪富閿�**/, Map<String, CodeSerialValue>> maxSerialValueMap = new HashMap<>();
 
 			for (int i = 0; i < dataCBOList.size(); i++) {
-				CodeWupinEntity cbo = dataCBOList.get(i);
+				BaseModel cbo = dataCBOList.get(i);
 				List<String> thisSecValueList = new LinkedList<>();
 				for (int j = 0; j < secValueList.size(); j++) {
 					thisSecValueList.add(secValueList.get(j));
@@ -300,10 +319,17 @@
 			Map<String, String> statusMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus()));
 			allCodeDOList.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> {
 				s.setLcStatus(statusMap.get(s.getOid()));
-
 			});
+
+
+			allCodeDOList.stream().forEach(
+				allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");}
+			);
+
 			codeAllCodeService.saveBatch(allCodeDOList);
-			iCodeWupinService.saveBatch(dataCBOList);
+//			iCodeWupinService.saveBatch(dataCBOList);
+			mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList);
+
 //			batchCBO.getCreateCbos().stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmName())).forEach(s -> {
 //				s.setLcStatus(statusMap.get(s.getOid()));
 //				try {
@@ -326,17 +352,17 @@
 	 * @param serialUnitList 娴佹按渚濇嵁鐨勫唴瀹�
 	 *                       杩橀渶瑕佸悗缁殑涓�涓Щ妞嶅皢浼氭秹鍙婂埌鍏朵粬鐨勬湇鍔�
 	 */
-	private void switchAttrSecValue(List<CodeBasicSecVO> attrSecVOList,CodeWupinEntity cbo,
-									List<String> thisSecValueList,boolean attrSevIsSerialDepend,
-									List<String> serialUnitList){
+	private void switchAttrSecValue(List<CodeBasicSecVO> attrSecVOList, BaseModel cbo,
+                                    List<String> thisSecValueList, boolean attrSevIsSerialDepend,
+                                    List<String> serialUnitList){
 		if (!CollectionUtils.isEmpty(attrSecVOList)) {
 			attrSecVOList.stream().forEach(attrSevVO -> {
 				String value = "";
 				if (StringUtils.isNotBlank(attrSevVO.getGetValueClass())) {
 					//浣跨敤缁勫悎瑙勫垯鏉ュ鐞嗙殑
-//					value = getValueByFormulaForCBO(cbo, attrSevVO.getGetValueClass());
+					value = getValueByFormulaForCBO(cbo, attrSevVO.getGetValueClass());
 				} else {
-//					value = cbo.getAttributeValue(attrSevVO.getReferAttributeId());
+					value = cbo.getData().get(attrSevVO.getReferAttributeId());
 				}
 				if (value == null) {
 					value = "";
@@ -584,9 +610,9 @@
 	 * @param templateVO 妯℃澘鐨勪俊鎭�
 	 * @param allCodeDOList 鎵�鏈夌殑鐮佸�肩殑瀵硅薄鍒楄〃
 	 */
-	private void wrapperAllCode(CodeClassifyFullInfoBO classifyFullInfoBO,CodeRuleVO ruleVO,
-								CodeWupinEntity cbo,CodeClassifyTemplateVO templateVO,
-								List<CodeAllCode> allCodeDOList,String serialUnitString,String serialValueString){
+	private void wrapperAllCode(CodeClassifyFullInfoBO classifyFullInfoBO, CodeRuleVO ruleVO,
+                                BaseModel cbo, CodeClassifyTemplateVO templateVO,
+                                List<CodeAllCode> allCodeDOList, String serialUnitString, String serialValueString){
 		CodeAllCode allCodeDO = new CodeAllCode();
 		allCodeDO.setCodeClassifyOid(classifyFullInfoBO.getCurrentClassifyVO().getOid());
 		allCodeDO.setCodeRuleOid(ruleVO.getOid());
@@ -702,4 +728,58 @@
 		return value;
 
 	}
+
+	/**
+	 * 鍥炴敹鐮佸��
+	 *
+	 * @param btmId                 涓氬姟鏁版嵁鐨勪笟鍔$被鍨�
+	 * @param businessOidCollection 涓氬姟鏁版嵁鐨勪富閿�
+	 * @return 鏄惁鏇存柊鎴愬姛
+	 */
+	@Override
+	public Boolean recycleCode(String btmId, Collection<String> businessOidCollection) {
+//		boolean oldPersistence =  WebUtil.isPersistence();
+//		WebUtil.setPersistence(false);
+//		BatchCBO batchCBO = new BatchCBO();
+		AtomicReference<Boolean> updateFlag = new AtomicReference<>(false);
+		VciBaseUtil.switchCollectionForOracleIn(businessOidCollection).stream().forEach(oids-> {
+//			Map<String, String> conditionMap = new HashMap<>();
+//			//缂栫爜瑕佽褰曚负鍥炴敹鐨勭姸鎬�
+//			conditionMap.put("createcodeoid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")");
+//			conditionMap.put("createcodebtm", btmId);
+
+			QueryWrapper<CodeAllCode> wrapper = new QueryWrapper<>();
+			wrapper.in("createcodeoid",QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oids.toArray(new String[0])) + ")");
+			wrapper.eq("createcodebtm", btmId);
+
+
+			List<CodeAllCode> allCodeDOS = codeAllCodeService.selectByWrapper(wrapper);
+//			allCodeMapper.selectByCondition(conditionMap, new PageHelper(-1));
+			if (!CollectionUtils.isEmpty(allCodeDOS)) {
+				allCodeDOS.stream().forEach(codeDO->{
+					codeDO.setLcStatus(CodeAllCodeLC.TASK_BACK.getValue());
+				});
+				updateFlag.set(codeAllCodeService.updateBatchById(allCodeDOS));
+//				batchCBO.copyFromOther(allCodeMapper.batchUpdate(allCodeDOS));
+			}
+		});
+//		WebUtil.setPersistence(oldPersistence);
+		return updateFlag.get();
+	}
+
+	/**
+	 * 浣跨敤CBO澶勭悊缁勫悎瑙勫垯鐨勫唴瀹�
+	 * @param cbo 鏁版嵁鐨勫唴瀹�
+	 * @param rule 瑙勫垯鐨勫唴瀹�
+	 * @return 杞崲鍚庣殑
+	 */
+	private String getValueByFormulaForCBO(BaseModel cbo,String rule){
+		Map<String, Object> dataMap = BeanUtils.beanToMap(cbo);
+		Map<String, String> map = new HashMap<String, String>();
+		for (String i : dataMap.keySet()) {
+			map.put(i, String.valueOf(dataMap.get(i)));
+		}
+//		WebUtil.copyValueToMapFromCbos(cbo,dataMap);
+		return formulaService.getValueByFormula(map,rule);
+	}
 }

--
Gitblit v1.9.3