|
@@ -3,8 +3,13 @@ package com.persagy.dmp.rwd.digital.service.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.ReflectUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.dmp.rwd.basic.constant.DigitalMessageConstant;
|
|
|
import com.persagy.dmp.rwd.basic.utils.DigitalCommonUtils;
|
|
@@ -17,6 +22,7 @@ import com.persagy.dmp.rwd.digital.dao.ObjectDigitalMapper;
|
|
|
import com.persagy.dmp.rwd.digital.entity.ObjectDigital;
|
|
|
import com.persagy.dmp.rwd.digital.service.IObjectDigitalService;
|
|
|
import com.persagy.dmp.rwd.parser.service.InfoDataFactory;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -78,7 +84,15 @@ public class ObjectDigitalServiceImpl implements IObjectDigitalService {
|
|
|
if(CollUtil.isEmpty(voList)) {
|
|
|
return null;
|
|
|
}
|
|
|
- validateOnSave(voList, true);
|
|
|
+ //获取$remove字段
|
|
|
+ Map<String, Object> removeMap = getRemoveInfo(voList);
|
|
|
+
|
|
|
+ //信息点校验
|
|
|
+ Map<String, Map<String, ObjectInfoDefine>> allInfoMap = validateOnSave(voList, true);
|
|
|
+
|
|
|
+ //获取基础属性
|
|
|
+ Set<String> fieldSet = ReflectUtil.getFieldMap(ObjectDigital.class).keySet();
|
|
|
+
|
|
|
List<String> idList = CollUtil.getFieldValues(voList, BaseEntity.PROP_ID, String.class);
|
|
|
List<ObjectDigital> dbList = dao.selectBatchIds(idList);
|
|
|
Map<String, ObjectDigital> dbMap = CollectionUtil.fieldValueMap(dbList, BaseEntity.PROP_ID);
|
|
@@ -88,11 +102,20 @@ public class ObjectDigitalServiceImpl implements IObjectDigitalService {
|
|
|
if(dbVO == null) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ //数据合并
|
|
|
+ ObjectDigital newDbVO = dbVO;
|
|
|
+ Map<String, ObjectInfoDefine> infoDefineMap = allInfoMap.get(vo.getClassCode());
|
|
|
+ dataMerge(newDbVO,vo,infoDefineMap,fieldSet);
|
|
|
+
|
|
|
+ //移除需要删除的信息点
|
|
|
+ Object remove = removeMap.get(newDbVO.getId());
|
|
|
+ remove(newDbVO,remove,fieldSet);
|
|
|
+
|
|
|
// 修改
|
|
|
- dao.updateById(vo);
|
|
|
+ dao.updateById(newDbVO);
|
|
|
// 修改后消息
|
|
|
- messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_UPDATE, dbVO, vo, false);
|
|
|
-
|
|
|
+ messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_UPDATE, dbVO, newDbVO, false);
|
|
|
});
|
|
|
return voList;
|
|
|
}
|
|
@@ -103,15 +126,15 @@ public class ObjectDigitalServiceImpl implements IObjectDigitalService {
|
|
|
* @param voList
|
|
|
* @param isUpdate
|
|
|
*/
|
|
|
- private void validateOnSave(List<ObjectDigital> voList, boolean isUpdate) {
|
|
|
- validateInfoCode(voList);
|
|
|
+ private Map<String, Map<String, ObjectInfoDefine>> validateOnSave(List<ObjectDigital> voList, boolean isUpdate) {
|
|
|
+ return validateInfoCode(voList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 信息点值校验
|
|
|
* @param voList
|
|
|
*/
|
|
|
- private void validateInfoCode(List<ObjectDigital> voList) {
|
|
|
+ private Map<String, Map<String, ObjectInfoDefine>> validateInfoCode(List<ObjectDigital> voList) {
|
|
|
// 查询信息点定义
|
|
|
List<String> typeCodeList = CollUtil.getFieldValues(voList, "classCode", String.class);
|
|
|
Map<String, Map<String, ObjectInfoDefine>> allInfoMap = infoService.queryByTypes(typeCodeList);
|
|
@@ -141,6 +164,108 @@ public class ObjectDigitalServiceImpl implements IObjectDigitalService {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ return allInfoMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取remove信息点
|
|
|
+ * @param voList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, Object> getRemoveInfo(List<ObjectDigital> voList){
|
|
|
+ Map<String, Object> removeMap = new HashMap<>();
|
|
|
+ for (ObjectDigital digital : voList) {
|
|
|
+ ObjectNode infos = digital.getInfos();
|
|
|
+ if(infos!=null){
|
|
|
+ removeMap.put(digital.getId(),infos.get("$remove"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return removeMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据合并
|
|
|
+ * @param dbVO 源数据
|
|
|
+ * @param vo 目标数据
|
|
|
+ * @param vo 待删除待数据
|
|
|
+ */
|
|
|
+ private void dataMerge(ObjectDigital dbVO,ObjectDigital vo,Map<String, ObjectInfoDefine> infoDefineMap,Set<String> fieldSet){
|
|
|
+ //基础属性处理
|
|
|
+ handleBasicColumn(dbVO,vo);
|
|
|
+ //动态信息点处理
|
|
|
+ ObjectNode infos = vo.getInfos();
|
|
|
+ for (Map.Entry<String, ObjectInfoDefine> entry : infoDefineMap.entrySet()) {
|
|
|
+ String code = entry.getKey();
|
|
|
+ if(fieldSet.contains(code)){
|
|
|
+ //属于基础信息点
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!infos.has(code)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonNode value = infos.get(code);
|
|
|
+ if (dbVO.getInfos() == null) {
|
|
|
+ dbVO.setInfos(JsonNodeFactory.instance.objectNode());
|
|
|
+ }
|
|
|
+ dbVO.getInfos().set(code, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 基础属性处理
|
|
|
+ * @param dbVO
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ private void handleBasicColumn(ObjectDigital dbVO,ObjectDigital vo){
|
|
|
+ if(StringUtils.isNotEmpty(vo.getName())){
|
|
|
+ dbVO.setName(vo.getName());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(vo.getLocalId())){
|
|
|
+ dbVO.setLocalId(vo.getLocalId());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(vo.getLocalName())){
|
|
|
+ dbVO.setLocalName(vo.getLocalName());
|
|
|
+ }
|
|
|
+ if(vo.getVirtualCodes()!=null){
|
|
|
+ dbVO.setVirtualCodes(vo.getVirtualCodes());
|
|
|
+ }
|
|
|
+ if(vo.getValid()!=null){
|
|
|
+ dbVO.setValid(vo.getValid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除需要移除的信息点
|
|
|
+ * @param dbVO
|
|
|
+ * @param remove
|
|
|
+ * @param BasicfieldSet
|
|
|
+ */
|
|
|
+ private void remove(ObjectDigital dbVO,Object remove,Set<String> BasicfieldSet){
|
|
|
+ if(remove == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray array = JSONArray.parseArray(remove.toString());
|
|
|
+ array.forEach(item->{
|
|
|
+ String removeCode = (String) item;
|
|
|
+ if(BasicfieldSet.contains(removeCode)){
|
|
|
+ //基础信息
|
|
|
+ if("name".equals(removeCode)){
|
|
|
+ dbVO.setName(null);
|
|
|
+ }
|
|
|
+ if("localId".equals(removeCode)){
|
|
|
+ dbVO.setLocalId(null);
|
|
|
+ }
|
|
|
+ if("localName".equals(removeCode)){
|
|
|
+ dbVO.setLocalName(null);
|
|
|
+ }
|
|
|
+ if("virtualCodes".equals(removeCode)){
|
|
|
+ dbVO.setVirtualCodes(new ArrayList<>());
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dbVO.getInfos().remove(removeCode);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|