|
|
|
@ -3,24 +3,20 @@ package com.dxhy.order.baseservice.module.commodity.service.impl; |
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.dxhy.order.baseservice.annotation.FieldName; |
|
|
|
|
import com.dxhy.order.baseservice.config.UserCenterConfig; |
|
|
|
|
import com.dxhy.order.baseservice.module.base.service.BaseService; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.constant.CommodityModifiyLogKeyNameEnum; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.dao.CommodityCodeModifyLogDao; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.CommodityCodeEntity; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.CommodityCodeModifyLog; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.GroupCommodity; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.dto.QueryModifyLogDTO; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.dto.QueryModifyLogResultDTO; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.model.dto.UserInfoDTO; |
|
|
|
|
import com.dxhy.order.baseservice.module.commodity.service.CommodityCodeModifyLogService; |
|
|
|
|
import com.dxhy.order.constant.ConfigureConstant; |
|
|
|
|
import com.dxhy.order.model.PageUtils; |
|
|
|
|
import com.dxhy.order.model.R; |
|
|
|
|
import com.dxhy.order.utils.HttpUtils; |
|
|
|
|
import com.dxhy.order.utils.JsonUtils; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
@ -31,7 +27,9 @@ import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.lang.annotation.Annotation; |
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
@ -73,34 +71,48 @@ public class CommodityCodeModifyLogServiceImpl implements CommodityCodeModifyLog |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Field[] fields = CommodityCodeEntity.class.getDeclaredFields(); |
|
|
|
|
List<CommodityCodeModifyLog> modifyLogs = new ArrayList<>(); |
|
|
|
|
for (int i = 0; i < fields.length; i++) { |
|
|
|
|
Field tempField = fields[i]; |
|
|
|
|
tempField.setAccessible(true); |
|
|
|
|
CommodityCodeModifyLog modifyLog = new CommodityCodeModifyLog(); |
|
|
|
|
modifyLog.setId(baseService.getGenerateShotKey()); |
|
|
|
|
modifyLog.setCommodityCodeId(originOne.getCommodityId()); |
|
|
|
|
modifyLog.setModifyTime(new Date()); |
|
|
|
|
modifyLog.setModifyUserId(Long.toString(modifyUserId)); |
|
|
|
|
|
|
|
|
|
List<JSONObject> compareResultList = new ArrayList<>(); |
|
|
|
|
// Class<? extends Class> aClass = CommodityCodeEntity.class.getClass();
|
|
|
|
|
|
|
|
|
|
Class<? extends CommodityCodeEntity> aClass = originOne.getClass(); |
|
|
|
|
Field[] declaredFields = aClass.getDeclaredFields(); |
|
|
|
|
for (Field declaredField : declaredFields) { |
|
|
|
|
FieldName annotation = declaredField.getAnnotation(FieldName.class); |
|
|
|
|
String fieldName = ""; |
|
|
|
|
if(annotation==null || StringUtils.isBlank(fieldName = annotation.name())){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); |
|
|
|
|
Object originValue = null; |
|
|
|
|
Object newValue = null; |
|
|
|
|
try { |
|
|
|
|
Object originValue = tempField.get(originOne) == null?"":tempField.get(originOne); |
|
|
|
|
Object newValue = tempField.get(newOne) == null?"":tempField.get(newOne); |
|
|
|
|
if (!originValue.equals(newValue)) { |
|
|
|
|
CommodityCodeModifyLog modifyLog = new CommodityCodeModifyLog(); |
|
|
|
|
modifyLog.setId(baseService.getGenerateShotKey()); |
|
|
|
|
modifyLog.setCommodityCodeId(originOne.getCommodityId()); |
|
|
|
|
modifyLog.setKey(tempField.getName()); |
|
|
|
|
modifyLog.setOriginValue(originValue.toString()); |
|
|
|
|
modifyLog.setOriginValue(originValue.toString()); |
|
|
|
|
modifyLog.setModifyTime(new Date()); |
|
|
|
|
modifyLog.setModifyUserId(Long.toString(modifyUserId)); |
|
|
|
|
modifyLogs.add(modifyLog); |
|
|
|
|
} |
|
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
Method getMethod = aClass.getDeclaredMethod(getMethodName); |
|
|
|
|
originValue = getMethod.invoke(originOne)==null?"":getMethod.invoke(originOne); |
|
|
|
|
newValue = getMethod.invoke(newOne)==null?"":getMethod.invoke(newOne); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
if (!originValue.equals(newValue)) { |
|
|
|
|
jsonObject.put("keyName",annotation.fileName()); |
|
|
|
|
jsonObject.put("originValue",originValue); |
|
|
|
|
jsonObject.put("newValue",newValue); |
|
|
|
|
compareResultList.add(jsonObject); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(modifyLogs.isEmpty()){ |
|
|
|
|
modifyLog.setCompareData(JSONObject.toJSONString(compareResultList)); |
|
|
|
|
|
|
|
|
|
if(compareResultList.isEmpty()){ |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
// 批量插入保存
|
|
|
|
|
return commodityCodeModifyLogDao.batchInsert(modifyLogs); |
|
|
|
|
return commodityCodeModifyLogDao.insertCommodityLog(modifyLog); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -161,10 +173,10 @@ public class CommodityCodeModifyLogServiceImpl implements CommodityCodeModifyLog |
|
|
|
|
|
|
|
|
|
Date modifyDate = commodityCodeModifyLogs.size() > 0 ? commodityCodeModifyLogs.get(commodityCodeModifyLogs.size() - 1).getModifyTime() : null; |
|
|
|
|
String modifyUserName = commodityCodeModifyLogs.size() > 0 ? commodityCodeModifyLogs.get(commodityCodeModifyLogs.size() - 1).getModifyUserName() : null; |
|
|
|
|
// PageInfo<CommodityCodeModifyLog> pageInfo = new PageInfo<>(commodityCodeModifyLogs);
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
|
|
|
|
|
QueryModifyLogResultDTO resultDTO = new QueryModifyLogResultDTO(); |
|
|
|
|
//resultDTO.setPageUtils(pageInfo.getList());
|
|
|
|
|
resultDTO.setList(commodityCodeModifyLogs); |
|
|
|
|
resultDTO.setCompareData(commodityCodeModifyLogs.size() > 0?JSONObject.parseArray(commodityCodeModifyLogs.get(0).getCompareData()):new ArrayList()); |
|
|
|
|
resultDTO.setModifyDate(modifyDate); |
|
|
|
|
resultDTO.setModifyUserName(modifyUserName); |
|
|
|
|
return resultDTO; |
|
|
|
|