|
@@ -1,13 +1,17 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import com.alibaba.druid.sql.visitor.functions.Char;
|
|
|
+import com.ym.mec.biz.dal.dao.DataChangeLogDao;
|
|
|
import com.ym.mec.biz.dal.dto.VipGroupActivityAddDto;
|
|
|
+import com.ym.mec.biz.dal.entity.DataChangeLog;
|
|
|
import com.ym.mec.biz.dal.enums.VipGroupActivityTypeEnum;
|
|
|
+import com.ym.mec.biz.service.DataChangeLogService;
|
|
|
import com.ym.mec.biz.service.LogService;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import io.swagger.annotations.ApiModelProperty;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.*;
|
|
@@ -19,10 +23,8 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class LogServiceImpl implements LogService {
|
|
|
|
|
|
- private static Set<Class<?>> FINAL_CLASS = new HashSet<>(Arrays.asList(int.class,Integer.class,long.class,Long.class,
|
|
|
- float.class,Float.class,double.class,Double.class,
|
|
|
- char.class, Char.class,boolean.class, Boolean.class,
|
|
|
- byte.class,Byte.class,short.class, Short.class, Enum.class));
|
|
|
+ @Autowired
|
|
|
+ private DataChangeLogDao dataChangeLogDao;
|
|
|
|
|
|
private Field[] getAllFields(Object object){
|
|
|
Class clazz = object.getClass();
|
|
@@ -37,10 +39,13 @@ public class LogServiceImpl implements LogService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void entityVariationAnalysis(Object oldEntity, Object newEntity) {
|
|
|
+ public void entityVariationAnalysis(Object oldEntity, Object newEntity, Integer operatorId) {
|
|
|
List<String> changes = new ArrayList<>();
|
|
|
Field[] allFields = getAllFields(oldEntity);
|
|
|
for (Field field : allFields) {
|
|
|
+ if(field.getName().equals("createTime")||field.getName().equals("updateTime")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
ApiModelProperty annotation = field.getAnnotation(ApiModelProperty.class);
|
|
|
if(Objects.isNull(annotation)){
|
|
|
continue;
|
|
@@ -66,23 +71,13 @@ public class LogServiceImpl implements LogService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- System.out.println(StringUtils.join(changes, ";"));
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- VipGroupActivityAddDto vipGroupActivityAddDto = new VipGroupActivityAddDto();
|
|
|
- vipGroupActivityAddDto.setId(1);
|
|
|
- vipGroupActivityAddDto.setStartTime(DateUtil.stringToDate("2020-12-01", "yyyy-MM-dd"));
|
|
|
- vipGroupActivityAddDto.setType(VipGroupActivityTypeEnum.BASE_ACTIVITY);
|
|
|
- vipGroupActivityAddDto.setSalarySettlementJson("默认课酬");
|
|
|
-
|
|
|
- VipGroupActivityAddDto vipGroupActivityAddDto1 = new VipGroupActivityAddDto();
|
|
|
- vipGroupActivityAddDto1.setId(1);
|
|
|
- vipGroupActivityAddDto1.setStartTime(DateUtil.stringToDate("2020-12-11", "yyyy-MM-dd"));
|
|
|
- vipGroupActivityAddDto1.setType(VipGroupActivityTypeEnum.DISCOUNT);
|
|
|
- vipGroupActivityAddDto1.setSalarySettlementJson("固定课酬");
|
|
|
-
|
|
|
- LogServiceImpl logService = new LogServiceImpl();
|
|
|
- logService.entityVariationAnalysis(vipGroupActivityAddDto, vipGroupActivityAddDto1);
|
|
|
+ if(CollectionUtils.isEmpty(changes)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DataChangeLog dataChangeLog = new DataChangeLog();
|
|
|
+ dataChangeLog.setClassName(oldEntity.getClass().getName());
|
|
|
+ dataChangeLog.setChangeInfo(StringUtils.join(changes, ";"));
|
|
|
+ dataChangeLog.setOperatorId(operatorId);
|
|
|
+ dataChangeLogDao.insert(dataChangeLog);
|
|
|
}
|
|
|
}
|