| | |
| | | package me.zhengjie.modules.quartz.task; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.contract.service.ContractService; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | import me.zhengjie.modules.system.domain.SysConfigProportion; |
| | |
| | | import me.zhengjie.modules.system.repository.SysConfigProportionRepository; |
| | | import me.zhengjie.modules.system.repository.SysUserContractRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import me.zhengjie.utils.StringUtils; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 合同是否到期提醒 |
| | | * |
| | | * @author 魏传栋 |
| | | * @date 2023-01-10 |
| | | */ |
| | |
| | | private final SysUserContractRepository sysUserContractRepository; |
| | | private final UserRepository userRepository; |
| | | private final WeComServiceImpl weComService; |
| | | private final ContractService contractService; |
| | | |
| | | // 合同到期提醒 |
| | | public void contractRemind() throws Exception { |
| | |
| | | List<String> weComList = new ArrayList<>(); |
| | | // 查询用户 |
| | | List<User> userList = userRepository.findAll(); |
| | | for(User user : userList){ |
| | | for (User user : userList) { |
| | | // 获取用户角色 |
| | | Role role = user.getRoles().iterator().next(); |
| | | // 高级别 |
| | | if(Long.valueOf(role.getLevel()).equals(Constant.ROLE_LEVEL_SUPER) || Long.valueOf(role.getLevel()).equals(Constant.ROLE_LEVEL_GENERAL)){ |
| | | if (Long.valueOf(role.getLevel()).equals(Constant.ROLE_LEVEL_SUPER) || Long.valueOf(role.getLevel()).equals(Constant.ROLE_LEVEL_GENERAL)) { |
| | | if (StringUtils.isNotBlank(user.getWeComId())) { |
| | | weComList.add(user.getWeComId()); |
| | | } |
| | |
| | | |
| | | // 查询合同 |
| | | List<SysUserContract> sysUserContractList = sysUserContractRepository.findAll(); |
| | | for(SysUserContract sysUserContract : sysUserContractList){ |
| | | for (SysUserContract sysUserContract : sysUserContractList) { |
| | | // 当合同结束时间大于今天 |
| | | if(sysUserContract.getContractEndTime().compareTo(today) > 0){ |
| | | if (sysUserContract.getContractEndTime().compareTo(today) > 0) { |
| | | // 查询合同即将到期的员工 |
| | | User user1 = userRepository.findById(sysUserContract.getUserId()).orElseGet(User::new); |
| | | // date转LocalDateTime |
| | |
| | | ZoneId zoneId = ZoneId.systemDefault(); |
| | | LocalDateTime todayLocalDateTime = instant.atZone(zoneId).toLocalDateTime(); |
| | | // 今天到合同结束时间的差值 |
| | | Long chronoUnit = ChronoUnit.DAYS.between(todayLocalDateTime.toLocalDate(), sysUserContract.getContractEndTime().toLocalDateTime().toLocalDate()); |
| | | Long chronoUnit = ChronoUnit.DAYS.between(todayLocalDateTime.toLocalDate(), sysUserContract.getContractEndTime().toLocalDateTime().toLocalDate()); |
| | | Integer count = 0; |
| | | for (Integer i = 0; i <= chronoUnit; i++) { |
| | | count++; |
| | | } |
| | | // 相差天数等于配置表的数值时给高级别用户发钉钉信息 |
| | | if(Double.valueOf(count).equals(sysConfigProportion.getProportion())){ |
| | | if (Double.valueOf(count).equals(sysConfigProportion.getProportion())) { |
| | | weComService.sendNotice(weComList, "合同将到期提醒", String.format("<div class=\"normal\">所属员工:%s</div>" + |
| | | "<div class=\"normal\">合同名称:%s</div>" + |
| | | "<div class=\"normal\">合同到期时间:%s</div>" + |
| | | "<div class=\"highlight\">所属员工合同即将到期,请登录PMS系统查看。</div>", |
| | | user1.getNickName(), |
| | | sysUserContract.getContractName(), |
| | | sysUserContract.getContractEndTime().toString().substring(0,10)), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | "<div class=\"normal\">合同名称:%s</div>" + |
| | | "<div class=\"normal\">合同到期时间:%s</div>" + |
| | | "<div class=\"highlight\">所属员工合同即将到期,请登录PMS系统查看。</div>", |
| | | user1.getNickName(), |
| | | sysUserContract.getContractName(), |
| | | sysUserContract.getContractEndTime().toString().substring(0, 10)), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 合同季度统计推送 |
| | | public void contractQuarterlyReport() throws Exception { |
| | | contractService.contractQuarterlyReport(null); |
| | | } |
| | | } |