123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- 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.eas.basedata.org.AdminOrgUnitCollection;
- 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.custom.attendanceexception.*;
- import com.kingdee.eas.custom.attendanceexception.bean.SyncAttendanceDataBean;
- 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;
- import com.kingdee.shr.base.syssetting.CallStatusEnum;
- import com.kingdee.util.DateTimeUtils;
- import okhttp3.MediaType;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.log4j.Logger;
- import com.kingdee.bos.*;
- import com.kingdee.eas.common.EASBizException;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.lang.String;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.text.MessageFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- public class AttendanceExceptionFacadeControllerBean extends AbstractAttendanceExceptionFacadeControllerBean {
- private static Logger logger = Logger.getLogger(AttendanceExceptionFacadeControllerBean.class);
- private Properties propt = new Properties();
- //通知员工个人消息模板
- //private static final String NOTIFYEMPLOYEEMSGTEMPLATE = "##### <font color=#6192f2>HR系统</font>\\n#### 考勤异常提醒:\\n您在{0}出现考勤异常,请及时处理! \\n###### (如有审批中的假勤单据,请及时催办)";
- //通知员工个人消息标题
- //private static final String NOTIFYEMPLOYEEMSGTITLE = "【考勤异常提醒】";
- //通知员工个人消息模板
- //private static final String NOTIFYEMPLOYEECUMULATIVEMSGTEMPLATE = "##### <font color=#6192f2>HR系统</font>\\n#### 员工考勤提醒:\\n您在{0}考勤异常次数已经达到{1}次,请您注意本月考勤 \\n###### (如有审批中的假勤单据,请及时催办)";
- //通知员工个人消息标题
- //private static final String NOTIFYEMPLOYEECUMULATIVEMSGTITLE = "【员工考勤提醒】";
- //通知提醒中心负责人异常消息模板
- //private static final String NOTIFYALERTLEADEREXCEPTIONMSGTEMPLATE = "##### <font color=#6192f2>HR系统</font>\\n#### 中心考勤异常周报:\\n#####时间:{0}-{1}\\n#####内容:{2}考勤人数{3}人,考勤异常人数{4}人,迟到{5}人,早退{6}人,旷工{7}人 \\n###### (如有审批中的假勤单据,请及时催办)";
- //通知提醒中心负责人异常消息标题
- //private static final String NOTIFYALERTLEADEREXCEPTIONMSGTITLE = "【考勤异常周报】";
- //来源标识
- private static final String SOURCE = "EHR";
- public AttendanceExceptionFacadeControllerBean() throws BOSException {
- String syncOAConfigPath = System.getProperty("EAS_HOME") + "/server/properties/scy/attendanceException.properties";
- try {
- propt.load(new FileInputStream(syncOAConfigPath));
- } catch (IOException e) {
- e.printStackTrace();
- String errorMsg = "获取配置文件报错,请检查配置:" + syncOAConfigPath + " " + e.getMessage();
- throw new BOSException(errorMsg);
- }
- }
- /**
- * 员工个人异常提醒
- *
- * @param ctx
- * @throws BOSException
- * @throws EASBizException
- */
- @Override
- protected void _notifyEmployeeException(Context ctx) throws BOSException, EASBizException {
- long startTime = System.currentTimeMillis();
- if (logger.isInfoEnabled()) {
- logger.info("AttendanceExceptionFacadeControllerBean.notifyEmployeeException start");
- }
- super._notifyEmployeeException(ctx);
- IAttendanceExceptionLog iAttendanceExceptionLog = AttendanceExceptionLogFactory.getLocalInstance(ctx);
- PushTypeEnum pushTypeEnum = PushTypeEnum.EMPLOYEEREMINDER;
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd E HH:mm:ss");
- //昨天
- Date preDay = AtsDateUtils.getPreDay(new Date());
- logger.error("_notifyEmployeeCumulativeException preDay: " + sdf.format(preDay));
- //1.查询异常数据
- Map<String, List<SyncAttendanceDataBean>> exceptionData = getAttendanceExceptionData(ctx, preDay, preDay, pushTypeEnum, 0);
- String yearMonthDay = DateTimeUtils.format(preDay, "yyyy年MM月dd日");
- for (String personNumber : exceptionData.keySet()) {
- String msgId = UUID.randomUUID().toString();
- AttendanceExceptionLogInfo logInfo = new AttendanceExceptionLogInfo();
- logInfo.setMessageId(msgId);
- logInfo.setPushType(pushTypeEnum);
- try {
- //发送异常消息
- JSONObject dingMsgBean = new JSONObject();
- dingMsgBean.put("msgTempCode", "work_notice_03");
- dingMsgBean.put("toAllUser", false);
- dingMsgBean.put("userIdList", personNumber);
- dingMsgBean.put("source", SOURCE);
- JSONObject param = new JSONObject();
- //消息id
- param.put("msgId", msgId);
- //时间
- param.put("time", yearMonthDay);
- dingMsgBean.put("param", param);
- sendAttendanceExceptionMsg(dingMsgBean, logInfo);
- //推送异常数据
- List<SyncAttendanceDataBean> syncAttendanceDataBeans = exceptionData.get(personNumber);
- syncAttendanceDataBeans.stream().forEach(syncAttendanceDataBean -> {
- syncAttendanceDataBean.setMsgId(msgId);
- });
- pushAttendanceExceptionData(syncAttendanceDataBeans, logInfo);
- } catch (Exception e) {
- logger.error("员工个人异常提醒报错", e);
- }
- //保存消息记录
- iAttendanceExceptionLog.save(logInfo);
- }
- if (logger.isInfoEnabled()) {
- long endTime = System.currentTimeMillis();
- float duration = (endTime - startTime) / 1000f;
- logger.info(String.format("AttendanceExceptionFacadeControllerBean.notifyEmployeeException end, duration: %fS", duration));
- }
- }
- /**
- * 员工考勤异常关怀提醒
- *
- * @param ctx
- * @param exceptionLimit 异常次数上限
- * @throws BOSException
- * @throws EASBizException
- */
- @Override
- protected void _notifyEmployeeCumulativeException(
- Context ctx,
- String exceptionLimit
- ) throws BOSException, EASBizException {
- long startTime = System.currentTimeMillis();
- if (logger.isInfoEnabled()) {
- logger.info("AttendanceExceptionFacadeControllerBean.notifyEmployeeCumulativeException start");
- }
- super._notifyEmployeeCumulativeException(ctx, exceptionLimit);
- int limit = 5;
- if (StringUtils.isNotBlank(exceptionLimit)) {
- limit = Integer.parseInt(exceptionLimit);
- }
- IAttendanceExceptionLog iAttendanceExceptionLog = AttendanceExceptionLogFactory.getLocalInstance(ctx);
- PushTypeEnum pushTypeEnum = PushTypeEnum.EMPLOYEEEXCEPTIONALERT;
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd E HH:mm:ss");
- Date today = new Date();
- //当前月第一天
- Date currentFirstDay = AtsDateUtils.getCurrentFirstDay(today);
- logger.error("_notifyEmployeeCumulativeException currentFirstDay: " + sdf.format(currentFirstDay));
- //昨天
- Date preDay = AtsDateUtils.getPreDay(today);
- logger.error("_notifyEmployeeCumulativeException preDay: " + sdf.format(preDay));
- //查询异常数据
- Map<String, List<SyncAttendanceDataBean>> exceptionData = getAttendanceExceptionData(ctx, currentFirstDay, preDay, pushTypeEnum, 0);
- String yearMonth = DateTimeUtils.format(today, "yyyy年MM月");
- for (String personNumber : exceptionData.keySet()) {
- String msgId = UUID.randomUUID().toString();
- AttendanceExceptionLogInfo logInfo = new AttendanceExceptionLogInfo();
- logInfo.setMessageId(msgId);
- logInfo.setPushType(pushTypeEnum);
- try {
- //发送异常消息
- JSONObject dingMsgBean = new JSONObject();
- dingMsgBean.put("msgTempCode", "work_notice_02");
- dingMsgBean.put("toAllUser", false);
- dingMsgBean.put("userIdList", personNumber);
- dingMsgBean.put("source", SOURCE);
- JSONObject param = new JSONObject();
- //消息id
- param.put("msgId", msgId);
- //时间
- param.put("time", yearMonth);
- //考勤异常人数
- param.put("eorNum", limit);
- dingMsgBean.put("param", param);
- sendAttendanceExceptionMsg(dingMsgBean, logInfo);
- //推送异常数据
- List<SyncAttendanceDataBean> syncAttendanceDataBeans = exceptionData.get(personNumber);
- syncAttendanceDataBeans.stream().forEach(syncAttendanceDataBean -> {
- syncAttendanceDataBean.setMsgId(msgId);
- });
- pushAttendanceExceptionData(syncAttendanceDataBeans, logInfo);
- //写入提醒记录
- addRemindRecord(ctx, yearMonth, personNumber);
- } catch (Exception e) {
- logger.error("提醒员工累计异常报错: " + e.getMessage(), e);
- }
- //保存消息记录
- iAttendanceExceptionLog.save(logInfo);
- }
- if (logger.isInfoEnabled()) {
- long endTime = System.currentTimeMillis();
- float duration = (endTime - startTime) / 1000f;
- logger.info(String.format("AttendanceExceptionFacadeControllerBean.notifyEmployeeCumulativeException end, duration: %fS", duration));
- }
- }
- /**
- * 提醒中心负责人累计异常
- *
- * @param ctx
- * @throws BOSException
- * @throws EASBizException
- */
- @Override
- protected void _alertLeaderExceptionTotal(Context ctx) throws BOSException, EASBizException {
- long startTime = System.currentTimeMillis();
- if (logger.isInfoEnabled()) {
- logger.info("AttendanceExceptionFacadeControllerBean.alertLeaderExceptionTotal start");
- }
- super._alertLeaderExceptionTotal(ctx);
- IAttendanceExceptionLog iAttendanceExceptionLog = AttendanceExceptionLogFactory.getLocalInstance(ctx);
- //中心负责人关系表
- ICenterLeaderRelation iCenterLeaderRelation = CenterLeaderRelationFactory.getLocalInstance(ctx);
- //获取中心负责人
- Map<String, Set<String>> leaders = iCenterLeaderRelation.getLeaders();
- //获取各中心考勤人数
- Map<String, Integer> attendanceCountMap = getAttendanceCount(ctx);
- //获取中心名称
- Map<String, String> orgMap = getOrgMap(ctx);
- PushTypeEnum pushTypeEnum = PushTypeEnum.CENTERLEADERREMINDER;
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd E HH:mm:ss");
- //获取考勤异常数据,本周周一至周五中心考勤异常数据
- Calendar calendar = Calendar.getInstance();
- Date endDate = calendar.getTime();
- int intWeek = calendar.get(7);
- calendar.add(Calendar.DAY_OF_WEEK, 2 - intWeek);
- Date monday = calendar.getTime();
- logger.error("_alertLeaderExceptionTotal startDate: " + sdf.format(monday));
- if (intWeek > 6) {
- calendar.add(Calendar.DAY_OF_WEEK, 4);
- endDate = calendar.getTime();
- }
- 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);
- 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();
- AttendanceExceptionLogInfo logInfo = new AttendanceExceptionLogInfo();
- logInfo.setMessageId(msgId);
- logInfo.setPushType(pushTypeEnum);
- try {
- Set<String> alertUserSet = leaders.get(centerNumber);
- String orgName = orgMap.getOrDefault(centerNumber, "中心");
- //中心负责人
- String alertUsers = convertSetToString(alertUserSet);
- if (StringUtils.isBlank(alertUsers)) {
- throw new BOSException(orgName + "的负责人为空!");
- }
- //中心考勤总人数
- Integer attendanceCount = attendanceCountMap.getOrDefault(centerNumber, 0);
- Map<String, Integer> orgExceptionTimes = exceptionCountMap.get(centerNumber);
- //迟到人数
- Integer lateEmployees = orgExceptionTimes.getOrDefault("lateEmployees", 0);
- //早退人数
- Integer earlyLeaveEmployees = orgExceptionTimes.getOrDefault("earlyLeaveEmployees", 0);
- //旷工人数
- Integer absentEmployees = orgExceptionTimes.getOrDefault("absentEmployees", 0);
- //个人原因补卡人数
- //Integer personalRecheckCountEmployees = orgExceptionTimes.getOrDefault("personalRecheckCountEmployees", 0);
- //异常人数
- Integer exceptionEmployees = orgExceptionTimes.getOrDefault("exceptionEmployees", 0);
- //消息内容
- // String content = MessageFormat.format(NOTIFYALERTLEADEREXCEPTIONMSGTEMPLATE,
- // mondayFormat,
- // endDateFormat,
- // orgName,
- // attendanceCount,
- // exceptionEmployees,
- // lateEmployees,
- // earlyLeaveEmployees,
- // absentEmployees
- // );
- //发送异常消息
- JSONObject dingMsgBean = new JSONObject();
- dingMsgBean.put("msgTempCode", "work_notice_01");
- dingMsgBean.put("toAllUser", false);
- dingMsgBean.put("userIdList", alertUsers);
- dingMsgBean.put("source", SOURCE);
- JSONObject param = new JSONObject();
- //消息id
- param.put("msgId", msgId);
- //时间
- param.put("time", mondayFormat + "-" + endDateFormat);
- //中心考勤人数
- param.put("centerNum", attendanceCount);
- //考勤异常人数
- param.put("eorNum", exceptionEmployees);
- //迟到人数
- param.put("lateNum", lateEmployees);
- //早退人数
- param.put("earlyNum", earlyLeaveEmployees);
- //旷工人数
- param.put("hookyNum", absentEmployees);
- 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) {
- logger.error("提醒中心负责人累计异常报错", e);
- }
- //保存消息记录
- iAttendanceExceptionLog.save(logInfo);
- }
- if (logger.isInfoEnabled()) {
- long endTime = System.currentTimeMillis();
- float duration = (endTime - startTime) / 1000f;
- logger.info(String.format("AttendanceExceptionFacadeControllerBean.alertLeaderExceptionTotal end, duration: %fS", duration));
- }
- }
- /**
- * 获取考勤异常数据
- *
- * @param ctx
- * @param startDate 开始日期
- * @param endDate 结束日期
- * @return
- * @throws BOSException
- * @throws EASBizException
- */
- protected Map<String, List<SyncAttendanceDataBean>> getAttendanceExceptionData(
- Context ctx,
- Date startDate,
- Date endDate,
- PushTypeEnum pushType,
- int limit
- ) throws BOSException {
- String sql = getSql(startDate, endDate);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- try {
- IRowSet iRowSet = DBUtil.executeQuery(ctx, sql);
- Map<String, List<SyncAttendanceDataBean>> result = new HashMap<>();
- Map<String, Integer> personExceptionTimes = new HashMap<>();
- if (!PushTypeEnum.CENTERLEADERREMINDER.equals(pushType)) {
- //非中心负责人提醒
- while (iRowSet.next()) {
- //设置考勤结果和次数
- SyncAttendanceDataBean data = setAttendanceResult(iRowSet, sdf);
- int times = data.getTimes();
- String personNumber = data.getEmployeeId();
- //累计员工期间总异常次数
- if (personExceptionTimes.containsKey(personNumber)) {
- Integer i = personExceptionTimes.get(personNumber);
- personExceptionTimes.put(personNumber, i + times);
- } else {
- personExceptionTimes.put(personNumber, times);
- }
- if (!result.containsKey(personNumber)) {
- result.put(personNumber, new ArrayList<>());
- }
- result.get(personNumber).add(data);
- }
- if (PushTypeEnum.EMPLOYEEEXCEPTIONALERT.equals(pushType)) {
- String yearMonth = DateTimeUtils.format(startDate, "yyyy年M月");
- //获取提醒记录
- Set<String> remindRecord = getRemindRecord(ctx, yearMonth);
- //员工累计异常提醒
- for (Map.Entry<String, Integer> entry : personExceptionTimes.entrySet()) {
- if (entry.getValue() < limit || remindRecord.contains(entry.getKey())) {
- //移除没有达到预警上限的数据,获取已经提醒过的人员
- result.remove(entry.getKey());
- }
- }
- }
- }
- return result;
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException(e);
- }
- }
- /**
- * 获取中心考勤异常数据
- *
- * @param ctx
- * @param startDate 开始日期
- * @param endDate 结束日期
- * @return
- * @throws BOSException
- * @throws EASBizException
- */
- protected Map<String, List<SyncAttendanceDataBean>> getAttendanceExceptionDataForLeader(
- Context ctx,
- Date startDate,
- Date endDate,
- Map<String, Map<String, Integer>> exceptionCountMap
- ) throws BOSException {
- String sql = getSql(startDate, endDate);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- Map<String, Map<String, Set<String>>> exceptionData = new HashMap<>();
- try {
- IRowSet iRowSet = DBUtil.executeQuery(ctx, sql);
- Map<String, List<SyncAttendanceDataBean>> result = new HashMap<>();
- while (iRowSet.next()) {
- //设置考勤结果和次数
- 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);
- }
- for (String orgNumber : exceptionData.keySet()) {
- Map<String, Set<String>> orgExceptionData = exceptionData.get(orgNumber);
- Map<String, Integer> orgExceptionTimes = new HashMap<>();
- //迟到人数
- orgExceptionTimes.put("lateEmployees", orgExceptionData.get("lateEmployees").size());
- //早退人数
- orgExceptionTimes.put("earlyLeaveEmployees", orgExceptionData.get("earlyLeaveEmployees").size());
- //旷工人数
- orgExceptionTimes.put("absentEmployees", orgExceptionData.get("absentEmployees").size());
- //个人原因补卡人数
- orgExceptionTimes.put("personalRecheckCountEmployees", orgExceptionData.get("personalRecheckCountEmployees").size());
- //异常人数
- orgExceptionTimes.put("exceptionEmployees", orgExceptionData.get("exceptionEmployees").size());
- exceptionCountMap.put(orgNumber, orgExceptionTimes);
- }
- return result;
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- throw new RuntimeException(e);
- }
- }
- /**
- * 设置考勤结果和次数
- *
- * @param iRowSet
- * @param sdf
- * @throws SQLException
- */
- protected SyncAttendanceDataBean setAttendanceResult(IRowSet iRowSet, SimpleDateFormat sdf) throws SQLException {
- SyncAttendanceDataBean data = new SyncAttendanceDataBean();
- data.setEmployeeId(iRowSet.getString("personNumber"));
- data.setEmployeeName(iRowSet.getString("personName"));
- Date attenceDate = iRowSet.getDate("attenceDate");
- if (attenceDate != null) {
- data.setExceptionDate(sdf.format(attenceDate));
- }
- data.setDepartmentCode(iRowSet.getString("adminOrgNumber"));
- data.setDepartmentName(iRowSet.getString("adminOrgName"));
- data.setDepartmentManagerCode(iRowSet.getString("adminOrgLongNumber"));
- data.setDepartmentSortCode(iRowSet.getString("sortCode"));
- data.setDepartmentManagerName(iRowSet.getString("displayName"));
- StringBuilder attendanceResult = new StringBuilder();
- int times = 0;
- 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("迟到", s19 > 0);
- attendanceFlags.put("早退", s21 > 0);
- attendanceFlags.put("旷工", s23.compareTo(BigDecimal.ZERO) > 0);
- attendanceFlags.put("个人原因补卡次数", s113 > 0);
- for (Map.Entry<String, Boolean> entry : attendanceFlags.entrySet()) {
- if (entry.getValue()) {
- times++;
- attendanceResult.append(entry.getKey()).append("、");
- }
- }
- // 移除最后一个顿号
- if (attendanceResult.length() > 0) {
- attendanceResult.setLength(attendanceResult.length() - 1);
- }
- data.setTimes(times);
- data.setAttendanceResult(attendanceResult.toString());
- return data;
- }
- /**
- * 获取考勤异常查询sql
- *
- * @param startDate
- * @param endDate
- * @return
- * @throws BOSException
- */
- protected String getSql(
- Date startDate,
- Date endDate
- ) throws BOSException {
- if (startDate == null || endDate == null) {
- logger.error("getAttendanceExceptionData startDate or endDate is null");
- throw new BOSException("getAttendanceExceptionData startDate or endDate is null");
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- StringBuilder sql = new StringBuilder()
- .append("select").append("\n")
- .append(" person.fid as personId,").append("\n")
- .append(" person.fnumber as personNumber,").append("\n")
- .append(" person.Fname_l2 as personName,").append("\n")
- .append(" attendanceResult.FAttenceDate as attenceDate,").append("\n")
- .append(" attendanceResult.s19 as s19,").append("\n")
- .append(" attendanceResult.s21 as s21,").append("\n")
- .append(" attendanceResult.s23 as s23,").append("\n")
- .append(" attendanceResult.s113 as s113,").append("\n")
- .append(" adminOrg.fid as adminOrgId,").append("\n")
- .append(" adminOrg.fnumber as adminOrgNumber,").append("\n")
- .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("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("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")
- .append(" and (").append("\n")
- .append(" attendanceResult.s19 > 0").append("\n")
- .append(" or attendanceResult.s21 > 0").append("\n")
- .append(" or attendanceResult.s23 > 0").append("\n")
- .append(" or attendanceResult.S113 > 0").append("\n")
- .append(" );").append("\n");
- if (logger.isInfoEnabled()) {
- logger.info(String.format("AttendanceExceptionFacadeControllerBean.getSql: %s", sql.toString()));
- }
- return sql.toString();
- }
- /**
- * 发送考勤异常消息
- *
- * @param dingMsgBean
- * @param logInfo
- * @throws BOSException
- */
- protected void sendAttendanceExceptionMsg(
- JSONObject dingMsgBean,
- AttendanceExceptionLogInfo logInfo
- ) throws BOSException {
- try {
- String url = propt.getProperty("sendDingMsgUrl");
- if (url == null || url.isEmpty()) {
- logger.error("pushAttendanceExceptionData url is null");
- throw new BOSException("pushAttendanceExceptionData url is null");
- }
- logger.error("pushAttendanceExceptionData url: " + url);
- if (dingMsgBean == null) {
- logger.error("pushAttendanceExceptionData dingMsgBean is null");
- throw new BOSException("pushAttendanceExceptionData dingMsgBean is null");
- }
- String params = dingMsgBean.toJSONString();
- logInfo.setMessageRequest(params);
- OkHttpClient client = new OkHttpClient();
- MediaType mediaType = MediaType.parse("application/json");
- RequestBody body = RequestBody.create(mediaType, params);
- Request request = new Request.Builder()
- .url(url)
- .post(body)
- .addHeader("Accept", "*/*")
- .addHeader("Accept-Encoding", "gzip, deflate, br")
- .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
- .addHeader("Connection", "keep-alive")
- .addHeader("Content-Type", "application/json")
- .build();
- Response response = client.newCall(request).execute();
- logger.error("response----" + response.isSuccessful());
- if (response.isSuccessful()) {
- String resultBody = response.body().string();
- logInfo.setMessageResponse(resultBody);
- logger.error("resultBody----" + resultBody);
- JSONObject result = JSONObject.parseObject(resultBody);
- if (result.getBoolean("success")) {
- logInfo.setPushStatus(CallStatusEnum.success);
- } else {
- //推送失败
- throw new BOSException(result.getString("msg"));
- }
- } else {
- throw new BOSException("接口请求超时");
- }
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- logInfo.setPushStatus(CallStatusEnum.failure);
- logInfo.setPushResult("发送考勤异常消息报错: " + e.getMessage());
- throw new BOSException(e);
- }
- }
- /**
- * 推送考勤异常数据
- *
- * @param list
- * @param logInfo
- * @throws BOSException
- */
- protected void pushAttendanceExceptionData(
- List list,
- AttendanceExceptionLogInfo logInfo
- ) throws BOSException {
- try {
- String url = propt.getProperty("syncAttendanceDataUrl");
- if (url == null || url.isEmpty()) {
- logger.error("pushAttendanceExceptionData url is null");
- throw new BOSException("pushAttendanceExceptionData url is null");
- }
- logger.error("pushAttendanceExceptionData url: " + url);
- if (list == null || list.size() <= 0) {
- logger.error("pushAttendanceExceptionData list is null");
- throw new BOSException("pushAttendanceExceptionData list is null");
- }
- String params = JSON.toJSONString(list);
- logInfo.setDataPushRequest(params);
- OkHttpClient client = new OkHttpClient();
- MediaType mediaType = MediaType.parse("application/json");
- RequestBody body = RequestBody.create(mediaType, params);
- Request request = new Request.Builder()
- .url(url)
- .post(body)
- .addHeader("Accept", "*/*")
- .addHeader("Accept-Encoding", "gzip, deflate, br")
- .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
- .addHeader("Connection", "keep-alive")
- .addHeader("Content-Type", "application/json")
- .build();
- Response response = client.newCall(request).execute();
- if (response.isSuccessful()) {
- String resultBody = response.body().string();
- logInfo.setDataPushResponse(resultBody);
- logger.error("resultBody----" + resultBody);
- JSONObject result = JSONObject.parseObject(resultBody);
- if (result.getBoolean("success")) {
- logInfo.setPushStatus(CallStatusEnum.success);
- } else {
- //推送失败
- throw new BOSException(result.getString("msg"));
- }
- } else {
- throw new BOSException("接口请求超时");
- }
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- logInfo.setPushStatus(CallStatusEnum.failure);
- logInfo.setPushResult("推送考勤数据报错: " + e.getMessage());
- throw new BOSException(e);
- }
- }
- /**
- * set转字符串
- *
- * @param set
- * @return
- */
- public String convertSetToString(Set set) {
- if (set != null && set.size() > 0) {
- Iterator iter = set.iterator();
- StringBuffer sql = new StringBuffer();
- while (iter.hasNext()) {
- sql.append(iter.next()).append(",");
- }
- sql.deleteCharAt(sql.length() - 1);
- return sql.toString();
- } else {
- return "";
- }
- }
- /**
- * 获取各个中心考勤总人数
- *
- * @param ctx
- * @return
- */
- public Map<String, Integer> getAttendanceCount(Context ctx) {
- Map<String, Integer> attendanceCountMap = new HashMap<>();
- 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);
- 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);
- }
- }
- } catch (BOSException e) {
- logger.error("获取各个中心考勤总人数报错: " + 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<>();
- 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"));
- 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);
- }
- } catch (Exception e) {
- logger.error("获取中心名称报错: " + e.getMessage(), e);
- throw new RuntimeException(e);
- }
- return orgMap;
- }
- /**
- * 获取提醒记录
- *
- * @param ctx
- * @param yearMonth
- * @return
- */
- private Set<String> getRemindRecord(Context ctx, String yearMonth) {
- Set<String> remindRecordSet = new HashSet<>();
- try {
- String querySql = "select personNumber from T_Remind_Record where yearMonth=?";
- IRowSet iRowSet = DBUtil.executeQuery(ctx, querySql, new Object[]{yearMonth});
- while (iRowSet.next()) {
- remindRecordSet.add(iRowSet.getString("personNumber"));
- }
- } catch (Exception e) {
- logger.error("获取提醒记录报错: " + e.getMessage(), e);
- throw new RuntimeException(e);
- }
- return remindRecordSet;
- }
- /**
- * 新增提醒记录
- *
- * @param ctx
- * @param yearMonth
- */
- private void addRemindRecord(Context ctx, String yearMonth, String personNumber) {
- try {
- String querySql = "insert into T_Remind_Record(yearMonth,personNumber) values (?,?)";
- DBUtil.execute(ctx, querySql, new Object[]{yearMonth, personNumber});
- } catch (Exception e) {
- logger.error("新增提醒记录报错: " + e.getMessage(), e);
- throw new RuntimeException("新增提醒记录报错: " + e.getMessage());
- }
- }
- }
|