liuxm
2024-06-06 432a1b0c4dd251f686e9bb7950c4868aaf3e4ed7
添加验证和异常处理
1个文件已添加
10个文件已修改
202 ■■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/ExceptionHandlerAdvice.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevOpsPlan.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionNode.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionProcess.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/PrAssemblyPlanMapper.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/PrProductionProcessMapper.xml 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsPlanCtrl.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsSv.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/ExceptionHandlerAdvice.java
New file
@@ -0,0 +1,24 @@
package com.dy.pmsGlobal.aop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@ResponseBody
@RestControllerAdvice
@Slf4j
public class ExceptionHandlerAdvice {
    /**
     * 处理系统异常,兜底处理所有异常
     */
    @ExceptionHandler(value = Exception.class)
    public BaseResponse<?> defaultExceptionHandler(Throwable ex) {
        log.error("[defaultExceptionHandler]", ex);
        // 返回 ERROR
        return BaseResponseUtils.buildException(ex.getMessage());
    }
}
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java
@@ -65,6 +65,7 @@
    /**
     * 状态:正常(1)、暂停(0)、结束(-1)
     */
    @NotNull(message = "状态不能为空")
    public Integer status;
    /**
@@ -95,6 +96,7 @@
    /**
     * 结束日期
     */
    @NotEmpty(message = "结束日期不能为空")
    public String endDate;
    /**
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevOpsPlan.java
@@ -6,6 +6,8 @@
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dy.common.po.BaseEntity;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import java.util.Date;
@@ -31,16 +33,13 @@
    /**
     * 名称
     */
    @NotEmpty(message = "名称不能为空")
    public String name;
//    /**
//     * 点位数量
//     */
//    public Integer num;
    /**
     * 状态:正常(1)、暂停(0)、结束(-1)
     */
    @NotNull(message = "状态不能为空")
    public Integer status;
    /**
@@ -50,8 +49,6 @@
    public Long creator;
    @TableField(exist = false)
    public String creatorName;
//    @TableField(exist = false)
//    public String proName;
    /**
     * 创建时间
@@ -61,11 +58,13 @@
    /**
     * 开始日期
     */
    @NotEmpty(message = "开始日期不能为空")
    public String startDate;
    /**
     * 结束日期
     */
    @NotEmpty(message = "结束日期不能为空")
    public String endDate;
    /**
@@ -76,5 +75,6 @@
    /**
     * 作业内容
     */
    @NotEmpty(message = "作业内容不能为空")
    public String content;
}
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionNode.java
@@ -10,6 +10,7 @@
import com.dy.common.po.BaseEntity;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
/**
@@ -39,27 +40,31 @@
    /**
     * 排序
     */
    @NotEmpty(message = "节点顺序不能为空")
    @NotNull(message = "节点顺序不能为空")
    public Integer sort;
    /**
     * 节点作业内容
     */
    @NotEmpty(message = "节点作业内容不能为空")
    public String content;
    /**
     * 是否开始节点,1是,0否
     */
    @NotNull(message = "是否开始节点不能为空")
    public Boolean isStart;
    /**
     * 是否结束节点,1是,0否
     */
    @NotNull(message = "是否结束节点不能为空")
    public Boolean isEnd;
    /**
     * 是否记录设备周期,1是,0否
     */
    @NotNull(message = "是否记录设备周期不能为空")
    public Boolean isRecord;
    /**
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionProcess.java
@@ -6,6 +6,10 @@
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dy.common.po.BaseEntity;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
import java.util.Date;
@@ -33,6 +37,7 @@
     * 产品实体编号
     */
    @JSONField(serializeUsing= ObjectWriterImplToString.class)
    @NotNull(message = "产品不能为空")
    public Long proId;
    /**
@@ -44,6 +49,7 @@
    /**
     * 名称
     */
    @NotEmpty(message = "名称不能为空")
    public String name;
    /**
@@ -75,10 +81,15 @@
    public String remark;
    @TableField(exist = false)
    @Valid
    @NotEmpty(message = "流程节点不能为空")
    public List<PrProductionNode> nodes;
    /**
     * 是否被引用
     */
    public boolean isQuote;
    public Boolean isQuote;
    @TableField(exist = false)
    public String planNames;
}
pms-parent/pms-global/src/main/resources/mapper/PrAssemblyPlanMapper.xml
@@ -36,6 +36,19 @@
        deleted,content
    </sql>
    <select id="selectPlanNamesByProcessId" resultType="java.lang.String" >
        select GROUP_CONCAT(name SEPARATOR ',')
        from pr_assembly_plan
        where process_id = #{processId} and deleted = 0
    </select>
    <select id="processIsQuote" resultType="java.lang.Boolean" parameterType="java.lang.Long">
        select count(1)
        from pr_assembly_plan
        where  deleted = 0
        <if test="id != null">
            and process_id = #{id}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
