Commit 95f6e43c authored by fangxinjiang's avatar fangxinjiang

科目预警提醒-fxj

parent 55c2bd3d
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import java.util.Date;
/**
* 预警配置表
*
* @author fxj
* @date 2025-07-21 09:49:56
*/
@Data
@TableName("ekp_alert_table")
@Schema(description = "预警配置表")
public class EkpAlertTable {
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@ExcelProperty("主键")
@Schema(description = "主键")
private String fdId;
/**
* 预警科目ID
*/
@ExcelAttribute(name = "预警科目ID", maxLength = 1000)
@Length(max = 1000, message = "预警科目ID不能超过1000个字符")
@ExcelProperty("预警科目ID")
@Schema(description = "预警科目ID")
private String fdAlertSubject;
/**
* 预警科目
*/
@ExcelAttribute(name = "预警科目", maxLength = 1000)
@Length(max = 1000, message = "预警科目不能超过1000个字符")
@ExcelProperty("预警科目")
@Schema(description = "预警科目")
private String fdAlertSubjectText;
/**
* 有效日期始
*/
@ExcelAttribute(name = "有效日期始", isDate = true)
@ExcelProperty("有效日期始")
@Schema(description = "有效日期始")
private Date fdEffectiveStartDate;
/**
* 有效日期止
*/
@ExcelAttribute(name = "有效日期止", isDate = true)
@ExcelProperty("有效日期止")
@Schema(description = "有效日期止")
private Date fdEffectiveEndDate;
/**
* 检测方式
*/
@ExcelAttribute(name = "检测方式", maxLength = 200)
@Length(max = 200, message = "检测方式不能超过200个字符")
@ExcelProperty("检测方式")
@Schema(description = "检测方式")
private String fdDetectionMethod;
/**
* 阈值(%)
*/
@ExcelAttribute(name = "阈值")
@ExcelProperty("阈值")
@Schema(description = "阈值")
private Integer fdThresholdValue;
/**
* 是否有效:是 否
*/
@ExcelAttribute(name = "是否有效", maxLength = 200)
@Length(max = 200, message = "是否有效不能超过200个字符")
@ExcelProperty("是否有效")
@Schema(description = "是否有效")
private String fdIsActive;
/**
* 预警内容
*/
@ExcelAttribute(name = "预警内容")
@ExcelProperty("预警内容")
@Schema(description = "预警内容")
private String fdAlertMessage;
/**
* 检测方式-每日时间
*/
@ExcelAttribute(name = "检测方式-每日", isDate = true)
@ExcelProperty("检测方式-每日")
@Schema(description = "检测方式-每日")
private Date fdEverydayTime;
/**
* 检测方式-每月:每月时间(日)
*/
@ExcelAttribute(name = "检测方式", maxLength = 20)
@Length(max = 20, message = "检测方式不能超过20个字符")
@ExcelProperty("检测方式")
@Schema(description = "检测方式")
private String fdChecktype;
/**
* 检测方式-每月:1.每月 2.每日
*/
@ExcelAttribute(name = "检测方式-每月")
@ExcelProperty("检测方式-每月")
@Schema(description = "检测方式-每月")
private Integer fdMonthday;
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.util.Date;
/**
* EKP预算预警表
*
* @author fxj
* @date 2025-07-15 11:53:01
*/
@Data
@TableName("ekp_budget_warning_info")
@Schema(description = "EKP预算预警表")
public class EkpBudgetWarningInfo{
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@ExcelProperty("主键")
@Schema(description = "主键")
private String fdId;
/**
* 预警内容
*/
@ExcelAttribute(name = "预警内容", maxLength = 300)
@Length(max = 300, message = "预警内容不能超过300个字符")
@ExcelProperty("预警内容")
@Schema(description = "预警内容")
private String fdContent;
/**
* 预警时间
*/
@ExcelAttribute(name = "预警时间", isDate = true)
@ExcelProperty("预警时间")
@Schema(description = "预警时间")
private Date fdCreateTime;
/**
* 科目
*/
@ExcelAttribute(name = "科目", maxLength = 50)
@Length(max = 50, message = "科目不能超过50个字符")
@ExcelProperty("科目")
@Schema(description = "科目")
private String fdSubject;
/**
* 阅读状态:0未读 1已读
*/
@ExcelAttribute(name = "阅读状态:0未读 1已读", maxLength = 10)
@Length(max = 10, message = "阅读状态:0未读 1已读不能超过10个字符")
@ExcelProperty("阅读状态:0未读 1已读")
@Schema(description = "阅读状态:0未读 1已读")
private String fdReadStatus;
/**
* 接受人姓名
*/
@ExcelAttribute(name = "接受人姓名", maxLength = 50)
@Length(max = 50, message = "接受人姓名不能超过50个字符")
@ExcelProperty("接受人姓名")
@Schema(description = "接受人姓名")
private String fdRecipientName;
/**
* 接收人账号
*/
@ExcelAttribute(name = "接收人账号", maxLength = 50)
@Length(max = 50, message = "接收人账号不能超过50个字符")
@ExcelProperty("接收人账号")
@Schema(description = "接收人账号")
private String fdRecipientAccount;
/**
* 接收人ID(EKP-ID)
*/
@ExcelAttribute(name = "接收人ID(EKP-ID)", maxLength = 36)
@Length(max = 36, message = "接收人ID(EKP-ID)不能超过36个字符")
@ExcelProperty("接收人ID(EKP-ID)")
@Schema(description = "接收人ID(EKP-ID)")
private String fdRecipientId;
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import java.util.Date;
/**
* 预警配置表
*
* @author fxj
* @date 2025-07-21 09:49:56
*/
@Data
@Schema(description = "预警配置表")
public class BudgetWarningVo {
/**
* 科目
*/
@Schema(description = "科目")
private String km;
/**
* 提醒时间
*/
@Schema(description = "提醒时间")
private String at;
/**
* 余额
*/
@Schema(description = "余额")
private Double ye;
/**
* 比率
*/
@Schema(description = "比率")
private Double bl;
/**
* 二级成本中心
*/
@Schema(description = "二级成本中心")
private String cbzx;
/**
* 二级成本中心-提醒人
*/
@Schema(description = "二级成本中心-提醒人")
private String txr;
/**
* 阀值-剩余
*/
@Schema(description = "阀值-剩余")
private Integer fz;
}
package com.yifu.cloud.plus.v1.ekp.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.CheckedException;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @Author: huyc
* @Date: 2023/7/28
* @Description:
* @return: 企业微信配置
**/
@Configuration
@Data
@Slf4j
public class WxConfig {
@Value("${wx.corpid}")
private String corpid;
@Value("${wx.corpsecret}")
private String corpsecret;
@Value("${wx.agentid}")
private String agentid;
@Value("${wx.authUrl}")
private String authUrl;
@Value("${wx.domainName}")
private String domainName;
@Autowired
private RedisTemplate redisTemplate;
//未授权
private String accossTokenInvliad = "40014";
/**
* @param
* @Author: huyc
* @Date: 2023/7/28
* @Description: 获取微信accos_token
* @return: java.lang.String
**/
public String getAccessToken(RestTemplate restTemplate) {
if (Common.isNotNull(agentid)) {
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN.concat(agentid), corpsecret);
}
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN, corpsecret);
}
public String getAccessToken(RestTemplate restTemplate,String corpsecret)throws AuthenticationServiceException {
if(Common.isEmpty(corpsecret)){
throw new AuthenticationServiceException("未找到对应的corpsecret请联系管理员配置");
}
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN.concat(agentid), corpsecret);
}
/**
* @param restTemplate
* @param tokenKey
* @param corpsecretKey
* @Description: 获取token
* @Author: huyc
* @Date: 2023/7/28 14:46
* @return: java.lang.String
**/
public String getToken(RestTemplate restTemplate,String tokenKey, String corpsecretKey) {
Object wxToken = redisTemplate.opsForValue().get(tokenKey);
if (null != wxToken) {
return String.valueOf(wxToken);
}
String requestTokenUrl = String.format(SecurityConstants.WX_GET_ACCOSS_TOKEN, corpid, corpsecretKey);
String result = restTemplate.getForObject(requestTokenUrl, String.class);
if (Common.isEmpty(result)) {
throw new CheckedException("微信授权失败");
}
String token = JSON.parseObject(result).getString("access_token");
if (Common.isEmpty(token)) {
log.info(result);
throw new CheckedException("获取微信token失败");
}
redisTemplate.opsForValue().set(tokenKey, token);
redisTemplate.expire(tokenKey, 3600, TimeUnit.SECONDS);
return token;
}
/**
* @param
* @Author: huyc
* @Date: 2023/7/28 14:43
* @Description: 移除微信accossToken
* @return: java.lang.String
**/
public void removeAccessToken() {
redisTemplate.delete(CacheConstants.WX_ACCOSS_TOKEN);
}
/**
* @param restTemplate
* @param requestMap 请求内容
* @Author: huyc
* @Date: 2023/7/28 14:48
* @Description: 发送卡片消息
* @return: java.lang.String
**/
public boolean sendTextCard(RestTemplate restTemplate, Map<String, Object> requestMap) {
// 必须加上header说明
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
Gson gson = new Gson();
log.debug("发企业微信===请求:{}", gson.toJson(requestMap));
HttpEntity<String> requestEntity = new HttpEntity<>(gson.toJson(requestMap), headers);
String accessToken = getAccessToken(restTemplate);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(String.format(SecurityConstants.WX_SEND_MESSAGE, accessToken), requestEntity, String.class);
log.debug("发企业微信===返回:{}",JSON.toJSONString(responseEntity));
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(responseEntity));
JSONObject jsonBody = jsonObject.getJSONObject("body");
if (jsonBody != null) {
String errcode = jsonBody.getString("errcode");
if (accossTokenInvliad.equals(errcode)) {
//删除accossToken缓存
removeAccessToken();
return false;
}
if (!CommonConstants.ZERO_STRING.equals(errcode)) { //非正常,则打印错误日志
log.info(jsonObject.toJSONString());
}
} else {
log.info(jsonObject.toJSONString());
}
return true;
}
/**
* 功能描述: 获取微信accos_token
* @Author: huyc
* @Date: 2023/7/28 14:50
* @return: java.lang.String
*/
public String getAppAccessToken(RestTemplate restTemplate) {
return this.getToken(restTemplate, CacheConstants.WX_ACCOSS_TOKEN, corpsecret);
}
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.controller;
import com.yifu.cloud.plus.v1.ekp.service.EkpAlertTableService;
import com.yifu.cloud.plus.v1.ekp.vo.EkpIncomePushInfoVo;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpIncomeParamRisk;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 预警配置表
*
* @author fxj
* @date 2025-07-21 09:49:56
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/ekpalerttable")
@Tag(name = "预警配置表管理")
public class EkpAlertTableController {
private final EkpAlertTableService ekpAlertTableService;
/**
* @return
* @Author fxj
* @Description 定时任务推送 预算超额预警信息 按日推送
* @Date 10:03 2025/7/21
* @Param
**/
@Inner
@PostMapping("/inner/pushBudgetAlertInfoTomanager")
public void pushRiskInfoToEkp() {
ekpAlertTableService.pushBudgetAlertInfoTomanager(1);
}
/**
* @return
* @Author fxj
* @Description 定时任务推送 预算超额预警信息 按月推送
* @Date 10:03 2025/7/21
* @Param
**/
@Inner
@PostMapping("/inner/pushBudgetAlertInfoTomanagerMonth")
public void pushBudgetAlertInfoTomanagerMonth() {
ekpAlertTableService.pushBudgetAlertInfoTomanager(0);
}
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.ekp.entity.EkpAlertTable;
import com.yifu.cloud.plus.v1.ekp.vo.BudgetWarningVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 预警配置表
*
* @author fxj
* @date 2025-07-21 09:49:56
*/
@Mapper
public interface EkpAlertTableMapper extends BaseMapper<EkpAlertTable> {
/**
* 预警配置表简单分页查询
*
* @param ekpAlertTable 预警配置表
* @return
*/
IPage<EkpAlertTable> getEkpAlertTablePage(Page<EkpAlertTable> page, @Param("ekpAlertTable") EkpAlertTable ekpAlertTable);
List<BudgetWarningVo> getBudgetWarningVos(@Param("km") String km);
List<EkpAlertTable> getEkpAlertTableList(int type);
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.ekp.entity.EkpBudgetWarningInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* EKP预算预警表
*
* @author fxj
* @date 2025-07-15 11:53:01
*/
@Mapper
public interface EkpBudgetWarningInfoMapper extends BaseMapper<EkpBudgetWarningInfo> {
/**
* EKP预算预警表简单分页查询
*
* @param ekpBudgetWarningInfo EKP预算预警表
* @return
*/
IPage<EkpBudgetWarningInfo> getEkpBudgetWarningInfoPage(Page<EkpBudgetWarningInfo> page, @Param("ekpBudgetWarningInfo") EkpBudgetWarningInfo ekpBudgetWarningInfo);
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.ekp.entity.EkpAlertTable;
/**
* 预警配置表
*
* @author fxj
* @date 2025-07-21 09:49:56
*/
public interface EkpAlertTableService extends IService<EkpAlertTable> {
void pushBudgetAlertInfoTomanager(int type);
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.ekp.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.ekp.config.WxConfig;
import com.yifu.cloud.plus.v1.ekp.entity.EkpAlertTable;
import com.yifu.cloud.plus.v1.ekp.entity.EkpBudgetWarningInfo;
import com.yifu.cloud.plus.v1.ekp.mapper.EkpAlertTableMapper;
import com.yifu.cloud.plus.v1.ekp.mapper.EkpBudgetWarningInfoMapper;
import com.yifu.cloud.plus.v1.ekp.service.EkpAlertTableService;
import com.yifu.cloud.plus.v1.ekp.vo.BudgetWarningVo;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysUserListVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.SecurityConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.UpmsDaprUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* 预警配置表
*
* @author fxj
* @date 2025-07-21 09:49:56
*/
@Log4j2
@Service
public class EkpAlertTableServiceImpl extends ServiceImpl<EkpAlertTableMapper, EkpAlertTable> implements EkpAlertTableService {
@Autowired
private WxConfig wxConfig;
@Autowired
private UpmsDaprUtils upmsDaprUtils;
@Autowired
private EkpBudgetWarningInfoMapper warningInfoMapper;
/**
* @Author fxj
* @Description 推送企业微信消息
* @Date 15:29 2025/7/21
**/
private void pushInsuranceAlertToWx(List<BudgetWarningVo> vos) {
try {
if (Common.isNotKong(vos)){
// 科目+二级成本中心 作为key 创建预警信息map
Map<String, BudgetWarningVo> pushMap = new HashMap<>();
// 科目+二级成本中心 作为key 创建用户信息map
Map<String, List<SysUser>> sysUserMap = new HashMap<>();
// 遍历预警信息列表,按科目+二级成本中心初始化Map
for (BudgetWarningVo vo : vos) {
// 创建组合键
String key = vo.getKm() + "_" + vo.getCbzx();
// 将预警信息放入Map中
pushMap.put(key, vo);
sysUserMap = getMapInfo(vo);
}
//开始推送信息到企业微信
if (Common.isNotKong(pushMap) && Common.isNotKong(sysUserMap)){
List<SysUser> users;
BudgetWarningVo config;
String content;
for (Map.Entry<String, BudgetWarningVo> entry : pushMap.entrySet()){
users = sysUserMap.get(entry.getKey());
config = pushMap.get(entry.getKey());
if (Common.isNotKong(users) && Common.isNotKong(config)){
content = String.format("系统告警:%s 当前您所属的成本中心:%s下的%s预算余额当前剩余%s元,已不足%s%%,请关注预算使用情况,如有需要,可尽快追加预算。以免影响人员报销。",
config.getAt(),
config.getCbzx(),
config.getKm(),
config.getYe(),
config.getFz(),
config.getFz());
// 处理推送信息保存
hanlderWarning(users, config, content);
}
}
}
}
} catch (Exception e){
log.error("推送预算预警信息到企业微信异常",e);
}
}
private void hanlderWarning(List<SysUser> users, BudgetWarningVo config, String content) {
EkpBudgetWarningInfo warningInfo;
for (SysUser user : users){
sendMessageToWx(user.getWxMessage(), content);
warningInfo = new EkpBudgetWarningInfo();
warningInfo.setFdContent(content);
warningInfo.setFdReadStatus(CommonConstants.ZERO_STRING);
warningInfo.setFdCreateTime(new Date());
warningInfo.setFdSubject(config.getKm());
warningInfo.setFdRecipientName(user.getNickname());
warningInfo.setFdRecipientAccount(user.getUsername());
if (Common.isNotKong(config.getTxr())){
String[] temp = config.getTxr().split(",");
if (temp.length > 1){
for (String t : temp){
if (t.indexOf(user.getUsername()) >= 0 && t.split("_").length > 1){
warningInfo.setFdRecipientId(t.split("_")[1]);
break;
}
}
}
}
warningInfoMapper.insert(warningInfo);
}
}
/**
* @Author fxj
* @Description 初始化 账号对应的用户信息
* @Date 19:49 2025/4/23
**/
private Map<String, List<SysUser>> getMapInfo(BudgetWarningVo vo) {
Map<String, List<SysUser>> sysUserMap = new HashMap<>();
if (Common.isNotKong(vo) && Common.isNotKong(vo.getTxr())) {
if (vo.getTxr().length() > CommonConstants.ZERO_INT) {
R<SysUserListVo> res = upmsDaprUtils.getUserIdsByUserNames(getLoginNames(vo.getTxr()));
List<SysUser> users = null;
if (Common.isNotNull(res) && Common.isNotNull(res.getData()) && Common.isNotNull(res.getData().getUserList())) {
users = res.getData().getUserList();
}
if (Common.isNotKong(users)) {
sysUserMap.put(vo.getKm() + "_" +vo.getCbzx(), users);
}
}
}
return sysUserMap;
}
private String getLoginNames(String txr) {
//txr格式 loginName_id 获取到所有的loginName
if (Common.isEmpty(txr)) {
return txr;
}
return Arrays.stream(txr.split(","))
.map(part -> part.split("_")[0])
.filter(loginName -> !loginName.isEmpty())
.collect(Collectors.joining( ","));
}
//发送企业微信待办
private void sendMessageToWx(String useruserWx, String content) {
if (Common.isEmpty(useruserWx) || Common.isEmpty(content)) {
return;
}
StringBuilder sendUser = null;
if (Common.isNotKong(useruserWx)) {
sendUser = new StringBuilder(useruserWx);
}
if (sendUser != null) {
RestTemplate restTemplate = new RestTemplate();
Map<String, Object> requestMap = new HashMap<>();
Map<String, Object> textcard = new HashMap<>();
textcard.put("title", "预算预警");
// 传参77 企微详情提升“请至EKP系统处理!”
textcard.put("url", String.format(SecurityConstants.WX_GET_MESSAGE_AUTH_URL, wxConfig.getCorpid(), wxConfig.getDomainName() + "/auth/oauth/wxLogin", "77" ));
textcard.put("description", content.toString());
requestMap.put("touser", sendUser);
requestMap.put("agentid", wxConfig.getAgentid());
requestMap.put("msgtype", "textcard");
requestMap.put("textcard", textcard);
// 必须加上header说明
if (!wxConfig.sendTextCard(restTemplate, requestMap)) {
wxConfig.sendTextCard(restTemplate, requestMap);
}
}
}
/**
* @Author fxj
* @Description
* @Date 16:39 2025/7/21
* @Param type 0 按月 1 按日
* @return
**/
@Override
public void pushBudgetAlertInfoTomanager(int type) {
try {
// 1. 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 2. 查询所有有效的预警配置
List<EkpAlertTable> alertSubjects = baseMapper.getEkpAlertTableList(type);
// 3. 处理每个预警配置
List<BudgetWarningVo> budgetWarningVos = new ArrayList<>();
for (EkpAlertTable config : alertSubjects) {
// 4. 判断是否满足执行条件
if (shouldTriggerAlert(config,now,type)){
// 5. 获取实际数据并判断是否达到阈值,符合条件则返回预警信息
budgetWarningVos.addAll(isBudgetExceeded(config));
}
}
if (Common.isNotNull(budgetWarningVos)) {
// 6. 发送预警信息 + 记录预警信息
pushInsuranceAlertToWx(budgetWarningVos);
}
} catch (Exception e) {
log.error("执行预算预警任务时发生异常:", e);
}
}
/**
* @param config 预警配置
* @return 是否超额
*/
private List<BudgetWarningVo> isBudgetExceeded(EkpAlertTable config) {
List<BudgetWarningVo> resList = new ArrayList<>();
if (null == config || null == config.getFdThresholdValue() || null == config.getFdAlertSubjectText()) {
return resList;
}
//通过传参 科目获取需要预警的预算数据
List<BudgetWarningVo> list = baseMapper.getBudgetWarningVos(config.getFdAlertSubjectText());
if (Common.isNotKong(list)) {
for (BudgetWarningVo vo : list) {
//大于阀值且二级成本中心审核人不为空
if (vo.getBl() >= Double.valueOf(config.getFdThresholdValue()) && Common.isNotNull(vo.getTxr())) {
vo.setFz(100-(null==config.getFdThresholdValue()?0:config.getFdThresholdValue().intValue()));
resList.add(vo);
}
}
}
return resList;
}
/**
* 检查预警是否应该触发
*
* @param config 预警配置
* @param currentDateTime 当前时间
* @return 是否应该触发预警
*/
private boolean shouldTriggerAlert(EkpAlertTable config, LocalDateTime currentDateTime,int type) {
if (!"自动".equals(config.getFdDetectionMethod())){
return false;
}
if (type == 1){
// 处理按日配置
if ("每日".equals(config.getFdChecktype())) {
Date dailyTime = config.getFdEverydayTime(); // 获取每日执行时间
if (dailyTime != null) {
// 如果当前时间的小时 正好等于配置的时间的小时返回true
return currentDateTime.getHour() == dailyTime.getHours();
}
}
}{
// 处理按日配置
if ("每月".equals(config.getFdChecktype())) {
if (null != config.getFdMonthday()) {
// 当前日等于配置的日 返回 true
return currentDateTime.getDayOfMonth() == config.getFdMonthday().intValue();
}
}
}
return false;
}
}
...@@ -45,4 +45,11 @@ entry: ...@@ -45,4 +45,11 @@ entry:
entryFdFlowId: 191919ae533d0484bb60c5ed74e55a4b entryFdFlowId: 191919ae533d0484bb60c5ed74e55a4b
entryDocStatus: 20 entryDocStatus: 20
entryLoginName: admin entryLoginName: admin
entryDocSubject: 入账明细推送ekp接口 entryDocSubject: 入账明细推送ekp接口
\ No newline at end of file
wx:
corpid: wwbcb090af0dfe50e5
corpsecret: R0nKkvsY-oF41fuQvUXZ-kFG3_g_Ce0bpZt6mByx524
agentid: 1000009
authUrl: https://wx.worfu.com/yifu-auth/method/oauth/wxLogin
domainName: https://wx.worfu.com
\ No newline at end of file
...@@ -111,4 +111,11 @@ entry: ...@@ -111,4 +111,11 @@ entry:
entryFdFlowId: 191919ae533d080b60e6e784c55a3c8b entryFdFlowId: 191919ae533d080b60e6e784c55a3c8b
entryDocStatus: 20 entryDocStatus: 20
entryLoginName: admin entryLoginName: admin
entryDocSubject: 入账明细推送ekp接口 entryDocSubject: 入账明细推送ekp接口
\ No newline at end of file
wx:
corpid: wwbcb090af0dfe50e5
corpsecret: 16kqEL_eU-ARwYyqLgEBWHgxm8gXVnkzv_eJMLy9NpU
agentid: 1000010
authUrl: https://test-wx.worfu.com/yifu-auth/method/oauth/wxLogin
domainName: https://test-wx.worfu.com
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the yifu4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.ekp.mapper.EkpAlertTableMapper">
<resultMap id="budgetWarningMap" type="com.yifu.cloud.plus.v1.ekp.vo.BudgetWarningVo">
<id property="km" column="km"/>
<result property="at" column="at"/>
<result property="ye" column="ye"/>
<result property="bl" column="bl"/>
<result property="cbzx" column="cbzx"/>
<result property="txr" column="txr"/>
</resultMap>
<resultMap id="ekpAlertTableMap" type="com.yifu.cloud.plus.v1.ekp.entity.EkpAlertTable">
<id property="fdId" column="fd_id"/>
<result property="fdAlertSubject" column="fd_alert_subject"/>
<result property="fdAlertSubjectText" column="fd_alert_subject_text"/>
<result property="fdEffectiveStartDate" column="fd_effective_start_date"/>
<result property="fdEffectiveEndDate" column="fd_effective_end_date"/>
<result property="fdDetectionMethod" column="fd_detection_method"/>
<result property="fdThresholdValue" column="fd_threshold_value"/>
<result property="fdIsActive" column="fd_is_active"/>
<result property="fdAlertMessage" column="fd_alert_message"/>
<result property="fdEverydayTime" column="fd_everyday_time"/>
<result property="fdChecktype" column="fd_checktype"/>
<result property="fdMonthday" column="fd_monthday"/>
</resultMap>
<sql id="Base_Column_List">
a.fd_id,
a.fd_alert_subject,
a.fd_alert_subject_text,
a.fd_effective_start_date,
a.fd_effective_end_date,
a.fd_detection_method,
a.fd_threshold_value,
a.fd_is_active,
a.fd_alert_message,
a.fd_everyday_time,
a.fd_checktype,
a.fd_monthday
</sql>
<sql id="ekpAlertTable_where">
<if test="ekpAlertTable != null">
<if test="ekpAlertTable.fdId != null and ekpAlertTable.fdId.trim() != ''">
AND a.fd_id = #{ekpAlertTable.fdId}
</if>
<if test="ekpAlertTable.fdAlertSubject != null and ekpAlertTable.fdAlertSubject.trim() != ''">
AND a.fd_alert_subject = #{ekpAlertTable.fdAlertSubject}
</if>
<if test="ekpAlertTable.fdAlertSubjectText != null and ekpAlertTable.fdAlertSubjectText.trim() != ''">
AND a.fd_alert_subject_text = #{ekpAlertTable.fdAlertSubjectText}
</if>
<if test="ekpAlertTable.fdEffectiveStartDate != null">
AND a.fd_effective_start_date = #{ekpAlertTable.fdEffectiveStartDate}
</if>
<if test="ekpAlertTable.fdEffectiveEndDate != null">
AND a.fd_effective_end_date = #{ekpAlertTable.fdEffectiveEndDate}
</if>
<if test="ekpAlertTable.fdDetectionMethod != null and ekpAlertTable.fdDetectionMethod.trim() != ''">
AND a.fd_detection_method = #{ekpAlertTable.fdDetectionMethod}
</if>
<if test="ekpAlertTable.fdThresholdValue != null">
AND a.fd_threshold_value = #{ekpAlertTable.fdThresholdValue}
</if>
<if test="ekpAlertTable.fdIsActive != null and ekpAlertTable.fdIsActive.trim() != ''">
AND a.fd_is_active = #{ekpAlertTable.fdIsActive}
</if>
<if test="ekpAlertTable.fdAlertMessage != null and ekpAlertTable.fdAlertMessage.trim() != ''">
AND a.fd_alert_message = #{ekpAlertTable.fdAlertMessage}
</if>
<if test="ekpAlertTable.fdEverydayTime != null">
AND a.fd_everyday_time = #{ekpAlertTable.fdEverydayTime}
</if>
<if test="ekpAlertTable.fdChecktype != null and ekpAlertTable.fdChecktype.trim() != ''">
AND a.fd_checktype = #{ekpAlertTable.fdChecktype}
</if>
<if test="ekpAlertTable.fdMonthday != null">
AND a.fd_monthday = #{ekpAlertTable.fdMonthday}
</if>
</if>
</sql>
<!--ekpAlertTable简单分页查询-->
<select id="getEkpAlertTablePage" resultMap="ekpAlertTableMap">
SELECT
<include refid="Base_Column_List"/>
FROM ekp_alert_table a
<where>
1=1
<include refid="ekpAlertTable_where"/>
</where>
</select>
<select id="getBudgetWarningVos" resultMap="budgetWarningMap">
select
a.fd_ke_mu as 'km',
DATE_FORMAT(NOW(),"%Y-%m-%d %H:%i") as 'at',
ROUND((sum(a.fd_money) - sum(ifnull(b.fd_money,0))),2) as 'ye'
,ROUND(sum(ifnull(b.fd_money,0))/sum(a.fd_money)*100,2) as 'bl',
a.fd_cheng_ben_two as 'cbzx',c.txr
from (select sum(a.fd_money) fd_money,a.fd_cheng_ben_two,a.fd_ke_mu,a.fd_fee_type,a.fd_id from view_xing_zheng_yu_suan_all a where a.fd_date_month like concat(DATE_FORMAT(now(),'%Y-'),'%') GROUP BY a.fd_ke_mu,a.fd_cheng_ben_two) a
left join (
select
ifnull(sum(a.fd_money),0) fd_money,fd_ke_mu,fd_cheng_ben_two
from view_xing_zheng_yu_suan a where DATE_FORMAT(a.fd_date,'%Y') = DATE_FORMAT(now(),'%Y')
GROUP BY fd_ke_mu,fd_cheng_ben_two
) b on b.fd_ke_mu = a.fd_ke_mu and b.fd_cheng_ben_two = a.fd_cheng_ben_two
LEFT JOIN (
select GROUP_CONCAT(DISTINCT CONCAT(d.fd_login_name,"_",d.fd_id)) as 'txr',cb.fd_3c290891cded14 from ekp_3cf9b7112e544ba9fe18 cb
LEFT JOIN ekporg_18ca06406b8e5d35104b t on t.fd_parent_id=cb.fd_id
LEFT JOIN sys_org_person d on t.sys_org_person_id=d.fd_id
GROUP BY cb.fd_id
) c on c.fd_3c290891cded14 = a.fd_cheng_ben_two
where a.fd_ke_mu = #{km}
GROUP BY a.fd_ke_mu,a.fd_cheng_ben_two ORDER BY a.fd_id
</select>
<select id="getEkpAlertTableList" resultMap="ekpAlertTableMap">
SELECT
<include refid="Base_Column_List"/>
FROM ekp_alert_table a
<where>
1=1
AND a.fd_effective_start_date <![CDATA[ <= ]]> NOW()
AND a.fd_effective_end_date >= NOW()
AND a.fd_is_active = '是'
<if test="type ==0 ">
AND fd_checktype = '每月'
</if>
<if test="type ==1 ">
AND fd_checktype = '每日'
</if>
</where>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the yifu4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.ekp.mapper.EkpBudgetWarningInfoMapper">
<resultMap id="ekpBudgetWarningInfoMap" type="com.yifu.cloud.plus.v1.ekp.entity.EkpBudgetWarningInfo">
<id property="fdId" column="fd_id"/>
<result property="fdContent" column="fd_content"/>
<result property="fdCreateTime" column="fd_create_time"/>
<result property="fdSubject" column="fd_subject"/>
<result property="fdReadStatus" column="fd_read_status"/>
<result property="fdRecipientName" column="fd_recipient_name"/>
<result property="fdRecipientAccount" column="fd_recipient_account"/>
<result property="fdRecipientId" column="fd_recipient_id"/>
</resultMap>
<sql id="Base_Column_List">
a.fd_id,
a.fd_content,
a.fd_create_time,
a.fd_subject,
a.fd_read_status,
a.fd_recipient_name,
a.fd_recipient_account,
a.fd_recipient_id
</sql>
<sql id="ekpBudgetWarningInfo_where">
<if test="ekpBudgetWarningInfo != null">
<if test="ekpBudgetWarningInfo.fdId != null and ekpBudgetWarningInfo.fdId.trim() != ''">
AND a.fd_id = #{ekpBudgetWarningInfo.fdId}
</if>
<if test="ekpBudgetWarningInfo.fdContent != null and ekpBudgetWarningInfo.fdContent.trim() != ''">
AND a.fd_content = #{ekpBudgetWarningInfo.fdContent}
</if>
<if test="ekpBudgetWarningInfo.fdCreateTime != null">
AND a.fd_create_time = #{ekpBudgetWarningInfo.fdCreateTime}
</if>
<if test="ekpBudgetWarningInfo.fdSubject != null and ekpBudgetWarningInfo.fdSubject.trim() != ''">
AND a.fd_subject = #{ekpBudgetWarningInfo.fdSubject}
</if>
<if test="ekpBudgetWarningInfo.fdReadStatus != null and ekpBudgetWarningInfo.fdReadStatus.trim() != ''">
AND a.fd_read_status = #{ekpBudgetWarningInfo.fdReadStatus}
</if>
<if test="ekpBudgetWarningInfo.fdRecipientName != null and ekpBudgetWarningInfo.fdRecipientName.trim() != ''">
AND a.fd_recipient_name = #{ekpBudgetWarningInfo.fdRecipientName}
</if>
<if test="ekpBudgetWarningInfo.fdRecipientAccount != null and ekpBudgetWarningInfo.fdRecipientAccount.trim() != ''">
AND a.fd_recipient_account = #{ekpBudgetWarningInfo.fdRecipientAccount}
</if>
<if test="ekpBudgetWarningInfo.fdRecipientId != null and ekpBudgetWarningInfo.fdRecipientId.trim() != ''">
AND a.fd_recipient_id = #{ekpBudgetWarningInfo.fdRecipientId}
</if>
</if>
</sql>
<!--ekpBudgetWarningInfo简单分页查询-->
<select id="getEkpBudgetWarningInfoPage" resultMap="ekpBudgetWarningInfoMap">
SELECT
<include refid="Base_Column_List"/>
FROM ekp_budget_warning_info a
<where>
1=1
<include refid="ekpBudgetWarningInfo_where"/>
</where>
</select>
</mapper>
...@@ -72,4 +72,25 @@ public class EkpTask { ...@@ -72,4 +72,25 @@ public class EkpTask {
HttpDaprUtil.invokeMethodPost(daprEkpProperties.getAppUrl(),daprEkpProperties.getAppId(),"/icbcIssue/inner/getPdfFile","", Object.class, SecurityConstants.FROM_IN); HttpDaprUtil.invokeMethodPost(daprEkpProperties.getAppUrl(),daprEkpProperties.getAppId(),"/icbcIssue/inner/getPdfFile","", Object.class, SecurityConstants.FROM_IN);
log.info("------------定时生成生成昨日的回单文件-定时任务结束------------"); log.info("------------定时生成生成昨日的回单文件-定时任务结束------------");
} }
/**
* @Author fxj
* @Description 每日预算预警信息
* @Date 16:49 2025/7/21
**/
public void pushBudgetAlertInfoTomanager() {
log.info("------------定时生成每日预算预警信息-定时任务开始------------");
HttpDaprUtil.invokeMethodPost(daprEkpProperties.getAppUrl(),daprEkpProperties.getAppId(),"/ekpalerttable/inner/pushBudgetAlertInfoTomanager","", Object.class, SecurityConstants.FROM_IN);
log.info("------------定时生成生每日预算预警信息-定时任务结束------------");
}
/**
* @Author fxj
* @Description 每月预算预警信息
* @Date 16:49 2025/7/21
**/
public void pushBudgetAlertInfoTomanagerMonth() {
log.info("------------定时生成每月预算预警信息-定时任务开始------------");
HttpDaprUtil.invokeMethodPost(daprEkpProperties.getAppUrl(),daprEkpProperties.getAppId(),"/ekpalerttable/inner/pushBudgetAlertInfoTomanagerMonth","", Object.class, SecurityConstants.FROM_IN);
log.info("------------定时生成每月预算预警信息-定时任务结束------------");
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment