diff --git a/src/com/api/attendance/summary/AttendanceSummaryActionApi.java b/src/com/api/attendance/summary/AttendanceSummaryActionApi.java new file mode 100644 index 0000000..0d24eab --- /dev/null +++ b/src/com/api/attendance/summary/AttendanceSummaryActionApi.java @@ -0,0 +1,14 @@ +package com.api.attendance.summary; + +import com.engine.attendance.workflow.web.AttendanceSummaryApi; + +import javax.ws.rs.Path; + +/** + * @Author: sy + * @Description: 出勤汇总相关api + * @Date: 2024/3/26 + **/ +@Path("/attendance/summary") +public class AttendanceSummaryActionApi extends AttendanceSummaryApi { +} diff --git a/src/com/engine/attendance/workflow/cmd/GetCqSummarySearchConditionCmd.java b/src/com/engine/attendance/workflow/cmd/GetCqSummarySearchConditionCmd.java new file mode 100644 index 0000000..5ea84fc --- /dev/null +++ b/src/com/engine/attendance/workflow/cmd/GetCqSummarySearchConditionCmd.java @@ -0,0 +1,212 @@ +package com.engine.attendance.workflow.cmd; + +import com.api.browser.bean.SearchConditionItem; +import com.api.hrm.bean.WeaRadioGroup; +import com.api.hrm.util.HrmAdvancedSearchUtil; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.common.service.HrmCommonService; +import com.engine.common.service.impl.HrmCommonServiceImpl; +import com.engine.common.util.DbTools; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQSettingsBiz; +import com.google.common.collect.Lists; +import weaver.backup.logging.Logger; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.systemExpAndImp.logging.LoggerFactory; +import weaver.systeminfo.SystemEnv; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author: sy + * @Description: 出勤汇总查询条件 + * @Date: 2024/3/21 + **/ +public class GetCqSummarySearchConditionCmd extends AbstractCommonCommand> { + + public GetCqSummarySearchConditionCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + private Logger log = LoggerFactory.getLogger(this.getClass()); + + @Override + public Map execute(CommandContext commandContext) {Map retmap = new HashMap(); + List lsCondition = new ArrayList(); + List cusCondition = new ArrayList(); + String[] options = null; + String[] selectLinkageDatas = null; + try{ + HrmAdvancedSearchUtil hrmAdvancedSearchUtil = new HrmAdvancedSearchUtil(); + HrmCommonService hrmCommonService = new HrmCommonServiceImpl(); + + boolean kq_personal_reportsearch = KQSettingsBiz.showLeaveTypeSet("kq_personal_reportsearch"); + //展示列、时间范围、数据范围 + WeaRadioGroup wrg = null; + if(kq_personal_reportsearch) { + options = new String[]{"1,15537,false","2,15539,false","3,15541,false","7,27347,false","4,21904,false","6,32530,false", "9,18196,true", "10,526968,false"}; + } else { + options = new String[]{"1,15537,false","2,15539,false","3,15541,false","7,27347,false","4,21904,false","5,15384,false","8,81716,false","6,32530,false", "9,18196,true", "10,526968,false"}; + } + wrg = hrmAdvancedSearchUtil.getAdvanceCondition("typeselect","19482",options,null,user); + wrg.setLabelcol(3); + wrg.setFieldcol(20); + Map selectLinks = new HashMap(); + List domkey = new ArrayList(); + Map map = new HashMap(); + selectLinks.put("conditionType", "RANGEPICKER"); + domkey = new ArrayList(); + domkey.add("fromDate"); + domkey.add("toDate"); + selectLinks.put("domkey", domkey); + map.put("6", selectLinks); + wrg.setSelectLinkageDatas(map); + log.info("wrg_options : " + wrg.getOptions()); + lsCondition.add(wrg); + + if(kq_personal_reportsearch) { + if(hrmCommonService.isManager(user.getUID())){ + options = new String[]{"3,1867,false","4,15089,false"}; + } else { + options = new String[]{"3,1867,false"}; + } + } else { + if(hrmCommonService.isManager(user.getUID())){ + options = new String[]{"0,140,true","1,141,false","2,124,false","3,1867,false","4,15089,false"}; + }else{ + options = new String[]{"0,140,true","1,141,false","2,124,false","3,1867,false"}; + } + } + + selectLinkageDatas = new String[]{"1,subCompanyId,141,3,194","2,departmentId,124,3,57","3,resourceId,1867,3,17","4,allLevel,389995,4,1"}; + if(user.getUID()!=1){ + if(kq_personal_reportsearch) { + selectLinkageDatas[2]="3,resourceId,1867,3,17,"+user.getUID(); + options[0]="3,1867,true"; + } else { + selectLinkageDatas[2]="3,resourceId,1867,3,17,"+user.getUID(); + options[0]="0,140,false"; + options[3]="3,1867,true"; + } + } + wrg = hrmAdvancedSearchUtil.getAdvanceCondition("viewScope","34102",options,selectLinkageDatas,user); + wrg.setLabelcol(3); + wrg.setFieldcol(20); + lsCondition.add(wrg); + + WeaRadioGroup wrg1 = new WeaRadioGroup(); + + ChgPasswdReminder reminder = new ChgPasswdReminder(); + RemindSettings settings = reminder.getRemindSettings(); + String checkUnJob = Util.null2String(settings.getCheckUnJob(), "0"); + List statusList = Lists.newArrayList(); + if ("1".equals(checkUnJob)) {//启用后,只有有“离职人员查看”权限的用户才能检索非在职人员 + if (HrmUserVarify.checkUserRight("hrm:departureView", user)) { + statusList.add("9,332,false"); + } + } else { + statusList.add("9,332,false"); + } + statusList.add("0,15710,false"); + statusList.add("1,15711,false"); + statusList.add("2,480,false"); + statusList.add("3,15844,false"); + if ("1".equals(checkUnJob)) {//启用后,只有有“离职人员查看”权限的用户才能检索非在职人员 + if (HrmUserVarify.checkUserRight("hrm:departureView", user)) { + statusList.add("4,6094,false"); + statusList.add("5,6091,false"); + statusList.add("6,6092,false"); + statusList.add("7,2245,false"); + } + } else { + statusList.add("4,6094,false"); + statusList.add("5,6091,false"); + statusList.add("6,6092,false"); + statusList.add("7,2245,false"); + } + statusList.add("8,1831,true"); + options = new String[statusList.size()]; + for(int i = 0 ; i < statusList.size() ; i++){ + String statusStr = statusList.get(i); + options[i] = statusStr; + } + + wrg1 = hrmAdvancedSearchUtil.getAdvanceCondition("status","602",options,null,user); + wrg1.setLabelcol(3); + wrg1.setFieldcol(20); + lsCondition.add(wrg1); + + List showColumns = new ArrayList<>(); + String cascadekey = ""; + List> selectOptions = new ArrayList<>(); + Map selectOption = null; + + //设置展示列 + //个人信息相关 + selectOption = new HashMap<>(); + selectOption.put("key","subcompany"); + selectOption.put("cascadekey",cascadekey); + selectOption.put("showname",SystemEnv.getHtmlLabelName(528842, user.getLanguage()));//分部 + selectOption.put("selected",true); + selectOptions.add(selectOption); + + selectOption = new HashMap<>(); + selectOption.put("key","department"); + selectOption.put("cascadekey",cascadekey); + selectOption.put("showname",SystemEnv.getHtmlLabelName(528843, user.getLanguage()));//部门 + selectOption.put("selected",false); + selectOptions.add(selectOption); + + showColumns.add(selectOptions); + //考勤项目 + String kqxmSql = "select * from uf_jcl_kq_kqxm"; + List> kqxmDates = DbTools.getSqlToList(kqxmSql); + log.info("kqxmDates : " + kqxmDates); + selectOptions = new ArrayList<>(); + for(Map kqxm : kqxmDates) { + selectOption = new HashMap<>(); + selectOption.put("key", "kqxm" + "_" + kqxm.get("id")); + selectOption.put("cascadekey",cascadekey); + selectOption.put("showname",kqxm.get("mc")); + selectOption.put("selected",true); + selectOptions.add(selectOption); + } + showColumns.add(selectOptions); + + retmap.put("showColumns", showColumns); + createSearchConditionItemList(cusCondition); + + retmap.put("status", "1"); + retmap.put("conditions", lsCondition); + retmap.put("cusCondition", cusCondition); + }catch (Exception e) { + writeLog(e); + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(10004510,weaver.general.ThreadVarLanguage.getLang())+""); + } + return retmap; + } + + /** + * 这里只处理非下拉框字段 + * @param cusCondition + */ + public void createSearchConditionItemList(List cusCondition) { + + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/attendance/workflow/service/AttendanceSummaryService.java b/src/com/engine/attendance/workflow/service/AttendanceSummaryService.java new file mode 100644 index 0000000..80ea2d2 --- /dev/null +++ b/src/com/engine/attendance/workflow/service/AttendanceSummaryService.java @@ -0,0 +1,20 @@ +package com.engine.attendance.workflow.service; + +import java.util.Map; + +public interface AttendanceSummaryService { + + /** + * 新增出勤汇总 + * 基于入参中的出勤汇总主表id,获取主表信息,根据主表中的分部、考勤时间区间等字段, + * 对出勤结果表、补打卡表、出勤津贴表中数据根据分布和时间区间筛选后, + * 根据分部、部门、人员id、考勤项目进行分组统计 + * @param params + * @return + */ + Map addAttendanceSummary(Map params); + + Map getCqSummaryReport(Map params); + + Map getCqSummarySearchCondition(Map params); +} diff --git a/src/com/engine/attendance/workflow/service/impl/AttendanceSummaryServiceImpl.java b/src/com/engine/attendance/workflow/service/impl/AttendanceSummaryServiceImpl.java new file mode 100644 index 0000000..4d7960c --- /dev/null +++ b/src/com/engine/attendance/workflow/service/impl/AttendanceSummaryServiceImpl.java @@ -0,0 +1,1203 @@ +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; + } +} diff --git a/src/com/engine/attendance/workflow/web/AttendanceSummaryApi.java b/src/com/engine/attendance/workflow/web/AttendanceSummaryApi.java new file mode 100644 index 0000000..ad0f34a --- /dev/null +++ b/src/com/engine/attendance/workflow/web/AttendanceSummaryApi.java @@ -0,0 +1,83 @@ +package com.engine.attendance.workflow.web; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.engine.attendance.workflow.service.AttendanceSummaryService; +import com.engine.attendance.workflow.service.BusinessTripsApplyService; +import com.engine.attendance.workflow.service.impl.AttendanceSummaryServiceImpl; +import com.engine.attendance.workflow.service.impl.BusinessTripsApplyServiceImpl; +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: sy + * @Description: 出勤汇总数据相关功能接口 + * @Date: 2024/3/25 + **/ +public class AttendanceSummaryApi { + + private AttendanceSummaryService getAttendanceSummaryService(User user) { + return ServiceUtil.getService(AttendanceSummaryServiceImpl.class,user); + } + + /** + * 出勤汇总报表查询条件 + * @param request + * @param response + * @return + */ + @POST + @Path("/getCqSummarySearchCondition") + @Produces(MediaType.TEXT_PLAIN) + public String getCqSummarySearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response){ + Map apidatas = new HashMap(); + User user = HrmUserVarify.getUser(request, response); + apidatas = getAttendanceSummaryService(user).getCqSummarySearchCondition(ParamUtil.request2Map(request)); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + + /** + * 获取出勤汇总报表 + * @param request + * @param response + * @return + */ + @POST + @Path("/getCqSummaryReport") + @Produces(MediaType.TEXT_PLAIN) + public String getCqSummaryReport(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap(); + User user = HrmUserVarify.getUser(request, response); + apidatas = getAttendanceSummaryService(user).getCqSummaryReport(ParamUtil.request2Map(request)); + return JSONObject.toJSONString(apidatas); + } + + /** + * 新增出勤汇总数据 + * @param request + * @param response + * @return + */ + @POST + @Path("/addAttendanceSummary") + @Produces(MediaType.APPLICATION_JSON) + public String addAttendanceSummary(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap(); + User user = HrmUserVarify.getUser(request, response); + apidatas = getAttendanceSummaryService(user).addAttendanceSummary(ParamUtil.request2Map(request)); + return JSONObject.toJSONString(apidatas); + } +}