pms-parent/pms-global/src/main/resources/mapper/PrProductionProcessMapper.xml
@@ -17,6 +17,11 @@
                     select="com.dy.pmsGlobal.daoPlt.PltProductMapper.selectProNameById" fetchType="eager" />
        <association property="creatorName" column="creator" javaType="java.lang.Long"
                     select="com.dy.pmsGlobal.daoBa.BaUserMapper.selectNameByUserId" fetchType="eager" />
        <association property="isQuote" column="id" javaType="java.lang.Boolean" fetchType="eager"
                     select="com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper.processIsQuote" />
        <association property="planNames" column="id" javaType="java.lang.String" fetchType="eager"
                     select="com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper.selectPlanNamesByProcessId"  />
        <collection property="nodes" ofType="com.dy.pmsGlobal.pojoPr.PrProductionNode"
                      select="selectByProcess" fetchType="eager" column="id" />
    </resultMap>
@@ -105,34 +110,16 @@
    <select id="selectSome" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from pr_production_process
        from pr_production_process t
        <trim prefix="where" suffixOverrides="and">
            <!--                <if test="id != null">-->
            <!--                    id = #{id,jdbcType=BIGINT} and-->
            <!--                </if>-->
            <if test="proId != null">
                pro_id = #{proId,jdbcType=BIGINT} and
            </if>
<!--            <if test="name != null">-->
<!--                name = #{name,jdbcType=VARCHAR} and-->
<!--            </if>-->
            <!--                <if test="creator != null">-->
            <!--                    creator = #{creator,jdbcType=VARCHAR} and-->
            <!--                </if>-->
            <!--                <if test="dt != null">-->
            <!--                    dt = #{dt,jdbcType=TIMESTAMP} and-->
            <!--                </if>-->
            <!--                <if test="disabled != null">-->
            <!--                    disabled = #{disabled,jdbcType=TINYINT} and-->
            <!--                </if>-->
            <!--                <if test="deleted != null">-->
            <!--                    deleted = #{deleted,jdbcType=TINYINT} and-->
            <!--                </if>-->
            <!--                <if test="remark != null">-->
            <!--                    remark = #{remark,jdbcType=VARCHAR} and-->
            <!--                </if>-->
        </trim>
        order by id desc
        order by t.id desc
        <trim prefix="limit " >
            <if test="start != null and count != null">
                #{start}, #{count}
@@ -142,32 +129,14 @@
    <select id="selectSomeCount" resultType="java.lang.Long">
        select count(1)
        from pr_production_process
        from pr_production_process t
        <trim prefix="where" suffixOverrides="and">
<!--                <if test="id != null">-->
<!--                    id = #{id,jdbcType=BIGINT} and-->
<!--                </if>-->
            <if test="proId != null">
                pro_id = #{proId,jdbcType=BIGINT} and
            </if>
<!--                <if test="name != null">-->
<!--                    name = #{name,jdbcType=VARCHAR} and-->
<!--                </if>-->
<!--                <if test="creator != null">-->
<!--                    creator = #{creator,jdbcType=VARCHAR} and-->
<!--                </if>-->
<!--                <if test="dt != null">-->
<!--                    dt = #{dt,jdbcType=TIMESTAMP} and-->
<!--                </if>-->
<!--                <if test="disabled != null">-->
<!--                    disabled = #{disabled,jdbcType=TINYINT} and-->
<!--                </if>-->
<!--                <if test="deleted != null">-->
<!--                    deleted = #{deleted,jdbcType=TINYINT} and-->
<!--                </if>-->
<!--                <if test="remark != null">-->
<!--                    remark = #{remark,jdbcType=VARCHAR} and-->
<!--                </if>-->
            <!--            <if test="name != null">-->
            <!--                name = #{name,jdbcType=VARCHAR} and-->
            <!--            </if>-->
        </trim>
    </select>
    <select id="queryAll" resultType="map">
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
@@ -15,6 +15,7 @@
import com.dy.pmsGlobal.pojoPr.PrWorkingInstruction;
import com.dy.pmsGlobal.util.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -124,7 +125,9 @@
            }
            return null;
        }).filter(work -> work != null).toList();
        workDao.insertMany(workList);
        if(CollectionUtils.isNotEmpty(workList)){
            workDao.insertMany(workList);
        }
    }
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java
@@ -74,7 +74,7 @@
            throw new RuntimeException("计划名称不能重复");
        }
        PrProductionProcess process = processDao.selectByPrimaryKey(plan.processId);
        if(process == null || process.proId != plan.proId){
        if(process == null || !process.proId.equals(plan.proId)){
            throw new RuntimeException("产品与生产流程不匹配");
        }
        PrBatchNumber batch = new PrBatchNumber();
@@ -100,6 +100,10 @@
        //计划名称不能重复
        if(assemblyDao.exists(plan.name,plan.id)){
            throw new RuntimeException("计划名称不能重复");
        }
        PrProductionProcess process = processDao.selectByPrimaryKey(plan.processId);
        if(process == null || !process.proId.equals(plan.proId)){
            throw new RuntimeException("产品与生产流程不匹配");
        }
        PrAssemblyPlan origPlan = assemblyDao.selectByPrimaryKey(plan.id);
        PrBatchNumber batch = batchDao.selectByPrimaryKey(origPlan.batchId);
@@ -253,6 +257,6 @@
        PrAssemblyPlan param = new PrAssemblyPlan();
        param.id =plan.id;
        param.status = plan.status;
        return assemblyDao.updateByPrimaryKeySelective(plan);
        return assemblyDao.updateByPrimaryKeySelective(param);
    }
}
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsPlanCtrl.java
@@ -5,6 +5,7 @@
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.aop.Log;
import com.dy.pmsGlobal.pojoPr.PrAssemblyPlan;
import com.dy.pmsGlobal.pojoPr.PrDevOpsPlan;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
@@ -36,13 +37,7 @@
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        int count;
        try {
            count = sv.save(plan);
        }catch (Exception e){
            log.error("保存组装任务计划异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        int count = sv.save(plan);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -60,16 +55,22 @@
    @SsoPowerAop(power = "-1")
    @Log("更新组装任务计划")
    public BaseResponse<Boolean> update(@RequestBody @Valid PrDevOpsPlan plan, BindingResult bindingResult){
        int count;
        try {
            if (bindingResult != null && bindingResult.hasErrors()) {
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            count = sv.update(plan);
        }catch (Exception e){
            log.error("更新组装任务计划异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        int count = sv.update(plan);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
            return BaseResponseUtils.buildSuccess(true);
        }
    }
    @PostMapping(path="updateStatus")
    @SsoPowerAop(power = "-1")
    @Log("更新任务计划状态")
    public BaseResponse<Boolean> updateStatus(@RequestBody PrDevOpsPlan plan){
        int count = sv.updateStatus(plan);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -85,13 +86,8 @@
    @SsoPowerAop(power = "-1")
    @Log("根据ID查询组装任务计划")
    public BaseResponse<PrDevOpsPlan> one(Long id){
        try{
            PrDevOpsPlan plan=sv.selectById(id);
            return BaseResponseUtils.buildSuccess(plan);
        }catch (Exception e){
            log.error("根据ID查询组装任务计划异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        PrDevOpsPlan plan=sv.selectById(id);
        return BaseResponseUtils.buildSuccess(plan);
    }
    /**
@@ -103,13 +99,8 @@
    @SsoPowerAop(power = "-1")
    @Log("分页查询组装任务计划")
    public BaseResponse<QueryResultVo<List<PrDevOpsPlan>>> some(@RequestBody QueryVo vo){
        try {
            QueryResultVo<List<PrDevOpsPlan>> list = sv.selectSome(vo) ;
            return BaseResponseUtils.buildSuccess(list);
        }catch (Exception e){
            log.error("分页查询组装任务计划异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        QueryResultVo<List<PrDevOpsPlan>> list = sv.selectSome(vo) ;
        return BaseResponseUtils.buildSuccess(list);
    }
}
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsSv.java
@@ -63,4 +63,16 @@
        rsVo.obj = devOpsDao.selectSome(params);
        return rsVo ;
    }
    /**
     * 只更新状态,不更新其他字段
     * @param plan
     * @return
     */
    public int updateStatus(PrDevOpsPlan plan) {
        PrDevOpsPlan param = new PrDevOpsPlan();
        param.id =plan.id;
        param.status = plan.status;
        return devOpsDao.updateByPrimaryKeySelective(param);
    }
}