Jelajahi Sumber

调整八大步骤的数据

车车 10 bulan lalu
induk
melakukan
f60f551c08

+ 20 - 0
ktg-common/src/main/java/com/ktg/common/annotation/MarsDataScope.java

@@ -0,0 +1,20 @@
+package com.ktg.common.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * mars岗位数据权限过滤注解
+ *
+ * @author cgj
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface MarsDataScope
+{
+    /**
+     * 岗位表的别名
+     */
+    public String workstationAlias() default "";
+
+}

+ 125 - 0
ktg-framework/src/main/java/com/ktg/framework/aspectj/MarsDataScopeAspect.java

@@ -0,0 +1,125 @@
+package com.ktg.framework.aspectj;
+
+import com.ktg.common.annotation.MarsDataScope;
+import com.ktg.common.core.domain.BaseEntity;
+import com.ktg.common.core.domain.entity.SysRole;
+import com.ktg.common.core.domain.entity.SysUser;
+import com.ktg.common.core.domain.model.LoginUser;
+import com.ktg.common.utils.SecurityUtils;
+import com.ktg.common.utils.StringUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.springframework.stereotype.Component;
+
+/**
+ * 数据过滤处理
+ *
+ * @author guoruan
+ */
+@Aspect
+@Component
+public class MarsDataScopeAspect {
+    /**
+     * 全部数据权限
+     */
+    public static final String DATA_SCOPE_ALL = "1";
+
+    /**
+     * 自定数据权限
+     */
+    public static final String DATA_SCOPE_CUSTOM = "2";
+
+    /**
+     * 部门数据权限
+     */
+    public static final String DATA_SCOPE_DEPT = "3";
+
+    /**
+     * 部门及以下数据权限
+     */
+    public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
+
+    /**
+     * 仅本人数据权限
+     */
+    public static final String DATA_SCOPE_SELF = "5";
+
+    /**
+     * 数据权限过滤关键字
+     */
+    public static final String DATA_SCOPE = "workstationScope";
+
+    @Before("@annotation(controllerDataScope)")
+    public void doBefore(JoinPoint point, MarsDataScope controllerDataScope) {
+        clearDataScope(point);
+        handleDataScope(point, controllerDataScope);
+    }
+
+    protected void handleDataScope(final JoinPoint joinPoint, MarsDataScope controllerDataScope) {
+        // 获取当前的用户
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        if (StringUtils.isNotNull(loginUser)) {
+            SysUser currentUser = loginUser.getUser();
+            // 如果是超级管理员,则不过滤数据
+            if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) {
+                dataScopeFilter(joinPoint, currentUser, controllerDataScope.workstationAlias());
+            }
+        }
+    }
+
+    /**
+     * 数据范围过滤
+     *
+     * @param joinPoint 切点
+     * @param user      用户
+     * @param workstationAlias 别名
+     */
+    public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String workstationAlias) {
+        StringBuilder sqlString = new StringBuilder();
+
+        for (SysRole role : user.getRoles()) {
+            String dataScope = role.getDataScope();
+            if (DATA_SCOPE_ALL.equals(dataScope)) {
+                sqlString = new StringBuilder();
+                break;
+            } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
+                sqlString.append(StringUtils.format(
+                        " OR {}.workstation IN ( SELECT workstation_id FROM sys_role_dept WHERE role_id = {} ) ", workstationAlias,
+                        role.getRoleId()));
+            } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
+                sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", workstationAlias, user.getDeptId()));
+            } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
+                sqlString.append(StringUtils.format(
+                        " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
+                        workstationAlias, user.getDeptId(), user.getDeptId()));
+            } else if (DATA_SCOPE_SELF.equals(dataScope)) {
+                if (StringUtils.isNotBlank(workstationAlias)) {
+                    sqlString.append(StringUtils.format(" OR {}.user_id = {} ", workstationAlias, user.getUserId()));
+                } else {
+                    // 数据权限为仅本人且没有userAlias别名不查询任何数据
+                    sqlString.append(" OR 1=0 ");
+                }
+            }
+        }
+
+        if (StringUtils.isNotBlank(sqlString.toString())) {
+            Object params = joinPoint.getArgs()[0];
+            if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
+                BaseEntity baseEntity = (BaseEntity) params;
+                baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
+            }
+        }
+    }
+
+    /**
+     * 拼接权限sql前先清空params.dataScope参数防止注入
+     */
+    private void clearDataScope(final JoinPoint joinPoint) {
+        Object params = joinPoint.getArgs()[0];
+        if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
+            BaseEntity baseEntity = (BaseEntity) params;
+            baseEntity.getParams().put(DATA_SCOPE, "");
+        }
+    }
+}

