Commit 5bc7c1e3 authored by 李灿灿's avatar 李灿灿

feat:操作变更记录

parent c6215801
package com.yifu.cloud.plus.v1.yifu.insurances.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author licancan
* @description 业务操作记录表 t_business_operate
* @date 2022-12-08 10:20:16
*/
@TableName(value ="t_business_operate")
@Data
@Schema(description = "业务操作记录表")
public class TBusinessOperate extends BaseEntity {
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private String id;
/**
* 业务表id
*/
@Schema(description = "业务表id")
private String businessId;
/**
* 原来的信息
*/
@Schema(description = "原来的信息")
private String oldInfo;
/**
* 新的信息
*/
@Schema(description = "新的信息")
private String newInfo;
/**
* 操作描述
*/
@Schema(description = "操作描述:差异的信息(属性名称,逗号隔开)")
private String differenceInfo;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.yifu.cloud.plus.v1.yifu.insurances.mapper.insurances;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TBusinessOperate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author licancan
* @description 针对表【t_business_operate(业务操作记录表)】的数据库操作Mapper
* @date 2022-12-08 10:20:16
*/
@Mapper
public interface TBusinessOperateMapper extends BaseMapper<TBusinessOperate> {
}
package com.yifu.cloud.plus.v1.yifu.insurances.service.insurance;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TBusinessOperate;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author licancan
* @description 针对表【t_business_operate(业务操作记录表)】的数据库操作Service
* @date 2022-12-08 10:20:16
*/
public interface TBusinessOperateService extends IService<TBusinessOperate> {
/**
* 保存修改记录
*
* @author licancan
* @param businessId 业务表主键
* @param oldInfo 老的实体类
* @param newInfo 新的实体类
* @param remark 备注
* @return {@link TBusinessOperate}
*/
<T> TBusinessOperate saveModificationRecord(String businessId, T oldInfo, T newInfo, String remark);
/**
* 根据业务主键获取操作记录
*
* @author licancan
* @param businessId
* @return {@link List<TBusinessOperate>}
*/
List<TBusinessOperate> getOperateListByBusinessId(String businessId);
}
package com.yifu.cloud.plus.v1.yifu.insurances.service.insurance.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.equator.HrEquator;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TBusinessOperate;
import com.yifu.cloud.plus.v1.yifu.insurances.mapper.insurances.TBusinessOperateMapper;
import com.yifu.cloud.plus.v1.yifu.insurances.service.insurance.TBusinessOperateService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import static com.alibaba.fastjson.serializer.SerializerFeature.*;
/**
* @author licancan
* @description 针对表【t_business_operate(业务操作记录表)】的数据库操作Service实现
* @date 2022-12-08 10:20:16
*/
@Service
public class TBusinessOperateServiceImpl extends ServiceImpl<TBusinessOperateMapper, TBusinessOperate> implements TBusinessOperateService {
/**
* 保存修改记录
*
* @param businessId 业务表主键
* @param oldInfo 老的实体类
* @param newInfo 新的实体类
* @param remark 备注
* @return {@link TBusinessOperate}
* @author licancan
*/
@Override
public <T> TBusinessOperate saveModificationRecord(String businessId, T oldInfo, T newInfo, String remark) {
try{
//比较记录不影响业务逻辑,用try套住
//比较差异
String differenceKey = HrEquator.comparisonValue(oldInfo, newInfo);
//如果有差异保存差异
if(!Common.isEmpty(differenceKey)){
TBusinessOperate operate = new TBusinessOperate();
operate.setBusinessId(businessId);
operate.setCreateTime(LocalDateTime.now());
operate.setOldInfo(JSON.toJSONString(oldInfo,features));
operate.setNewInfo(JSON.toJSONString(newInfo,features));
operate.setDifferenceInfo(differenceKey);
operate.setRemark(remark);
baseMapper.insert(operate);
return operate;
}
}catch (Exception e){
log.error(JSON.toJSON(oldInfo)+"插入修改记录报错>>>",e);
}
return null;
}
/**
* 根据业务主键获取操作记录
*
* @param businessId
* @return {@link List <TBusinessOperate>}
* @author licancan
*/
@Override
public List<TBusinessOperate> getOperateListByBusinessId(String businessId) {
List<TBusinessOperate> list = this.baseMapper.selectList(Wrappers.<TBusinessOperate>query().lambda()
.eq(TBusinessOperate::getBusinessId,businessId));
return list;
}
private SerializerFeature[] features = new SerializerFeature[] {
WriteMapNullValue, WriteNullNumberAsZero, WriteNullListAsEmpty,
WriteNullStringAsEmpty,WriteDateUseDateFormat
};
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.yifu.insurances.mapper.insurances.TBusinessOperateMapper">
<resultMap id="BaseResultMap" type="com.yifu.cloud.plus.v1.yifu.insurances.entity.TBusinessOperate">
<id property="id" column="ID" jdbcType="VARCHAR"/>
<result property="businessId" column="BUSINESS_ID" jdbcType="VARCHAR"/>
<result property="oldInfo" column="OLD_INFO" jdbcType="VARCHAR"/>
<result property="newInfo" column="NEW_INFO" jdbcType="VARCHAR"/>
<result property="differenceInfo" column="DIFFERENCE_INFO" jdbcType="VARCHAR"/>
<result property="remark" column="REMARK" jdbcType="VARCHAR"/>
<result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
<result property="createName" column="CREATE_NAME" jdbcType="VARCHAR"/>
<result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
<result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
ID,BUSINESS_ID,OPERATE_DESC,
REMARK,CREATE_BY,CREATE_NAME,
CREATE_TIME,UPDATE_BY,
UPDATE_TIME
</sql>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment