diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java index 12bf1e34..feb73f1a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysCustomer.java @@ -1,6 +1,7 @@ package com.ruoyi.system.domain; import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.annotation.FieldCompare; import com.ruoyi.common.core.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -24,123 +25,179 @@ public class SysCustomer extends BaseEntity private Long id; /** 客户/企业代码 */ + @FieldCompare(chineseName = "客户/企业代码") @Excel(name = "客户/企业ID") private String enterpriseCode; /** 客户/企业名称 */ + @FieldCompare(chineseName = "客户/企业名称") @Excel(name = "客户/企业名称") private String enterpriseName; + /** 英文名称 */ + @FieldCompare(chineseName = "英文名称") @Excel(name = "英文名称") private String englishName; + /** 客户简称 */ + @FieldCompare(chineseName = "客户简称") @Excel(name = "客户简称") private String customerAbbreviation; /** 事业部 */ + @FieldCompare(chineseName = "事业部") @Excel(name = "事业部") private String customerPurser; - /** 内外销 */ + /** 内外销(1外销、2内销) */ + @FieldCompare(chineseName = "内外销",properties = "1:外销,2:内销") @Excel(name = "内外销") private String exportSales; - /** 国家地区 */ + /** 国家地区(1中国、2美国、3俄罗斯) */ + @FieldCompare(chineseName = "国家地区",properties = "1:中国,2:美国,3:俄罗斯") @Excel(name = "国家地区") private String customerCountry; + /** 邮编 */ + @FieldCompare(chineseName = "邮编") @Excel(name = "邮编") private String postalCode; + /** 公司地址 */ + @FieldCompare(chineseName = "公司地址") @Excel(name = "公司地址") private String customerAddress; + /** 法人代表 */ + @FieldCompare(chineseName = "法人代表") @Excel(name = "法人代表") private String legalRepresentative; + /** 成立日期 */ + @FieldCompare(chineseName = "成立日期") @Excel(name = "成立日期") private String establishedTime; /** 开票表编号 */ @Excel(name = "开票客户名称") private String invoicingCustomerName; + /** 开票公司名称 */ + @FieldCompare(chineseName = "开票公司名称") @Excel(name = "开票公司名称") private String invoicingCompanyName; + + /** 开票公司税号代码 */ + @FieldCompare(chineseName = "开票公司税号") @Excel(name = "开票公司税号") private String invoiceCode; /** 开户银行 */ + @FieldCompare(chineseName = "开户银行") @Excel(name = "开户银行") private String depositBank; /** 开户银行账号 */ + @FieldCompare(chineseName = "开户银行账号") @Excel(name = "开户银行账号") private String bankAccount; - /** 常用币种 */ + + + /** 报价币种(1RMB、2美元) */ + @FieldCompare(chineseName = "报价币种",properties = "1:RMB,2:美元") @Excel(name = "报价币种") private String commonCurrency; - /** 是否含税 */ + /** 是否含税(0不含税、1含税) */ + @FieldCompare(chineseName = "是否含税",properties = "0:不含税,1:含税") @Excel(name = "是否含税") private String confirmTax; /** 税率 */ + @FieldCompare(chineseName = "税率") @Excel(name = "税率") private Double taxRate; - /** 诚信评级 */ + /** 诚信评级(1A、2B、3C、4D) */ + @FieldCompare(chineseName = "诚信评级",properties = "1:A,2:B,3:C,4:D") @Excel(name = "诚信评级") private String integrityRating; /** RMB注册资金 */ + @FieldCompare(chineseName = "RMB注册资金") @Excel(name = "RMB注册资金") private String rmbRegisteredCapital; /** 外币注册资金 */ + @FieldCompare(chineseName = "外币注册资金") @Excel(name = "外币注册资金") private String registeredCapital; + /** 付款条件 */ + @FieldCompare(chineseName = "付款条件") @Excel(name = "付款条件") private String paymentTerms; + /** 海关代码 */ + @FieldCompare(chineseName = "海关代码") @Excel(name = "海关代码") private String customsCode; /*客户第一联系人id*/ private Long customerContactId; + /** 客户第一联系人 */ + @FieldCompare(chineseName = "客户第一联系人") @Excel(name = "客户第一联系人") private String customerContact; + /** 客户第一联系人职务 */ + @FieldCompare(chineseName = "客户第一联系人职务") @Excel(name = "客户第一联系人职务") private String customerOffice; + /** 客户第一联系人电话 */ + @FieldCompare(chineseName = "客户第一联系人电话") @Excel(name = "客户第一联系人电话") private String contactNumber; + /** 客户第一联系人邮箱 */ + @FieldCompare(chineseName = "客户第一联系人邮箱") @Excel(name = "客户第一联系人邮箱") private String customerEmail; + /** 客户第一联系人传真 */ + @FieldCompare(chineseName = "客户第一联系人传真") @Excel(name = "客户第一联系人传真") private String customerFax; - /** 客户第一联系人 */ @Excel(name = "客户第一收货人id") private Long deliveryAddressId; - /** 客户第一联系人 */ + + /** 客户第一收货人 */ + @FieldCompare(chineseName = "客户第一收货人") @Excel(name = "客户第一收货人") private String deliveryCustomerPerson; + + @Excel(name = "客户第一收货人职务") + private String deliveryCustomerOffice; + + @FieldCompare(chineseName = "客户第一收货人联系电话") @Excel(name = "客户第一收货人联系电话") private String deliveryCustomerPhone; + /** 客户第一收货人地址 */ + @FieldCompare(chineseName = "客户第一收货人地址") @Excel(name = "客户第一收货人地址") private String deliveryAddress; + @FieldCompare(chineseName = "客户第一收货人邮编") @Excel(name = "客户第一收货人邮编") private String deliveryCustomerPostal; + @FieldCompare(chineseName = "客户第一收货人传真") @Excel(name = "客户第一收货人传真") private String deliveryCustomerFax; @@ -170,6 +227,7 @@ public class SysCustomer extends BaseEntity private String useStatus; //1表示潜在客户(仅报价) 2表示 客户(已下单) + @FieldCompare(chineseName = "客户标识",properties = "1:潜在客户,2:客户") @Excel(name = "客户标识",dictType = "sys_customer_sign") private String customerSign; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java index cff3eb4f..b92f35a3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysCustomerService.java @@ -93,7 +93,6 @@ public interface ISysCustomerService public ProcessInstance submitApply(SysCustomer sysCustomer); - @Transactional(rollbackFor = Exception.class) int updateSysCustomerVo(SysCustomer sysCustomer); CustomerDto selectCustomerDtoByEnterpriseCode(String customerId); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java index 98755b4e..9c304744 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java @@ -2,12 +2,16 @@ package com.ruoyi.system.service.impl; import com.github.pagehelper.Page; import com.ruoyi.aftersales.domain.dto.CustomerDto; +import com.ruoyi.common.constant.BusinessKeysConstants; +import com.ruoyi.common.core.domain.entity.SysFieldDifferent; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.page.PageDomain; import com.ruoyi.common.core.page.TableSupport; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.FieldCompareUtil; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.process.general.service.IProcessService; @@ -17,8 +21,10 @@ import com.ruoyi.system.mapper.SysCustomerMapper; import com.ruoyi.system.mapper.SysInvoiceMapper; import com.ruoyi.system.mapper.SysUserMapper; import com.ruoyi.system.service.ISysCustomerService; +import com.ruoyi.system.service.ISysDiffLogService; import com.ruoyi.system.service.ISysInvoiceService; import com.ruoyi.system.service.ISysRoleService; +import lombok.SneakyThrows; import org.activiti.engine.TaskService; import org.activiti.engine.impl.persistence.entity.TaskEntityImpl; import org.activiti.engine.runtime.ProcessInstance; @@ -74,6 +80,9 @@ public class SysCustomerServiceImpl implements ISysCustomerService @Autowired private ISysRoleService roleService; + @Autowired + private ISysDiffLogService diffLogService; + @Override public SysCustomerVo selectSysCustomerById(Long id) { SysCustomerVo sysCustomerVo = sysCustomerMapper.selectSysCustomerById(id); @@ -182,6 +191,8 @@ public class SysCustomerServiceImpl implements ISysCustomerService @Override public int insertSysCustomer(SysCustomer sysCustomer) { + + SysDiffLog sysDiffLog = new SysDiffLog(); String loginName = ShiroUtils.getLoginName(); sysCustomer.setCreateBy(loginName); sysCustomer.setCreateTime(DateUtils.getNowDate()); @@ -230,6 +241,15 @@ public class SysCustomerServiceImpl implements ISysCustomerService // sysInvoiceService.insertSysInvoice(invoice); int result = sysCustomerMapper.insertSysCustomer(sysCustomer); sysCustomer.getCustomerId(); + Long id = sysCustomer.getId(); + sysDiffLog.setBusinessId(id); + sysDiffLog.setBusinessKey(BusinessKeysConstants.SYS_CUSTOMER); + sysDiffLog.setCreateTime(DateUtils.getNowDate()); + sysDiffLog.setCreateBy(loginName); + int insertSysDiffLog = diffLogService.insertSysDiffLog(sysDiffLog); + if (insertSysDiffLog <= 0){ + throw new BusinessException("添加客户基本信息修改记录失败"); + } return result; } @@ -249,7 +269,7 @@ public class SysCustomerServiceImpl implements ISysCustomerService - @Transactional(rollbackFor = Exception.class) + @SneakyThrows @Override public int updateSysCustomerVo(SysCustomer sysCustomer){ SysUser user = ShiroUtils.getSysUser(); @@ -268,6 +288,20 @@ public class SysCustomerServiceImpl implements ISysCustomerService }else { sysCustomer.setUsdFlag("0"); } + + Long id = sysCustomer.getId(); + SysCustomer oldSysCustomer = sysCustomerMapper.selectSysCustomerById(id); + if (oldSysCustomer == null){ + throw new BusinessException("客户信息不存在"); + } + List compare = FieldCompareUtil.compare(SysCustomer.class, sysCustomer, oldSysCustomer); + if (!CollectionUtils.isEmpty(compare)){ + int updateSysDiffLog = diffLogService.updateSysDiffLogByBusiness(id, BusinessKeysConstants.SYS_CUSTOMER, compare); + if (updateSysDiffLog <= 0){ + throw new BusinessException("修改客户信息数据修改记录失败"); + } + } + // 启动流程 return sysCustomerMapper.updateSysCustomer(sysCustomer); } @@ -504,6 +538,9 @@ public class SysCustomerServiceImpl implements ISysCustomerService // 使用状态-是 sysCustomer.setUseStatus("1"); } + + + sysCustomerMapper.updateSysCustomer(sysCustomer); return processInstance; } diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml index f52be75b..03ccc6d0 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml @@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -73,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" customer_contact_id,customer_contact,customer_office,contact_number,customer_email,customer_fax, delivery_address_id,delivery_customer_person,delivery_customer_phone, delivery_address,delivery_customer_postal,delivery_customer_fax,business_members, - identifying_people,first_add_time,update_info_time, create_time ,audit_status,use_status,update_by,rmb_flag,usd_flag, cancel_remark, + identifying_people,first_add_time,update_info_time, create_time ,audit_status,use_status,update_by, update_time,rmb_flag,usd_flag, cancel_remark, apply_user,apply_time , instance_id , instance_type from sys_customer @@ -85,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" customer_contact_id,customer_contact,customer_office,contact_number,customer_email,customer_fax, delivery_address_id,delivery_customer_person,delivery_customer_phone, delivery_address,delivery_customer_postal,delivery_customer_fax,business_members,rmb_flag,usd_flag, - identifying_people,first_add_time,update_info_time,audit_status,use_status, create_time from + identifying_people,first_add_time,update_info_time,audit_status,use_status, create_time,update_time from sys_customer and audit_status = '1' and use_status = '1' @@ -102,7 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" s.customer_fax,s.delivery_address_id,s.delivery_customer_person,s.delivery_customer_phone,s.delivery_address, s.delivery_customer_postal,s.delivery_customer_fax,s.business_members,s.identifying_people,s.first_add_time, s.update_info_time,s.audit_status,s.use_status,s.update_by,s.instance_id, s.instance_type,p.dict_value as instance_type_name, - s.submit_instance_id, s.cancel_instance_id, s.restore_instance_id, s.apply_title, s.apply_user, s.apply_time ,s.create_time,s.rmb_flag,s.usd_flag + s.submit_instance_id, s.cancel_instance_id, s.restore_instance_id, s.apply_title, s.apply_user, s.apply_time ,s.create_time,s.update_time ,s.rmb_flag,s.usd_flag from sys_customer as s left join( select dict_value,dict_label from sys_dict_data where dict_type = 'processType' diff --git a/ruoyi-admin/src/main/resources/templates/system/customer/customer.html b/ruoyi-admin/src/main/resources/templates/system/customer/customer.html index 98883862..73bb22bb 100644 --- a/ruoyi-admin/src/main/resources/templates/system/customer/customer.html +++ b/ruoyi-admin/src/main/resources/templates/system/customer/customer.html @@ -7,49 +7,6 @@ -
@@ -142,7 +99,7 @@
-
+
@@ -455,8 +412,18 @@ restoreUrl: prefix + "/restore/{id}", modalName: "客户基本信息", fixedColumns:true, - sortable: true,//开启排序 + showFooter: true, fixedRightNumber:1, + sortable: true, // 是否启用排序 + sortStable: true, // 设置为 true 将获得稳定的排序 + onDblClickCell: function (field,value,row, $element){ + var businessId = row.id; + var businessKey = "3"; + if (field == 'updateTime'){ + var url = ctx + "system/diffLog/getDiffDataList/" + businessId + "/" + businessKey; + $.modal.open("数据修改记录",url); + } + }, columns: [ {checkbox: true}, {title: '主键ID',field: 'id',visible: false}, @@ -473,6 +440,7 @@ return '' + value + ''; } }, + {title: '业务员',field: 'businessMembers',visible: false}, { title: '审核状态',field: 'auditStatus', visible: false, formatter: function (value, row, index) { return $.table.selectDictLabel(auditStatusDatas, value);} }, @@ -487,96 +455,88 @@ return '' + value + '';} }, - {field: 'applyUserName', title: '申请人', + {field: 'applyUserName', title: '申请人',align: 'center', formatter: function(value, row, index) { return '' + (value ? value : "-") + ''; } }, - - {title: '客户ID',field: 'enterpriseCode' }, - {title: '客户公司名称',field: 'enterpriseName'}, - {title: '客户公司简称',field: 'customerAbbreviation'}, - {title: '英文名称',field: 'englishName'}, - {title: '公司地址',field: 'customerAddress'}, - {title: '送货地址',field: 'deliveryAddress'}, - {title: '使用状态',field: 'useStatus', + {title: '客户ID',field: 'enterpriseCode',align: 'center',}, + {title: '客户公司名称',field: 'enterpriseName',align: 'center',}, + {title: '客户公司简称',field: 'customerAbbreviation',align: 'center',}, + {title: '英文名称',field: 'englishName',align: 'center',}, + {title: '公司地址',field: 'customerAddress',align: 'center', + formatter: function(value, row, index) { + return $.table.tooltip(value,5,"open"); + } + }, + {title: '送货地址',field: 'deliveryAddress',align: 'center', + formatter: function(value, row, index) { + return $.table.tooltip(value,5,"open"); + } + }, + {title: '使用状态',field: 'useStatus',align: 'center', formatter: function (value, row, index) {return $.table.selectDictLabel(useStatusDatas, value);}, }, - {field: 'applyTime',title: '申请时间'}, - {title: '业务员',field: 'businessMembers',visible: false}, + {field: 'applyTime',title: '申请时间',align: 'center',}, - {title: '事业部',field: 'customerPurser'}, - {title: '内外销',field: 'exportSales',visible: false, - formatter: function (value, row, index) {return $.table.selectDictLabel(exportSalesDatas, value);}, - }, + {title: '事业部',field: 'customerPurser',align: 'center',}, - {title: '邮编',field: 'postalCode',visible: false}, - {title: '国家地区',field: 'customerCountry',visible: false, - formatter: function (value, row, index) {return $.table.selectDictLabel(customerCountryDatas, value);}, - }, - {title: '国家/地区编号',field: 'countryNumber',visible: false, - formatter: function (value, row, index) {return $.table.selectDictLabel(countryNumberDatas, value); }, - }, - {title: '币种',field: 'commonCurrency',visible: false, - formatter: function (value, row, index) {return $.table.selectDictLabel(commonCurrencyDatas, value);}, - }, - {title: '备注内容',field: 'customerRemarks',visible: false}, - {title: '法人代表',field: 'legalRepresentative',visible: false}, - {title: '开票客户名称',field: 'invoicingCustomerName',visible: false}, - {title: '开票公司名称',field: 'invoicingCompanyName',visible: false}, - {title: '诚信评级',field: 'integrityRating',visible: false, - formatter: function (value, row, index) {return $.table.selectDictLabel(integrityRatingDatas, value);}, + {title: '第一联系人',field: 'customerContact',align: 'center',}, + {title: '第一联系人电话',field: 'contactNumber',align: 'center',}, + + {title: '第一联系人传真',field: 'customerFax',align: 'center',}, + {title: '第一联系人邮箱',field: 'customerEmail',align: 'center',}, + + {title: '付款条件',field: 'paymentTerms',align: 'center', + formatter: function(value, row, index) { + return $.table.tooltip(value,5,"open"); + } }, - {title: '第一联系人id',field: 'customerContactId',visible: false}, - {title: '第一联系人',field: 'customerContact'}, - {title: '第一联系人电话',field: 'contactNumber'}, - {title: '第一联系人职务',field: 'customerOffice',visible: false}, - {title: '第一联系人传真',field: 'customerFax'}, - {title: '第一联系人邮箱',field: 'customerEmail'}, - {title: '海关代码',field: 'customsCode',visible: false}, - {title: '付款条件',field: 'paymentTerms'}, - {title: '公司税号',field: 'invoiceCode',visible: false}, - {title: '成立日期',field: 'establishedTime'}, - {title: '开户银行',field: 'depositBank'}, - {title: '开户银行账号',field: 'bankAccount'}, - {title: 'RMB注册资金',field: 'rmbRegisteredCapital',visible: false}, - {title: '外币注册资金',field: 'registeredCapital',visible: false}, - {title: '是否含税',field: 'confirmTax', + + {title: '成立日期',field: 'establishedTime',align: 'center',}, + {title: '开户银行',field: 'depositBank',align: 'center',}, + {title: '开户银行账号',field: 'bankAccount',align: 'center',}, + + {title: '是否含税',field: 'confirmTax',align: 'center', formatter: function (value, row, index) { return $.table.selectDictLabel(confirmTaxDatas, value); }, }, - {title: '税率',field: 'taxRate'}, - {title: '第一收货人Id',field:'deliveryAddressId',visible: false}, - {title: '第一收货人',field:'deliveryCustomerPerson',visible: false}, - {title: '第一收货人地址',field: 'deliveryAddress',visible: false}, - {title: '第一收货人电话',field: 'deliveryCustomerPhone',visible: false}, - {title: '第一收货人邮编',field: 'deliveryCustomerPostal',visible:false}, - {title: '第一收货人传真',field: 'deliveryCustomerFax',visible: false}, - {title: '客户标识',field:'customerSign', + {title: '税率',field: 'taxRate',align: 'center',}, + + {title: '客户标识',field:'customerSign',align: 'center', formatter: function (value, row, index) {return $.table.selectDictLabel(customerSignDatas, value);} }, - {title: '录入时间',field: 'createTime', + {title: '录入时间',field: 'createTime',align: 'center', sortable: true, }, - {title: '上次修改时间',field: 'updateTime',}, + {title: '上次修改时间',field: 'updateTime',align: 'center', + + formatter: function(value, row, index) { + if (value) { + return '' + value + ''; + } else { + return value; + } + } + }, {title: '操作',align: 'center', formatter: function(value, row, index) { var actions = []; // 审核状态-审核通过 使用状态-是 未发起作废流程 if((row.auditStatus=="1" || row.auditStatus=="2") && !row.cancelInstanceId){ // 作废 - actions.push(' 作废'); + actions.push(' 作废'); // 编辑 - actions.push(' 编辑 '); + actions.push(' 编辑 '); }else{ - actions.push(' 编辑 '); + actions.push(' 编辑 '); } // 已作废 if(row.useStatus=="2" && !row.restoreInstanceId){ // 恢复 - actions.push(' 恢复 '); + actions.push(' 恢复 '); } //有流程实例id if (row.instanceId) { @@ -585,17 +545,18 @@ var todoUserIdList = row.todoUserId.split(","); if(todoUserIdList.includes(loginName) || loginName == 'admin'){ var nodeName = row.taskName=='驳回调整'?' 调整申请':' 审批'; - actions.push(' '+nodeName+' '); + actions.push(' '+nodeName+' '); } } // 审批历史 - actions.push(' 审批历史 '); + actions.push(' 审批历史 '); // 进度查看 - actions.push(' 进度查看 '); + actions.push(' 进度查看 '); } //详情 - actions.push(' 详情 '); - return actions.join(''); + actions.push(' 详情 '); + var actionLinks = actions.join(''); + return $.table.dropdownToggle(actionLinks); } } ], diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/BusinessKeysConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/BusinessKeysConstants.java index 84d2a34f..70b19a61 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/BusinessKeysConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/BusinessKeysConstants.java @@ -16,4 +16,7 @@ public class BusinessKeysConstants { /** 仓库信息 */ public static final String STOCK_INFO = "2"; + + /** 客户基本信息 */ + public static final String SYS_CUSTOMER = "3"; } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/FieldCompareUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/FieldCompareUtil.java index 6745dad4..216ed983 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/FieldCompareUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/FieldCompareUtil.java @@ -20,6 +20,15 @@ import java.util.*; * */ public class FieldCompareUtil { + /** + * 比较两个对象的变化并记录。 + * + * @param type 对象的类型 + * @param newObject 新对象 + * @param oldObject 旧对象 + * @return 变更记录列表 + * @throws Exception 如果发生异常 + */ /** * 比较两个对象的变化并记录。 * @@ -42,14 +51,9 @@ public class FieldCompareUtil { Object oldVal = getMethod.invoke(oldObject); Object newVal = getMethod.invoke(newObject); if (!areEqual(oldVal, newVal)) { - String s1 = formatValue(oldVal); - String s2 = formatValue(newVal); + String s1 = formatValue(oldVal, annotation); + String s2 = formatValue(newVal, annotation); String chineseName = annotation.chineseName(); - Map codeToNameMap = codeToNameMap(annotation); - if (!codeToNameMap.isEmpty()) { - s1 = codeToNameMap.getOrDefault(s1, s1); - s2 = codeToNameMap.getOrDefault(s2, s2); - } changeLogFields.add(new SysFieldDifferent(chineseName, s1, s2)); } } @@ -57,7 +61,7 @@ public class FieldCompareUtil { return changeLogFields; } - //统一处理条件判断 + // 统一处理条件判断 private static boolean areEqual(Object oldVal, Object newVal) { if (oldVal == null && newVal == null) { return true; @@ -71,21 +75,26 @@ public class FieldCompareUtil { return ((Number) oldVal).doubleValue() == ((Number) newVal).doubleValue(); } else if (oldVal instanceof Enum) { return oldVal.equals(newVal); - } else if (oldVal instanceof Date) { + } else if (oldVal instanceof java.util.Date) { return oldVal.equals(newVal); } else { return oldVal.equals(newVal); } } - //统一处理格式化值 - private static String formatValue(Object value) { + // 统一处理格式化值 + private static String formatValue(Object value, FieldCompare annotation) { if (value == null) { return ""; } + Map codeToNameMap = codeToNameMap(annotation); + if (!codeToNameMap.isEmpty()) { + return codeToNameMap.getOrDefault(value.toString(), value.toString()); + } + if (value instanceof String) { return ((String) value).trim(); - } else if (value instanceof Date) { + } else if (value instanceof java.util.Date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(value); } else if (value instanceof Number) { @@ -97,15 +106,10 @@ public class FieldCompareUtil { } } - - /** - * 字典映射 使用方式: - * @param newAnnotation - * @return - */ - private static Map codeToNameMap(FieldCompare newAnnotation) { + // 字典映射 使用方式 + private static Map codeToNameMap(FieldCompare annotation) { Map map = new HashMap<>(); - String properties = newAnnotation.properties(); + String properties = annotation.properties(); if (properties != null && properties.length() > 0) { String[] propertiesArr = properties.split(","); for (String propertie : propertiesArr) {