package com.engine.attendance.workflow.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.engine.attendance.workflow.cmd.GetCqSummarySearchConditionCmd; import com.engine.attendance.workflow.service.AttendanceSummaryService; import com.engine.common.util.DbTools; import com.engine.core.impl.Service; import com.engine.kq.biz.KQHolidaySetBiz; import com.engine.kq.biz.KQReportBiz; import com.engine.kq.util.PageUidFactory; import weaver.backup.logging.Logger; import weaver.conn.RecordSet; import weaver.general.TimeUtil; import weaver.general.Util; import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.SubCompanyComInfo; import weaver.hrm.job.JobTitlesComInfo; import weaver.hrm.resource.ResourceComInfo; import weaver.systemExpAndImp.logging.LoggerFactory; import weaver.systeminfo.SystemEnv; import java.time.LocalDate; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * @Author: sy * @Description: 出勤汇总实现类 * @Date: 2024/3/19 **/ public class AttendanceSummaryServiceImpl extends Service implements AttendanceSummaryService { private Logger log = LoggerFactory.getLogger(this.getClass()); /** * 新增出勤汇总 * 基于入参中的出勤汇总主表id,获取主表信息,根据主表中的分部、考勤时间区间等字段, * 对出勤结果表、补打卡表、出勤津贴表中数据根据分布和时间区间筛选后, * 根据分部、部门、人员id、考勤项目进行分组统计 * @param params * @return */ @Override public Map addAttendanceSummary(Map params) { ExecutorService taskExecutor = Executors.newCachedThreadPool(); taskExecutor.execute(() -> { String mainIds = Util.null2String(params.get("mainIds")); log.info("mainids : " + mainIds); List mainIdList = new ArrayList<>(); if (!mainIds.equals("")) { mainIdList = Arrays.asList(mainIds.split(",")); } for (String mainId : mainIdList) { List> addList = new ArrayList<>(); //查询出勤汇总主表信息 String sql = "select * from uf_jcl_kq_cqhz where id="+mainId; Map data = DbTools.getSqlToMap(sql); String subCompany = Util.null2String(data.get("fb")); String startDate = Util.null2String(data.get("ksrq")); String endDate = Util.null2String(data.get("jsrq")); log.info("subCompany : " + subCompany + ", startDate : " + startDate + ", endDate : " + endDate); if (!subCompany.equals("") && !startDate.equals("") && !endDate.equals("")) { String subCompanyListStr = SubCompanyComInfo.getAllChildSubcompanyId(subCompany, subCompany); //汇总出勤结果表、补打卡表、出勤津贴表数据 //出勤结果表 List> cqAddList = getCqAddList(mainId, subCompanyListStr, startDate, endDate); log.info("cqAddList_size : " + cqAddList.size()); if (cqAddList.size() > 0) { addList.addAll(cqAddList); } //补打卡表 List> bdkAddList = getBdkAddList(mainId, startDate, endDate); log.info("bdkAddList_size : " + bdkAddList.size()); if (bdkAddList.size() > 0) { addList.addAll(bdkAddList); } //出勤津贴表 List> cqjtAddList = getCqjtAddList(mainId, startDate, endDate); log.info("cqjtAddList_size : " + cqjtAddList.size()); if (cqjtAddList.size() > 0) { addList.addAll(cqjtAddList); } log.info("addList_size : " + addList.size()); //删除已有汇总数据 String delSql = "delete from uf_jcl_kq_cqhz_dt1 where mainid = " + mainId; boolean delSign = DbTools.update(delSql); log.info("delSign : " + delSign + ", delSql : " + delSql); //插入汇总数据 List dataList = new ArrayList<>(); String insertSql = " insert into uf_jcl_kq_cqhz_dt1(mainid,ry,kqxm," + " lc,lf,ls,lt," + " gzfb,gzbm) values(?,?,?,?,?,?,?,?,?)"; for (Map map : addList) { List list = new ArrayList<>(); list.add(mainId); list.add(map.get("ry")); list.add(map.get("kqxm")); list.add(map.get("lc")); list.add(map.get("lf")); list.add(map.get("ls")); list.add(map.get("lt")); list.add(map.get("gsfb")); list.add(map.get("gsbm")); dataList.add(list); } if(dataList.size()>0){ RecordSet rs = new RecordSet(); log.info("addlist :[{}]", (Throwable) dataList); boolean insertSign =rs.executeBatchSql(insertSql,dataList); log.info("insertSign : " + insertSign); } } } }); return null; } @Override public Map getCqSummaryReport(Map params) { Map retmap = new HashMap(); try{ String pageUid = PageUidFactory.getHrmPageUid("CqSummaryReport"); SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); DepartmentComInfo departmentComInfo = new DepartmentComInfo(); ResourceComInfo resourceComInfo = new ResourceComInfo(); JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial")); String fromDate = Util.null2String(jsonObj.get("fromDate")); String toDate = Util.null2String(jsonObj.get("toDate")); String typeSelect =Util.null2String(jsonObj.get("typeselect")); if(typeSelect.length()==0) {typeSelect = "3";} if(!typeSelect.equals("") && !typeSelect.equals("0")&& !typeSelect.equals("6")){ if(typeSelect.equals("1")){ fromDate = TimeUtil.getCurrentDateString(); toDate = TimeUtil.getCurrentDateString(); }else{ fromDate = TimeUtil.getDateByOption(typeSelect,"0"); toDate = TimeUtil.getDateByOption(typeSelect,"1"); } } //人员状态 String status = Util.null2String(jsonObj.get("status")); String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); String departmentId = Util.null2String(jsonObj.get("departmentId")); String resourceId = Util.null2String(jsonObj.get("resourceId")); log.info("status : " + status + ", subCompanyId : " + subCompanyId + ", departmentId : " + departmentId + ", resourceId : " + resourceId); String allLevel = Util.null2String(jsonObj.get("allLevel")); String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); String viewScope = Util.null2String(jsonObj.get("viewScope")); String isFromMyAttendance = Util.null2String(jsonObj.get("isFromMyAttendance"));//是否是来自我的考勤的请求,如果是,不加载考勤报表权限共享的限制,不然我的考勤会提示无权限 int pageIndex = Util.getIntValue(Util.null2String(jsonObj.get("pageIndex")), 1); int pageSize = KQReportBiz.getPageSize(Util.null2String(jsonObj.get("pageSize")),pageUid,user.getUID()); int count = 0; int pageCount = 0; int isHavePre = 0; int isHaveNext = 0; //设置列头 List columns = new ArrayList(); Map column = null; //人员相关信息 column = new HashMap<>(); column.put("title", SystemEnv.getHtmlLabelName(413, user.getLanguage())); //姓名 column.put("unit", ""); column.put("dataIndex", "lastname"); column.put("type", "lastname"); column.put("key", "lastname"); column.put("rowSpan", 3); column.put("width", 105); column.put("showDetial", "1"); columns.add(column); column = new HashMap<>(); column.put("title", SystemEnv.getHtmlLabelName(528842, user.getLanguage())); //分部 column.put("unit", ""); column.put("dataIndex", "subcompany"); column.put("type", "subcompany"); column.put("key", "subcompany"); column.put("rowSpan", 3); column.put("width", 105); column.put("showDetial", "1"); columns.add(column); column = new HashMap<>(); column.put("title", SystemEnv.getHtmlLabelName(528843, user.getLanguage())); //部门 column.put("unit", ""); column.put("dataIndex", "department"); column.put("type", "department"); column.put("key", "department"); column.put("rowSpan", 3); column.put("width", 105); column.put("showDetial", "1"); columns.add(column); //考勤项目 String kqxmSql = "select * from uf_jcl_kq_kqxm"; List> kqxmDates = DbTools.getSqlToList(kqxmSql); for(Map kqxm : kqxmDates) { String unit = getKqxmUnit(Util.null2String(kqxm.get("hsdw"))); column = new HashMap<>(); column.put("title", kqxm.get("mc")); column.put("unit", unit); column.put("dataIndex", "kqxm" + kqxm.get("id")); column.put("type", "kqxm" + kqxm.get("id")); column.put("key", "kqxm" + kqxm.get("id")); column.put("rowSpan", 3); column.put("width", 105); column.put("showDetial", "1"); columns.add(column); } //获取列表结果,typeSelect为9、10时查询出勤汇总明细表数据,其他则生成临时汇总数据 List> dtDates = null; LocalDate targetDate = LocalDate.now(); // 获取当前日期 log.info("currentDate : " + targetDate); if (typeSelect.equals("9")) { String targetYear = String.valueOf(targetDate.getYear()); String targetMonth = targetDate.getMonth().toString(); log.info("targetYear : " + targetYear + ", targetMonth : " + targetMonth); dtDates = getDtDates(targetYear, targetMonth, subCompanyId, departmentId, resourceId, status); } else if (typeSelect.equals("10")) { targetDate = targetDate.minusMonths(1); String targetYear = String.valueOf(targetDate.getYear()); String targetMonth = targetDate.getMonth().toString(); log.info("targetYear : " + targetYear + ", targetMonth : " + targetMonth); dtDates = getDtDates(targetYear, targetMonth, subCompanyId, departmentId, resourceId, status); } else { //调用临时汇总数据方法,生成数据 dtDates = getTemAttendanceSummary(jsonObj); } log.info("dtDates_size : " + (dtDates==null ? "null" : dtDates.size())); //处理明细表数据,分组生成列表数据 Map> groupData = new HashMap<>(); for (Map map : dtDates) { String groupKey = map.get("ry") + "_" + map.get("gzfb") + "_" + map.get("gzbm"); Map itemMap = new HashMap<>(); if (groupData.get(groupKey) == null) { //尚未存在则新建,加入 itemMap.put("resourceId", map.get("ry").toString()); itemMap.put("lastname", resourceComInfo.getLastname(Util.null2String(map.get("ry")))); itemMap.put("subcompanyId", map.get("gzfb").toString()); itemMap.put("subcompany", subCompanyComInfo.getSubcompanyname(Util.null2String(map.get("gzfb")))); itemMap.put("departmentId", map.get("gzbm").toString()); itemMap.put("department", departmentComInfo.getDepartmentName(Util.null2String(map.get("gzbm")))); //设置考勤项目累计数值,累天、累时、累分最多有一个有值,都没有则取累次 String cumulativeValue = Util.null2String(map.get("lt")) + Util.null2String(map.get("ls")) + Util.null2String(map.get("lf")); if (!cumulativeValue.equals("")) { itemMap.put("kqxm" + "_" + map.get("kqxm").toString(), cumulativeValue); } else { itemMap.put("kqxm" + "_" + map.get("kqxm").toString(), map.get("lc").toString()); } groupData.put(groupKey, itemMap); } else { //已存在则新增元素 itemMap = groupData.get(groupKey); //设置考勤项目累计数值,累天、累时、累分最多有一个有值,都没有则取累次 String cumulativeValue = Util.null2String(map.get("lt")) + Util.null2String(map.get("ls")) + Util.null2String(map.get("lf")); if (!cumulativeValue.equals("")) { itemMap.put("kqxm" + "_" + map.get("kqxm").toString(), cumulativeValue); } else { itemMap.put("kqxm" + "_" + map.get("kqxm").toString(), map.get("lc").toString()); } groupData.put(groupKey, itemMap); } } //获取最终的list,根据人员id排序 List> dataList = new ArrayList<>(groupData.values()); Collections.sort(dataList, new Comparator>() { @Override public int compare(Map o1, Map o2) { String str1 = o1.get("resourceId").toString(); String str2 = o2.get("resourceId").toString(); //str1在前,str2在后,默认升序 return str1.compareTo(str2); } }); //分页处理 int start = pageIndex * pageSize; int end = Math.min((pageIndex + 1) * pageSize, dataList.size()); List> resultList = dataList.subList(start, end); count = dataList.size(); if (count <= 0) { pageCount = 0; } else { pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0); } isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0; isHavePre = (pageIndex - 1 >= 1) ? 1 : 0; List lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate); retmap.put("holidays", lsHolidays); retmap.put("columns",columns); retmap.put("datas",resultList); retmap.put("pagesize", pageSize); retmap.put("pageindex", pageIndex); retmap.put("count", count); retmap.put("pagecount", pageCount); retmap.put("ishavepre", isHavePre); retmap.put("ishavenext", isHaveNext); }catch (Exception e){ log.info(e); } return retmap; } @Override public Map getCqSummarySearchCondition(Map params) { return this.commandExecutor.execute(new GetCqSummarySearchConditionCmd(params, user)); } private String getKqxmUnit(String hsdw) { if (hsdw.equals("0")) { return SystemEnv.getHtmlLabelName(518514, user.getLanguage()); //天 } else if (hsdw.equals("1")) { return SystemEnv.getHtmlLabelName(518515, user.getLanguage()); //小时 } else if (hsdw.equals("2")) { return SystemEnv.getHtmlLabelName(518516, user.getLanguage()); //分钟 } else if (hsdw.equals("3")) { return SystemEnv.getHtmlLabelName(18083, user.getLanguage()); //次 } else { return ""; } } private List> getDtDates(String targetYear, String targetMonth, String status, String subCompanyIds, String depIds, String empIds) { String mainListSql = "select * from uf_jcl_kq_cqhz where nd= " + targetYear + " and yf = " + targetMonth; List> mainDates = DbTools.getSqlToList(mainListSql); List mainIds = new ArrayList<>(); for (Map map : mainDates) { mainIds.add(map.get("id").toString()); } log.info("mainIds : " + mainIds); String dtListSql = "select * from uf_jcl_kq_cqhz_dt1 a left join hrmresource b on a.ry = b.id where 1=1"; if (!status.equals("") && !status.equals("9")) { dtListSql = dtListSql + " and b.status = " + status; } if (!subCompanyIds.equals("")) { dtListSql = dtListSql + " and a.gzfb in (" + subCompanyIds + ")"; } if (!depIds.equals("")) { dtListSql = dtListSql + " and a.gzbm in (" + depIds + ")"; } if (!empIds.equals("")) { dtListSql = dtListSql + " and a.ry in (" + empIds + ")"; } if (mainIds.size() > 0) { dtListSql = dtListSql + " and a.mainid in (" + String.join(",", mainIds) + ")"; List> dtDates = DbTools.getSqlToList(dtListSql); log.info("dtDates_size : " + dtDates.size() + ", dtListSql : " + dtListSql); return dtDates; } else { return null; } } /** * 获取临时出勤汇总数据 * 基于入参中分部、部门、人员id、人员状态、考勤时间区间等字段, * 对出勤结果表、补打卡表、出勤津贴表中数据根据分布和时间区间筛选后, * 根据分部、部门、人员id、考勤项目进行分组统计 * @param params * @return */ public List> getTemAttendanceSummary(Map params) { log.info("params : " + params); List> addList = new ArrayList<>(); //处理筛选条件 //时间范围,今天-1,本周-2,本月-3,本季-4,本年-5,指定日期范围-6,上个月-7,上一年-8 String dateRange = Util.null2String(params.get("typeselect"));//时间范围 String startDate = Util.null2String(params.get("fromDate")); String endDate = Util.null2String(params.get("toDate")); if (dateRange.length() == 0) { dateRange = "3"; } if (!dateRange.equals("") && !dateRange.equals("0") && !dateRange.equals("6")) { if (dateRange.equals("1")) { startDate = TimeUtil.getCurrentDateString(); endDate = TimeUtil.getCurrentDateString(); } else { startDate = TimeUtil.getDateByOption(dateRange, "0"); endDate = TimeUtil.getDateByOption(dateRange, "1"); } } //查看范围,总部-0,分部-1,部门-2,人员-3 String viewRange = Util.null2String(params.get("viewScope"));//查看范围 String subCompanyIds = Util.null2String(params.get("subCompanyId"));//可以多个分部id,以,分隔 String departmentIds = Util.null2String(params.get("departmentId"));//可以多个部门id,以,分隔 String empIds = Util.null2String(params.get("resourceId"));//可以多个人员id,以,分隔 //人员状态,试用-0,正式-1,临时-2,试用延期-3,解聘-4,离职-5,退休-6,无效-7,在职-8,全部-9 String empStatus = Util.null2String(params.get("status"));//人员状态 log.info("startDate : " + startDate + ", endDate : " + endDate + ", subCompanyIds : " + subCompanyIds + ", departmentIds : " + departmentIds + ", empIds : " + empIds + ", empStatus : " + empStatus); if (!startDate.equals("") && !endDate.equals("")) { //临时汇总出勤结果表、补打卡表、出勤津贴表数据 //出勤结果表 List> cqAddList = getTemCqAddList(startDate, endDate, subCompanyIds, departmentIds, empIds, empStatus); log.info("cqAddList_size : " + cqAddList.size()); if (cqAddList.size() > 0) { addList.addAll(cqAddList); } //补打卡表 List> bdkAddList = getTemBdkAddList(startDate, endDate, subCompanyIds, departmentIds, empIds, empStatus); log.info("bdkAddList_size : " + bdkAddList.size()); if (bdkAddList.size() > 0) { addList.addAll(bdkAddList); } //出勤津贴表 List> cqjtAddList = getTemCqjtAddList(startDate, endDate, subCompanyIds, departmentIds, empIds, empStatus); log.info("cqjtAddList_size : " + cqjtAddList.size()); if (cqjtAddList.size() > 0) { addList.addAll(cqjtAddList); } } return addList; } //汇总出勤结果表 public List> getCqAddList(String mainId, String subCompanyListStr, String startDate, String endDate) { String cqSql = "select * from uf_jcl_kq_cqjg where fbid in (" + subCompanyListStr + ") and rq >= '" + startDate +"'" + " and rq <= '" + endDate +"'"; List> cqDates = DbTools.getSqlToList(cqSql); //先根据分部、部门、人员、项目分组 Map>> toDealCqDataWithGroup = new HashMap<>(); for (Map map : cqDates) { //出勤状态 String cqzt = Util.null2String(map.get("cqzt")); if (!cqzt.equals("")) { //匹配出勤状态对应的考勤项目id String kqxmId = cqzt.equals("0") ? "1" : "5"; String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + kqxmId; Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", kqxmId); itemMap.put("sc", "1"); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } //日期类型 String rqlx = Util.null2String(map.get("rqlx")); if (!rqlx.equals("")) { //匹配日期类型对应的考勤项目id String kqxmId = null; if (rqlx.equals("0") || rqlx.equals("4")) { kqxmId = "2"; } else if (rqlx.equals("2") || rqlx.equals("3")) { kqxmId = "3"; } else if (rqlx.equals("1")) { kqxmId = "4"; } String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + kqxmId; Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", kqxmId); itemMap.put("sc", "1"); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } //项目1 if (!Util.null2String(map.get("xm1")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm1"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm1")); itemMap.put("sc", map.get("sc1")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目2 if (!Util.null2String(map.get("xm2")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm2"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm2")); itemMap.put("sc", map.get("sc2")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目3 if (!Util.null2String(map.get("xm3")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm3"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm3")); itemMap.put("sc", map.get("sc3")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目4 if (!Util.null2String(map.get("xm4")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm4"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm4")); itemMap.put("sc", map.get("sc4")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目5 if (!Util.null2String(map.get("xm5")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm5"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm5")); itemMap.put("sc", map.get("sc5")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目6 if (!Util.null2String(map.get("xm6")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm6"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm6")); itemMap.put("sc", map.get("sc6")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目7 if (!Util.null2String(map.get("xm7")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm7"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm7")); itemMap.put("sc", map.get("sc7")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目8 if (!Util.null2String(map.get("xm8")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm8"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm8")); itemMap.put("sc", map.get("sc8")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } } //处理分组好的数据 List> cqAddList = new ArrayList<>(); for(List> list : toDealCqDataWithGroup.values()) { String ry = list.get(0).get("ygid").toString(); String kqxm = list.get(0).get("xm").toString(); String gsfb = list.get(0).get("fbid").toString(); String gsbm = list.get(0).get("bm").toString(); int num = 0; double time = 0; //查询考勤项目核算单位:天,小时,分钟,次,即0,1,2,3 String kqxmSql = "select * from uf_jcl_kq_kqxm where id = " + kqxm; Map kqxmData = DbTools.getSqlToMap(kqxmSql); String accountUnit = Util.null2String(kqxmData.get("hsdw")); //汇总区间数据 for (Map map : list) { if (!accountUnit.equals("3")) { num++; double sc = Util.null2String(map.get("sc")).equals("") ? 0 : Double.parseDouble(map.get("sc").toString()); time += sc; } else { num ++; } } //设置出勤汇总子表数据 Map itemMap = new HashMap<>(); itemMap.put("mainid", mainId); itemMap.put("ry", ry); itemMap.put("kqxm", kqxm); itemMap.put("gsfb", gsfb); itemMap.put("gsbm", gsbm); itemMap.put("lc", String.valueOf(num)); if (accountUnit.equals("0")) { itemMap.put("lt", String.valueOf(time)); } if (accountUnit.equals("1")) { itemMap.put("ls", String.valueOf(time)); } if (accountUnit.equals("2")) { itemMap.put("lf", String.valueOf(time)); } cqAddList.add(itemMap); } return cqAddList; } //汇总补打卡表 public List> getBdkAddList(String mainId, String startDate, String endDate) { String bdkSql = "select a.*, b.fbid, b.bm from uf_jcl_kq_bdkjl a left join uf_jcl_kq_cqjg b on a.bdkry = b.ygid and a.dkrq = b.rq where a.dkrq >= '" + startDate +"'" + " and a.dkrq <= '" + endDate +"'"; List> bdkDates = DbTools.getSqlToList(bdkSql); //先根据分部、部门、人员、项目分组 Map>> toDealBdkDataWithGroup = new HashMap<>(); for (Map map : bdkDates) { //补打卡项目 if (!Util.null2String(map.get("bdklx")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("bdkry") + "_" + map.get("bdklx"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("bdkry", map.get("bdkry")); itemMap.put("xm", map.get("bdklx")); if (toDealBdkDataWithGroup.get(groupKey) != null) { toDealBdkDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealBdkDataWithGroup.put(groupKey, list); } } } //处理分组好的数据 List> bdkAddList = new ArrayList<>(); for(List> list : toDealBdkDataWithGroup.values()) { String ry = list.get(0).get("bdkry").toString(); String kqxm = list.get(0).get("xm").toString(); String gsfb = list.get(0).get("fbid").toString(); String gsbm = list.get(0).get("bm").toString(); int num = list.size(); //设置出勤汇总子表数据 Map itemMap = new HashMap<>(); itemMap.put("mainid", mainId); itemMap.put("ry", ry); itemMap.put("kqxm", kqxm); itemMap.put("gsfb", gsfb); itemMap.put("gsbm", gsbm); itemMap.put("lc", String.valueOf(num)); bdkAddList.add(itemMap); } return bdkAddList; } //汇总出勤津贴表 public List> getCqjtAddList(String mainId, String startDate, String endDate) { String cqjtSql = "select a.*, b.fbid, b.bm from uf_jcl_kq_cqjt a left join uf_jcl_kq_cqjg b on a.yg = b.ygid and a.rq = b.rq where a.rq >= '" + startDate +"'" + " and a.rq <= '" + endDate+"'"; List> cqjtDates = DbTools.getSqlToList(cqjtSql); //先根据分部、部门、人员、项目分组 Map>> toDealCqjtDataWithGroup = new HashMap<>(); for (Map map : cqjtDates) { //津贴类型 if (!Util.null2String(map.get("jtlx")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("bdkry") + "_" + map.get("bdklx"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("yg", map.get("yg")); itemMap.put("xm", map.get("jtlx")); if (toDealCqjtDataWithGroup.get(groupKey) != null) { toDealCqjtDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqjtDataWithGroup.put(groupKey, list); } } } //处理分组好的数据 List> cqjtAddList = new ArrayList<>(); for(List> list : toDealCqjtDataWithGroup.values()) { String ry = list.get(0).get("yg").toString(); String kqxm = list.get(0).get("xm").toString(); String gsfb = list.get(0).get("fbid").toString(); String gsbm = list.get(0).get("bm").toString(); int num = list.size(); double time = 0; //查询考勤项目核算单位:天,小时,分钟,次,即0,1,2,3 String kqxmSql = "select * from uf_jcl_kq_kqxm where id = " + kqxm; Map kqxmData = DbTools.getSqlToMap(kqxmSql); String accountUnit = Util.null2String(kqxmData.get("hsdw")); //汇总区间数据 for (Map map : list) { if (!accountUnit.equals("3")) { double sc = Util.null2String(map.get("sc")).equals("") ? 0 : Double.parseDouble(map.get("sc").toString()); time += sc; } } //设置出勤汇总子表数据 Map itemMap = new HashMap<>(); itemMap.put("mainid", mainId); itemMap.put("ry", ry); itemMap.put("kqxm", kqxm); itemMap.put("gsfb", gsfb); itemMap.put("gsbm", gsbm); itemMap.put("lc", String.valueOf(num)); if (accountUnit.equals("0")) { itemMap.put("lt", String.valueOf(time)); } if (accountUnit.equals("1")) { itemMap.put("ls", String.valueOf(time)); } if (accountUnit.equals("2")) { itemMap.put("lf", String.valueOf(time)); } cqjtAddList.add(itemMap); } return cqjtAddList; } //临时汇总出勤结果表 private List> getTemCqAddList(String startDate, String endDate, String subCompanyIds, String departmentIds, String empIds, String empStatus) { String cqSql = "select a.* from uf_jcl_kq_cqjg a left join hrmresource b on a.ygid = b.id where b.status = " + empStatus + " and a.rq >= '" + startDate +"'" + " and a.rq <= '" + endDate +"'"; if (!subCompanyIds.equals("")) { cqSql = cqSql + " and a.fbid in (" + subCompanyIds + ")"; } if (!departmentIds.equals("")) { cqSql = cqSql + " and a.bm in (" + departmentIds + ")"; } if (!empIds.equals("")) { cqSql = cqSql + " and a.ygid in (" + empIds + ")"; } List> cqDates = DbTools.getSqlToList(cqSql); //先根据分部、部门、人员、项目分组 Map>> toDealCqDataWithGroup = new HashMap<>(); for (Map map : cqDates) { //出勤状态 String cqzt = Util.null2String(map.get("cqzt")); if (!cqzt.equals("")) { //匹配出勤状态对应的考勤项目id String kqxmId = cqzt.equals("0") ? "1" : "5"; String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + kqxmId; Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", kqxmId); itemMap.put("sc", "1"); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } //日期类型 String rqlx = Util.null2String(map.get("rqlx")); if (!rqlx.equals("")) { //匹配日期类型对应的考勤项目id String kqxmId = null; if (rqlx.equals("0") || rqlx.equals("4")) { kqxmId = "2"; } else if (rqlx.equals("2") || rqlx.equals("3")) { kqxmId = "3"; } else if (rqlx.equals("1")) { kqxmId = "4"; } String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + kqxmId; Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", kqxmId); itemMap.put("sc", "1"); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } //项目1 if (!Util.null2String(map.get("xm1")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm1"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm1")); itemMap.put("sc", map.get("sc1")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目2 if (!Util.null2String(map.get("xm2")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm2"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm2")); itemMap.put("sc", map.get("sc2")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目3 if (!Util.null2String(map.get("xm3")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm3"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm3")); itemMap.put("sc", map.get("sc3")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目4 if (!Util.null2String(map.get("xm4")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm4"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm4")); itemMap.put("sc", map.get("sc4")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目5 if (!Util.null2String(map.get("xm5")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm5"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm5")); itemMap.put("sc", map.get("sc5")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目6 if (!Util.null2String(map.get("xm6")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm6"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm6")); itemMap.put("sc", map.get("sc6")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目7 if (!Util.null2String(map.get("xm7")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm7"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm7")); itemMap.put("sc", map.get("sc7")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } else { continue; } //项目8 if (!Util.null2String(map.get("xm8")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("ygid") + "_" + map.get("xm8"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("ygid", map.get("ygid")); itemMap.put("xm", map.get("xm8")); itemMap.put("sc", map.get("sc8")); if (toDealCqDataWithGroup.get(groupKey) != null) { toDealCqDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqDataWithGroup.put(groupKey, list); } } } //处理分组好的数据 List> cqAddList = new ArrayList<>(); for(List> list : toDealCqDataWithGroup.values()) { String ry = list.get(0).get("ygid").toString(); String kqxm = list.get(0).get("xm").toString(); String gsfb = list.get(0).get("fbid").toString(); String gsbm = list.get(0).get("bm").toString(); int num = 0; double time = 0; //查询考勤项目核算单位:天,小时,分钟,次,即0,1,2,3 String kqxmSql = "select * from uf_jcl_kq_kqxm where id = " + kqxm; Map kqxmData = DbTools.getSqlToMap(kqxmSql); String accountUnit = Util.null2String(kqxmData.get("hsdw")); //汇总区间数据 for (Map map : list) { if (!accountUnit.equals("3")) { num++; double sc = Util.null2String(map.get("sc")).equals("") ? 0 : Double.parseDouble(map.get("sc").toString()); time += sc; } else { num ++; } } //设置出勤汇总子表数据 Map itemMap = new HashMap<>(); itemMap.put("ry", ry); itemMap.put("kqxm", kqxm); itemMap.put("gsfb", gsfb); itemMap.put("gsbm", gsbm); itemMap.put("lc", String.valueOf(num)); if (accountUnit.equals("0")) { itemMap.put("lt", String.valueOf(time)); } if (accountUnit.equals("1")) { itemMap.put("ls", String.valueOf(time)); } if (accountUnit.equals("2")) { itemMap.put("lf", String.valueOf(time)); } cqAddList.add(itemMap); } return cqAddList; } //临时汇总补打卡表 private List> getTemBdkAddList(String startDate, String endDate, String subCompanyIds, String departmentIds, String empIds, String empStatus) { String bdkSql = "select a.*, b.fbid, b.bm from uf_jcl_kq_bdkjl a " + "left join uf_jcl_kq_cqjg b on a.bdkry = b.ygid and a.dkrq = b.rq " + "left join hrmresource c on a.bdkry = c.id " + "where c.status = " + empStatus + " and a.dkrq >= '" + startDate +"'" + " and a.dkrq <= '" + endDate +"'"; if (!subCompanyIds.equals("")) { bdkSql = bdkSql + " and b.fbid in (" + subCompanyIds + ")"; } if (!departmentIds.equals("")) { bdkSql = bdkSql + " and b.bm in (" + departmentIds + ")"; } if (!empIds.equals("")) { bdkSql = bdkSql + " and a.bdkry in (" + empIds + ")"; } List> bdkDates = DbTools.getSqlToList(bdkSql); //先根据分部、部门、人员、项目分组 Map>> toDealBdkDataWithGroup = new HashMap<>(); for (Map map : bdkDates) { //补打卡项目 if (!Util.null2String(map.get("bdklx")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("bdkry") + "_" + map.get("bdklx"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("bdkry", map.get("bdkry")); itemMap.put("xm", map.get("bdklx")); if (toDealBdkDataWithGroup.get(groupKey) != null) { toDealBdkDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealBdkDataWithGroup.put(groupKey, list); } } } //处理分组好的数据 List> bdkAddList = new ArrayList<>(); for(List> list : toDealBdkDataWithGroup.values()) { String ry = list.get(0).get("bdkry").toString(); String kqxm = list.get(0).get("xm").toString(); String gsfb = list.get(0).get("fbid").toString(); String gsbm = list.get(0).get("bm").toString(); int num = list.size(); //设置出勤汇总子表数据 Map itemMap = new HashMap<>(); itemMap.put("ry", ry); itemMap.put("kqxm", kqxm); itemMap.put("gsfb", gsfb); itemMap.put("gsbm", gsbm); itemMap.put("lc", String.valueOf(num)); bdkAddList.add(itemMap); } return bdkAddList; } //临时汇总出勤津贴表 private List> getTemCqjtAddList(String startDate, String endDate, String subCompanyIds, String departmentIds, String empIds, String empStatus) { String cqjtSql = "select a.*, b.fbid, b.bm from uf_jcl_kq_cqjt a " + "left join uf_jcl_kq_cqjg b on a.yg = b.ygid and a.rq = b.rq " + "left join hrmresource c on a.yg = c.id " + "where c.status = " + empStatus + " and a.rq >= '" + startDate +"'" + " and a.rq <= '" + endDate +"'"; if (!subCompanyIds.equals("")) { cqjtSql = cqjtSql + " and b.fbid in (" + subCompanyIds + ")"; } if (!departmentIds.equals("")) { cqjtSql = cqjtSql + " and b.bm in (" + departmentIds + ")"; } if (!empIds.equals("")) { cqjtSql = cqjtSql + " and a.yg in (" + empIds + ")"; } List> cqjtDates = DbTools.getSqlToList(cqjtSql); //先根据分部、部门、人员、项目分组 Map>> toDealCqjtDataWithGroup = new HashMap<>(); for (Map map : cqjtDates) { //津贴类型 if (!Util.null2String(map.get("jtlx")).equals("")) { String groupKey = map.get("fbid") + "_" + map.get("bm") + "_" + map.get("bdkry") + "_" + map.get("bdklx"); Map itemMap = new HashMap<>(); itemMap.put("fbid", map.get("fbid")); itemMap.put("bm", map.get("bm")); itemMap.put("yg", map.get("yg")); itemMap.put("xm", map.get("jtlx")); if (toDealCqjtDataWithGroup.get(groupKey) != null) { toDealCqjtDataWithGroup.get(groupKey).add(itemMap); } else { List> list = new ArrayList<>(); list.add(itemMap); toDealCqjtDataWithGroup.put(groupKey, list); } } } //处理分组好的数据 List> cqjtAddList = new ArrayList<>(); for(List> list : toDealCqjtDataWithGroup.values()) { String ry = list.get(0).get("yg").toString(); String kqxm = list.get(0).get("xm").toString(); String gsfb = list.get(0).get("fbid").toString(); String gsbm = list.get(0).get("bm").toString(); int num = list.size(); double time = 0; //查询考勤项目核算单位:天,小时,分钟,次,即0,1,2,3 String kqxmSql = "select * from uf_jcl_kq_kqxm where id = " + kqxm; Map kqxmData = DbTools.getSqlToMap(kqxmSql); String accountUnit = Util.null2String(kqxmData.get("hsdw")); //汇总区间数据 for (Map map : list) { if (!accountUnit.equals("3")) { double sc = Util.null2String(map.get("sc")).equals("") ? 0 : Double.parseDouble(map.get("sc").toString()); time += sc; } } //设置出勤汇总子表数据 Map itemMap = new HashMap<>(); itemMap.put("ry", ry); itemMap.put("kqxm", kqxm); itemMap.put("gsfb", gsfb); itemMap.put("gsbm", gsbm); itemMap.put("lc", String.valueOf(num)); if (accountUnit.equals("0")) { itemMap.put("lt", String.valueOf(time)); } if (accountUnit.equals("1")) { itemMap.put("ls", String.valueOf(time)); } if (accountUnit.equals("2")) { itemMap.put("lf", String.valueOf(time)); } cqjtAddList.add(itemMap); } return cqjtAddList; } }