Commit 53d6e315b970abd185a54a32382b4b5ec2df849e

Authored by 房远帅
1 parent 6c5045b9

采购计划:采购吨超协汇总消息提醒供应管理科计划管理员

1 1 package com.lframework.xingyun.sc.procurement.controller.summary;
2 2
3 3 import com.lframework.starter.common.constants.StringPool;
  4 +import com.lframework.starter.common.utils.CollectionUtil;
4 5 import com.lframework.starter.web.core.annotations.security.HasPermission;
5 6 import com.lframework.starter.web.core.components.resp.InvokeResult;
6 7 import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
7 8 import com.lframework.starter.web.core.components.resp.PageResult;
8 9 import com.lframework.starter.web.core.controller.DefaultBaseController;
  10 +import com.lframework.starter.web.inner.service.system.SysUserRoleService;
9 11 import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryBo;
  12 +import com.lframework.xingyun.sc.handlers.MessageHandler;
10 13 import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary;
  14 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
11 15 import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryService;
12 16 import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo;
13 17 import io.swagger.annotations.Api;
14 18 import io.swagger.annotations.ApiImplicitParam;
15 19 import io.swagger.annotations.ApiOperation;
  20 +import java.time.LocalDate;
  21 +import java.time.format.DateTimeFormatter;
  22 +import java.util.Collections;
  23 +import java.util.List;
  24 +import java.util.Map;
  25 +import javax.annotation.Resource;
16 26 import javax.validation.Valid;
17 27 import javax.validation.constraints.NotBlank;
18 28 import lombok.extern.slf4j.Slf4j;
19   -import org.springframework.beans.factory.annotation.Autowired;
20 29 import org.springframework.format.annotation.DateTimeFormat;
21 30 import org.springframework.scheduling.annotation.Scheduled;
22 31 import org.springframework.validation.annotation.Validated;
23 32 import org.springframework.web.bind.annotation.GetMapping;
24   -import org.springframework.web.bind.annotation.PathVariable;
25 33 import org.springframework.web.bind.annotation.PostMapping;
26 34 import org.springframework.web.bind.annotation.RequestMapping;
27 35 import org.springframework.web.bind.annotation.RequestParam;
28 36 import org.springframework.web.bind.annotation.RestController;
29 37
30   -import java.time.LocalDate;
31   -
32 38 @Api(tags = "内贸计划明细汇总表管理")
33 39 @Slf4j
34 40 @Validated
... ... @@ -36,8 +42,14 @@ import java.time.LocalDate;
36 42 @RequestMapping("/procurement/plan/summary")
37 43 public class DomesticPlanSummaryController extends DefaultBaseController {
38 44
39   - @Autowired
  45 + @Resource
40 46 private DomesticPlanSummaryService domesticPlanSummaryService;
  47 + @Resource
  48 + private ProcurementPlanService procurementPlanService;
  49 + @Resource
  50 + private SysUserRoleService sysUserRoleService;
  51 + @Resource
  52 + private MessageHandler messageHandler;
41 53
42 54 @ApiOperation("分页查询内贸计划明细汇总表列表")
43 55 @HasPermission({"plan-manage:detail-form:query"})
... ... @@ -77,4 +89,37 @@ public class DomesticPlanSummaryController extends DefaultBaseController {
77 89 log.error("[内贸计划明细汇总表] 定时任务执行失败!", e);
78 90 }
79 91 }
  92 +
  93 + @Scheduled(cron = "0 0 0 * * ?")
  94 + @ApiOperation(hidden = true, value = "每天凌晨12点提醒供应管理科计划管理员:昨天创建的采购计划总数/完成数/流程中数")
  95 + public void scheduledNotifyYesterdayPlanAdmin() {
  96 + try {
  97 + log.info("[采购计划统计提醒] 定时任务开始执行 凌晨12点...");
  98 + LocalDate yesterday = LocalDate.now().minusDays(1);
  99 + Map<String, Long> stat = procurementPlanService.countCreatedPlansByDate(yesterday);
  100 + long total = stat.getOrDefault("totalCount", 0L);
  101 + long completed = stat.getOrDefault("completedCount", 0L);
  102 + long inProgress = stat.getOrDefault("inProgressCount", 0L);
  103 +
  104 + // 组装消息
  105 + String dateStr = yesterday.format(DateTimeFormatter.ofPattern(StringPool.DATE_PATTERN));
  106 + String title = String.format("%s 采购计划创建统计提醒", dateStr);
  107 + String content = String.format(
  108 + "【采购计划统计提醒】%s 创建的采购计划共 %d 单,流程已完成(COMPLETED) %d 单,流程中 %d 单。请相关计划管理员及时跟进处理!",
  109 + dateStr, total, completed, inProgress);
  110 + String bizKey = "PROCUREMENT_PLAN_STAT_" + dateStr;
  111 +
  112 + // 发送给供应管理科计划管理员
  113 + List<String> userIds = sysUserRoleService.listUserIdByRoleCodes(Collections.singletonList("gyglkjhgly"));
  114 + if (CollectionUtil.isEmpty(userIds)) {
  115 + log.warn("[采购计划统计提醒] 供应管理科计划管理员 下无用户,跳过消息发送!");
  116 + return;
  117 + }
  118 + messageHandler.sendMsg(userIds, title, content, bizKey, null);
  119 + log.info("[采购计划统计提醒] 消息发送完成 接收人{}个 总数{}完成{}流程中{}",
  120 + userIds.size(), total, completed, inProgress);
  121 + } catch (Exception e) {
  122 + log.error("[采购计划统计提醒] 定时任务执行失败!", e);
  123 + }
  124 + }