+ 13 - 4
ktg-iscs/src/main/java/com/ktg/iscs/controller/IsJobTicketStepController.java

@@ -4,17 +4,17 @@ import com.ktg.common.core.controller.BaseController;
 import com.ktg.common.pojo.CommonResult;
 import com.ktg.iscs.domain.dto.step.IsJobTicketStepDTO;
 import com.ktg.iscs.domain.dto.ticket.AddJobTicketDTO;
+import com.ktg.iscs.domain.vo.step.IsJobTicketStepVO;
 import com.ktg.iscs.service.IIsJobTicketStepService;
 import com.ktg.iscs.service.IIsJobTicketUserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.v3.oas.annotations.Parameter;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 
 /**
  * 作业票执行步骤Controller
@@ -31,6 +31,8 @@ public class IsJobTicketStepController extends BaseController {
     private IIsJobTicketStepService isJobTicketStepService;
     @Autowired
     private IIsJobTicketUserService iIsJobTicketUserService;
+    @Autowired
+    private IIsJobTicketStepService iIsJobTicketStepService;
 
     @ApiOperation("八大步骤执行")
     @PostMapping("/updateJobStep")
@@ -44,5 +46,12 @@ public class IsJobTicketStepController extends BaseController {
         return CommonResult.success(iIsJobTicketUserService.addJobUsers(dto));
     }
 
+    @ApiOperation("获取八大步骤详细")
+    @Parameter(name = "ticketId", description = "ticketId")
+    @GetMapping(value = "/selectStepsByTicketId")
+    public CommonResult<List<IsJobTicketStepVO>> selectStepsByTicketId(Long ticketId) {
+        return CommonResult.success(iIsJobTicketStepService.selectStepsByTicketId(ticketId));
+    }
+
 
 }

+ 54 - 0
ktg-iscs/src/main/java/com/ktg/iscs/domain/vo/step/IsJobTicketStepVO.java

@@ -0,0 +1,54 @@
+package com.ktg.iscs.domain.vo.step;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.ktg.common.annotation.Excel;
+import com.ktg.common.core.domain.model.BaseBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * 作业票执行步骤对象 is_job_ticket_step
+ *
+ * @author cgj
+ * @date 2024-12-23
+ */
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+@Data
+public class IsJobTicketStepVO extends BaseBean
+{
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "执行步骤ID")
+    @TableId(type = IdType.AUTO)
+    private Long stepId;
+
+    @ApiModelProperty(value = "所属作业票ID")
+    @Excel(name = "所属作业票ID")
+    private Long ticketId;
+
+    @ApiModelProperty(value = "执行步骤序号")
+    @Excel(name = "执行步骤序号")
+    private Integer stepIndex;
+
+    @ApiModelProperty(value = "步骤状态(0-未执行 1-已执行)")
+    @Excel(name = "步骤状态(0-未执行 1-已执行)")
+    private String stepStatus;
+
+    @ApiModelProperty(value = "作业步骤详情")
+    @Excel(name = "作业步骤详情")
+    private String stepContent;
+
+    @ApiModelProperty(value = "锁计数")
+    private Integer lockNum;
+
+    @ApiModelProperty(value = "人员计数")
+    private Integer userNum;
+
+    @ApiModelProperty(value = "冲突的作业票数")
+    private Integer conflictJobNum;
+
+}

+ 5 - 0
ktg-iscs/src/main/java/com/ktg/iscs/service/IIsJobTicketStepService.java

@@ -3,6 +3,9 @@ package com.ktg.iscs.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ktg.iscs.domain.IsJobTicketStep;
 import com.ktg.iscs.domain.dto.step.IsJobTicketStepDTO;
