Commit 9c1b8099 by zhangshaowu

排班信息

1 parent df011e1f
......@@ -28,6 +28,10 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
......
......@@ -2,6 +2,7 @@ package com.pipihelper.project.configurer;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
......@@ -56,8 +57,8 @@ public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
// 按需配置,更多参考FastJson文档哈
converter.setFastJsonConfig(config);
converter.setDefaultCharset(Charset.forName("UTF-8"));
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));
converter.setDefaultCharset(StandardCharsets.UTF_8);
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8));
converters.add(converter);
}
......
......@@ -6,7 +6,6 @@ import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventReceiveMessageDTO;
import com.pipihelper.project.tx.dto.TxConfig;
import com.pipihelper.project.tx.service.TxApiService;
import com.pipitest.project.feishu.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
......
package com.pipihelper.project.interceptor;
import com.pipihelper.project.core.Result;
import com.pipihelper.project.core.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
/**
* 白名单拦截器,用于控制允许访问的请求
*
* @author zlikun
* @date 2021/10/21 14:39
*/
@Slf4j
@Component
@Aspect
public class ResponseAop {
//这里改成自己项目的控制层路径
@Pointcut("execution(public * com.pipihelper.project.controller..*(..))")
public void httpResponse() {
}
//环切
@Around("httpResponse()")
public Result handlerController(ProceedingJoinPoint proceedingJoinPoint) {
Result result = new Result();
try {
//获取方法的执行结果
Object proceed = proceedingJoinPoint.proceed();
//如果方法的执行结果是Result,则将该对象直接返回
if (proceed instanceof Result) {
result = (Result) proceed;
} else {
//否则,就要封装到Result的data中
result.setData(proceed);
}
} catch (Throwable throwable) {
//如果出现了异常,调用异常处理方法将错误信息封装到Result中并返回
result = handlerException(throwable);
}
return result;
}
//异常处理
private Result handlerException(Throwable throwable) {
Result result = new Result();
//这里需要注意,返回枚举类中的枚举在写的时候应该和异常的名称相对应,以便动态的获取异常代码和异常信息,我这边是统一返回500,msg存报的异常
//获取异常名称的方法
String errorName = throwable.toString();
errorName = errorName.substring(errorName.lastIndexOf(".") + 1);
result.setMessage(errorName);
result.setCode(ResultCode.INTERNAL_SERVER_ERROR);
return result;
}
}
package com.pipihelper.project.rostering.model;
import lombok.Data;
import java.util.Date;
/**
* 指定日期内出现X个N班次
* (x=数字 n=班次名称)
* @description: 时间规则配置
* @author: zsw
* @create: 2022-10-14 18:48
**/
@Data
public class DateRuleModel {
/**
*
*/
private Date date;
private String shift;
private Integer times;
}
package com.pipihelper.project.rostering.model;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 班次规则
* @description:
* @author: zsw
* @create: 2022-10-14 16:52
**/
@Data
public class ShiftRuleModel {
/**
* 班次名称
*/
private String name;
/**
* 每天每班次出现的人数
*/
private Integer everyDay;
/**
* 班次前允许
*/
private List<String> frontAllow;
/**
* 班次前不允许
*/
private List<String> frontDenied;
/**
* 班次后允许
*/
private List<String> backAllow;
/**
* 班次后不允许
*/
private List<String> backDenied;
/**
* 班次最大连续次数
*/
private Integer maxContinuity;
/**
* 班次最大次数后指定班次
*/
private String maxContinuityFollow;
//{"backAllow":["早班"],"backDenied":["晚班"],"everyDay":5,"frontAllow":["早班"],"frontDenied":["晚班"],"maxContinuity":5,"maxContinuityFollow":"休息","name":"早班"}
public static void main(String[] args) {
ShiftRuleModel shiftRuleModel = new ShiftRuleModel();
shiftRuleModel.setName("早班");
shiftRuleModel.setEveryDay(5);
shiftRuleModel.setFrontAllow(Lists.newArrayList("早班"));
shiftRuleModel.setFrontDenied(Lists.newArrayList("晚班"));
shiftRuleModel.setBackAllow(Lists.newArrayList("早班"));
shiftRuleModel.setBackDenied(Lists.newArrayList("晚班"));
shiftRuleModel.setMaxContinuity(5);
shiftRuleModel.setMaxContinuityFollow("休息");
String s = JSONObject.toJSONString(shiftRuleModel);
System.out.println(s);
}
}
package com.pipihelper.project.rostering.model;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;
import java.util.Date;
/**
* @description: 人员配置
* @author: zsw
* @create: 2022-10-14 18:10
**/
@Data
public class StaffRuleModel {
/**
* 班次名称
*/
private String name;
/**
* 当月班次最大出现次数
*/
private Threshold maxTimes;
/**
* 当月班次最小出现次数
*/
private Threshold minTimes;
/**
* 指定班次
*/
private Threshold fixedShift;
@Data
public static class Threshold {
/**
* 班次
*/
private String shift;
/**
* 次数
*/
private Integer times;
/**
* 日期
*/
private Date date;
}
//{"fixedShift":{"date":"2022-10-14 00:00:00","shift":"AAAA"},"maxTimes":{"shift":"AAA","times":5},"minTimes":{"shift":"AAA","times":5},"name":"xxxx"}
public static void main(String[] args) {
StaffRuleModel staffRuleModel = new StaffRuleModel();
staffRuleModel.setName("xxxx");
Threshold maxTimes = new Threshold();
maxTimes.setShift("AAA");
maxTimes.setTimes(5);
Threshold minTimes = new Threshold();
minTimes.setShift("AAA");
minTimes.setTimes(5);
Threshold fixedShift = new Threshold();
fixedShift.setDate(DateUtil.parse("2022-10-14 00:00:00"));
fixedShift.setShift("AAAA");
staffRuleModel.setMaxTimes(maxTimes);
staffRuleModel.setMinTimes(minTimes);
staffRuleModel.setFixedShift(fixedShift);
String s = JSONObject.toJSONString(staffRuleModel, SerializerFeature.WriteDateUseDateFormat);
System.out.println(s);
}
}
package com.pipihelper.project.rostering.service;
import com.pipihelper.project.rostering.model.DateRuleModel;
import com.pipihelper.project.rostering.model.StaffRuleModel;
import com.pipihelper.project.rostering.model.RosteringModel;
import com.pipihelper.project.rostering.model.ShiftRuleModel;
import java.util.List;
/**
* @description:
* @author: zsw
......@@ -7,5 +14,20 @@ package com.pipihelper.project.rostering.service;
**/
public interface RosteringService {
/**
* 生成班次
* @param staffs 人员
* @param shifts 班次
* @param shiftRuleModels 班次规则
* @param staffRuleModels 原因规则
* @param dateRuleModels 时间规则
* @return
*/
List<RosteringModel> gen(List<String> staffs,
List<String> shifts,
List<ShiftRuleModel> shiftRuleModels,
List<StaffRuleModel> staffRuleModels,
List<DateRuleModel> dateRuleModels);
}
package com.pipihelper.project.rostering.service.impl;
import com.pipihelper.project.rostering.model.DateRuleModel;
import com.pipihelper.project.rostering.model.RosteringModel;
import com.pipihelper.project.rostering.model.ShiftRuleModel;
import com.pipihelper.project.rostering.model.StaffRuleModel;
import com.pipihelper.project.rostering.service.RosteringService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @description:
* @author: zsw
......@@ -10,4 +16,40 @@ import org.springframework.stereotype.Service;
**/
@Service
public class RosteringServiceImpl implements RosteringService {
@Override
public List<RosteringModel> gen(List<String> staffs,
List<String> shifts,
List<ShiftRuleModel> shiftRuleModels,
List<StaffRuleModel> staffRuleModels,
List<DateRuleModel> dateRuleModels) {
//校验
verify(staffs, shifts, shiftRuleModels, staffRuleModels);
return null;
}
private void verify(List<String> staffs,
List<String> shifts,
List<ShiftRuleModel> shiftRuleModels,
List<StaffRuleModel> staffRuleModels) {
if (shiftRuleModels.stream().noneMatch(e -> shifts.contains(e.getName()))) {
throw new RuntimeException("班次配置不合法");
}
if (staffRuleModels.stream().noneMatch(e -> staffs.contains(e.getName()))) {
throw new RuntimeException("员工配置不合法");
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!