Browse Source

[fix] 基础资料模块

仓库信息前端列表:新增双击上次修改时间打开修改记录数据页面的方法,上次修改时间字段加上颜色标注
仓库后端实体类和get、set方法去掉多余的:stock_manager_phone字段
mapper.xml对应的方法去掉stock_manager_phone字段
修复仓库修改报错问题:修改前端接口传入参数,stockNo -> stockId
全局业务模块常量BusinessKeysConstants新增仓库信息STOCK_INFO= "2"
新增 全局sqlException方法,用于捕获 系统运行时触发SQLException.class相关的异常
仓库实体类StockInfo需要修改的字段新增@FieldCompare注解用于标识
修改仓库信息Mapper.xml层的新增方法:新增stockId为自增主键,解决新增一条数据获取不到id的问题
修改仓库信息的新增后端接口:新增插入一条数据的同时在通用修改记录里面加上一条数据,并且加上事务处理
修改仓库信息的修改后端接口:新增修改仓库信息同时,引用FieldCompareUtil.compare方法进行前后数据对比,并且引用
diffLogService.updateSysDiffLogByBusiness通用方法处理修改后的数据,并且加上事务处理和异常处理
修改通用的insertSysDiffLog方法:新增对businessId和businessKey非空判断,防止后续查不出来修改记录数据的问题
dev
liuxiaoxu 1 month ago
parent
commit
57008142ad
  1. 6
      ruoyi-admin/src/main/java/com/ruoyi/stock/domain/StockInfo.java
  2. 40
      ruoyi-admin/src/main/java/com/ruoyi/stock/service/impl/StockInfoServiceImpl.java
  3. 9
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysDiffLogServiceImpl.java
  4. 2
      ruoyi-admin/src/main/resources/mapper/stock/StockInfoMapper.xml
  5. 23
      ruoyi-admin/src/main/resources/templates/stock/stockInfo/stockInfo.html
  6. 3
      ruoyi-common/src/main/java/com/ruoyi/common/constant/BusinessKeysConstants.java
  7. 24
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java

6
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;

40
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<SysFieldDifferent> 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);
}

9
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);
}

2
ruoyi-admin/src/main/resources/mapper/stock/StockInfoMapper.xml

@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<insert id="insertStockInfo" parameterType="StockInfo">
<insert id="insertStockInfo" parameterType="StockInfo" useGeneratedKeys="true" keyProperty="stockId">
insert into stock_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="stockNO != null and stockNO != ''">StockNO,</if>

23
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 '<span style="color:#337ab7; cursor: pointer;">' + value + '</span>';
} else {
return value;
}
}
},
{
title: '操作',

3
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";
}

24
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);
}
}
}

Loading…
Cancel
Save