+import com.ktg.iscs.domain.vo.step.IsJobTicketStepVO;
+
+import java.util.List;
 
 /**
  * 作业票执行步骤Service接口
@@ -14,4 +17,6 @@ public interface IIsJobTicketStepService extends IService<IsJobTicketStep> {
 
     Boolean updateJobStep(IsJobTicketStepDTO dto);
 
+    List<IsJobTicketStepVO> selectStepsByTicketId(Long ticketId);
+
 }

+ 57 - 3
ktg-iscs/src/main/java/com/ktg/iscs/service/impl/IsJobTicketStepServiceImpl.java

@@ -3,13 +3,22 @@ package com.ktg.iscs.service.impl;
 import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ktg.common.utils.bean.BeanUtils;
+import com.ktg.iscs.domain.IsJobTicketPoints;
 import com.ktg.iscs.domain.IsJobTicketStep;
+import com.ktg.iscs.domain.IsJobTicketUser;
 import com.ktg.iscs.domain.dto.step.IsJobTicketStepDTO;
+import com.ktg.iscs.domain.vo.step.IsJobTicketStepVO;
 import com.ktg.iscs.mapper.IsJobTicketStepMapper;
+import com.ktg.iscs.service.IIsJobTicketPointsService;
 import com.ktg.iscs.service.IIsJobTicketStepService;
+import com.ktg.iscs.service.IIsJobTicketUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * 作业票执行步骤Service业务层处理
  *
@@ -21,14 +30,59 @@ public class IsJobTicketStepServiceImpl extends ServiceImpl<IsJobTicketStepMappe
 
     @Autowired
     private IsJobTicketStepMapper isJobTicketStepMapper;
+    @Autowired
+    private IIsJobTicketPointsService iIsJobTicketPointsService;
+    @Autowired
+    private IIsJobTicketUserService iIsJobTicketUserService;
+
 
     @Override
     public Boolean updateJobStep(IsJobTicketStepDTO dto) {
         Assert.notNull(dto.getStepId(), "步骤Id不可为空!");
         Assert.notNull(dto.getStepStatus(), "状态不可为空!");
-        update(Wrappers.<IsJobTicketStep>lambdaUpdate()
-                .eq(IsJobTicketStep::getStepId, dto.getStepId())
-                .set(IsJobTicketStep::getStepStatus, dto.getStepStatus()));
+        update(Wrappers.<IsJobTicketStep>lambdaUpdate().eq(IsJobTicketStep::getStepId, dto.getStepId()).set(IsJobTicketStep::getStepStatus, dto.getStepStatus()));
         return true;
     }
+
+    @Override
+    public List<IsJobTicketStepVO> selectStepsByTicketId(Long ticketId) {
+        Assert.notNull(ticketId, "作业票id不能为空!");
+        List<IsJobTicketStep> stepList = list(Wrappers.<IsJobTicketStep>lambdaQuery().eq(IsJobTicketStep::getTicketId, ticketId));
+        List<IsJobTicketStepVO> stepVOList = BeanUtils.toBean(stepList, IsJobTicketStepVO.class);
+        // 1.获取需要分析的数据
+        List<IsJobTicketPoints> pointList = iIsJobTicketPointsService.list(Wrappers.<IsJobTicketPoints>lambdaQuery()
+                .eq(IsJobTicketPoints::getTicketId, ticketId));
+        List<IsJobTicketUser> userList = iIsJobTicketUserService.list(Wrappers.<IsJobTicketUser>lambdaQuery()
+                .eq(IsJobTicketUser::getTicketId, ticketId));
+        // 1.1读取第三步的计数
+        int oneLockNum = pointList.size();
+        int oneUserNum = userList.size();
+        stepVOList.get(2).setLockNum(oneLockNum).setUserNum(oneUserNum);
+        // 1.2读取第五步的计数
+        int twoLockNum = (int) pointList.stream()
+                .filter(o -> o.getPointStatus() != null && Integer.parseInt(o.getPointStatus()) >= 1).count();
+        int twoUserNum = (int) userList.stream()
+                .filter(o -> o.getJobStatus() != null && o.getJobStatus() >= 4).count();
+        stepVOList.get(4).setLockNum(twoLockNum).setUserNum(twoUserNum);
+        // 1.3读取第八步的计数
+        int threeLockNum = (int) pointList.stream()
+                .filter(o -> o.getPointStatus() != null && Integer.parseInt(o.getPointStatus()) != 2).count();
+        int threeUserNum = (int) userList.stream()
+                .filter(o -> o.getJobStatus() != null && o.getJobStatus() != 5).count();
+        stepVOList.get(7).setLockNum(threeLockNum).setUserNum(threeUserNum).setConflictJobNum(0);
+        // 2读取第八步的作业票干扰,判断该作业票点位被哪些额外作业票锁定了
+        // 2.1获取被其他作业票锁定的隔离点
+        if (!pointList.isEmpty()) {
+            List<Long> pointIds = pointList.stream().map(IsJobTicketPoints::getPointId).collect(Collectors.toList());
+            List<IsJobTicketPoints> conflictPoints = iIsJobTicketPointsService.list(Wrappers.<IsJobTicketPoints>lambdaQuery()
+                    .in(IsJobTicketPoints::getPointId, pointIds)
+                    .ne(IsJobTicketPoints::getTicketId, ticketId)
+                    .eq(IsJobTicketPoints::getPointStatus, 1));
+            if (!conflictPoints.isEmpty()) {
+                int conflictJobNum = (int) conflictPoints.stream().map(IsJobTicketPoints::getTicketId).distinct().count();
+                stepVOList.get(7).setConflictJobNum(conflictJobNum);
+            }
+        }
+        return stepVOList;
+    }
 }