Commit df6fff7a by liushuangwu

Merge branch 'master' of http://pipi-gitlab.apeiwan.com/zhangshaowu/pipi-helper

 Conflicts:
	src/main/java/com/pipihelper/project/feishu/controller/FeishuTaskController.java
2 parents 9559df76 4a7e39e2
Showing 26 changed files with 335 additions and 546 deletions
......@@ -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);
}
......
......@@ -30,14 +30,14 @@ public class FeiShuEventController {
public JSONObject event(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s);
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getAppConfigMap().get(feiShuConfig.getTestHelperApp()).getEncryptKey());
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey());
JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt")));
System.out.println(encryptJsonObject);
if (encryptJsonObject.containsKey("challenge")) {
return encryptJsonObject;
}
FeiShuEventDTO feiShuEventDTO = encryptJsonObject.toJavaObject(FeiShuEventDTO.class);
if (!feiShuEventDTO.getHeader().getToken().equalsIgnoreCase(feiShuConfig.getAppConfigMap().get(feiShuConfig.getTestHelperApp()).getVerificationToken())) {
if (!feiShuEventDTO.getHeader().getToken().equalsIgnoreCase(feiShuConfig.getVerificationToken())) {
return null;
}
if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
......
package com.pipihelper.project.controller;
package com.pipihelper.project.feishu.controller;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.core.Result;
import com.pipihelper.project.core.ResultGenerator;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.enums.SendMsgBusinessType;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -25,6 +24,8 @@ public class SendMsgUseFeiShu {
@Autowired
private FeiShuConfig feiShuConfig;
@PostMapping("/send-msg")
public Result sendMsg(String receiveId, String msg, String receiveIdType){
JSONObject sendMsg = new JSONObject();
......@@ -32,8 +33,9 @@ public class SendMsgUseFeiShu {
sendMsg.put("msg_type", "text");
JSONObject content = new JSONObject();
content.put("text", msg);
sendMsg.put("content", content.toString());
feiShuApiService.sendMsg(SendMsgBusinessType.TALK.getBusinessType(), receiveIdType, sendMsg, feiShuConfig.getTestHelperApp());
feiShuApiService.sendMsg(receiveIdType, sendMsg);
return ResultGenerator.genSuccessResult();
}
}
package com.pipihelper.project.feishu.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@Data
public class AppConfig {
private String encryptKey;
private String verificationToken;
private String appId;
private String appSecret;
private String fkChatId;
private String fkChatIdTest;
private String tableId;
private String peopleTableId;
private String taskTableId;
}
......@@ -21,10 +21,16 @@ import java.util.Map;
public class FeiShuConfig {
private String feiShuOpenApiHost;
private String testHelperApp;
private String anniversaryApp;
private String encryptKey;
private String verificationToken;
private String appId;
private String appSecret;
private String fkChatId;
private String fkChatIdTest;
private Map<String, AppConfig> appConfigMap;
private String tableId;
private String peopleTableId;
private String taskTableId;
}
package com.pipihelper.project.feishu.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@Getter
@AllArgsConstructor
public enum CardElements {
APP_TYPE("appType","select_static","APP类型"),
MODULE("module","select_static","业务场景"),
LEVEL("level","select_static","优先级"),
ASSIGN("assign","select_person","指派处理人"),
VERIFY("verify","select_person","转发给其他值班人"),
HANDLE("handle","button","我来"),
FINISH_TIME("finishTime","date_picker","预计完成时间"),
FINISH("finish","button","完成"),
FILE_FINISH("fileFinish","overflow","完成|完成并归档");
// FILED("button","","","");
private String action;
private String tag;
private String msg;
}
package com.pipihelper.project.feishu.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ModuleType {
FRIENDS(1,"娱乐"),
PLAY(2,"游戏"),
MIDDLEWARE(3,"中台"),
OTHER(4,"其他"),
NONE(0,"未指定");
private Integer type;
private String msg;
public static Integer getTypeByMsg(String msg) {
for (ModuleType moduleType : ModuleType.values()) {
if (moduleType.getMsg().equals(msg)) {
return moduleType.getType();
}
}
return null;
}
public static String getMsgByType(Integer type) {
for (ModuleType moduleType : ModuleType.values()) {
if (moduleType.getType().equals(type)) {
return moduleType.getMsg();
}
}
return null;
}
}
package com.pipihelper.project.feishu.enums;
import com.pipihelper.project.core.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Getter
@AllArgsConstructor
public enum MsgCard {
//CardElements.APP_TYPE, CardElements.MODULE, CardElements.LEVEL,CardElements.ASSIGN,CardElements.VERIFY, CardElements.HANDLE, CardElements.FINISH_TIME, CardElements.FINISH
TESTER_CARD_01("tester_0", Arrays.asList(CardElements.VERIFY, CardElements.HANDLE), "待值班确认", 1),
TESTER_CARD_02("tester_1", Arrays.asList(CardElements.LEVEL, CardElements.ASSIGN), "待值班指派", 1),
TESTER_CARD_03("tester_2", Arrays.asList(CardElements.FILE_FINISH), "负责人已完成待值班已确认", 1),//问题已完成,负责人未点完成,不允许测试点完成
TESTER_CARD_04("tester_3", Arrays.asList(CardElements.FINISH_TIME,CardElements.FILE_FINISH), "值班负责任务",4),//负责人是自己的时候,可以点击填写完成时间
TESTER_CARD_05("tester_4", new ArrayList<>(), "负责人已确认待解决",4),//开发确认后,测试侧卡片
CODER_CARD_01("coder_0", Arrays.asList(CardElements.ASSIGN, CardElements.HANDLE), "待负责人确认",1),
CODER_CARD_02("coder_1", Arrays.asList(CardElements.FINISH_TIME,CardElements.FINISH), "负责人已确认待解决",4),//负责人只能完成,不能归档
FILE("file", new ArrayList<>(), "卡片固化",null);
private String type;
private List<CardElements> elements;
private String msg;
private Integer interval;
public static List<CardElements> getElementsByType(String type) {
for (MsgCard msgCard : MsgCard.values()) {
if (msgCard.getType().equals(type)) {
return msgCard.getElements();
}
}
throw new ServiceException("类型不匹配");
}
public static Integer getIntervalByType(String type) {
for (MsgCard msgCard : MsgCard.values()) {
if (msgCard.getType().equals(type)) {
return msgCard.getInterval();
}
}
throw new ServiceException("类型不匹配");
}
}
package com.pipihelper.project.feishu.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @Description: TODO
* @author: charles
* @date: 2022年06月08日 14:21
*/
@Getter
@AllArgsConstructor
public enum NoticeType {
NONE(0,"未发送提醒"),
URGENT_APP(1,"app内加急"),
URGENT_SMS(2,"短信加急"),
URGENT_PHONE(3,"电话加急"),
URGENT_APP_24(4,"app内加急"),
URGENT_SMS_24(5,"短信加急"),
URGENT_PHONE_24(6,"电话加急");
private Integer type;
private String msg;
}
package com.pipihelper.project.feishu.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum SendMsgBusinessType {
/***
* 机器人发送消息的消息类型
*/
FEEDBACKS(0,"反馈群反馈问题"),
FEEDBACKS_DATA(1,""),
TALK(2,"一般性对话"),
DUTY_NOTICE(3, "值班提醒"),
HAR(4,"解析har文件"),
SYNC_DICT(5,"同步字典"),
TEST_DATA(6,"处理测试数据"),
DEFAULT(-1,"");
private Integer businessType;
private String description;
}
......@@ -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;
......@@ -47,8 +46,8 @@ public class FeiShuEventService {
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
//单独处理群消息
if (message.getChat_id().equals(feiShuConfig.getAppConfigMap().get(feiShuConfig.getTestHelperApp()).getFkChatId())
|| message.getChat_id().equals(feiShuConfig.getAppConfigMap().get(feiShuConfig.getTestHelperApp()).getFkChatIdTest())) { //判断是否为指定群消息
if (message.getChat_id().equals(feiShuConfig.getFkChatId())
|| message.getChat_id().equals(feiShuConfig.getFkChatIdTest())) { //判断是否为指定群消息
return;
}
else {
......
package com.pipihelper.project.feishu.service.anniversary;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.department.FeiShuDepartmentDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public abstract class AbstractNoticeService {
@Resource
private FeiShuConfig feiShuConfig;
@Autowired
private FeiShuApiService feiShuApiService;
/**
* 发送通知
*/
public abstract void notice();
/**
* 生成员工消息卡片
* @param feiShuEmployeeDTO
* @return
*/
public abstract FeiShuMsgDTO generateEmployeeMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO);
/**
* 生产领导消息卡片
* @param feiShuEmployeeDTO
* @return
*/
public abstract FeiShuMsgDTO generateLeaderMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO);
/**
* 获取领导OpenId
*
* @param departmentId
* @return
*/
public String getLeaderOpenId(String departmentId) {
if (StringUtils.isBlank(departmentId)) {
return "";
}
if ("0".equals(departmentId)) {
// 若递归无上级负责人,则获取企业创建人
return feiShuApiService.getUser("0", feiShuConfig.getAnniversaryApp()).getJSONObject("data").getJSONArray("items").getJSONObject(0).getString("open_id");
}
FeiShuDepartmentDTO feiShuDepartmentDTO = feiShuApiService.getDepartment(departmentId, feiShuConfig.getAnniversaryApp());
return StringUtils.isNotBlank(feiShuDepartmentDTO.getLeaderUserId()) ? feiShuDepartmentDTO.getLeaderUserId() : getLeaderOpenId(feiShuDepartmentDTO.getParentDepartmentId());
}
/**
* 给部门领导发送消息,若领导是自己,则找父部门领导
*
* @param feiShuMsgDTO
* @param feiShuEmployeeDTO
*/
public void sendMsgToLeader(FeiShuMsgDTO feiShuMsgDTO, FeiShuEmployeeDTO feiShuEmployeeDTO) {
String leaderOpenId = getLeaderOpenId(feiShuEmployeeDTO.getSystemFields().getDepartmentId());
// 领导是自己,找父部门领导
if (leaderOpenId.equals(feiShuEmployeeDTO.getUserId()) && !"0".equals(feiShuEmployeeDTO.getSystemFields().getDepartmentId())) {
leaderOpenId = getLeaderOpenId(feiShuApiService.getDepartment(feiShuEmployeeDTO.getSystemFields().getDepartmentId(), feiShuConfig.getAnniversaryApp()).getParentDepartmentId());
}
if (!leaderOpenId.equals(feiShuEmployeeDTO.getUserId()) && StringUtils.isNotBlank(leaderOpenId)) {
// 给领导发送消息
feiShuMsgDTO.setReceiveId(leaderOpenId);
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id", feiShuConfig.getAnniversaryApp());
}
}
/**
* 读取模板文件
* @param file
* @return
*/
public String getInteractiveCardStr(String file){
try {
InputStream in = this.getClass().getResourceAsStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(in);
Stream<String> streamOfString= new BufferedReader(inputStreamReader).lines();
String streamToString = streamOfString.collect(Collectors.joining());
return streamToString;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
package com.pipihelper.project.feishu.service.anniversary;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
/**
* 飞书入职周年提醒
*/
@Service
@Slf4j
public class AnniversaryNoticeService extends AbstractNoticeService{
@Autowired
private FeiShuApiService feiShuApiService;
@Resource
private FeiShuConfig feiShuConfig;
@Override
public void notice() {
// 1. 获取当天生日人
List<FeiShuEmployeeDTO> feiShuEmployeeDTOList = feiShuApiService.getEmployeeList(feiShuConfig.getAnniversaryApp());
List<FeiShuEmployeeDTO> hireDayEmployees = feiShuEmployeeDTOList.stream()
.filter(feiShuEmployeeDTO -> StringUtils.isNotEmpty(feiShuEmployeeDTO.getSystemFields().getHireDate()))
.filter(feiShuEmployeeDTO -> {
LocalDate hireDay = LocalDate.parse(feiShuEmployeeDTO.getSystemFields().getHireDate());
// 使用plusYears可以避免2月29日的特殊情况.当年若无2月29日,生日则为2月28日
long years = LocalDate.now().getYear() - hireDay.getYear();
// 1,2,3,5周年时发送提醒
return hireDay.plusYears(years).equals(LocalDate.now()) && (years == 1 || years == 2 || years == 3 || years == 5);
})
.peek(feiShuEmployeeDTO -> {
// 给员工自己发消息
feiShuApiService.sendMsg(generateEmployeeMsgCard(feiShuEmployeeDTO), "open_id",feiShuConfig.getAnniversaryApp());
// 给领导发送消息
sendMsgToLeader(generateLeaderMsgCard(feiShuEmployeeDTO),feiShuEmployeeDTO);
}).collect(Collectors.toList());
log.info("{} 当日周年人: {}", LocalDate.now(), hireDayEmployees);
}
@Override
public FeiShuMsgDTO generateEmployeeMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO) {
LocalDate hireDay = LocalDate.parse(feiShuEmployeeDTO.getSystemFields().getHireDate());
long years = LocalDate.now().getYear() - hireDay.getYear();
String fileName = String.format("/templates/anniversary-employee-%s.json", years);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(String.format(getInteractiveCardStr(fileName), feiShuEmployeeDTO.getSystemFields().getName()));
feiShuMsgDTO.setReceiveId(feiShuEmployeeDTO.getUserId());
return feiShuMsgDTO;
}
@Override
public FeiShuMsgDTO generateLeaderMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO) {
LocalDate hireDay = LocalDate.parse(feiShuEmployeeDTO.getSystemFields().getHireDate());
long years = LocalDate.now().getYear() - hireDay.getYear();
String fileName = String.format("/templates/anniversary-leader-%s.json", String.valueOf(years));
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(String.format(getInteractiveCardStr(fileName), feiShuEmployeeDTO.getSystemFields().getName()));
return feiShuMsgDTO;
}
}
package com.pipihelper.project.feishu.service.anniversary;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
/**
* 飞书生日提醒
*/
@Service
@Slf4j
public class BirthdayNoticeService extends AbstractNoticeService {
@Autowired
private FeiShuApiService feiShuApiService;
@Resource
private FeiShuConfig feiShuConfig;
@Override
public void notice() {
// 1. 获取当天生日人
List<FeiShuEmployeeDTO> feiShuEmployeeDTOList = feiShuApiService.getEmployeeList(feiShuConfig.getAnniversaryApp());
List<FeiShuEmployeeDTO> birthdayEmployees = feiShuEmployeeDTOList.stream()
.filter(feiShuEmployeeDTO -> StringUtils.isNotEmpty(feiShuEmployeeDTO.getSystemFields().getBirthday()))
.filter(feiShuEmployeeDTO -> {
LocalDate birthday = LocalDate.parse(feiShuEmployeeDTO.getSystemFields().getBirthday());
// 使用plusYears可以避免2月29日的特殊情况.当年若无2月29日,生日则为2月28日
long years = LocalDate.now().getYear() - birthday.getYear();
return birthday.plusYears(years).equals(LocalDate.now());
})
.map(feiShuEmployeeDTO -> {
// 给员工自己发消息
feiShuApiService.sendMsg(generateEmployeeMsgCard(feiShuEmployeeDTO), "open_id", feiShuConfig.getAnniversaryApp());
// 给领导发送消息
sendMsgToLeader(generateLeaderMsgCard(feiShuEmployeeDTO), feiShuEmployeeDTO);
return feiShuEmployeeDTO;
}).collect(Collectors.toList());
log.info("{} 当日生日人: {}", LocalDate.now(), birthdayEmployees);
}
@Override
public FeiShuMsgDTO generateEmployeeMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO) {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(String.format(getInteractiveCardStr("/templates/birthday-employee.json"), feiShuEmployeeDTO.getSystemFields().getName()));
feiShuMsgDTO.setReceiveId(feiShuEmployeeDTO.getUserId());
return feiShuMsgDTO;
}
@Override
public FeiShuMsgDTO generateLeaderMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO) {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(String.format(getInteractiveCardStr("/templates/birthday-leader.json"), feiShuEmployeeDTO.getSystemFields().getName()));
return feiShuMsgDTO;
}
}
package com.pipihelper.project.feishu.service.anniversary;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
/**
* 飞书转正日提醒
*/
@Service
@Slf4j
public class ConversionNoticeService extends AbstractNoticeService{
@Autowired
private FeiShuApiService feiShuApiService;
@Resource
private FeiShuConfig feiShuConfig;
/**
* 逻辑来自HR
* 转正日为入职日过6个月
* 一般是入职是X月Y日,那么6个月是到X+6月Y-1日到期,第二天的X+6月Y日是转正的第一天了
* 特殊情况就是有一些月份的30日 31日入职,那么转正月份因为当月最后1天不是30号或者31号,那么我们就按照当月的最后1天作为转正日
* 最典型的就是8月31日入职,转正日期可能是2月28日,也可能是2月29日
* 或者12月31日入职,那么转正日期是6月30日(因为6月没有31号);但是1月31日入职,转正日期就是7月31日(因为7月最后1天就是31号)
*/
@Override
public void notice() {
// 1. 获取当天生日人
List<FeiShuEmployeeDTO> feiShuEmployeeDTOList = feiShuApiService.getEmployeeList(feiShuConfig.getAnniversaryApp());
List<FeiShuEmployeeDTO> hireDayEmployees = feiShuEmployeeDTOList.stream()
.filter(feiShuEmployeeDTO -> StringUtils.isNotEmpty(feiShuEmployeeDTO.getSystemFields().getHireDate()))
.filter(feiShuEmployeeDTO -> {
LocalDate hireDay = LocalDate.parse(feiShuEmployeeDTO.getSystemFields().getHireDate());
// 使用plusMonths正好满足需求
return hireDay.plusMonths(6L).equals(LocalDate.now());
})
.map(feiShuEmployeeDTO -> {
// 给员工自己发消息
feiShuApiService.sendMsg(generateEmployeeMsgCard(feiShuEmployeeDTO), "open_id",feiShuConfig.getAnniversaryApp());
// 给领导发送消息
sendMsgToLeader(generateLeaderMsgCard(feiShuEmployeeDTO),feiShuEmployeeDTO);
return feiShuEmployeeDTO;
}).collect(Collectors.toList());
log.info("{} 当日转正人: {}", LocalDate.now(), hireDayEmployees);
}
@Override
public FeiShuMsgDTO generateEmployeeMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO){
String name = feiShuEmployeeDTO.getSystemFields().getName();
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(String.format(getInteractiveCardStr("/templates/conversion-employee.json"), name, name));
feiShuMsgDTO.setReceiveId(feiShuEmployeeDTO.getUserId());
return feiShuMsgDTO;
}
@Override
public FeiShuMsgDTO generateLeaderMsgCard(FeiShuEmployeeDTO feiShuEmployeeDTO) {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(String.format(getInteractiveCardStr("/templates/conversion-leader.json"), feiShuEmployeeDTO.getSystemFields().getName()));
return feiShuMsgDTO;
}
}
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("员工配置不合法");
}
}
}
......@@ -11,11 +11,6 @@ spring:
# 飞书相关配置参数
feishu:
feiShuOpenApiHost: https://open.feishu.cn/open-apis
testHelperApp: testHelperApp
anniversaryApp: anniversaryApp
# 测试小助手配置
appConfigMap[testHelperApp]:
encryptKey: aGTqmJcfXluKWfFWHGw5SdzIg6QIxPsp
verificationToken: ChUEDdWQbyHpHUV6H5fVeL5fOP3HfBE6
appId: cli_a2cff17bd3f8d013
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!