Commit 33f38c47 by 张富康

feat(perfSalary): 新增绩效评分企微通知功能

- 新增PerfQwNotificationJob定时任务,每天7点和19点触发绩效评分企微通知
- 新增PerfQwNotificationService实现具体通知逻辑
- 实现判断当前时间是否在绩效考核周期内,过滤非考核期发送
- 从数据库查询所有有未处理绩效的员工的上级领导手机号
- 调用企微接口发送文本卡片消息提醒相关领导及时处理绩效评分
- QWManager新增获取广联数科员工企微ID映射及拼接消息接收者功能
- PerformanceEvaluationMapper新增查询未处理绩效员工上级手机号的方法及映射xml配置
1 parent 2fcc9a38
package cn.com.glsx.dj.staff.job;
import cn.com.glsx.dj.staff.service.perfSalary.PerfQwNotificationService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource;
@Slf4j
@ElasticJobConf(name = "PerfQwNotificationJob", cron = "0 0 7,19 * * ? ", description = "绩效评分企微通知", overwrite = false)
public class PerfQwNotificationJob implements SimpleJob {
@Resource
private PerfQwNotificationService perfQwNotificationService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------绩效评分企微通知开始-----------------");
try {
perfQwNotificationService.perfQwNotification();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------绩效评分企微通知结束-----------------");
}
}
...@@ -33,4 +33,6 @@ public interface PerformanceEvaluationMapper extends OreMapper<PerformanceEvalua ...@@ -33,4 +33,6 @@ public interface PerformanceEvaluationMapper extends OreMapper<PerformanceEvalua
StaffMonthSalaryDTO queryStaffMonthSalary(@Param("evaluationMonth") String evaluationMonth, @Param("mobilePhone") String mobilePhone); StaffMonthSalaryDTO queryStaffMonthSalary(@Param("evaluationMonth") String evaluationMonth, @Param("mobilePhone") String mobilePhone);
List<String> querySuperiorLeaderMobilePhoneLeader(@Param("date") String date);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.service.common; package cn.com.glsx.dj.staff.service.common;
import cn.com.glsx.dj.staff.util.HttpUtil; import cn.com.glsx.dj.staff.util.HttpUtil;
import cn.com.glsx.entmicro.model.request.EntmicroStaffRequest;
import cn.com.glsx.entmicro.model.response.EntmicroStaffResponse;
import cn.com.glsx.entmicro.remote.EntmicroStaffRemote;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.request.SendWorkWechatMessageRequestDTO; import cn.com.glsx.scrm.wechat.dto.workwechat.message.request.SendWorkWechatMessageRequestDTO;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.response.SendWorkWechatMessageResponseDTO; import cn.com.glsx.scrm.wechat.dto.workwechat.message.response.SendWorkWechatMessageResponseDTO;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.oreframework.boot.env.OrePropertyConfigurer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
public class QWManager { public class QWManager {
...@@ -17,8 +28,10 @@ public class QWManager { ...@@ -17,8 +28,10 @@ public class QWManager {
@Autowired @Autowired
private Environment environment; private Environment environment;
public SendWorkWechatMessageResponseDTO sendMessage( @Resource
SendWorkWechatMessageRequestDTO sendWorkWechatMessageRequestDTO) { private EntmicroStaffRemote entmicroStaffRemote;
public SendWorkWechatMessageResponseDTO sendMessage(SendWorkWechatMessageRequestDTO sendWorkWechatMessageRequestDTO) {
log.info("发送企微应用消息:{}", JSON.toJSONString(sendWorkWechatMessageRequestDTO)); log.info("发送企微应用消息:{}", JSON.toJSONString(sendWorkWechatMessageRequestDTO));
SendWorkWechatMessageResponseDTO responseDTO=null; SendWorkWechatMessageResponseDTO responseDTO=null;
try { try {
...@@ -60,4 +73,41 @@ public class QWManager { ...@@ -60,4 +73,41 @@ public class QWManager {
} }
return userId; return userId;
} }
/**
* 获取全量广联数科员工企微
*/
public Map<String, String> getSendUserIds() {
EntmicroStaffRequest entmicroStaffRequest = new EntmicroStaffRequest();
// dev = 44209813 test = 44209813 线上 = 44202977
Integer merchantId = OrePropertyConfigurer.getProperty("dj.send.work.wechat.merchant.id",Integer.class,44202977);
entmicroStaffRequest.setMerchantId(merchantId);
RpcResponse<List<EntmicroStaffResponse>> staffResponse = entmicroStaffRemote.findStaffByMerchantId(entmicroStaffRequest);
if (staffResponse.hasResult()) {
List<EntmicroStaffResponse> result = staffResponse.getResult();
return result.stream().filter(item ->
StringUtils.isNotBlank(item.getStaffPhone()) && StringUtils.isNotBlank(item.getUserId()))
.collect(Collectors.toMap(EntmicroStaffResponse::getStaffPhone, EntmicroStaffResponse::getUserId, (a, b) -> a));
}
if (staffResponse.isFailed()) {
log.warn("获取发送员工失败,失败原因:{}", staffResponse.getException().getMessage());
}
return null;
}
public String getJoinedUserIds(Map<String, String> phoneToUserIdMap, List<String> phoneNumbers) {
StringBuilder userIds = new StringBuilder();
for (String phoneNumber : phoneNumbers) {
String userId = phoneToUserIdMap.get(phoneNumber);
if (userId != null) {
if (userIds.length() > 0) {
userIds.append("|");
}
userIds.append(userId);
}
}
return userIds.toString();
}
} }
package cn.com.glsx.dj.staff.service.perfSalary;
import cn.com.glsx.dj.staff.dto.performance.PerformanceTimeCycleDTO;
import cn.com.glsx.dj.staff.enums.PerformanceTimeCycleCodeEnum;
import cn.com.glsx.dj.staff.mapper.PerformanceTimeCycleMapper;
import cn.com.glsx.dj.staff.mapper.perfSalary.PerformanceEvaluationMapper;
import cn.com.glsx.dj.staff.service.common.QWManager;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.WorkWechatTextCardMessageDTO;
import cn.com.glsx.scrm.wechat.dto.workwechat.message.request.SendWorkWechatMessageRequestDTO;
import cn.com.glsx.scrm.wechat.enums.WorkWechatAppMessageTypeEnum;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.env.OrePropertyConfigurer;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class PerfQwNotificationService {
@Resource
private QWManager qWManager;
@Resource
private PerformanceTimeCycleMapper performanceTimeCycleMapper;
@Resource
private PerformanceEvaluationMapper performanceEvaluationMapper;
public void perfQwNotification() {
// 判断当前时间是否在T1范围内 如果不在则return
// 校验是否在修改的时间
PerformanceTimeCycleDTO performanceTimeCycleDTO = performanceTimeCycleMapper.selectByCode(PerformanceTimeCycleCodeEnum.T1.getCode());
Date startDate = performanceTimeCycleDTO.getStartDate();
Date endDate = performanceTimeCycleDTO.getEndDate();
Date now = DateUtil.date();
// 判断当前时间是否在考核时间范围内 当前时间需要大于等于开始时间,小于等于结束时间
boolean judgeTime = now.compareTo(startDate) < 0 || now.compareTo(endDate) > 0;
if (judgeTime) {
return;
}
// 获取所有未处理绩效的员工的上级领导手机号
// 上个月
DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1);
String lastMonth = DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN);
List<String> mobilePhoneList = performanceEvaluationMapper.querySuperiorLeaderMobilePhoneLeader(lastMonth);
if (CollUtil.isEmpty(mobilePhoneList)) {
log.info("没有未处理绩效的员工的上级领导手机号");
return;
}
Map<String, String> sendUserIds = qWManager.getSendUserIds();
String joinedUserIds = qWManager.getJoinedUserIds(sendUserIds, mobilePhoneList);
SendWorkWechatMessageRequestDTO requestDTO = new SendWorkWechatMessageRequestDTO();
// dev = 44209813 test = 44209813
// 线上 = 44202977
Integer merchantId = OrePropertyConfigurer.getProperty("dj.send.work.wechat.merchant.id", Integer.class, 44202977);
String title = OrePropertyConfigurer.getProperty("dj.send.work.wechat.perf.title", String.class, "驻店销售评绩效通知");
String btnTxt = OrePropertyConfigurer.getProperty("dj.send.work.wechat.btnTxt", String.class, "去处理");
String url = OrePropertyConfigurer.getProperty("dj.send.work.wechat.perf.url", String.class, "");
String descriptionEvn = OrePropertyConfigurer.getProperty("dj.send.work.wechat.perf.description", String.class,
"你好,本月的驻店销售评分开始了,请尽快去完成~\n" +
"1号凌晨1点,根据总部配置的自动评绩效规则,已出首轮续效哦,支持手工修改;\n" +
"亲,超过总部配置的每月{}号,就无法评绩效了哦;");
// 获取endDate的日期数
Integer dayDate = DateUtil.dayOfMonth(endDate);
requestDTO.setMerchantId(merchantId);
requestDTO.setToUser(joinedUserIds);
requestDTO.setMsgType(WorkWechatAppMessageTypeEnum.TEXTCARD.getValue());
String description = StrUtil.format(descriptionEvn, dayDate);
WorkWechatTextCardMessageDTO textCard = new WorkWechatTextCardMessageDTO();
textCard.setTitle(title);
textCard.setDescription(description);
textCard.setBtnTxt(btnTxt);
textCard.setUrl(url);
requestDTO.setTextCard(textCard);
try {
qWManager.sendMessage(requestDTO);
} catch (Exception e) {
log.error("发送企微应用消息异常:", e);
}
}
}
...@@ -506,4 +506,13 @@ ...@@ -506,4 +506,13 @@
</select> </select>
<select id="querySuperiorLeaderMobilePhoneLeader" resultType="java.lang.String">
select distinct(superior_leader_mobile_phone)
from sal_performance_evaluation
where deleted_flag = 'N'
and evaluation_month = #{date}
and handle_status = 0
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!