| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.estate.expert.admin.domain.business.check.Check; |
| | | import com.estate.expert.admin.domain.business.check.CheckVo; |
| | | import com.estate.expert.admin.domain.business.onduty.OnDutyVo; |
| | | import com.estate.expert.admin.domain.common.request.AddCheckInfoRequest; |
| | | import com.estate.expert.admin.domain.common.request.EditCheckInfoRequest; |
| | | 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.repository.CheckMapper; |
| | | import com.estate.expert.admin.domain.user.User; |
| | | import com.estate.expert.admin.service.CheckService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public CheckVo detail(Integer id) { |
| | | return this.baseMapper.detail(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageRespMp<Check> listCheckInfoRecords(Integer planId, Integer creatorId, PageReq pageReq) { |
| | | Page<Check> page = lambdaQuery().eq(Check::getPlanId, planId).eq(Objects.nonNull(creatorId), Check::getCreatorId, creatorId) |
| | | .page(new Page<>(pageReq.getPage(), pageReq.getSize())); |
| | | // 将 Spring Data Page 转换为自定义 PageResp |
| | | return PageRespMp.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 添加检查信息(MyBatis Plus 方式) |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void addCheckInfo(User creator, AddCheckInfoRequest request) { |
| | | // 1. 创建 Check 实体对象(MyBatis Plus 实体) |
| | | Check check = new Check(); |
| | | |
| | | // 2. 设置基本字段 |
| | | check.setTitle(request.getTitle()); |
| | | check.setSafetySlip(request.getSafetySlip()); |
| | | check.setCheckUserImg(request.getCheckUserImg()); |
| | | check.setIntegrityNotification(request.getIntegrityNotification()); |
| | | |
| | | // 3. 设置关联字段 |
| | | check.setPlanId(request.getPlanId()); |
| | | check.setProjectId(request.getProjectId()); |
| | | check.setClientId(request.getClientId()); |
| | | |
| | | // 4. 设置创建者ID(MyBatis Plus 使用 creatorId 字段) |
| | | check.setCreatorId(creator.getId()); |
| | | |
| | | // 5. 设置时间字段 |
| | | check.setTime(new Date()); |
| | | |
| | | // createTime: 当前时间戳 |
| | | check.setCreateTime(new Date()); |
| | | |
| | | // 6. 保存到数据库(MyBatis Plus 方式) |
| | | save(check); |
| | | } |
| | | |
| | | /** |
| | | * 编辑检查信息(MyBatis Plus 方式) |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void editCheckInfo(EditCheckInfoRequest request) { |
| | | // 1. 根据 id 查询现有的 Check 实体 |
| | | Check check = getById(request.getId()); |
| | | if (check == null) { |
| | | throw new RuntimeException("检查信息不存在"); |
| | | } |
| | | |
| | | // 2. 更新字段 |
| | | check.setTitle(request.getTitle()); |
| | | check.setSafetySlip(request.getSafetySlip()); |
| | | check.setCheckUserImg(request.getCheckUserImg()); |
| | | check.setIntegrityNotification(request.getIntegrityNotification()); |
| | | |
| | | // 3. 保存更新(MyBatis Plus 方式) |
| | | updateById(check); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除检查信息(MyBatis Plus 方式) |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void deleteCheckInfoByIds(List<Integer> ids) { |
| | | // 使用 MyBatis Plus 的批量删除方法(逻辑删除,因为 Check 实体有 @TableLogic 注解) |
| | | removeByIds(ids); |
| | | } |
| | | } |