From 25999c575dd42b4715e49d3fe57e73c2c3204ccb Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期日, 20 九月 2026 11:45:05 +0800
Subject: [PATCH] update

---
 admin-server/src/main/java/com/estate/expert/admin/service/impl/OnDutyServiceImpl.java |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/admin-server/src/main/java/com/estate/expert/admin/service/impl/OnDutyServiceImpl.java b/admin-server/src/main/java/com/estate/expert/admin/service/impl/OnDutyServiceImpl.java
index 6ba51d3..67b1a3c 100644
--- a/admin-server/src/main/java/com/estate/expert/admin/service/impl/OnDutyServiceImpl.java
+++ b/admin-server/src/main/java/com/estate/expert/admin/service/impl/OnDutyServiceImpl.java
@@ -3,6 +3,8 @@
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.estate.expert.admin.domain.business.check.Check;
+import com.estate.expert.admin.domain.business.client.Client;
 import com.estate.expert.admin.domain.business.onduty.OnDuty;
 import com.estate.expert.admin.domain.business.onduty.OnDutyVo;
 import com.estate.expert.admin.domain.business.position.Position;
@@ -11,12 +13,17 @@
 import com.estate.expert.admin.domain.common.request.OnDutyRequest;
 import com.estate.expert.admin.domain.common.request.PageReq;
 import com.estate.expert.admin.domain.common.response.PageRespMp;
+import com.estate.expert.admin.domain.exam.task.check.CheckTask;
 import com.estate.expert.admin.domain.project.Project;
 import com.estate.expert.admin.domain.project.ProjectRepository;
 import com.estate.expert.admin.domain.repository.OnDutyMapper;
 import com.estate.expert.admin.domain.user.User;
+import com.estate.expert.admin.service.CheckTaskService;
+import com.estate.expert.admin.service.ClientService;
 import com.estate.expert.admin.service.OnDutyService;
 import com.estate.expert.admin.service.PositionService;
+import com.estate.expert.common.exception.BizException;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -45,6 +52,11 @@
     @Resource
     private PositionService positionService;
 
+    @Autowired
+    private CheckTaskService checkTaskService;
+
+    @Autowired
+    private ClientService clientService;
     @Override
     public List<OnDutyVo> pageList(Page<OnDutyVo> page, OnDutyRequest request) {
         String sTime =null;
@@ -65,12 +77,26 @@
     @Override
     @Transactional
     public OnDuty add(User creator, AddOnDutyRequest request) {
+        //1.校验任务id
+        CheckTask checkTask = checkTaskService.get(request.getCheckTaskIdId());
+        if (Objects.isNull(checkTask)) {
+            throw new BizException("检查任务不存在");
+        }
+        Client client = clientService.get(checkTask.getProject().getClient().getId());
+        if (Objects.isNull(client)) {
+            throw new BizException("委托方不存在");
+        }
         // 2. 查询岗位信息,获取 positionName(MyBatis Plus 方式)
         Position position = positionService.getById(request.getPositionId());
         if (position == null) {
-            throw new RuntimeException("岗位不存在");
+            throw new BizException("岗位不存在");
         }
         String positionName = position.getName();
+        //校验该岗位是否已添加
+        Long count = lambdaQuery().eq(OnDuty::getCheckTaskIdId, request.getCheckTaskIdId()).eq(OnDuty::getPositionId, request.getPositionId()).count();
+        if (count > 0) {
+            throw new BizException("该岗位已上传");
+        }
 
         // 3. 处理图片列表(逗号分隔)
         String imgStr = null;
@@ -87,7 +113,9 @@
         onDuty.setRemark(request.getRemark());
         onDuty.setImg(imgStr);
         onDuty.setState(request.getState());
-
+        onDuty.setPlanId(checkTask.getPlan().getId());
+        onDuty.setProjectId(checkTask.getProject().getId());
+        onDuty.setClientId(client.getId());
         // 5. 设置创建者
         onDuty.setCreatorId(creator.getId());
 
@@ -113,6 +141,7 @@
     @Override
     public PageRespMp<OnDuty> listOnDutyRecords(Integer checkTaskId, Integer creatorId, PageReq pageReq) {
         Page<OnDuty> page = lambdaQuery().eq(OnDuty::getCheckTaskIdId, checkTaskId).eq(Objects.nonNull(creatorId), OnDuty::getCreatorId, creatorId)
+                .orderByDesc(OnDuty::getCreateTime)
                 .page(new Page<>(pageReq.getPage(), pageReq.getSize()));
         //转换为 PageRespMp
         return PageRespMp.of(page);
@@ -127,14 +156,14 @@
         // 1. 查询现有记录
         OnDuty onDuty = this.getById(request.getId());
         if (onDuty == null) {
-            throw new RuntimeException("在岗记录不存在");
+            throw new BizException("在岗记录不存在");
         }
 
         // 2. 如果岗位ID发生变化,需要更新岗位名称(MyBatis Plus 方式)
         if (!onDuty.getPositionId().equals(request.getPositionId())) {
             Position position = positionService.getById(request.getPositionId());
             if (position == null) {
-                throw new RuntimeException("岗位不存在");
+                throw new BizException("岗位不存在");
             }
             onDuty.setPositionName(position.getName());
         }

--
Gitblit v1.7.1