Commit 3cef9a81 by zhaolianjie

Merge remote-tracking branch 'origin/master'

2 parents a11da856 4fedb4c2
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;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.pipihelper.project.core.Result;
import com.pipihelper.project.core.ResultCode;
import com.pipihelper.project.core.ServiceException;
import com.pipihelper.project.core.Result;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -36,6 +23,15 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Spring MVC 配置
*/
......@@ -98,12 +94,18 @@ public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
});
}
//解决跨域问题
@Override
public void addCorsMappings(CorsRegistry registry) {
//registry.addMapping("/**");
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowCredentials(true)
.allowedHeaders("*")
.maxAge(3600);
WebMvcConfigurer.super.addCorsMappings(registry);
}
//添加拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
......
......@@ -42,7 +42,7 @@ public class RosteringController {
return ResultGenerator.genSuccessResult(rosteringService.findAllStaff());
}
@GetMapping(value = "export")
@RequestMapping(value = "export")
public void listStaff(String datas, String date, HttpServletResponse response) {
List<RosteringExportModel> rosteringModels = JSONObject.parseArray(datas, RosteringExportModel.class);
Workbook workbook = rosteringService.export(rosteringModels);
......@@ -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));
}
......
......@@ -31,6 +31,7 @@ import com.pipihelper.project.utils.CacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -82,6 +83,9 @@ public class FeiShuEventController {
@Autowired
private MassageService massageService;
@Value("${spring.profiles.active}")
private String active;
@PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception {
......@@ -220,6 +224,13 @@ public class FeiShuEventController {
return null;
}
@PostMapping("/uprset-employee")
public Object uprsetEmployee() {
employeeService.uprsetAllEmployee();
System.out.println(active);
return feiShuApiService.getEmployeeList();
}
@PostMapping("/employee-list")
public Object event() {
employeeService.uprsetAllEmployee();
......@@ -232,8 +243,8 @@ public class FeiShuEventController {
startEmployeeId = maxPain.getEmployeeId();
}
int countByFloor = employeeService.findCountByFloor(floor);
int limit = 2;
if (countByFloor < 2) {
int limit = 30;
if (countByFloor < 30) {
limit = countByFloor;
}
List<Employee> employeeList = employeeService.findStartList(startEmployeeId, floor, limit);
......@@ -281,7 +292,11 @@ public class FeiShuEventController {
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setName("按摩群 " + DateUtil.today());
if ("prod".equals(active)) {
feiShuChatDTO.setOwnerId(feiShuConfig.getXiaoshanOpenId());
} else {
feiShuChatDTO.setOwnerId(pushPainBOList.get(0).getOpenId());
}
feiShuChatDTO.setUserIdList(userIdList);
String chatId = feiShuApiService.createChatList(feiShuChatDTO);
massageService.sendMassageMsgCardToPiPiChat(pushPainBOList, chatId);
......
......@@ -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;
/**
......@@ -20,19 +21,24 @@ public interface RosteringService {
Workbook export(List<RosteringExportModel> rosteringModels);
void createStaff(RosteringStaff rosteringStaff);
void deleteStaff(Integer id);
void updateStaff(RosteringStaff rosteringStaff);
List<RosteringStaff> findAllStaff();
/**
* 生成班次
*
* @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;
......@@ -40,6 +41,7 @@ import java.util.stream.Collectors;
@Service
public class RosteringServiceImpl implements RosteringService {
@Autowired
private RosteringStaffDao rosteringStaffDao;
......@@ -54,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("部门");
......@@ -83,7 +84,7 @@ public class RosteringServiceImpl implements RosteringService {
List<String> dates = rosteringModels.stream().map(e -> {
String dateStr = DateUtil.format(e.getDate(), "yyyy/MM/dd");
return dateStr + e.getWeek();
}).collect(Collectors.toList());
}).distinct().collect(Collectors.toList());
for (int i = 0; i < dates.size(); i++) {
int orderNum = i + 5;
String name = dates.get(i);
......@@ -110,64 +111,84 @@ public class RosteringServiceImpl implements RosteringService {
String dateStr = DateUtil.format(e.getDate(), "yyyy/MM/dd");
String date = dateStr + e.getWeek();
map.put(date, e.getShift());
datas.add(map);
});
datas.add(map);
});
return ExcelExportUtil.exportExcel(new ExportParams(), colList, datas);
}
@Override
public void createStaff(RosteringStaff rosteringStaff) {
}
@Override
public void deleteStaff(Integer id) {
}
@Override
public void updateStaff(RosteringStaff rosteringStaff) {
}
@Override
public List<RosteringStaff> findAllStaff() {
return rosteringStaffDao.findAll();
}
@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<>();
......@@ -198,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);
}
/**
* 根据班次规则获取
*
......
......@@ -139,7 +139,7 @@ public class MassageNoticeScheduleService {
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setName("按摩群 " + DateUtil.today());
feiShuChatDTO.setOwnerId(feiShuConfig.getChatId());
feiShuChatDTO.setOwnerId(feiShuConfig.getXiaoshanOpenId());
feiShuChatDTO.setUserIdList(userIdList);
String chatId = feiShuApiService.createChatList(feiShuChatDTO);
massageService.sendMassageMsgCardToPiPiChat(pushPainBOList, chatId);
......
......@@ -15,8 +15,8 @@ feishu:
verificationToken: iFeLGB7JZQV37zDjIFTw0dUQ0QfFlkm5
appId: cli_a3c0cb967f619013
appSecret: NdqjzD2Bkaif6HyU8KCXGbFJzDhEEimt
ChatId: oc_2c70ffa8559b1bdd75c4dca0490b7a05
xiaoshanOpenId: od-41a0dc296e8761e3708560eeea68bbf6
ChatId: oc_71cef927cc2788067eb7d0d3dd4942a3
xiaoshanOpenId: ou_95a0fdeae5d7dc2d593fe59805253476
# 腾讯云配置参数
tx:
......
spring:
profiles:
active: dev
active: prod
# 日志
logging:
file:
......
......@@ -23,7 +23,7 @@
"header": {
"template": "red",
"title": {
"content": "🔔 叮~今日份按摩名单",
"content": "🔔 叮~今日份B27-14按摩名单",
"tag": "plain_text"
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!