From 65ca50935315a89e219b7c974caf95dc28895ffc Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: Thu, 16 Oct 2025 08:37:56 +0800
Subject: [PATCH] 修改
---
hazmat-framework/src/main/java/com/gkhy/hazmat/framework/aspectj/LogAspect.java | 120 ++++++++++++++++++++++--------
hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml | 2
hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzEntryRecordMapper.java | 2
hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzProductEntryRecordMapper.java | 2
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.java | 27 ++++++
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java | 2
hazmat-system/src/main/resources/mapper/system/HzEntryRecordMapper.xml | 3
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java | 27 ++++++
hazmat-system/src/main/resources/mapper/system/HzProductEntryRecordMapper.xml | 3
9 files changed, 153 insertions(+), 35 deletions(-)
diff --git a/hazmat-framework/src/main/java/com/gkhy/hazmat/framework/aspectj/LogAspect.java b/hazmat-framework/src/main/java/com/gkhy/hazmat/framework/aspectj/LogAspect.java
index c2120ab..5c67aa1 100644
--- a/hazmat-framework/src/main/java/com/gkhy/hazmat/framework/aspectj/LogAspect.java
+++ b/hazmat-framework/src/main/java/com/gkhy/hazmat/framework/aspectj/LogAspect.java
@@ -55,40 +55,96 @@
*
* @param joinPoint 切点
*/
- @Around("logPointCut()")
- public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{
- SysUser user= SecurityUtils.getLoginUserWithoutError()!=null?SecurityUtils.getLoginUserWithoutError().getUser():null;
- long startTime = System.currentTimeMillis();
- //获取当前请求对象
- ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- HttpServletRequest request = attributes.getRequest();
- Signature signature = joinPoint.getSignature();
- MethodSignature methodSignature = (MethodSignature) signature;
- Method method = methodSignature.getMethod();
- StringBuffer requestURL = request.getRequestURL();
- JSONObject webLog = new JSONObject();
- String urlStr = request.getRequestURL().toString();
- webLog.put("basePath", StringUtils.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
- webLog.put("ip", ServletUtil.getClientIP(request,null));
- webLog.put("method",request.getMethod());
- Object params=getParameter(method, joinPoint.getArgs());
+// @Around("logPointCut()")
+// public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{
+//
+// SysUser user= SecurityUtils.getLoginUserWithoutError()!=null?SecurityUtils.getLoginUserWithoutError().getUser():null;
+// long startTime = System.currentTimeMillis();
+// //获取当前请求对象
+// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+// HttpServletRequest request = attributes.getRequest();
+// Signature signature = joinPoint.getSignature();
+// MethodSignature methodSignature = (MethodSignature) signature;
+// Method method = methodSignature.getMethod();
+// StringBuffer requestURL = request.getRequestURL();
+// JSONObject webLog = new JSONObject();
+// String urlStr = request.getRequestURL().toString();
+// webLog.put("basePath", StringUtils.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
+// webLog.put("ip", ServletUtil.getClientIP(request,null));
+// webLog.put("method",request.getMethod());
+// Object params=getParameter(method, joinPoint.getArgs());
+//
+// webLog.put("parameter",StringUtils.sub(JSON.toJSONString(params),0,2000));
+// webLog.put("uri",request.getRequestURI());
+// webLog.put("url",requestURL.toString());
+// if(user!=null) {
+// webLog.put("userName", user.getName());
+// }
+// log.info(webLog.toString());
+// Object result = joinPoint.proceed();
+// if (result == null) {
+// //如果切到了 没有返回类型的void方法,这里直接返回
+// return null;
+// }
+// long endTime = System.currentTimeMillis();
+// webLog.put("result",StringUtils.sub(JSON.toJSONString(result),0,20000));
+// webLog.put("spendTime",endTime - startTime);
+// log.info(webLog.toString());
+// return result;
+// }
- webLog.put("parameter",StringUtils.sub(JSON.toJSONString(params),0,2000));
- webLog.put("uri",request.getRequestURI());
- webLog.put("url",requestURL.toString());
- if(user!=null) {
- webLog.put("userName", user.getName());
+ @Around("logPointCut()")
+ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
+ // 初始化日志对象
+ JSONObject webLog = new JSONObject();
+ Object result = null;
+ long startTime = System.currentTimeMillis();
+
+ try {
+ // 1. 前置日志记录(单独try-catch防止此处异常影响主流程)
+ try {
+ SysUser user = SecurityUtils.getLoginUserWithoutError() != null
+ ? SecurityUtils.getLoginUserWithoutError().getUser() : null;
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ HttpServletRequest request = attributes.getRequest();
+
+ // 构建日志对象
+ webLog.put("basePath", StringUtils.removeSuffix(request.getRequestURL().toString(), URLUtil.url(request.getRequestURL().toString()).getPath()));
+ webLog.put("ip", ServletUtil.getClientIP(request, null));
+ webLog.put("method", request.getMethod());
+ webLog.put("uri", request.getRequestURI());
+ webLog.put("url", request.getRequestURL().toString());
+
+ // 方法参数记录
+ Signature signature = joinPoint.getSignature();
+ MethodSignature methodSignature = (MethodSignature) signature;
+ Object params = getParameter(methodSignature.getMethod(), joinPoint.getArgs());
+ webLog.put("parameter", StringUtils.sub(JSON.toJSONString(params), 0, 2000));
+
+ if(user != null) {
+ webLog.put("userName", user.getName());
+ }
+ log.info("[AOP-LOG] 请求日志: {}", webLog.toString());
+ } catch (Exception preLogEx) {
+ log.error("[AOP-LOG] 前置日志记录异常", preLogEx);
+ }
+
+ // 2. 核心业务执行(不catch,让业务异常正常抛出)
+ result = joinPoint.proceed();
+
+ } finally {
+ try {
+ // 3. 后置日志记录(确保始终执行,单独catch防止异常传播)
+ long endTime = System.currentTimeMillis();
+ if(result != null) {
+ webLog.put("result", StringUtils.sub(JSON.toJSONString(result), 0, 20000));
+ }
+ webLog.put("spendTime", endTime - startTime);
+ log.info("[AOP-LOG] 响应日志: {}", webLog.toString());
+ } catch (Exception postLogEx) {
+ log.error("[AOP-LOG] 后置日志记录异常", postLogEx);
+ }
}
- log.info(webLog.toString());
- Object result = joinPoint.proceed();
- if (result == null) {
- //如果切到了 没有返回类型的void方法,这里直接返回
- return null;
- }
- long endTime = System.currentTimeMillis();
- webLog.put("result",StringUtils.sub(JSON.toJSONString(result),0,2000));
- webLog.put("spendTime",endTime - startTime);
- log.info(webLog.toString());
return result;
}
diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzEntryRecordMapper.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzEntryRecordMapper.java
index a11f875..daa287d 100644
--- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzEntryRecordMapper.java
+++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzEntryRecordMapper.java
@@ -39,4 +39,6 @@
* @return
*/
List<HzEntryRecordVO> entryCountStatic(@Param("startTime") String startTime, @Param("endTime")String endTime,@Param("companyId")Long companyId);
+
+ HzEntryRecord selectLastEndCodeEntryRecord(@Param("codePrex") String codePrex, @Param("companyId") Long companyId);
}
diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzProductEntryRecordMapper.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzProductEntryRecordMapper.java
index f283f76..3a563e0 100644
--- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzProductEntryRecordMapper.java
+++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzProductEntryRecordMapper.java
@@ -31,4 +31,6 @@
* @return
*/
HzProductEntryRecord selectLastEntryRecord(@Param("codePrex") String codePrex,@Param("companyId") Long companyId);
+
+ HzProductEntryRecord selectLastEndCodeEntryRecord(@Param("codePrex") String codePrex, @Param("companyId") Long companyId);
}
diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.java
index bc85ce8..d005ddc 100644
--- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.java
+++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.java
@@ -295,6 +295,9 @@
if(entryRecord.getNum()>hazmatBasic.getMaxEntry()){
throw new ApiException("数量超过单次入库最大数量<"+hazmatBasic.getMaxEntry()+">");
}
+ if (!Objects.equals(existEr.getNum(),entryRecord.getNum())) {
+ generateCode2(entryRecord);
+ }
entryRecord.setUpdateBy(currentUser.getUsername());
int row=baseMapper.updateById(entryRecord);
if(row<1){
@@ -303,6 +306,30 @@
return row;
}
+ private void generateCode2(HzEntryRecord entryRecord) {
+ SysCompany company=companyMapper.selectById(entryRecord.getCompanyId());
+ String code=company.getCode();
+ if(StringUtils.isBlank(code)){
+ throw new ApiException("公司两位编码为空");
+ }
+ String currentDate= DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
+ StringBuilder prefixBuilder=new StringBuilder().append(CodePrexEnum.MATERIAL.getCode())
+ .append(code)
+ .append(currentDate);
+
+ HzEntryRecord er=baseMapper.selectLastEndCodeEntryRecord(prefixBuilder.toString(),entryRecord.getCompanyId());
+ int startCode=1;
+ int endCode=startCode+entryRecord.getNum()-1;
+ if(er!=null){
+ startCode=er.getEndCode()+1;
+ endCode=startCode+entryRecord.getNum()-1;
+ }
+ entryRecord.setCodePrex(prefixBuilder.toString());
+ entryRecord.setStartCode(startCode);
+ entryRecord.setEndCode(endCode);
+ entryRecord.setState(EntryStateEnum.UNENTER.getCode());
+ }
+
@Override
public CommonPage selectHazmatListByEntryId(Long entryId) {
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java
index 8bec69e..b85b5b4 100644
--- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java
+++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java
@@ -263,7 +263,7 @@
HzWarehouseRecord warehouseRecord = new HzWarehouseRecord()
.setWarehouseId(dbhazmat.getWarehouseId())
.setBasicId(dbhazmat.getBasicId())
- .setCupboardId(hazmat.getCupboardId())
+ .setCupboardId(dbhazmat.getCupboardId())
.setCreateId(currentUser.getId())
.setNum(1)
.setState(OperateStatusEnum.RETURN.getCode())
diff --git a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java
index cb70f0f..7a7234b 100644
--- a/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java
+++ b/hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java
@@ -226,7 +226,9 @@
if(existEr.getState().equals(EntryStateEnum.ENTER.getCode())){
throw new ApiException("已经入库,不能再修改");
}
-
+ if (!Objects.equals(existEr.getNum(),entryRecord.getNum())){
+ generateCode2(entryRecord);
+ }
entryRecord.setUpdateBy(currentUser.getUsername());
int row=baseMapper.updateById(entryRecord);
if(row<1){
@@ -235,6 +237,29 @@
return row;
}
+ private void generateCode2(HzProductEntryRecord entryRecord) {
+ SysCompany company=companyMapper.selectById(entryRecord.getCompanyId());
+ String code=company.getCode();
+ if(StringUtils.isBlank(code)){
+ throw new ApiException("公司两位编码为空");
+ }
+ String currentDate= DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
+ StringBuilder prefixBuilder=new StringBuilder().append(CodePrexEnum.GOOD.getCode())
+ .append(code)
+ .append(currentDate);
+ HzProductEntryRecord per=baseMapper.selectLastEndCodeEntryRecord(prefixBuilder.toString(),entryRecord.getCompanyId());
+ int startCode=1;
+ int endCode=startCode+entryRecord.getNum()-1;
+ if(per!=null){
+ startCode=per.getEndCode()+1;
+ endCode=startCode+entryRecord.getNum()-1;
+ }
+ entryRecord.setCodePrex(prefixBuilder.toString());
+ entryRecord.setStartCode(startCode);
+ entryRecord.setEndCode(endCode);
+ entryRecord.setState(EntryStateEnum.UNENTER.getCode());
+ }
+
@Override
public CommonPage selectProductListByEntryId(Long entryId,Long companyId) {
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
diff --git a/hazmat-system/src/main/resources/mapper/system/HzEntryRecordMapper.xml b/hazmat-system/src/main/resources/mapper/system/HzEntryRecordMapper.xml
index 91a917e..0d70094 100644
--- a/hazmat-system/src/main/resources/mapper/system/HzEntryRecordMapper.xml
+++ b/hazmat-system/src/main/resources/mapper/system/HzEntryRecordMapper.xml
@@ -102,4 +102,7 @@
group by month,day
order by month asc,day asc
</select>
+ <select id="selectLastEndCodeEntryRecord" resultType="com.gkhy.hazmat.system.domain.HzEntryRecord">
+ select * from hz_entry_record where company_id=#{companyId} and code_prex=#{codePrex} order by end_code desc limit 1
+ </select>
</mapper>
diff --git a/hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml b/hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml
index 893e884..53d38b9 100644
--- a/hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml
+++ b/hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml
@@ -157,7 +157,7 @@
LEFT JOIN hz_hazmat_flow hhf2 on hh2.id = hhf2.hazmat_id
LEFT JOIN sys_user sy on hhf2.create_id = sy.id
LEFT JOIN sys_dept sd on sy.depart_id = sd.id
- where hh2.create_time >= #{startTime} and hh2.create_time <= #{endTime} and hh2.state =3 and hhf2.state = 4
+ where hhf2.create_time >= #{startTime} and hhf2.create_time <= #{endTime} and hh2.state =3 and hhf2.state = 4
<if test="companyId!=null">
and hh2.company_id=#{companyId}
</if>
diff --git a/hazmat-system/src/main/resources/mapper/system/HzProductEntryRecordMapper.xml b/hazmat-system/src/main/resources/mapper/system/HzProductEntryRecordMapper.xml
index 0fd3ff1..860cfce 100644
--- a/hazmat-system/src/main/resources/mapper/system/HzProductEntryRecordMapper.xml
+++ b/hazmat-system/src/main/resources/mapper/system/HzProductEntryRecordMapper.xml
@@ -83,4 +83,7 @@
<select id="selectLastEntryRecord" resultType="com.gkhy.hazmat.system.domain.HzProductEntryRecord">
select * from hz_product_entry_record where company_id=#{companyId} and code_prex=#{codePrex} order by id desc limit 1
</select>
+ <select id="selectLastEndCodeEntryRecord" resultType="com.gkhy.hazmat.system.domain.HzProductEntryRecord">
+ select * from hz_product_entry_record where company_id=#{companyId} and code_prex=#{codePrex} order by end_code desc limit 1
+ </select>
</mapper>
--
Gitblit v1.9.2