Ver Fonte

绩效辅导调度计划通知

彭佳杰 há 2 dias atrás
pai
commit
5bcd760a85

+ 26 - 11
code/opmc/nckd-jxccl-opmc/src/main/java/nckd/jxccl/opmc/pm/plugin/form/KpiTutorHeadFormPlugin.java

@@ -1,5 +1,6 @@
 package nckd.jxccl.opmc.pm.plugin.form;
 
+import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
 import kd.bos.entity.datamodel.events.PropertyChangedArgs;
 import kd.bos.form.control.Control;
@@ -10,9 +11,11 @@ import kd.bos.form.plugin.AbstractFormPlugin;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.org.OrgUnitServiceHelper;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 
+import java.util.Collections;
 import java.util.EventObject;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -28,25 +31,37 @@ public class KpiTutorHeadFormPlugin extends AbstractFormPlugin implements Before
     @Override
     public void registerListener(EventObject e) {
         super.registerListener(e);
-        BasedataEdit user = this.getView().getControl("nckd_user");
+        BasedataEdit user = this.getView().getControl("nckd_responsibleuser");
         user.addBeforeF7SelectListener(this);
+        BasedataEdit specialUser = this.getView().getControl("nckd_specialuser");
+        specialUser.addBeforeF7SelectListener(this);
+        BasedataEdit specialResponsible = this.getView().getControl("nckd_specialresponsible");
+        specialResponsible.addBeforeF7SelectListener(this);
     }
 
     @Override
     public void beforeF7Select(BeforeF7SelectEvent e) {
         String name = e.getProperty().getName();
-        if (StringUtils.equals(name, "nckd_user")) {
-            Object org = this.getModel().getValue("nckd_org");
-            if (ObjectUtils.isEmpty(org)) {
+        if (StringUtils.equalsAny(name, "nckd_responsibleuser", "nckd_specialuser", "nckd_specialresponsible")) {
+            Object orgValue = this.getModel().getValue("nckd_org");
+            if (ObjectUtils.isEmpty(orgValue)) {
                 e.setCancel(true);
                 this.getView().showTipNotification("请先选择绩效组织!");
-            } else {
-                QFilter qFilter = new QFilter("entryentity.ispartjob", QCP.equals, false);
-                qFilter.and("status", QCP.equals, "C");
-                qFilter.and("enable", QCP.equals, "1");
-                DynamicObjectCollection query = QueryServiceHelper.query("bos_user", "id,number,name", qFilter.toArray());
-                List<Long> userIds = query.stream().map(i -> i.getLong("id")).collect(Collectors.toList());
-                e.getCustomQFilters().add(new QFilter("id",QCP.in,userIds));
+                return;
+            }
+            DynamicObject org = (DynamicObject) orgValue;
+            List<Long> orgIds = OrgUnitServiceHelper.getAllSubordinateOrgs(1L, Collections.singletonList(org.getLong("id")), true);
+            QFilter qFilter = new QFilter("entryentity.ispartjob", QCP.equals, false);
+            qFilter.and("status", QCP.equals, "C");
+            qFilter.and("enable", QCP.equals, "1");
+            if (StringUtils.equals(name, "nckd_responsibleuser")) {
+                qFilter.and("entryentity.dpt", QCP.equals, org.getPkValue());
+                e.getCustomQFilters().add(qFilter);
+            } else if (StringUtils.equals(name, "nckd_specialuser")) {
+                qFilter.and("entryentity.dpt", QCP.in, orgIds);
+                e.getCustomQFilters().add(qFilter);
+            } else if (StringUtils.equals(name, "nckd_specialresponsible")) {
+
             }
         }
     }

+ 117 - 38
code/opmc/nckd-jxccl-opmc/src/main/java/nckd/jxccl/opmc/pm/task/NoticeKpiUnqualifiedTask.java

@@ -12,7 +12,9 @@ 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.user.UserServiceHelper;
 import kd.bos.servicehelper.workflow.MessageCenterServiceHelper;
+import kd.bos.url.UrlService;
 import kd.bos.workflow.engine.msg.info.MessageInfo;
 import nckd.jxccl.opmc.pm.helper.KpiImportUtils;
 import org.apache.commons.lang3.ObjectUtils;
@@ -42,80 +44,157 @@ public class NoticeKpiUnqualifiedTask extends AbstractTask {
         List<DynamicObject> yearUnqualifiedUser = KpiImportUtils.yearUnqualifiedUser();
         //查询连续三个月绩效考核 不合格 人员
         List<DynamicObject> monthUnqualifiedUser = KpiImportUtils.monthUnqualifiedUser();
+        //查询所有绩效辅导组织负责人
+        DynamicObject[] tutor_head = BusinessDataServiceHelper.load("nckd_kpi_tutor_head", "nckd_entryentity.nckd_specialuser,nckd_entryentity.nckd_specialresponsible,nckd_responsibleuser,nckd_org", null);
+        //特殊负责人管辖的员工
+        Map<Long, DynamicObject> head_specialUsers = Arrays.stream(tutor_head).flatMap(i -> i.getDynamicObjectCollection("nckd_entryentity").stream()).
+                collect(Collectors.toMap(i -> i.getLong("nckd_specialuser.id"), i -> i, (existing, replacement) -> existing));
+        //特殊员工
+        List<Long> specialUsers = Arrays.stream(tutor_head).flatMap(i -> i.getDynamicObjectCollection("nckd_entryentity").stream()).map(i -> i.getLong("nckd_specialuser.id")).collect(Collectors.toList());
         //根据部门汇总人员数据
         HashMap<Long, List<DynamicObject>> org_userMap = new HashMap<>();
+        HashMap<Long, List<DynamicObject>> special_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");
+            //判断特殊员工
+            long userId = user.getLong("id");
+            if (specialUsers.contains(userId)) {
+                //特殊负责人
+                Long headId = head_specialUsers.get(userId).getLong("id");
+                List<DynamicObject> specialUsersList = special_userMap.get(headId);
+                if (ObjectUtils.isEmpty(specialUsersList)) {
+                    ArrayList<DynamicObject> list = new ArrayList<>();
+                    list.add(user);
+                    special_userMap.put(headId, list);
+                } else {
+                    specialUsersList.add(user);
+                }
+            } else {
+                //正常员工
+                //过滤主任职
+                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);
+                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")});
+                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<>();
+        //未找到对应负责人的组织
+        List<Long> unFindOrg = 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));
+            DynamicObject user = findUser(org_head, orgParent, curOrgId, unFindOrg);
+            if (ObjectUtils.isNotEmpty(user)) {
+                buildMessage(messageInfos, user, org_userMap.get(curOrgId),tutor_head[0].getLong("id"));
             }
-
+        }
+        //特殊员工
+        for (Long headId : special_userMap.keySet()) {
+            buildMessage(messageInfos, headId, special_userMap.get(headId),tutor_head[0].getLong("id"));
         }
 
         Map<String, Object> stringObjectMap = MessageCenterServiceHelper.batchSendMessages(messageInfos);
