This commit is contained in:
2023-12-26 16:56:15 +08:00
parent c8735c6fa7
commit c1104b6443
5 changed files with 73 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ package com.cnbm.packing.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnbm.admin.utils.BaseSupportUtils;
import com.cnbm.common.exception.RenException;
import com.cnbm.common.page.PageData;
import com.cnbm.common.service.impl.CrudServiceImpl;
@@ -65,11 +66,48 @@ public class WorkingTimeServiceBizImpl extends CrudServiceImpl<WorkingTimeMapper
@Override
@Transactional(rollbackFor = Exception.class)
public void save(WorkingTimeDTO dto) {
//验证时间段不重合
timeOverlap(dto);
WorkingTime entity = ConvertUtils.sourceToTarget(dto, WorkingTime.class);
BaseSupportUtils.setCommonField(entity);
insert(entity);
}
public void timeOverlap(WorkingTimeDTO newTime){
List<WorkingTimeDTO> dtoList = list();
LocalTime newBeginTime = newTime.getBeginTime().toLocalTime();
LocalTime newEndTime = newTime.getEndTime().toLocalTime();
//不跨天
if(newBeginTime.isBefore(newEndTime)) {
for(WorkingTimeDTO oldTime: dtoList) {
LocalTime beginTime = oldTime.getBeginTime().toLocalTime();
LocalTime endTime = oldTime.getEndTime().toLocalTime();
//不重叠算法A.end< B.start || A.start > B.end
if(! (newEndTime.isBefore(beginTime)|| newBeginTime.isAfter(endTime))){
throw new RenException("班次时间重合");
}
}
}
//跨天
else{
//是否存在跨天班次
long count = dtoList.stream().filter(e->e.getBeginTime().toLocalTime().isAfter(e.getEndTime().toLocalTime())).count();
if(count>0){
throw new RenException("班次时间重合");
}
else{
for(WorkingTimeDTO oldTime: dtoList) {
LocalTime beginTime = oldTime.getBeginTime().toLocalTime();
LocalTime endTime = oldTime.getEndTime().toLocalTime();
//不重叠算法A.end< B.start || A.start > B.end
if(! (newEndTime.isBefore(beginTime)|| newBeginTime.isAfter(endTime))){
throw new RenException("班次时间重合");
}
}
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(WorkingTimeDTO dto) {
@@ -94,7 +132,6 @@ public class WorkingTimeServiceBizImpl extends CrudServiceImpl<WorkingTimeMapper
@Override
public String getOrderName(LocalDateTime time) {
LocalTime localTime = time.toLocalTime();
List<WorkingTimeDTO> resultList = new ArrayList<>();
List<WorkingTimeDTO> listAll = mapper.list();