Przeglądaj źródła

安全工具增加替换报废工具接口

wuhonghao 4 lat temu
rodzic
commit
359be88ce8

+ 26 - 1
railway-admin/src/main/java/com/railway/web/controller/business/safetool/BaseSafetyToolController.java

@@ -28,7 +28,16 @@ public class BaseSafetyToolController extends BaseController {
     @ApiOperation(value = "新增")
     @PostMapping("/add")
     public AjaxResult add(@Validated @RequestBody BaseSafetyTool baseSafetyTool) {
-        return toAjax(baseSafetyToolService.create(baseSafetyTool));
+        //校验安全工具有效编码唯一
+        BaseSafetyTool validate = new BaseSafetyTool();
+        validate.setToolCode(baseSafetyTool.getToolCode());
+        validate.setState("1");
+        List<BaseSafetyTool> list = baseSafetyToolService.getList(validate);
+        if(list.size()==1){
+            return new AjaxResult(AjaxResult.Type.WARN,"工具编号已存在");
+        }else{
+            return toAjax(baseSafetyToolService.create(baseSafetyTool));
+        }
     }
 
     @ApiOperation(value = "删除")
@@ -60,4 +69,20 @@ public class BaseSafetyToolController extends BaseController {
         return getDataTable(list);
     }
 
+    @ApiOperation(value = "替换安全工具")
+    @PostMapping("/replaceTool")
+    public AjaxResult replaceTool(@Validated @RequestBody BaseSafetyTool baseSafetyTool) {
+        //校验安全工具有效编码唯一
+        BaseSafetyTool validate = new BaseSafetyTool();
+        validate.setToolCode(baseSafetyTool.getToolCode());
+        validate.setState("1");
+        List<BaseSafetyTool> list = baseSafetyToolService.getList(validate);
+        if(list.size()==1&&list.get(0).getToolId().equals(baseSafetyTool.getToolId())){
+            return toAjax(baseSafetyToolService.replaceTool(baseSafetyTool));
+        }else{
+            return new AjaxResult(AjaxResult.Type.WARN,"工具编号已存在");
+        }
+    }
+
+
 }

+ 3 - 0
railway-business/src/main/java/com/railway/business/safetool/domain/BaseSafetyTool.java

@@ -92,6 +92,9 @@ public class BaseSafetyTool extends BaseEntity{
     @Length(min = 1, max = 20, message = "【报废操作人】长度必须介于 {min} 和 {max} 之间")
     private String scrapUser;
 
+    @ApiModelProperty(value = "车间id")
+    private Long replaceToolId;
+
     @ApiModelProperty(value = "生产厂家")
     @Length(min = 1, max = 100, message = "【生产厂家】长度必须介于 {min} 和 {max} 之间")
     private String produceFactory;

+ 6 - 0
railway-business/src/main/java/com/railway/business/safetool/service/IBaseSafetyToolService.java

@@ -34,4 +34,10 @@ public interface IBaseSafetyToolService{
     */
     List<BaseSafetyTool> getList(BaseSafetyTool baseSafetyTool);
 
+    /**
+     *  替换安全工具
+     */
+    int replaceTool(BaseSafetyTool baseSafetyTool);
+
+
 }

+ 25 - 0
railway-business/src/main/java/com/railway/business/safetool/service/impl/BaseSafetyToolServiceImpl.java

@@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
 import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.domain.BaseSafetyTool;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.railway.common.utils.SecurityUtils;
@@ -69,4 +70,28 @@ private BaseSafetyToolMapper baseSafetyToolMapper;
 	public List<BaseSafetyTool> getList(BaseSafetyTool baseSafetyTool) {
 		return baseSafetyToolMapper.getList(baseSafetyTool);
 	}
+
+	/**
+	 * 替换安全工具
+	 */
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public int replaceTool(BaseSafetyTool baseSafetyTool) {
+		Long toolId = baseSafetyTool.getToolId();
+		//插入新的安全工具
+		baseSafetyTool.setCreateTime(new Date());
+		baseSafetyTool.setCreateBy(SecurityUtils.getUsername());
+		baseSafetyTool.setState("1");
+		baseSafetyToolMapper.insert(baseSafetyTool);
+
+		//将原安全工具状态设置为报废并记录替换ID
+		BaseSafetyTool temp = new BaseSafetyTool();
+		temp.setToolId(toolId);
+		temp.setScrapDate(new Date());
+		temp.setState("0");
+		temp.setScrapUser(SecurityUtils.getUsername());
+		temp.setReplaceToolId(baseSafetyTool.getToolId());
+
+		return baseSafetyToolMapper.update(temp);
+	}
 }

