Browse Source

【BUG】解决安全工具没有实验时间问题

ZhaoMn 3 years ago
parent
commit
c4df491c3b
19 changed files with 293 additions and 95 deletions
  1. 3 2
      railway-admin/src/main/java/com/railway/web/controller/business/safetool/BaseSafetyToolController.java
  2. 2 3
      railway-admin/src/main/java/com/railway/web/controller/business/safetool/SecExperimentController.java
  3. 10 3
      railway-admin/src/main/java/com/railway/web/controller/business/safetool/SecQcodeController.java
  4. 3 3
      railway-admin/src/main/java/com/railway/web/controller/business/safetool/SecScheduledController.java
  5. 3 0
      railway-business/src/main/java/com/railway/business/safetool/domain/BaseSafetyTool.java
  6. 1 1
      railway-business/src/main/java/com/railway/business/safetool/domain/SecExperimentTool.java
  7. 31 0
      railway-business/src/main/java/com/railway/business/safetool/enums/TestStateEnum.java
  8. 31 0
      railway-business/src/main/java/com/railway/business/safetool/enums/ToolStateEnum.java
  9. 34 0
      railway-business/src/main/java/com/railway/business/safetool/enums/ToolTestStateEnum.java
  10. 10 0
      railway-business/src/main/java/com/railway/business/safetool/mapper/BaseSafetyToolMapper.java
  11. 6 2
      railway-business/src/main/java/com/railway/business/safetool/mapper/SecScheduledMapper.java
  12. 5 5
      railway-business/src/main/java/com/railway/business/safetool/service/ISecExperimentService.java
  13. 29 28
      railway-business/src/main/java/com/railway/business/safetool/service/ISecScheduledService.java
  14. 14 4
      railway-business/src/main/java/com/railway/business/safetool/service/impl/BaseSafetyToolServiceImpl.java
  15. 43 19
      railway-business/src/main/java/com/railway/business/safetool/service/impl/SecExperimentServiceImpl.java
  16. 30 15
      railway-business/src/main/java/com/railway/business/safetool/service/impl/SecScheduledServiceImpl.java
  17. 27 8
      railway-business/src/main/resources/mapper/safetool/BaseSafetyToolMapper.xml
  18. 2 1
      railway-business/src/main/resources/mapper/safetool/SecExperimentMapper.xml
  19. 9 1
      railway-business/src/main/resources/mapper/safetool/SecScheduledMapper.xml

+ 3 - 2
railway-admin/src/main/java/com/railway/web/controller/business/safetool/BaseSafetyToolController.java

@@ -1,6 +1,7 @@
 package com.railway.web.controller.business.safetool;
 package com.railway.web.controller.business.safetool;
 
 
 import com.railway.business.safetool.domain.BaseSafetyTool;
 import com.railway.business.safetool.domain.BaseSafetyTool;
+import com.railway.business.safetool.enums.ToolStateEnum;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.common.annotation.Log;
 import com.railway.common.annotation.Log;
 import com.railway.common.core.controller.BaseController;
 import com.railway.common.core.controller.BaseController;
