|
@@ -21,30 +21,41 @@ import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.copier.CopyOptions;
|
|
import cn.hutool.core.bean.copier.CopyOptions;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.excel.EasyExcelFactory;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.feign.RemoteScorePackageService;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.model.WmScorePackageSettleExcelModel;
|
|
|
|
+import com.qunzhixinxi.hnqz.common.core.constant.SecurityConstants;
|
|
|
|
+import com.qunzhixinxi.hnqz.daemon.quartz.config.LocalDateTimeConverter;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.constants.HnqzQuartzEnum;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.constants.HnqzQuartzEnum;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleAmountOverrunInSeveralMonths;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleAmountOverrunInSeveralMonths;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberWithoutSuchTaskTypesInSeveralMonths;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberWithoutSuchTaskTypesInSeveralMonths;
|
|
|
|
+import com.qunzhixinxi.hnqz.daemon.quartz.entity.SysDept;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmTask;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmTask;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberSettleAmountOverrunInSeveralMonthsMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberSettleAmountOverrunInSeveralMonthsMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberSettleSameAmountInSeveralMonthsMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberSettleSameAmountInSeveralMonthsMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberWithoutSuchTaskTypesInSeveralMonthsMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberWithoutSuchTaskTypesInSeveralMonthsMapper;
|
|
|
|
+import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SysDeptMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SysUserMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SysUserMapper;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.service.*;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.service.*;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.zhuqu.ZhuaquTest;
|
|
import com.qunzhixinxi.hnqz.daemon.quartz.zhuqu.ZhuaquTest;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.core.io.ByteArrayResource;
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.mail.MessagingException;
|
|
import javax.mail.MessagingException;
|
|
import javax.mail.internet.MimeMessage;
|
|
import javax.mail.internet.MimeMessage;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -53,8 +64,10 @@ import java.time.format.DateTimeFormatter;
|
|
import java.time.temporal.TemporalAdjusters;
|
|
import java.time.temporal.TemporalAdjusters;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.TreeMap;
|
|
import java.util.TreeMap;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
@@ -80,6 +93,8 @@ public class SpringBeanTaskDemo {
|
|
private final SingleMemberSettleAmountOverrunInSeveralMonthsMapper singleMemberSettleAmountOverrunInSeveralMonthsMapper;
|
|
private final SingleMemberSettleAmountOverrunInSeveralMonthsMapper singleMemberSettleAmountOverrunInSeveralMonthsMapper;
|
|
private final SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthMapper singleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthMapper;
|
|
private final SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthMapper singleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthMapper;
|
|
private final SingleMemberWithoutSuchTaskTypesInSeveralMonthsMapper singleMemberWithoutSuchTaskTypesInSeveralMonthsMapper;
|
|
private final SingleMemberWithoutSuchTaskTypesInSeveralMonthsMapper singleMemberWithoutSuchTaskTypesInSeveralMonthsMapper;
|
|
|
|
+ private final SysDeptMapper sysDeptMapper;
|
|
|
|
+ private final RemoteScorePackageService remoteScorePackageService;
|
|
|
|
|
|
// /**
|
|
// /**
|
|
// * 测试Spring Bean的演示方法
|
|
// * 测试Spring Bean的演示方法
|
|
@@ -437,4 +452,121 @@ public class SpringBeanTaskDemo {
|
|
|
|
|
|
return HnqzQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
|
|
return HnqzQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 每天发送当日结算数据给企业指定邮箱
|
|
|
|
+ *
|
|
|
|
+ * @param para 参数(格式为"2024-02-23,1611890565;1611890564")
|
|
|
|
+ * @return {@link String}
|
|
|
|
+ */
|
|
|
|
+ @SneakyThrows
|
|
|
|
+ public String sendCurrentDaySettleDataToDeptDaily(String para) {
|
|
|
|
+ // 校验参数
|
|
|
|
+ List<String> params = null;
|
|
|
|
+ if (StrUtil.isNotBlank(para) && !"1".equals(para)) {
|
|
|
|
+ if (!para.contains(StrUtil.COMMA)) {
|
|
|
|
+ log.error("参数错误");
|
|
|
|
+ return HnqzQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ params = StrUtil.split(para, StrUtil.COMMA);
|
|
|
|
+ if (params.size() != 2) {
|
|
|
|
+ log.error("参数错误2");
|
|
|
|
+ return HnqzQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 当前指定的日期
|
|
|
|
+ LocalDate currentDay = null;
|
|
|
|
+ LambdaQueryWrapper<SysDept> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ if (CollUtil.isNotEmpty(params)) {
|
|
|
|
+ // 指定的日期
|
|
|
|
+ currentDay = LocalDate.parse(params.get(0), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
+ // 指定的企业id
|
|
|
|
+ List<String> deptIds = StrUtil.split(params.get(1), ";");
|
|
|
|
+ queryWrapper.in(SysDept::getDeptId, deptIds);
|
|
|
|
+ } else {
|
|
|
|
+ // 默认取定期任务执行时的前一天日期
|
|
|
|
+ currentDay = LocalDate.now().minusDays(1L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LocalDateTime startOfDay = currentDay.atStartOfDay();
|
|
|
|
+ LocalDateTime endOfDay = startOfDay.plusDays(1L);
|
|
|
|
+
|
|
|
|
+ // 获取所有企业的信息
|
|
|
|
+ queryWrapper.eq(SysDept::getDelFlag, "0");
|
|
|
|
+ List<SysDept> depts = sysDeptMapper.selectList(queryWrapper);
|
|
|
|
+
|
|
|
|
+ LocalDate finalCurrentDay = currentDay;
|
|
|
|
+ depts.forEach(dept -> {
|
|
|
|
+ try {
|
|
|
|
+ if (ArrayUtil.isEmpty(dept.getEmails())) {
|
|
|
|
+ log.warn("{} 没有配置接收邮箱", dept.getName());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 本企业当日结算成功数据-发送邮件
|
|
|
|
+ MimeMessage mail = sender.createMimeMessage();
|
|
|
|
+ MimeMessageHelper helper = new MimeMessageHelper(mail, true);
|
|
|
|
+
|
|
|
|
+ helper.setFrom("yaoyi_report@yaoyi.net");
|
|
|
|
+ helper.setTo(dept.getEmails());
|
|
|
|
+
|
|
|
|
+ String title = "本企业结算成功数据(" + DateTimeFormatter.ofPattern("yyyy-MM-dd").format(finalCurrentDay) + ")";
|
|
|
|
+ helper.setSubject(title);
|
|
|
|
+
|
|
|
|
+ // 获取指定企业当日结算的数据
|
|
|
|
+ Map<String, Object> reqParams = new HashMap<>();
|
|
|
|
+ reqParams.put("sendPackageDeptId", dept.getDeptId());
|
|
|
|
+ reqParams.put("notifyTime", new LocalDateTime[]{startOfDay, endOfDay});
|
|
|
|
+ List<WmScorePackageSettleExcelModel> excelModels = remoteScorePackageService.exportPackageSettle(reqParams, SecurityConstants.FROM_IN);
|
|
|
|
+
|
|
|
|
+ if (CollUtil.isNotEmpty(excelModels)) {
|
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
+ EasyExcelFactory.write(byteArrayOutputStream, WmScorePackageSettleExcelModel.class)
|
|
|
|
+ .registerConverter(new LocalDateTimeConverter())
|
|
|
|
+ .autoCloseStream(false).sheet("本企业结算成功数据")
|
|
|
|
+ .doWrite(excelModels);
|
|
|
|
+ helper.addAttachment(title, new ByteArrayResource(byteArrayOutputStream.toByteArray()), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
+ helper.setText(String.format("当日结算成功%s条,详情数据见附件", excelModels.size()));
|
|
|
|
+
|
|
|
|
+ sender.send(mail);
|
|
|
|
+ log.info("{}本企业结算成功数据发送成功", dept.getDeptId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // MAH当日结算成功数据-发送邮件
|
|
|
|
+ MimeMessage mail2 = sender.createMimeMessage();
|
|
|
|
+ MimeMessageHelper helper2 = new MimeMessageHelper(mail2, true);
|
|
|
|
+
|
|
|
|
+ helper2.setFrom("yaoyi_report@yaoyi.net");
|
|
|
|
+ helper2.setTo(dept.getEmails());
|
|
|
|
+
|
|
|
|
+ String title2 = "MAH企业结算成功数据(" + DateTimeFormatter.ofPattern("yyyy-MM-dd").format(finalCurrentDay) + ")";
|
|
|
|
+ helper2.setSubject(title2);
|
|
|
|
+
|
|
|
|
+ // 获取指定企业当日结算的数据
|
|
|
|
+ Map<String, Object> reqParams2 = new HashMap<>();
|
|
|
|
+ reqParams2.put("mahSettleDeptId", dept.getDeptId());
|
|
|
|
+ reqParams2.put("notifyTime", new LocalDateTime[]{startOfDay, endOfDay});
|
|
|
|
+ List<WmScorePackageSettleExcelModel> excelModels2 = remoteScorePackageService.exportPackageSettleByMAH(reqParams2, SecurityConstants.FROM_IN);
|
|
|
|
+
|
|
|
|
+ if (CollUtil.isNotEmpty(excelModels2)) {
|
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
|
|
|
|
+ EasyExcelFactory.write(byteArrayOutputStream2, WmScorePackageSettleExcelModel.class)
|
|
|
|
+ .registerConverter(new LocalDateTimeConverter())
|
|
|
|
+ .autoCloseStream(false).sheet("MAH企业结算成功数据")
|
|
|
|
+ .doWrite(excelModels2);
|
|
|
|
+ helper2.addAttachment(title2, new ByteArrayResource(byteArrayOutputStream2.toByteArray()), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
+ helper2.setText(String.format("当日结算成功%s条,详情数据见附件", excelModels2.size()));
|
|
|
|
+
|
|
|
|
+ sender.send(mail2);
|
|
|
|
+ log.info("{}MAH企业结算成功数据发送成功", dept.getDeptId());
|
|
|
|
+ }
|
|
|
|
+ } catch (MessagingException ex) {
|
|
|
|
+ log.error("邮件发送失败", ex);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return HnqzQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
|
|
|
|
+ }
|
|
}
|
|
}
|