|
@@ -12,28 +12,34 @@ import cn.com.ty.lift.business.project.service.ProjectHistoryService;
|
|
|
import cn.com.ty.lift.common.constants.FieldName;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author bieao
|
|
|
* @date 2020/3/10
|
|
|
* @description BeanUtil
|
|
|
*/
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
public class BeanUtils {
|
|
|
|
|
|
@Resource
|
|
|
- private static ProjectHistoryService projectHistoryService;
|
|
|
+ private ProjectHistoryService projectHistoryService;
|
|
|
|
|
|
@Resource
|
|
|
- private static LiftHistoryService liftHistoryService;
|
|
|
+ private LiftHistoryService liftHistoryService;
|
|
|
|
|
|
@Resource
|
|
|
- private static CapitalRepairHistoryService capitalRepairHistoryService;
|
|
|
+ private CapitalRepairHistoryService capitalRepairHistoryService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -43,23 +49,35 @@ public class BeanUtils {
|
|
|
* @description 比较实体,并存入相应操作记录表
|
|
|
* @date 2020/3/10 12:56 下午
|
|
|
*/
|
|
|
- public static void saveOperaHistory(Object oldEntry, Object newEntry, Long mtCompanyId) {
|
|
|
+ public void saveOperaHistory(Object oldEntry, Object newEntry, Long mtCompanyId) throws NoSuchFieldException {
|
|
|
Map<String, Object> oldResult = BeanUtil.beanToMap(oldEntry);
|
|
|
+ oldResult.remove("createDate");
|
|
|
+ oldResult.remove("updateDate");
|
|
|
+ oldResult.remove("creatorId");
|
|
|
+ oldResult.remove("updateId");
|
|
|
Map<String, Object> newResult = BeanUtil.beanToMap(newEntry);
|
|
|
+ newResult.remove("createDate");
|
|
|
+ newResult.remove("updateDate");
|
|
|
+ newResult.remove("creatorId");
|
|
|
+ newResult.remove("updateId");
|
|
|
List<ProjectHistory> projectHistories = new ArrayList<>();
|
|
|
List<LiftHistory> liftHistories = new ArrayList<>();
|
|
|
List<CapitalRepairHistory> capitalRepairHistories = new ArrayList<>();
|
|
|
for (Map.Entry<String, Object> entry : oldResult.entrySet()) {
|
|
|
Object oldValue = oldResult.get(entry.getKey());
|
|
|
Object newValue = newResult.get(entry.getKey());
|
|
|
- boolean result = ObjectUtil.equal(oldValue, newValue);
|
|
|
- if (!result) {
|
|
|
+ if (Objects.isNull(oldValue) && Objects.isNull(newValue)) continue;
|
|
|
+ if (Objects.isNull(newValue)) continue;
|
|
|
+ Class<?> cls = newEntry.getClass();
|
|
|
+ Field field = cls.getDeclaredField(entry.getKey());
|
|
|
+ if (!field.isAnnotationPresent(FieldName.class)) continue;
|
|
|
+ FieldName fieldName = field.getDeclaredAnnotation(FieldName.class);
|
|
|
+ boolean result = ObjectUtil.notEqual(oldValue, newValue);
|
|
|
+ if (result) {
|
|
|
if (newEntry instanceof Project) {
|
|
|
Project project = (Project) newEntry;
|
|
|
- Class<? extends Project> cls = project.getClass();
|
|
|
- FieldName fieldName = cls.getDeclaredAnnotation(FieldName.class);
|
|
|
ProjectHistory projectHistory = new ProjectHistory();
|
|
|
- projectHistory.setId(project.getId());
|
|
|
+ projectHistory.setProjectId(project.getId());
|
|
|
projectHistory.setMtCompanyId(mtCompanyId);
|
|
|
projectHistory.setOperaItem(fieldName.name());
|
|
|
projectHistory.setDescription("编辑项目信息");
|
|
@@ -67,34 +85,33 @@ public class BeanUtils {
|
|
|
projectHistory.setCode(project.getProjectCode());
|
|
|
projectHistory.setBeforeContent(oldValue.toString());
|
|
|
projectHistory.setAfterContent(newValue.toString());
|
|
|
+ projectHistory.setOperatorId(10000L);
|
|
|
projectHistory.setOperateDate(LocalDateTime.now());
|
|
|
projectHistories.add(projectHistory);
|
|
|
} else if (newEntry instanceof Lift) {
|
|
|
Lift lift = (Lift) newEntry;
|
|
|
- Class<? extends Lift> cls = lift.getClass();
|
|
|
- FieldName fieldName = cls.getDeclaredAnnotation(FieldName.class);
|
|
|
LiftHistory liftHistory = new LiftHistory();
|
|
|
- liftHistory.setId(lift.getId());
|
|
|
+ liftHistory.setLiftId(lift.getId());
|
|
|
liftHistory.setCode(lift.getLiftCode());
|
|
|
liftHistory.setMtCompanyId(mtCompanyId);
|
|
|
liftHistory.setOperaItem(fieldName.name());
|
|
|
liftHistory.setDescription("编辑电梯信息");
|
|
|
liftHistory.setBeforeContent(oldValue.toString());
|
|
|
liftHistory.setAfterContent(newValue.toString());
|
|
|
+ liftHistory.setOperatorId(10000L);
|
|
|
liftHistory.setOperateDate(LocalDateTime.now());
|
|
|
liftHistories.add(liftHistory);
|
|
|
} else if (newEntry instanceof CapitalRepair) {
|
|
|
CapitalRepair repair = (CapitalRepair) newEntry;
|
|
|
- Class<? extends CapitalRepair> cls = repair.getClass();
|
|
|
- FieldName fieldName = cls.getDeclaredAnnotation(FieldName.class);
|
|
|
CapitalRepairHistory capitalRepairHistory = new CapitalRepairHistory();
|
|
|
- capitalRepairHistory.setId(repair.getId());
|
|
|
+ capitalRepairHistory.setProjectId(repair.getId());
|
|
|
capitalRepairHistory.setProjectCode(repair.getProjectCode());
|
|
|
capitalRepairHistory.setMtCompanyId(mtCompanyId);
|
|
|
capitalRepairHistory.setOperaItem(fieldName.name());
|
|
|
capitalRepairHistory.setDescription("编辑大修信息");
|
|
|
capitalRepairHistory.setBeforeContent(oldValue.toString());
|
|
|
capitalRepairHistory.setAfterContent(newValue.toString());
|
|
|
+ capitalRepairHistory.setOperatorId(10000L);
|
|
|
capitalRepairHistory.setOperateDate(LocalDateTime.now());
|
|
|
capitalRepairHistories.add(capitalRepairHistory);
|
|
|
}
|
|
@@ -102,10 +119,13 @@ public class BeanUtils {
|
|
|
}
|
|
|
if (newEntry instanceof Project) {
|
|
|
projectHistoryService.saveBatch(projectHistories, projectHistories.size());
|
|
|
+ log.info("保存项目操作记录:" + projectHistories.size() + "条");
|
|
|
} else if (newEntry instanceof Lift) {
|
|
|
liftHistoryService.saveBatch(liftHistories, liftHistories.size());
|
|
|
+ log.info("保存电梯操作记录:" + liftHistories.size() + "条");
|
|
|
} else if (newEntry instanceof CapitalRepair) {
|
|
|
capitalRepairHistoryService.saveBatch(capitalRepairHistories, capitalRepairHistories.size());
|
|
|
+ log.info("保存大修项目操作记录:" + capitalRepairHistories.size() + "条");
|
|
|
}
|
|
|
}
|
|
|
}
|