|
@@ -3,9 +3,12 @@ package com.ruoyi.zhdd.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpStatus;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
|
|
import com.ruoyi.common.core.page.PagePlus;
|
|
@@ -14,14 +17,21 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.UserUtil;
|
|
|
+import com.ruoyi.system.service.ISysConfigService;
|
|
|
import com.ruoyi.zhdd.domain.DutyReport;
|
|
|
+import com.ruoyi.zhdd.domain.DutyReportRecord;
|
|
|
import com.ruoyi.zhdd.domain.bo.DutyReportBo;
|
|
|
+import com.ruoyi.zhdd.domain.vo.DutyReportRecordVo;
|
|
|
import com.ruoyi.zhdd.domain.vo.DutyReportVo;
|
|
|
import com.ruoyi.zhdd.mapper.DutyReportMapper;
|
|
|
+import com.ruoyi.zhdd.service.IDutyReportRecordService;
|
|
|
import com.ruoyi.zhdd.service.IDutyReportService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -36,6 +46,11 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class DutyReportServiceImpl extends ServicePlusImpl<DutyReportMapper, DutyReport, DutyReportVo> implements IDutyReportService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService sysConfigService;
|
|
|
+ @Autowired
|
|
|
+ private IDutyReportRecordService dutyReportRecordService;
|
|
|
+
|
|
|
@Override
|
|
|
public DutyReportVo queryById(String id) {
|
|
|
return getVoById(id);
|
|
@@ -64,21 +79,29 @@ public class DutyReportServiceImpl extends ServicePlusImpl<DutyReportMapper, Dut
|
|
|
private LambdaQueryWrapper<DutyReport> buildQueryWrapper(DutyReportBo bo) {
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<DutyReport> lqw = Wrappers.lambdaQuery();
|
|
|
- lqw.like(StringUtils.isNotBlank(bo.getCreateBy()), DutyReport::getCreateBy, bo.getCreateBy());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getReportContent()), DutyReport::getReportContent, bo.getReportContent());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), DutyReport::getCreateBy, bo.getCreateBy());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getReportContent()), DutyReport::getReportContent, bo.getReportContent());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getCreateByName()), DutyReport::getCreateByName, bo.getCreateByName());
|
|
|
lqw.eq(bo.getStatus() != null, DutyReport::getStatus, bo.getStatus());
|
|
|
if (params.get("beginTime") != null && params.get("endTime") != null) {
|
|
|
- lqw.between(DutyReport::getDutyDate, Timestamp.valueOf(Convert.toStr(params.get("beginTime")) + " 00:00:00"), Timestamp.valueOf(Convert.toStr(params.get("endTime")) + " 23:59:59"));
|
|
|
+ lqw.between(DutyReport::getCreateTime, Timestamp.valueOf(Convert.toStr(params.get("beginTime")) + " 00:00:00"), Timestamp.valueOf(Convert.toStr(params.get("endTime")) + " 23:59:59"));
|
|
|
}
|
|
|
- lqw.orderByDesc(DutyReport::getUpdateTime);
|
|
|
+ lqw.orderByDesc(DutyReport::getCreateTime);
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean insertByBo(DutyReportBo bo) {
|
|
|
+ // 查询是否存在未交班的报告
|
|
|
+ LoginUser cacheLoginUser = UserUtil.getCacheLoginUser();
|
|
|
+ DutyReportVo voOne = this.getVoOne(Wrappers.<DutyReport>lambdaQuery()
|
|
|
+ .eq(DutyReport::getCreateBy, cacheLoginUser.getUsername())
|
|
|
+ .eq(DutyReport::getStatus, 1));
|
|
|
+ if (voOne != null) {
|
|
|
+ throw new ServiceException("存在未交班的报告,请先交班后再提交新的报告!");
|
|
|
+ }
|
|
|
DutyReport add = BeanUtil.toBean(bo, DutyReport.class);
|
|
|
- validEntityBeforeSave(add);
|
|
|
- add.setDutyDate(new Date());
|
|
|
+ add.setStatus(1);
|
|
|
return save(add);
|
|
|
}
|
|
|
|
|
@@ -89,37 +112,100 @@ public class DutyReportServiceImpl extends ServicePlusImpl<DutyReportMapper, Dut
|
|
|
// 只能修改自己的
|
|
|
LoginUser cacheLoginUser = UserUtil.getCacheLoginUser();
|
|
|
if (!dutyReportVo.getCreateBy().equals(cacheLoginUser.getUsername())) {
|
|
|
- throw new ServiceException("只能编辑自己的报告!");
|
|
|
+ throw new ServiceException("只能编辑自己的值班报告!");
|
|
|
}
|
|
|
- /*if (dutyReportVo.getStatus() == 2) {
|
|
|
- throw new ServiceException("报告已提交不能修改");
|
|
|
- }*/
|
|
|
- long l = DateUtil.betweenDay(dutyReportVo.getCreateTime(), DateUtil.date(), false);
|
|
|
+ if (dutyReportVo.getStatus() != 1) {
|
|
|
+ throw new ServiceException("当前报告不能修改!");
|
|
|
+ }
|
|
|
+ /*long l = DateUtil.betweenDay(dutyReportVo.getCreateTime(), DateUtil.date(), false);
|
|
|
if (l > 7) {
|
|
|
throw new ServiceException("只能对7天内的报告做修改!");
|
|
|
- }
|
|
|
+ }*/
|
|
|
DutyReport update = BeanUtil.toBean(bo, DutyReport.class);
|
|
|
- validEntityBeforeSave(update);
|
|
|
return updateById(update);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
|
|
|
+ if (isValid) {
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 保存前的数据校验
|
|
|
+ * 交班
|
|
|
*
|
|
|
- * @param entity 实体类数据
|
|
|
+ * @param bo
|
|
|
+ * @return
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(DutyReport entity) {
|
|
|
- //TODO 做一些数据校验,如唯一约束
|
|
|
- if (entity.getStatus() != 1 && entity.getStatus() != 2) {
|
|
|
- throw new ServiceException("状态值非法-" + entity.getStatus());
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean passwork(DutyReportBo bo) {
|
|
|
+ if (StrUtil.hasBlank(bo.getId(), bo.getReportContent())) {
|
|
|
+ throw new ServiceException("存在空值,不能交班!");
|
|
|
}
|
|
|
+ if ("[]".equals(bo.getReceiveUser())) {
|
|
|
+ throw new ServiceException("接班人员不能为空!");
|
|
|
+ }
|
|
|
+ DutyReportVo dutyReportVo = this.queryById(bo.getId());
|
|
|
+ if (dutyReportVo == null || dutyReportVo.getStatus() != 1) {
|
|
|
+ throw new ServiceException("当前已交班,不能再次交班!");
|
|
|
+ }
|
|
|
+ String days = sysConfigService.selectConfigByKey("report.deadline");
|
|
|
+ Date date = DateUtil.date();
|
|
|
+ Date deadline = DateUtil.offsetDay(date, Convert.toInt(days));
|
|
|
+ // 更新报告数据
|
|
|
+ boolean update = this.update(Wrappers.<DutyReport>lambdaUpdate()
|
|
|
+ .eq(DutyReport::getId, bo.getId())
|
|
|
+ .set(DutyReport::getReportContent, bo.getReportContent())
|
|
|
+ .set(DutyReport::getStatus, 2)
|
|
|
+ .set(DutyReport::getReceiveUser, bo.getReceiveUser())
|
|
|
+ .set(DutyReport::getPassDateTime, date)
|
|
|
+ .set(DutyReport::getDeadline, deadline));
|
|
|
+ // 新增交班记录
|
|
|
+ List<SysUser> sysUsers = JSONUtil.toList(bo.getReceiveUser(), SysUser.class);
|
|
|
+ List<DutyReportRecord> saveList = new ArrayList<>();
|
|
|
+ for (SysUser sysUser : sysUsers) {
|
|
|
+ DutyReportRecord dutyReportRecord = new DutyReportRecord();
|
|
|
+ dutyReportRecord.setReportId(bo.getId());
|
|
|
+ dutyReportRecord.setReportContent(bo.getReportContent());
|
|
|
+ dutyReportRecord.setStatus(2);
|
|
|
+ dutyReportRecord.setCreateBy(bo.getCreateBy());
|
|
|
+ dutyReportRecord.setCreateByName(dutyReportVo.getCreateByName());
|
|
|
+ dutyReportRecord.setReceiveUser(sysUser.getUserName());
|
|
|
+ dutyReportRecord.setReceiveUserName(sysUser.getNickName());
|
|
|
+ dutyReportRecord.setDeadline(deadline);
|
|
|
+ dutyReportRecord.setPassDateTime(date);
|
|
|
+ saveList.add(dutyReportRecord);
|
|
|
+ }
|
|
|
+ dutyReportRecordService.saveAll(saveList);
|
|
|
+ return update;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 接班
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
|
|
|
- if (isValid) {
|
|
|
- //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ public boolean receivework(String id) {
|
|
|
+ DutyReportRecordVo dutyReportRecordVo = dutyReportRecordService.queryById(id);
|
|
|
+ if (dutyReportRecordVo == null) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- return removeByIds(ids);
|
|
|
+ boolean update = dutyReportRecordService.update(Wrappers.<DutyReportRecord>lambdaUpdate()
|
|
|
+ .eq(DutyReportRecord::getId, id)
|
|
|
+ .set(DutyReportRecord::getStatus, 3)
|
|
|
+ .set(DutyReportRecord::getReceiveDateTime, new Date()));
|
|
|
+ if (update) {
|
|
|
+ // 更新报告记录中状态
|
|
|
+ this.update(Wrappers.<DutyReport>lambdaUpdate()
|
|
|
+ .eq(DutyReport::getId, dutyReportRecordVo.getReportId())
|
|
|
+ .eq(DutyReport::getStatus, 2)
|
|
|
+ .set(DutyReport::getStatus, 3));
|
|
|
+ }
|
|
|
+ return update;
|
|
|
}
|
|
|
}
|