Commit 23aee837 by liushuangwu

111

1 parent 3d68f4e2
package com.pipihelper.project.feishu.controller; package com.pipihelper.project.feishu.controller;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -194,28 +195,27 @@ public class FeiShuEventController { ...@@ -194,28 +195,27 @@ public class FeiShuEventController {
@PostMapping("/employee-list") @PostMapping("/employee-list")
public Object event() { public Object event() {
employeeService.uprsetAllEmployee(); employeeService.uprsetAllEmployee();
LastMaxPain maxPain = lastMaxPainService.findByFloor(14); for (Integer floor : Lists.newArrayList(14)) {
LastMaxPain maxPain = lastMaxPainService.findByFloor(floor);
int startEmployeeId = 0; int startEmployeeId = 0;
if (maxPain != null) { if (maxPain != null) {
startEmployeeId = maxPain.getEmployeeId(); startEmployeeId = maxPain.getEmployeeId();
} }
int countByFloor = employeeService.findCountByFloor(14); int countByFloor = employeeService.findCountByFloor(floor);
int limit = 30; int limit = 2;
if(countByFloor < 30){ if (countByFloor < 2) {
limit = countByFloor; limit = countByFloor;
} }
List<Employee> employeeList = employeeService.findStartList(startEmployeeId, 14, limit); List<Employee> employeeList = employeeService.findStartList(startEmployeeId, floor, limit);
Integer maxEmploeeId = 0; Integer maxEmploeeId = 0;
if (employeeList.size() == limit) { if (employeeList.size() == limit) {
maxEmploeeId = employeeList.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0); maxEmploeeId = employeeList.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0);
} else { } else {
List<Employee> employees = employeeService.findStartList(0, 14, limit - employeeList.size()); List<Employee> employees = employeeService.findStartList(0, floor, limit - employeeList.size());
maxEmploeeId = employees.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0); maxEmploeeId = employees.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0);
employeeList.addAll(employees); employeeList.addAll(employees);
} }
System.out.println(maxEmploeeId);
Map<String, FeiShuDepartmentDTO> departmentMap = new HashMap<>(); Map<String, FeiShuDepartmentDTO> departmentMap = new HashMap<>();
List<String> departmentIdList = employeeList.stream().map(Employee::getDepartmentId).distinct().collect(Collectors.toList()); List<String> departmentIdList = employeeList.stream().map(Employee::getDepartmentId).distinct().collect(Collectors.toList());
...@@ -224,8 +224,7 @@ public class FeiShuEventController { ...@@ -224,8 +224,7 @@ public class FeiShuEventController {
departmentMap.put(it, department); departmentMap.put(it, department);
}); });
painService.deleteAllByFloor(14); painService.deleteAllByFloor(floor);
System.out.println(employeeList);
List<PushPainBO> pushPainBOList = new ArrayList<>(); List<PushPainBO> pushPainBOList = new ArrayList<>();
String[] userIdList = new String[employeeList.size()]; String[] userIdList = new String[employeeList.size()];
AtomicInteger i = new AtomicInteger(1); AtomicInteger i = new AtomicInteger(1);
...@@ -233,7 +232,7 @@ public class FeiShuEventController { ...@@ -233,7 +232,7 @@ public class FeiShuEventController {
Pain pain = new Pain(); Pain pain = new Pain();
pain.setOpenId(it.getOpenId()); pain.setOpenId(it.getOpenId());
pain.setStatus(0); pain.setStatus(0);
pain.setFloor(Optional.ofNullable(it.getFloor()).orElse(14)); pain.setFloor(Optional.ofNullable(it.getFloor()).orElse(floor));
int increment = i.getAndIncrement(); int increment = i.getAndIncrement();
pain.setPindex(increment); pain.setPindex(increment);
pain.setName(it.getName()); pain.setName(it.getName());
...@@ -246,19 +245,18 @@ public class FeiShuEventController { ...@@ -246,19 +245,18 @@ public class FeiShuEventController {
pushPainBO.setName(it.getName()); pushPainBO.setName(it.getName());
pushPainBO.setDepartMentName(departMentName); pushPainBO.setDepartMentName(departMentName);
pushPainBO.setOpenId(it.getOpenId()); pushPainBO.setOpenId(it.getOpenId());
pushPainBO.setTimeRange("15:00-16:00"); pushPainBO.setTimeRange(painService.getTimeRange(increment, floor));
pushPainBOList.add(pushPainBO); pushPainBOList.add(pushPainBO);
userIdList[increment-1] = it.getOpenId(); userIdList[increment - 1] = it.getOpenId();
}); });
System.out.println(pushPainBOList);
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO(); FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setName("etgh "); feiShuChatDTO.setName("按摩群 " + DateUtil.today());
feiShuChatDTO.setOwnerId(pushPainBOList.get(0).getOpenId()); feiShuChatDTO.setOwnerId(pushPainBOList.get(0).getOpenId());
feiShuChatDTO.setUserIdList(userIdList); feiShuChatDTO.setUserIdList(userIdList);
String chatId = feiShuApiService.createChatList(feiShuChatDTO); String chatId = feiShuApiService.createChatList(feiShuChatDTO);
massageService.sendMassageMsgCardToPiPiChat(pushPainBOList,chatId); massageService.sendMassageMsgCardToPiPiChat(pushPainBOList, chatId);
massageService.sendMassageMsgCardToPiPiChat(pushPainBOList,feiShuConfig.getChatId()); massageService.sendMassageMsgCardToPiPiChat(pushPainBOList, feiShuConfig.getChatId());
if (maxPain != null) { if (maxPain != null) {
maxPain.setEmployeeId(maxEmploeeId); maxPain.setEmployeeId(maxEmploeeId);
...@@ -266,13 +264,21 @@ public class FeiShuEventController { ...@@ -266,13 +264,21 @@ public class FeiShuEventController {
} else { } else {
maxPain = new LastMaxPain(); maxPain = new LastMaxPain();
maxPain.setEmployeeId(maxEmploeeId); maxPain.setEmployeeId(maxEmploeeId);
maxPain.setFloor(14); maxPain.setFloor(floor);
lastMaxPainService.create(maxPain); lastMaxPainService.create(maxPain);
} }
}
List<FeiShuEmployeeDTO> dtos = feiShuApiService.getEmployeeList(); List<FeiShuEmployeeDTO> dtos = feiShuApiService.getEmployeeList();
return dtos; return dtos;
} }
@PostMapping("/department-user")
public Object departmentUser(String department) {
return feiShuApiService.getUser(department);
}
@PostMapping("/department") @PostMapping("/department")
public Object department(String department) { public Object department(String department) {
......
...@@ -7,6 +7,7 @@ import com.pipihelper.project.feishu.entity.Employee; ...@@ -7,6 +7,7 @@ import com.pipihelper.project.feishu.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
...@@ -18,6 +19,21 @@ public class EmployeeService { ...@@ -18,6 +19,21 @@ public class EmployeeService {
@Autowired @Autowired
private EmployeeDao employeeDao; private EmployeeDao employeeDao;
private static final List<String> eightFloorEightdepartmentIdList = new ArrayList<>();
static {
eightFloorEightdepartmentIdList.add("od-3890573b4cd286f437d8e935e10f79bd");
eightFloorEightdepartmentIdList.add("od-80c6807080faabbb1c4db7bd4d9bd3fd");
eightFloorEightdepartmentIdList.add("od-257f04c282e11a4dbb40bbce905dc288");
eightFloorEightdepartmentIdList.add("od-4ff65217e64292e3ff5726258ddb2bd8");
eightFloorEightdepartmentIdList.add("od-5493776cfddf24c28e1c4620b9ee3406");
eightFloorEightdepartmentIdList.add("od-133305bbba80fa87b979453a1ffc689a");
eightFloorEightdepartmentIdList.add("od-2a43207cc2d92d781cb1cdfdcf33dc28");
eightFloorEightdepartmentIdList.add("od-f2a40e56473fbdfbdcca9efb4302cbca");
eightFloorEightdepartmentIdList.add("od-d7ddf7e8b966b0886319ff93f4dac95b");
eightFloorEightdepartmentIdList.add("od-ab7c4b49f80d53ca54f60bb47661bad3");
}
@Autowired @Autowired
private FeiShuApiService feiShuApiService; private FeiShuApiService feiShuApiService;
...@@ -76,7 +92,7 @@ public class EmployeeService { ...@@ -76,7 +92,7 @@ public class EmployeeService {
employee.setName(systemFieldsDTO.getName()); employee.setName(systemFieldsDTO.getName());
employee.setMobile(systemFieldsDTO.getMobile()); employee.setMobile(systemFieldsDTO.getMobile());
} }
employee.setFloor(14); employee.setFloor(eightFloorEightdepartmentIdList.contains(employee.getDepartmentId()) ? 8 : 14);
this.create(employee); this.create(employee);
}); });
} }
......
...@@ -52,6 +52,11 @@ public class PainService { ...@@ -52,6 +52,11 @@ public class PainService {
return painDao.findAll(); return painDao.findAll();
} }
public String getTimeRange(int pindex, int floor) {
String timeRange = pindexFloors.stream().filter(it -> it.floor != null && it.floor == floor)
.filter(it -> pindex <= it.getEndIndex() && pindex >= it.getStartIndex()).findFirst().get().timeRange;
return timeRange;
}
public List<Pain> findAllReorderByFloor(int floor) { public List<Pain> findAllReorderByFloor(int floor) {
List<Pain> painList = painDao.findAllByFloor(floor); List<Pain> painList = painDao.findAllByFloor(floor);
...@@ -64,7 +69,7 @@ public class PainService { ...@@ -64,7 +69,7 @@ public class PainService {
int increment = atomicInteger.getAndIncrement(); int increment = atomicInteger.getAndIncrement();
pain.setPindex(increment); pain.setPindex(increment);
String timeRange = pindexFloors.stream().filter(it -> it.floor != null && it.floor == floor) String timeRange = pindexFloors.stream().filter(it -> it.floor != null && it.floor == floor)
.filter(it -> floor <= it.getEndIndex() && floor >= it.getStartIndex()).findFirst().get().timeRange; .filter(it -> increment <= it.getEndIndex() && increment >= it.getStartIndex()).findFirst().get().timeRange;
pain.setTimeRange(timeRange); pain.setTimeRange(timeRange);
}); });
return painList; return painList;
......
package com.pipihelper.project.scheduled; package com.pipihelper.project.scheduled;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.pipihelper.project.feishu.bo.PushPainBO;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.chat.FeiShuChatDTO;
import com.pipihelper.project.feishu.dto.department.FeiShuDepartmentDTO;
import com.pipihelper.project.feishu.entity.Employee;
import com.pipihelper.project.feishu.entity.LastMaxPain;
import com.pipihelper.project.feishu.entity.Pain; import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.EmployeeService;
import com.pipihelper.project.feishu.service.FeiShuApiService; import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.LastMaxPainService;
import com.pipihelper.project.feishu.service.PainService; import com.pipihelper.project.feishu.service.PainService;
import com.pipihelper.project.feishu.service.massage.MassageService; import com.pipihelper.project.feishu.service.massage.MassageService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -11,8 +22,16 @@ import org.springframework.scheduling.annotation.Async; ...@@ -11,8 +22,16 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/** /**
* @Description: TODO * @Description: TODO
...@@ -32,13 +51,104 @@ public class MassageNoticeScheduleService { ...@@ -32,13 +51,104 @@ public class MassageNoticeScheduleService {
@Autowired @Autowired
private FeiShuApiService feiShuApiService; private FeiShuApiService feiShuApiService;
@Autowired
private EmployeeService employeeService;
@Autowired
private LastMaxPainService lastMaxPainService;
@Resource
private FeiShuConfig feiShuConfig;
private final static Map<Integer, Integer> floorCountMap = new HashMap<>();
static {
floorCountMap.put(8, 10);
floorCountMap.put(14, 30);
}
/** /**
* 每周四定时生成要按摩的人员名单,并发送大群和单人消息 * 每周四定时生成要按摩的人员名单,并发送大群和单人消息
*/ */
@Async @Async
@Scheduled(cron = "0 0 10 * * ?") @Scheduled(cron = "0 0 10 * * ?")
public void sendMsgCardToPipiChat(){ public void sendMsgCardToPipiChat() {
employeeService.uprsetAllEmployee();
for (Integer floor : Lists.newArrayList(14)) {
LastMaxPain maxPain = lastMaxPainService.findByFloor(floor);
int startEmployeeId = 0;
if (maxPain != null) {
startEmployeeId = maxPain.getEmployeeId();
}
int countByFloor = employeeService.findCountByFloor(floor);
int limit = floorCountMap.get(floor);
if (countByFloor < limit) {
limit = countByFloor;
}
List<Employee> employeeList = employeeService.findStartList(startEmployeeId, floor, limit);
Integer maxEmploeeId;
if (employeeList.size() == limit) {
maxEmploeeId = employeeList.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0);
} else {
List<Employee> employees = employeeService.findStartList(0, floor, limit - employeeList.size());
maxEmploeeId = employees.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0);
employeeList.addAll(employees);
}
Map<String, FeiShuDepartmentDTO> departmentMap = new HashMap<>();
List<String> departmentIdList = employeeList.stream().map(Employee::getDepartmentId).distinct().collect(Collectors.toList());
departmentIdList.forEach(it -> {
FeiShuDepartmentDTO department = feiShuApiService.getDepartment(it);
departmentMap.put(it, department);
});
painService.deleteAllByFloor(floor);
if (CollectionUtil.isEmpty(employeeList)) {
return;
}
List<PushPainBO> pushPainBOList = new ArrayList<>();
String[] userIdList = new String[employeeList.size()];
AtomicInteger i = new AtomicInteger(1);
employeeList.forEach(it -> {
Pain pain = new Pain();
pain.setOpenId(it.getOpenId());
pain.setStatus(0);
pain.setFloor(Optional.ofNullable(it.getFloor()).orElse(floor));
int increment = i.getAndIncrement();
pain.setPindex(increment);
pain.setName(it.getName());
String departMentName = departmentMap.getOrDefault(it.getDepartmentId(), new FeiShuDepartmentDTO()).getName();
pain.setDepartMentName(departMentName);
painService.create(pain);
PushPainBO pushPainBO = new PushPainBO();
pushPainBO.setIndex(increment);
pushPainBO.setName(it.getName());
pushPainBO.setDepartMentName(departMentName);
pushPainBO.setOpenId(it.getOpenId());
pushPainBO.setTimeRange(painService.getTimeRange(increment, floor));
pushPainBOList.add(pushPainBO);
userIdList[increment - 1] = it.getOpenId();
});
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setName("按摩群 " + DateUtil.today());
feiShuChatDTO.setOwnerId(pushPainBOList.get(0).getOpenId());
feiShuChatDTO.setUserIdList(userIdList);
String chatId = feiShuApiService.createChatList(feiShuChatDTO);
massageService.sendMassageMsgCardToPiPiChat(pushPainBOList, chatId);
massageService.sendMassageMsgCardToPiPiChat(pushPainBOList, feiShuConfig.getChatId());
if (maxPain != null) {
maxPain.setEmployeeId(maxEmploeeId);
lastMaxPainService.update(maxPain);
} else {
maxPain = new LastMaxPain();
maxPain.setEmployeeId(maxEmploeeId);
maxPain.setFloor(floor);
lastMaxPainService.create(maxPain);
}
}
} }
...@@ -47,9 +157,9 @@ public class MassageNoticeScheduleService { ...@@ -47,9 +157,9 @@ public class MassageNoticeScheduleService {
*/ */
// @Async // @Async
// @Scheduled(cron = "0 0 10 * * ?") // @Scheduled(cron = "0 0 10 * * ?")
public void massageStart(){ public void massageStart() {
List<Pain> pains = painService.findListAsc(3); List<Pain> pains = painService.findListAsc(3);
for(Pain pain:pains){ for (Pain pain : pains) {
String messageId = pain.getMessageId(); String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId); massageService.updateSingleMassageMsgCardWhenBegin(messageId);
//1代表正在按 //1代表正在按
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!