feat(wms/attendance): 新增排班批量修改功能
- 新增BatchUpdateScheduleBo类,用于接收批量修改排班的请求参数 - 在IWmsAttendanceScheduleService接口中定义batchUpdateSchedule方法 - 在WmsAttendanceScheduleController中新增批量修改排班的API接口 - 在WmsAttendanceScheduleServiceImpl中实现批量修改排班逻辑,支持更新已有记录和插入新记录
This commit is contained in:
@@ -20,6 +20,7 @@ import com.klp.common.utils.poi.ExcelUtil;
|
||||
import com.klp.domain.vo.WmsAttendanceScheduleVo;
|
||||
import com.klp.domain.bo.WmsAttendanceScheduleBo;
|
||||
import com.klp.domain.bo.GenerateScheduleBo;
|
||||
import com.klp.domain.bo.BatchUpdateScheduleBo;
|
||||
import com.klp.service.IWmsAttendanceScheduleService;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
|
||||
@@ -107,4 +108,15 @@ public class WmsAttendanceScheduleController extends BaseController {
|
||||
iWmsAttendanceScheduleService.generateSchedule(boList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改指定日期多个员工的班次
|
||||
*/
|
||||
@Log(title = "排班批量修改", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping("/batchUpdate")
|
||||
public R<Void> batchUpdateSchedule(@Validated @RequestBody BatchUpdateScheduleBo bo) {
|
||||
iWmsAttendanceScheduleService.batchUpdateSchedule(bo);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.klp.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BatchUpdateScheduleBo {
|
||||
|
||||
@NotEmpty(message = "员工ID列表不能为空")
|
||||
private List<Long> userIds;
|
||||
|
||||
@NotNull(message = "日期不能为空")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private Date workDate;
|
||||
|
||||
@NotNull(message = "班次ID不能为空")
|
||||
private Long shiftId;
|
||||
|
||||
private String shiftName;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.klp.domain.WmsAttendanceSchedule;
|
||||
import com.klp.domain.vo.WmsAttendanceScheduleVo;
|
||||
import com.klp.domain.bo.WmsAttendanceScheduleBo;
|
||||
import com.klp.domain.bo.GenerateScheduleBo;
|
||||
import com.klp.domain.bo.BatchUpdateScheduleBo;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
|
||||
@@ -52,4 +53,9 @@ public interface IWmsAttendanceScheduleService {
|
||||
* 生成排班
|
||||
*/
|
||||
void generateSchedule(List<GenerateScheduleBo> boList);
|
||||
|
||||
/**
|
||||
* 批量修改指定日期多个员工的班次
|
||||
*/
|
||||
void batchUpdateSchedule(BatchUpdateScheduleBo bo);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.klp.domain.bo.WmsAttendanceScheduleBo;
|
||||
import com.klp.domain.bo.GenerateScheduleBo;
|
||||
import com.klp.domain.bo.BatchUpdateScheduleBo;
|
||||
import com.klp.domain.vo.WmsAttendanceScheduleVo;
|
||||
import com.klp.domain.WmsAttendanceSchedule;
|
||||
import com.klp.domain.WmsAttendanceShiftRule;
|
||||
@@ -149,6 +150,48 @@ public class WmsAttendanceScheduleServiceImpl implements IWmsAttendanceScheduleS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改指定日期多个员工的班次
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchUpdateSchedule(BatchUpdateScheduleBo bo) {
|
||||
Date workDate = bo.getWorkDate();
|
||||
Long shiftId = bo.getShiftId();
|
||||
String shiftName = bo.getShiftName();
|
||||
List<Long> userIds = bo.getUserIds();
|
||||
|
||||
baseMapper.update(null, Wrappers.<WmsAttendanceSchedule>lambdaUpdate()
|
||||
.in(WmsAttendanceSchedule::getUserId, userIds)
|
||||
.eq(WmsAttendanceSchedule::getWorkDate, workDate)
|
||||
.set(WmsAttendanceSchedule::getShiftId, shiftId)
|
||||
.set(WmsAttendanceSchedule::getShiftName, shiftName));
|
||||
|
||||
Set<Long> existingUserIds = baseMapper.selectList(Wrappers.<WmsAttendanceSchedule>lambdaQuery()
|
||||
.in(WmsAttendanceSchedule::getUserId, userIds)
|
||||
.eq(WmsAttendanceSchedule::getWorkDate, workDate)
|
||||
.select(WmsAttendanceSchedule::getUserId))
|
||||
.stream()
|
||||
.map(WmsAttendanceSchedule::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<WmsAttendanceSchedule> insertList = userIds.stream()
|
||||
.filter(uid -> !existingUserIds.contains(uid))
|
||||
.map(uid -> {
|
||||
WmsAttendanceSchedule s = new WmsAttendanceSchedule();
|
||||
s.setUserId(uid);
|
||||
s.setWorkDate(workDate);
|
||||
s.setShiftId(shiftId);
|
||||
s.setShiftName(shiftName);
|
||||
return s;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!insertList.isEmpty()) {
|
||||
baseMapper.insertBatch(insertList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成正常排班
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user