Commit 53d6e315b970abd185a54a32382b4b5ec2df849e

Authored by 房远帅
1 parent 6c5045b9

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

1 package com.lframework.xingyun.sc.procurement.controller.summary; 1 package com.lframework.xingyun.sc.procurement.controller.summary;
2 2
3 import com.lframework.starter.common.constants.StringPool; 3 import com.lframework.starter.common.constants.StringPool;
  4 +import com.lframework.starter.common.utils.CollectionUtil;
4 import com.lframework.starter.web.core.annotations.security.HasPermission; 5 import com.lframework.starter.web.core.annotations.security.HasPermission;
5 import com.lframework.starter.web.core.components.resp.InvokeResult; 6 import com.lframework.starter.web.core.components.resp.InvokeResult;
6 import com.lframework.starter.web.core.components.resp.InvokeResultBuilder; 7 import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
7 import com.lframework.starter.web.core.components.resp.PageResult; 8 import com.lframework.starter.web.core.components.resp.PageResult;
8 import com.lframework.starter.web.core.controller.DefaultBaseController; 9 import com.lframework.starter.web.core.controller.DefaultBaseController;
  10 +import com.lframework.starter.web.inner.service.system.SysUserRoleService;
9 import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryBo; 11 import com.lframework.xingyun.sc.bo.procurement.GetDomesticPlanSummaryBo;
  12 +import com.lframework.xingyun.sc.handlers.MessageHandler;
10 import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary; 13 import com.lframework.xingyun.sc.procurement.entity.summary.DomesticPlanSummary;
  14 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
11 import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryService; 15 import com.lframework.xingyun.sc.procurement.service.summary.DomesticPlanSummaryService;
12 import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo; 16 import com.lframework.xingyun.sc.procurement.vo.summary.QueryDomesticPlanSummaryVo;
13 import io.swagger.annotations.Api; 17 import io.swagger.annotations.Api;
14 import io.swagger.annotations.ApiImplicitParam; 18 import io.swagger.annotations.ApiImplicitParam;
15 import io.swagger.annotations.ApiOperation; 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 import javax.validation.Valid; 26 import javax.validation.Valid;
17 import javax.validation.constraints.NotBlank; 27 import javax.validation.constraints.NotBlank;
18 import lombok.extern.slf4j.Slf4j; 28 import lombok.extern.slf4j.Slf4j;
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 import org.springframework.format.annotation.DateTimeFormat; 29 import org.springframework.format.annotation.DateTimeFormat;
21 import org.springframework.scheduling.annotation.Scheduled; 30 import org.springframework.scheduling.annotation.Scheduled;
22 import org.springframework.validation.annotation.Validated; 31 import org.springframework.validation.annotation.Validated;
23 import org.springframework.web.bind.annotation.GetMapping; 32 import org.springframework.web.bind.annotation.GetMapping;
24 -import org.springframework.web.bind.annotation.PathVariable;  
25 import org.springframework.web.bind.annotation.PostMapping; 33 import org.springframework.web.bind.annotation.PostMapping;
26 import org.springframework.web.bind.annotation.RequestMapping; 34 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestParam; 35 import org.springframework.web.bind.annotation.RequestParam;
28 import org.springframework.web.bind.annotation.RestController; 36 import org.springframework.web.bind.annotation.RestController;
29 37
30 -import java.time.LocalDate;  
31 -  
32 @Api(tags = "内贸计划明细汇总表管理") 38 @Api(tags = "内贸计划明细汇总表管理")
33 @Slf4j 39 @Slf4j
34 @Validated 40 @Validated
@@ -36,8 +42,14 @@ import java.time.LocalDate; @@ -36,8 +42,14 @@ import java.time.LocalDate;
36 @RequestMapping("/procurement/plan/summary") 42 @RequestMapping("/procurement/plan/summary")
37 public class DomesticPlanSummaryController extends DefaultBaseController { 43 public class DomesticPlanSummaryController extends DefaultBaseController {
38 44
39 - @Autowired 45 + @Resource
40 private DomesticPlanSummaryService domesticPlanSummaryService; 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 @ApiOperation("分页查询内贸计划明细汇总表列表") 54 @ApiOperation("分页查询内贸计划明细汇总表列表")
43 @HasPermission({"plan-manage:detail-form:query"}) 55 @HasPermission({"plan-manage:detail-form:query"})
@@ -77,4 +89,37 @@ public class DomesticPlanSummaryController extends DefaultBaseController { @@ -77,4 +89,37 @@ public class DomesticPlanSummaryController extends DefaultBaseController {
77 log.error("[内贸计划明细汇总表] 定时任务执行失败!", e); 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,4 +791,32 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
791 data.setShowExamine(hasTodo && CustomerDevelopStatus.AUDIT.name().equals(data.getApprovalStatus())); 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,4 +152,13 @@ public interface ProcurementPlanService extends BaseMpService<ProcurementPlan> {
152 * @param id 采购计划ID(可以是主计划或子计划ID) 152 * @param id 采购计划ID(可以是主计划或子计划ID)
153 */ 153 */
154 void abort(String id); 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 }