|
|
@@ -7,18 +7,24 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ktg.common.core.text.Convert;
|
|
|
import com.ktg.common.utils.DateUtils;
|
|
|
import com.ktg.common.utils.bean.BeanUtils;
|
|
|
-import com.ktg.iscs.domain.*;
|
|
|
+import com.ktg.iscs.domain.IsJobTicket;
|
|
|
+import com.ktg.iscs.domain.IsJobTicketPoints;
|
|
|
+import com.ktg.iscs.domain.IsJobTicketUser;
|
|
|
import com.ktg.iscs.domain.dto.ticket.AddJobTicketDTO;
|
|
|
import com.ktg.iscs.domain.dto.ticket.AddTicketUserDTO;
|
|
|
import com.ktg.iscs.domain.dto.ticket.PageTicketDTO;
|
|
|
+import com.ktg.iscs.domain.enums.JobStatusEnum;
|
|
|
+import com.ktg.iscs.domain.enums.TicketStatusEnum;
|
|
|
import com.ktg.iscs.domain.vo.points.PointDetailVO;
|
|
|
import com.ktg.iscs.domain.vo.ticket.JobTicketDetailVO;
|
|
|
+import com.ktg.iscs.domain.vo.ticket.JobTicketUpdateProgressReqVO;
|
|
|
import com.ktg.iscs.domain.vo.ticket.PageTicketVO;
|
|
|
import com.ktg.iscs.mapper.IsJobTicketMapper;
|
|
|
import com.ktg.iscs.service.IIsIsolationPointService;
|
|
|
import com.ktg.iscs.service.IIsJobTicketPointsService;
|
|
|
import com.ktg.iscs.service.IIsJobTicketService;
|
|
|
import com.ktg.iscs.service.IIsJobTicketUserService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -29,6 +35,12 @@ import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.ktg.iscs.domain.constant.ErrorCodeConstants.*;
|
|
|
+import static com.ktg.iscs.domain.enums.JobUserEnum.JTCOLOCKER;
|
|
|
+import static com.ktg.iscs.domain.enums.JobUserEnum.JTLOCKER;
|
|
|
+import static com.ktg.iscs.domain.enums.TicketStatusEnum.*;
|
|
|
+import static com.ktg.system.strategy.ServiceExceptionUtil.exception;
|
|
|
+
|
|
|
/**
|
|
|
* 作业票Service业务层处理
|
|
|
*
|
|
|
@@ -36,6 +48,7 @@ import java.util.stream.Collectors;
|
|
|
* @date 2024-10-18
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class IsJobTicketServiceImpl extends ServiceImpl<IsJobTicketMapper, IsJobTicket> implements IIsJobTicketService
|
|
|
{
|
|
|
@Autowired
|
|
|
@@ -47,7 +60,6 @@ public class IsJobTicketServiceImpl extends ServiceImpl<IsJobTicketMapper, IsJob
|
|
|
@Autowired
|
|
|
private IIsIsolationPointService iIsIsolationPointService;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 查询作业票
|
|
|
*
|
|
|
@@ -248,4 +260,132 @@ public class IsJobTicketServiceImpl extends ServiceImpl<IsJobTicketMapper, IsJob
|
|
|
public Page<PageTicketVO> getIsJobTicketPage(Page<IsJobTicket> page, PageTicketDTO dto) {
|
|
|
return isJobTicketMapper.getIsJobTicketPage(page, dto);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean updateTicketProgress(JobTicketUpdateProgressReqVO reqVO) {
|
|
|
+ IsJobTicket isJobTicket = isJobTicketMapper.selectIsJobTicketByTicketId(reqVO.ticketId);
|
|
|
+ if (isJobTicket == null) {
|
|
|
+ log.error("Job ticket not exists, ticketId: {}, userId : {}", reqVO.ticketId, reqVO.userId);
|
|
|
+ throw exception(JOB_TICKET_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<IsJobTicketUser> jobUserList = iIsJobTicketUserService.selectIsJobTicketUserListByTicketId(reqVO.ticketId);
|
|
|
+ if (jobUserList.isEmpty()) {
|
|
|
+ log.error("Job ticket user not exists, ticketId: {}, userId : {}", reqVO.ticketId, reqVO.userId);
|
|
|
+ throw exception(JOB_TICKET_USER_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可能身兼数职
|
|
|
+ List<IsJobTicketUser> matchList = jobUserList.stream().filter(jobUser -> Objects.equals(jobUser.getUserId(), reqVO.userId)).collect(Collectors.toList());
|
|
|
+ if (matchList.isEmpty()) {
|
|
|
+ log.error("Job ticket user not included, ticketId: {}, userId : {}", reqVO.ticketId, reqVO.userId);
|
|
|
+ throw exception(JOB_TICKET_USER_NOT_INCLUDED);
|
|
|
+ } else {
|
|
|
+ handleTicketStatus(isJobTicket, matchList, reqVO.ticketId, reqVO.userId);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理工作票状态
|
|
|
+ * @param isJobTicket 工作票
|
|
|
+ * @param jobUserList 在工作票中的所有人
|
|
|
+ */
|
|
|
+ private void handleTicketStatus(IsJobTicket isJobTicket, List<IsJobTicketUser> jobUserList, Long ticketId, Long userId) {
|
|
|
+ List<IsJobTicketUser> matchUserList = jobUserList.stream().filter(jobUser -> Objects.equals(jobUser.getUserId(), userId)).collect(Collectors.toList());
|
|
|
+ if (Objects.equals(isJobTicket.getTicketStatus(), FINISHED.status)) {
|
|
|
+ log.warn("Job ticket status is finished, cannot update progress, ticketId: {}, userId : {}", ticketId, userId);
|
|
|
+ throw exception(JOB_TICKET_STATUS_FINISHED);
|
|
|
+ }
|
|
|
+ if (matchUserList.stream().anyMatch(user -> Objects.equals(user.getUserRole(), JTLOCKER.key))) {
|
|
|
+ if (Objects.equals(isJobTicket.getTicketStatus(), NOT_STARTED.status)
|
|
|
+ || Objects.equals(isJobTicket.getTicketStatus(), READY_TO_LOCK.status)
|
|
|
+ || Objects.equals(isJobTicket.getTicketStatus(), READY_TO_UNLOCK.status)) {
|
|
|
+ handleJobStatus(isJobTicket, matchUserList, userId, true);
|
|
|
+ } else if (Objects.equals(isJobTicket.getTicketStatus(), PROCESSING.status)) {
|
|
|
+ // 同时为上锁人、共锁人
|
|
|
+ if (matchUserList.stream().anyMatch(user -> Objects.equals(user.getUserRole(), JTCOLOCKER.key))) {
|
|
|
+ handleJobStatus(isJobTicket, jobUserList, userId, false);
|
|
|
+ } else {
|
|
|
+ log.warn("Job ticket status is processing, cannot update progress, ticketId: {}, userId : {}", ticketId, userId);
|
|
|
+ throw exception(JOB_TICKET_STATUS_NOT_PERMITTED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (matchUserList.stream().anyMatch(user -> Objects.equals(user.getUserRole(), JTCOLOCKER.key))) {
|
|
|
+ if (Objects.equals(isJobTicket.getTicketStatus(), NOT_STARTED.status)
|
|
|
+ || Objects.equals(isJobTicket.getTicketStatus(), READY_TO_LOCK.status)
|
|
|
+ || Objects.equals(isJobTicket.getTicketStatus(), READY_TO_UNLOCK.status)) {
|
|
|
+ log.warn("Job ticket status is processing, cannot update progress, ticketId: {}, userId : {}", ticketId, userId);
|
|
|
+ throw exception(JOB_TICKET_STATUS_NOT_PERMITTED);
|
|
|
+ } else if (Objects.equals(isJobTicket.getTicketStatus(), PROCESSING.status)) {
|
|
|
+ handleJobStatus(isJobTicket, jobUserList, userId, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理工作票相关人员作业状态
|
|
|
+ *
|
|
|
+ * @param isJobTicket 工作票
|
|
|
+ * @param jobUserList 在工作票中的所有人
|
|
|
+ * @param isLocker true:上锁人 false:共锁人
|
|
|
+ */
|
|
|
+ private void handleJobStatus(IsJobTicket isJobTicket, List<IsJobTicketUser> jobUserList, Long userId, boolean isLocker) {
|
|
|
+ List<IsJobTicketUser> matchUserList = jobUserList.stream()
|
|
|
+ .filter(jobUser -> Objects.equals(jobUser.getUserId(), userId)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (isLocker) {
|
|
|
+ matchUserList.stream().filter(user -> Objects.equals(user.getUserRole(), JTLOCKER.key)).findFirst().ifPresent(jobUser -> {
|
|
|
+ if (Objects.equals(jobUser.getJobStatus(), JobStatusEnum.NOT_STARTED.status)
|
|
|
+ || Objects.equals(jobUser.getJobStatus(), JobStatusEnum.ACQUIRE_LOCK.status)
|
|
|
+ || Objects.equals(jobUser.getJobStatus(), JobStatusEnum.ACQUIRE_KEY.status)
|
|
|
+ || Objects.equals(jobUser.getJobStatus(), JobStatusEnum.READY_TO_LOCK.status)) {
|
|
|
+ jobUser.setJobStatus(jobUser.getJobStatus() + 1);
|
|
|
+ } else if (Objects.equals(jobUser.getJobStatus(), JobStatusEnum.READY_TO_UNLOCK.status)) {
|
|
|
+ // 检查所有人
|
|
|
+ if (checkJobStatus(isJobTicket, jobUserList)) {
|
|
|
+ jobUser.setJobStatus(JobStatusEnum.UNLOCKED.status);
|
|
|
+ } else {
|
|
|
+ throw exception(JOB_TICKET_USER_WAIT_COLOCKERS);
|
|
|
+ }
|
|
|
+ } else if (Objects.equals(jobUser.getJobStatus(), JobStatusEnum.UNLOCKED.status)) {
|
|
|
+ // 任务已完成,更新
|
|
|
+ jobUser.setJobStatus(JobStatusEnum.UNLOCKED.status);
|
|
|
+ isJobTicket.setTicketStatus(FINISHED.status);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ matchUserList.stream().filter(user -> Objects.equals(user.getUserRole(), JTCOLOCKER.key)).findFirst().ifPresent(jobUser -> {
|
|
|
+ if (Objects.equals(jobUser.getJobStatus(), JobStatusEnum.NOT_STARTED.status)) {
|
|
|
+ if (Objects.equals(isJobTicket.getTicketStatus(), PROCESSING.status)) {
|
|
|
+ jobUser.setJobStatus(JobStatusEnum.READY_TO_UNLOCK.status);
|
|
|
+ } else if (Objects.equals(isJobTicket.getTicketStatus(), READY_TO_LOCK.status)) {
|
|
|
+ jobUser.setJobStatus(JobStatusEnum.READY_TO_LOCK.status);
|
|
|
+ checkJobStatus(isJobTicket, jobUserList);
|
|
|
+ } else if (Objects.equals(isJobTicket.getTicketStatus(), NOT_STARTED.status)
|
|
|
+ || Objects.equals(isJobTicket.getTicketStatus(), READY_TO_LOCK.status)) {
|
|
|
+ // 等上锁人上锁
|
|
|
+ throw exception(JOB_TICKET_USER_WAIT_TO_LOCK);
|
|
|
+ } else {
|
|
|
+ // 作业票本人Job部分已完成
|
|
|
+ throw exception(JOB_TICKET_USER_JOB_IS_DONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关联人作业状态更新工作票状态
|
|
|
+ */
|
|
|
+ private Boolean checkJobStatus(IsJobTicket isJobTicket, List<IsJobTicketUser> jobUserList) {
|
|
|
+ List<IsJobTicketUser> coLockerList = jobUserList.stream()
|
|
|
+ .filter(jobUser -> Objects.equals(jobUser.getUserRole(), JTCOLOCKER.key)).collect(Collectors.toList());
|
|
|
+ boolean isCoLockerDone = coLockerList.stream().allMatch(jobUser -> Objects.equals(jobUser.getJobStatus(), JobStatusEnum.UNLOCKED.status));
|
|
|
+ if (isCoLockerDone) {
|
|
|
+ isJobTicket.setTicketStatus(TicketStatusEnum.READY_TO_UNLOCK.status);
|
|
|
+ }
|
|
|
+ return isCoLockerDone;
|
|
|
+ }
|
|
|
}
|