|
@@ -0,0 +1,122 @@
|
|
|
|
|
+package nckd.jxccl.opmc.pm.task;
|
|
|
|
|
+
|
|
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
|
+import kd.bos.dataentity.entity.LocaleString;
|
|
|
|
|
+import kd.bos.exception.KDException;
|
|
|
|
|
+import kd.bos.logging.Log;
|
|
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
|
+import kd.bos.schedule.executor.AbstractTask;
|
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
|
+import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
|
|
+import kd.bos.servicehelper.workflow.MessageCenterServiceHelper;
|
|
|
|
|
+import kd.bos.workflow.engine.msg.info.MessageInfo;
|
|
|
|
|
+import nckd.jxccl.opmc.pm.helper.KpiImportUtils;
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @ClassName: NoticeKpiUnqualifiedTask
|
|
|
|
|
+ * @Description: 定时推送绩效导入结果不合格人员
|
|
|
|
|
+ * @Author: PJJ
|
|
|
|
|
+ * @Date: 2026/1/14 上午9:39
|
|
|
|
|
+ * @Version: 1.0
|
|
|
|
|
+ */
|
|
|
|
|
+public class NoticeKpiUnqualifiedTask extends AbstractTask {
|
|
|
|
|
+ private static final Log logger = LogFactory.getLog(NoticeKpiUnqualifiedTask.class);
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
|
|
|
+ //去年年度绩效不合格用户
|
|
|
|
|
+ List<DynamicObject> yearUnqualifiedUser = KpiImportUtils.yearUnqualifiedUser();
|
|
|
|
|
+ //查询连续三个月绩效考核 不合格 人员
|
|
|
|
|
+ List<DynamicObject> monthUnqualifiedUser = KpiImportUtils.monthUnqualifiedUser();
|
|
|
|
|
+ //根据部门汇总人员数据
|
|
|
|
|
+ HashMap<Long, List<DynamicObject>> org_userMap = new HashMap<>();
|
|
|
|
|
+ yearUnqualifiedUser.addAll(monthUnqualifiedUser);
|
|
|
|
|
+ for (DynamicObject user : yearUnqualifiedUser) {
|
|
|
|
|
+ //过滤主任职
|
|
|
|
|
+ DynamicObjectCollection entry = user.getDynamicObjectCollection("entryentity");
|
|
|
|
|
+ List<DynamicObject> collect = entry.stream().filter(i -> !i.getBoolean("ispartjob")).collect(Collectors.toList());
|
|
|
|
|
+ Long orgId = collect.get(0).getLong("dpt.id");
|
|
|
|
|
+
|
|
|
|
|
+ List<DynamicObject> users = org_userMap.get(orgId);
|
|
|
|
|
+ if(ObjectUtils.isEmpty(users)){
|
|
|
|
|
+ ArrayList<DynamicObject> objects = new ArrayList<>();
|
|
|
|
|
+ objects.add(user);
|
|
|
|
|
+ org_userMap.put(orgId, objects);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ users.add(user);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ //查询所有绩效辅导组织负责人
|
|
|
|
|
+ DynamicObject[] tutor_head = BusinessDataServiceHelper.load("nckd_kpi_tutor_head", "nckd_user,nckd_org", null);
|
|
|
|
|
+ Map<Long, DynamicObject> org_head = Arrays.stream(tutor_head).collect(Collectors.toMap(i -> i.getLong("nckd_org.id"), i -> i));
|
|
|
|
|
+ //查询组织架构表
|
|
|
|
|
+ DynamicObjectCollection structure = QueryServiceHelper.query("bos_org_structure", "parent.id,org.id",
|
|
|
|
|
+ new QFilter[]{new QFilter("view.number", QCP.equals,"01").and("status",QCP.equals,"C").and("enable",QCP.equals,"1")});
|
|
|
|
|
+ //组织和上级组织map
|
|
|
|
|
+ Map<Long, Long> orgParent = structure.stream().collect(Collectors.toMap(i -> i.getLong("org.id"), i -> i.getLong("parent.id")));
|
|
|
|
|
+ //发送消息
|
|
|
|
|
+ List<MessageInfo> messageInfos = new ArrayList<>();
|
|
|
|
|
+ for (Long curOrgId : org_userMap.keySet()) {
|
|
|
|
|
+ //员工对应组织先找负责人
|
|
|
|
|
+ DynamicObject userHead = org_head.get(curOrgId);
|
|
|
|
|
+ //找不到往上找一级
|
|
|
|
|
+ if ( ObjectUtils.isEmpty(userHead) ) {
|
|
|
|
|
+ Long org_parent = orgParent.get(curOrgId);
|
|
|
|
|
+ DynamicObject userHead_parent = org_head.get(org_parent);
|
|
|
|
|
+ //为空再找一级
|
|
|
|
|
+ if( ObjectUtils.isEmpty(userHead_parent) ){
|
|
|
|
|
+ Long org_grandParent = orgParent.get(org_parent);
|
|
|
|
|
+ DynamicObject userHead_grandParent = org_head.get(org_grandParent);
|
|
|
|
|
+ if( ObjectUtils.isEmpty(userHead_grandParent) ){
|
|
|
|
|
+ logger.info("当前组织id" + curOrgId + "往上两级也未找到对应负责人");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ buildMessage(messageInfos,userHead_grandParent,org_userMap.get(curOrgId));
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ buildMessage(messageInfos,userHead_parent,org_userMap.get(curOrgId));
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ buildMessage(messageInfos,userHead,org_userMap.get(curOrgId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> stringObjectMap = MessageCenterServiceHelper.batchSendMessages(messageInfos);
|
|
|
|
|
+ logger.info("员工绩效不合格消息提醒发送结果" + stringObjectMap.get("success") + "返回结果" + stringObjectMap.get("description"));
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void buildMessage(List<MessageInfo> messageInfos, DynamicObject user, List<DynamicObject> dynamicObjects) {
|
|
|
|
|
+ // 构建 消息
|
|
|
|
|
+ MessageInfo messageInfo = new MessageInfo();
|
|
|
|
|
+ // 设置 消息标题
|
|
|
|
|
+ messageInfo.setMessageTitle(new LocaleString("员工绩效评估不合格提醒"));
|
|
|
|
|
+ // 设置 文本消息内容
|
|
|
|
|
+ Set<String> collect = dynamicObjects.stream().map(i -> i.getLocaleString("name").getLocaleValue_zh_CN() + ":" + i.getString("number")).collect(Collectors.toSet());
|
|
|
|
|
+// String.format("",collect);
|
|
|
|
|
+ messageInfo.setMessageContent(new LocaleString(collect.toString()));
|
|
|
|
|
+ // 设置 消息类型
|
|
|
|
|
+ messageInfo.setType(MessageInfo.TYPE_TASK);
|
|
|
|
|
+ // 设置 标签
|
|
|
|
|
+ messageInfo.setTag("员工绩效");
|
|
|
|
|
+ // 设置 消息接收人
|
|
|
|
|
+ messageInfo.setUserIds(Collections.singletonList(user.getLong("id")));
|
|
|
|
|
+ messageInfos.add(messageInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|