| | |
| | | package com.vci.ubcs.code.applyjtcodeservice.feigh; |
| | | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.nacos.shaded.com.google.protobuf.ServiceException; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.vci.ubcs.code.applyjtcodeservice.entity.*; |
| | | import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient; |
| | |
| | | import com.vci.ubcs.starter.revision.model.BaseModel; |
| | | import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; |
| | | import com.vci.ubcs.starter.util.MdmBtmTypeConstant; |
| | | import com.vci.ubcs.starter.util.SaveLogUtil; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.map.CaseInsensitiveMap; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | 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.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @NonDS |
| | | @ApiIgnore |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @Data |
| | | @Slf4j |
| | | public class MdmInterJtClient implements IMdmInterJtClient { |
| | | |
| | | @Value("${docking.apply.partCode:10}") |
| | | public String partCode; |
| | | |
| | | /** |
| | | * 集团申请单服务 |
| | | */ |
| | |
| | | */ |
| | | private final IDockingPreClassifyService dockingPreClassifyService; |
| | | |
| | | /*** |
| | | * 属性映射服务 |
| | | */ |
| | | private final IDockingPreAttrMappingService dockingPreAttrMappingService; |
| | | |
| | | /** |
| | | * 集团取值范围申请单服务 |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private IMdmEngineClient mdmEngineClient; |
| | | |
| | | private final SaveLogUtil saveLogUtil; |
| | | |
| | | /*** |
| | | * 申请集团编码 |
| | | * @return |
| | |
| | | return R.fail("集团码申请失败:"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * 查询集团属性映射 |
| | | * @param codeClassifyOid:编码分类oid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R<List<DockingPreAttrMappingVO>> list_mapping(String codeClassifyOid) { |
| | | List<DockingPreAttrMapping> dockingPreAttrMappings= dockingPreAttrMappingService.selectByWrapper(Wrappers.<DockingPreAttrMapping>query().lambda().eq(DockingPreAttrMapping::getTargetClassifyId,codeClassifyOid)); |
| | | List<DockingPreAttrMappingVO> dockingPreAttrMappingVOList=new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(dockingPreAttrMappings)){ |
| | | dockingPreAttrMappingVOList=dockingPreAttrMappingService.dockingPreAttrMappingDO2VOS(dockingPreAttrMappings,true); |
| | | } |
| | | return R.data(dockingPreAttrMappingVOList); |
| | | } |
| | | |
| | | /*** |
| | | * 申请集团编码数据维护 |
| | | * @return |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /* |
| | | * 主数据业务服务 |
| | | */ |
| | | |
| | | /** |
| | | * 获取集团集团码,赋值到主数据 |
| | | * @param dockingReturnStoreVO |
| | |
| | | public R getApplyGroupCode(DockingReturnStoreVO dockingReturnStoreVO) { |
| | | log.info("获取集团集团码,赋值到主数据 start"); |
| | | try { |
| | | List<BaseModel> editObjectList = new ArrayList(); |
| | | |
| | | Map<String,List<BaseModel>> editObjectMap = new HashMap<>(); |
| | | List<DockingPreApplyForm> dockingPreApplyFormList = new ArrayList(); |
| | | //String classId = javaObject.getClassId(); |
| | | //String sysName = javaObject.getSysName(); |
| | |
| | | } else if ("9".equals(formState)) { |
| | | msg = "审核中"; |
| | | } |
| | | // 如果返回了审查意见就用返回的 |
| | | msg = Func.isNotBlank(mainData.getExamineOpinion()) ? msg+",意见:"+mainData.getExamineOpinion():msg; |
| | | jcontent.put("applyId", applyId); |
| | | jcontent.put("formState", formState); |
| | | jcontent.put("customCoding", customCoding); |
| | |
| | | DockingPreApplyForm dockingPreApplyForm = oldDockingPreApplyFormList.get(0); |
| | | dockingPreApplyForm.setMsg(msg); |
| | | dockingPreApplyForm.setCode("1"); |
| | | dockingPreApplyForm.setLastModifyTime(new Date()); |
| | | if (res) { |
| | | dockingPreApplyForm.setGroupCode(customCoding); |
| | | } |
| | |
| | | String jdataid = dockingPreApplyForm.getDataOid(); |
| | | String jdatabtmname = dockingPreApplyForm.getDataBtmName(); |
| | | if (res) { |
| | | |
| | | //此处需要查询业务数据,去更改 |
| | | BaseModel baseModel = new BaseModel(); |
| | | baseModel.setId(customCoding); |
| | | log.info("申请单:"+applyId+",集团码:"+customCoding+"编码:"+baseModel.getId()); |
| | | editObjectList.add(baseModel); |
| | | R<List<BaseModel>> R = mdmEngineClient.selectByTypeAndOid(jdatabtmname,jdataid); |
| | | // TODO:新增业务逻辑,需要根据集团返回的属性进行判断,如果集团对该属性进行了修改编码系统也就需要对属性进行修改 |
| | | if(R.isSuccess()){ |
| | | List<BaseModel> newDatalist=new ArrayList<>(); |
| | | List<BaseModel> oldDatalist=R.getData(); |
| | | if(!CollectionUtils.isEmpty(oldDatalist)){ |
| | | if(editObjectMap.containsKey(jdatabtmname)){ |
| | | newDatalist=editObjectMap.getOrDefault(jdatabtmname,new ArrayList<>()); |
| | | } |
| | | BaseModel baseModel=oldDatalist.get(0); |
| | | //DefaultAttrAssimtUtil.updateDefaultAttrAssimt(baseModel); |
| | | baseModel.setLastModifyTime(new Date()); |
| | | baseModel.getData().put("GROUPCODE",customCoding); |
| | | // 1、取到集团返回的ViewInfos中编码视图中的属性 |
| | | List<Map<String, Object>> viewValueList = mainData.getViewInfos().stream().filter(item -> item.getViewName().equals("编码视图")).map(DockingViewVO::getViewValue).findFirst().orElse(null); |
| | | // 2、比对属性是否和oldDatalist属性一致,不一致就需要更改 |
| | | if(Func.isNotEmpty(viewValueList)){ |
| | | // 3、需要将集团属性转换为我们系统的属性,再和我们系统的现有属性比对 |
| | | String codeclsfid = VciBaseUtil.getMapStrValueIgnoreCase(baseModel.getData(),"CODECLSFID"); |
| | | // 3.1、通过该条数据的分类id,拿到集团属性映射配置,用来将集团的属性映射到我们系统的属性 |
| | | List<DockingPreAttrMapping> dockingPreAttrMappings = dockingPreAttrMappingService.selectByWrapper(Wrappers.<DockingPreAttrMapping>query().lambda().eq(DockingPreAttrMapping::getTargetClassifyId, codeclsfid).eq(DockingPreAttrMapping::getViewName,"编码视图")); |
| | | if(Func.isNotEmpty(dockingPreAttrMappings)){ |
| | | log.info("开始调用sourceAttrKey2TargetKey方法。"); |
| | | //根据集团属性映射将集团转到我们系统,并修改不一致的到我们系统中对应的该条记录的值 |
| | | sourceAttrKey2TargetKey(dockingPreAttrMappings, viewValueList.get(0), baseModel); |
| | | } |
| | | } |
| | | log.info("申请单:"+applyId+",集团码:"+customCoding+"编码:"+baseModel.getId()); |
| | | newDatalist.add(baseModel); |
| | | editObjectMap.put(jdatabtmname,newDatalist); |
| | | } |
| | | } |
| | | } |
| | | List<String> dataOidList=new ArrayList<>(); |
| | | dataOidList.add(jdataid); |
| | | //调用主数据服务批量保存接口 |
| | | mdmEngineClient.updateBatchByType(jdatabtmname,editObjectList); |
| | | } |
| | | dockingPreApplyFormService.saveOrUpdateBatch(dockingPreApplyFormList); |
| | | |
| | | if(!CollectionUtils.isEmpty(editObjectMap)) { |
| | | //调用主数据服务批量保存接口 |
| | | editObjectMap.forEach((btmName, modeList) -> { |
| | | mdmEngineClient.updateBatchBtypeDatas(btmName, modeList); |
| | | }); |
| | | } |
| | | if(!CollectionUtils.isEmpty(dockingPreApplyFormList)){ |
| | | dockingPreApplyFormService.saveOrUpdateBatch(dockingPreApplyFormList); |
| | | } |
| | | saveLogUtil.operateLog("申请单结果返回",false, JSON.toJSONString(dockingReturnStoreVO.getMainData())); |
| | | }catch (Throwable e){ |
| | | e.printStackTrace(); |
| | | return R.fail("集团码集成赋值失败"+e); |
| | | saveLogUtil.operateLog("申请单结果返回",true,"错误信息:"+e.getMessage()+"\n"+ JSON.toJSONString(dockingReturnStoreVO.getMainData())); |
| | | return R.fail("集团码集成赋值失败,原因:"+e.getMessage()); |
| | | } |
| | | log.info("获取集团集团码,赋值到主数据 end"); |
| | | return R.success("集团码赋值成功"); |
| | | } |
| | | |
| | | /** |
| | | * 根据集团属性映射将集团转到我们系统 |
| | | * @param dockingPreAttrMappings |
| | | * @param viewValueMap |
| | | * @param baseModel |
| | | */ |
| | | private void sourceAttrKey2TargetKey(List<DockingPreAttrMapping> dockingPreAttrMappings,Map<String, Object> viewValueMap,BaseModel baseModel) throws ServiceException { |
| | | log.info("开始根据集团属性映射,将集团属性转成编码系统属性,并进行是否修改的比对!"); |
| | | //深拷贝记录下原对象,如果有更改用来放在旧业务数据字段(oldbusinessdata)上 |
| | | BaseModel oldBaseModel = null; |
| | | try { |
| | | oldBaseModel = deepCopy(baseModel); |
| | | } catch (Exception e) { |
| | | log.error("记录旧的业务数据时,baseModel对象深拷贝出现错误,原因:"+e.getMessage()); |
| | | e.printStackTrace(); |
| | | throw new ServiceException("记录旧的业务数据时,baseModel对象深拷贝出现错误,原因:"+e.getMessage()); |
| | | } |
| | | Map<String, Object> targetKeyMap = new CaseInsensitiveMap<>(); |
| | | // 将集团属性转成我们系统属性的map |
| | | dockingPreAttrMappings.stream().forEach(item->{ |
| | | targetKeyMap.put(item.getTargetAttrKey(),viewValueMap.get(item.getSourceAttrKey())); |
| | | }); |
| | | // 比对baseModel的data中的属性是否和targetKeyMap不一致,不一致的话就需要将baseModel的data中的对应key的value值转成集团的 |
| | | boolean isEdit = false; |
| | | // 忽略大小写 |
| | | Map caseInsensitiveMap = new CaseInsensitiveMap(baseModel.getData()); |
| | | for (Map.Entry<String, Object> entry : targetKeyMap.entrySet()) { |
| | | String key = entry.getKey(); |
| | | Object targetValue = entry.getValue(); |
| | | String dataValue = String.valueOf(caseInsensitiveMap.get(key)); |
| | | if (targetValue != null && !targetValue.equals(dataValue)) { |
| | | caseInsensitiveMap.put(key, targetValue.toString()); |
| | | isEdit = true; |
| | | } |
| | | } |
| | | // 集团对我们系统属性做了调整,我们需要对老的业务数据做记录 |
| | | if (isEdit) { |
| | | log.info("集团返回的数据存在差异,开始执行对编码系统basemodel对象修改操作!"); |
| | | // 清空原先的map,使用新的不区分key大小写的map |
| | | baseModel.getData().clear(); |
| | | baseModel.getData().putAll(caseInsensitiveMap); |
| | | // 移除历史的oldbusinessdata字段,否则会超长 |
| | | oldBaseModel.getData().remove("oldbusinessdata"); |
| | | baseModel.getData().put("oldbusinessdata", JSON.toJSONString(oldBaseModel)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 深拷贝 |
| | | * @param baseModel |
| | | * @return |
| | | * @throws ClassNotFoundException |
| | | * @throws IOException |
| | | */ |
| | | public static BaseModel deepCopy(BaseModel baseModel) throws ClassNotFoundException, IOException { |
| | | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| | | ObjectOutputStream oos = new ObjectOutputStream(bos); |
| | | oos.writeObject(baseModel); |
| | | oos.close(); |
| | | |
| | | ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); |
| | | ObjectInputStream ois = new ObjectInputStream(bis); |
| | | BaseModel copy = (BaseModel) ois.readObject(); |
| | | ois.close(); |
| | | |
| | | return copy; |
| | | } |
| | | |
| | | /*** |
| | |
| | | throw new Throwable("存储视图模型出现问题"); |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * 获取分类视图 |
| | | * |
| | | * @param jclassObject |
| | | * @throws Throwable |
| | | */ |
| | | private void getVilewMode(DockingClassifyVO jclassObject, List<DockingClassifyViewVO> list) |
| | | throws Throwable { |
| | | private void getVilewMode(@NotNull DockingClassifyVO jclassObject, List<DockingClassifyViewVO> list) throws Throwable { |
| | | String nodeLinkName = jclassObject.getNodeLinkName(); |
| | | try { |
| | | String jclassId =StringUtils.isBlank(jclassObject.getId())?"":jclassObject.getId(); |
| | | Map<String, DockingPreViewModel> jviewmodelMap = new HashMap<String, DockingPreViewModel>(); |
| | | //Map<String, String> condtionMa = new HashMap<String, String>(); |
| | | // condtionMa.put("jsourceclsfid", jclassId); |
| | | // Map<String, String> condtionMa = new HashMap<String, String>(); |
| | | // condtionMa.put("jsourceclsfid", jclassId); |
| | | List<DockingPreViewModel> dockingPreViewModelList= dockingPreViewModelService.list(Wrappers.<DockingPreViewModel>query().lambda().eq(DockingPreViewModel::getSourceClassifyId,false));// 根据分类查询模型视图对象 |
| | | for (DockingPreViewModel dockingPreViewModel : dockingPreViewModelList) { |
| | | jviewmodelMap.put(dockingPreViewModel.getViewName(),dockingPreViewModel); |
| | |
| | | |
| | | for (DockingClassifyViewVO viewInfo : list) { |
| | | String viewName =StringUtils.isBlank(viewInfo.getViewName())?"":viewInfo.getViewName(); |
| | | String impactList = StringUtils.isBlank(viewInfo.getImpactList())?"":viewInfo.getImpactList(); |
| | | String impactList = viewInfo.getImpactList() == null ? "" : viewInfo.getImpactList().get(0).get(0); |
| | | log.info("VilewMode:-------------->视图名称:"+viewName); |
| | | log.info("VilewMode:-------------->影响编码项:"+impactList); |
| | | log.info("VilewMode:--------------> 集团分类主键:"+jclassId); |
| | |
| | | throw new Throwable("组织分类" + nodeLinkName + "模型视图存储出现问题"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /*** |
| | | * 获取模型视图属性 |