+        if( ObjectUtils.isNotEmpty(unFindOrg) ){
+            sendSettingMsg(tutor_head[0].getLong("id"));
+        }
         logger.info("员工绩效不合格消息提醒发送结果" + stringObjectMap.get("success") + "返回结果" + stringObjectMap.get("description"));
 
     }
 
-    private void buildMessage(List<MessageInfo> messageInfos, DynamicObject user, List<DynamicObject> dynamicObjects) {
+    private void sendSettingMsg(Long id) {
+        MessageInfo messageInfo = new MessageInfo();
+        messageInfo.setMessageTitle(new LocaleString("未配置消息"));
+        messageInfo.setMessageContent(new LocaleString("未配置消息"));
+        messageInfo.setType(MessageInfo.TYPE_ALARM);
+        messageInfo.setEntityNumber("nckd_kpi_tutor_head");
+        messageInfo.setBizDataId(id);
+        messageInfo.setTag("员工绩效");
+        messageInfo.setUserIds(Collections.singletonList(UserServiceHelper.getCurrentUserId()));
+        messageInfo.setSenderId(UserServiceHelper.getCurrentUserId());
+        Map<String, Object> stringObjectMap = MessageCenterServiceHelper.batchSendMessages(Collections.singletonList(messageInfo));
+        logger.info("未配置消息" + stringObjectMap.get("success") + "返回结果" + stringObjectMap.get("description"));
+    }
+
+    private DynamicObject findUser(Map<Long, DynamicObject> org_head, Map<Long, Long> orgParent, Long curOrgId, List<Long> unFindOrg) {
+        //员工对应组织先找负责人
+        DynamicObject userHead = org_head.get(curOrgId);
+        if (ObjectUtils.isEmpty(userHead)) {
+            Long org_parent = orgParent.get(curOrgId);
+            if (org_parent == null) {
+                unFindOrg.add(curOrgId);
+                return null;
+            } else {
+                DynamicObject user = findUser(org_head, orgParent, org_parent, unFindOrg);
+                return user;
+            }
+        } else {
+            return userHead;
+        }
+    }
+
+    private void buildMessage(List<MessageInfo> messageInfos, DynamicObject user, List<DynamicObject> dynamicObjects,Long id) {
         // 构建 消息
         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.setEntityNumber("nckd_kpi_tutor_head");
+        // 设置 业务单据ID
+        messageInfo.setBizDataId(id);
         // 设置 标签
         messageInfo.setTag("员工绩效");
+//        long managerBoId = entryDyo.getDynamicObject(SanDingConstant.NCKD_MANAGER_KEY).getLong(SanDingConstant.BOID_KEY);
         // 设置 消息接收人
         messageInfo.setUserIds(Collections.singletonList(user.getLong("id")));
+        // 设置 消息Web端url
+//        messageInfo.setContentUrl(UrlService.getDomainContextUrl() + "/index.html?formId=" + SanDingConstant.NCKD_SANDINGTASK_ENTITY + "&pkId=" + SANDING_TASK_MAP.get(entryDyo.getLong(SanDingConstant.ID_KEY)));
+        // 设置发送人
+        messageInfo.setSenderId(UserServiceHelper.getCurrentUserId());
+        messageInfos.add(messageInfo);
+    }
+
+    private void buildMessage(List<MessageInfo> messageInfos, Long headId, List<DynamicObject> dynamicObjects,Long id) {
+        // 构建 消息
+        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.setEntityNumber("nckd_kpi_tutor_head");
+        messageInfo.setBizDataId(id);
+
+        // 设置 标签
+        messageInfo.setTag("员工绩效");
+        // 设置 消息接收人
+        messageInfo.setUserIds(Collections.singletonList(headId));
+        // 设置发送人
+        messageInfo.setSenderId(UserServiceHelper.getCurrentUserId());
         messageInfos.add(messageInfo);
     }