@@ -48,7 +49,7 @@ public class BaseSafetyToolController extends BaseController {
     //校验安全工具有效编码唯一
     //校验安全工具有效编码唯一
     BaseSafetyTool validate = new BaseSafetyTool();
     BaseSafetyTool validate = new BaseSafetyTool();
     validate.setToolCode(baseSafetyTool.getToolCode());
     validate.setToolCode(baseSafetyTool.getToolCode());
-    validate.setState("1");
+    validate.setState(ToolStateEnum.NORMAL.getCode());
     List<BaseSafetyTool> list = baseSafetyToolService.getList(validate);
     List<BaseSafetyTool> list = baseSafetyToolService.getList(validate);
     if (list.size() == 1) {
     if (list.size() == 1) {
       return new AjaxResult(AjaxResult.Type.WARN, "工具编号已存在");
       return new AjaxResult(AjaxResult.Type.WARN, "工具编号已存在");
@@ -92,7 +93,7 @@ public class BaseSafetyToolController extends BaseController {
     //校验安全工具有效编码唯一
     //校验安全工具有效编码唯一
     BaseSafetyTool validate = new BaseSafetyTool();
     BaseSafetyTool validate = new BaseSafetyTool();
     validate.setToolCode(baseSafetyTool.getToolCode());
     validate.setToolCode(baseSafetyTool.getToolCode());
-    validate.setState("1");
+    validate.setState(ToolStateEnum.NORMAL.getCode());
     List<BaseSafetyTool> list = baseSafetyToolService.getList(validate);
     List<BaseSafetyTool> list = baseSafetyToolService.getList(validate);
     if (list.size() == 1 && list.get(0).getToolId().equals(baseSafetyTool.getToolId())) {
     if (list.size() == 1 && list.get(0).getToolId().equals(baseSafetyTool.getToolId())) {
       return toAjax(baseSafetyToolService.replaceTool(baseSafetyTool));
       return toAjax(baseSafetyToolService.replaceTool(baseSafetyTool));

+ 2 - 3
railway-admin/src/main/java/com/railway/web/controller/business/safetool/SecExperimentController.java

@@ -47,14 +47,13 @@ public class SecExperimentController extends BaseController {
   @ApiOperation(value = "完成实验")
   @ApiOperation(value = "完成实验")
   @PostMapping("/expEnd")
   @PostMapping("/expEnd")
   public AjaxResult expEnd(@RequestBody @Valid SecExpEndParmVo p) {
   public AjaxResult expEnd(@RequestBody @Valid SecExpEndParmVo p) {
-    return toAjax(secExperimentService.update(p));
+    return toAjax(secExperimentService.setExperimentState(p));
   }
   }
 
 
   @ApiOperation(value = "设置安全工具是否合格")
   @ApiOperation(value = "设置安全工具是否合格")
   @PostMapping("/setToolNQ")
   @PostMapping("/setToolNQ")
   public AjaxResult setToolNQ(@RequestBody @Valid SecExpNQParmVo p) {
   public AjaxResult setToolNQ(@RequestBody @Valid SecExpNQParmVo p) {
-
-    return toAjax(secExperimentService.nq(p));
+    return toAjax(secExperimentService.setToolTestState(p));
   }
   }
 
 
   @ApiOperation(value = "送检记录详情")
   @ApiOperation(value = "送检记录详情")

+ 10 - 3
railway-admin/src/main/java/com/railway/web/controller/business/safetool/SecQcodeController.java

@@ -1,6 +1,8 @@
 package com.railway.web.controller.business.safetool;
 package com.railway.web.controller.business.safetool;
 
 
 import com.railway.business.safetool.domain.BaseSafetyTool;
 import com.railway.business.safetool.domain.BaseSafetyTool;
+import com.railway.business.safetool.enums.ToolStateEnum;
+import com.railway.business.safetool.enums.ToolTestStateEnum;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.common.annotation.Log;
 import com.railway.common.annotation.Log;
 import com.railway.common.core.controller.BaseController;
 import com.railway.common.core.controller.BaseController;
@@ -39,14 +41,19 @@ public class SecQcodeController extends BaseController {
   @GetMapping(value = {"/", "/{qcode}"})
   @GetMapping(value = {"/", "/{qcode}"})
   public AjaxResult getInfo(String qcode) {
   public AjaxResult getInfo(String qcode) {
     BaseSafetyTool tool = safetyToolService.getInfoByQcode(qcode);
     BaseSafetyTool tool = safetyToolService.getInfoByQcode(qcode);
-    if (null == tool){
+    if (null == tool) {
       return AjaxResult.error("二维码已失效,请检查!");
       return AjaxResult.error("二维码已失效,请检查!");
     }
     }
     Long deptId = SecurityUtils.getDeptId();
     Long deptId = SecurityUtils.getDeptId();
-    if(tool.getDeptId().compareTo(deptId) != 0){
+    if (tool.getDeptId().compareTo(deptId) != 0) {
       return AjaxResult.error("非本车间安全工具,请检查!");
       return AjaxResult.error("非本车间安全工具,请检查!");
     }
     }
-    safetyToolService.setBaseSafetyTool(tool);
+    // 是否已报废
+    if (tool.getState().equals(ToolStateEnum.NORMAL.getCode())) {
+      safetyToolService.setBaseSafetyTool(tool);
+    } else {
+      tool.setTestState(ToolTestStateEnum.SCRAP.getCode());
+    }
     AjaxResult ajax = AjaxResult.success();
     AjaxResult ajax = AjaxResult.success();
     ajax.put("info", tool);
     ajax.put("info", tool);
     return ajax;
     return ajax;

+ 3 - 3
railway-admin/src/main/java/com/railway/web/controller/business/safetool/SecScheduledController.java

@@ -41,9 +41,9 @@ public class SecScheduledController extends BaseController {
 
 
   @ApiOperation(value = "新增")
   @ApiOperation(value = "新增")
   @PostMapping("/add")
   @PostMapping("/add")
-  public AjaxResult add(@Validated @RequestBody SecScheduledToolListVo secScheduled) {
+  public AjaxResult add(@Validated @RequestBody SecScheduledToolListVo scheduledToolVo) {
     try {
     try {
-      return success(secScheduledService.create(secScheduled));
+      return success(secScheduledService.create(scheduledToolVo));
     } catch (Exception e) {
     } catch (Exception e) {
       e.printStackTrace();
       e.printStackTrace();
     }
     }
@@ -64,7 +64,7 @@ public class SecScheduledController extends BaseController {
 
 
   @ApiOperation(value = "查询详情")
   @ApiOperation(value = "查询详情")
   @GetMapping(value = {"/", "/{id}"})
   @GetMapping(value = {"/", "/{id}"})
-  public AjaxResult getInfo(String id) {
+  public AjaxResult getInfo(Long id) {
     SecScheduledToolListVo info = secScheduledService.getInfo(id);
     SecScheduledToolListVo info = secScheduledService.getInfo(id);
     AjaxResult ajax = AjaxResult.success();
     AjaxResult ajax = AjaxResult.success();
     ajax.put("info", info);
     ajax.put("info", info);

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

@@ -104,6 +104,9 @@ public class BaseSafetyTool extends BaseEntity {
   @Length(max = 255, message = "【试验结果描述】长度必须介于 {min} 和 {max} 之间")
   @Length(max = 255, message = "【试验结果描述】长度必须介于 {min} 和 {max} 之间")
   private String testResultDesc;
   private String testResultDesc;
 
 
+  @ApiModelProperty(value = "实验状态 0:报废 1:待送检 2:已送检 3:已实验 ")
+  private String testState;
+
   @ApiModelProperty(value = "状态 0:报废 1:正常")
   @ApiModelProperty(value = "状态 0:报废 1:正常")
   @Excel(name = "状态")
   @Excel(name = "状态")
   @Length(min = 1, max = 1, message = "【状态 0:报废 1:正常】长度必须介于 {min} 和 {max} 之间")
   @Length(min = 1, max = 1, message = "【状态 0:报废 1:正常】长度必须介于 {min} 和 {max} 之间")

+ 1 - 1
railway-business/src/main/java/com/railway/business/safetool/domain/SecExperimentTool.java

@@ -21,7 +21,7 @@ public class SecExperimentTool extends BaseEntity{
     @ApiModelProperty(value = "安全工具id")
     @ApiModelProperty(value = "安全工具id")
     private Long toolId;
     private Long toolId;
 
 
-    @ApiModelProperty(value = "是否合格")
+    @ApiModelProperty(value = "是否合格, 1 合格; 0 不合格、报废")
     private String isok;
     private String isok;
 
 
     @ApiModelProperty(value = "送检记录id")
     @ApiModelProperty(value = "送检记录id")

+ 31 - 0
railway-business/src/main/java/com/railway/business/safetool/enums/TestStateEnum.java

@@ -0,0 +1,31 @@
+package com.railway.business.safetool.enums;
+
+/**
+ * @author ZhaoMn
+ */
+
+public enum TestStateEnum {
+
+  /**
+   * 推送状态
+   */
+  WAITING("0", "待送检|待实验"),
+  ALREADY("1", "已送检|已实验"),
+  ;
+
+  private final String code;
+  private final String info;
+
+  TestStateEnum(String code, String info) {
+    this.code = code;
+    this.info = info;
+  }
+
+  public String getCode() {
+    return code;
+  }
+
+  public String getInfo() {
+    return info;
+  }
+}

+ 31 - 0
railway-business/src/main/java/com/railway/business/safetool/enums/ToolStateEnum.java

@@ -0,0 +1,31 @@
+package com.railway.business.safetool.enums;
+
+/**
+ * @author ZhaoMn
+ */
+
+public enum ToolStateEnum {
+
+  /**
+   * 推送状态
+   */
+  SCRAP("0", "报废"),
+  NORMAL("1", "正常"),
+  ;
+
+  private final String code;
+  private final String info;
+
+  ToolStateEnum(String code, String info) {
+    this.code = code;
+    this.info = info;
+  }
+
+  public String getCode() {
+    return code;
+  }
+
+  public String getInfo() {
+    return info;
+  }
+}

+ 34 - 0
railway-business/src/main/java/com/railway/business/safetool/enums/ToolTestStateEnum.java

@@ -0,0 +1,34 @@
+package com.railway.business.safetool.enums;
+
+/**
+ * @author ZhaoMn
+ */
+
+public enum ToolTestStateEnum {
+
+  /**
+   * 推送状态
+   */
+  SCRAP("0", "已报废"),
+  NO_PLAN("1", "未计划"),
+  NOT_CONFIRM("2", "待送检"),
+  CONFIRM("3", "已送检"),
+  TESTED("4", "实验完成"),
+  ;
+
+  private final String code;
+  private final String info;
+
+  ToolTestStateEnum(String code, String info) {
+    this.code = code;
+    this.info = info;
+  }
+
+  public String getCode() {
+    return code;
+  }
+
+  public String getInfo() {
+    return info;
+  }
+}

+ 10 - 0
railway-business/src/main/java/com/railway/business/safetool/mapper/BaseSafetyToolMapper.java

@@ -51,4 +51,14 @@ public interface BaseSafetyToolMapper {
      */
      */
     List<BaseSafetyTool> getListByIds(Long [] ids);
     List<BaseSafetyTool> getListByIds(Long [] ids);
 
 
+    /**
+     * 查询列表
+     */
+    List<BaseSafetyTool> listByExperimentId(Long experimentId);
+
+    /**
+     * 查询列表
+     */
+    List<BaseSafetyTool> listByScheduledId(Long scheduledId);
+
 }
 }

+ 6 - 2
railway-business/src/main/java/com/railway/business/safetool/mapper/SecScheduledMapper.java

@@ -1,7 +1,6 @@
 package com.railway.business.safetool.mapper;
 package com.railway.business.safetool.mapper;
 
 
 import com.github.pagehelper.Page;
 import com.github.pagehelper.Page;
-import com.railway.business.safetool.domain.SecExperiment;
 import com.railway.business.safetool.domain.SecScheduled;
 import com.railway.business.safetool.domain.SecScheduled;
 import com.railway.business.safetool.domain.vo.SecScheduledCountVo;
 import com.railway.business.safetool.domain.vo.SecScheduledCountVo;
 import com.railway.business.safetool.domain.vo.SecScheduledListParmVo;
 import com.railway.business.safetool.domain.vo.SecScheduledListParmVo;
@@ -40,7 +39,12 @@ public interface SecScheduledMapper {
     /**
     /**
      * 获取单个
      * 获取单个
      */
      */
-    SecScheduledToolListVo getInfo(@Param("id") String id);
+    SecScheduled getInfo(@Param("id") Long id);
+
+    /**
+     * 获取单个
+     */
+    SecScheduledToolListVo getDetail(@Param("id") Long id);
 
 
     /**
     /**
     * 查询列表
     * 查询列表

+ 5 - 5
railway-business/src/main/java/com/railway/business/safetool/service/ISecExperimentService.java

@@ -1,5 +1,6 @@
 package com.railway.business.safetool.service;
 package com.railway.business.safetool.service;
 
 
+import com.railway.business.safetool.domain.SecExperiment;
 import com.railway.business.safetool.domain.vo.SecExpAddParmVo;
 import com.railway.business.safetool.domain.vo.SecExpAddParmVo;
 import com.railway.business.safetool.domain.vo.SecExpEndParmVo;
 import com.railway.business.safetool.domain.vo.SecExpEndParmVo;
 import com.railway.business.safetool.domain.vo.SecExpInfoVo;
 import com.railway.business.safetool.domain.vo.SecExpInfoVo;
@@ -19,13 +20,12 @@ public interface ISecExperimentService{
     */
     */
     int create(SecExpAddParmVo secExpAddParmVo);
     int create(SecExpAddParmVo secExpAddParmVo);
 
 
-
-
     /**
     /**
     * 更新
     * 更新
     */
     */
-    int update(SecExpEndParmVo secExperiment);
-    int nq(SecExpNQParmVo nq);
+    int update(SecExperiment info);
+    int setToolTestState(SecExpNQParmVo nq);
+    int setExperimentState(SecExpEndParmVo param);
 
 
     /**
     /**
     * 获取单个
     * 获取单个
@@ -35,6 +35,6 @@ public interface ISecExperimentService{
     /**
     /**
     * 查询列表
     * 查询列表
     */
     */
-    List<SecExpListVo> getList(SecExpListParmVo parm);
+    List<SecExpListVo> getList(SecExpListParmVo param);
 
 
 }
 }

+ 29 - 28
railway-business/src/main/java/com/railway/business/safetool/service/ISecScheduledService.java

@@ -6,42 +6,43 @@ import com.railway.business.safetool.domain.vo.SecScheduledListParmVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolListVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolListVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolVo;
 import java.util.List;
 import java.util.List;
-/**
-* 安全工具计划表
-* @author lijie
-* @date 2021/12/04
-*/
-public interface ISecScheduledService{
 
 
-    /**
-    * 新增
-    */
-    Long create(SecScheduledToolListVo secScheduled) throws Exception;
+/**
+ * 安全工具计划表
+ *
+ * @author lijie
+ * @date 2021/12/04
+ */
+public interface ISecScheduledService {
 
 
-    /**
-    * 删除
-    */
-    int delete(String[] ids);
+  /**
+   * 新增
+   */
+  Long create(SecScheduledToolListVo scheduledToolVo) throws Exception;
 
 
-    /**
-    * 更新
-    */
-    int update(SecScheduled secScheduled);
+  /**
+   * 删除
+   */
+  int delete(String[] ids);
 
 
-    /**
-    * 获取单个
-    */
-    SecScheduledToolListVo getInfo(String id);
+  /**
+   * 更新
+   */
+  int update(SecScheduled secScheduled);
 
 
-    /**
-    * 查询列表
-    */
-    List<SecScheduledCountVo> getList(SecScheduledListParmVo secScheduled);
+  /**
+   * 获取单个
+   */
+  SecScheduledToolListVo getInfo(Long id);
 
 
+  /**
+   * 查询列表
+   */
+  List<SecScheduledCountVo> getList(SecScheduledListParmVo secScheduled);
 
 
 
 
-     int delTools(SecScheduledToolVo secScheduled) throws Exception ;
+  int delTools(SecScheduledToolVo secScheduled) throws Exception;
 
 
 
 
-     int addTools(SecScheduledToolVo toolsVo) throws Exception;
+  int addTools(SecScheduledToolVo toolsVo) throws Exception;
 }
 }

+ 14 - 4
railway-business/src/main/java/com/railway/business/safetool/service/impl/BaseSafetyToolServiceImpl.java

@@ -3,6 +3,8 @@ package com.railway.business.safetool.service.impl;
 import com.railway.business.safetool.domain.BaseSafetyTool;
 import com.railway.business.safetool.domain.BaseSafetyTool;
 import com.railway.business.safetool.domain.SecExperiment;
 import com.railway.business.safetool.domain.SecExperiment;
 import com.railway.business.safetool.domain.SecScheduled;
 import com.railway.business.safetool.domain.SecScheduled;
+import com.railway.business.safetool.enums.ToolStateEnum;
+import com.railway.business.safetool.enums.ToolTestStateEnum;
 import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.mapper.SecExperimentMapper;
 import com.railway.business.safetool.mapper.SecExperimentMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
@@ -81,7 +83,7 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
   public int create(BaseSafetyTool baseSafetyTool) {
   public int create(BaseSafetyTool baseSafetyTool) {
     baseSafetyTool.setCreateTime(new Date());
     baseSafetyTool.setCreateTime(new Date());
     baseSafetyTool.setCreateBy(SecurityUtils.getUsername());
     baseSafetyTool.setCreateBy(SecurityUtils.getUsername());
-    baseSafetyTool.setState("1");
+    baseSafetyTool.setState(ToolStateEnum.NORMAL.getCode());
     setTool(baseSafetyTool);
     setTool(baseSafetyTool);
     return safetyToolMapper.insert(baseSafetyTool);
     return safetyToolMapper.insert(baseSafetyTool);
   }
   }
@@ -132,14 +134,22 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
    */
    */
   @Override
   @Override
   public void setBaseSafetyTool(BaseSafetyTool tool) {
   public void setBaseSafetyTool(BaseSafetyTool tool) {
+    // 查询该工具相关的 待送检 计划
     List<SecScheduled> scheduledList = scheduledMapper.listScheduled(tool.getToolId());
     List<SecScheduled> scheduledList = scheduledMapper.listScheduled(tool.getToolId());
     if(CollectionUtils.isNotEmpty(scheduledList)){
     if(CollectionUtils.isNotEmpty(scheduledList)){
       tool.setScheduledId(scheduledList.get(0).getId());
       tool.setScheduledId(scheduledList.get(0).getId());
+      tool.setTestState(ToolTestStateEnum.NOT_CONFIRM.getCode());
+      return;
     }
     }
+    // 查询该工具相关的 待实验 送检记录
     List<SecExperiment> experimentList = experimentMapper.listExperiment(tool.getToolId());
     List<SecExperiment> experimentList = experimentMapper.listExperiment(tool.getToolId());
-    if(CollectionUtils.isNotEmpty(experimentList)){
+    if (CollectionUtils.isNotEmpty(experimentList)) {
       tool.setExperimentId(experimentList.get(0).getId());
       tool.setExperimentId(experimentList.get(0).getId());
+      tool.setTestState(ToolTestStateEnum.CONFIRM.getCode());
+      return;
     }
     }
+    // 既没有在计划中,也没有待实验的送检记录,表示该工具没有计划,可以增加到计划中
+    tool.setTestState(ToolTestStateEnum.NO_PLAN.getCode());
   }
   }
 
 
   /**
   /**
@@ -247,14 +257,14 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
     //插入新的安全工具
     //插入新的安全工具
     baseSafetyTool.setCreateTime(new Date());
     baseSafetyTool.setCreateTime(new Date());
     baseSafetyTool.setCreateBy(SecurityUtils.getUsername());
     baseSafetyTool.setCreateBy(SecurityUtils.getUsername());
-    baseSafetyTool.setState("1");
+    baseSafetyTool.setState(ToolStateEnum.NORMAL.getCode());
     safetyToolMapper.insert(baseSafetyTool);
     safetyToolMapper.insert(baseSafetyTool);
 
 
     //将原安全工具状态设置为报废并记录替换ID
     //将原安全工具状态设置为报废并记录替换ID
     BaseSafetyTool temp = new BaseSafetyTool();
     BaseSafetyTool temp = new BaseSafetyTool();
     temp.setToolId(toolId);
     temp.setToolId(toolId);
     temp.setScrapDate(new Date());
     temp.setScrapDate(new Date());
-    temp.setState("0");
+    temp.setState(ToolStateEnum.SCRAP.getCode());
     temp.setScrapUser(SecurityUtils.getUsername());
     temp.setScrapUser(SecurityUtils.getUsername());
     temp.setReplaceToolId(baseSafetyTool.getToolId());
     temp.setReplaceToolId(baseSafetyTool.getToolId());
 
 

+ 43 - 19
railway-business/src/main/java/com/railway/business/safetool/service/impl/SecExperimentServiceImpl.java

@@ -1,5 +1,6 @@
 package com.railway.business.safetool.service.impl;
 package com.railway.business.safetool.service.impl;
 
 
+import com.railway.business.safetool.domain.BaseSafetyTool;
 import com.railway.business.safetool.domain.SecExperiment;
 import com.railway.business.safetool.domain.SecExperiment;
 import com.railway.business.safetool.domain.SecExperimentTool;
 import com.railway.business.safetool.domain.SecExperimentTool;
 import com.railway.business.safetool.domain.vo.SecExpAddParmVo;
 import com.railway.business.safetool.domain.vo.SecExpAddParmVo;
@@ -9,6 +10,9 @@ import com.railway.business.safetool.domain.vo.SecExpListParmVo;
 import com.railway.business.safetool.domain.vo.SecExpListVo;
 import com.railway.business.safetool.domain.vo.SecExpListVo;
 import com.railway.business.safetool.domain.vo.SecExpNQParmVo;
 import com.railway.business.safetool.domain.vo.SecExpNQParmVo;
 import com.railway.business.safetool.domain.vo.SecExpToolsVo;
 import com.railway.business.safetool.domain.vo.SecExpToolsVo;
+import com.railway.business.safetool.enums.TestStateEnum;
+import com.railway.business.safetool.enums.ToolStateEnum;
+import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.mapper.SecExperimentMapper;
 import com.railway.business.safetool.mapper.SecExperimentMapper;
 import com.railway.business.safetool.mapper.SecExperimentToolMapper;
 import com.railway.business.safetool.mapper.SecExperimentToolMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
@@ -32,14 +36,17 @@ public class SecExperimentServiceImpl implements ISecExperimentService {
   private final SecScheduledMapper scheduledMapper;
   private final SecScheduledMapper scheduledMapper;
   private final SecExperimentMapper secExperimentMapper;
   private final SecExperimentMapper secExperimentMapper;
   private final SecExperimentToolMapper secExperimentToolMapper;
   private final SecExperimentToolMapper secExperimentToolMapper;
+  private final BaseSafetyToolMapper toolMapper;
 
 
   public SecExperimentServiceImpl(
   public SecExperimentServiceImpl(
       SecScheduledMapper scheduledMapper,
       SecScheduledMapper scheduledMapper,
       SecExperimentMapper secExperimentMapper,
       SecExperimentMapper secExperimentMapper,
-      SecExperimentToolMapper secExperimentToolMapper) {
+      SecExperimentToolMapper secExperimentToolMapper,
+      BaseSafetyToolMapper toolMapper) {
     this.scheduledMapper = scheduledMapper;
     this.scheduledMapper = scheduledMapper;
     this.secExperimentMapper = secExperimentMapper;
     this.secExperimentMapper = secExperimentMapper;
     this.secExperimentToolMapper = secExperimentToolMapper;
     this.secExperimentToolMapper = secExperimentToolMapper;
+    this.toolMapper = toolMapper;
   }
   }
 
 
   /**
   /**
@@ -59,46 +66,63 @@ public class SecExperimentServiceImpl implements ISecExperimentService {
     }
     }
     //设置已送检状态
     //设置已送检状态
     if (r > 0) {
     if (r > 0) {
-      r = scheduledMapper.updateScheduled(secExpAddParmVo.getSecid(), "1");
+      r = scheduledMapper.updateScheduled(secExpAddParmVo.getSecid(), TestStateEnum.ALREADY.getCode());
     }
     }
     return r;
     return r;
   }
   }
 
 
-
   /**
   /**
    * 更新
    * 更新
    */
    */
   @Override
   @Override
   @Transactional(rollbackFor = Exception.class)
   @Transactional(rollbackFor = Exception.class)
-  public int update(SecExpEndParmVo p) {
+  public int update(SecExperiment info) {
+    info.setUpdateTime(new Date());
+    info.setUpdateBy(SecurityUtils.getUsername());
+    return secExperimentMapper.update(info);
+  }
+
+  @Override
+  public int setExperimentState(SecExpEndParmVo param) {
     SecExperiment secExperiment = new SecExperiment();
     SecExperiment secExperiment = new SecExperiment();
-    BeanUtils.copyProperties(p, secExperiment);
-    secExperiment.setState("1");
+    BeanUtils.copyProperties(param, secExperiment);
+    secExperiment.setState(TestStateEnum.ALREADY.getCode());
     secExperiment.setExpDate(new Date());
     secExperiment.setExpDate(new Date());
-    secExperiment.setUpdateTime(new Date());
-    secExperiment.setUpdateBy(SecurityUtils.getUsername());
-    int r = secExperimentMapper.update(secExperiment);
-    if (r > 0) {
+    int ret = update(secExperiment);
+    if (ret > 0) {
       //设置待送检状态
       //设置待送检状态
-      r = secExperimentMapper.updateScheduled(secExperiment.getId(), "0");
+      ret = secExperimentMapper.updateScheduled(secExperiment.getId(), TestStateEnum.WAITING.getCode());
+      // 更新工具最后实验时间
+      List<BaseSafetyTool> toolList =  toolMapper.listByExperimentId(secExperiment.getId());
+      for(BaseSafetyTool tool : toolList){
+        tool.setLastTestDate(secExperiment.getExpDate());
+        toolMapper.update(tool);
+      }
     }
     }
-    return r;
+    return ret;
   }
   }
 
 
   /**
   /**
    * 设置安全工具
    * 设置安全工具
    *
    *
-   * @param p 设置参数
+   * @param param 设置参数
    * @return 设置结果
    * @return 设置结果
    */
    */
   @Override
   @Override
   @Transactional(rollbackFor = Exception.class)
   @Transactional(rollbackFor = Exception.class)
-  public int nq(SecExpNQParmVo p) {
-    SecExperimentTool set = new SecExperimentTool();
-    BeanUtils.copyProperties(p, set);
-    set.setUpdateTime(new Date());
-    set.setUpdateBy(SecurityUtils.getUsername());
-    return secExperimentToolMapper.update(set);
+  public int setToolTestState(SecExpNQParmVo param) {
+    SecExperimentTool experimentTool = secExperimentToolMapper.getInfo(param.getId());
+    experimentTool.setIsok(param.getIsok());
+    experimentTool.setUpdateTime(new Date());
+    experimentTool.setUpdateBy(SecurityUtils.getUsername());
+    int ret = secExperimentToolMapper.update(experimentTool);
+    // 如果工具不合格,则同时更新安全工具记录状态为报废
+    if(ret > 0 && param.getIsok().equals(ToolStateEnum.SCRAP.getCode())){
+      BaseSafetyTool tool = toolMapper.getInfo(experimentTool.getToolId());
+      tool.setState(ToolStateEnum.SCRAP.getCode());
+      toolMapper.update(tool);
+    }
+    return ret;
   }
   }
 
 
   /**
   /**

+ 30 - 15
railway-business/src/main/java/com/railway/business/safetool/service/impl/SecScheduledServiceImpl.java

@@ -7,6 +7,7 @@ import com.railway.business.safetool.domain.vo.SecScheduledCountVo;
 import com.railway.business.safetool.domain.vo.SecScheduledListParmVo;
 import com.railway.business.safetool.domain.vo.SecScheduledListParmVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolListVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolListVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolVo;
 import com.railway.business.safetool.domain.vo.SecScheduledToolVo;
+import com.railway.business.safetool.enums.TestStateEnum;
 import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.mapper.BaseSafetyToolMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
 import com.railway.business.safetool.mapper.SecScheduledToolMapper;
 import com.railway.business.safetool.mapper.SecScheduledToolMapper;
@@ -49,32 +50,38 @@ public class SecScheduledServiceImpl implements ISecScheduledService {
    */
    */
   @Override
   @Override
   @Transactional(rollbackFor = Exception.class)
   @Transactional(rollbackFor = Exception.class)
-  public Long create(SecScheduledToolListVo secScheduled) throws Exception {
-    secScheduled.setCreateTime(new Date());
-    secScheduled.setCreateBy(SecurityUtils.getUsername());
-    List<SecScheduledToolVo> baseSafetyTools = secScheduled.getBaseSafetyTools();
+  public Long create(SecScheduledToolListVo scheduledToolVo) throws Exception {
+    scheduledToolVo.setCreateTime(new Date());
+    scheduledToolVo.setCreateBy(SecurityUtils.getUsername());
+    List<SecScheduledToolVo> baseSafetyTools = scheduledToolVo.getBaseSafetyTools();
 
 
     if (CollectionUtils.isEmpty(baseSafetyTools)) {
     if (CollectionUtils.isEmpty(baseSafetyTools)) {
       throw new Exception("安全工具不能为空");
       throw new Exception("安全工具不能为空");
     }
     }
-    SecScheduled s = new SecScheduled();
-    BeanUtils.copyBeanProp(s, secScheduled);
-    s.setState("0");
-    s.setDelFlag("0");
-    int r = secScheduledMapper.insert(s);
+    SecScheduled scheduled = new SecScheduled();
+    BeanUtils.copyBeanProp(scheduled, scheduledToolVo);
+    scheduled.setState(TestStateEnum.WAITING.getCode());
+    scheduled.setDelFlag("0");
+    int r = secScheduledMapper.insert(scheduled);
     if (r < 1) {
     if (r < 1) {
       throw new Exception("计划插入失败");
       throw new Exception("计划插入失败");
     }
     }
     for (SecScheduledToolVo t : baseSafetyTools) {
     for (SecScheduledToolVo t : baseSafetyTools) {
+      // 插入计划-工具映射关系
       SecScheduledTool secScheduledTool = new SecScheduledTool();
       SecScheduledTool secScheduledTool = new SecScheduledTool();
-      secScheduledTool.setScheduledId(s.getId());
+      secScheduledTool.setScheduledId(scheduled.getId());
       secScheduledTool.setToolId(t.getToolId());
       secScheduledTool.setToolId(t.getToolId());
       r = secScheduledToolMapper.insert(secScheduledTool);
       r = secScheduledToolMapper.insert(secScheduledTool);
       if (r < 1) {
       if (r < 1) {
         throw new Exception("计划关系插入失败");
         throw new Exception("计划关系插入失败");
       }
       }
+      // 更新工具下次实验时间
+      BaseSafetyTool tool = new BaseSafetyTool();
+      tool.setToolId(t.getToolId());
+      tool.setNextTestDate(scheduled.getScheduledTime());
+      safetyToolMapper.update(tool);
     }
     }
-    return s.getId();
+    return scheduled.getId();
   }
   }
 
 
   /**
   /**
@@ -106,8 +113,8 @@ public class SecScheduledServiceImpl implements ISecScheduledService {
    * 获取单个
    * 获取单个
    */
    */
   @Override
   @Override
-  public SecScheduledToolListVo getInfo(String id) {
-    return secScheduledMapper.getInfo(id);
+  public SecScheduledToolListVo getInfo(Long id) {
+    return secScheduledMapper.getDetail(id);
   }
   }
 
 
   /**
   /**
@@ -145,13 +152,21 @@ public class SecScheduledServiceImpl implements ISecScheduledService {
     if (!safetyTool.getDeptId().equals(sysUser.getDeptId())) {
     if (!safetyTool.getDeptId().equals(sysUser.getDeptId())) {
       throw new Exception("该工具归属“" + safetyTool.getDeptName() + "”管理,请检查后重新操作");
       throw new Exception("该工具归属“" + safetyTool.getDeptName() + "”管理,请检查后重新操作");
     }
     }
-
+    // 查询计划详情
+    SecScheduled scheduled = secScheduledMapper.getInfo(toolsVo.getScheduledId());
+    // 创建计划-工具映射关系对象
     SecScheduledTool secScheduledTool = new SecScheduledTool();
     SecScheduledTool secScheduledTool = new SecScheduledTool();
     secScheduledTool.setScheduledId(toolsVo.getScheduledId());
     secScheduledTool.setScheduledId(toolsVo.getScheduledId());
     secScheduledTool.setToolId(toolsVo.getToolId());
     secScheduledTool.setToolId(toolsVo.getToolId());
 
 
     if (secScheduledToolMapper.check(secScheduledTool) == 0) {
     if (secScheduledToolMapper.check(secScheduledTool) == 0) {
-      return secScheduledToolMapper.insert(secScheduledTool);
+      int ret = secScheduledToolMapper.insert(secScheduledTool);
+      if(ret > 0){
+        // 更新工具下次实验时间
+        safetyTool.setNextTestDate(scheduled.getScheduledTime());
+        safetyToolMapper.update(safetyTool);
+      }
+      return ret;
     } else {
     } else {
       throw new Exception("该工具已经添加到其他计划中,请删除后重新操作");
       throw new Exception("该工具已经添加到其他计划中,请删除后重新操作");
     }
     }

+ 27 - 8
railway-business/src/main/resources/mapper/safetool/BaseSafetyToolMapper.xml

@@ -40,17 +40,14 @@
   <sql id="Base_Column_List">
   <sql id="Base_Column_List">
     t.tool_id,
     t.tool_id,
     t.dept_id,
     t.dept_id,
-    d.dept_name,
     t.store_place,
     t.store_place,
-    dt1.dict_label as tool_name,
     t.tool_type,
     t.tool_type,
     t.tool_code,
     t.tool_code,
     t.tool_qcode,
     t.tool_qcode,
     t.qcode_url,
     t.qcode_url,
     t.elec_level,
     t.elec_level,
-    dt1.remark unit,
     t.test_cycle,
     t.test_cycle,
-    dt2.dict_label as test_cycle_text,
+    t.unit,
     t.last_test_date,
     t.last_test_date,
     t.next_test_date,
     t.next_test_date,
     t.test_result,
     t.test_result,
@@ -292,7 +289,10 @@
 
 
   <select id="getInfo" resultMap="BaseResultMap">
   <select id="getInfo" resultMap="BaseResultMap">
     SELECT
     SELECT
-    <include refid="Base_Column_List"/>
+    <include refid="Base_Column_List"/>,
+    d.dept_name,
+    dt1.dict_label as tool_name,
+    dt2.dict_label as test_cycle_text
     FROM base_safety_tool t
     FROM base_safety_tool t
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
@@ -302,7 +302,10 @@
 
 
   <select id="getInfoByQcode" resultMap="BaseResultMap">
   <select id="getInfoByQcode" resultMap="BaseResultMap">
     SELECT
     SELECT
-    <include refid="Base_Column_List"/>
+    <include refid="Base_Column_List"/>,
+    d.dept_name,
+    dt1.dict_label as tool_name,
+    dt2.dict_label as test_cycle_text
     FROM base_safety_tool t
     FROM base_safety_tool t
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
@@ -312,7 +315,10 @@
 
 
   <select id="getList" resultMap="BaseResultMap">
   <select id="getList" resultMap="BaseResultMap">
     SELECT
     SELECT
-    <include refid="Base_Column_List"/>
+    <include refid="Base_Column_List"/>,
+    d.dept_name,
+    dt1.dict_label as tool_name,
+    dt2.dict_label as test_cycle_text
     FROM base_safety_tool t
     FROM base_safety_tool t
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
@@ -404,7 +410,10 @@
 
 
   <select id="getListByIds" resultMap="BaseResultMap">
   <select id="getListByIds" resultMap="BaseResultMap">
     SELECT
     SELECT
-    <include refid="Base_Column_List"/>
+    <include refid="Base_Column_List"/>,
+    d.dept_name,
+    dt1.dict_label as tool_name,
+    dt2.dict_label as test_cycle_text
     FROM base_safety_tool t
     FROM base_safety_tool t
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dept d on t.dept_id = d.dept_id
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
     LEFT JOIN sys_dict_data dt1 ON (t.tool_type = dt1.dict_value AND dt1.dict_type = 'tool_type')
@@ -415,4 +424,14 @@
     </foreach>
     </foreach>
   </select>
   </select>
 
 
+  <select id="listByExperimentId"
+          resultType="com.railway.business.safetool.domain.BaseSafetyTool">
+
+  </select>
+
+  <select id="listByScheduledId"
+          resultType="com.railway.business.safetool.domain.BaseSafetyTool">
+
+  </select>
+
 </mapper>
 </mapper>

+ 2 - 1
railway-business/src/main/resources/mapper/safetool/SecExperimentMapper.xml

@@ -21,7 +21,7 @@
 
 
   <insert id="insertTool">
   <insert id="insertTool">
     INSERT INTO sec_experiment_tool (tool_id,isok,exp_id,del_flag,create_time,create_by)
     INSERT INTO sec_experiment_tool (tool_id,isok,exp_id,del_flag,create_time,create_by)
-    select tool_id,'0' isok ,#{expid} exp_id ,'0' del_flag, now() create_time , #{createby}
+    select tool_id,'1' isok ,#{expid} exp_id ,'0' del_flag, now() create_time , #{createby}
     create_by
     create_by
     from sec_scheduled_tool
     from sec_scheduled_tool
     where scheduled_id = #{secid}
     where scheduled_id = #{secid}
@@ -157,6 +157,7 @@
     t.del_flag
     t.del_flag
   </sql>
   </sql>
 
 
+  <!-- state='0' 待实验 -->
   <select id="listExperiment" resultMap="listExperimentResultMap">
   <select id="listExperiment" resultMap="listExperimentResultMap">
     SELECT
     SELECT
     <include refid="list_Column_List"/>
     <include refid="list_Column_List"/>

+ 9 - 1
railway-business/src/main/resources/mapper/safetool/SecScheduledMapper.xml

@@ -114,6 +114,13 @@
     where id = #{secid}
     where id = #{secid}
   </update>
   </update>
 
 
+  <select id="getInfo" resultMap="BaseResultMap">
+    SELECT
+    <include refid="Base_Column_List"/>
+    FROM sec_experiment
+    WHERE del_flag='0' and id = #{id}
+  </select>
+
   <resultMap id="BaseResultMap2" type="com.railway.business.safetool.domain.vo.SecScheduledCountVo">
   <resultMap id="BaseResultMap2" type="com.railway.business.safetool.domain.vo.SecScheduledCountVo">
     <result column="id" property="id"/>
     <result column="id" property="id"/>
     <result column="dept_id" property="deptId"/>
     <result column="dept_id" property="deptId"/>
@@ -161,7 +168,7 @@
     </collection>
     </collection>
   </resultMap>
   </resultMap>
 
 
-  <select id="getInfo" resultMap="BaseResultMap">
+  <select id="getDetail" resultMap="BaseResultMap">
     select s.id, s.dept_id, s.lab_id, s.scheduled_time,
     select s.id, s.dept_id, s.lab_id, s.scheduled_time,
     d1.dept_name deptName, d2.dept_name labName,
     d1.dept_name deptName, d2.dept_name labName,
     d3.dict_label toolName ,t.unit,t.tool_id,t.tool_code, r.id as scheduled_tool_id
     d3.dict_label toolName ,t.unit,t.tool_id,t.tool_code, r.id as scheduled_tool_id
@@ -193,6 +200,7 @@
     t.del_flag
     t.del_flag
   </sql>
   </sql>
 
 
+  <!-- state='0' 待送检 -->
   <select id="listScheduled" resultMap="listResultMap">
   <select id="listScheduled" resultMap="listResultMap">
     SELECT
     SELECT
     <include refid="list_Column_List"/>
     <include refid="list_Column_List"/>