+ 18 - 9
railway-business/src/main/resources/mapper/safetool/BaseSafetyToolMapper.xml

@@ -24,6 +24,7 @@
                 <result column="scrap_reason" property="scrapReason"/>
                 <result column="scrap_date" property="scrapDate"/>
                 <result column="scrap_user" property="scrapUser"/>
+                <result column="replace_tool_id" property="replaceToolId"/>
                 <result column="produce_factory" property="produceFactory"/>
                 <result column="produce_date" property="produceDate"/>
                 <result column="remark" property="remark"/>
@@ -55,6 +56,7 @@
         t.scrap_reason,
         t.scrap_date,
         t.scrap_user,
+        t.replace_tool_id,
         t.produce_factory,
         t.produce_date,
         t.remark,
@@ -65,10 +67,7 @@
         t.update_time
     </sql>
 
-    <insert id="insert" parameterType="com.railway.business.safetool.domain.BaseSafetyTool">
-        <selectKey keyProperty="toolId" order="BEFORE" resultType="String">
-            select replace(uuid(), '-', '') from dual
-        </selectKey>
+    <insert id="insert" parameterType="com.railway.business.safetool.domain.BaseSafetyTool"  useGeneratedKeys="true" keyProperty="toolId">
         INSERT INTO base_safety_tool
         <trim prefix="(" suffix=")" suffixOverrides=",">
                     <if test ='null != deptId'>
@@ -122,6 +121,9 @@
                     <if test ='null != scrapUser'>
                     scrap_user,
                     </if>
+                    <if test ='null != replaceToolId'>
+                    replace_tool_id,
+                    </if>
                     <if test ='null != produceFactory'>
                     produce_factory,
                     </if>
@@ -188,7 +190,7 @@
                     #{testResultDesc},
                     </if>
                     <if test ='null != state'>
-                        #{state},
+                    #{state},
                     </if>
                     <if test ='null != scrapReason'>
                     #{scrapReason},
@@ -199,6 +201,9 @@
                     <if test ='null != scrapUser'>
                     #{scrapUser},
                     </if>
+                    <if test ='null != replaceToolId'>
+                    #{replaceToolId},
+                    </if>
                     <if test ='null != produceFactory'>
                     #{produceFactory},
                     </if>
@@ -252,6 +257,7 @@
                     <if test ='null != scrapReason'>scrap_reason = #{scrapReason},</if>
                     <if test ='null != scrapDate'>scrap_date = #{scrapDate},</if>
                     <if test ='null != scrapUser'>scrap_user = #{scrapUser},</if>
+                    <if test ='null != replaceToolId'>replace_tool_id = #{replaceToolId},</if>
                     <if test ='null != produceFactory'>produce_factory = #{produceFactory},</if>
                     <if test ='null != produceDate'>produce_date = #{produceDate},</if>
                     <if test ='null != remark'>remark = #{remark},</if>
@@ -309,16 +315,16 @@
                 <if test="testCycle!=null and testCycle!=''">
                     and t.test_cycle=#{testCycle}
                 </if>
-                <if test="lastTestDate!=null and lastTestDate!=''">
+                <if test="lastTestDate!=null">
                     and t.last_test_date=#{lastTestDate}
                 </if>
-                <if test="nextTestDate!=null and nextTestDate!=''">
+                <if test="nextTestDate!=null">
                     and t.next_test_date=#{nextTestDate}
                 </if>
                 <if test="testResult!=null and testResult!=''">
                     and t.test_result=#{testResult}
                 </if>
-                <if test="testDate!=null and testDate!=''">
+                <if test="testDate!=null">
                     and t.test_date=#{testDate}
                 </if>
                 <if test="testResultDesc!=null and testResultDesc!=''">
@@ -336,10 +342,13 @@
                 <if test="scrapUser!=null and scrapUser!=''">
                     and t.scrap_user=#{scrapUser}
                 </if>
+                <if test="replaceToolId!=null and replaceToolId!=''">
+                    and t.replace_tool_id=#{replaceToolId}
+                </if>
                 <if test="produceFactory!=null and produceFactory!=''">
                     and t.produce_factory=#{produceFactory}
                 </if>
-                <if test="produceDate!=null and produceDate!=''">
+                <if test="produceDate!=null">
                     and t.produce_date=#{produceDate}
                 </if>
                 <if test="remark!=null and remark!=''">