危化品全生命周期管理后端
“djh”
2025-10-16 65ca50935315a89e219b7c974caf95dc28895ffc
修改
9 files modified
188 ■■■■ changed files
hazmat-framework/src/main/java/com/gkhy/hazmat/framework/aspectj/LogAspect.java 120 ●●●● patch | view | raw | blame | history
hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzEntryRecordMapper.java 2 ●●●●● patch | view | raw | blame | history
hazmat-system/src/main/java/com/gkhy/hazmat/system/mapper/HzProductEntryRecordMapper.java 2 ●●●●● patch | view | raw | blame | history
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzEntryRecordServiceImpl.java 27 ●●●●● patch | view | raw | blame | history
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatServiceImpl.java 2 ●●● patch | view | raw | blame | history
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzProductEntryRecordServiceImpl.java 27 ●●●●● patch | view | raw | blame | history
hazmat-system/src/main/resources/mapper/system/HzEntryRecordMapper.xml 3 ●●●●● patch | view | raw | blame | history
hazmat-system/src/main/resources/mapper/system/HzHazmatMapper.xml 2 ●●● patch | view | raw | blame | history
hazmat-system/src/main/resources/mapper/system/HzProductEntryRecordMapper.xml 3 ●●●●● patch | view | raw | blame | history
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;
    }
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);
}
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);
}
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();
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())
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();
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>
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 &gt;= #{startTime} and hh2.create_time &lt;= #{endTime} and hh2.state =3 and hhf2.state = 4
        where hhf2.create_time &gt;= #{startTime} and hhf2.create_time &lt;= #{endTime} and hh2.state =3 and hhf2.state = 4
        <if test="companyId!=null">
            and hh2.company_id=#{companyId}
        </if>
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>