diff --git a/ruoyi-admin/src/main/java/com/ruoyi/stock/domain/StockInfo.java b/ruoyi-admin/src/main/java/com/ruoyi/stock/domain/StockInfo.java index e293d326..63010d31 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/stock/domain/StockInfo.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/stock/domain/StockInfo.java @@ -1,6 +1,7 @@ package com.ruoyi.stock.domain; import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.FieldCompare; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; @@ -22,23 +23,28 @@ public class StockInfo extends BaseEntity private Long stockId; /** 仓库编号 */ + @FieldCompare(chineseName = "仓库编号") @Excel(name = "仓库编号") private String stockNO; /** 仓库名 */ + @FieldCompare(chineseName = "仓库名") @Excel(name = "仓库名") private String stockName; /** 仓库地址 */ + @FieldCompare(chineseName = "仓库地址") @Excel(name = "仓库地址") private String stockAddr; /** 仓库管理人 */ + @FieldCompare(chineseName = "仓库管理人") @Excel(name = "仓库管理人") private String stockManager; /** 仓库备注 */ + @FieldCompare(chineseName = "仓库备注") @Excel(name = "仓库备注") private String stockMemo; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/stock/service/impl/StockInfoServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/stock/service/impl/StockInfoServiceImpl.java index 3b5c2019..7b2f31a8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/stock/service/impl/StockInfoServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/stock/service/impl/StockInfoServiceImpl.java @@ -1,13 +1,23 @@ package com.ruoyi.stock.service.impl; +import com.ruoyi.common.constant.BusinessKeysConstants; +import com.ruoyi.common.core.domain.entity.SysFieldDifferent; 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.stock.domain.StockInfo; import com.ruoyi.stock.mapper.StockInfoMapper; import com.ruoyi.stock.service.IStockInfoService; +import com.ruoyi.system.domain.SysDiffLog; +import com.ruoyi.system.service.ISysDiffLogService; +import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import java.util.List; @@ -23,6 +33,9 @@ public class StockInfoServiceImpl implements IStockInfoService @Autowired private StockInfoMapper stockInfoMapper; + @Autowired + private ISysDiffLogService diffLogService; + @Autowired private RedisCache redisCache; @@ -56,11 +69,22 @@ public class StockInfoServiceImpl implements IStockInfoService * @param stockInfo 仓库信息 * @return 结果 */ + @Transactional(rollbackFor = Exception.class) @Override public int insertStockInfo(StockInfo stockInfo) { + + SysDiffLog sysDiffLog = new SysDiffLog(); stockInfo.setFirstAddTime(DateUtils.getNowDate()); - return stockInfoMapper.insertStockInfo(stockInfo); + int insertStockInfo = stockInfoMapper.insertStockInfo(stockInfo); + Long stockId = stockInfo.getStockId(); + sysDiffLog.setBusinessId(stockId); + sysDiffLog.setBusinessKey(BusinessKeysConstants.STOCK_INFO); + int insertSysDiffLog = diffLogService.insertSysDiffLog(sysDiffLog); + if (insertSysDiffLog <= 0){ + throw new BusinessException("新增仓库信息数据修改记录失败"); + } + return insertStockInfo; } /** @@ -69,10 +93,24 @@ public class StockInfoServiceImpl implements IStockInfoService * @param stockInfo 仓库信息 * @return 结果 */ + @SneakyThrows + @Transactional(rollbackFor = Exception.class) @Override public int updateStockInfo(StockInfo stockInfo) { stockInfo.setUpdateInfoTime(DateUtils.getNowDate()); + Long stockId = stockInfo.getStockId(); + StockInfo oldStockInfo = stockInfoMapper.selectStockInfoById(stockId); + if (oldStockInfo == null){ + throw new RuntimeException("仓库信息数据不存在"); + } + List compare = FieldCompareUtil.compare(StockInfo.class, stockInfo, oldStockInfo); + if (!CollectionUtils.isEmpty(compare)){ + int updateSysDiffLog = diffLogService.updateSysDiffLogByBusiness(stockId,BusinessKeysConstants.STOCK_INFO,compare); + if (updateSysDiffLog <= 0){ + throw new RuntimeException("修改仓库信息数据修改记录失败"); + } + } return stockInfoMapper.updateStockInfo(stockInfo); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysDiffLogServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysDiffLogServiceImpl.java index 57f4a140..c5f55787 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysDiffLogServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysDiffLogServiceImpl.java @@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.ruoyi.common.constant.BusinessKeysConstants; import com.ruoyi.common.core.domain.entity.SysFieldDifferent; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.system.domain.Vo.SysDiffLogVo; @@ -81,6 +82,14 @@ public class SysDiffLogServiceImpl implements ISysDiffLogService String loginName = ShiroUtils.getLoginName(); sysDiffLog.setCreateBy(loginName); sysDiffLog.setCreateTime(DateUtils.getNowDate()); + Long businessId = sysDiffLog.getBusinessId(); + String businessKey = sysDiffLog.getBusinessKey(); + if (businessId == null) { + throw new BusinessException("业务ID不能为空"); + } + if (businessKey == null) { + throw new BusinessException("业务Key不能为空"); + } return sysDiffLogMapper.insertSysDiffLog(sysDiffLog); } diff --git a/ruoyi-admin/src/main/resources/mapper/stock/StockInfoMapper.xml b/ruoyi-admin/src/main/resources/mapper/stock/StockInfoMapper.xml index f622ee66..30f8c187 100644 --- a/ruoyi-admin/src/main/resources/mapper/stock/StockInfoMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/stock/StockInfoMapper.xml @@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + insert into stock_info StockNO, diff --git a/ruoyi-admin/src/main/resources/templates/stock/stockInfo/stockInfo.html b/ruoyi-admin/src/main/resources/templates/stock/stockInfo/stockInfo.html index 687f1281..24248056 100644 --- a/ruoyi-admin/src/main/resources/templates/stock/stockInfo/stockInfo.html +++ b/ruoyi-admin/src/main/resources/templates/stock/stockInfo/stockInfo.html @@ -69,6 +69,14 @@ exportUrl: prefix + "/export", clickToSelect: true, modalName: "仓库信息", + onDblClickCell: function (field, value, row, $element) { + var businessId = row.stockId; + var businessKey = "2"; + if (field == "updateInfoTime"){ + var url = ctx + "system/diffLog/getDiffDataList/" + businessId + "/" + businessKey; + $.modal.open("数据修改记录", url); + } + }, columns: [ {checkbox: true}, {title: '仓库id',field: 'stockId',visible: false}, @@ -94,13 +102,14 @@ // } }, {title: '上次修改时间',field: 'updateInfoTime',align: 'center', - // formatter: function (value, row, index) { - // if (value == null) {return " ";} - // else { - // var vArr = value.split(',') - // return vArr[0]; - // } - // } + + formatter: function (value, row, index) { + if (value){ + return '' + value + ''; + } else { + return value; + } + } }, { title: '操作', 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 9c77c563..84d2a34f 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 @@ -13,4 +13,7 @@ public class BusinessKeysConstants { /** 测试产品型号管理 */ public static final String PRODUCT_MODEL = "1"; + + /** 仓库信息 */ + public static final String STOCK_INFO = "2"; } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index 64a7ef43..9407df63 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -17,6 +17,8 @@ import com.ruoyi.common.exception.DemoModeException; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.security.PermissionUtils; +import java.sql.SQLException; + /** * 全局异常处理器 * @@ -127,4 +129,26 @@ public class GlobalExceptionHandler log.error(e.getMessage(), e); return AjaxResult.error("请正确使用审批流程上的角色进行操作"); } + + + /** + * SQL不能为空异常 + * */ + @ExceptionHandler(SQLException.class) + public AjaxResult sqlException(SQLException e) + { + //记录异常信息 + log.error("SQL 发生异常:",e); + //提取错误信息 + String errorMessage = e.getMessage(); + int startIndex = errorMessage.indexOf("doesn't have a default value"); + if (startIndex != -1){ + String fieldName = errorMessage.substring(0,startIndex).trim(); + return AjaxResult.error("字段:"+fieldName+"不能为空,请确保提供了改字段的值。"); + }else { + return AjaxResult.error("数据库操作失败:"+errorMessage); + } + + } + }