Explorar el Código

【BUG】修复禅道Bug #189,#193

ZhaoMn hace 3 años
padre
commit
e2779f9b14

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

@@ -5,8 +5,6 @@ import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.common.annotation.Log;
 import com.railway.common.core.controller.BaseController;
 import com.railway.common.core.domain.AjaxResult;
-import com.railway.common.core.domain.entity.SysRole;
-import com.railway.common.core.domain.entity.SysUser;
 import com.railway.common.enums.BusinessType;
 import com.railway.common.utils.QrCodeUtil;
 import com.railway.common.utils.SecurityUtils;
@@ -44,19 +42,9 @@ public class SecQcodeController extends BaseController {
     if (null == tool) {
       return AjaxResult.error("二维码已失效,请检查!");
     }
-    if(!SecurityUtils.isAdmin()){
-      String labRoleName = "实验员";
-      boolean isLabRole = false;
-      SysUser user = SecurityUtils.getLoginUser().getUser();
-      List<SysRole> roles = user.getRoles();
-      for(SysRole role : roles){
-        if(labRoleName.equals(role.getRoleKey())){
-          isLabRole = true;
-          break;
-        }
-      }
-      Long deptId = user.getDeptId();
-      if (!isLabRole && tool.getDeptId().compareTo(deptId) != 0) {
+    if(SecurityUtils.isNotLabUser()){
+      Long deptId = SecurityUtils.getDeptId();
+      if (tool.getDeptId().compareTo(deptId) != 0) {
         return AjaxResult.error("非本车间安全工具,请检查!");
       }
     }

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

@@ -143,6 +143,12 @@ public class BaseSafetyTool extends BaseEntity {
   @ApiModelProperty(value = "del_flag")
   private String delFlag;
 
+  @ApiModelProperty(value = "要排序的列")
+  private String orderBy;
+
+  @ApiModelProperty(value = "1-ASC 正序排序,0-DESC 倒序排序")
+  private String isAsc;
+
   public BaseSafetyTool() {
   }
 

+ 5 - 2
railway-business/src/main/java/com/railway/business/safetool/domain/vo/SecExpListParmVo.java

@@ -23,8 +23,11 @@ public class SecExpListParmVo implements Serializable {
     @ApiModelProperty(value = "送检车间ID")
     private Long deptId;
 
-    @ApiModelProperty(value = "排序ASC DESC")
-    private String orderby;
+    @ApiModelProperty(value = "要排序的列")
+    private String orderBy;
+
+    @ApiModelProperty(value = "1-ASC 正序排序,0-DESC 倒序排序")
+    private String isAsc;
 
     @ApiModelProperty(value = "状态:1已实验  0未实验")
     private String state;

+ 4 - 5
railway-business/src/main/java/com/railway/business/safetool/domain/vo/SecScheduledListParmVo.java

@@ -20,11 +20,10 @@ public class SecScheduledListParmVo implements Serializable {
     @ApiModelProperty(value = "实验室ID")
     protected Long labId;
 
-    @ApiModelProperty(value = "排序方式 asc desc")
-    protected String orderby;
+    @ApiModelProperty(value = "要排序的列")
+    private String orderBy;
 
-
-    public SecScheduledListParmVo() {
-    }
+    @ApiModelProperty(value = "1-ASC 正序排序,0-DESC 倒序排序")
+    private String isAsc;
 
 }

+ 2 - 18
railway-business/src/main/java/com/railway/business/safetool/service/impl/BaseSafetyToolServiceImpl.java

@@ -12,8 +12,6 @@ import com.railway.business.safetool.mapper.SecExperimentMapper;
 import com.railway.business.safetool.mapper.SecScheduledMapper;
 import com.railway.business.safetool.service.IBaseSafetyToolService;
 import com.railway.common.core.domain.AjaxResult;
-import com.railway.common.core.domain.entity.SysRole;
-import com.railway.common.core.domain.entity.SysUser;
 import com.railway.common.enums.QcodeEnum;
 import com.railway.common.qrcode.impl.SnowflakeClient;
 import com.railway.common.utils.DateUtils;
@@ -170,23 +168,9 @@ public class BaseSafetyToolServiceImpl implements IBaseSafetyToolService {
    */
   @Override
   public List<BaseSafetyTool> getList(BaseSafetyTool baseSafetyTool) {
-    if(!SecurityUtils.isAdmin()){
-      String labRoleName = "实验员";
-      boolean isLabRole = false;
-      SysUser user = SecurityUtils.getLoginUser().getUser();
-      List<SysRole> roles = user.getRoles();
-      for(SysRole role : roles){
-        if(labRoleName.equals(role.getRoleKey())){
-          isLabRole = true;
-          break;
-        }
-      }
-      if (!isLabRole) {
-        Long deptId = user.getDeptId();
-        baseSafetyTool.setDeptId(deptId);
-      }
+    if(SecurityUtils.isNotLabUser()){
+      baseSafetyTool.setDeptId(SecurityUtils.getDeptId());
     }
-
     List<BaseSafetyTool> list = safetyToolMapper.getList(baseSafetyTool);
     for(BaseSafetyTool tool : list){
       if(StringUtils.isEmpty(tool.getToolQcode()) || StringUtils.isEmpty(tool.getQcodeUrl())) {

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

@@ -29,6 +29,7 @@ import com.railway.common.utils.file.FileUploadUtils;
 import com.railway.common.utils.file.FileUtils;
 import com.railway.system.service.ISysFileService;
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -110,15 +111,18 @@ public class SecExperimentServiceImpl implements ISecExperimentService {
     SecExperiment secExperiment = new SecExperiment();
     BeanUtils.copyProperties(secExpInfoVo, secExperiment);
     secExperiment.setState(TestStateEnum.ALREADY.getCode());
-    secExperiment.setExpDate(new Date());
+    Date expDate = new Date();
+    secExperiment.setExpDate(expDate);
 
     ExpReportVo reportVo = new ExpReportVo();
     // 工具清单
     Map<String, ExpReportDetailVo> detailMap = new LinkedHashMap<>();
-
+    // 查询实验工具
     List<BaseSafetyTool> toolList = toolMapper.listByExperimentId(secExperiment.getId());
     reportVo.setTotal(toolList.size());
+    List<Integer> toolCycleList = new ArrayList<>();
     for (BaseSafetyTool tool : toolList) {
+      toolCycleList.add(tool.getTestCycle());
       ExpReportDetailVo detail = detailMap.get(tool.getToolType());
       if (null == detail) {
         detail = new ExpReportDetailVo();
@@ -128,7 +132,9 @@ public class SecExperimentServiceImpl implements ISecExperimentService {
       }
       detail.setTotal(detail.getTotal() + 1);
       // 更新工具最后实验时间
-      tool.setLastTestDate(secExperiment.getExpDate());
+      tool.setLastTestDate(expDate);
+      Date nextDate = DateUtils.addMonths(expDate, tool.getTestCycle());
+      tool.setNextTestDate(nextDate);
       toolMapper.update(tool);
       if (ToolStateEnum.SCRAP.getCode().equals(tool.getState())) {
         reportVo.setScrapTotal(reportVo.getScrapTotal() + 1);
@@ -178,6 +184,10 @@ public class SecExperimentServiceImpl implements ISecExperimentService {
       //设置计划为待送检状态
       SecScheduled scheduled = scheduledMapper.getInfoByExpId(secExperiment.getId());
       scheduled.setState(TestStateEnum.WAITING.getCode());
+      if(toolCycleList.size() > 0) {
+        int minCycle = toolCycleList.stream().reduce(Integer::min).get();
+        scheduled.setScheduledTime(DateUtils.addMonths(expDate, minCycle));
+      }
       ret = scheduledMapper.update(scheduled);
     }
     return ret;
@@ -232,7 +242,7 @@ public class SecExperimentServiceImpl implements ISecExperimentService {
    */
   @Override
   public List<SecExpListVo> getList(SecExpListParmVo parm) {
-    if (!SecurityUtils.isAdmin()) {
+    if (SecurityUtils.isNotLabUser()) {
       parm.setDeptId(SecurityUtils.getLoginUser().getDeptId());
     }
     return secExperimentMapper.getList(parm);

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

@@ -406,6 +406,15 @@
         and DATE_FORMAT(t.update_time, '%Y-%m-%d') = #{updateTime}
       </if>
     </where>
+    order by t.next_test_date
+    <if test="isAsc!=null and isAsc!=''">
+      <if test="isAsc == '1'.toString()">
+        asc
+      </if>
+      <if test="isAsc == '0'.toString()">
+        desc
+      </if>
+    </if>
   </select>
 
   <select id="getListByIds" resultMap="BaseResultMap">

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

@@ -128,8 +128,14 @@
         and e.scheduled_time =#{scheduledTime}
       </if>
     </where>
-    <if test="orderby!=null and orderby!=''">
-      order by end_time ${orderby}
+    order by e.end_time
+    <if test="isAsc!=null and isAsc!=''">
+      <if test="isAsc == '1'.toString()">
+        asc
+      </if>
+      <if test="isAsc == '0'.toString()">
+        desc
+      </if>
     </if>
   </select>
 

+ 8 - 2
railway-business/src/main/resources/mapper/safetool/SecScheduledMapper.xml

@@ -157,8 +157,14 @@
       </if>
     </where>
     group by s.id
-    <if test="orderby!=null and orderby!=''">
-      order by scheduled_time ${orderby}
+    order by s.scheduled_time
+    <if test="isAsc!=null and isAsc!=''">
+      <if test="isAsc == '1'.toString()">
+        asc
+      </if>
+      <if test="isAsc == '0'.toString()">
+        desc
+      </if>
     </if>
   </select>
 

+ 23 - 0
railway-common/src/main/java/com/railway/common/utils/SecurityUtils.java

@@ -1,8 +1,11 @@
 package com.railway.common.utils;
 
 import com.railway.common.constant.HttpStatus;
+import com.railway.common.core.domain.entity.SysRole;
+import com.railway.common.core.domain.entity.SysUser;
 import com.railway.common.core.domain.model.LoginUser;
 import com.railway.common.exception.ServiceException;
+import java.util.List;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@@ -108,4 +111,24 @@ public class SecurityUtils {
     return userId != null && 1L == userId;
   }
 
+  /**
+   * 是否为实验员
+   *
+   * @return 结果
+   */
+  public static boolean isNotLabUser() {
+    if(isAdmin()){
+      return false;
+    }
+    String labRoleName = "实验员";
+    SysUser user = getLoginUser().getUser();
+    List<SysRole> roles = user.getRoles();
+    for(SysRole role : roles){
+      if(labRoleName.equals(role.getRoleKey())){
+        return false;
+      }
+    }
+    return true;
+  }
+
 }