80 125 }
... ...
... ... @@ -791,4 +791,32 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
791 791 data.setShowExamine(hasTodo && CustomerDevelopStatus.AUDIT.name().equals(data.getApprovalStatus()));
792 792 }
793 793 }
  794 +
  795 + @Override
  796 + public Map<String, Long> countCreatedPlansByDate(LocalDate date) {
  797 + if (date == null) {
  798 + date = LocalDate.now();
  799 + }
  800 + LocalDateTime start = date.atStartOfDay();
  801 + LocalDateTime end = date.atTime(23, 59, 59);
  802 + // 1. 总数:create_time 在昨天范围 + deleted=0(非归档)
  803 + long totalCount = this.count(Wrappers.lambdaQuery(ProcurementPlan.class)
  804 + .ge(ProcurementPlan::getCreateTime, start)
  805 + .le(ProcurementPlan::getCreateTime, end)
  806 + .eq(ProcurementPlan::getFrozen, false)
  807 + .and(w -> w.isNull(ProcurementPlan::getDeleted).or().eq(ProcurementPlan::getDeleted, false)));
  808 + // 2. 已完成:流程 COMPLETED
  809 + long completedCount = this.count(Wrappers.lambdaQuery(ProcurementPlan.class)
  810 + .ge(ProcurementPlan::getCreateTime, start)
  811 + .le(ProcurementPlan::getCreateTime, end)
  812 + .eq(ProcurementPlan::getFrozen, false)
  813 + .and(w -> w.isNull(ProcurementPlan::getDeleted).or().eq(ProcurementPlan::getDeleted, false))
  814 + .eq(ProcurementPlan::getProcessStatus, "COMPLETED"));
  815 + long inProgressCount = Math.max(totalCount - completedCount, 0L);
  816 + Map<String, Long> result = new HashMap<>();
  817 + result.put("totalCount", totalCount);
  818 + result.put("completedCount", completedCount);
  819 + result.put("inProgressCount", inProgressCount);
  820 + return result;
  821 + }
794 822 }
... ...
... ... @@ -152,4 +152,13 @@ public interface ProcurementPlanService extends BaseMpService<ProcurementPlan> {
152 152 * @param id 采购计划ID(可以是主计划或子计划ID)
153 153 */
154 154 void abort(String id);
  155 +
  156 + /**
  157 + * 统计指定日期创建的采购计划数量(按天0点~23:59:59,deleted=0 非归档/删除 非冻结的)
  158 + * 返回 Map: totalCount=总数;completedCount=流程状态COMPLETED数;inProgressCount=流程中非COMPLETED数
  159 + *
  160 + * @param date
  161 + * @return
  162 + */
  163 + java.util.Map<String, Long> countCreatedPlansByDate(java.time.LocalDate date);
155 164 }
... ...