mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-10-08 21:26:40 +08:00
dataTracer
This commit is contained in:
parent
11850a4dd8
commit
db4b844146
@ -6,7 +6,7 @@ import net.lab1024.smartadmin.service.common.constant.CacheModuleConst;
|
|||||||
import net.lab1024.smartadmin.service.common.constant.StringConst;
|
import net.lab1024.smartadmin.service.common.constant.StringConst;
|
||||||
import net.lab1024.smartadmin.service.common.util.SmartBeanUtil;
|
import net.lab1024.smartadmin.service.common.util.SmartBeanUtil;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.domain.CategoryEntity;
|
import net.lab1024.smartadmin.service.module.business.category.domain.CategoryEntity;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.domain.CategoryTreeVO;
|
import net.lab1024.smartadmin.service.module.business.category.domain.vo.CategoryTreeVO;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -5,7 +5,11 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import net.lab1024.smartadmin.service.common.swagger.SwaggerTagConst;
|
import net.lab1024.smartadmin.service.common.swagger.SwaggerTagConst;
|
||||||
import net.lab1024.smartadmin.service.common.controller.SystemBaseController;
|
import net.lab1024.smartadmin.service.common.controller.SystemBaseController;
|
||||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.domain.*;
|
import net.lab1024.smartadmin.service.module.business.category.domain.form.CategoryAddForm;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.form.CategoryTreeQueryForm;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.form.CategoryUpdateForm;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.vo.CategoryTreeVO;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.vo.CategoryVO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -5,6 +5,11 @@ import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
|||||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.domain.*;
|
import net.lab1024.smartadmin.service.module.business.category.domain.*;
|
||||||
import net.lab1024.smartadmin.service.common.util.SmartBeanUtil;
|
import net.lab1024.smartadmin.service.common.util.SmartBeanUtil;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.form.CategoryAddForm;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.form.CategoryTreeQueryForm;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.form.CategoryUpdateForm;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.vo.CategoryTreeVO;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.vo.CategoryVO;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.dto;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.dto;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
@ -1,6 +1,7 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.form;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.dto.CategoryBaseDTO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类目 添加 DTO 类
|
* 类目 添加 DTO 类
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.form;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
@ -1,7 +1,8 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.form;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.dto.CategoryBaseDTO;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
@ -1,7 +1,8 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.vo;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.dto.CategorySimpleDTO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,7 +1,8 @@
|
|||||||
package net.lab1024.smartadmin.service.module.business.category.domain;
|
package net.lab1024.smartadmin.service.module.business.category.domain.vo;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.domain.dto.CategoryBaseDTO;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -0,0 +1,74 @@
|
|||||||
|
package net.lab1024.smartadmin.service.module.business.goods;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import net.lab1024.smartadmin.service.common.enumeration.BaseEnum;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.goods.domain.GoodsEntity;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.DataTracerFieldService;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.DataTracerService;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.constant.DataTracerBusinessTypeEnum;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.constant.DataTracerOperateTypeEnum;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.domain.DataTracerDTO;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.domain.DataTracerExtraDataDTO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ ]
|
||||||
|
*
|
||||||
|
* @author yandanyang
|
||||||
|
* @date 2021/8/23 10:38
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class GoodsDataTracerService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataTracerService dataTracerService;
|
||||||
|
@Autowired
|
||||||
|
private DataTracerFieldService dataTracerFieldService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void goodsAddRecord(GoodsEntity goodsEntity, LocalDateTime operateTime, Long operatorId, String operatorName) {
|
||||||
|
DataTracerDTO dataTracerDTO = new DataTracerDTO();
|
||||||
|
dataTracerDTO.setBusinessId(goodsEntity.getGoodsId());
|
||||||
|
dataTracerDTO.setBusinessType(DataTracerBusinessTypeEnum.GOODS);
|
||||||
|
dataTracerDTO.setOperateType(DataTracerOperateTypeEnum.Common.SAVE);
|
||||||
|
dataTracerDTO.setOperateContent(DataTracerOperateTypeEnum.Common.SAVE.getDesc());
|
||||||
|
dataTracerDTO.setOperateTime(operateTime);
|
||||||
|
dataTracerService.saveOperateRecord(dataTracerDTO, operatorId, operatorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void goodsUpdateRecord(GoodsEntity originGoodsEntity, GoodsEntity newGoodsEntity, LocalDateTime operateTime, Long operatorId, String operatorName) {
|
||||||
|
String operateContent = dataTracerFieldService.beanParse(originGoodsEntity, newGoodsEntity);
|
||||||
|
DataTracerDTO dataTracerDTO = new DataTracerDTO();
|
||||||
|
dataTracerDTO.setBusinessId(originGoodsEntity.getGoodsId());
|
||||||
|
dataTracerDTO.setBusinessType(DataTracerBusinessTypeEnum.GOODS);
|
||||||
|
dataTracerDTO.setOperateType(DataTracerOperateTypeEnum.Common.UPDATE);
|
||||||
|
dataTracerDTO.setOperateContent(operateContent);
|
||||||
|
dataTracerDTO.setOperateTime(operateTime);
|
||||||
|
dataTracerDTO.setExtraData(new DataTracerExtraDataDTO(GoodsEntity.class, originGoodsEntity, newGoodsEntity));
|
||||||
|
dataTracerService.saveOperateRecord(dataTracerDTO, operatorId, operatorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void batchRecord(List<Long> goodsIdList, String operateContent, BaseEnum operateType, LocalDateTime operateTime, Long operatorId, String operatorName) {
|
||||||
|
List<DataTracerDTO> dataTracerList = Lists.newArrayList();
|
||||||
|
for (Long goodsId : goodsIdList) {
|
||||||
|
DataTracerDTO dataTracerDTO = new DataTracerDTO();
|
||||||
|
dataTracerDTO.setBusinessId(goodsId);
|
||||||
|
dataTracerDTO.setBusinessType(DataTracerBusinessTypeEnum.GOODS);
|
||||||
|
dataTracerDTO.setOperateType(operateType);
|
||||||
|
dataTracerDTO.setOperateContent(operateContent);
|
||||||
|
dataTracerDTO.setOperateTime(operateTime);
|
||||||
|
dataTracerList.add(dataTracerDTO);
|
||||||
|
}
|
||||||
|
dataTracerService.saveBatchOperateRecord(dataTracerList, operatorId, operatorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,15 +4,17 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||||
import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
|
import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
|
||||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||||
|
import net.lab1024.smartadmin.service.common.util.SmartBeanUtil;
|
||||||
|
import net.lab1024.smartadmin.service.common.util.SmartPageUtil;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.CategoryQueryService;
|
import net.lab1024.smartadmin.service.module.business.category.CategoryQueryService;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.constant.CategoryTypeEnum;
|
import net.lab1024.smartadmin.service.module.business.category.constant.CategoryTypeEnum;
|
||||||
import net.lab1024.smartadmin.service.module.business.category.domain.CategoryEntity;
|
import net.lab1024.smartadmin.service.module.business.category.domain.CategoryEntity;
|
||||||
import net.lab1024.smartadmin.service.module.business.goods.domain.*;
|
import net.lab1024.smartadmin.service.module.business.goods.domain.*;
|
||||||
import net.lab1024.smartadmin.service.common.util.SmartBeanUtil;
|
import net.lab1024.smartadmin.service.module.support.datatracer.constant.DataTracerOperateTypeEnum;
|
||||||
import net.lab1024.smartadmin.service.common.util.SmartPageUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -37,6 +39,9 @@ public class GoodsService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CategoryQueryService categoryQueryService;
|
private CategoryQueryService categoryQueryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsDataTracerService goodsDataTracerService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加商品
|
* 添加商品
|
||||||
*
|
*
|
||||||
@ -49,9 +54,9 @@ public class GoodsService {
|
|||||||
if (!res.getOk()) {
|
if (!res.getOk()) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
GoodsEntity goodsEntity = SmartBeanUtil.copy(addForm, GoodsEntity.class);
|
GoodsEntity goodsEntity = SmartBeanUtil.copy(addForm, GoodsEntity.class);
|
||||||
goodsDao.insert(goodsEntity);
|
goodsDao.insert(goodsEntity);
|
||||||
|
goodsDataTracerService.goodsAddRecord(goodsEntity, LocalDateTime.now(), addForm.getUpdateId(), addForm.getUpdateName());
|
||||||
return ResponseDTO.ok();
|
return ResponseDTO.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,9 +72,10 @@ public class GoodsService {
|
|||||||
if (!res.getOk()) {
|
if (!res.getOk()) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
GoodsEntity originEntity = goodsDao.selectById(updateForm.getGoodsId());
|
||||||
GoodsEntity goodsEntity = SmartBeanUtil.copy(updateForm, GoodsEntity.class);
|
GoodsEntity goodsEntity = SmartBeanUtil.copy(updateForm, GoodsEntity.class);
|
||||||
goodsDao.updateById(goodsEntity);
|
goodsDao.updateById(goodsEntity);
|
||||||
|
goodsDataTracerService.goodsUpdateRecord(originEntity,goodsEntity, LocalDateTime.now(), updateForm.getUpdateId(), updateForm.getUpdateName());
|
||||||
return ResponseDTO.ok();
|
return ResponseDTO.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +101,6 @@ public class GoodsService {
|
|||||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "商品名称不能重复~");
|
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "商品名称不能重复~");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验类目id
|
// 校验类目id
|
||||||
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
|
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
|
||||||
if (!optional.isPresent() || !CategoryTypeEnum.GOODS.equalsValue(optional.get().getCategoryType())) {
|
if (!optional.isPresent() || !CategoryTypeEnum.GOODS.equalsValue(optional.get().getCategoryType())) {
|
||||||
@ -120,6 +125,8 @@ public class GoodsService {
|
|||||||
return goodsEntity;
|
return goodsEntity;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
goodsManager.updateBatchById(goodsList);
|
goodsManager.updateBatchById(goodsList);
|
||||||
|
List<Long> goodsIdList = goodsList.stream().map(GoodsEntity::getGoodsId).collect(Collectors.toList());
|
||||||
|
goodsDataTracerService.batchRecord(goodsIdList, "删除商品", DataTracerOperateTypeEnum.Common.DELETE, LocalDateTime.now(), delForm.getUpdateId(), delForm.getUpdateName());
|
||||||
return ResponseDTO.ok();
|
return ResponseDTO.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,12 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.lab1024.smartadmin.service.module.business.category.CategoryDao;
|
||||||
import net.lab1024.smartadmin.service.module.business.goods.constant.GoodsTypeEnum;
|
import net.lab1024.smartadmin.service.module.business.goods.constant.GoodsTypeEnum;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldBigDecimalValue;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldDoc;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldEnumValue;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldSqlValue;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -27,6 +32,8 @@ public class GoodsEntity {
|
|||||||
*
|
*
|
||||||
* @see GoodsTypeEnum
|
* @see GoodsTypeEnum
|
||||||
*/
|
*/
|
||||||
|
@FieldDoc("商品类型")
|
||||||
|
@FieldEnumValue(enumClass = GoodsTypeEnum.class)
|
||||||
private Integer goodsType;
|
private Integer goodsType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,11 +44,13 @@ public class GoodsEntity {
|
|||||||
/**
|
/**
|
||||||
* 商品分类
|
* 商品分类
|
||||||
*/
|
*/
|
||||||
|
@FieldSqlValue(relateColumn = "categoryId",relateDisplayColumn = "categoryName",relateMapper = CategoryDao.class)
|
||||||
private Long categoryId;
|
private Long categoryId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品名称
|
* 商品名称
|
||||||
*/
|
*/
|
||||||
|
@FieldDoc("商品名称")
|
||||||
private String goodsName;
|
private String goodsName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,6 +61,8 @@ public class GoodsEntity {
|
|||||||
/**
|
/**
|
||||||
* 商品价格
|
* 商品价格
|
||||||
*/
|
*/
|
||||||
|
@FieldDoc("商品价格")
|
||||||
|
@FieldBigDecimalValue
|
||||||
private BigDecimal price;
|
private BigDecimal price;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,6 +73,7 @@ public class GoodsEntity {
|
|||||||
/**
|
/**
|
||||||
* 上架状态
|
* 上架状态
|
||||||
*/
|
*/
|
||||||
|
@FieldDoc("上架状态")
|
||||||
private Boolean shelvesFlag;
|
private Boolean shelvesFlag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package net.lab1024.smartadmin.service.module.support.beanrecord;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [ ]
|
|
||||||
*
|
|
||||||
* @author 罗伊
|
|
||||||
*/
|
|
||||||
public enum OperateTypeEnum {
|
|
||||||
|
|
||||||
ADD(1, "新增"),
|
|
||||||
|
|
||||||
UPDATE(2, "修改"),
|
|
||||||
|
|
||||||
DELETE(3, "删除");
|
|
||||||
|
|
||||||
private Integer value;
|
|
||||||
|
|
||||||
private String desc;
|
|
||||||
|
|
||||||
OperateTypeEnum(Integer value, String desc) {
|
|
||||||
this.value = value;
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc() {
|
|
||||||
return desc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +1,16 @@
|
|||||||
package net.lab1024.smartadmin.service.module.support.beanrecord;
|
package net.lab1024.smartadmin.service.module.support.datatracer;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.lab1024.smartadmin.service.module.support.beanrecord.annotation.FieldBigDecimalValue;
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldBigDecimalValue;
|
||||||
import net.lab1024.smartadmin.service.module.support.beanrecord.annotation.FieldDoc;
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldDoc;
|
||||||
import net.lab1024.smartadmin.service.module.support.beanrecord.annotation.FieldEnumValue;
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldEnumValue;
|
||||||
import net.lab1024.smartadmin.service.module.support.beanrecord.annotation.FieldSqlValue;
|
import net.lab1024.smartadmin.service.module.support.datatracer.anno.FieldSqlValue;
|
||||||
|
import net.lab1024.smartadmin.service.module.support.datatracer.constant.DataTracerOperateTypeEnum;
|
||||||
import net.lab1024.smartadmin.service.third.SmartApplicationContext;
|
import net.lab1024.smartadmin.service.third.SmartApplicationContext;
|
||||||
import net.lab1024.smartadmin.service.common.util.SmartBaseEnumUtil;
|
import net.lab1024.smartadmin.service.common.util.SmartBaseEnumUtil;
|
||||||
import net.lab1024.smartadmin.service.common.util.SmartBigDecimalUtil;
|
import net.lab1024.smartadmin.service.common.util.SmartBigDecimalUtil;
|
||||||
@ -29,13 +31,13 @@ import java.util.Map.Entry;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [ ]
|
* [ 对象对比 ]
|
||||||
*
|
*
|
||||||
* @author 罗伊
|
* @author 罗伊
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class BeanRecordService {
|
public class DataTracerFieldService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段描述缓存
|
* 字段描述缓存
|
||||||
@ -59,16 +61,16 @@ public class BeanRecordService {
|
|||||||
if (!valid) {
|
if (!valid) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
OperateTypeEnum operateType = this.getOperateType(oldObjectList, newObjectList);
|
DataTracerOperateTypeEnum.Common operateType = this.getOperateType(oldObjectList, newObjectList);
|
||||||
String operateContent = "";
|
String operateContent = "";
|
||||||
if (OperateTypeEnum.ADD.equals(operateType) || OperateTypeEnum.DELETE.equals(operateType)) {
|
if (DataTracerOperateTypeEnum.Common.SAVE.equals(operateType) || DataTracerOperateTypeEnum.Common.DELETE.equals(operateType)) {
|
||||||
operateContent = this.getObjectListContent(newObjectList);
|
operateContent = this.getObjectListContent(newObjectList);
|
||||||
if (StringUtils.isEmpty(operateContent)) {
|
if (StringUtils.isEmpty(operateContent)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return operateType.getDesc() + ":" + operateContent;
|
return operateType.getDesc() + ":" + operateContent;
|
||||||
}
|
}
|
||||||
if (OperateTypeEnum.UPDATE.equals(operateType)) {
|
if (DataTracerOperateTypeEnum.Common.UPDATE.equals(operateType)) {
|
||||||
return this.getUpdateContentList(oldObjectList, newObjectList);
|
return this.getUpdateContentList(oldObjectList, newObjectList);
|
||||||
}
|
}
|
||||||
return operateContent;
|
return operateContent;
|
||||||
@ -128,12 +130,12 @@ public class BeanRecordService {
|
|||||||
if (!valid) {
|
if (!valid) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
OperateTypeEnum operateType = this.getOperateType(oldObject, newObject);
|
DataTracerOperateTypeEnum.Common operateType = this.getOperateType(oldObject, newObject);
|
||||||
String operateContent = "";
|
String operateContent = "";
|
||||||
if (OperateTypeEnum.ADD.equals(operateType) || OperateTypeEnum.DELETE.equals(operateType)) {
|
if (DataTracerOperateTypeEnum.Common.SAVE.equals(operateType) || DataTracerOperateTypeEnum.Common.DELETE.equals(operateType)) {
|
||||||
operateContent = this.getAddDeleteContent(newObject);
|
operateContent = this.getAddDeleteContent(newObject);
|
||||||
}
|
}
|
||||||
if (OperateTypeEnum.UPDATE.equals(operateType)) {
|
if (DataTracerOperateTypeEnum.Common.UPDATE.equals(operateType)) {
|
||||||
operateContent = this.getUpdateContent(oldObject, newObject);
|
operateContent = this.getUpdateContent(oldObject, newObject);
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(operateContent)) {
|
if (StringUtils.isEmpty(operateContent)) {
|
||||||
@ -149,7 +151,7 @@ public class BeanRecordService {
|
|||||||
* @param object
|
* @param object
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String beanParse(String operateDesc, Object object) {
|
public String beanObjectParse(String operateDesc, Object object) {
|
||||||
String content = this.getAddDeleteContent(object);
|
String content = this.getAddDeleteContent(object);
|
||||||
if (StringUtils.isEmpty(operateDesc)) {
|
if (StringUtils.isEmpty(operateDesc)) {
|
||||||
return content;
|
return content;
|
||||||
@ -303,8 +305,8 @@ public class BeanRecordService {
|
|||||||
}
|
}
|
||||||
String relateFieldValue = fieldValue.toString();
|
String relateFieldValue = fieldValue.toString();
|
||||||
QueryWrapper qw = new QueryWrapper();
|
QueryWrapper qw = new QueryWrapper();
|
||||||
qw.select(fieldSqlValue.relateDisplayColumn());
|
qw.select(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, fieldSqlValue.relateDisplayColumn()));
|
||||||
qw.eq(fieldSqlValue.relateColumn(), relateFieldValue);
|
qw.eq(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, fieldSqlValue.relateColumn()), relateFieldValue);
|
||||||
List<Object> displayValue = mapper.selectObjs(qw);
|
List<Object> displayValue = mapper.selectObjs(qw);
|
||||||
if (CollectionUtils.isEmpty(displayValue)) {
|
if (CollectionUtils.isEmpty(displayValue)) {
|
||||||
return "";
|
return "";
|
||||||
@ -343,14 +345,14 @@ public class BeanRecordService {
|
|||||||
* @param newObject
|
* @param newObject
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private OperateTypeEnum getOperateType(Object oldObject, Object newObject) {
|
private DataTracerOperateTypeEnum.Common getOperateType(Object oldObject, Object newObject) {
|
||||||
if (oldObject == null && newObject != null) {
|
if (oldObject == null && newObject != null) {
|
||||||
return OperateTypeEnum.ADD;
|
return DataTracerOperateTypeEnum.Common.SAVE;
|
||||||
}
|
}
|
||||||
if (oldObject != null && newObject == null) {
|
if (oldObject != null && newObject == null) {
|
||||||
return OperateTypeEnum.DELETE;
|
return DataTracerOperateTypeEnum.Common.DELETE;
|
||||||
}
|
}
|
||||||
return OperateTypeEnum.UPDATE;
|
return DataTracerOperateTypeEnum.Common.UPDATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,18 +368,18 @@ public class BeanRecordService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (oldObject == null && newObject != null) {
|
if (oldObject == null && newObject != null) {
|
||||||
log.info("bean operate log: oldObject is null,new:" + newObject.getClass().getName() + " " + OperateTypeEnum.ADD.getDesc());
|
log.info("bean operate log: oldObject is null,new:" + newObject.getClass().getName() + " " + DataTracerOperateTypeEnum.Common.SAVE.getDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (oldObject != null && newObject == null) {
|
if (oldObject != null && newObject == null) {
|
||||||
log.info("bean operate log: newObject is null,old:" + oldObject.getClass().getName() + " " + OperateTypeEnum.DELETE.getDesc());
|
log.info("bean operate log: newObject is null,old:" + oldObject.getClass().getName() + " " + DataTracerOperateTypeEnum.Common.DELETE.getDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (oldObject != null && newObject != null) {
|
if (oldObject != null && newObject != null) {
|
||||||
String oldClass = oldObject.getClass().getName();
|
String oldClass = oldObject.getClass().getName();
|
||||||
String newClass = newObject.getClass().getName();
|
String newClass = newObject.getClass().getName();
|
||||||
if (oldClass.equals(newClass)) {
|
if (oldClass.equals(newClass)) {
|
||||||
log.info("bean operate log: " + oldObject.getClass().getName() + " " + OperateTypeEnum.UPDATE.getDesc());
|
log.info("bean operate log: " + oldObject.getClass().getName() + " " + DataTracerOperateTypeEnum.Common.UPDATE.getDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log.error("bean operate log: is different class:old:" + oldClass + " new:" + newClass);
|
log.error("bean operate log: is different class:old:" + oldClass + " new:" + newClass);
|
||||||
@ -400,11 +402,11 @@ public class BeanRecordService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isEmpty(oldObjectList) && CollectionUtils.isNotEmpty(newObjectList)) {
|
if (CollectionUtils.isEmpty(oldObjectList) && CollectionUtils.isNotEmpty(newObjectList)) {
|
||||||
log.info("bean operate log: oldObjectList is null,new:" + newObjectList.getClass().getName() + " " + OperateTypeEnum.ADD.getDesc());
|
log.info("bean operate log: oldObjectList is null,new:" + newObjectList.getClass().getName() + " " + DataTracerOperateTypeEnum.Common.SAVE.getDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(oldObjectList) && CollectionUtils.isEmpty(newObjectList)) {
|
if (CollectionUtils.isNotEmpty(oldObjectList) && CollectionUtils.isEmpty(newObjectList)) {
|
||||||
log.info("bean operate log: newObject is null,old:" + oldObjectList.getClass().getName() + " " + OperateTypeEnum.DELETE.getDesc());
|
log.info("bean operate log: newObject is null,old:" + oldObjectList.getClass().getName() + " " + DataTracerOperateTypeEnum.Common.DELETE.getDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(oldObjectList) && CollectionUtils.isNotEmpty(newObjectList)) {
|
if (CollectionUtils.isNotEmpty(oldObjectList) && CollectionUtils.isNotEmpty(newObjectList)) {
|
||||||
@ -413,7 +415,7 @@ public class BeanRecordService {
|
|||||||
String oldClass = oldObject.getClass().getName();
|
String oldClass = oldObject.getClass().getName();
|
||||||
String newClass = newObject.getClass().getName();
|
String newClass = newObject.getClass().getName();
|
||||||
if (oldClass.equals(newClass)) {
|
if (oldClass.equals(newClass)) {
|
||||||
log.info("bean operate log: " + oldObject.getClass().getName() + " " + OperateTypeEnum.UPDATE.getDesc());
|
log.info("bean operate log: " + oldObject.getClass().getName() + " " + DataTracerOperateTypeEnum.Common.UPDATE.getDesc());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log.error("bean operate log: is different class:old:" + oldClass + " new:" + newClass);
|
log.error("bean operate log: is different class:old:" + oldClass + " new:" + newClass);
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.support.beanrecord.annotation;
|
package net.lab1024.smartadmin.service.module.support.datatracer.anno;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.support.beanrecord.annotation;
|
package net.lab1024.smartadmin.service.module.support.datatracer.anno;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.support.beanrecord.annotation;
|
package net.lab1024.smartadmin.service.module.support.datatracer.anno;
|
||||||
|
|
||||||
import net.lab1024.smartadmin.service.common.enumeration.BaseEnum;
|
import net.lab1024.smartadmin.service.common.enumeration.BaseEnum;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.lab1024.smartadmin.service.module.support.beanrecord.annotation;
|
package net.lab1024.smartadmin.service.module.support.datatracer.anno;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
@ -15,7 +15,7 @@ import net.lab1024.smartadmin.service.common.enumeration.BaseEnum;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum DataTracerBusinessTypeEnum implements BaseEnum {
|
public enum DataTracerBusinessTypeEnum implements BaseEnum {
|
||||||
|
|
||||||
NOTICE(1, "系统通知"),
|
GOODS(1, "商品"),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -18,11 +18,9 @@ public interface DataTracerOperateTypeEnum extends BaseEnum {
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
enum Common implements BaseEnum {
|
enum Common implements BaseEnum {
|
||||||
SAVE(0, "保存"),
|
SAVE(1, "保存"),
|
||||||
SAVE_SUBMIT(1, "保存并提交"),
|
|
||||||
UPDATE(2, "更新"),
|
UPDATE(2, "更新"),
|
||||||
UPDATE_SUBMIT(3, "更新并提交"),
|
DELETE(3, "删除");
|
||||||
DELETE(4, "删除");
|
|
||||||
|
|
||||||
private final Integer value;
|
private final Integer value;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user