Commit b69f10e6 by zhangshaowu

排班信息

1 parent d3148508
......@@ -62,7 +62,7 @@ public class RosteringController {
@PostMapping(value = "gen")
public Result genRostering(@RequestParam("month") int month,
public Result genRostering(@RequestParam("date") Date date,
@RequestParam("shiftRuleModel") String shiftRuleModelStr,
@RequestParam("staffRuleModel") String staffRuleModelStr,
@RequestParam("dateRuleModel") String dateRuleModelStr) {
......@@ -70,7 +70,7 @@ public class RosteringController {
List<ShiftRuleModel> shiftRuleModels = JSONObject.parseArray(shiftRuleModelStr, ShiftRuleModel.class);
List<StaffRuleModel> staffRuleModels = JSONObject.parseArray(staffRuleModelStr, StaffRuleModel.class);
List<DateRuleModel> dateRuleModels = JSONObject.parseArray(dateRuleModelStr, DateRuleModel.class);
return ResultGenerator.genSuccessResult(rosteringService.gen(month, shiftRuleModels, staffRuleModels, dateRuleModels));
return ResultGenerator.genSuccessResult(rosteringService.gen(date, shiftRuleModels, staffRuleModels, dateRuleModels));
}
......
......@@ -8,6 +8,7 @@ import com.pipihelper.project.rostering.model.RosteringModel;
import com.pipihelper.project.rostering.model.ShiftRuleModel;
import org.apache.poi.ss.usermodel.Workbook;
import java.util.Date;
import java.util.List;
/**
......@@ -31,13 +32,13 @@ public interface RosteringService {
/**
* 生成班次
*
* @param month
* @param date
* @param shiftRuleModels 班次规则
* @param staffRuleModels 原因规则
* @param dateRuleModels 时间规则
* @return
*/
List<RosteringModel> gen(int month,
List<RosteringModel> gen(Date date,
List<ShiftRuleModel> shiftRuleModels,
List<StaffRuleModel> staffRuleModels,
List<DateRuleModel> dateRuleModels);
......
......@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -41,9 +42,6 @@ import java.util.stream.Collectors;
public class RosteringServiceImpl implements RosteringService {
@Autowired
private RosteringStaffDao rosteringStaffDao;
......@@ -58,7 +56,6 @@ public class RosteringServiceImpl implements RosteringService {
Map<String, List<RosteringExportModel>> dataMap = rosteringModels.stream().collect(Collectors.groupingBy(RosteringExportModel::getName));
List<ExcelExportEntity> colList = new ArrayList<>();
ExcelExportEntity departmentCol = new ExcelExportEntity();
departmentCol.setName("部门");
......@@ -141,52 +138,57 @@ public class RosteringServiceImpl implements RosteringService {
}
@Override
public List<RosteringModel> gen(int month,
public List<RosteringModel> gen(Date date,
List<ShiftRuleModel> shiftRuleModels,
List<StaffRuleModel> staffRuleModels,
List<DateRuleModel> dateRuleModels) {
int daysOfMonth = getDaysOfNextMonth(month);
int daysOfMonth = getDaysOfNextMonth(date);
Map<String, StaffRuleModel> staffRuleModelMap = staffRuleModels.stream().collect(Collectors.toMap(StaffRuleModel::getName, Function.identity()));
//记录用户当次排版已经排了多少次
Map<String, List<ShiftRuleModel>> staffMap = new HashMap<>();
for (int i = 0; i < daysOfMonth; i++) {
int currentDay = i + 1;
staffRuleModels.forEach(e -> {
List<ShiftRuleModel> currentShifts = Optional.ofNullable(staffMap.get(e.getName())).orElse(Lists.newArrayList());
int year = DateUtil.year(date);
int month = DateUtil.month(date);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, currentDay);
Date time = calendar.getTime();
//指定日期班次
StaffRuleModel.Threshold fixedShift = e.getFixedShift();
boolean isFixed = Optional.ofNullable(fixedShift).map(StaffRuleModel.Threshold::getDate).filter(fixedDate -> DateUtil.dayOfMonth(fixedDate) == currentDay).isPresent();
ShiftRuleModel shiftRuleModel = null;
if (isFixed) {
shiftRuleModel = shiftRuleModels.stream().filter(shift -> ObjectUtil.equal(shift.getName(), fixedShift.getShift())).findFirst().orElse(null);
}
DateRuleModel dateRuleModel = dateRuleModels.stream().filter(e -> DateUtil.isSameDay(e.getDate(), time)).findAny().orElse(null);
if (shiftRuleModel == null) {
shiftRuleModel = getByShiftRule(shiftRuleModels, currentShifts, e);
}
List<ShiftRuleModel> dateShifts = new ArrayList<>();
//判断是否已经达到了最大次数
StaffRuleModel.Threshold maxTimes = e.getMaxTimes();
if (maxTimes != null && maxTimes.getTimes() != null && StringUtils.isNotBlank(maxTimes.getShift())) {
String shift = maxTimes.getShift();
int count = (int) currentShifts.stream().filter(result -> ObjectUtil.equal(result.getName(), shift)).count();
count = ObjectUtil.equal(shiftRuleModel.getName(), shift) ? count + 1 : count;
if (count > maxTimes.getTimes()) {
shiftRuleModel = getRandom(shiftRuleModels.stream().filter(ignore -> ObjectUtil.notEqual(ignore.getName(), shift)).collect(Collectors.toList()));
}
}
staffRuleModels.forEach(e -> {
List<ShiftRuleModel> currentShifts = Optional.ofNullable(staffMap.get(e.getName())).orElse(Lists.newArrayList());
ShiftRuleModel shiftRuleModel = gen(e, shiftRuleModels, currentDay, currentShifts);
//添加到map中
currentShifts.add(shiftRuleModel);
staffMap.putIfAbsent(e.getName(), currentShifts);
dateShifts.add(shiftRuleModel);
});
//日期规则配置
if (dateRuleModel != null) {
Integer times = dateRuleModel.getTimes();
String shift = dateRuleModel.getShift();
int size = (int) dateShifts.stream().filter(e -> ObjectUtil.equal(e.getName(), shift)).count();
//判断是否满足每天指定班次的人数
if (size < times) {
}
}
}
List<RosteringModel> result = new ArrayList<>();
......@@ -217,23 +219,45 @@ public class RosteringServiceImpl implements RosteringService {
}
private ShiftRuleModel gen(StaffRuleModel staffRuleModel, List<ShiftRuleModel> shiftRuleModels, Integer currentDay, List<ShiftRuleModel> currentShifts) {
//指定日期班次
StaffRuleModel.Threshold fixedShift = staffRuleModel.getFixedShift();
boolean isFixed = Optional.ofNullable(fixedShift).map(StaffRuleModel.Threshold::getDate).filter(fixedDate -> DateUtil.dayOfMonth(fixedDate) == currentDay).isPresent();
ShiftRuleModel shiftRuleModel = null;
if (isFixed) {
shiftRuleModel = shiftRuleModels.stream().filter(shift -> ObjectUtil.equal(shift.getName(), fixedShift.getShift())).findFirst().orElse(null);
}
if (shiftRuleModel == null) {
shiftRuleModel = getByShiftRule(shiftRuleModels, currentShifts, staffRuleModel);
}
//判断是否已经达到了最大次数
StaffRuleModel.Threshold maxTimes = staffRuleModel.getMaxTimes();
if (maxTimes != null && maxTimes.getTimes() != null && StringUtils.isNotBlank(maxTimes.getShift())) {
String shift = maxTimes.getShift();
int count = (int) currentShifts.stream().filter(result -> ObjectUtil.equal(result.getName(), shift)).count();
count = ObjectUtil.equal(shiftRuleModel.getName(), shift) ? count + 1 : count;
if (count > maxTimes.getTimes()) {
shiftRuleModel = getRandom(shiftRuleModels.stream().filter(ignore -> ObjectUtil.notEqual(ignore.getName(), shift)).collect(Collectors.toList()));
}
}
return shiftRuleModel;
}
/**
* 获取某个月的天数
*
* @return
*/
private int getDaysOfNextMonth(int month) {
private int getDaysOfNextMonth(Date date) {
Calendar calendar = Calendar.getInstance();
//获得当前日期往后推1个月 amount 为设置的月份值 +为往后推 +号可以省略 -为往前推
calendar.add(Calendar.MONTH, +1);
//获得下一个月是多少年
int year = calendar.get(Calendar.YEAR);
calendar.set(year, month, 0);
//获得下一个月有多少天
return calendar.get(Calendar.DAY_OF_MONTH);
calendar.setTime(date);
calendar.set(Calendar.DATE, 1);
calendar.roll(Calendar.DATE, -1);
return calendar.get(Calendar.DATE);
}
/**
* 根据班次规则获取
*
......
spring:
profiles:
active: prod
active: dev
# 日志
logging:
file:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!