| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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; |
| | | 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.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 org.springframework.beans.factory.annotation.Autowired; |
| | | 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> |
| | |
| | | @Service |
| | | public class OnDutyServiceImpl extends ServiceImpl<OnDutyMapper, OnDuty> implements OnDutyService { |
| | | |
| | | @Resource |
| | | private ProjectRepository projectRepository; |
| | | |
| | | @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; |
| | |
| | | public OnDutyVo detail(Integer id) { |
| | | return this.baseMapper.detail(id); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public OnDuty add(User creator, AddOnDutyRequest request) { |
| | | //1.校验任务id |
| | | CheckTask checkTask = checkTaskService.get(request.getCheckTaskIdId()); |
| | | if (Objects.isNull(checkTask)) { |
| | | throw new RuntimeException("检查任务不存在"); |
| | | } |
| | | Client client = clientService.get(checkTask.getProject().getClient().getId()); |
| | | if (Objects.isNull(client)) { |
| | | throw new RuntimeException("委托方不存在"); |
| | | } |
| | | // 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.setCheckTaskIdId(request.getCheckTaskIdId()); |
| | | onDuty.setContent("人员在岗"); // 固定值 |
| | | onDuty.setPositionId(request.getPositionId()); |
| | | onDuty.setPositionName(positionName); |
| | | 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()); |
| | | |
| | | // 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 checkTaskId, Integer creatorId, PageReq pageReq) { |
| | | Page<OnDuty> page = lambdaQuery().eq(OnDuty::getCheckTaskIdId, checkTaskId).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); |
| | | } |
| | | |
| | | @Override |
| | | public List<OnDutyVo> exportList(OnDutyRequest query) { |
| | | String sTime =null; |
| | | String eTime =null; |
| | | if(query.getTime()!=null && !query.getTime().isEmpty()){ |
| | | sTime = query.getTime().split(" - ")[0] + " 00:00:00"; |
| | | eTime = query.getTime().split(" - ")[1] + " 23:59:59"; |
| | | } |
| | | List<OnDutyVo> list = this.baseMapper.exportList( query,sTime,eTime); |
| | | return list; |
| | | } |
| | | } |
| | | |