From afd077349567d2af006fcf5b3a42f3cd8cfb4ac7 Mon Sep 17 00:00:00 2001 From: HanLong <404402223@qq.com> Date: Wed, 24 Dec 2025 14:46:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:[=E8=B5=84=E6=BA=90=E5=BA=93=E7=AE=A1?= =?UTF-8?q?=E7=90=86][=E4=BB=AA=E5=99=A8=E7=AE=A1=E7=90=86]=E7=A8=BD?= =?UTF-8?q?=E6=9F=A5=E8=BD=A8=E8=BF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hxhq/common/core/domain/MpBaseEntity.java | 2 + .../com/hxhq/business/controller/YqController.java | 55 +++++--- .../src/main/java/com/hxhq/business/domain/Yq.java | 25 +++- .../main/java/com/hxhq/business/domain/YqJcgj.java | 22 ++- .../java/com/hxhq/business/form/yq/YqForm.java | 155 +++++++++++++++++++++ .../com/hxhq/business/form/yq/YqSearchForm.java | 71 ++++++++++ .../com/hxhq/business/service/IYqJcgjService.java | 9 ++ .../java/com/hxhq/business/service/IYqService.java | 5 + .../business/service/impl/YqJcgjServiceImpl.java | 27 +++- .../hxhq/business/service/impl/YqServiceImpl.java | 63 +++++++++ .../com/hxhq/business/utils/ObjectCompareUtil.java | 40 +++++- 11 files changed, 439 insertions(+), 35 deletions(-) create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqForm.java create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqSearchForm.java diff --git a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/domain/MpBaseEntity.java b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/domain/MpBaseEntity.java index d83930e..4cf8cd1 100644 --- a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/domain/MpBaseEntity.java +++ b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/domain/MpBaseEntity.java @@ -2,6 +2,7 @@ package com.hxhq.common.core.domain; import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonFormat; +import com.hxhq.common.core.annotation.Excel; import java.io.Serializable; import java.util.Date; @@ -39,6 +40,7 @@ public class MpBaseEntity implements Serializable private Date updateTime; /** 备注 */ + @Excel(name = "备注") private String remark; @TableField(value = "del_flag", fill = FieldFill.INSERT) diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/YqController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/YqController.java index cd7a3f9..9d7b5f6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/YqController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/YqController.java @@ -1,9 +1,16 @@ package com.hxhq.business.controller; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import com.hxhq.business.domain.YqJcgj; +import com.hxhq.business.form.yq.YqForm; +import com.hxhq.business.service.IYqJcgjService; +import com.hxhq.common.security.utils.SecurityUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import com.hxhq.business.domain.Yq; import com.hxhq.business.service.IYqService; @@ -20,46 +27,58 @@ import com.hxhq.common.core.web.page.TableDataInfo; */ @RestController @RequestMapping("/business/yq") -public class YqController extends BaseController -{ +public class YqController extends BaseController { @Autowired private IYqService yqService; + @Autowired + private IYqJcgjService yqJcgjService; + /** * 查询仪器管理列表 */ @GetMapping("/list") - public TableDataInfo list(Yq yq) - { + public TableDataInfo list(Yq yq) { startPage(); List list = yqService.queryList(yq); return getDataTable(list); } /** + * 查询仪器稽查轨迹列表 + */ + @GetMapping("/jcgj/list") + public TableDataInfo list(Long id) { + if(id == null ) { + return getDataTable(new ArrayList<>()); + } + startPage(); + YqJcgj yqJcgj = new YqJcgj(); + yqJcgj.setYqId(id); + List list = yqJcgjService.queryList(yqJcgj); + return getDataTable(list); + } + + /** * 获取仪器管理详细信息 */ @GetMapping(value = "/info") - public AjaxResult getInfo(Long id) - { + public AjaxResult getInfo(Long id) { return AjaxResult.success(yqService.getById(id)); } /** - * 新增仪器管理信息 + * 新增、编辑仪器管理信息 */ @PostMapping("/save") - public AjaxResult save(@RequestBody Yq yq) - { - return toAjax(yqService.saveOrUpdate(yq)); + public AjaxResult save(@RequestBody @Validated YqForm form) { + // TODO 签名密码校验 + if(form.getId() != null) { + yqService.updateYq(form); + } else { + yqService.addYq(form); + } + return success(); } - /** - * 删除仪器管理信息 - */ - @PostMapping("/delete") - public AjaxResult delete(@RequestBody Long[] ids) - { - return toAjax(yqService.removeByIds(Arrays.asList(ids))); - } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Yq.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Yq.java index bb6f5b7..222a6dd 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Yq.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Yq.java @@ -4,6 +4,7 @@ import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; import com.baomidou.mybatisplus.annotation.TableName; +import com.hxhq.common.core.annotation.Excel; import com.hxhq.common.core.domain.MpBaseEntity; import org.hibernate.validator.constraints.Length; @@ -27,6 +28,7 @@ public class Yq extends MpBaseEntity { */ @NotEmpty(message = "请输入仪器名称") @Length(max = 50, message = "仪器名称不能超过50字") + @Excel(name = "仪器名称") private String mc; /** @@ -34,6 +36,7 @@ public class Yq extends MpBaseEntity { */ @NotEmpty(message = "请输入仪器编号") @Length(max = 50, message = "仪器编号不能超过50字") + @Excel(name = "仪器编号") private String bh; /** @@ -41,6 +44,7 @@ public class Yq extends MpBaseEntity { */ @NotEmpty(message = "请输入仪器型号") @Length(max = 50, message = "仪器型号不能超过50字") + @Excel(name = "仪器型号") private String xh; /** @@ -48,6 +52,7 @@ public class Yq extends MpBaseEntity { */ @NotEmpty(message = "请输入仪器来源") @Length(max = 50, message = "仪器来源不能超过50字") + @Excel(name = "仪器来源") private String ly; /** @@ -55,6 +60,7 @@ public class Yq extends MpBaseEntity { */ @JsonFormat(pattern = "yyyy-MM-dd") @NotNull(message = "请选择校准日期") + @Excel(name = "下次校准日期") private Date jzrq; /** @@ -63,11 +69,17 @@ public class Yq extends MpBaseEntity { @NotNull(message = "请选择所属部门") private Long bmId; + /** 部门名称 */ + @Excel(name = "所属部门") + private String bmMc; + + /** * 温层 */ @NotNull(message = "请选择所温层") - private Long wc; + @Excel(name = "温层") + private String wc; public void setMc(String mc) { @@ -118,12 +130,19 @@ public class Yq extends MpBaseEntity { return bmId; } - public void setWc(Long wc) { + public void setWc(String wc) { this.wc = wc; } - public Long getWc() { + public String getWc() { return wc; } + public String getBmMc() { + return bmMc; + } + + public void setBmMc(String bmMc) { + this.bmMc = bmMc; + } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/YqJcgj.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/YqJcgj.java index 80328bc..7ca9314 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/YqJcgj.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/YqJcgj.java @@ -19,13 +19,13 @@ public class YqJcgj extends MpBaseEntity private Long yqId; /** 稽查轨迹类型 */ - private String jcgjlx; + private Integer jcgjlx; /** 稽查名称 */ private String jcmc; /** 稽查名称颜色:1:蓝色;3:红色;5:绿色;7:橙色 */ - private Long jcmcys; + private Integer jcmcys; /** 稽查内容 */ private String jcnr; @@ -36,6 +36,9 @@ public class YqJcgj extends MpBaseEntity /** 签名人id */ private Long qmrId; + /** 签名人名称 */ + private String qmrMc; + public void setYqId(Long yqId) { @@ -47,12 +50,12 @@ public class YqJcgj extends MpBaseEntity return yqId; } - public void setJcgjlx(String jcgjlx) + public void setJcgjlx(Integer jcgjlx) { this.jcgjlx = jcgjlx; } - public String getJcgjlx() + public Integer getJcgjlx() { return jcgjlx; } @@ -67,12 +70,12 @@ public class YqJcgj extends MpBaseEntity return jcmc; } - public void setJcmcys(Long jcmcys) + public void setJcmcys(Integer jcmcys) { this.jcmcys = jcmcys; } - public Long getJcmcys() + public Integer getJcmcys() { return jcmcys; } @@ -107,4 +110,11 @@ public class YqJcgj extends MpBaseEntity return qmrId; } + public String getQmrMc() { + return qmrMc; + } + + public void setQmrMc(String qmrMc) { + this.qmrMc = qmrMc; + } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqForm.java new file mode 100644 index 0000000..5ce5819 --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqForm.java @@ -0,0 +1,155 @@ +package com.hxhq.business.form.yq; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.hxhq.common.core.annotation.Excel; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.Date; + +public class YqForm { + + private Long id; + + @NotEmpty(message = "请输入仪器名称") + @Length(max = 50, message = "仪器名称不能超过50字") + @Excel(name = "仪器名称") + private String mc; + + /** + * 编号 + */ + @NotEmpty(message = "请输入仪器编号") + @Length(max = 50, message = "仪器编号不能超过50字") + @Excel(name = "仪器编号") + private String bh; + + /** + * 型号 + */ + @NotEmpty(message = "请输入仪器型号") + @Length(max = 50, message = "仪器型号不能超过50字") + @Excel(name = "仪器型号") + private String xh; + + /** + * 来源 + */ + @NotEmpty(message = "请输入仪器来源") + @Length(max = 50, message = "仪器来源不能超过50字") + @Excel(name = "仪器来源") + private String ly; + + /** + * 校准日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + @NotNull(message = "请选择校准日期") + @Excel(name = "下次校准日期") + private Date jzrq; + + + /** 部门名称 */ + @NotEmpty(message = "请选择所属部门") + @Excel(name = "所属部门") + private String bmMc; + + + /** + * 温层 + */ + @NotNull(message = "请选择所温层") + @Excel(name = "温层") + private String wc; + + + /** 备注 */ + @Length(max = 500, message = "备注不能超过500字") + private String remark; + + + /** 签名人密码 */ + @NotNull(message = "请输入签名人密码") + private String qmrmm; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMc() { + return mc; + } + + public void setMc(String mc) { + this.mc = mc; + } + + public String getBh() { + return bh; + } + + public void setBh(String bh) { + this.bh = bh; + } + + public String getXh() { + return xh; + } + + public void setXh(String xh) { + this.xh = xh; + } + + public String getLy() { + return ly; + } + + public void setLy(String ly) { + this.ly = ly; + } + + public Date getJzrq() { + return jzrq; + } + + public void setJzrq(Date jzrq) { + this.jzrq = jzrq; + } + + public String getBmMc() { + return bmMc; + } + + public void setBmMc(String bmMc) { + this.bmMc = bmMc; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getQmrmm() { + return qmrmm; + } + + public void setQmrmm(String qmrmm) { + this.qmrmm = qmrmm; + } + + public String getWc() { + return wc; + } + + public void setWc(String wc) { + this.wc = wc; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqSearchForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqSearchForm.java new file mode 100644 index 0000000..9191717 --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/yq/YqSearchForm.java @@ -0,0 +1,71 @@ +package com.hxhq.business.form.yq; + +/** 仪器列表搜索 */ +public class YqSearchForm { + + /** 名称 */ + private String mc; + + /** 编号 */ + private String bh; + + /** 失效日期开始 */ + private String startDate; + + /** 失效日期结束 */ + private String endDate; + + /** 制剂状态:1:入库;3:已发放;5:已锁定;7:待归档;9:归档;11:待解档 */ + private Integer zjzt; + + /** 借阅状态 1:未借阅 3:待借阅 5:借阅中 */ + private Integer jyzt; + + public String getMc() { + return mc; + } + + public void setMc(String mc) { + this.mc = mc; + } + + public String getBh() { + return bh; + } + + public void setBh(String bh) { + this.bh = bh; + } + + public String getStartDate() { + return startDate; + } + + public void setStartDate(String startDate) { + this.startDate = startDate; + } + + public String getEndDate() { + return endDate; + } + + public void setEndDate(String endDate) { + this.endDate = endDate; + } + + public Integer getZjzt() { + return zjzt; + } + + public void setZjzt(Integer zjzt) { + this.zjzt = zjzt; + } + + public Integer getJyzt() { + return jyzt; + } + + public void setJyzt(Integer jyzt) { + this.jyzt = jyzt; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqJcgjService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqJcgjService.java index 3251e4c..eef8b92 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqJcgjService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqJcgjService.java @@ -20,4 +20,13 @@ public interface IYqJcgjService extends IService */ public List queryList(YqJcgj yqJcgj); + /** + * 新增稽查轨迹 + * @param yqId 仪器id + * @param jcgjlx 稽查轨迹类型:1:流程;3:编辑 + * @param jcmc 稽查名称 + * @param jcmcys 稽查名称颜色:1:蓝色;3:红色;5:绿色;7:橙色 + * @param jcnr 稽查内容 + */ + public void saveJcgj(Long yqId, Integer jcgjlx, String jcmc, Integer jcmcys, String jcnr); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqService.java index f950315..86451d7 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IYqService.java @@ -3,6 +3,7 @@ package com.hxhq.business.service; import java.util.List; import com.hxhq.business.domain.Yq; import com.baomidou.mybatisplus.extension.service.IService; +import com.hxhq.business.form.yq.YqForm; /** * 仪器管理Service接口 @@ -20,4 +21,8 @@ public interface IYqService extends IService */ public List queryList(Yq yq); + /** 新增仪器信息 */ + void addYq(YqForm yqForm); + + void updateYq(YqForm yqForm); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqJcgjServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqJcgjServiceImpl.java index f731731..99936d6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqJcgjServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqJcgjServiceImpl.java @@ -1,8 +1,14 @@ package com.hxhq.business.service.impl; import java.util.List; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hxhq.business.domain.MjyJcgj; +import com.hxhq.common.core.domain.MpBaseEntity; +import com.hxhq.common.security.utils.SecurityUtils; +import com.hxhq.system.api.domain.SysUser; import org.springframework.stereotype.Service; import com.hxhq.business.mapper.YqJcgjMapper; import com.hxhq.business.domain.YqJcgj; @@ -18,6 +24,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class YqJcgjServiceImpl extends ServiceImpl implements IYqJcgjService { + /** * 查询仪器管理-稽查轨迹列表 * @@ -27,8 +34,26 @@ public class YqJcgjServiceImpl extends ServiceImpl impleme @Override public List queryList(YqJcgj yqJcgj) { - QueryWrapper queryWrapper = Wrappers.query(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if(yqJcgj.getId() != null) { + queryWrapper.eq(YqJcgj::getYqId, yqJcgj.getId()); + } + queryWrapper.orderByDesc(MpBaseEntity::getCreateTime); return this.list(queryWrapper); } + @Override + public void saveJcgj(Long yqId, Integer jcgjlx, String jcmc, Integer jcmcys, String jcnr) { + SysUser sysUser = SecurityUtils.getLoginUser().getSysUser(); + YqJcgj yqJcgj = new YqJcgj(); + yqJcgj.setYqId(yqId); + yqJcgj.setJcgjlx(jcgjlx); + yqJcgj.setJcmc(jcmc); + yqJcgj.setJcmcys(jcmcys); + yqJcgj.setJcnr(jcnr); + yqJcgj.setQmrId(sysUser.getUserId()); + yqJcgj.setQmrMc(sysUser.getNickName()); + this.save(yqJcgj); + } + } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqServiceImpl.java index 5883ef8..d70e2e6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/YqServiceImpl.java @@ -1,13 +1,30 @@ package com.hxhq.business.service.impl; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hxhq.business.domain.MjyJcgj; +import com.hxhq.business.domain.YqJcgj; +import com.hxhq.business.enums.zykgl.JcgjlxEnum; +import com.hxhq.business.enums.zykgl.JcmcysEnum; +import com.hxhq.business.form.yq.YqForm; +import com.hxhq.business.service.IYqJcgjService; +import com.hxhq.business.utils.ObjectCompareUtil; +import com.hxhq.common.core.exception.ServiceException; +import com.hxhq.common.security.utils.SecurityUtils; +import com.hxhq.system.api.domain.SysUser; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.hxhq.business.mapper.YqMapper; import com.hxhq.business.domain.Yq; import com.hxhq.business.service.IYqService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.transaction.annotation.Transactional; /** * 仪器管理Service业务层处理 @@ -18,6 +35,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class YqServiceImpl extends ServiceImpl implements IYqService { + @Autowired + private IYqJcgjService yqJcgjService; + /** * 查询仪器管理列表 * @@ -31,4 +51,47 @@ public class YqServiceImpl extends ServiceImpl implements IYqServi return this.list(queryWrapper); } + @Override + public void addYq(YqForm yqForm) { + Yq yq = new Yq(); + BeanUtils.copyProperties(yqForm, yq); + save(yq); + yqJcgjService.saveJcgj(yq.getId(), JcgjlxEnum.bj.getValue(), "新增仪器", JcmcysEnum.blue.getValue(), null); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateYq(YqForm yqForm) { + SysUser sysUser = SecurityUtils.getLoginUser().getSysUser(); + + Yq yq = getById(yqForm.getId()); + if(yq == null) { + throw new ServiceException("仪器不存在或已删除"); + } + + List fieldChanges = ObjectCompareUtil.compareObjects(yq, yqForm); + if (fieldChanges.size() == 0) { + throw new SecurityException("你没有修改任何内容"); + } + BeanUtils.copyProperties(yqForm, yq); + updateById(yq); + + // 稽查轨迹 + List yqJcgjList = new ArrayList<>(); + for (ObjectCompareUtil.FieldChange fieldChange : fieldChanges) { + YqJcgj yqJcgj = new YqJcgj(); + yqJcgj.setYqId(yq.getId()); + yqJcgj.setJcgjlx(JcgjlxEnum.bj.getValue()); + yqJcgj.setJcmc("编辑仪器"); + yqJcgj.setQmyy("编辑"); + yqJcgj.setJcmcys(JcmcysEnum.orange.getValue()); + yqJcgj.setJcnr(fieldChange.toString()); + yqJcgj.setQmrId(sysUser.getUserId()); + yqJcgj.setQmrMc(sysUser.getNickName()); + yqJcgjList.add(yqJcgj); + } + yqJcgjService.saveBatch(yqJcgjList); + } + + } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/ObjectCompareUtil.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/ObjectCompareUtil.java index 55cde02..c780a28 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/ObjectCompareUtil.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/utils/ObjectCompareUtil.java @@ -1,6 +1,7 @@ package com.hxhq.business.utils; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonFormat; import com.hxhq.common.core.utils.DateUtils; import com.hxhq.common.core.utils.StringUtils; import org.slf4j.Logger; @@ -54,18 +55,38 @@ public class ObjectCompareUtil { Object oldValue = field.get(oldObj); String oldValueStr = ""; String newValueStr = ""; - if (field.getType().getName().equals("java.util.Date")) { - oldValueStr = autoConvert(oldValue, "yyyy-MM-dd HH:mm:ss"); + if(oldValue == null) { + oldValueStr = ""; } else { - oldValueStr = oldValue.toString(); + if (field.getType().getName().equals("java.util.Date")) { + JsonFormat annotation = field.getAnnotation(JsonFormat.class); + if(annotation != null && StringUtils.isNotEmpty(annotation.pattern())) { + oldValueStr = autoConvert(oldValue, annotation.pattern()); + } else { + oldValueStr = autoConvert(oldValue, "yyyy-MM-dd HH:mm:ss"); + } + } else { + oldValueStr = oldValue.toString(); + } } + try { Object newValue = JSONObject.parseObject(JSONObject.toJSONString(newObj)).get(name); - if (field.getType().getName().equals("java.util.Date")) { - newValueStr = autoConvert(newValue, "yyyy-MM-dd HH:mm:ss"); + if(newValue == null) { + newValueStr = ""; } else { - newValueStr = newValue.toString(); + if (field.getType().getName().equals("java.util.Date")) { + JsonFormat annotation = field.getAnnotation(JsonFormat.class); + if(annotation != null && StringUtils.isNotEmpty(annotation.pattern())) { + newValueStr = autoConvert(newValue, annotation.pattern()); + } else { + newValueStr = autoConvert(newValue, "yyyy-MM-dd HH:mm:ss"); + } + } else { + newValueStr = newValue.toString(); + } } + if (StringUtils.isNoneBlank(oldValueStr) && StringUtils.isNoneBlank(newValueStr)) { // 对比字段值 if (!Objects.equals(oldValue, newValue)) { @@ -208,7 +229,12 @@ public class ObjectCompareUtil { @Override public String toString() { - return String.format("字段名:%s;原值:%s;新值:%s", fieldLabel, oldValue, newValue); + Map map = new HashMap<>(); + map.put("字段名", fieldLabel); + map.put("原值", oldValue); + map.put("新值", newValue); + return JSONObject.toJSONString(map); + //return String.format("字段名:%s;原值:%s;新值:%s", fieldLabel, oldValue, newValue); } }