|
@@ -1,6 +1,5 @@
|
|
|
package com.ruoyi.zhdd.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -15,11 +14,14 @@ import com.ruoyi.common.utils.PageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.zhdd.domain.DutyEmp;
|
|
|
import com.ruoyi.zhdd.domain.bo.DutyEmpBo;
|
|
|
+import com.ruoyi.zhdd.domain.bo.DutyEmpSaveBo;
|
|
|
import com.ruoyi.zhdd.domain.vo.DutyEmpVo;
|
|
|
import com.ruoyi.zhdd.mapper.DutyEmpMapper;
|
|
|
import com.ruoyi.zhdd.service.IDutyEmpService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -59,55 +61,38 @@ public class DutyEmpServiceImpl extends ServicePlusImpl<DutyEmpMapper, DutyEmp,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean insertByBo(DutyEmpBo bo) {
|
|
|
- DutyEmp add = BeanUtil.toBean(bo, DutyEmp.class);
|
|
|
+ @Transactional
|
|
|
+ public Boolean insertByBo(DutyEmpSaveBo bo) {
|
|
|
// 校验是否存在重叠时间段
|
|
|
- // 先获取当前星期下所有的数据
|
|
|
- List<DutyEmpVo> dutyEmpVos = this.listVo(Wrappers.<DutyEmp>lambdaQuery().eq(DutyEmp::getPeriod, add.getPeriod()));
|
|
|
- for (DutyEmpVo dutyEmpVo : dutyEmpVos) {
|
|
|
- int startTime = DateUtil.timeToSecond(dutyEmpVo.getPeriodTime().split("~")[0]);
|
|
|
- int endTime = DateUtil.timeToSecond(dutyEmpVo.getPeriodTime().split("~")[1]);
|
|
|
- int requestStartTime = DateUtil.timeToSecond(bo.getPeriodTime().split("~")[0]);
|
|
|
- int requestendTime = DateUtil.timeToSecond(bo.getPeriodTime().split("~")[1]);
|
|
|
- if ((requestStartTime > startTime && requestStartTime < endTime) ||
|
|
|
- (requestendTime > startTime && requestendTime < endTime) ||
|
|
|
- (requestStartTime <= startTime && requestendTime >= endTime)) {
|
|
|
- throw new ServiceException(bo.getPeriodTime() + "存在重叠时间段,请检查!");
|
|
|
+ List<String> periods = bo.getDutyDetailList().stream().map(DutyEmpSaveBo.DutyDetail::getPeriodTime).collect(Collectors.toList());
|
|
|
+ for (int i = 0; i < periods.size(); i++) {
|
|
|
+ int startTime = DateUtil.timeToSecond(periods.get(i).split("~")[0]);
|
|
|
+ int endTime = DateUtil.timeToSecond(periods.get(i).split("~")[1]);
|
|
|
+ for (int j = i + 1; j < periods.size(); j++) {
|
|
|
+ // 循环比较
|
|
|
+ int compareStartTime = DateUtil.timeToSecond(periods.get(j).split("~")[0]);
|
|
|
+ int compareEndTime = DateUtil.timeToSecond(periods.get(j).split("~")[1]);
|
|
|
+ if ((startTime > compareStartTime && startTime < compareEndTime) ||
|
|
|
+ (endTime > compareStartTime && endTime < compareEndTime) ||
|
|
|
+ (startTime <= compareStartTime && endTime >= compareEndTime)) {
|
|
|
+ throw new ServiceException(periods.get(i) + "存在重叠时间段,请检查!");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- // 处理人名
|
|
|
- if (StrUtil.isNotBlank(bo.getEmpJson())) {
|
|
|
- List<SysUser> users = JSONUtil.toList(StrUtil.blankToDefault(bo.getEmpJson(), "[]"), SysUser.class);
|
|
|
+ List<DutyEmp> list = new ArrayList<>();
|
|
|
+ for (DutyEmpSaveBo.DutyDetail dutyDetail : bo.getDutyDetailList()) {
|
|
|
+ DutyEmp dutyEmp = new DutyEmp();
|
|
|
+ dutyEmp.setPeriod(bo.getPeriod());
|
|
|
+ dutyEmp.setPeriodTime(dutyDetail.getPeriodTime());
|
|
|
+ dutyEmp.setEmpJson(dutyDetail.getEmpJson());
|
|
|
+ List<SysUser> users = JSONUtil.toList(StrUtil.blankToDefault(dutyDetail.getEmpJson(), "[]"), SysUser.class);
|
|
|
String userNames = users.stream().map(SysUser::getNickName).collect(Collectors.joining(","));
|
|
|
- add.setEmpName(userNames);
|
|
|
+ dutyEmp.setEmpName(userNames);
|
|
|
+ list.add(dutyEmp);
|
|
|
}
|
|
|
- return save(add);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Boolean updateByBo(DutyEmpBo bo) {
|
|
|
- DutyEmp update = BeanUtil.toBean(bo, DutyEmp.class);
|
|
|
- List<DutyEmpVo> dutyEmpVos = this.listVo(Wrappers.<DutyEmp>lambdaQuery().eq(DutyEmp::getPeriod, update.getPeriod()));
|
|
|
- for (DutyEmpVo dutyEmpVo : dutyEmpVos) {
|
|
|
- if (dutyEmpVo.getId().equals(bo.getId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- int startTime = DateUtil.timeToSecond(dutyEmpVo.getPeriodTime().split("~")[0]);
|
|
|
- int endTime = DateUtil.timeToSecond(dutyEmpVo.getPeriodTime().split("~")[1]);
|
|
|
- int requestStartTime = DateUtil.timeToSecond(bo.getPeriodTime().split("~")[0]);
|
|
|
- int requestendTime = DateUtil.timeToSecond(bo.getPeriodTime().split("~")[1]);
|
|
|
- if ((requestStartTime > startTime && requestStartTime < endTime) ||
|
|
|
- (requestendTime > startTime && requestendTime < endTime) ||
|
|
|
- (requestStartTime <= startTime && requestendTime >= endTime)) {
|
|
|
- throw new ServiceException(bo.getPeriodTime() + "存在重叠时间段,请检查!");
|
|
|
- }
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(bo.getEmpJson())) {
|
|
|
- List<SysUser> users = JSONUtil.toList(StrUtil.blankToDefault(bo.getEmpJson(), "[]"), SysUser.class);
|
|
|
- String userNames = users.stream().map(SysUser::getNickName).collect(Collectors.joining(","));
|
|
|
- update.setEmpName(userNames);
|
|
|
- }
|
|
|
- return updateById(update);
|
|
|
+ // 先删除之前的星期数据
|
|
|
+ this.remove(Wrappers.<DutyEmp>lambdaQuery().eq(DutyEmp::getPeriod, bo.getPeriod()));
|
|
|
+ return saveBatch(list);
|
|
|
}
|
|
|
|
|
|
@Override
|