| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.thoughtworks.xstream.XStream; |
| | | import com.thoughtworks.xstream.io.xml.DomDriver; |
| | | import com.vci.ubcs.code.applyjtcodeservice.feign.MdmApplyGroupCodeProvider; |
| | | import com.vci.ubcs.code.constant.MdmDuckingConstant; |
| | | import com.vci.ubcs.code.dto.CodeOrderDTO; |
| | | import com.vci.ubcs.code.dto.datapush.classify.JsonRootDataDTO; |
| | | import com.vci.ubcs.code.dto.datapush.classify.NodeClassifyDTO; |
| | | import com.vci.ubcs.code.dto.datapush.classify.NodeDataDTO; |
| | |
| | | import com.vci.ubcs.code.dto.datapush.result.ResultNodeDataDTO; |
| | | import com.vci.ubcs.code.dto.datapush.result.ResultNodeObjectDTO; |
| | | import com.vci.ubcs.code.entity.*; |
| | | import com.vci.ubcs.code.enumpack.CodeDefaultLC; |
| | | import com.vci.ubcs.code.enumpack.SysIntegrationDataFlowTypeEnum; |
| | | import com.vci.ubcs.code.feign.MdmSearchItemCodeProvider; |
| | | import com.vci.ubcs.code.mapper.CommonsMapper; |
| | | import com.vci.ubcs.code.service.*; |
| | | import com.vci.ubcs.code.util.gennerAttrMapUtil; |
| | | import com.vci.ubcs.code.vo.pagemodel.*; |
| | | import com.vci.ubcs.code.vo.webserviceModel.apply.ApplyDataVO; |
| | | import com.vci.ubcs.code.vo.webserviceModel.apply.ApplyDatasVO; |
| | | import com.vci.ubcs.code.vo.webserviceModel.apply.ProppertyVO; |
| | | import com.vci.ubcs.code.vo.webserviceModel.applybz.ApplyBZDataVO; |
| | | import com.vci.ubcs.code.vo.webserviceModel.applybz.ApplyBZDatasVO; |
| | | import com.vci.ubcs.code.vo.webserviceModel.attrmap.*; |
| | | import com.vci.ubcs.code.vo.webserviceModel.result.xml.XMLResultDataObjectDetailDO; |
| | | import com.vci.ubcs.code.webService.config.AttributeMapConfig; |
| | | import com.vci.ubcs.omd.feign.IBtmTypeClient; |
| | | import com.vci.ubcs.omd.vo.BtmTypeVO; |
| | | import com.vci.ubcs.starter.revision.model.BaseModel; |
| | | import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; |
| | | import com.vci.ubcs.starter.util.HttpUtils; |
| | | import com.vci.ubcs.code.util.WsErpClientUtil; |
| | | import com.vci.ubcs.starter.web.enumpck.UserSecretEnum; |
| | | import com.vci.ubcs.starter.web.pagemodel.SessionInfo; |
| | | import com.vci.ubcs.starter.web.util.BeanUtil; |
| | | import com.vci.ubcs.starter.web.util.BeanUtilForVCI; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import com.vci.ubcs.starter.web.util.WebUtil; |
| | | import com.vci.ubcs.system.user.entity.User; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.util.StringUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.support.DefaultTransactionStatus; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.jws.WebMethod; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.xml.ws.WebServiceContext; |
| | | import javax.xml.ws.handler.MessageContext; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.vci.ubcs.code.constant.MdmDuckingConstant.*; |
| | | import static com.vci.ubcs.code.constant.MdmEngineConstant.DEFAULT_SYNC_ATTR_LIST; |
| | | |
| | | |
| | | /* |
| | |
| | | public String DATA_PARAM_NAME; |
| | | @Value("${dataSyncPush.dataId:itemid}") |
| | | private String itemId; |
| | | |
| | | @Value("${erp.item.attrKey:xhdh}") |
| | | public String attrKey; |
| | | |
| | | @Value("${erp.item.systemId:ERP}") |
| | | public String systemId; |
| | | |
| | | /** |
| | | * 业务类型的服务 |
| | |
| | | private CommonsMapper commonsMapper; |
| | | @Resource |
| | | private MdmEngineService mdmEngineServiceI; |
| | | |
| | | /** |
| | | * 批量处理的服务 |
| | | */ |
| | | @Resource |
| | | private MdmIOService mdmIOService; |
| | | @Resource |
| | | private IPasswordFreeLoginService passwordFreeLoginService; |
| | | @Resource |
| | | private WebServiceContext webServiceContext; |
| | | @Resource |
| | | private IDockingLogeService dockingLogeService; |
| | | @Resource |
| | |
| | | private IDockingSystemConfigService dockingSystemConfigService; |
| | | @Resource |
| | | private ICodeClassifyService codeClassifyService; |
| | | |
| | | @Autowired(required = false) |
| | | private AttributeMapConfig attributeMapConfig; |
| | | /*** |
| | | * resdis缓存服务 |
| | | */ |
| | |
| | | private IDockingSysIntHeaderService dockingSysIntHeaderService; |
| | | @Autowired(required = false) |
| | | private MdmSearchItemCodeProvider mdmSearchItemCodeProvider; |
| | | |
| | | @Autowired |
| | | HttpServletRequest request; |
| | | |
| | | @Override |
| | | public void DockingDataSyncScheduing() { |
| | |
| | | searchItemParam.setStatus("1");// |
| | | SearchItemVO searchItemVO= mdmSearchItemCodeProvider.getppModelByElem(searchItemParam); |
| | | if(searchItemVO!=null) { |
| | | searchItemVO.getCode(); |
| | | searchItemVO.getMsg(); |
| | | List<CodeClassify> codeClassifyList = codeClassifyService.selectByWrapper(Wrappers.<CodeClassify>query().lambda().in(CodeClassify::getId, btmName)); |
| | | try { |
| | | //免密登录申请token,request中添加用户信息 |
| | | try { |
| | | passwordFreeLoginService.pwdFreeLoginByBoolean(systemId.toLowerCase(Locale.ROOT), request); |
| | | }catch (Throwable e){ |
| | | throw new Throwable("用户鉴权失败."); |
| | | } |
| | | final BladeUser user = AuthUtil.getUser(); |
| | | List<CodeClassify> codeClassifyList = codeClassifyService.selectByWrapper(Wrappers.<CodeClassify>query().lambda().in(CodeClassify::getId, btmName)); |
| | | if (CollectionUtils.isEmpty(codeClassifyList)) { |
| | | throw new Throwable("分类未查询到"); |
| | | } |
| | | CodeClassify codeClassify= codeClassifyList.get(0); |
| | | CodeClassifyTemplateVO templateVO = mdmEngineServiceI.getUsedTemplateByClassifyOid(codeClassify.getOid()); |
| | | if(templateVO==null||StringUtils.isBlank(templateVO.getOid())){ |
| | | throw new Throwable ("根据传输的分类,未获取MDM系统中对应模板"); |
| | | } |
| | | List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s -> !DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) && |
| | | ((Func.isNotEmpty(s.getClassifyInvokeAttr()) || Func.isNotEmpty(s.getClassifyInvokeAttrName())) || VciBaseUtil.getBoolean(s.getFormDisplayFlag())) |
| | | ).collect(Collectors.toList()); |
| | | List<SearchItemDataVO> dataList = searchItemVO.getData(); |
| | | Map<String, SearchItemDataVO> dataVOMap = new HashMap<>(); |
| | | List<String> itemCodeList = new ArrayList<>(); |
| | |
| | | sb.append(" and lastr=1 and lastv=1"); |
| | | sb.append(" and codeclsfid = '" + codeClassify.getOid() + "'"); |
| | | List<Map<String, String>> newDataList = commonsMapper.queryByOnlySqlForMap(sb.toString()); |
| | | //List<BaseModel> baseModelList=new ArrayList<>(); |
| | | Map<String,BaseModel> baseModelMap=new HashMap<>(); |
| | | newDataList.stream().forEach(dataMap->{ |
| | | String value= dataMap.getOrDefault(attrKey,""); |
| | | if(dataVOMap.containsKey(attrKey)){ |
| | | SearchItemDataVO searchItemDataVO=dataVOMap.get(attrKey); |
| | | |
| | | }else{ |
| | | |
| | | |
| | | } |
| | | |
| | | BaseModel baseModel=new BaseModel(); |
| | | DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,baseModel,false,user); |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(baseModel,user); |
| | | //baseModelList.add(baseModel); |
| | | String attrKeyValue=dataMap.getOrDefault(attrKey,""); |
| | | baseModelMap.put(attrKeyValue,baseModel); |
| | | }); |
| | | ApplyDatasVO editDatasVO = new ApplyDatasVO(); |
| | | |
| | | List<ApplyDataVO> addObjectList=new ArrayList<>(); |
| | | List<ApplyDataVO> editObjectList=new ArrayList<>(); |
| | | dataVOMap.forEach((key,value)->{ |
| | | if(baseModelMap.containsKey(key)){ |
| | | BaseModel baseModel=baseModelMap.get(key); |
| | | changeObjectToMap(value,baseModel.getId(),user,"editstatus",editObjectList); |
| | | }else{ |
| | | changeObjectToMap(value,"",user,"create",addObjectList); |
| | | } |
| | | }); |
| | | if(!CollectionUtils.isEmpty(addObjectList)){ |
| | | DataObjectVO dataObjectVO = new DataObjectVO(); |
| | | ApplyDatasVO applyDatasVO = new ApplyDatasVO(); |
| | | applyDatasVO.setObject(addObjectList); |
| | | LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>(); |
| | | this.getConfigDatas(systemId, btmName, applyDatasVO, attrVOS, dataObjectVO); |
| | | CodeOrderDTO orderDTO = new CodeOrderDTO(); |
| | | orderDTO.setCodeClassifyOid(codeClassify.getOid());//分类主键 |
| | | orderDTO.setSecDTOList(codeOrderSecDTOList);//分类码段 |
| | | mdmIOService.batchSyncApplyCode(orderDTO, applyDatasVO, resultDataObjectDetailDOs,false); |
| | | } |
| | | |
| | | if(!CollectionUtils.isEmpty(editObjectList)){ |
| | | DataObjectVO dataObjectVO = new DataObjectVO(); |
| | | LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>(); |
| | | CodeClassifyVO codeClassifyVO=new CodeClassifyVO(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassify, codeClassifyVO); this.getConfigDatas(systemId, btmName, applyDatasVO, attrVOS, dataObjectVO); |
| | | mdmIOService.batchSyncEditDatas(codeClassifyVO,dataObjectVO, resultDataObjectDetailDOs,false); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * 读取属性映射配置信息 |
| | | * @param systemId |
| | | * @param libray |
| | | * @param applyDatasVO |
| | | * @param codeClassifyTemplateAttrVOList |
| | | * @param dataObjectVO |
| | | * @throws Throwable |
| | | */ |
| | | public void getConfigDatas(String systemId, String libray, ApplyBZDatasVO applyDatasVO, List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOList, DataObjectVO dataObjectVO) throws Throwable { |
| | | LinkedHashMap<String,LinkedHashMap<String,String>> dataKeyValueMap=new LinkedHashMap<>(); |
| | | //如果将数据转换成所需要的数据对象 |
| | | Map<String, String> attrMapConfigMap=new HashMap<>(); |
| | | Map<String, String> propMaps=new HashMap<>(); |
| | | log.info("开始读取系统配置文件 start"); |
| | | Map<String, String> stringStringMap=attributeMapConfig.getSystem_attrmap(); |
| | | log.info("集成系统属性映射配置文件条目数-》"+stringStringMap.size()); |
| | | //stringStringMap.put("RLM","D:\\RLM.xml"); |
| | | if(!CollectionUtils.isEmpty(stringStringMap)) { |
| | | List<LibraryClsfDO> libraryClsfDOList=new ArrayList<>(); |
| | | try { |
| | | log.info("info:需要读取配置文件"); |
| | | LibraryDO libraryDO = gennerAttrMapUtil.getNewInstance().gennerAttrMapBySystem(systemId, stringStringMap); |
| | | libraryClsfDOList = libraryDO.getClsf(); |
| | | } catch (Throwable e) { |
| | | e.printStackTrace(); |
| | | throw new Throwable("集成系统标识为:【" + systemId + "】,分类库为:【" + libray + "】的集成属性配置文件读取失败"); |
| | | } |
| | | String path = stringStringMap.get(systemId); |
| | | if (!CollectionUtils.isEmpty(libraryClsfDOList)) { |
| | | Map<String, List<ClsfAttrMappingDO>> libPropMaps = libraryClsfDOList.stream().collect(Collectors.toMap(LibraryClsfDO::getLibrary, LibraryClsfDO::getProp, (key1, key2) -> key2)); |
| | | log.info("根据参数:libray:-》" + libray + "从配置文件中找对应属性映射配置"); |
| | | if (libPropMaps.containsKey(libray.toUpperCase(Locale.ROOT))) { |
| | | log.info("根据参数:libray:-》" + libray + "匹配到相应的属性映射信息"); |
| | | List<ClsfAttrMappingDO> clsfAttrMappingDOList = libPropMaps.get(libray.toUpperCase(Locale.ROOT)); |
| | | propMaps = clsfAttrMappingDOList.stream().collect(Collectors.toMap(ClsfAttrMappingDO::getSourceKey, ClsfAttrMappingDO::getTargetKey, (key1, key2) -> key2)); |
| | | log.info("根据参数:libray:-》" + libray + "匹配到相应的属性映射信息,属性映射条目数+" + clsfAttrMappingDOList.size()); |
| | | } else { |
| | | throw new Throwable("根据系统标识【" + systemId + "】找到对应的配置文件:【" + path + "】,但未获取到对应的库【" + libray + "】属性映射信息配置"); |
| | | } |
| | | }else{ |
| | | throw new Throwable("根据系统标识【" + systemId + "】找到对应的配置文件:【" + path + "】,但未获取到对应的库【" + libray + "】属性映射信息配置"); |
| | | } |
| | | }else{ |
| | | throw new Throwable("未获取到集成属性映射系统配置信息"); |
| | | } |
| | | log.info("根据参数:libray:-》"+libray+"从配置文件中找对应属性映射配置 end "); |
| | | LinkedList<String> rowNameList=new LinkedList<>(); |
| | | LinkedHashMap<String,Integer> filedIndexMap=new LinkedHashMap<>(); |
| | | //根据分类模板组织数据 |
| | | final int[] index = {0}; |
| | | try { |
| | | codeClassifyTemplateAttrVOList.stream().forEach(codeClassifyTemplateAttrVO -> { |
| | | String attrName = codeClassifyTemplateAttrVO.getName(); |
| | | String field = codeClassifyTemplateAttrVO.getId(); |
| | | rowNameList.add(attrName); |
| | | filedIndexMap.put(field, index[0]++); |
| | | }); |
| | | dataObjectVO.setColName(rowNameList);//放入属性 |
| | | attrMapConfigMap.putAll(propMaps); |
| | | LinkedList<RowDatas> rowDataList = new LinkedList<>(); |
| | | List<ApplyBZDataVO> applyBZDataVOList=new ArrayList<>(); |
| | | |
| | | if(!CollectionUtils.isEmpty(applyDatasVO.getObject())){ |
| | | applyBZDataVOList=applyDatasVO.getObject(); |
| | | } |
| | | //Map<String, List<ProppertyVO>> dataPropMap = applyDataVOList.stream().collect(Collectors.toMap(ApplyDataVO::getId, ApplyDataVO::getProp, (key1, key2) -> key2)); |
| | | final int[] rowIndex = {0}; |
| | | applyBZDataVOList.stream().forEach(applyDataVO -> { |
| | | rowIndex[0]++; |
| | | RowDatas rowDatas = new RowDatas(); |
| | | rowDatas.setOid(applyDataVO.getId()); |
| | | rowDatas.setCreator(applyDataVO.getCreator()); |
| | | rowDatas.setEditor(applyDataVO.getEditor()); |
| | | rowDatas.setCode(applyDataVO.getCode()); |
| | | rowDatas.setOperation("create"); |
| | | rowDatas.setStatus(applyDataVO.getStatus()); |
| | | rowDatas.setRowIndex(rowIndex[0] + ""); |
| | | List<ProppertyVO> proppertyVOList = applyDataVO.getProp(); |
| | | |
| | | LinkedHashMap<Integer, String> integerValueMap = new LinkedHashMap<>(); |
| | | Map<String, String> filedValueMap = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(proppertyVOList)) { |
| | | Map<String, String> sourceKeyValueMap = proppertyVOList.stream().collect(Collectors.toMap(ProppertyVO::getKey, ProppertyVO::getValue, (key1, key2) -> key2)); |
| | | Map<String, String> keyValueMap = new HashMap<>(); |
| | | //判断attrMapConfigMap是否有值,如果没有则说明基础默认的是编码系统字段 |
| | | if (!CollectionUtils.isEmpty(attrMapConfigMap)) { |
| | | sourceKeyValueMap.keySet().forEach(sourceKey -> { |
| | | String dataValue = sourceKeyValueMap.get(sourceKey); |
| | | if (attrMapConfigMap.containsKey(sourceKey)) { |
| | | String targetKey = attrMapConfigMap.get(sourceKey); |
| | | keyValueMap.put(targetKey, StringUtils.isBlank(dataValue)?"":dataValue); |
| | | } |
| | | }); |
| | | } else { |
| | | sourceKeyValueMap.forEach((filed,value)->{ |
| | | keyValueMap.put(filed,StringUtils.isBlank(value)?"":value) ; |
| | | }); |
| | | } |
| | | |
| | | filedIndexMap.forEach((attrKey, column) -> { |
| | | String keyValue = ""; |
| | | if (keyValueMap.containsKey(attrKey)) { |
| | | keyValue =StringUtils.isBlank(keyValueMap.get(attrKey))?"":keyValueMap.get(attrKey); |
| | | } |
| | | integerValueMap.put(column, keyValue); |
| | | filedValueMap.put(attrKey, keyValue); |
| | | }); |
| | | } |
| | | rowDatas.setData(integerValueMap); |
| | | rowDatas.setFiledValue(filedValueMap); |
| | | rowDataList.add(rowDatas); |
| | | }); |
| | | dataObjectVO.setRowData(rowDataList); |
| | | }catch (Throwable e){ |
| | | throw new Throwable("组织数据映射值失败"); |
| | | } |
| | | } |
| | | private void changeObjectToMap(SearchItemDataVO searchItemDataVO, String code, BladeUser user,String operation,List<ApplyDataVO> object){ |
| | | ApplyDataVO applyDataVO=new ApplyDataVO(); |
| | | List<ProppertyVO> propList=new ArrayList<>(); |
| | | //String status= searchItemDataVO.getStatus();//数据状态 字符型,枚举值;制单:0;审批中:1;通过:2;驳回:3; |
| | | |
| | | String mmodelCode=searchItemDataVO.getMmodelcode();//制造型号代号 |
| | | initProperty("mmodelCode","","mmodelCode",propList); |
| | | String projectCode= searchItemDataVO.getProjectcode();//项目编码 |
| | | initProperty("projectcode","","projectCode",propList); |
| | | String projectItem=searchItemDataVO.getProjectitem();//项目代号 |
| | | initProperty("projectitem","","projectItem",propList); |
| | | String materialCode=searchItemDataVO.getMaterialcode();//产品编码 |
| | | initProperty("materialcode","","materialCode",propList); |
| | | String creatBy=searchItemDataVO.getCreatby();//创建者 |
| | | Date cretaeDon= searchItemDataVO.getCreatedon();//创建日期 日期型,如:2023-09-08 19:24:11 |
| | | String lastchangeBy=searchItemDataVO.getLastchangedby();//更改者 |
| | | Date lastchangeDon=searchItemDataVO.getLastchangedon();//更改时间 日期型,如:2023-09-08 19:24:11 |
| | | String isenabled= searchItemDataVO.getIsenabled();//字符型,枚举值;停用:0;启用:1; |
| | | applyDataVO.setOperate(operation); |
| | | applyDataVO.setCode(code); |
| | | if(isenabled.equals(0)){ |
| | | applyDataVO.setStatus(CodeDefaultLC.DISABLE.getValue()); |
| | | }else{ |
| | | applyDataVO.setStatus(CodeDefaultLC.RELEASED.getValue()); |
| | | } |
| | | applyDataVO.setId(VciBaseUtil.getPk()); |
| | | applyDataVO.setEditor(lastchangeBy); |
| | | applyDataVO.setCreator(creatBy); |
| | | applyDataVO.setProp(propList); |
| | | object.add(applyDataVO); |
| | | } |
| | | private void initProperty(String key,String text,String value,List<ProppertyVO> propList){ |
| | | ProppertyVO vo=new ProppertyVO(); |
| | | vo.setKey(key); |
| | | vo.setText(text); |
| | | vo.setValue(value); |
| | | propList.add(vo); |
| | | } |
| | | /*** |
| | | * 查询redis中数据,对比后插入dockingtask |
| | | * @param type |