|
@@ -1,5 +1,7 @@
|
|
|
package com.persagy.dmp.rwd.edit.service;
|
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.persagy.common.criteria.CriteriaUtils;
|
|
|
import com.persagy.common.criteria.JacksonCriteria;
|
|
@@ -9,6 +11,7 @@ import com.persagy.common.web.PagedResponse;
|
|
|
import com.persagy.dmp.rwd.edit.config.web.UserUtils;
|
|
|
import com.persagy.dmp.rwd.edit.entity.ClassDef;
|
|
|
import com.persagy.dmp.rwd.edit.entity.ClassDefChangeRecord;
|
|
|
+import com.persagy.dmp.rwd.edit.entity.FuncidDefChangeRecord;
|
|
|
import com.persagy.dmp.rwd.edit.entity.QClassDefChangeRecord;
|
|
|
import com.persagy.dmp.rwd.edit.entity.dto.ClassDefChangeRecordDTO;
|
|
|
import com.persagy.dmp.rwd.edit.enumeration.EnumOperationType;
|
|
@@ -17,9 +20,11 @@ import com.persagy.dmp.rwd.edit.model.DtDataModel;
|
|
|
import com.persagy.dmp.rwd.edit.repository.ClassDefChangeRecordRepository;
|
|
|
import com.persagy.dmp.rwd.edit.repository.ClassDefRepository;
|
|
|
import com.persagy.dmp.rwd.model.ClassDefModel;
|
|
|
+import com.persagy.dmp.rwd.model.FuncidDefModel;
|
|
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
|
|
import io.micrometer.core.instrument.util.StringUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.beanutils.BeanMap;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -106,7 +111,7 @@ public class ClassDefChangeRecordService {
|
|
|
}
|
|
|
//设置设备类名称
|
|
|
if(StringUtils.isNotEmpty(item.getEquipmentCode())){
|
|
|
- changeRecordDTO.setEquipClassName(classDefDataMap.get(item.getEquipmentCode()));
|
|
|
+ changeRecordDTO.setEquipmentName(classDefDataMap.get(item.getEquipmentCode()));
|
|
|
}
|
|
|
result.add(changeRecordDTO);
|
|
|
});
|
|
@@ -123,6 +128,7 @@ public class ClassDefChangeRecordService {
|
|
|
response.setFail("code is required");
|
|
|
return response;
|
|
|
}
|
|
|
+
|
|
|
List<ClassDefModel> classDefList = queryClassDef(code, null, null);
|
|
|
if (EnumOperationType.create.equals(param.getOperationType())) {
|
|
|
if (classDefList.size() > 0) {
|
|
@@ -150,15 +156,17 @@ public class ClassDefChangeRecordService {
|
|
|
param.setSystemCode(classDef.getSystemCode());
|
|
|
param.setEquipmentCode(classDef.getEquipmentCode());
|
|
|
param.setParentCode(classDef.getParentCode());
|
|
|
+ //添加变更记录
|
|
|
+ addChangeRecord(classDef, param);
|
|
|
}
|
|
|
- QClassDefChangeRecord qt = QClassDefChangeRecord.classDefChangeRecord;
|
|
|
+ /*QClassDefChangeRecord qt = QClassDefChangeRecord.classDefChangeRecord;
|
|
|
BooleanExpression ex = qt.code.eq(code).and(qt.state.eq(EnumVersionState.INIT)).and(qt.version.isNull());
|
|
|
Iterable<ClassDefChangeRecord> all = repository.findAll(ex);
|
|
|
List<ClassDefChangeRecord> list = new ArrayList<>();
|
|
|
all.forEach(list::add);
|
|
|
if (list.size() > 0) {
|
|
|
repository.deleteAll(list);
|
|
|
- }
|
|
|
+ }*/
|
|
|
param.setOperationUser(UserUtils.currentUserId() + "");
|
|
|
param.setOperationTime(new Date());
|
|
|
param.setValid(true);
|
|
@@ -401,5 +409,42 @@ public class ClassDefChangeRecordService {
|
|
|
List<ClassDefModel> data = query.getData();
|
|
|
return data;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加变更记录
|
|
|
+ * @param classDef
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ private void addChangeRecord(ClassDefModel classDef, ClassDefChangeRecord param){
|
|
|
+ Map<?, ?> beforeParamMap = new BeanMap(classDef);
|
|
|
+ Map<?, ?> afterParamMap = new BeanMap(param);
|
|
|
+
|
|
|
+ //比较变更记录
|
|
|
+ List<JSONObject> operationContentBefore = new ArrayList<>();
|
|
|
+ List<JSONObject> operationContentAfter = new ArrayList<>();
|
|
|
+ Set<?> keySets = Collections.unmodifiableSet(beforeParamMap.keySet());
|
|
|
+ for (Map.Entry<?, ?> afterEntry : afterParamMap.entrySet()) {
|
|
|
+ Object afterValue = afterEntry.getValue();
|
|
|
+ if(afterValue == null || "class".equals(afterEntry.getKey()) || "".equals(afterValue.toString())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object beforeValue = beforeParamMap.get(afterEntry.getKey());
|
|
|
+ if(!keySets.contains(afterEntry.getKey())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ if(beforeValue == null || (beforeValue!=null && !afterValue.toString().equals(beforeValue.toString()))){
|
|
|
+ //变更前
|
|
|
+ object.put(afterEntry.getKey().toString(),beforeValue);
|
|
|
+ operationContentBefore.add(object);
|
|
|
+ //变更后
|
|
|
+ object = new JSONObject();
|
|
|
+ object.put(afterEntry.getKey().toString(),afterEntry.getValue());
|
|
|
+ operationContentAfter.add(object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ param.setOperationContentBefore(operationContentBefore.toString());
|
|
|
+ param.setOperationContentAfter(operationContentAfter.toString());
|
|
|
+ }
|
|
|
}
|
|
|
|