81 lines
3.6 KiB
Java
81 lines
3.6 KiB
Java
|
|
package com.engine.salary.timer;
|
||
|
|
|
||
|
|
import com.engine.common.util.ServiceUtil;
|
||
|
|
import com.engine.salary.entity.salaryBill.param.SalarySendGrantParam;
|
||
|
|
import com.engine.salary.entity.salaryBill.po.SalarySendInfoPO;
|
||
|
|
import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO;
|
||
|
|
import com.engine.salary.service.SalaryBillService;
|
||
|
|
import com.engine.salary.service.SalarySendService;
|
||
|
|
import com.engine.salary.service.SalaryTemplateService;
|
||
|
|
import com.engine.salary.service.impl.SalaryBillServiceImpl;
|
||
|
|
import com.engine.salary.service.impl.SalarySendServiceImpl;
|
||
|
|
import com.engine.salary.service.impl.SalaryTemplateServiceImpl;
|
||
|
|
import com.engine.salary.util.SalaryDateUtil;
|
||
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
||
|
|
import weaver.hrm.User;
|
||
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
||
|
|
|
||
|
|
import java.text.ParseException;
|
||
|
|
import java.text.SimpleDateFormat;
|
||
|
|
import java.time.LocalDate;
|
||
|
|
import java.time.LocalDateTime;
|
||
|
|
import java.util.*;
|
||
|
|
import java.util.stream.Collectors;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author Harryxzy
|
||
|
|
* @ClassName AutoSendSalaryJob
|
||
|
|
* @date 2023/07/03 10:39
|
||
|
|
* @description 自动发送工资单
|
||
|
|
*/
|
||
|
|
public class AutoSendSalaryJob extends BaseCronJob {
|
||
|
|
|
||
|
|
private SalarySendService getSalarySendService(User user) {
|
||
|
|
return ServiceUtil.getService(SalarySendServiceImpl.class, user);
|
||
|
|
}
|
||
|
|
|
||
|
|
private SalaryTemplateService getSalaryTemplateService(User user) {
|
||
|
|
return ServiceUtil.getService(SalaryTemplateServiceImpl.class, user);
|
||
|
|
}
|
||
|
|
|
||
|
|
private SalaryBillService getSalaryBillService(User user) {
|
||
|
|
return ServiceUtil.getService(SalaryBillServiceImpl.class, user);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void execute() {
|
||
|
|
User tempUser = new User();
|
||
|
|
tempUser.setUid(1);
|
||
|
|
tempUser.setLoginid("sysadmin");
|
||
|
|
// 获取所有设置了定时发送的默认工资单模板
|
||
|
|
List<SalaryTemplatePO> autoSendTemplate = getSalaryTemplateService(tempUser).getAutoSendTemplate();
|
||
|
|
LocalDateTime nowLocalDateTime = SalaryDateUtil.dateToLocalDateTime(new Date());
|
||
|
|
LocalDate autoSendDate = SalaryDateUtil.dateToLocalDate(new Date());
|
||
|
|
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
|
||
|
|
List<Long> needSendSobIds = autoSendTemplate.stream().filter(po -> {
|
||
|
|
int maxDays = autoSendDate.lengthOfMonth();
|
||
|
|
Integer sendDays = Integer.valueOf(po.getAutoSendDayOfMonth());
|
||
|
|
if (sendDays.intValue() > maxDays) {
|
||
|
|
sendDays = maxDays;
|
||
|
|
}
|
||
|
|
LocalDate autoSendlocalDate = autoSendDate.withDayOfMonth(sendDays);
|
||
|
|
LocalDateTime autoSendDateTime = null;
|
||
|
|
try {
|
||
|
|
autoSendDateTime = autoSendlocalDate.atTime(SalaryDateUtil.dateToLocalDateTime(timeFormat.parse(po.getAutoSendTimeOfDay())).toLocalTime());
|
||
|
|
} catch (ParseException e) {
|
||
|
|
throw new RuntimeException(e);
|
||
|
|
}
|
||
|
|
if (!autoSendDateTime.isAfter(nowLocalDateTime)) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}).map(SalaryTemplatePO::getSalarySobId).collect(Collectors.toList());
|
||
|
|
// 获取工资单状态为未发送、已撤回的发放id(且工资单类型为正常,未冻结)
|
||
|
|
List<SalarySendInfoPO> needSendList = getSalarySendService(tempUser).getNeedSendInfoId(needSendSobIds);
|
||
|
|
Map<Long, Set<Long>> sendMap = SalaryEntityUtil.group2Map(needSendList, SalarySendInfoPO::getSalarySendId, SalarySendInfoPO::getId);
|
||
|
|
for(Map.Entry<Long, Set<Long>> entry : sendMap.entrySet()){
|
||
|
|
getSalaryBillService(tempUser).grant(SalarySendGrantParam.builder().salarySendId(entry.getKey()).ids(new ArrayList<Long>(entry.getValue())).build());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|