Browse Source

考勤异常提醒代码更新

Heyuan 1 month ago
parent
commit
f2a954a349

+ 15 - 3
sql/CreateTable.sql

@@ -6,10 +6,22 @@ Create Table CT_LOG_SyncLog ( FCreatorID VARCHAR(44),FCreateTime DateTime,FLastU
 If not exists (select 1 from KSQL_USERTABLES where KSQL_TABNAME='CT_PER_InterviewRecord')
 Create Table CT_PER_InterviewRecord ( FCreatorID VARCHAR(44),FCreateTime DateTime,FLastUpdateUserID VARCHAR(44),FLastUpdateTime DateTime,FControlUnitID VARCHAR(44),FNumber NVARCHAR(80),FBizDate DateTime,FHandlerID VARCHAR(44),FDescription NVARCHAR(80),FHasEffected INT,FAuditorID VARCHAR(44),FSourceBillID NVARCHAR(80),FSourceFunction NVARCHAR(80),FID VARCHAR(44) DEFAULT '' NOT NULL ,CFInterviewTime DateTime,CFInterviewResult NCLOB(2000),CFInterviewerID VARCHAR(44),CFGradeLevel NVARCHAR(100),CFEvaResultID VARCHAR(44),CONSTRAINT CPK_PER_IntrvRIrht PRIMARY KEY (FID));
 
-
--- 考勤异常提醒记录
+-- 累计考勤异常提醒记录
 CREATE TABLE T_Remind_Record (
     ID INT IDENTITY(1,1) PRIMARY KEY,  -- 自增主键
     yearMonth VARCHAR(10) NOT NULL,
     personNumber VARCHAR(50) NOT NULL
-);
+);
+
+-- 考勤异常提醒记录表
+If not exists (select 1 from KSQL_USERTABLES where KSQL_TABNAME='CT_ATT_AttendanceExceptionLog')
+Create Table CT_ATT_AttendanceExceptionLog ( FFivouchered INT DEFAULT 0,CFPushResult VARCHAR(2000),CFPushType VARCHAR(100),CFMessageResponse CLOB(2000),CFMessageRequest CLOB(2000),CFDataPushResponse CLOB(2000),CFDataPushRequest CLOB(2000),CFPushStatus INT DEFAULT 1,FNumber NVARCHAR(80),FBizDate DateTime,FHandlerID VARCHAR(44),FDescription VARCHAR(255),FHasEffected INT,FAuditorID VARCHAR(44),FSourceBillID VARCHAR(80),FSourceFunction VARCHAR(80),FCreatorID VARCHAR(44),FCreateTime DateTime,FLastUpdateUserID VARCHAR(44),FLastUpdateTime DateTime,FControlUnitID VARCHAR(44),FID VARCHAR(44) DEFAULT '' NOT NULL ,CFMessageId NVARCHAR(255),CONSTRAINT PK_AttendanceExcep PRIMARY KEY (FID));
+
+-- 中心负责人关系表分录
+If not exists (select 1 from KSQL_USERTABLES where KSQL_TABNAME='CT_ATT_CenterLRE')
+Create Table CT_ATT_CenterLRE ( FID VARCHAR(44) DEFAULT '' NOT NULL ,FSeq INT DEFAULT 0 NOT NULL ,FParentID VARCHAR(44) DEFAULT '' NOT NULL ,CFSeq INT,CFPersonID VARCHAR(44),CONSTRAINT CPK_ATT_CenterLg0n PRIMARY KEY (FID));
+
+-- 中心负责人关系表主表
+If not exists (select 1 from KSQL_USERTABLES where KSQL_TABNAME='CT_ATT_CenterLeaderRelation')
+Create Table CT_ATT_CenterLeaderRelation ( FCreatorID VARCHAR(44),FCreateTime DateTime,FLastUpdateUserID VARCHAR(44),FLastUpdateTime DateTime,FControlUnitID VARCHAR(44),FNumber NVARCHAR(80),FBizDate DateTime,FHandlerID VARCHAR(44),FDescription NVARCHAR(80),FHasEffected INT,FAuditorID VARCHAR(44),FSourceBillID NVARCHAR(80),FSourceFunction NVARCHAR(80),FID VARCHAR(44) DEFAULT '' NOT NULL ,CFDepartmentID VARCHAR(44),CFNotifyOrgLeader INT,CFPersonIds NVARCHAR(2000),CFPersonNames NVARCHAR(2000),CFPersonNumbers NVARCHAR(2000),CONSTRAINT CPK_ATT_CenterLrce PRIMARY KEY (FID));
+

+ 9 - 22
src/com/kingdee/eas/custom/attendanceexception/app/CenterLeaderRelationControllerBean.java

@@ -13,7 +13,6 @@ import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.custom.attendanceexception.CenterLeaderRelationEntryCollection;
 import com.kingdee.eas.custom.attendanceexception.CenterLeaderRelationEntryInfo;
 import com.kingdee.eas.custom.synctask.utils.HRTimeWebUtils;
-import com.kingdee.eas.hr.ats.AtsUtil;
 import com.kingdee.eas.hr.emp.IPersonPosition;
 import com.kingdee.eas.hr.emp.PersonPositionCollection;
 import com.kingdee.eas.hr.emp.PersonPositionFactory;
