From b506a0a10cdf3ac34cfdae2b82da4dae49b41567 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 20 一月 2026 11:10:33 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/estate_expert
---
admin-server/src/main/java/com/estate/expert/admin/service/impl/OnDutyServiceImpl.java | 139 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 139 insertions(+), 0 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 1b6a229..7c4e588 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
@@ -5,12 +5,28 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
+import com.estate.expert.admin.domain.common.request.AddOnDutyRequest;
+import com.estate.expert.admin.domain.common.request.EditOnDutyRequest;
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.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.OnDutyService;
+import com.estate.expert.admin.service.PositionService;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.Date;
import java.util.List;
+import java.util.Objects;
/**
* <p>
@@ -22,6 +38,12 @@
*/
@Service
public class OnDutyServiceImpl extends ServiceImpl<OnDutyMapper, OnDuty> implements OnDutyService {
+
+ @Resource
+ private ProjectRepository projectRepository;
+
+ @Resource
+ private PositionService positionService;
@Override
public List<OnDutyVo> pageList(Page<OnDutyVo> page, OnDutyRequest request) {
@@ -39,4 +61,121 @@
public OnDutyVo detail(Integer id) {
return this.baseMapper.detail(id);
}
+
+ @Override
+ @Transactional
+ public OnDuty add(User creator, AddOnDutyRequest request) {
+ // 1. 查询项目信息,获取 clientId
+ Project project = projectRepository.findById(request.getProjectId())
+ .orElseThrow(() -> new RuntimeException("项目不存在"));
+
+ if (project.getClient() == null) {
+ throw new RuntimeException("项目未关联委托方");
+ }
+ Integer clientId = project.getClient().getId();
+
+ // 2. 查询岗位信息,获取 positionName(MyBatis Plus 方式)
+ Position position = positionService.getById(request.getPositionId());
+ if (position == null) {
+ throw new RuntimeException("岗位不存在");
+ }
+ String positionName = position.getName();
+
+ // 3. 处理图片列表(逗号分隔)
+ String imgStr = null;
+ if (!CollectionUtils.isEmpty(request.getImages())) {
+ imgStr = String.join(",", request.getImages());
+ }
+
+ // 4. 构建 OnDuty 实体
+ OnDuty onDuty = new OnDuty();
+ onDuty.setPlanId(request.getPlanId());
+ onDuty.setProjectId(request.getProjectId());
+ onDuty.setClientId(clientId);
+ onDuty.setContent("人员在岗"); // 固定值
+ onDuty.setPositionId(request.getPositionId());
+ onDuty.setPositionName(positionName);
+ onDuty.setRemark(request.getRemark());
+ onDuty.setImg(imgStr);
+ onDuty.setState(request.getState());
+
+ // 5. 设置创建者
+ onDuty.setCreatorId(creator.getId());
+
+ // 6. 设置时间字段
+ // time: 当前日期(00:00:00)
+ LocalDate today = LocalDate.now();
+ Date timeDate = Date.from(today.atStartOfDay(ZoneId.systemDefault()).toInstant());
+ onDuty.setTime(timeDate);
+
+ // createTime: 当前时间戳
+ onDuty.setCreateTime(new Date());
+
+ // 6. 保存到数据库
+ this.save(onDuty);
+
+ return onDuty;
+ }
+
+ /**
+ * 分页查询在岗情况列表(JPA 实现)
+ * 用于新的列表查询接口,支持"全部/我创建的"筛选
+ */
+ @Override
+ public PageRespMp<OnDuty> listOnDutyRecords(Integer planId, Integer creatorId, PageReq pageReq) {
+ Page<OnDuty> page = lambdaQuery().eq(OnDuty::getPlanId, planId).eq(Objects.nonNull(creatorId), OnDuty::getCreatorId, creatorId)
+ .page(new Page<>(pageReq.getPage(), pageReq.getSize()));
+ //转换为 PageRespMp
+ return PageRespMp.of(page);
+ }
+
+ /**
+ * 编辑在岗情况记录
+ */
+ @Override
+ @Transactional
+ public OnDuty edit(EditOnDutyRequest request) {
+ // 1. 查询现有记录
+ OnDuty onDuty = this.getById(request.getId());
+ if (onDuty == null) {
+ throw new RuntimeException("在岗记录不存在");
+ }
+
+ // 2. 如果岗位ID发生变化,需要更新岗位名称(MyBatis Plus 方式)
+ if (!onDuty.getPositionId().equals(request.getPositionId())) {
+ Position position = positionService.getById(request.getPositionId());
+ if (position == null) {
+ throw new RuntimeException("岗位不存在");
+ }
+ onDuty.setPositionName(position.getName());
+ }
+
+ // 3. 更新可编辑字段
+ onDuty.setPositionId(request.getPositionId());
+ onDuty.setState(request.getState());
+ onDuty.setRemark(request.getRemark());
+
+ // 4. 处理图片列表(逗号分隔)
+ String imgStr = null;
+ if (!CollectionUtils.isEmpty(request.getImages())) {
+ imgStr = String.join(",", request.getImages());
+ }
+ onDuty.setImg(imgStr);
+
+ // 5. 保存更新(MyBatis-Plus 的 updateById)
+ this.updateById(onDuty);
+
+ return onDuty;
+ }
+
+ /**
+ * 批量删除在岗情况记录
+ */
+ @Override
+ @Transactional
+ public void deleteByIds(List<Integer> ids) {
+ // 使用 MyBatis-Plus 的批量删除方法(物理删除)
+ this.removeByIds(ids);
+ }
}
+
--
Gitblit v1.7.1