| | |
| | | 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.springframework.web.bind.annotation.RestController; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | // 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), oldDatalist, baseModel); |
| | | sourceAttrKey2TargetKey(dockingPreAttrMappings, viewValueList.get(0), baseModel); |
| | | } |
| | | } |
| | | log.info("申请单:"+applyId+",集团码:"+customCoding+"编码:"+baseModel.getId()); |
| | |
| | | * 根据集团属性映射将集团转到我们系统 |
| | | * @param dockingPreAttrMappings |
| | | * @param viewValueMap |
| | | * @param oldDatalist |
| | | * @param baseModel |
| | | */ |
| | | private void sourceAttrKey2TargetKey(List<DockingPreAttrMapping> dockingPreAttrMappings,Map<String, Object> viewValueMap, List<BaseModel> oldDatalist,BaseModel baseModel){ |
| | | Map<String, Object> targetKeyMap = new HashMap<>(); |
| | | 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 = baseModel.getData().get(key); |
| | | |
| | | String dataValue = String.valueOf(caseInsensitiveMap.get(key)); |
| | | if (targetValue != null && !targetValue.equals(dataValue)) { |
| | | baseModel.getData().put(key, targetValue.toString()); |
| | | caseInsensitiveMap.put(key, targetValue.toString()); |
| | | isEdit = true; |
| | | } |
| | | } |
| | | // 集团对我们系统属性做了调整,我们需要对老的业务数据做记录 |
| | | if (isEdit) { |
| | | baseModel.getData().put("oldbusinessdata", JSON.toJSONString(oldDatalist)); |
| | | 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; |
| | | } |
| | | |
| | | /*** |
| | | * 接受集团分类主模型数据 |
| | | * @param dockingClassifyModelAttrVO |