Commit c7843d83 authored by hongguangwu's avatar hongguangwu

MVP1.7.14-派单办理失败发企微-初次提交

parent c831c013
......@@ -99,7 +99,7 @@ public class UpmsDaprUtils {
}
/**
* @Author fxj
* @Description 通过用户ID 获取 在用的MVP系统的用户
* @Description 通过用户ID 获取 在用的MVP系统的用户
* @Date 17:24 2025/3/12
**/
public R<SysUsersVo> getUserVoByUserIds(String userIds) {
......@@ -109,6 +109,21 @@ public class UpmsDaprUtils {
}
return allUserVoR;
}
/**
* @Author hgw
* @Description 通过用户ID 获取 在用的MVP系统的用户
* @Date 2025-8-1 14:51:03
**/
public R<SysUsersVo> getInUseUserByIds(String userIds) {
R<SysUsersVo> allUserVoR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(),daprUpmsProperties.getAppId()
,"/user/inner/getInUseUserByIds", userIds, SysUsersVo.class, SecurityConstants.FROM_IN);
if (Common.isEmpty(allUserVoR)){
return R.failed("获取指定用户IDS对应在用的用户信息失败!");
}
return allUserVoR;
}
public R<SysUser> getSimpleUser(String userId) {
R<SysUser> userR = HttpDaprUtil.invokeMethodPost(daprUpmsProperties.getAppUrl(),daprUpmsProperties.getAppId(),"/user/inner/getSimpleUser",userId, SysUser.class, SecurityConstants.FROM_IN);
if (Common.isEmpty(userR)){
......
package com.yifu.cloud.plus.v1.yifu.social.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @description 派单办理失败发送企微消息
* @date 2025-8-1 11:22:43
*/
@Data
@Schema(description = "派单办理失败发送企微消息")
public class TSocialAlert {
@Schema(description = "客服ID")
private String createBy;
@Schema(description = "客服姓名")
private String createName;
@Schema(description = "社保条数")
private int socialNum;
@Schema(description = "公积金条数")
private int fundNum;
}
\ No newline at end of file
package com.yifu.cloud.plus.v1.yifu.social.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.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);
}
/**
* @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;
}
}
package com.yifu.cloud.plus.v1.yifu.social.controller;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import com.yifu.cloud.plus.v1.yifu.social.service.TSocialWarnService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @Author hgw
* @Date2025-8-1 11:19:32
* @Description 派单提醒相关
* @Version 1.0
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/socialWarn")
@Tag(name = "派单提醒相关")
public class TSocialWarnController {
@Resource
private TSocialWarnService socialWarnService;
@Operation(description = "每天10:00推送派单办理失败的消息")
@Inner
@PostMapping("/inner/pushSocialAlertToWx")
public void pushSocialAlertToWx() {
socialWarnService.pushSocialAlertToWx();
}
}
package com.yifu.cloud.plus.v1.yifu.social.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.yifu.social.vo.TSocialAlert;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @author hgw
* @description 查询派单失败的数据
* @date 2025-8-1 15:23:34
*/
@Mapper
public interface TSocialWarnMapper extends BaseMapper<TSocialAlert> {
/**
* @Description: 获取派单办理失败的信息
* @Author: hgw
* @Date: 2025/8/1 15:09
* @return: java.util.List<com.yifu.cloud.plus.v1.yifu.social.vo.TSocialAlert>
**/
List<TSocialAlert> getSocialAlertToWx();
}
package com.yifu.cloud.plus.v1.yifu.social.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.social.vo.TSocialAlert;
/**
* @author hgw
* @description 查询派单办理失败的信息,推送企微
* @date 2025-8-1 15:23:20
*/
public interface TSocialWarnService extends IService<TSocialAlert> {
void pushSocialAlertToWx();
}
package com.yifu.cloud.plus.v1.yifu.social.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysUsersVo;
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 com.yifu.cloud.plus.v1.yifu.social.config.WxConfig;
import com.yifu.cloud.plus.v1.yifu.social.mapper.TSocialWarnMapper;
import com.yifu.cloud.plus.v1.yifu.social.service.TSocialWarnService;
import com.yifu.cloud.plus.v1.yifu.social.vo.TSocialAlert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author hgw
* @description 派单办理失败的,推送企微
* @date 2025-8-1 15:23:16
*/
@Service
public class TSocialWarnServiceImpl extends ServiceImpl<TSocialWarnMapper, TSocialAlert> implements TSocialWarnService {
@Autowired
private UpmsDaprUtils upmsDaprUtils;
@Autowired
private WxConfig wxConfig;
/**
* @Description: 10点推送企微消息——派单办理失败
* @Author: hgw
* @Date: 2025/8/1 15:11
* @return: void
**/
@Override
public void pushSocialAlertToWx() {
try {
// TODO - 逻辑待产品梳理清楚,sql待完善
List<TSocialAlert> list = baseMapper.getSocialAlertToWx();
String userIds;
if (Common.isNotKong(list)) {
userIds = list.stream().map(TSocialAlert::getCreateBy).distinct().collect(Collectors.joining(","));
// 获取在用账号信息
Map<String, SysUser> inUseUserMap = this.getInUseUserByIds(userIds);
if (inUseUserMap != null && !inUseUserMap.isEmpty()) {
// 离职人员
StringBuilder liZhiUserName = new StringBuilder();
SysUser user;
Map<String, String> pushMap = new HashMap<>();
StringBuilder content;
for (TSocialAlert vo : list) {
user = inUseUserMap.get(vo.getCreateBy());
if (user == null || Common.isEmpty(user.getWxMessage())) {
if (Common.isNotNull(liZhiUserName)) {
liZhiUserName.append("、");
}
liZhiUserName.append(vo.getCreateName());
} else {
content = new StringBuilder("当前存在");
if (vo.getSocialNum() > 0) {
content.append("社保派单失败数量:").append(vo.getSocialNum());
if (vo.getFundNum() > 0) {
content.append(",公积金派单失败数量:").append(vo.getFundNum());
}
} else if (vo.getFundNum() > 0) {
content.append("公积金派单失败数量:").append(vo.getFundNum());
}
content.append("<br/>请及时至HRO系统进行处理。");
pushMap.put(user.getWxMessage(), content.toString());
}
}
// 离职的人,发给陈红:
if (Common.isNotNull(liZhiUserName)) {
// 陈红的 user.getWxMessage()
pushMap.put("66870fa57d72637233f81f1e0b26311e", "申请人" + liZhiUserName
+ "状态异常,当前存在社保派单失败、公积金派单失败。请及时至HRO系统进行处理。");
}
//开始推送信息到企业微信
if (Common.isNotKong(pushMap)) {
pushMap.forEach((k, v) -> {
sendMessageToWx(k, v);
});
}
}
}
} catch (Exception e) {
log.error("推送社保办理失败信息到企业微信异常", e);
}
}
/**
* @Description 获取在用账号信息
* @Date 2025-8-1 11:50:06
**/
private Map<String, SysUser> getInUseUserByIds(String userIds) {
Map<String, SysUser> userMap = null;
if (Common.isNotKong(userIds)) {
R<SysUsersVo> res = upmsDaprUtils.getInUseUserByIds(userIds);
if (Common.isNotNull(res) && Common.isNotNull(res.getData()) && Common.isNotNull(res.getData().getUserList())) {
userMap = res.getData().getUserList();
}
}
return userMap;
}
//发送企业微信待办
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", "派单办理失败提醒");
textcard.put("url", String.format(SecurityConstants.WX_GET_MESSAGE_AUTH_URL, wxConfig.getCorpid(), wxConfig.getDomainName() + "/auth/oauth/wxLogin", "66"));
textcard.put("description", content);
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);
}
}
}
}
\ No newline at end of file
......@@ -78,4 +78,12 @@ socialFriend:
appSecret : V52dkvxtFUgIvzlfNE9G8g==
#线上
#appKey : 3082B14EE2114C2D93B3A222DD925C26=
#appSecret : VmURqoxqmoKnNLXzAWynqQ==
\ No newline at end of file
#appSecret : VmURqoxqmoKnNLXzAWynqQ==
#企业微信配置
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
......@@ -67,4 +67,12 @@ socialFriend:
urlDownloadEmployeeFeedback: /gateway/pts/hrss/sourceFile/downloadEmployeeFeedback
urlUpload : /gateway/file/upload
appKey : 3082B14EE2114C2D93B3A222DD925C26=
appSecret : VmURqoxqmoKnNLXzAWynqQ==
\ No newline at end of file
appSecret : VmURqoxqmoKnNLXzAWynqQ==
#企业微信配置
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
......@@ -66,4 +66,12 @@ socialFriend:
urlDownloadEmployeeFeedback: /gateway/pts/hrss/sourceFile/downloadEmployeeFeedback
urlUpload : /gateway/file/upload
appKey : 89357285571962202409230949030
appSecret : V52dkvxtFUgIvzlfNE9G8g==
\ No newline at end of file
appSecret : V52dkvxtFUgIvzlfNE9G8g==
#企业微信配置
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"?>
<!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.yifu.social.mapper.TSocialWarnMapper">
<select id="getSocialAlertToWx" resultType="com.yifu.cloud.plus.v1.yifu.social.vo.TSocialAlert">
select
d.CREATE_BY createBy,d.CREATE_NAME createName
,sum(if(d.SOCIAL_HANDLE_STATUS in ('2','3'),1,0)) socialNum
,sum(if(d.FUND_HANDLE_STATUS = '2',1,0)) fundNum
from t_dispatch_info d
where d.CREATE_TIME >= CONCAT(DATE_SUB(CURDATE(), INTERVAL 1 DAY), ' 00:00:00')
and d.CREATE_TIME <![CDATA[ <= ]]> CONCAT(CURDATE(), ' 00:00:00')
and (d.SOCIAL_HANDLE_STATUS in ('2','3') or d.FUND_HANDLE_STATUS = '2')
GROUP BY d.CREATE_BY
</select>
</mapper>
......@@ -734,4 +734,28 @@ public class UserController {
}
return naVo;
}
/**
* @Author hgw
* @Description 获取所有在用的账号,key是userId
* @Date 2025-8-1 14:48:15
**/
@Inner
@PostMapping(value = {"/inner/getInUseUserByIds"})
public SysUsersVo getInUseUserByIds(@RequestBody String userIds) {
SysUsersVo naVo = new SysUsersVo();
if (Common.isNotNull(userIds)) {
//获取所有在用的账号
List<SysUser> sysUsers = userService.list(Wrappers.<SysUser>query().lambda()
.eq(SysUser::getLockFlag,CommonConstants.ZERO_STRING)
.eq(SysUser::getDelFlag,CommonConstants.ZERO_STRING)
.in(SysUser::getUserId, Common.getList(userIds)));
if (Common.isNotEmpty(sysUsers)) {
Map<String,SysUser> userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, v->v));
naVo.setUserList(userMap);
}
}
return naVo;
}
}
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