From 432a1b0c4dd251f686e9bb7950c4868aaf3e4ed7 Mon Sep 17 00:00:00 2001
From: liuxm <liuxm_a@163.com>
Date: 星期四, 06 六月 2024 09:55:57 +0800
Subject: [PATCH] 添加验证和异常处理
---
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionProcess.java | 13 +++
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java | 2
pms-parent/pms-global/src/main/resources/mapper/PrProductionProcessMapper.xml | 53 ++----------
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/ExceptionHandlerAdvice.java | 24 ++++++
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java | 8 +
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevOpsPlan.java | 14 +-
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java | 5 +
pms-parent/pms-global/src/main/resources/mapper/PrAssemblyPlanMapper.xml | 13 +++
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsPlanCtrl.java | 51 +++++-------
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionNode.java | 7 +
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsSv.java | 12 +++
11 files changed, 118 insertions(+), 84 deletions(-)
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/ExceptionHandlerAdvice.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/ExceptionHandlerAdvice.java
new file mode 100644
index 0000000..5ec1a92
--- /dev/null
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/aop/ExceptionHandlerAdvice.java
@@ -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());
+ }
+
+}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java
index 603ef80..5b0ec9a 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrAssemblyPlan.java
@@ -65,6 +65,7 @@
/**
* 鐘舵��:姝e父(1)銆佹殏鍋�(0)銆佺粨鏉�(-1)
*/
+ @NotNull(message = "鐘舵�佷笉鑳戒负绌�")
public Integer status;
/**
@@ -95,6 +96,7 @@
/**
* 缁撴潫鏃ユ湡
*/
+ @NotEmpty(message = "缁撴潫鏃ユ湡涓嶈兘涓虹┖")
public String endDate;
/**
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevOpsPlan.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevOpsPlan.java
index 921a9e8..65f6f52 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevOpsPlan.java
+++ b/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;
/**
* 鐘舵��:姝e父(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;
}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionNode.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionNode.java
index 9fc4736..167b071 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionNode.java
+++ b/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;
/**
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionProcess.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionProcess.java
index 996719e..9a1901a 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrProductionProcess.java
+++ b/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;
}
\ No newline at end of file
diff --git a/pms-parent/pms-global/src/main/resources/mapper/PrAssemblyPlanMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/PrAssemblyPlanMapper.xml
index 193996c..6082990 100644
--- a/pms-parent/pms-global/src/main/resources/mapper/PrAssemblyPlanMapper.xml
+++ b/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" />
diff --git a/pms-parent/pms-global/src/main/resources/mapper/PrProductionProcessMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/PrProductionProcessMapper.xml
index 5dc10ae..a1dea71 100644
--- a/pms-parent/pms-global/src/main/resources/mapper/PrProductionProcessMapper.xml
+++ b/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">
diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
index fa3c6c1..7b99040 100644
--- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
+++ b/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);
+ }
}
diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java
index 252dff5..0b6b158 100644
--- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java
+++ b/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);
}
}
diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsPlanCtrl.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsPlanCtrl.java
index 4be3c4b..931fe73 100644
--- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsPlanCtrl.java
+++ b/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);
}
}
diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsSv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsSv.java
index 47cfefb..026a625 100644
--- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/DevOpsSv.java
+++ b/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);
+ }
}
--
Gitblit v1.8.0