@@ -31,11 +30,10 @@ import com.kingdee.eas.custom.attendanceexception.CenterLeaderRelationInfo;
 public class CenterLeaderRelationControllerBean extends AbstractCenterLeaderRelationControllerBean {
     private static Logger logger = Logger.getLogger(CenterLeaderRelationControllerBean.class);
     //一级组织类型id
-    private final String FIRSTLEVELORGID = "00000000-0000-0000-0000-00000000000362824988";
+    //private final String FIRSTLEVELORGID = "00000000-0000-0000-0000-00000000000362824988";
 
     @Override
     protected IObjectPK _save(Context ctx, IObjectValue model) throws BOSException, EASBizException {
-
         CenterLeaderRelationInfo info = (CenterLeaderRelationInfo) model;
         AdminOrgUnitInfo department = info.getDepartment();
         if (department == null) {
@@ -45,11 +43,11 @@ public class CenterLeaderRelationControllerBean extends AbstractCenterLeaderRela
         //1.校验组织是否为一级部门
         IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
         department = iAdminOrgUnit.getAdminOrgUnitInfo(new ObjectUuidPK(orgId));
-        String unitLayerTypeId = department.getUnitLayerType().getId().toString();
-        if (!FIRSTLEVELORGID.equals(unitLayerTypeId)) {
-            String orgName = department.getName();
-            throw new BOSException(orgName + "不是一级组织,不能维护负责人!");
-        }
+//        String unitLayerTypeId = department.getUnitLayerType().getId().toString();
+//        if (!FIRSTLEVELORGID.equals(unitLayerTypeId)) {
+//            String orgName = department.getName();
+//            throw new BOSException(orgName + "不是一级组织,不能维护负责人!");
+//        }
         //2.校验是否存在重复组织数据
         FilterInfo filterInfo = new FilterInfo();
         FilterItemCollection filterItems = filterInfo.getFilterItems();
@@ -101,28 +99,17 @@ public class CenterLeaderRelationControllerBean extends AbstractCenterLeaderRela
     @Override
     protected Map _getLeaders(Context ctx) throws BOSException {
         super._getLeaders(ctx);
-        //获取组织负责人
-        Map<String, Set<String>> orgLeadersMap = getOrgLeaders(ctx);
+        Map<String, String> orgLeadersMap = new HashMap();
         //中心负责人关系表
-        CenterLeaderRelationCollection relationCol = getCenterLeaderRelationCollection(ctx, "select id,department.number,personNumbers,notifyOrgLeader");
+        CenterLeaderRelationCollection relationCol = getCenterLeaderRelationCollection(ctx, "select id,department.longNumber,personNumbers");
         for (int i = 0; i < relationCol.size(); i++) {
             CenterLeaderRelationInfo info = relationCol.get(i);
             //中心
             AdminOrgUnitInfo department = info.getDepartment();
-            //员工ids
-            //String personIds = info.getPersonIds();
             //员工工号s
             String personNumbers = info.getPersonNumbers();
-            //是否通知组织负责人
-            boolean notifyOrgLeader = info.isNotifyOrgLeader();
             if (department != null && StringUtils.isNotBlank(personNumbers)) {
-                String orgNumber = department.getNumber();
-                Set<String> set = AtsUtil.toSet(personNumbers);
-                if (orgLeadersMap.containsKey(orgNumber) && notifyOrgLeader) {
-                    orgLeadersMap.get(orgNumber).addAll(set);
-                } else {
-                    orgLeadersMap.put(orgNumber, set);
-                }
+                orgLeadersMap.put(department.getLongNumber(), personNumbers);
             } else {
                 String id = info.getId().toString();
                 logger.error("CenterLeaderRelationInfo exist department is null or personNumbers is null, id=" + id);

+ 96 - 139
src/com/kingdee/eas/custom/attendanceexception/task/AttendanceExceptionFacadeControllerBean.java

@@ -3,6 +3,7 @@ package com.kingdee.eas.custom.attendanceexception.task;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.kingdee.bos.metadata.entity.*;
+import com.kingdee.bos.metadata.query.util.CompareType;
 import com.kingdee.eas.basedata.org.AdminOrgUnitCollection;
 import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
 import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
@@ -13,7 +14,6 @@ import com.kingdee.eas.custom.attendanceexception.bizEnum.PushTypeEnum;
 import com.kingdee.eas.fi.arap.util.DBUtil;
 import com.kingdee.eas.hr.ats.AttendanceFileCollection;
 import com.kingdee.eas.hr.ats.AttendanceFileFactory;
-import com.kingdee.eas.hr.ats.AttendanceFileInfo;
 import com.kingdee.eas.hr.ats.IAttendanceFile;
 import com.kingdee.eas.hr.ats.util.AtsDateUtils;
 import com.kingdee.jdbc.rowset.IRowSet;
@@ -106,13 +106,13 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
                 pushAttendanceExceptionData(syncAttendanceDataBeans, logInfo);
             } catch (Exception e) {
                 String message = e.getMessage();
-                logInfo.setPushStatus(CallStatusEnum.failure);
-                logInfo.setPushResult(message);
                 logger.error("员工个人异常提醒报错 " + message, e);
                 if (message.contains("connect timed out")) {
                     iAttendanceExceptionLog.save(logInfo);
                     break;
                 }
+                logInfo.setPushStatus(CallStatusEnum.failure);
+                logInfo.setPushResult(message);
             }
             //保存消息记录
             iAttendanceExceptionLog.save(logInfo);
@@ -190,13 +190,13 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
                 addRemindRecord(ctx, yearMonth, personNumber);
             } catch (Exception e) {
                 String message = e.getMessage();
-                logInfo.setPushStatus(CallStatusEnum.failure);
-                logInfo.setPushResult(message);
                 logger.error("提醒员工累计异常报错: " + message, e);
                 if (message.contains("connect timed out")) {
                     iAttendanceExceptionLog.save(logInfo);
                     break;
                 }
+                logInfo.setPushStatus(CallStatusEnum.failure);
+                logInfo.setPushResult(message);
             }
             //保存消息记录
             iAttendanceExceptionLog.save(logInfo);
@@ -227,11 +227,7 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
         //中心负责人关系表
         ICenterLeaderRelation iCenterLeaderRelation = CenterLeaderRelationFactory.getLocalInstance(ctx);
         //获取中心负责人
-        Map<String, Set<String>> leaders = iCenterLeaderRelation.getLeaders();
-        //获取各中心考勤人数
-        Map<String, Integer> attendanceCountMap = getAttendanceCount(ctx);
-        //获取中心名称
-        Map<String, String> orgMap = getOrgMap(ctx);
+        Map<String, String> leaders = iCenterLeaderRelation.getLeaders();
         PushTypeEnum pushTypeEnum = PushTypeEnum.CENTERLEADERREMINDER;
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd E HH:mm:ss");
         //获取考勤异常数据,本周周一至周五中心考勤异常数据
@@ -247,36 +243,65 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
         //}
         logger.error("_alertLeaderExceptionTotal endDate: " + sdf.format(endDate));
         //1.查询异常数据
-        Map<String, Map<String, Integer>> exceptionCountMap = new HashMap<>();
-        Map<String, List<SyncAttendanceDataBean>> exceptionData = getAttendanceExceptionDataForLeader(ctx, monday, endDate, exceptionCountMap);
+        List<Map<String, Object>> exceptionDataList = getAttendanceExceptionDataForLeader(ctx, monday, endDate);
         String mondayFormat = DateTimeUtils.format(monday, "yyyy年MM月dd日");
         String endDateFormat = DateTimeUtils.format(endDate, "yyyy年MM月dd日");
-        for (String centerNumber : exceptionData.keySet()) {
-            String msgId = UUID.randomUUID().toString();
+        for (String orgLongNumber : leaders.keySet()) {
             AttendanceExceptionLogInfo logInfo = new AttendanceExceptionLogInfo();
+            String msgId = UUID.randomUUID().toString();
             logInfo.setMessageId(msgId);
             logInfo.setPushType(pushTypeEnum);
             try {
-                Set<String> alertUserSet = leaders.get(centerNumber);
-                String orgName = orgMap.getOrDefault(centerNumber, "中心");
-                //中心负责人
-                String alertUsers = convertSetToString(alertUserSet);
+                //获取组织名称
+                AdminOrgUnitInfo orgInfo = getOrgInfo(ctx, orgLongNumber);
+                String orgName = orgInfo.getName();
+                //负责人
+                String alertUsers = leaders.get(orgLongNumber);
                 if (StringUtils.isBlank(alertUsers)) {
                     throw new BOSException(orgName + "的负责人为空!");
                 }
-                //中心考勤总人数
-                Integer attendanceCount = attendanceCountMap.getOrDefault(centerNumber, 0);
-                Map<String, Integer> orgExceptionTimes = exceptionCountMap.get(centerNumber);
+                //考勤总人数(包含下级)
+                Integer attendanceCount = getAttendanceCount(ctx, orgLongNumber);
                 //迟到人数
-                Integer lateEmployees = orgExceptionTimes.getOrDefault("lateEmployees", 0);
+                Set<String> lateEmployees = new HashSet<>();
                 //早退人数
-                Integer earlyLeaveEmployees = orgExceptionTimes.getOrDefault("earlyLeaveEmployees", 0);
+                Set<String> earlyLeaveEmployees = new HashSet<>();
                 //旷工人数
-                Integer absentEmployees = orgExceptionTimes.getOrDefault("absentEmployees", 0);
+                Set<String> absentEmployees = new HashSet<>();
                 //个人原因补卡人数
-                //Integer personalRecheckCountEmployees = orgExceptionTimes.getOrDefault("personalRecheckCountEmployees", 0);
+                //Set<String>  personalRecheckCountEmployees = new HashSet<>();
                 //异常人数
-                Integer exceptionEmployees = orgExceptionTimes.getOrDefault("exceptionEmployees", 0);
+                Set<String> exceptionEmployees = new HashSet<>();
+                //遍历人员
+                List<SyncAttendanceDataBean> syncAttendanceDataBeans = new ArrayList<>();
+                exceptionDataList.stream().forEach(map -> {
+                    SyncAttendanceDataBean exceptionDataBean = (SyncAttendanceDataBean) map.get("data");
+                    //部门长编码
+                    String departmentManagerCode = exceptionDataBean.getDepartmentManagerCode();
+                    if (departmentManagerCode.startsWith(orgLongNumber)) {
+                        Map<String, Boolean> attendanceFlags = (Map<String, Boolean>) map.get("attendanceFlags");
+                        String personNumber = exceptionDataBean.getEmployeeId();
+                        exceptionDataBean.setMsgId(msgId);
+                        syncAttendanceDataBeans.add(exceptionDataBean);
+                        exceptionEmployees.add(personNumber);
+                        if (attendanceFlags.get("lateEmployees")) {
+                            //迟到
+                            lateEmployees.add(personNumber);
+                        }
+                        if (attendanceFlags.get("earlyLeaveEmployees")) {
+                            //早退
+                            earlyLeaveEmployees.add(personNumber);
+                        }
+                        if (attendanceFlags.get("absentEmployees")) {
+                            //旷工
+                            absentEmployees.add(personNumber);
+                        }
+//                    if(attendanceFlags.get("personalRecheckCountEmployees")){
+//                        //个人原因补卡
+//                        personalRecheckCountEmployees.add(personNumber);
+//                    }
+                    }
+                });
                 //发送异常消息
                 JSONObject dingMsgBean = new JSONObject();
                 dingMsgBean.put("msgTempCode", "work_notice_01");
@@ -288,33 +313,31 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
                 param.put("msgId", msgId);
                 //时间
                 param.put("time", mondayFormat + "-" + endDateFormat);
-                //中心考勤人数
+                //考勤人数
                 param.put("centerNum", attendanceCount);
                 //考勤异常人数
-                param.put("eorNum", exceptionEmployees);
+                param.put("eorNum", exceptionEmployees.size());
                 //迟到人数
-                param.put("lateNum", lateEmployees);
+                param.put("lateNum", lateEmployees.size());
                 //早退人数
-                param.put("earlyNum", earlyLeaveEmployees);
+                param.put("earlyNum", earlyLeaveEmployees.size());
                 //旷工人数
-                param.put("hookyNum", absentEmployees);
+                param.put("hookyNum", absentEmployees.size());
+                //中心
+                param.put("depart", orgName);
                 dingMsgBean.put("param", param);
                 sendAttendanceExceptionMsg(dingMsgBean, logInfo);
                 //推送异常数据
-                List<SyncAttendanceDataBean> syncAttendanceDataBeans = exceptionData.get(centerNumber);
-                syncAttendanceDataBeans.stream().forEach(syncAttendanceDataBean -> {
-                    syncAttendanceDataBean.setMsgId(msgId);
-                });
                 pushAttendanceExceptionData(syncAttendanceDataBeans, logInfo);
             } catch (Exception e) {
                 String message = e.getMessage();
-                logInfo.setPushStatus(CallStatusEnum.failure);
-                logInfo.setPushResult(message);
                 logger.error("提醒中心负责人累计异常报错 " + message, e);
                 if (message.contains("connect timed out")) {
                     iAttendanceExceptionLog.save(logInfo);
                     break;
                 }
+                logInfo.setPushStatus(CallStatusEnum.failure);
+                logInfo.setPushResult(message);
             }
             //保存消息记录
             iAttendanceExceptionLog.save(logInfo);
@@ -397,82 +420,30 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
      * @throws BOSException
      * @throws EASBizException
      */
-    protected Map<String, List<SyncAttendanceDataBean>> getAttendanceExceptionDataForLeader(
+    protected List<Map<String, Object>> getAttendanceExceptionDataForLeader(
             Context ctx,
             Date startDate,
-            Date endDate,
-            Map<String, Map<String, Integer>> exceptionCountMap
+            Date endDate
     ) throws BOSException {
         String sql = getSql(startDate, endDate);
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        Map<String, Map<String, Set<String>>> exceptionData = new HashMap<>();
+        List<Map<String, Object>> attendanceExceptionDatas = new ArrayList<Map<String, Object>>();
         try {
             IRowSet iRowSet = DBUtil.executeQuery(ctx, sql);
-            Map<String, List<SyncAttendanceDataBean>> result = new HashMap<>();
             while (iRowSet.next()) {
+                Map<String, Object> map = new HashMap<String, Object>();
                 //设置考勤结果和次数
                 SyncAttendanceDataBean data = setAttendanceResult(iRowSet, sdf);
-                //中心编码
-                String admintwoNumber = iRowSet.getString("admintwoNumber");
-                String personNumber = data.getEmployeeId();
                 Map<String, Boolean> attendanceFlags = new LinkedHashMap<>();
-                int s19 = iRowSet.getInt("s19");
-                int s21 = iRowSet.getInt("s21");
-                BigDecimal s23 = iRowSet.getBigDecimal("s23");
-                int s113 = iRowSet.getInt("s113");
-                attendanceFlags.put("lateEmployees", s19 > 0);//迟到
-                attendanceFlags.put("earlyLeaveEmployees", s21 > 0);//早退
-                attendanceFlags.put("absentEmployees", s23.compareTo(BigDecimal.ZERO) > 0);//旷工
-                attendanceFlags.put("personalRecheckCountEmployees", s113 > 0);//个人原因补卡
-                Map<String, Set<String>> exceptionPersonMap = null;
-                if (exceptionData.containsKey(admintwoNumber)) {
-                    exceptionPersonMap = exceptionData.get(admintwoNumber);
-                } else {
-                    exceptionPersonMap = new HashMap<>();
-                    exceptionData.put(admintwoNumber, exceptionPersonMap);
-                }
-                Set<String> exceptionEmployees = exceptionPersonMap.get("exceptionEmployees");
-                if (exceptionEmployees == null) {
-                    exceptionEmployees = new HashSet<>();
-                    exceptionPersonMap.put("exceptionEmployees", exceptionEmployees);
-                }
-                exceptionEmployees.add(personNumber);
-                for (Map.Entry<String, Boolean> entry : attendanceFlags.entrySet()) {
-                    if (entry.getValue()) {
-                        Set<String> set = exceptionPersonMap.get(entry.getKey());
-                        if (set == null) {
-                            set = new HashSet<>();
-                            exceptionPersonMap.put(entry.getKey(), set);
-                        }
-                        set.add(personNumber);
-                    }
-                }
-                if (!result.containsKey(admintwoNumber)) {
-                    result.put(admintwoNumber, new ArrayList<>());
-                }
-                result.get(admintwoNumber).add(data);
+                attendanceFlags.put("lateEmployees", iRowSet.getInt("s19") > 0);//迟到
+                attendanceFlags.put("earlyLeaveEmployees", iRowSet.getInt("s21") > 0);//早退
+                attendanceFlags.put("absentEmployees", iRowSet.getBigDecimal("s23").compareTo(BigDecimal.ZERO) > 0);//旷工
+                attendanceFlags.put("personalRecheckCountEmployees", iRowSet.getInt("s113") > 0);//个人原因补卡
+                map.put("data", data);
+                map.put("attendanceFlags", attendanceFlags);
+                attendanceExceptionDatas.add(map);
             }
-            for (String orgNumber : exceptionData.keySet()) {
-                Map<String, Set<String>> orgExceptionData = exceptionData.get(orgNumber);
-                Map<String, Integer> orgExceptionTimes = new HashMap<>();
-                //迟到人数
-                Set<String> lateEmployees = orgExceptionData.get("lateEmployees");
-                orgExceptionTimes.put("lateEmployees", lateEmployees != null ? lateEmployees.size() : 0);
-                //早退人数
-                Set<String> earlyLeaveEmployees = orgExceptionData.get("earlyLeaveEmployees");
-                orgExceptionTimes.put("earlyLeaveEmployees", earlyLeaveEmployees != null ? earlyLeaveEmployees.size() : 0);
-                //旷工人数
-                Set<String> absentEmployees = orgExceptionData.get("absentEmployees");
-                orgExceptionTimes.put("absentEmployees", absentEmployees != null ? absentEmployees.size() : 0);
-                //个人原因补卡人数
-                Set<String> personalRecheckCountEmployees = orgExceptionData.get("personalRecheckCountEmployees");
-                orgExceptionTimes.put("personalRecheckCountEmployees", personalRecheckCountEmployees != null ? personalRecheckCountEmployees.size() : 0);
-                //异常人数
-                Set<String> exceptionEmployees = orgExceptionData.get("exceptionEmployees");
-                orgExceptionTimes.put("exceptionEmployees", exceptionEmployees != null ? exceptionEmployees.size() : 0);
-                exceptionCountMap.put(orgNumber, orgExceptionTimes);
-            }
-            return result;
+            return attendanceExceptionDatas;
         } catch (SQLException e) {
             logger.error(e.getMessage(), e);
             throw new RuntimeException(e);
@@ -561,15 +532,15 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
                 .append("    adminOrg.fname_l2 as adminOrgName,").append("\n")
                 .append("    adminOrg.FLongNumber as adminOrgLongNumber,").append("\n")
                 .append("    adminOrg.FSortCode as sortCode,").append("\n")
-                .append("    adminOrg.FDisplayName_L2 as displayName,").append("\n")
-                .append("    admintwo.fid as admintwoId,").append("\n")
-                .append("    admintwo.fnumber as admintwoNumber,").append("\n")
-                .append("    admintwo.Fname_l2 as admintwoName").append("\n")
+                .append("    adminOrg.FDisplayName_L2 as displayName").append("\n")
+//                .append("    admintwo.fid as admintwoId,").append("\n")
+//                .append("    admintwo.fnumber as admintwoNumber,").append("\n")
+//                .append("    admintwo.Fname_l2 as admintwoName").append("\n")
                 .append("from").append("\n")
                 .append("    T_HR_ATS_AttendanceResult attendanceResult").append("\n")
                 .append("    left join t_bd_person person on person.fid = attendanceResult.FProposerID").append("\n")
                 .append("    left join T_ORG_admin adminOrg on attendanceResult.FAdminOrgUnitID = adminOrg.fid").append("\n")
-                .append("    left join T_ORG_admin admintwo on adminOrg.FLevelTwoGroupID = admintwo.fid").append("\n")
+                //.append("    left join T_ORG_admin admintwo on adminOrg.FLevelTwoGroupID = admintwo.fid").append("\n")
                 .append("where").append("\n")
                 .append("    attendanceResult.FAttenceDate >= { TS '").append(sdf.format(startDate)).append("' }").append("\n")
                 .append("    and attendanceResult.FAttenceDate <= { TS '").append(sdf.format(endDate)).append("' }").append("\n")
@@ -727,71 +698,57 @@ public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceE
     }
 
     /**
-     * 获取各个中心考勤总人数
+     * 获取组织考勤总人数(包含下级)
      *
      * @param ctx
      * @return
      */
-    public Map<String, Integer> getAttendanceCount(Context ctx) {
-        Map<String, Integer> attendanceCountMap = new HashMap<>();
+    public int getAttendanceCount(Context ctx, String orgLongNumber) {
         try {
             IAttendanceFile iAttendanceFile = AttendanceFileFactory.getLocalInstance(ctx);
             FilterInfo filterInfo = new FilterInfo();
             FilterItemCollection filterItems = filterInfo.getFilterItems();
             filterItems.add(new FilterItemInfo("attendFileState", "1"));
-            SelectorItemCollection sic = new SelectorItemCollection();
-            sic.add("adminOrgUnit.levelTwoGroup.number");
-            EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
+            //打卡考勤
+            filterItems.add(new FilterItemInfo("isAttendance", "1"));
+            filterItems.add(new FilterItemInfo("adminOrgUnit.longNumber", orgLongNumber + "%", CompareType.LIKE));
+            EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
             AttendanceFileCollection attendanceFileCol = iAttendanceFile.getAttendanceFileCollection(viewInfo);
-            for (int i = 0; i < attendanceFileCol.size(); i++) {
-                AttendanceFileInfo attendanceFileInfo = attendanceFileCol.get(i);
-                String number = attendanceFileInfo.getAdminOrgUnit().getLevelTwoGroup().getNumber();
-                if (attendanceCountMap.containsKey(number)) {
-                    Integer i1 = attendanceCountMap.get(number);
-                    attendanceCountMap.put(number, i1 + 1);
-                } else {
-                    attendanceCountMap.put(number, 1);
-                }
-            }
+            return attendanceFileCol.size();
         } catch (BOSException e) {
-            logger.error("获取各个中心考勤总人数报错: " + e.getMessage(), e);
+            logger.error("获取" + orgLongNumber + "考勤总人数报错: " + e.getMessage(), e);
             throw new RuntimeException(e);
         }
-        return attendanceCountMap;
     }
 
 
     /**
-     * 获取中心名称
+     * 根据长编码获取组织
      *
      * @param ctx
      * @return
      */
-    public Map<String, String> getOrgMap(Context ctx) {
-        Map<String, String> orgMap = new HashMap<>();
+    public AdminOrgUnitInfo getOrgInfo(Context ctx, String orgLongNumber) throws BOSException {
+        AdminOrgUnitCollection adminOrgUnitCollection = null;
         try {
             IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
             FilterInfo filterInfo = new FilterInfo();
             FilterItemCollection filterItems = filterInfo.getFilterItems();
             //组织层级为一级组织
             filterItems.add(new FilterItemInfo("unitLayerType", "00000000-0000-0000-0000-00000000000362824988"));
-            filterItems.add(new FilterItemInfo("isSealUp", "0"));
+            filterItems.add(new FilterItemInfo("longNumber", "0"));
             SelectorItemCollection sic = new SelectorItemCollection();
             sic.add("number");
             sic.add("name");
-            EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
-            AdminOrgUnitCollection adminOrgUnitCol = iAdminOrgUnit.getAdminOrgUnitCollection(viewInfo);
-            for (int i = 0; i < adminOrgUnitCol.size(); i++) {
-                AdminOrgUnitInfo adminOrgUnitInfo = adminOrgUnitCol.get(i);
-                String number = adminOrgUnitInfo.getNumber();
-                String name = adminOrgUnitInfo.getName();
-                orgMap.put(number, name);
-            }
+            adminOrgUnitCollection = iAdminOrgUnit.getAdminOrgUnitCollection("where longNumber = '" + orgLongNumber + "'");
         } catch (Exception e) {
-            logger.error("获取中心名称报错: " + e.getMessage(), e);
-            throw new RuntimeException(e);
+            logger.error("获取组织报错: " + e.getMessage(), e);
+            throw new BOSException(e);
+        }
+        if (adminOrgUnitCollection == null || adminOrgUnitCollection.size() == 0) {
+            throw new BOSException("未找到长编码为[" + orgLongNumber + "]的组织");
         }
-        return orgMap;
+        return adminOrgUnitCollection.get(0);
     }
 
     /**

+ 0 - 114
websrc/com/kingdee/eas/custom/attendanceexception/handler/CenterLeaderRelationEditHandler.java

@@ -1,114 +0,0 @@
-package com.kingdee.eas.custom.attendanceexception.handler;
-
-import com.kingdee.bos.BOSException;
-import com.kingdee.bos.Context;
-import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
-import com.kingdee.bos.metadata.entity.FilterInfo;
-import com.kingdee.bos.metadata.entity.FilterItemCollection;
-import com.kingdee.bos.metadata.entity.FilterItemInfo;
-import com.kingdee.bos.metadata.query.util.CompareType;
-import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
-import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
-import com.kingdee.eas.basedata.org.IAdminOrgUnit;
-import com.kingdee.eas.basedata.person.PersonInfo;
-import com.kingdee.eas.common.EASBizException;
-import com.kingdee.eas.custom.attendanceexception.CenterLeaderRelationEntryCollection;
-import com.kingdee.eas.custom.attendanceexception.CenterLeaderRelationEntryInfo;
-import com.kingdee.eas.custom.attendanceexception.CenterLeaderRelationInfo;
-import com.kingdee.eas.framework.CoreBaseInfo;
-import com.kingdee.shr.base.syssetting.context.SHRContext;
-import com.kingdee.shr.base.syssetting.exception.SHRWebException;
-import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
-import com.kingdee.shr.base.syssetting.web.handler.EditHandler;
-import org.apache.log4j.Logger;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @Description 中心负责人关系表表单Handler
- * @Date 2025/4/16 11:18
- * @Created by Heyuan
- */
-public class CenterLeaderRelationEditHandler extends EditHandler {
-    private static Logger logger = Logger.getLogger(CenterLeaderRelationEditHandler.class);
-    private Context ctx = SHRContext.getInstance().getContext();
-    //一级组织类型id
-    private final String FIRSTLEVELORGID = "00000000-0000-0000-0000-00000000000362824988";
-
-    @Override
-    protected void verifyModel(
-            HttpServletRequest request,
-            HttpServletResponse response,
-            CoreBaseInfo model
-    ) throws SHRWebException {
-        try {
-            CenterLeaderRelationInfo info = (CenterLeaderRelationInfo) model;
-            AdminOrgUnitInfo department = info.getDepartment();
-            if (department == null) {
-                throw new ShrWebBizException("组织不能为空!");
-            }
-            String orgId = department.getId().toString();
-            //1.校验组织是否为一级部门
-            IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
-            department = iAdminOrgUnit.getAdminOrgUnitInfo(new ObjectUuidPK(orgId));
-            String unitLayerTypeId = department.getUnitLayerType().getId().toString();
-            if (!FIRSTLEVELORGID.equals(unitLayerTypeId)) {
-                String orgName = department.getName();
-                throw new ShrWebBizException(orgName + "不是一级组织,不能维护负责人!");
-            }
-            //2.校验是否存在重复组织数据
-            FilterInfo filterInfo = new FilterInfo();
-            FilterItemCollection filterItems = filterInfo.getFilterItems();
-            filterItems.add(new FilterItemInfo("department", department.getId()));
-            if (info.getId() != null) {
-                filterItems.add(new FilterItemInfo("id", info.getId(), CompareType.NOTEQUALS));
-            }
-            boolean exists = this.getBizInterface(request).exists(filterInfo);
-            if (exists) {
-                String orgName = department.getName();
-                throw new ShrWebBizException("组织[" + orgName + "]数据已经存在,请勿重复添加!");
-            }
-            //3.校验分录人员数据
-            CenterLeaderRelationEntryCollection entrys = info.getEntry();
-            if (entrys.size() <= 0) {
-                throw new ShrWebBizException("分录不能为空!");
-            } else {
-                StringBuilder numbers = new StringBuilder();
-                StringBuilder names = new StringBuilder();
-                Set<String> personIds = new HashSet<>();
-                for (int i = entrys.size() - 1; i >= 0; i--) {
-                    CenterLeaderRelationEntryInfo entryInfo = entrys.get(i);
-                    PersonInfo person = entryInfo.getPerson();
-                    String personId = person.getId().toString();
-                    if (personIds.contains(personId)) {
-                        //去除重复人员
-                        entrys.remove(entryInfo);
-                        continue;
-                    }
-                    personIds.add(personId);
-                    String number = person.getNumber();
-                    numbers.append(number).append(",");
-                    String name = person.getName();
-                    names.append(name).append(",");
-                }
-                if (numbers.length() > 0) {
-                    numbers.deleteCharAt(numbers.lastIndexOf(","));
-                }
-                info.setPersonNumbers(numbers.toString());
-                if (names.length() > 0) {
-                    names.deleteCharAt(names.lastIndexOf(","));
-                }
-                info.setPersonNames(names.toString());
-            }
-        } catch (BOSException e) {
-            logger.error(e);
-            throw new ShrWebBizException(e);
-        } catch (EASBizException e) {
-            logger.error(e);
-            throw new ShrWebBizException(e);
-        }
-    }
-}

+ 68 - 10
websrc/com/kingdee/eas/custom/attendanceexception/service/CenterLeaderRelationImportService.java

@@ -1,13 +1,20 @@
 package com.kingdee.eas.custom.attendanceexception.service;
 
+import com.kingdee.bos.BOSException;
 import com.kingdee.bos.Context;
 import com.kingdee.bos.metadata.entity.*;
+import com.kingdee.eas.basedata.person.IPerson;
+import com.kingdee.eas.basedata.person.PersonCollection;
+import com.kingdee.eas.basedata.person.PersonFactory;
+import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.custom.attendanceexception.*;
 import com.kingdee.eas.framework.CoreBaseInfo;
 import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseColumnInfo;
 import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseImportService;
+import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseRowInfo;
 import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;
 import com.kingdee.util.StringUtils;
+import org.apache.log4j.Logger;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -21,6 +28,60 @@ import java.util.*;
  * @Created by Heyuan
  */
 public class CenterLeaderRelationImportService extends BaseImportService {
+    private static Logger logger = Logger.getLogger(CenterLeaderRelationImportService.class);
+
+    /**
+     * 设置其他字段
+     *
+     * @param baseInfo
+     * @param row
+     * @throws ImportException
+     */
+    @Override
+    protected void setOtherFieldInfo(CoreBaseInfo baseInfo, BaseRowInfo row) throws ImportException {
+        super.setOtherFieldInfo(baseInfo, row);
+        try {
+            CenterLeaderRelationInfo relationInfo = (CenterLeaderRelationInfo) baseInfo;
+            CenterLeaderRelationEntryCollection entrys = relationInfo.getEntry();
+            entrys.clear();
+            Map<String, BaseColumnInfo> mapColumnInfo = row.getMapColumnInfo();
+            Context ctx = this.getContext();
+            IPerson iPerson = null;
+            iPerson = PersonFactory.getLocalInstance(ctx);
+            for (String key : mapColumnInfo.keySet()) {
+                BaseColumnInfo columnInfo = mapColumnInfo.get(key);
+                String propName = columnInfo.getPropName();
+                String name = columnInfo.getName();
+                if (columnInfo.isCustomField() && propName.startsWith("person")) {
+                    String value = row.getValueOfString(propName);
+                    if (StringUtils.isEmpty(value)) {
+                        continue;
+                    }
+                    String filter = null;
+                    if (value.contains("##")) {
+                        String[] split = value.split("##");
+                        String number = split[0];
+                        filter = "where number = '" + number + "'";
+                    } else {
+                        filter = "where number = '" + value + "' or name = '" + value + "'";
+                    }
+                    PersonCollection personCollection = iPerson.getPersonCollection(filter);
+                    if (personCollection.size() > 0) {
+                        PersonInfo personInfo = personCollection.get(0);
+                        CenterLeaderRelationEntryInfo entry = new CenterLeaderRelationEntryInfo();
+                        entry.setPerson(personInfo);
+                        entrys.add(entry);
+                    } else {
+                        throw new ImportException(name + " " + value + " 未找到,请检查数据是否有误");
+                    }
+                }
+            }
+        } catch (BOSException e) {
+            logger.error(e.getMessage(), e);
+            throw new ImportException(e);
+        }
+    }
+
     /**
      * 模板下载时携带数据
      *
@@ -29,13 +90,9 @@ public class CenterLeaderRelationImportService extends BaseImportService {
      * @param sheet
      */
     @Override
-    public void completeGenerateExcel(Map<String, BaseColumnInfo> columnInfoMap,
-                                      XSSFWorkbook wb,
-                                      XSSFSheet sheet) {
+    public void completeGenerateExcel(Map<String, BaseColumnInfo> columnInfoMap, XSSFWorkbook wb, XSSFSheet sheet) {
         Context ctx = this.getContext();
         int beginRow = 4;//数据生成开始行数
-        //隐藏第一列
-        //sheet.setColumnHidden(0, true);
         try {
             ICenterLeaderRelation iCenterLeaderRelation = CenterLeaderRelationFactory.getLocalInstance(ctx);
             SelectorItemCollection sic = getSelectorItemCollection(columnInfoMap);
@@ -78,6 +135,8 @@ public class CenterLeaderRelationImportService extends BaseImportService {
                         if (obj instanceof CoreBaseInfo) {
                             CoreBaseInfo coreBaseInfo = (CoreBaseInfo) obj;
                             value = coreBaseInfo.get("number") + "##" + coreBaseInfo.get("name");
+                        } else if (obj instanceof Boolean) {
+                            value = (Boolean) obj ? "是" : "否";
                         } else {
                             value = obj.toString();
                         }
@@ -113,7 +172,7 @@ public class CenterLeaderRelationImportService extends BaseImportService {
     }
 
     /**
-     *
+     * 获取查询字段
      *
      * @param columnInfoMap
      * @return
@@ -124,16 +183,15 @@ public class CenterLeaderRelationImportService extends BaseImportService {
             BaseColumnInfo columnInfo = columnInfoMap.get(key);
             if (!columnInfo.isCustomField() && !columnInfo.isDynamicColumn()) {
                 String supplierEntityName = columnInfo.getSupplierEntityName();
-                if (DataType.OBJECTVALUE.equals(columnInfo.getPropDataType())
-                        || !StringUtils.isEmpty(supplierEntityName)) {
+                if (DataType.OBJECTVALUE.equals(columnInfo.getPropDataType()) || !StringUtils.isEmpty(supplierEntityName)) {
                     sic.add(key + ".*");
                 } else {
                     sic.add(key);
                 }
             }
         }
-        sic.add("Entry.person.number");
-        sic.add("Entry.person.name");
+        sic.add("entry.person.number");
+        sic.add("entry.person.name");
         return sic;
     }
 }