From da53b734322a467437bf302819cb82039a534c2e Mon Sep 17 00:00:00 2001 From: shilei <798989044@qq.com> Date: Tue, 6 Aug 2024 15:06:52 +0800 Subject: [PATCH] =?UTF-8?q?#weaver-zhewen-1#=20=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/zw/workflow/countUserWorkTime.jsp | 261 ++ .../zw/workflow/getSchedulingDateType.jsp | 223 + .../zw/workflow/getSchedulingRestData.jsp | 35 + .../workflow/queryMainSchedulingUserData.jsp | 54 + .../zw/workflow/querySchedulingUserData.jsp | 66 + .../zw/workflow/querySchedulingUserData2.jsp | 127 + .../zw/workflow/queryUserWorkdayData.jsp | 378 ++ .../zw/workflow/queryUserWorkdayData2.jsp | 383 ++ src/com/engine/kq/biz/KQFormatBiz.java | 339 ++ src/com/engine/kq/biz/KQLeaveRulesBiz.java | 1307 ++++++ src/com/engine/kq/biz/KQReportBiz.java | 3653 +++++++++++++++++ .../kq/biz/KQShiftManagementComInfo.java | 814 ++++ .../kq/cmd/report/ExportDailyExcelCmd.java | 690 ++++ .../engine/kq/cmd/report/ExportExcelCmd.java | 718 ++++ .../kq/cmd/report/GetKQDailyReportCmd.java | 696 ++++ .../engine/kq/cmd/report/GetKQReportCmd.java | 818 ++++ .../interfaces/zw/utils/CommonUtil.java | 136 + .../action/WorkflowToSchedulingAction.java | 278 ++ 18 files changed, 10976 insertions(+) create mode 100644 interface/zw/workflow/countUserWorkTime.jsp create mode 100644 interface/zw/workflow/getSchedulingDateType.jsp create mode 100644 interface/zw/workflow/getSchedulingRestData.jsp create mode 100644 interface/zw/workflow/queryMainSchedulingUserData.jsp create mode 100644 interface/zw/workflow/querySchedulingUserData.jsp create mode 100644 interface/zw/workflow/querySchedulingUserData2.jsp create mode 100644 interface/zw/workflow/queryUserWorkdayData.jsp create mode 100644 interface/zw/workflow/queryUserWorkdayData2.jsp create mode 100644 src/com/engine/kq/biz/KQFormatBiz.java create mode 100644 src/com/engine/kq/biz/KQLeaveRulesBiz.java create mode 100644 src/com/engine/kq/biz/KQReportBiz.java create mode 100644 src/com/engine/kq/biz/KQShiftManagementComInfo.java create mode 100644 src/com/engine/kq/cmd/report/ExportDailyExcelCmd.java create mode 100644 src/com/engine/kq/cmd/report/ExportExcelCmd.java create mode 100644 src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java create mode 100644 src/com/engine/kq/cmd/report/GetKQReportCmd.java create mode 100644 src/weaver/interfaces/zw/utils/CommonUtil.java create mode 100755 src/weaver/interfaces/zw/workflow/action/WorkflowToSchedulingAction.java diff --git a/interface/zw/workflow/countUserWorkTime.jsp b/interface/zw/workflow/countUserWorkTime.jsp new file mode 100644 index 0000000..5da37b5 --- /dev/null +++ b/interface/zw/workflow/countUserWorkTime.jsp @@ -0,0 +1,261 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="com.alibaba.fastjson.JSONArray" %> +<%@ page import="java.util.Map" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="java.time.LocalDate" %> +<%@ page import="java.time.temporal.TemporalAdjusters" %> +<%@ page import="java.time.DayOfWeek" %> +<%@ page import="java.util.HashMap" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupBiz" %> +<%@ page import="weaver.common.DateUtil" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + RecordSet rs = new RecordSet(); + String serialids = request.getParameter("serialids"); + + String userid = request.getParameter("userid"); + String pbyf = request.getParameter("pbyf"); + String serdata = request.getParameter("serdata"); + List restList = getSchedulingRestData(); + + String worktime = "0"; + String totalworktime = "0"; + if(StringUtils.isNotBlank(serialids)){ + String sql = ""; + String[] serialidArray = serialids.split(","); + for(int i=0;i weekMap = queryWeekTypeByMonth(userid,pbyf); + if(StringUtils.isNotBlank(serdata)){ + JSONArray jsonArray = JSONArray.parseArray(serdata); + for(int i=0;i + +<%=jsonObject.toJSONString() %> + + +<%! + public Map queryWeekTypeByMonth(String userid,String pbyf){ + + Map weekMap = new HashMap(); + if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7) { + LocalDate date = LocalDate.parse(pbyf + "-01"); // 获取当前日期 + LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天 + LocalDate startDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天 + String monthStartDate = startDayOfMonth.toString(); + String monthEndDate = lastDayOfMonth.toString(); + Map holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate); + + int thisMonth = date.getMonthValue(); // 获取当前是哪月 + int daysInMonth = date.lengthOfMonth(); // 获取本月有多少天 + + for (int i = 1; i <= daysInMonth; i++) { + LocalDate currentDate = LocalDate.of(date.getYear(), thisMonth, i); + System.out.println("currentDate:" + currentDate.toString()); + DayOfWeek dayOfWeek = currentDate.getDayOfWeek(); + System.out.println(i + "号是周 " + dayOfWeek.getValue()); + int weekValue = dayOfWeek.getValue(); + + String changeType = "" ; + if(holidayMap.containsKey(currentDate.toString())){ + changeType = holidayMap.get(currentDate.toString()); + } + + if("1".equals(changeType) || "3".equals(changeType)){ + weekValue = 11; + } + + if(StringUtils.isNotBlank(changeType)){ + weekMap.put(currentDate.toString(), weekValue+""); + }else{ + weekMap.put(currentDate.toString(), weekValue+""); + } + } + } + return weekMap; + } + + public Map getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){ + + Map holidayMap = new HashMap(); + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + + try { + if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){ + String activeGroupId = getUserActiveGroupId(userid); + bb.writeLog("activeGroupId:"+activeGroupId); + if(StringUtils.isNotBlank(activeGroupId)){ + String sql =" select holidayDate,changeType from KQ_HolidaySet\n" + + " where groupid = " + activeGroupId+ + " and holidayDate >='"+monthStartDate+"'\n" + + " and holidayDate <='"+monthEndDate+"' " ; + rs.execute(sql); + while (rs.next()){ + String holidayDate = Util.null2String(rs.getString("holidayDate")); + String changeType = Util.null2String(rs.getString("changeType")); + holidayMap.put(holidayDate,changeType); + } + } + } + }catch (Exception e){ + + } + return holidayMap; + } + + /*** + * + * @param userid + * @return + */ + public String getUserActiveGroupId(String userid){ + BaseBean bb = new BaseBean(); + + KQGroupMemberComInfo kqGroupMemberComInfo = null; + KQGroupComInfo kqGroupComInfo = null ; + String activeGroupId = ""; + try{ + kqGroupMemberComInfo = new KQGroupMemberComInfo(); + kqGroupComInfo = new KQGroupComInfo(); + + Map> groupMemberMap = getUserGroup(); + + String activeGroup = ""; + if(groupMemberMap.containsKey(userid)){ + List groupIds = groupMemberMap.get(userid); + bb.writeLog("groupIds:"+groupIds.size()); + + for(String i : groupIds){ + String isDelete = kqGroupComInfo.getIsdelete(i); + if(!"1".equals(isDelete)) { + String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate())); + if (i.equals(currentGroupId)) { + activeGroupId = i; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog(e); + } + return activeGroupId; + } + + + /*** + * + * @return + */ + public Map> getUserGroup(){ + BaseBean bb = new BaseBean(); + Map> groupMemberMap = new HashMap<>(); + RecordSet rs = new RecordSet(); + String viewScope = "3"; + try { + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + Map groupParams = new HashMap(); + if("3".equals(viewScope)){ + groupParams.put("isNoAccount", "1"); + } + rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams)); + while (rs.next()) { + String id = rs.getString("resourceid"); + String gid = rs.getString("groupid"); + if (!groupMemberMap.containsKey(id)) + groupMemberMap.put(id, new ArrayList<>()); + groupMemberMap.get(id).add(gid); + } + } catch (Exception e) { + } + return groupMemberMap; + } + + public List getSchedulingRestData(){ + + List list = new ArrayList(); + RecordSet rs = new RecordSet(); + try{ + String sql =" select id " + + " from kq_ShiftManagement \n" + + " where is_rest = 1 \n" + + " and (isdelete is null or isdelete = 0) "; + + rs.executeQuery(sql); + while (rs.next()){ + String id = Util.null2String(rs.getString("id")); + list.add(id); + } + }catch (Exception e){ + + } + return list; + } + +%> + + + diff --git a/interface/zw/workflow/getSchedulingDateType.jsp b/interface/zw/workflow/getSchedulingDateType.jsp new file mode 100644 index 0000000..aa3d558 --- /dev/null +++ b/interface/zw/workflow/getSchedulingDateType.jsp @@ -0,0 +1,223 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="java.time.LocalDate" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="java.util.Map" %> +<%@ page import="java.util.HashMap" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page import="com.engine.kq.biz.KQGroupBiz" %> +<%@ page import="com.engine.kq.biz.KQGroupComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %> +<%@ page import="weaver.common.DateUtil" %> +<%@ page import="java.time.DayOfWeek" %> +<%@ page import="java.time.temporal.TemporalAdjusters" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + + BaseBean bb = new BaseBean(); + + RecordSet rs = new RecordSet(); + String pbyf = request.getParameter("pbyf"); + String userid = request.getParameter("userid"); + String deptid = request.getParameter("deptid"); + int daysInMonth = 0; + Map weekMap = new HashMap(); + List> weekList = new ArrayList>(); + if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7) { + LocalDate date = LocalDate.parse(pbyf + "-01"); // 获取当前日期 + LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天 + LocalDate startDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天 + String monthStartDate = startDayOfMonth.toString(); + String monthEndDate = lastDayOfMonth.toString(); + Map holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate); + + + int thisMonth = date.getMonthValue(); // 获取当前是哪月 + daysInMonth = date.lengthOfMonth(); // 获取本月有多少天 + + for (int i = 1; i <= daysInMonth; i++) { + LocalDate currentDate = LocalDate.of(date.getYear(), thisMonth, i); + System.out.println("currentDate:" + currentDate.toString()); + DayOfWeek dayOfWeek = currentDate.getDayOfWeek(); + System.out.println(i + "号是周 " + dayOfWeek.getValue()); + int weekValue = dayOfWeek.getValue(); + String weekDayName = ""; + switch (weekValue) { + case 1: + weekDayName = "周一"; + break; + case 2: + weekDayName = "周二"; + break; + case 3: + weekDayName = "周三"; + break; + case 4: + weekDayName = "周四"; + break; + case 5: + weekDayName = "周五"; + break; + case 6: + weekDayName = "周六"; + break; + case 7: + weekDayName = "周日"; + break; + } + + String changeType = "" ; + if(holidayMap.containsKey(currentDate.toString())){ + changeType = holidayMap.get(currentDate.toString()); + } + weekMap = new HashMap(); + weekMap.put("weekname", weekDayName); + weekMap.put("changeType", changeType); + weekMap.put("weekday", i+""); + weekMap.put("weekdate", currentDate.toString()); + weekList.add(weekMap); + } + } + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("data",weekList); + jsonObject.put("count",daysInMonth); +%> + +<%=jsonObject.toJSONString() %> + + +<%! + + /*** + * + * @param userid + * @return + */ + public String getUserActiveGroupId(String userid){ + BaseBean bb = new BaseBean(); + + KQGroupMemberComInfo kqGroupMemberComInfo = null; + KQGroupComInfo kqGroupComInfo = null ; + String activeGroupId = ""; + try{ + kqGroupMemberComInfo = new KQGroupMemberComInfo(); + kqGroupComInfo = new KQGroupComInfo(); + + Map> groupMemberMap = getUserGroup(); + + String activeGroup = ""; + if(groupMemberMap.containsKey(userid)){ + List groupIds = groupMemberMap.get(userid); + bb.writeLog("groupIds:"+groupIds.size()); + + for(String i : groupIds){ + String isDelete = kqGroupComInfo.getIsdelete(i); + if(!"1".equals(isDelete)) { + String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate())); + if (i.equals(currentGroupId)) { + activeGroupId = i; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog(e); + } + return activeGroupId; + } + + + /*** + * + * @return + */ + public Map> getUserGroup(){ + BaseBean bb = new BaseBean(); + Map> groupMemberMap = new HashMap<>(); + RecordSet rs = new RecordSet(); + String viewScope = "3"; + try { + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + Map groupParams = new HashMap(); + if("3".equals(viewScope)){ + groupParams.put("isNoAccount", "1"); + } + rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams)); + while (rs.next()) { + String id = rs.getString("resourceid"); + String gid = rs.getString("groupid"); + if (!groupMemberMap.containsKey(id)) + groupMemberMap.put(id, new ArrayList<>()); + groupMemberMap.get(id).add(gid); + } + } catch (Exception e) { + } + return groupMemberMap; + } + + + public Map getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){ + + Map holidayMap = new HashMap(); + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + + try { + if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){ + String activeGroupId = getUserActiveGroupId(userid); + bb.writeLog("activeGroupId:"+activeGroupId); + if(StringUtils.isNotBlank(activeGroupId)){ + String sql =" select holidayDate,changeType from KQ_HolidaySet\n" + + " where groupid = " + activeGroupId+ + " and holidayDate >='"+monthStartDate+"'\n" + + " and holidayDate <='"+monthEndDate+"' " ; + rs.execute(sql); + while (rs.next()){ + String holidayDate = Util.null2String(rs.getString("holidayDate")); + String changeType = Util.null2String(rs.getString("changeType")); + String changeTypename = "" ; + if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日 + changeTypename += "公众假日"; + }else if("2".equals(changeType)){ + changeTypename += "调配工作日"; + }else if("3".equals(changeType)){ + changeTypename += "调配休息日"; + } + holidayMap.put(holidayDate,changeTypename); + +// if(weekMap.containsKey(holidayDate)){ +// String holidayDate_new = weekMap.get(holidayDate); +// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日 +// holidayDate_new += "[公众假日]"; +// }else if("1".equals(changeType)){ +// holidayDate_new += "[调配工作日]"; +// }else if("2".equals(changeType)){ +// holidayDate_new += "[调配休息日]"; +// } +// weekMap.put(holidayDate,holidayDate_new); +// } + } + } + } + }catch (Exception e){ + + } + return holidayMap; + } + +%> + + diff --git a/interface/zw/workflow/getSchedulingRestData.jsp b/interface/zw/workflow/getSchedulingRestData.jsp new file mode 100644 index 0000000..40fe7b6 --- /dev/null +++ b/interface/zw/workflow/getSchedulingRestData.jsp @@ -0,0 +1,35 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + + List list = new ArrayList(); + RecordSet rs = new RecordSet(); + String sql =" select id " + + " from kq_ShiftManagement \n" + + " where is_rest = 1 \n" + + " and (isdelete is null or isdelete = 0) "; + + rs.executeQuery(sql); + while (rs.next()){ + String id = Util.null2String(rs.getString("id")); + list.add(id); + } + JSONObject jsonObject = new JSONObject(); + jsonObject.put("data",list); +%> + +<%=jsonObject.toJSONString() %> + + + diff --git a/interface/zw/workflow/queryMainSchedulingUserData.jsp b/interface/zw/workflow/queryMainSchedulingUserData.jsp new file mode 100644 index 0000000..fc1d4d8 --- /dev/null +++ b/interface/zw/workflow/queryMainSchedulingUserData.jsp @@ -0,0 +1,54 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="java.util.Map" %> +<%@ page import="java.util.HashMap" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + + List> mainList = new ArrayList>(); + RecordSet rs = new RecordSet(); + String pbry = request.getParameter("pbry"); + if(StringUtils.isNotBlank(pbry)) { + String sql = "select id,lastname from hrmresource where id in("+pbry+")"; + rs.executeQuery(sql); + while (rs.next()){ + String userid = Util.null2String(rs.getString("id")); + String lastname = Util.null2String(rs.getString("lastname")); + + Map mainMap = new HashMap(); + mainMap.put("id",userid); + mainMap.put("name",lastname); + + List> specialobjList = new ArrayList>(); + Map specialobjMap = new HashMap(); + specialobjMap.put("id",userid); + specialobjMap.put("name",lastname); + specialobjList.add(specialobjMap); + + Map valueMap = new HashMap(); + valueMap.put("value",userid); + valueMap.put("specialobj",specialobjList); + mainMap.put("value",valueMap); + mainList.add(mainMap); + } + } + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("main",mainList); +%> + +<%=jsonObject.toJSONString() %> + + diff --git a/interface/zw/workflow/querySchedulingUserData.jsp b/interface/zw/workflow/querySchedulingUserData.jsp new file mode 100644 index 0000000..a340b07 --- /dev/null +++ b/interface/zw/workflow/querySchedulingUserData.jsp @@ -0,0 +1,66 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="java.time.LocalDate" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="java.util.Map" %> +<%@ page import="java.util.HashMap" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + + List> userList = new ArrayList>(); + + List> dt1List = new ArrayList>(); + + Map userMap = null; + BaseBean bb = new BaseBean(); + + RecordSet rs = new RecordSet(); + + String cjrbm = request.getParameter("cjrbm"); + + if(StringUtils.isNotBlank(cjrbm)) { + String sql = "select id,lastname from hrmresource where departmentid = ?"; + rs.executeQuery(sql,new Object[]{cjrbm}); + while (rs.next()){ + String userid = Util.null2String(rs.getString("id")); + String lastname = Util.null2String(rs.getString("lastname")); + + userMap = new HashMap(); + userMap.put("id",userid); + userMap.put("name",lastname); + + List> specialobjList = new ArrayList>(); + Map specialobjMap = new HashMap(); + specialobjMap.put("id",userid); + specialobjMap.put("name",lastname); + specialobjList.add(specialobjMap); + + Map valueMap = new HashMap(); + valueMap.put("value",userid); + valueMap.put("specialobj",specialobjList); + userMap.put("value",valueMap); + userList.add(userMap); + + } + } + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("data",userList); + jsonObject.put("dt1",userList); +%> + +<%=jsonObject.toJSONString() %> + + diff --git a/interface/zw/workflow/querySchedulingUserData2.jsp b/interface/zw/workflow/querySchedulingUserData2.jsp new file mode 100644 index 0000000..2095907 --- /dev/null +++ b/interface/zw/workflow/querySchedulingUserData2.jsp @@ -0,0 +1,127 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="java.time.LocalDate" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="java.util.Map" %> +<%@ page import="java.util.HashMap" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + String cjrbm = request.getParameter("cjrbm"); + + + Map valueMap = new HashMap<>(); + List> dt1List = new ArrayList>(); + if(StringUtils.isNotBlank(cjrbm)) { + String sql = "select id,lastname from hrmresource where departmentid = "+cjrbm ; + List> hrmList = queryListBySql(sql); + valueMap = getMainUserDate(hrmList); + dt1List = getDt1UserDate(hrmList); + } + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("data",valueMap); + jsonObject.put("dt1",dt1List); +%> + +<%=jsonObject.toJSONString() %> + + +<%! + + public List> getDt1UserDate(List> hrmList){ + List> dt1List = new ArrayList>(); + for(int i=0;i hrmMap = hrmList.get(i); + + String userid = Util.null2String(hrmMap.get("id")); + String lastname = Util.null2String(hrmMap.get("lastname")); + + Map dt1Map = new HashMap(); + dt1Map.put("id",userid); + dt1Map.put("name",lastname); + + List> specialobjList2 = new ArrayList>(); + Map specialobjMap2 = new HashMap(); + specialobjMap2.put("id",userid); + specialobjMap2.put("name",lastname); + specialobjList2.add(specialobjMap2); + + Map valueMap2 = new HashMap(); + valueMap2.put("value",userid); + valueMap2.put("specialobj",specialobjList2); + dt1Map.put("value",valueMap2); + dt1List.add(dt1Map); + } + return dt1List; + } + /*** + * + * @param hrmList + * @return + */ + public Map getMainUserDate(List> hrmList){ + String userids = ""; + List> specialobjList = new ArrayList>(); + for(int i=0;i hrmMap = hrmList.get(i); + String userid = Util.null2String(hrmMap.get("id")); + String lastname = Util.null2String(hrmMap.get("lastname")); + userids += StringUtils.isBlank(userids) ? userid : ","+userid ; + + Map specialobjMap = new HashMap(); + specialobjMap.put("id",userid); + specialobjMap.put("name",lastname); + specialobjList.add(specialobjMap); + } + + Map valueMap = new HashMap(); + valueMap.put("value",userids); + valueMap.put("specialobj",specialobjList); + return valueMap; + } + + public List> queryListBySql(String sql){ + RecordSet rs = new RecordSet(); + BaseBean bb = new BaseBean(); + List> list = new ArrayList>(); + try{ + if(StringUtils.isNotBlank(sql)){ + Map map = new HashMap(); + rs.executeQuery(sql); + String[] column = rs.getColumnName(); + while (rs.next()){ + map = new HashMap(); + for(int i=0;i0){ + list.add(map); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog("queryListBySql-e:"+e); + } + return list; + } + +%> + + diff --git a/interface/zw/workflow/queryUserWorkdayData.jsp b/interface/zw/workflow/queryUserWorkdayData.jsp new file mode 100644 index 0000000..5962936 --- /dev/null +++ b/interface/zw/workflow/queryUserWorkdayData.jsp @@ -0,0 +1,378 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="weaver.common.DateUtil" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page import="com.alibaba.fastjson.JSONArray" %> +<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupBiz" %> +<%@ page import="java.time.LocalDate" %> +<%@ page import="java.time.format.DateTimeFormatter" %> +<%@ page import="java.time.DayOfWeek" %> +<%@ page import="java.time.temporal.TemporalAdjusters" %> +<%@ page import="java.util.*" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + String[] workSchedule = {"09:00-11:00","11:00-16:00","16:00-20:00","20:00-21:30"}; + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + int userid = user.getUID(); + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + String pbdata = request.getParameter("pbdata"); +// if(StringUtils.isBlank(pb)){ +// +// JSONArray jsonArray = new JSONArray(); +// JSONObject userObject = new JSONObject(); +// userObject.put("userid","3039"); +// userObject.put("serialid","10"); +// jsonArray.add(userObject); +// +// userObject = new JSONObject(); +// userObject.put("userid","3373"); +// userObject.put("serialid","7"); +// jsonArray.add(userObject); +// +// userObject = new JSONObject(); +// userObject.put("userid","3661"); +// userObject.put("serialid","9"); +// jsonArray.add(userObject); +// pb = jsonArray.toJSONString(); +// } + String yjl = request.getParameter("yjl"); + String pbrq = request.getParameter("pbrq"); + String dateType = "0"; + if(StringUtils.isNotBlank(pbrq)){ + dateType = getWeekTypeByDate(pbrq,userid+""); + } + + Map defaultScheduleMap = new HashMap(); + if(StringUtils.isNotBlank(yjl)){ + String sql = " select dysjd,pzrs from uf_pbjcsj where yjl = ? and pblx = ?" ; + rs.executeQuery(sql,new Object[]{yjl,dateType}); + while (rs.next()){ + int dysd = Util.getIntValue(Util.null2String(rs.getString("dysjd"))); + int pzrs = Util.getIntValue(Util.null2String(rs.getString("pzrs"))); + + String sjd = ""; + if(dysd < workSchedule.length){ + sjd = workSchedule[dysd]; + if(StringUtils.isNotBlank(sjd)){ + defaultScheduleMap.put(sjd,pzrs); + } + } + } + } + + List> workScheduleList = new ArrayList>(); + Map workScheduleMap = null; + for(int k=0;k0){ + String[] schedule = workSchedule[k].split("-"); + String scheduleStartTime = schedule[0]; + String scheduleEndTime = schedule[1]; + if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){ + workScheduleMap = new HashMap(); + workScheduleMap.put("start",scheduleStartTime); + workScheduleMap.put("end",scheduleEndTime); + workScheduleList.add(workScheduleMap); + } + } + } + + Map> userScheduleDayMap = new HashMap>(); + Map necessaryMap = new HashMap(); + + Map userScheduleMap = new HashMap(); + if(StringUtils.isNotBlank(pbdata)) { + JSONArray jsonArray = JSONArray.parseArray(pbdata); + + String yxrys = "" ; + for(int i = 0;i userList = new ArrayList(); + String sql =" select h.id \n" + + " from hrmresource h \n" + + " inner join hrmjobtitles k on k.id = h.jobtitle\n" + + " where h.id in("+yxrys+")\n" + + " and k.jobtitlename in('店长','验光师')\n" + + " and h.status in(0,1,2,3,4)\n" + + " union \n" + + " select h.id \n" + + " from hrmresource h \n" + + " inner join cus_fielddata k on k.id = h.id\n" + + " where k.field39 = 2 \n" + + " and k.scopeid=3 \n" + + " and k.scope='HrmCustomFieldByInfoType' " + + " and h.id in("+yxrys+") and h.status in(0,1,2,3,4) " + + " union " + + " select h.id\n" + + " from hrmresource h \n" + + " inner join cus_fielddata k on k.id = h.id \n" + + " where k.scopeid=-1 " + + " and k.scope='HrmCustomFieldByInfoType'\n" + + " and substring(k.field1,charindex('_',k.field1)+1,len(k.field1)) in(select id from uf_gwjbsjb where jbmc in('配镜三级','配镜四级','配镜五级')) and charindex('_', k.field1) > 0 \n" + + " and h.status in(0,1,2,3,4) "+ + " and h.id in("+yxrys+") "; + + rs.executeQuery(sql); + while (rs.next()){ + String id = Util.null2String(rs.getString("id")); + userList.add(id); + } + + for(int i = 0;i userSchedule_Map = new HashMap(); + if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){ + userSchedule_Map.put("startTime",startTime); + userSchedule_Map.put("endTime",endTime); + + + for(int k=0;k workSchedule_Map = workScheduleList.get(k); + String scheduleStartTime = workSchedule_Map.get("start"); + String scheduleEndTime = workSchedule_Map.get("end"); + if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){ + if(startTime.compareTo(scheduleStartTime) <=0 && endTime.compareTo(scheduleEndTime) >=0){ + + String defWorkSchedule = scheduleStartTime+"-"+scheduleEndTime ; + if(userScheduleMap.containsKey(defWorkSchedule)){ + int count = userScheduleMap.get(defWorkSchedule); + count++; + userScheduleMap.put(defWorkSchedule,count); + }else{ + userScheduleMap.put(defWorkSchedule,1); + } + + if(userList.contains(pbry)){ + necessaryMap.put(defWorkSchedule,1); + } + } + } + } + } + userScheduleDayMap.put(pbry,userSchedule_Map); + } + } + + int defaultcount = 0; + int datacount = 0; + Iterator> iterator = defaultScheduleMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + int value =entry.getValue(); + String key = entry.getKey(); + if(userScheduleMap.containsKey(key)){ + int useValue = userScheduleMap.get(key); + if(useValue < value){ + datacount++; + } + }else{ + datacount++; + } + defaultcount++; + } + + JSONObject jsonObject = new JSONObject(); + if(defaultcount >0 && datacount == 0){ + if(necessaryMap.size() == 4){ + jsonObject.put("pbcode","1"); + }else{ + jsonObject.put("pbcode","2"); + } + }else{ + jsonObject.put("pbcode","0"); + } + + jsonObject.put("pbinfo",userScheduleDayMap); +%> + +<%=jsonObject.toJSONString() %> + +<%! + + public String getWeekTypeByDate(String pbrq,String userid){ + + String dateType = "0"; + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate currentDate = LocalDate.parse(pbrq, df); + + DayOfWeek dayOfWeek = currentDate.getDayOfWeek(); + int weekValue = dayOfWeek.getValue(); + + LocalDate lastDayOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天 + LocalDate startDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天 + String monthStartDate = startDayOfMonth.toString(); + String monthEndDate = lastDayOfMonth.toString(); + Map holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate); + + String changeType = "" ; + if(holidayMap.containsKey(currentDate.toString())){ + changeType = holidayMap.get(currentDate.toString()); + } + + if("1".equals(changeType) || "3".equals(changeType)){ + dateType = "1"; + }else if(weekValue == 6 || weekValue == 7){ + dateType = "1"; + } + return dateType; + } + + /*** + * + * @param userid + * @param monthStartDate + * @param monthEndDate + * @return + */ + public Map getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){ + + Map holidayMap = new HashMap(); + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + + try { + if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){ + String activeGroupId = getUserActiveGroupId(userid); + bb.writeLog("activeGroupId:"+activeGroupId); + if(StringUtils.isNotBlank(activeGroupId)){ + String sql =" select holidayDate,changeType from KQ_HolidaySet\n" + + " where groupid = " + activeGroupId+ + " and holidayDate >='"+monthStartDate+"'\n" + + " and holidayDate <='"+monthEndDate+"' " ; + rs.execute(sql); + while (rs.next()){ + String holidayDate = Util.null2String(rs.getString("holidayDate")); + String changeType = Util.null2String(rs.getString("changeType")); +// String changeTypename = "" ; +// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日 +// changeTypename += "公众假日"; +// }else if("2".equals(changeType)){ +// changeTypename += "调配工作日"; +// }else if("3".equals(changeType)){ +// changeTypename += "调配休息日"; +// } + holidayMap.put(holidayDate,changeType); + +// if(weekMap.containsKey(holidayDate)){ +// String holidayDate_new = weekMap.get(holidayDate); +// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日 +// holidayDate_new += "[公众假日]"; +// }else if("1".equals(changeType)){ +// holidayDate_new += "[调配工作日]"; +// }else if("2".equals(changeType)){ +// holidayDate_new += "[调配休息日]"; +// } +// weekMap.put(holidayDate,holidayDate_new); +// } + } + } + } + }catch (Exception e){ + + } + return holidayMap; + } + + /*** + * + * @param userid + * @return + */ + public String getUserActiveGroupId(String userid){ + BaseBean bb = new BaseBean(); + + KQGroupMemberComInfo kqGroupMemberComInfo = null; + KQGroupComInfo kqGroupComInfo = null ; + String activeGroupId = ""; + try{ + kqGroupMemberComInfo = new KQGroupMemberComInfo(); + kqGroupComInfo = new KQGroupComInfo(); + + Map> groupMemberMap = getUserGroup(); + + String activeGroup = ""; + if(groupMemberMap.containsKey(userid)){ + List groupIds = groupMemberMap.get(userid); + bb.writeLog("groupIds:"+groupIds.size()); + + for(String i : groupIds){ + String isDelete = kqGroupComInfo.getIsdelete(i); + if(!"1".equals(isDelete)) { + String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate())); + if (i.equals(currentGroupId)) { + activeGroupId = i; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog(e); + } + return activeGroupId; + } + + + /*** + * + * @return + */ + public Map> getUserGroup(){ + BaseBean bb = new BaseBean(); + Map> groupMemberMap = new HashMap<>(); + RecordSet rs = new RecordSet(); + String viewScope = "3"; + try { + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + Map groupParams = new HashMap(); + if("3".equals(viewScope)){ + groupParams.put("isNoAccount", "1"); + } + rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams)); + while (rs.next()) { + String id = rs.getString("resourceid"); + String gid = rs.getString("groupid"); + if (!groupMemberMap.containsKey(id)) + groupMemberMap.put(id, new ArrayList<>()); + groupMemberMap.get(id).add(gid); + } + } catch (Exception e) { + } + return groupMemberMap; + } + + +%> + + diff --git a/interface/zw/workflow/queryUserWorkdayData2.jsp b/interface/zw/workflow/queryUserWorkdayData2.jsp new file mode 100644 index 0000000..39312ad --- /dev/null +++ b/interface/zw/workflow/queryUserWorkdayData2.jsp @@ -0,0 +1,383 @@ +<%@ page import="weaver.conn.RecordSet" %> +<%@ page import="weaver.general.Util" %> +<%@ page import="org.apache.commons.lang3.StringUtils" %> +<%@ page import="com.alibaba.fastjson.JSONObject" %> +<%@ page import="weaver.common.DateUtil" %> +<%@ page import="weaver.hrm.User" %> +<%@ page import="weaver.hrm.HrmUserVarify" %> +<%@ page import="weaver.general.BaseBean" %> +<%@ page import="com.alibaba.fastjson.JSONArray" %> +<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupComInfo" %> +<%@ page import="com.engine.kq.biz.KQGroupBiz" %> +<%@ page import="java.time.LocalDate" %> +<%@ page import="java.time.format.DateTimeFormatter" %> +<%@ page import="java.time.DayOfWeek" %> +<%@ page import="java.time.temporal.TemporalAdjusters" %> +<%@ page import="java.util.*" %> +<%@ page language="java" contentType="text/html; charset=UTF-8" %> +<% + + String[] workSchedule = {"09:00-11:00","11:00-16:00","16:00-20:00","20:00-21:30"}; + User user = HrmUserVarify.getUser(request, response); + if(user==null) { + response.sendRedirect("/login/Login.jsp"); + return; + } + int userid = user.getUID(); + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + String pbdata = request.getParameter("pbdata"); +// if(StringUtils.isBlank(pb)){ +// +// JSONArray jsonArray = new JSONArray(); +// JSONObject userObject = new JSONObject(); +// userObject.put("userid","3039"); +// userObject.put("serialid","10"); +// jsonArray.add(userObject); +// +// userObject = new JSONObject(); +// userObject.put("userid","3373"); +// userObject.put("serialid","7"); +// jsonArray.add(userObject); +// +// userObject = new JSONObject(); +// userObject.put("userid","3661"); +// userObject.put("serialid","9"); +// jsonArray.add(userObject); +// pb = jsonArray.toJSONString(); +// } + String yjl = request.getParameter("yjl"); + String pbrq = request.getParameter("pbrq"); + String dateType = "0"; + if(StringUtils.isNotBlank(pbrq)){ + dateType = getWeekTypeByDate(pbrq,userid+""); + } + + Map defaultScheduleMap = new HashMap(); + if(StringUtils.isNotBlank(yjl)){ + String sql = " select dysjd,pzrs from uf_pbjcsj where yjl = ? and pblx = ?" ; + rs.executeQuery(sql,new Object[]{yjl,dateType}); + while (rs.next()){ + int dysd = Util.getIntValue(Util.null2String(rs.getString("dysjd"))); + int pzrs = Util.getIntValue(Util.null2String(rs.getString("pzrs"))); + + String sjd = ""; + if(dysd < workSchedule.length){ + sjd = workSchedule[dysd]; + if(StringUtils.isNotBlank(sjd)){ + defaultScheduleMap.put(sjd,pzrs); + } + } + } + } + + List> workScheduleList = new ArrayList>(); + Map workScheduleMap = null; + for(int k=0;k0){ + String[] schedule = workSchedule[k].split("-"); + String scheduleStartTime = schedule[0]; + String scheduleEndTime = schedule[1]; + if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){ + workScheduleMap = new HashMap(); + workScheduleMap.put("start",scheduleStartTime); + workScheduleMap.put("end",scheduleEndTime); + workScheduleList.add(workScheduleMap); + } + } + } + + Map> userScheduleDayMap = new HashMap>(); + + Map userScheduleMap = new HashMap(); + Map necessaryMap = new HashMap(); + if(StringUtils.isNotBlank(pbdata)) { + JSONArray jsonArray = JSONArray.parseArray(pbdata); + + String yxrys = "" ; + for(int i = 0;i"); + List userList = new ArrayList(); + String sql =" select h.id \n" + + " from hrmresource h \n" + + " inner join hrmjobtitles k on k.id = h.jobtitle\n" + + " where h.id in("+yxrys+")\n" + + " and k.jobtitlename in('店长','验光师')\n" + + " and h.status in(0,1,2,3,4)\n" + + " union \n" + + " select h.id \n" + + " from hrmresource h \n" + + " inner join cus_fielddata k on k.id = h.id\n" + + " where k.field39 = 2 \n" + + " and k.scopeid=3 \n" + + " and k.scope='HrmCustomFieldByInfoType' " + + " and h.id in("+yxrys+") and h.status in(0,1,2,3,4) " + + " union " + + " select h.id\n" + + " from hrmresource h \n" + + " inner join cus_fielddata k on k.id = h.id \n" + + " where k.scopeid=-1 " + + " and k.scope='HrmCustomFieldByInfoType'\n" + + " and substring(k.field1,charindex('_',k.field1)+1,len(k.field1)) in(select id from uf_gwjbsjb where jbmc in('配镜三级','配镜四级','配镜五级')) and charindex('_', k.field1) > 0 \n" + + " and h.status in(0,1,2,3,4) "+ + " and h.id in("+yxrys+") "; + + out.println("sql:"+sql+"
"); + rs.executeQuery(sql); + while (rs.next()){ + String id = Util.null2String(rs.getString("id")); + out.println("id:"+id+"
"); + userList.add(id); + } + + for(int i = 0;i userSchedule_Map = new HashMap(); + if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){ + userSchedule_Map.put("startTime",startTime); + userSchedule_Map.put("endTime",endTime); + + + for(int k=0;k workSchedule_Map = workScheduleList.get(k); + String scheduleStartTime = workSchedule_Map.get("start"); + String scheduleEndTime = workSchedule_Map.get("end"); + if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){ + if(startTime.compareTo(scheduleStartTime) <=0 && endTime.compareTo(scheduleEndTime) >=0){ + + String defWorkSchedule = scheduleStartTime+"-"+scheduleEndTime ; + if(userScheduleMap.containsKey(defWorkSchedule)){ + int count = userScheduleMap.get(defWorkSchedule); + count++; + userScheduleMap.put(defWorkSchedule,count); + }else{ + userScheduleMap.put(defWorkSchedule,1); + } + + if(userList.contains(pbry)){ + necessaryMap.put(defWorkSchedule,1); + } + } + } + } + } + userScheduleDayMap.put(pbry,userSchedule_Map); + } + } + + int defaultcount = 0; + int datacount = 0; + Iterator> iterator = defaultScheduleMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + int value =entry.getValue(); + String key = entry.getKey(); + if(userScheduleMap.containsKey(key)){ + int useValue = userScheduleMap.get(key); + if(useValue < value){ + datacount++; + } + }else{ + datacount++; + } + defaultcount++; + } + + out.println("necessaryMap:"+necessaryMap.size()); + + JSONObject jsonObject = new JSONObject(); + if(defaultcount >0 && datacount == 0){ + if(necessaryMap.size() == 4){ + jsonObject.put("pbcode","1"); + }else{ + jsonObject.put("pbcode","2"); + } + }else{ + jsonObject.put("pbcode","0"); + } + + jsonObject.put("pbinfo",userScheduleDayMap); +%> + +<%=jsonObject.toJSONString() %> + +<%! + + public String getWeekTypeByDate(String pbrq,String userid){ + + String dateType = "0"; + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate currentDate = LocalDate.parse(pbrq, df); + + DayOfWeek dayOfWeek = currentDate.getDayOfWeek(); + int weekValue = dayOfWeek.getValue(); + + LocalDate lastDayOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天 + LocalDate startDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天 + String monthStartDate = startDayOfMonth.toString(); + String monthEndDate = lastDayOfMonth.toString(); + Map holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate); + + String changeType = "" ; + if(holidayMap.containsKey(currentDate.toString())){ + changeType = holidayMap.get(currentDate.toString()); + } + + if("1".equals(changeType) || "3".equals(changeType)){ + dateType = "1"; + }else if(weekValue == 6 || weekValue == 7){ + dateType = "1"; + } + return dateType; + } + + /*** + * + * @param userid + * @param monthStartDate + * @param monthEndDate + * @return + */ + public Map getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){ + + Map holidayMap = new HashMap(); + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + + try { + if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){ + String activeGroupId = getUserActiveGroupId(userid); + bb.writeLog("activeGroupId:"+activeGroupId); + if(StringUtils.isNotBlank(activeGroupId)){ + String sql =" select holidayDate,changeType from KQ_HolidaySet\n" + + " where groupid = " + activeGroupId+ + " and holidayDate >='"+monthStartDate+"'\n" + + " and holidayDate <='"+monthEndDate+"' " ; + rs.execute(sql); + while (rs.next()){ + String holidayDate = Util.null2String(rs.getString("holidayDate")); + String changeType = Util.null2String(rs.getString("changeType")); +// String changeTypename = "" ; +// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日 +// changeTypename += "公众假日"; +// }else if("2".equals(changeType)){ +// changeTypename += "调配工作日"; +// }else if("3".equals(changeType)){ +// changeTypename += "调配休息日"; +// } + holidayMap.put(holidayDate,changeType); + +// if(weekMap.containsKey(holidayDate)){ +// String holidayDate_new = weekMap.get(holidayDate); +// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日 +// holidayDate_new += "[公众假日]"; +// }else if("1".equals(changeType)){ +// holidayDate_new += "[调配工作日]"; +// }else if("2".equals(changeType)){ +// holidayDate_new += "[调配休息日]"; +// } +// weekMap.put(holidayDate,holidayDate_new); +// } + } + } + } + }catch (Exception e){ + + } + return holidayMap; + } + + /*** + * + * @param userid + * @return + */ + public String getUserActiveGroupId(String userid){ + BaseBean bb = new BaseBean(); + + KQGroupMemberComInfo kqGroupMemberComInfo = null; + KQGroupComInfo kqGroupComInfo = null ; + String activeGroupId = ""; + try{ + kqGroupMemberComInfo = new KQGroupMemberComInfo(); + kqGroupComInfo = new KQGroupComInfo(); + + Map> groupMemberMap = getUserGroup(); + + String activeGroup = ""; + if(groupMemberMap.containsKey(userid)){ + List groupIds = groupMemberMap.get(userid); + bb.writeLog("groupIds:"+groupIds.size()); + + for(String i : groupIds){ + String isDelete = kqGroupComInfo.getIsdelete(i); + if(!"1".equals(isDelete)) { + String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate())); + if (i.equals(currentGroupId)) { + activeGroupId = i; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog(e); + } + return activeGroupId; + } + + + /*** + * + * @return + */ + public Map> getUserGroup(){ + BaseBean bb = new BaseBean(); + Map> groupMemberMap = new HashMap<>(); + RecordSet rs = new RecordSet(); + String viewScope = "3"; + try { + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + Map groupParams = new HashMap(); + if("3".equals(viewScope)){ + groupParams.put("isNoAccount", "1"); + } + rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams)); + while (rs.next()) { + String id = rs.getString("resourceid"); + String gid = rs.getString("groupid"); + if (!groupMemberMap.containsKey(id)) + groupMemberMap.put(id, new ArrayList<>()); + groupMemberMap.get(id).add(gid); + } + } catch (Exception e) { + } + return groupMemberMap; + } + + +%> + + diff --git a/src/com/engine/kq/biz/KQFormatBiz.java b/src/com/engine/kq/biz/KQFormatBiz.java new file mode 100644 index 0000000..451af0d --- /dev/null +++ b/src/com/engine/kq/biz/KQFormatBiz.java @@ -0,0 +1,339 @@ +package com.engine.kq.biz; + +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import weaver.common.DateUtil; +import weaver.conn.BatchRecordSet; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 考勤数据格式化 + */ +public class KQFormatBiz extends BaseBean { + private String today = DateUtil.getCurrentDate(); + protected KQLog kqLog = new KQLog(); + + /** + * 考勤报表格式化 + * + * @param lsFormatParams + */ + public void format(List> lsFormatParams) { + format(lsFormatParams, -1); + } + + /** + * 考勤报表格式化 + * @param lsFormatParams + * @param formatType -1: 其他; 11:右键重新计算考勤数据; 12: 考勤自动和手动同步;13:钉钉同步或者导入; 14:云桥考勤同步 15: 考勤导入;16:排班更新 + */ + public void format(List> lsFormatParams, int formatType) { + BatchRecordSet bRs = new BatchRecordSet(); + String sql = ""; + List params = null; + try { + for(List list : lsFormatParams) { + list.add(formatType); + } + if (KQSettingsBiz.getKqformatthread()) { + sql = " insert into kq_format_pool (resourceid, kqdate, formattype) values (?,?,?)"; + if (KQSettingsBiz.getKqformatAccurate()){ + sql = " insert into kq_format_pool (resourceid, kqdate, exectime,formattype) values (?,?,?,?)"; + lsFormatParams = processFormatParams(lsFormatParams); + } + bRs.executeBatchSqlNew(sql, lsFormatParams); + } else { + String resourceid = ""; + String kqdate = ""; + for (int i = 0; lsFormatParams != null && i < lsFormatParams.size(); i++) { + params = lsFormatParams.get(i); + resourceid = Util.null2String(params.get(0)); + kqdate = Util.null2String(params.get(1)); + new KQFormatData().formatKqDateByLock(resourceid, kqdate,formatType); + } + } + } catch (Exception e) { + writeLog(" KQFormatData.formatKqDate lsFormatParams >>>>>>>>>" + e); + } + } + + public void formatDateByKQDate(String kqdate) { + String sql = ""; + RecordSet rs = new RecordSet(); + List> lsFormatParams = new ArrayList<>(); + List formatParams = null; + try { + if (DateUtil.timeInterval(kqdate, today) < 0) { + kqLog.info("今天之后的无需处理的数据:kqdate==" + kqdate + "today==" + today); + return;//今天之后的无需处理 + } + + sql = " SELECT distinct resourceid FROM ( " + + new KQGroupBiz().getGroupMemberSql() + ") t "; + rs.executeQuery(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + if(Util.null2String(kqdate).length()!=10)return; + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(kqdate); + lsFormatParams.add(formatParams); + } + this.format(lsFormatParams); + } catch (Exception e) { + writeLog(e); + kqLog.info(e); + } + } + + public void formatDateByGroupId(String groupid, String kqdate) { + String sql = ""; + RecordSet rs = new RecordSet(); + List> lsFormatParams = new ArrayList<>(); + List formatParams = null; + try { + if (DateUtil.timeInterval(kqdate, today) < 0) { + kqLog.info("今天之后的无需处理的数据:groupid==" + groupid + "kqdate==" + kqdate + "today==" + today); + return;//今天之后的无需处理 + } + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + String kqtype = kqGroupComInfo.getKqtype(groupid); + if (kqtype.equals("2")) {//排班 + sql = "select resourceid, kqdate from kq_shiftschedule where groupid=" + groupid + " and kqdate='" + kqdate + "' and (isdelete is null or isdelete <> '1') "; + } else { + sql = "select resourceid,'" + kqdate + "' from (" + kqGroupBiz.getGroupMemberSql(groupid) + ") t "; + } + rs.executeQuery(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + if(Util.null2String(kqdate).length()!=10)return; + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(kqdate); + lsFormatParams.add(formatParams); + } + this.format(lsFormatParams); + } catch (Exception e) { + writeLog(e); + kqLog.info(e); + } + } + + public void formatDate(String resourceid, String kqdate) { + List> lsFormatParams = new ArrayList<>(); + List formatParams = null; + try { + if (DateUtil.timeInterval(kqdate, today) < 0) { + kqLog.info("今天之后的无需处理的数据:resourceid==" + resourceid + "kqdate==" + kqdate + "today==" + today); + return;//今天之后的无需处理 + } + if(Util.null2String(kqdate).length()!=10)return; + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(kqdate); + lsFormatParams.add(formatParams); + this.format(lsFormatParams); + } catch (Exception e) { + writeLog(e); + kqLog.info(e); + } + } + + public void delFormatData(String resourceid, String kqdate) { + RecordSet rs = new RecordSet(); + String sql = ""; + try { + sql = " delete from kq_format_detail where resourceid =? and kqdate = ? ";//删除非工作日数据 + rs.executeUpdate(sql, resourceid, kqdate); + + sql = " delete from kq_format_total where resourceid =? and kqdate = ? ";//删除非工作日数据 + rs.executeUpdate(sql, resourceid, kqdate); + } catch (Exception e) { + writeLog(e); + kqLog.info(e); + } + } + + public void clearFormatPool() { + RecordSet rs = new RecordSet(); + String sql = ""; + try { + //删除三天前的数据格式化数据 + if (rs.getDBType().equals("sqlserver")) { + sql = " delete from kq_format_pool where status = 1 and datediff(day,created,getdate()) > 1"; + } else if (rs.getDBType().equals("mysql")) { + sql = " delete from kq_format_pool where status = 1 and datediff(now(),created) > 1"; + } + else if (rs.getDBType().equals("postgresql")) { + sql = " delete from kq_format_pool where status = 1 and datediff(now(),created) > 1"; + } + else if (rs.getOrgindbtype().equals("st")) { + sql = " delete from kq_format_pool where status = 1 and to_number(trunc(sysdate) - trunc(created)) > 1"; + } else { + sql = " delete from kq_format_pool where status = 1 and trunc(sysdate) - trunc(created) > 1"; + } + rs.executeUpdate(sql); + } catch (Exception e) { + writeLog(e); + } + } + + public Map getDefinedField(){ + Map retMap = new HashMap<>(); + String definedField = ""; + String definedFieldSum = ""; + String definedParam = ""; + String definedParamSum = ""; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (!Util.null2String(kqReportFieldComInfo.getIsenable()).equals("1")) continue; + if (Util.null2String(kqReportFieldComInfo.getIsSystem()).equals("1")) continue; + if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue; + + if(definedField.length()>0)definedField+=","; + definedField+=kqReportFieldComInfo.getFieldname(); + + if(definedFieldSum.length()>0)definedFieldSum+=","; + definedFieldSum+="sum("+kqReportFieldComInfo.getFieldname()+") as "+kqReportFieldComInfo.getFieldname(); + + if(definedParam.length()>0)definedParam+=","; + definedParam+="?"; + + if(definedParamSum.length()>0)definedParamSum+=","; + definedParamSum+="sum("+kqReportFieldComInfo.getFieldname()+")"; + + String[] cascadekeys = Util.splitString(Util.null2String(kqReportFieldComInfo.getCascadekey()),","); + for(int i=0;cascadekeys!=null&&i0)definedField+=","; + definedField+=fieldname; + + if(definedFieldSum.length()>0)definedFieldSum+=","; + definedFieldSum+="sum("+fieldname+") as "+fieldname; + + if(definedParam.length()>0)definedParam+=","; + definedParam+="?"; + + if(definedParamSum.length()>0)definedParamSum+=","; + definedParamSum+="sum("+fieldname+")"; + } + } + retMap.put("definedField",definedField); + retMap.put("definedFieldSum",definedFieldSum); + retMap.put("definedParam",definedParam); + retMap.put("definedParamSum",definedParamSum); + return retMap; + } + + public boolean needCal(String workDate, String workTime){ + boolean needCalForgotCheckMins = true; + if (KQSettingsBiz.getKqformatAccurate()) { + workTime = new KQTimesArrayComInfo().turn48to24Time(workTime); + if (workDate.length() > 0 && workTime.length() > 0) { + String currentFullTime = DateUtil.getFullDate(); + String endTime = workDate + " " + workTime; + if (DateUtil.timeInterval(currentFullTime, endTime) > 0) { + //当前时间之后的状态无效计算 + needCalForgotCheckMins = false; + } + kqLog.writeLog("currentFullTime:"+currentFullTime+"wroktime:"+endTime+"needCalForgotCheckMins:"+needCalForgotCheckMins); + } + } + return needCalForgotCheckMins; + } + + public boolean needCal(String workDate, String workTime,String isneedcal){ + boolean needCalForgotCheckMins = true; + boolean isneedformat = "1".equals(isneedcal); + if (isneedformat) { + workTime = new KQTimesArrayComInfo().turn48to24Time(workTime); + if (workDate.length() > 0 && workTime.length() > 0) { + String currentFullTime = DateUtil.getFullDate(); + String endTime = workDate + " " + workTime; + if (DateUtil.timeInterval(currentFullTime, endTime) > 0) { + //当前时间之后的状态无效计算 + needCalForgotCheckMins = false; + } + } + } + return needCalForgotCheckMins; + } + + private List> processFormatParams(List> lsFormatParams) { + List> lsFormatParamsTmp = new ArrayList<>(); + try { + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + KQWorkTime kqWorkTime = new KQWorkTime(); + List formatParams = null; + for(int i=0;i 2) { + formattype = Util.null2String(formatParams.get(2)); + } + + formatParams = new ArrayList<>(); + formatParams.add(resourceId); + formatParams.add(kqDate); + formatParams.add(new java.sql.Timestamp(DateUtil.getCalendar(DateUtil.getFullDate()).getTimeInMillis())); + formatParams.add(formattype); + lsFormatParamsTmp.add(formatParams); + + String nextDate = DateUtil.addDate(kqDate, 1);//下一天日期 + WorkTimeEntity workTime = kqWorkTime.getWorkTime(resourceId, kqDate); + List lsWorkTime = new ArrayList<>(); + if (workTime != null) { + lsWorkTime = workTime.getWorkTime();//工作时间 + for (int j = 0; lsWorkTime != null && j < lsWorkTime.size(); j++) { + TimeScopeEntity workTimeScope = lsWorkTime.get(j); + String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? nextDate : kqDate; + workBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime())+":00:00"; + String workEndDateTime = workTimeScope.getEndTimeAcross() ? nextDate : kqDate; + workEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime())+":00:00"; + + formatParams = new ArrayList<>(); + formatParams.add(resourceId); + formatParams.add(kqDate); + formatParams.add(new java.sql.Timestamp(DateUtil.getCalendar(workBeginDateTime).getTimeInMillis())); + formatParams.add(formattype); + lsFormatParamsTmp.add(formatParams); + + formatParams = new ArrayList<>(); + formatParams.add(resourceId); + formatParams.add(kqDate); + formatParams.add(new java.sql.Timestamp(DateUtil.getCalendar(workEndDateTime).getTimeInMillis())); + formatParams.add(formattype); + lsFormatParamsTmp.add(formatParams); + } + }else{ + formatParams = new ArrayList<>(); + formatParams.add(resourceId); + formatParams.add(kqDate); + formatParams.add(formattype); + lsFormatParamsTmp.add(formatParams); + } + } + + }catch (Exception e) { + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + return lsFormatParamsTmp; + } +} diff --git a/src/com/engine/kq/biz/KQLeaveRulesBiz.java b/src/com/engine/kq/biz/KQLeaveRulesBiz.java new file mode 100644 index 0000000..b0c4b4c --- /dev/null +++ b/src/com/engine/kq/biz/KQLeaveRulesBiz.java @@ -0,0 +1,1307 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSONObject; +import com.api.hrm.util.ServiceUtil; +import com.engine.kq.entity.KQBalanceOfLeaveEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.KQTransMethod; +import com.weaver.general.TimeUtil; +import org.apache.commons.lang.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.StringUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.common.Tools; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +public class KQLeaveRulesBiz { + + public static final ThreadLocal THREAD_LOCAL = new ThreadLocal<>(); + + + /** + * 记录日志 + */ + private static KQLog logger = new KQLog(); + + /** + * 根据假期规则ID获取假期规则名称 + * + * @param ruleId 假期规则的ID + * @return + */ + public static String getLeaveName(String ruleId) { + String leaveName = ""; + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + leaveName = kqLeaveRulesComInfo.getLeaveName(ruleId); + return leaveName; + } + + /** + * 判断是否具有假期余额 + * + * @param ruleId + * @return + */ + public static boolean getBalanceEnable(String ruleId) { + int balanceEnable = 0; + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + balanceEnable = Util.getIntValue(kqLeaveRulesComInfo.getBalanceEnable(ruleId), 0); + if (balanceEnable == 1) { + return true; + } else { + return false; + } + } + /** + * 判断优先假期类型id字符串 + * + * @param ruleId + * @return + */ + public static String getLeaveids(String ruleId) { + int schevacationON = 0; + String schevacation = "-1"; + + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + schevacationON = Util.getIntValue(kqLeaveRulesComInfo.getSchevacationON(ruleId), 0); + if (schevacationON == 1) { + schevacation=Util.null2s(kqLeaveRulesComInfo.getSchevacation(ruleId), "-1"); + } + return schevacation; + + } + + /** + * 判断人员的假期类型id字符串 + * + * @param scheLeaveids + * @param resourceId + * @return + */ + public static String getusedLeaveids(String scheLeaveids, String resourceId) { + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcompanyId = resourceComInfo.getSubCompanyID(resourceId); + String departmentId = resourceComInfo.getDepartmentID(resourceId); + + List scheLeaveidsList = Util.splitString2List(scheLeaveids, ","); + + /** + * 加载应用范围为总部的以及应用范围为分部(但是范围中包含了所属分部ID)的假期规则 + */ + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_LeaveRules "; + String sqlWhere = " where (isDelete is null or isDelete <>1) and isEnable=1 and balanceEnable=1 "; + /*如果找不到人员所在分部,则只返回应用范围为总部的假期规则*/ + if (!resourceId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere += " and ( (scopeType=3 and ','+scopeValue+',' like '%," + resourceId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere += " and ( (scopeType=3 and concat(',',scopeValue,',') like '%," + resourceId + ",%') "; + } else { + sqlWhere += " and ( (scopeType=3 and ','||scopeValue||',' like '%," + resourceId + ",%') "; + } + } + if (!departmentId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere += " or (scopeType=2 and ','+scopeValue+',' like '%," + departmentId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere += " or (scopeType=2 and concat(',',scopeValue,',') like '%," + departmentId + ",%') "; + } else { + sqlWhere += " or (scopeType=2 and ','||scopeValue||',' like '%," + departmentId + ",%') "; + } + } + if (!subcompanyId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere += " or (scopeType=1 and ','+scopeValue+',' like '%," + subcompanyId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere += " or (scopeType=1 and concat(',',scopeValue,',') like '%," + subcompanyId + ",%') "; + } else { + sqlWhere += " or (scopeType=1 and ','||scopeValue||',' like '%," + subcompanyId + ",%') "; + } + } + + sqlWhere += " or scopeType=0 )"; + sql = sql + sqlWhere + " order by showOrder,id "; + scheLeaveids = ""; + List remleaveidsList = new ArrayList<>(); + recordSet.executeQuery(sql); + /*如果指定人员所在分部下面单独设置过假期规则,则取分部下面的假期规则*/ + while (recordSet.next()) { + String leaveid = recordSet.getString("id");//假期类型id + remleaveidsList.add(leaveid); + } + + for (String id : scheLeaveidsList) { + if (remleaveidsList.contains(id)) { + if (scheLeaveids.equals("")) { + scheLeaveids = id; + } else { + scheLeaveids += "," + id; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return scheLeaveids; + + } + /** + * 获取最小请假单位 + * 1-按天请假 + * 2-按半天请假 + * 3-按小时请假 + * 4-按整天请假 + * 其他:无效数据 + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static int getMinimumUnit(String ruleId) { + int minimumUnit = -1;//最小请假单位 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + minimumUnit = Util.getIntValue(kqLeaveRulesComInfo.getMinimumUnit(ruleId), -1); + return minimumUnit; + } + + /** + * 获取请假时长计算方式 + * 1-按照工作日计算请假时长 + * 2-按照自然日计算请假时长 + * 其他:无效数据 + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static int getComputingMode(String ruleId) { + int computingMode = -1;//计算请假时长方式 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + computingMode = Util.getIntValue(kqLeaveRulesComInfo.getComputingMode(ruleId), -1); + return computingMode; + } + + /** + * 按照自然日计算请假时长排除节假日、休息日 + * 0-不排除 + * 1-排除节假日 + * 2-排除休息日 + * 1,2-排除节假日和休息日 + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static String getFilterHolidays(String ruleId) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String filterHolidays = Util.null2s(kqLeaveRulesComInfo.getFilterHolidays(ruleId), "0"); + return filterHolidays; + } + + /** + * 获取日折算时长(多少小时算一天) + * + * @param ruleId 指定的假期规则ID + * @return + */ + public static String getHoursToDay(String ruleId) { + double hoursToDay = -1;//日折算时长 + int computingMode = -1;//计算请假时长方式 + int minimumUnit = -1;//最小请假单位 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + hoursToDay = Util.getDoubleValue(kqLeaveRulesComInfo.getHoursToDay(ruleId), -1); + computingMode = Util.getIntValue(kqLeaveRulesComInfo.getComputingMode(ruleId), -1); + minimumUnit = Util.getIntValue(kqLeaveRulesComInfo.getMinimumUnit(ruleId), -1); + if (computingMode != 2) { + hoursToDay = -1; + } + return String.format("%.2f", hoursToDay); + } + + /** + * 1-按天请假 + * 2-按半天请假 + * 3-按小时请假 + * 4-按整天请假 + * + * @param minimumUnit + * @param lan + * @return + */ + public static String getMinimumUnitName(String minimumUnit, int lan) { + String minimumUnitName = ""; + switch (minimumUnit) { + case "1": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + case "2": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + case "3": + case "5": + case "6": + minimumUnitName = SystemEnv.getHtmlLabelName(391, lan); + break; + case "4": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + default: + break; + } + return minimumUnitName; + } + + /** + * 获取所有的假期规则 + * unitType:1-按天请假、2-按半天请假、3-按小时请假、4-按整天请假、-1:数据异常,无效数据 + * + * @return + */ + public static List> getAllLeaveRules() { + Map ruleMap = new HashMap(); + List> ruleList = new ArrayList>(); + + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + kqLeaveRulesComInfo.setTofirstRow(); + while (kqLeaveRulesComInfo.next()) { + if (kqLeaveRulesComInfo.getIsEnable().equals("1")) { + ruleMap = new HashMap(); + ruleMap.put("id", kqLeaveRulesComInfo.getId()); + ruleMap.put("name", kqLeaveRulesComInfo.getLeaveName()); + ruleMap.put("unitType", kqLeaveRulesComInfo.getMinimumUnit()); + ruleMap.put("proportion", kqLeaveRulesComInfo.getProportion()); + ruleMap.put("scopeType",kqLeaveRulesComInfo.getScopeType()); + ruleMap.put("scopeValue",kqLeaveRulesComInfo.getScopeValue()); + ruleList.add(ruleMap); + } + } + return ruleList; + } + + /** + * 根据人员ID获取其可见的所有假期类型 + * + * @param resourceId 指定人员ID + * @return + */ + public static String getAllLeaveRulesByUserId(String resourceId, String languageId) { + String resultStr = ""; + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcomId = resourceComInfo.getSubCompanyID(resourceId); + String deptId = resourceComInfo.getDepartmentID(resourceId); + + List tempList = new ArrayList(); + + Map itemMap = new HashMap(); + List itemList = new ArrayList(); + + String sql = "select * from kq_leaveRules where 1=1 and (isDelete is null or isDelete <>1) and isEnable=1"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + while (recordSet.next()) { + String scopeType = recordSet.getString("scopeType"); + String scopeValue = recordSet.getString("scopeValue"); + String leaveName = recordSet.getString("leaveName"); + String id = recordSet.getString("id"); + + if (scopeType.equals("1")) { + tempList = Util.TokenizerString(scopeValue, ","); + if (!tempList.contains(subcomId)) { + continue; + } + } + + itemMap = new HashMap(); + itemMap.put("name", Util.formatMultiLang(leaveName, languageId)); + itemMap.put("id", id); + itemList.add(itemMap); + } + resultStr = JSONObject.toJSONString(itemList); + } catch (Exception e) { + e.printStackTrace(); + } + return resultStr; + } + public static boolean filterSubLeaveRule(KQLeaveRulesComInfo kqLeaveRulesComInfo, User user, String leaveId) { + return filterSubLeaveRule(Util.null2String(user.getUID()), kqLeaveRulesComInfo.getScopeType(leaveId), kqLeaveRulesComInfo.getScopeValue(leaveId), Util.null2String(user.getUserSubCompany1()),Util.null2String(user.getUserDepartment())); + } + public static boolean filterSubLeaveRule(String userId, String scopeType, String scopeValue, String subCompany, String deptId) { + boolean isAdmin = ServiceUtil.isAdmin(userId); + if (isAdmin) { + return false; + } + if ("1".equals(scopeType)) { + if (scopeValue.indexOf(",") > 0) { + String[] split = scopeValue.split(","); + for (String v : split) { + if (!StringUtil.isEmpty(v) && v.equals(subCompany)) { + return false; + } + } + return true; + } else { + return !scopeValue.equals(subCompany); + } + }else if("2".equals(scopeType)){ + if (scopeValue.indexOf(",") > 0) { + String[] split = scopeValue.split(","); + for (String v : split) { + if (!StringUtil.isEmpty(v) && v.equals(deptId)) { + return false; + } + } + return true; + } else { + return !scopeValue.equals(deptId); + } + }else if("3".equals(scopeType)){ + if (scopeValue.indexOf(",") > 0) { + String[] split = scopeValue.split(","); + for (String v : split) { + if (!StringUtil.isEmpty(v) && v.equals(userId)) { + return false; + } + } + return true; + } else { + return !scopeValue.equals(userId); + } + } + return false; + } + /** + * 初始化年假 + * + * @param ruleId + * @return + */ + public static boolean initAnnualLeave(int ruleId) { + boolean isInitSuccess = false; + try { + /*判断年假是否初始化过*/ + RecordSet recordSet = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='年假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=1," + + "isDelete=0,isEnable=1,leaveCode='annualLeave' where id=" + ruleId; + isInitSuccess = recordSet.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + + String deleteDetailSql = "delete from kq_LeaveRulesDetail where scopeType=0 and ruleId=" + ruleId; + recordSet.executeUpdate(deleteDetailSql); + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('年假-总部规则'," + ruleId + ",0,'',3,0,1,0,'','',0,0,0,0)"; + isInitSuccess = recordSet.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'年假-初始化',0,'',1,8,1,1,0,1,'annualLeave')"; + isInitSuccess = recordSet.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('年假-总部规则'," + nextId + ",0,'',3,0,1,0,'','',0,0,0,0)"; + isInitSuccess = recordSet.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set annualLeave=" + nextId + " where id=1"; + isInitSuccess = recordSet.executeUpdate(historySql); + + ruleId = nextId; + } + + String detailId = ""; + sql = "select * from kq_LeaveRulesDetail where scopeType=0 and ruleId=" + ruleId; + recordSet.executeQuery(sql); + if (recordSet.next()) { + detailId = recordSet.getString("id"); + } + if (detailId.equals("")) { + return false; + } + + /*先删除原来的明细记录,在插入新的明细记录*/ + String detailSql = "delete from kq_WorkingAgeToLeave where leaveRulesId=" + detailId; + isInitSuccess = recordSet.executeUpdate(detailSql); + if (!isInitSuccess) { + sql = "delete from kq_LeaveRules where leaveRulesId=" + detailId; + recordSet.executeUpdate(sql); + return false; + } + + /*插入明细记录*/ + detailSql = "insert into kq_WorkingAgeToLeave(leaveRulesId,lowerLimit,upperLimit,amount) values(?,?,?,?)"; + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 0, 1, 0); + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 1, 10, 5); + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 10, 20, 10); + isInitSuccess = recordSet.executeUpdate(detailSql, detailId, 20, 9999, 15); + } catch (Exception e) { + logger.info(e.getMessage()); + } + return isInitSuccess; + } + + /** + * 初始化带薪事假 + * + * @param ruleId + * @return + */ + public static boolean initPaidCompassionateLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='带薪事假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='paidCompassionateLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'带薪事假-初始化',0,'',1,8,1,0,0,1,'paidCompassionateLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set paidCompassionateLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化带薪病假 + * + * @param ruleId + * @return + */ + public static boolean initPaidSickLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='带薪病假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='paidSickLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'带薪病假-初始化',0,'',1,8,1,0,0,1,'paidSickLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set paidSickLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化调休 + * + * @param ruleId + * @return + */ + public static boolean initVacationLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='调休-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=1," + + "isDelete=0,isEnable=1,leaveCode='vacationLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + + String deleteDetailSql = "delete from kq_LeaveRulesDetail where scopeType=0 and ruleId=" + ruleId; + rs.executeUpdate(deleteDetailSql); + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('调休-总部规则'," + ruleId + ",0,'',5,0,1,0,'','',0,0,0,0)"; + isInitSuccess = rs.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + } else { + /*判断系统中是否已经存在调休了,如果已存在,则不允许新建新的调休假期*/ + sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id in (select ruleId from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5)"; + rs.executeQuery(sql); + if (rs.getCounts() > 0) { + return false; + } + + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'调休-初始化',0,'',1,8,1,1,0,1,'vacationLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String insertDetailSql = "insert into kq_LeaveRulesDetail(ruleName,ruleId,scopeType,scopeValue,distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod)" + + "values('调休-总部规则'," + nextId + ",0,'',5,0,1,0,'','',0,0,0,0)"; + isInitSuccess = rs.executeUpdate(insertDetailSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set vacationLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化事假 + * + * @param ruleId + * @return + */ + public static boolean initCompassionateLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='事假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='compassionateLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'事假-初始化',0,'',1,8,1,0,0,1,'compassionateLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set compassionateLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化病假 + * + * @param ruleId + * @return + */ + public static boolean initSickLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='病假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='sickLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'病假-初始化',0,'',1,8,1,0,0,1,'sickLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set sickLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化产假 + * + * @param ruleId + * @return + */ + public static boolean initMaternityLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='产假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=2,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='maternityLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'产假-初始化',0,'',1,8,2,0,0,1,'maternityLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set maternityLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化陪产假 + * + * @param ruleId + * @return + */ + public static boolean initPaternityLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (recordSet.next()) { + String updateSql = "update kq_LeaveRules set leaveName='陪产假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=2,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='paternityLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'陪产假-初始化',0,'',1,8,2,0,0,1,'paternityLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set paternityLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化婚假 + * + * @param ruleId + * @return + */ + public static boolean initMarriageLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='婚假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=2,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='marriageLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'婚假-初始化',0,'',1,8,2,0,0,1,'marriageLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set marriageLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化丧假 + * + * @param ruleId + * @return + */ + public static boolean initFuneralLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='丧假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='funeralLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'丧假-初始化',0,'',1,8,1,0,0,1,'funeralLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set funeralLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 初始化哺乳假 + * + * @param ruleId + * @return + */ + public static boolean initBreastfeedingLeave(int ruleId) { + /*判断是否初始化过*/ + RecordSet recordSet = new RecordSet(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete<>1) and id=" + ruleId; + recordSet.executeQuery(sql); + boolean initialized = recordSet.getCounts() > 0; + + /*没有初始化过就新建,已经初始化过就更新*/ + boolean isInitSuccess = false; + if (initialized) { + String updateSql = "update kq_LeaveRules set leaveName='哺乳假-初始化',scopeType=0,scopeValue='',minimumUnit=1,hoursToDay=8,computingMode=1,balanceEnable=0," + + "isDelete=0,isEnable=1,leaveCode='breastfeedingLeave' where id=" + ruleId; + isInitSuccess = rs.executeUpdate(updateSql); + if (!isInitSuccess) { + return false; + } + } else { + KQTransMethod kqTransMethod = new KQTransMethod(); + int nextId = kqTransMethod.getNextId(); + + String insertSql = "insert into kq_LeaveRules(id,leaveName,scopeType,scopeValue,minimumUnit,hoursToDay,computingMode,balanceEnable,isDelete,isEnable,leaveCode)" + + "values(" + nextId + ",'哺乳假-初始化',0,'',1,8,1,0,0,1,'breastfeedingLeave')"; + isInitSuccess = rs.executeUpdate(insertSql); + if (!isInitSuccess) { + return false; + } + + String historySql = "update kq_initHistory set breastfeedingLeave=" + nextId + " where id=1"; + isInitSuccess = rs.executeUpdate(historySql); + } + return isInitSuccess; + } + + /** + * 根据人员ID以及名称获取对应的假期规则ID(主要对于对接小E) + * + * @param resourceId 人员ID + * @param leaveName 假期规则名称 + * @return + */ + public static List getLeaveRuleIdByName(String resourceId, String leaveName) { + List dataList = new ArrayList(); + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcomId = resourceComInfo.getSubCompanyID(resourceId); + + Map dataMap = new HashMap(); + + String sql = "select * from kq_LeaveRules where (isDelete is null or isDelete <>1) and isEnable=1 and leaveName like '%" + leaveName + "%'"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + while (recordSet.next()) { + int scopeType = Util.getIntValue(recordSet.getString("scopeType"), 0); + String scopeValue = Util.null2String(recordSet.getString("scopeValue")); + + if (scopeType == 1) { + List tempList = Util.TokenizerString(scopeValue, ","); + if (!tempList.contains(subcomId)) { + continue; + } + } + + dataMap = new HashMap(); + dataMap.put("ruleId", recordSet.getString("id")); + dataMap.put("name", Util.formatMultiLang(recordSet.getString("leaveName"), "7")); + dataList.add(dataMap); + } + } catch (Exception e) { + e.printStackTrace(); + } + return dataList; + } + + /** + * 判断此请假类型是否是由 法定年假+福利年假 组合而成的混合模式 + * + * @param ruleId 指定的请假类型的id(对应于kq_LeaveRules表的主键ID) + * @return true--是混合模式、false--不是 + */ + public static boolean isMixMode(String ruleId) { + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=6 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + flag = true; + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + + /** + * 获取请假类型的颜色(随机生成) + * + * @return + */ + public static String getColor() { + String color = ""; + try { + StringBuffer result = new StringBuffer(); + for (int i = 0; i < 6; i++) { + //随机生成0-15的数值并转换成16进制 + result.append(Integer.toHexString(new Random().nextInt(16))); + } + color = "#" + result.toString().toUpperCase(); + } catch (Exception e) { + System.out.println("获取16进制字符串异常,返回默认..."); + color = "#00CCCC"; + } + return color; + } + + public static String getChildName(String balanceofleaveid){ + String name = ""; + try { + String sql = "select childId from kq_balanceOfLeave where id=?"; + RecordSet recordSet = new RecordSet(); + KQChildrenComInfo kqChildrenComInfo = new KQChildrenComInfo(); + recordSet.executeQuery(sql, balanceofleaveid); + if (recordSet.next()) { + String chlid = Util.null2s(recordSet.getString("childId"), ""); + if(StringUtils.isNotBlank(chlid)){ + name= kqChildrenComInfo.getChildrenName(chlid); + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return name; + } + /** + * 是否是调休 + * @param ruleId + * @return + */ + public static boolean isTiaoXiu(String ruleId){ + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + flag = true; + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + + public static boolean isTiaoXiu(String ruleId, String subCompanyId, String departmentId, String resourceId) { + boolean flag = false; + RecordSet recordSet = new RecordSet(); + try { + KQLeaveRulesDetailComInfo detailComInfo = new KQLeaveRulesDetailComInfo(); + recordSet.writeLog("isTiaoXiu>>1=" +ruleId+";2="+ subCompanyId+";3="+ departmentId+";4="+ resourceId ); + int distributionMode = Util.getIntValue(detailComInfo.getDistributionMode(ruleId, subCompanyId, departmentId, resourceId), 1); + if (distributionMode == 5) { + flag = true; + } + recordSet.writeLog("isTiaoXiu>>distributionMode=" +distributionMode); +// if (!flag) { + if (true) { + + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) " + + "and distributionMode=5 and ruleId=? "; + String sqlWhere = ""; + if (!resourceId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=3 and ','+scopeValue+',' like '%," + resourceId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=3 and concat(',',scopeValue,',') like '%," + resourceId + ",%') "; + } else { + sqlWhere = " and (scopeType=3 and ','||scopeValue||',' like '%," + resourceId + ",%') "; + } + recordSet.writeLog("isTiaoXiu>>sql1=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } else if (!departmentId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=2 and ','+scopeValue+',' like '%," + departmentId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=2 and concat(',',scopeValue,',') like '%," + departmentId + ",%') "; + } else { + sqlWhere = " and (scopeType=2 and ','||scopeValue||',' like '%," + departmentId + ",%') "; + } + recordSet.writeLog("isTiaoXiu>>sql2=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } else if (!subCompanyId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=1 and ','+scopeValue+',' like '%," + subCompanyId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=1 and concat(',',scopeValue,',') like '%," + subCompanyId + ",%') "; + } else { + sqlWhere = " and (scopeType=1 and ','||scopeValue||',' like '%," + subCompanyId + ",%') "; + } + recordSet.writeLog("isTiaoXiu>>sql3=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } else { + sqlWhere = " and scopeType=0 "; + recordSet.writeLog("isTiaoXiu>>sql4=" + sql + sqlWhere); + recordSet.executeQuery(sql + sqlWhere, ruleId); + if (recordSet.next()) { + return true; + } + } + } + + recordSet.writeLog("isTiaoXiu>>flag=" + flag); + } catch (Exception e) { + recordSet.writeLog(e.getMessage()); + recordSet.writeLog(e); + } + return flag; + } + + public static int getTiaoXiu(String subCompanyId, String departmentId, String resourceId) { + int ruleid = 0; + RecordSet recordSet = new RecordSet(); + try { + + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) " + + "and distributionMode=5 "; + String sqlWhere = ""; + if (!resourceId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=3 and ','+scopeValue+',' like '%," + resourceId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=3 and concat(',',scopeValue,',') like '%," + resourceId + ",%') "; + } else { + sqlWhere = " and (scopeType=3 and ','||scopeValue||',' like '%," + resourceId + ",%') "; + } + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + } + if (!departmentId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=2 and ','+scopeValue+',' like '%," + departmentId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=2 and concat(',',scopeValue,',') like '%," + departmentId + ",%') "; + } else { + sqlWhere = " and (scopeType=2 and ','||scopeValue||',' like '%," + departmentId + ",%') "; + } + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + } + if (!subCompanyId.equals("")) { + if (recordSet.getDBType().equalsIgnoreCase("sqlserver")) { + sqlWhere = " and (scopeType=1 and ','+scopeValue+',' like '%," + subCompanyId + ",%') "; + } else if (recordSet.getDBType().equalsIgnoreCase("mysql")) { + sqlWhere = " and (scopeType=1 and concat(',',scopeValue,',') like '%," + subCompanyId + ",%') "; + } else { + sqlWhere = " and (scopeType=1 and ','||scopeValue||',' like '%," + subCompanyId + ",%') "; + } + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + } + + sqlWhere = " and scopeType=0 "; + + recordSet.executeQuery(sql + sqlWhere); + while (recordSet.next()) { + ruleid = recordSet.getInt("ruleId"); + return ruleid; + } + + } catch (Exception e) { + recordSet.writeLog(e.getMessage()); + recordSet.writeLog(e); + } + return ruleid; + } + + public static Map isRepeat(String ruleid,int scopeType,String scopeValue,User user,String ruleDetailId){ + Map result = new HashMap<>(); + result.put("flag","0");//0=未重复,1=重复了不让保存 +// String sql = "select id,ruleid,scopetype,scopevalue,distributionmode from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=5 "; + String sql = "select id,ruleid,scopetype,scopevalue,distributionmode from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) "; + RecordSet recordSet = new RecordSet(); + recordSet.writeLog("ruleid="+ruleid+",scopeType="+scopeType+",scopeValue="+scopeValue); + recordSet.executeQuery(sql); + while (recordSet.next()) { + String tmp_id = Util.null2String(recordSet.getString("id")); + String tmp_ruleid = Util.null2String(recordSet.getString("ruleid")); + String tmp_scopetype = Util.null2String(recordSet.getString("scopetype")); + String tmp_scopevalue = Util.null2String(recordSet.getString("scopevalue")); + String tmp_distributionmode = Util.null2String(recordSet.getString("distributionmode")); + recordSet.writeLog("tmp_id="+tmp_id+",tmp_ruleid="+tmp_ruleid+",tmp_scopetype="+tmp_scopetype+",tmp_scopevalue="+tmp_scopevalue); + if(tmp_ruleid.equals(ruleid) && ("".equals(ruleDetailId) || !tmp_id.equals(ruleDetailId))){ + //同一个假期类型,不能同时设置为【加班自动计入调休】和其他的规则,比如按工龄自动发放 + if(!tmp_distributionmode.equals("5")){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546798, user.getLanguage())); + return result; + } + } + + if(tmp_distributionmode.equals("5") && tmp_scopetype.equals(Util.null2String(scopeType)) && ("".equals(ruleDetailId) || !tmp_id.equals(ruleDetailId))){ + //总部级别的范围单独处理下,因为存在之前是分部级别,维护了分部id,这个时候即便是scopytype=0,但是scopevalue依然有值了,所以总部级别不用进行scopevalue的比对 + if("0".equals(tmp_scopetype)){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546797, user.getLanguage())); + return result; + } + if(null != scopeValue && scopeValue.indexOf(",")>-1){ + String[] values = scopeValue.split(","); + for (String value : values) { + if((","+tmp_scopevalue+",").indexOf(","+value+",")>-1){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546797, user.getLanguage())); + return result; + } + } + }else { + if((","+tmp_scopevalue+",").indexOf(","+scopeValue+",")>-1){ + result.put("flag","1"); + result.put("msg", SystemEnv.getHtmlLabelName(546797, user.getLanguage())); + return result; + } + } + } + } + + return result; + } + + /** + * 是否是育儿假,且不开启叠加 + * @param ruleId + * @return + */ + public static boolean isLeaveOfParental(String ruleId){ + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=8 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + String severalChildren = Util.null2s(recordSet.getString("severalChildren"), "0"); + if(severalChildren.equals("0")){ + flag = true; + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + /** + * 是否是育儿假且开启了叠加 + * @param ruleId + * @return + */ + public static boolean isLeaveOfParentalNum(String ruleId){ + boolean flag = false; + try { + String sql = "select * from kq_LeaveRulesDetail where (isDelete is null or isDelete<>1) and distributionMode=8 and ruleId=?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql, ruleId); + if (recordSet.next()) { + String severalChildren = Util.null2s(recordSet.getString("severalChildren"), "0"); + if(severalChildren.equals("1")){ + flag = true; + } + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return flag; + } + + /** + * 半天单位 时间选择方式:1-下拉框选择 、2-具体时间 + * @param ruleId + * @return + */ + public static int getTimeselection(String ruleId) { + int timeselection = 1;//最小请假单位 + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + timeselection = Util.getIntValue(kqLeaveRulesComInfo.getTimeSelection(ruleId), 1); + return timeselection; + } + + public void updateChildLeaveDate(int scopeType,String scopeValue,int validityRule,String ruleId){ + RecordSet rs = new RecordSet(); + try { + // 查询当年育儿假数据 + String sql = "select * from kq_balanceOfLeave where (isDelete is null or isDelete<>1) and leaveRulesId = "+ruleId ; + + if (scopeType == 1 ) { + sql += " and resourceid in (select id from hrmresource where subCompanyId1 in (" + scopeValue + ") )"; + }else if (scopeType == 2 ) { + sql += " and resourceid in (select id from hrmresource where departmentId in (" + scopeValue + ") )"; + }else if (scopeType == 3) { + sql += " and (" + Tools.getOracleSQLIn(scopeValue, "resourceid") + ") "; + } + KQBalanceOfLeaveEntity balanceEntity = null; + ArrayList balanceEntities = new ArrayList<>(); + rs.executeQuery(sql); + while (rs.next()) { + int id = rs.getInt("id"); + String childId = Util.null2s(rs.getString("childId"), ""); + if(StringUtils.isNotBlank(childId)){ + String expirationDate = Util.null2s(rs.getString("expirationDate"), ""); + String effectiveDate = Util.null2s(rs.getString("effectiveDate"), ""); + balanceEntity = new KQBalanceOfLeaveEntity(); + balanceEntity.setId(id); + balanceEntity.setExpirationDate(expirationDate); + balanceEntity.setEffectiveDate(effectiveDate); + balanceEntities.add(balanceEntity); + } + } + sql = " update kq_balanceOfLeave set expirationDate =? where id= ? "; + for (int i = 0; balanceEntities != null && i < balanceEntities.size(); i++) { + KQBalanceOfLeaveEntity balance = balanceEntities.get(i); + String uid = Util.null2String(balance.getId()); + String effectiveDate = Util.null2String(balance.getEffectiveDate()); + String expirationDate = "2222-12-31"; + if (validityRule != 0) { + expirationDate = TimeUtil.dateAdd(TimeUtil.yearAdd(effectiveDate, 1), -1); + } + rs.executeUpdate(sql, expirationDate,uid); + } + + }catch (Exception e){ + e.printStackTrace(); + rs.writeLog(e); + } + } +} diff --git a/src/com/engine/kq/biz/KQReportBiz.java b/src/com/engine/kq/biz/KQReportBiz.java new file mode 100644 index 0000000..f3626a7 --- /dev/null +++ b/src/com/engine/kq/biz/KQReportBiz.java @@ -0,0 +1,3653 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum; +import com.engine.kq.enums.FlowReportTypeEnum; +import com.engine.kq.enums.KqSplitFlowTypeEnum; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.KQDurationCalculatorUtil; + +import java.text.DecimalFormatSymbols; +import java.util.Map.Entry; + +import com.engine.kq.util.KQTransMethod; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.file.Prop; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import java.text.DecimalFormat; +import java.util.*; + +public class KQReportBiz extends BaseBean { + + private static DecimalFormat df = new DecimalFormat("0.00"); + + private DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + + public String format(double value) { +// DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + df.setMaximumFractionDigits(5); + df.setDecimalFormatSymbols(symbols); + return df.format(value); + } + + + private KQLog kqLog = new KQLog(); + /** + * 初始化当天考勤数据 + */ + public void initKQReportData(){ + String date = DateUtil.getCurrentDate(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + boolean hasInit = false; + sql = "select 1 from kq_report_check where check_date = ? "; + rs.executeQuery(sql,date); + if(rs.next()) { + hasInit = true; + } + + String beforeyesterday = DateUtil.addDate(date,-2); + String yesterday = DateUtil.addDate(date,-1); + if(!hasInit){ + //这里做过功能是每天都刷下考勤缓存 因为这个缓存也是异步的,一点都不稳定 + kqLog.info("begin do KQOneStopUp refreshCominfo invoke ..."); + new KQOneStopUp().refreshCominfo(); + kqLog.info("end do KQOneStopUp refreshCominfo invoke ..."); + + KQFormatBiz kqFormatBiz = new KQFormatBiz(); + kqFormatBiz.clearFormatPool(); + //格式化上上天数据 + kqFormatBiz.formatDateByKQDate(beforeyesterday); + //格式化上一天数据 + kqFormatBiz.formatDateByKQDate(yesterday); + //初始化今天数据 + kqFormatBiz.formatDateByKQDate(date); + + sql = " insert into kq_report_check(check_date) values (?)"; + rs.executeUpdate(sql,date); + + writeLog(date+"执行考勤报表数据格式化成功!"); + } + }catch (Exception e){ + writeLog(e); + } + } + + public Map getModel_ShiftRule(String i,String serialId) { + RecordSet rs = new RecordSet(); + HashMap sectionMap = new HashMap<>(); + String getStartWorkSections = "select * from kq_ShiftOnOffWorkSections where SERIALID=? and record=? "; + rs.executeQuery(getStartWorkSections,serialId,i); + while (rs.next()) { + String onoffworktype = Util.null2String(rs.getString("onoffworktype")); + String clockinnot = Util.null2s(Util.null2String(rs.getString("clockinnot")), "0"); + sectionMap.put(onoffworktype, clockinnot); + } + return sectionMap; + } + + /*** + * 获取考勤状态 + * @param resourceId + * @param fromdate + * @param todate + * @param isAll + * @return + */ + public List getKqDateInfo(String resourceId, String fromdate, String todate, boolean isAll) { + List kqdates = new ArrayList<>(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + Map kqdate = null; + List datas = null; + Map data = null; + sql = " select kqdate,serialid, workbegindate, workbegintime,workenddate, workendtime," + + " signintime,signouttime,beLateMins,graveBeLateMins,leaveEarlyMins,graveLeaveEarlyMins," + + " absenteeismMins, forgotCheckMins,forgotBeginWorkCheckMins,otherinfo,serialnumber "+ + " from kq_format_detail " + + " where resourceid=? and kqdate>=? and kqdate<=? "; + if(!isAll){ + if(rs.getDBType().equalsIgnoreCase("oracle") || Util.null2String(rs.getOrgindbtype()).equals("dm") || Util.null2String(rs.getOrgindbtype()).equals("st")) { + sql += " and nvl(beLateMins,0)+nvl(graveBeLateMins,0)+nvl(leaveEarlyMins,0)+nvl(graveLeaveEarlyMins,0)+nvl(absenteeismMins,0)+nvl(forgotCheckMins,0)+nvl(forgotBeginWorkCheckMins,0)>0 "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + sql += " and ifnull(beLateMins,0)+ifnull(graveBeLateMins,0)+ifnull(leaveEarlyMins,0)+ifnull(graveLeaveEarlyMins,0)+ifnull(absenteeismMins,0)+ifnull(forgotCheckMins,0)+ifnull(forgotBeginWorkCheckMins,0)>0 "; + }else { + sql += " and isnull(beLateMins,0)+isnull(graveBeLateMins,0)+isnull(leaveEarlyMins,0)+isnull(graveLeaveEarlyMins,0)+isnull(absenteeismMins,0)+isnull(forgotCheckMins,0)+isnull(forgotBeginWorkCheckMins,0)>0 "; + } + } + sql += " order by kqdate,serialnumber "; + + rs.executeQuery(sql,resourceId,fromdate, todate); + while(rs.next()){ + String serialnumber = Util.null2String(rs.getString("serialnumber")); + String serialid = Util.null2String(rs.getString("serialid")); + String workbegindate = Util.null2String(rs.getString("workbegindate")); + String workbegintime = Util.null2String(rs.getString("workbegintime")); + String workenddate = Util.null2String(rs.getString("workenddate")); + String workendtime = Util.null2String(rs.getString("workendtime")); + String signintime = Util.null2String(rs.getString("signintime")); + String signouttime = Util.null2String(rs.getString("signouttime")); + int beLateMins = rs.getInt("beLateMins"); + int graveBeLateMins = rs.getInt("graveBeLateMins"); + int leaveEarlyMins = rs.getInt("leaveEarlyMins"); + int graveLeaveEarlyMins = rs.getInt("graveLeaveEarlyMins"); + int absenteeismMins = rs.getInt("absenteeismMins"); + int forgotCheckMins = rs.getInt("forgotCheckMins"); + int forgotBeginWorkCheckMins = rs.getInt("forgotBeginWorkCheckMins"); + String otherinfo = Util.null2String(rs.getString("otherinfo")); + + String shift_begindate = ""; + String shift_beginworktime = ""; + String shift_enddate = ""; + String shift_endworktime = ""; + if(otherinfo.length() > 0){ + JSONObject otherinfo_object = JSONObject.parseObject(otherinfo); + if(otherinfo_object != null && !otherinfo_object.isEmpty()){ + JSONObject shiftRule = (JSONObject) otherinfo_object.get("shiftRule"); + if(shiftRule != null && !shiftRule.isEmpty()){ + shift_begindate = Util.null2String(shiftRule.get("shift_begindate")); + shift_beginworktime = Util.null2String(shiftRule.get("shift_beginworktime")); + shift_enddate = Util.null2String(shiftRule.get("shift_enddate")); + shift_endworktime = Util.null2String(shiftRule.get("shift_endworktime")); + if(shift_begindate.length() > 0){ + workbegindate = shift_begindate; + } + if(shift_beginworktime.length() > 0){ + workbegintime = shift_beginworktime; + } + if(shift_enddate.length() > 0){ + workenddate = shift_enddate; + } + if(shift_endworktime.length() > 0){ + workendtime = shift_endworktime; + } + } + } + } + + kqdate = new HashMap<>(); + datas = new ArrayList<>(); + kqdate.put("kqdate",Util.null2String(rs.getString("kqdate"))); + if(workbegindate.length()>0){ + data = new HashMap<>(); + data.put("workbegindate",workbegindate); + data.put("workbegintime",workbegintime); + data.put("signintime",signintime); + + data.put("workenddate",workenddate); + data.put("workendtime",workendtime); + data.put("signouttime",signouttime); + String status = ""; + if(beLateMins>0||graveBeLateMins>0){ + status = ButtonStatusEnum.BELATE.getStatusCode(); + } + if(forgotBeginWorkCheckMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.NOSIGN_ON.getStatusCode(); + } + if(leaveEarlyMins>0||graveLeaveEarlyMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.LEAVEERALY.getStatusCode(); + } + if(absenteeismMins>0){ + int isondutyfreecheck =0; + int isoffdutyfreecheck =0; + Map model_ShiftRule = getModel_ShiftRule(serialnumber, serialid); + Iterator iter = model_ShiftRule.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = (Entry) iter.next(); + String key = Util.null2String(entry.getKey()); + String value = Util.null2String(entry.getValue()); + if(key.equals("start")&&value.equals("1")){ + isondutyfreecheck = 1; + } + if(key.equals("end")&&value.equals("1")){ + isoffdutyfreecheck = 1; + } + } + data.put("start",isondutyfreecheck); + data.put("end",isoffdutyfreecheck); + if(status.length()>0)status+=","; + status += ButtonStatusEnum.ABSENT.getStatusCode(); + } + if(forgotCheckMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.NOSIGN.getStatusCode(); + } + data.put("status",status); + datas.add(data); + } + + kqdate.put("checkInfo",datas); + kqdates.add(kqdate); + } + } catch (Exception e) { + writeLog(e); + } + return kqdates; + } + + /** + * 获取真实的开始日期和结束日期,没有权限的人最大只能查询本季 + * @param fromDate + * @param toDate + * @param user + * @return + */ + public Map realDate(String fromDate, String toDate, User user, String reportType) { + Map dateMap = new HashMap<>(); + dateMap.put("fromDate", fromDate); + dateMap.put("toDate", toDate); + boolean hasRight = false; + if("-100".equals(reportType)) { + RecordSet rs = new RecordSet(); + String departmentId = ""; + rs.executeQuery("select subcompanyid1, departmentId from hrmresource where id = ?", user.getUID()); + if (rs.next()) { + departmentId = StringUtil.vString(rs.getString("departmentId")); + } + hasRight = HrmUserVarify.checkUserRight("MobileSignInfo:Manage", user, departmentId); + } else { + hasRight = new KQReportBiz().hasReportRight(reportType,""+user.getUID()); + } + boolean kq_personal_reportsearch = KQSettingsBiz.showLeaveTypeSet("kq_personal_reportsearch"); + if(!hasRight && kq_personal_reportsearch) { // 开启开关,且没有权限的账号,最大查询只支持到本季 + String seasonFromDate = TimeUtil.getDateByOption("4","0"); + String seasonToDate = TimeUtil.getDateByOption("4","1"); + if(toDate.compareTo(seasonFromDate) < 0 || fromDate.compareTo(seasonToDate) > 0) { + dateMap.put("fromDate", "-1"); + dateMap.put("toDate", "-1"); + return dateMap; + } else if(fromDate.compareTo(seasonFromDate) < 0) { + fromDate = seasonFromDate; + if(toDate.compareTo(seasonToDate) > 0) { + toDate = seasonToDate; + } + } else if(fromDate.compareTo(seasonFromDate) >= 0) { + if(toDate.compareTo(seasonToDate) > 0) { + toDate = seasonToDate; + } + } + } + dateMap.put("fromDate", fromDate); + dateMap.put("toDate", toDate); + return dateMap; + } + + /** + * 是否有考勤报表相关权限 + * @param reportType 1:考勤汇总报表; 2:每日统计报表; 3:原始打卡记录; 4:员工假期余额 + * @param userId + * @return + */ + public boolean hasReportRight(String reportType, String userId){ + String sql = ""; + RecordSet rs = new RecordSet(); + sql = " select sharelevel,subcomid, deptid,userid,jobtitleid,foralluser from kq_reportshare where resourceid=? "; + if(reportType.length()>0 ){ + sql += " and (reportname =0 or reportname =" + reportType+")"; + } + rs.executeQuery(sql,userId); + if(rs.next()) { + return true; + } + return false; + } + + /** + * 将操作导出四大考勤报表的日志记录到数据库中,谁操作的导出,什么时间操作的导出,导出的条件都存储下来 + * @param params + * @param user + */ + public void insertKqReportExportLog(Map params, User user) { + RecordSet rs = new RecordSet(); + String exportParams = JSON.toJSONString(params); + String sql = "insert into kq_exportreport_log(operatorid,exportparams) values(?,?)"; + rs.executeUpdate(sql, user.getUID(), exportParams); + } + + /** + * 获取报表权限 + * @param reportType 报表类型 + * @param userId 用户id + * @param tableExt 别名 + * @return + */ + public String getReportRight(String reportType, String userId, String tableExt){ + String rightSql = ""; + String sql = ""; + RecordSet rs = new RecordSet(); + try{ + List userAllUserIds = new ArrayList<>(); + List userAllDeptIds = new ArrayList<>(); + List userAllSubCompanyIds = new ArrayList<>(); + List userAllJobtitleIds = new ArrayList<>(); + boolean forAllUser = false; + sql = " select sharelevel,subcomid, deptid,userid,jobtitleid,foralluser from kq_reportshare where resourceid=? "; + if(reportType.length()>0 ){ + sql += " and (reportname =0 or reportname =" + reportType+")"; + } + rs.executeQuery(sql,userId); + while(rs.next()){ + int sharelevel = rs.getInt("sharelevel"); + if(sharelevel==0){//分部 + if(Util.null2String(rs.getString("subcomid")).length()>0){ + userAllSubCompanyIds.add(rs.getString("subcomid")); + } + }else if(sharelevel==1){//部门 + if(Util.null2String(rs.getString("deptid")).length()>0) { + userAllDeptIds.add(rs.getString("deptid")); + } + }else if(sharelevel==2){//人员 + if(Util.null2String(rs.getString("userid")).length()>0) { + userAllUserIds.add(rs.getString("userid")); + } + }else if(sharelevel==3){//岗位 + if(Util.null2String(rs.getString("jobtitleid")).length()>0) { + userAllJobtitleIds.add(rs.getString("jobtitleid")); + } + }else if(sharelevel==4){//所有人 + forAllUser = true; + userAllUserIds.clear(); + userAllDeptIds.clear(); + userAllSubCompanyIds.clear(); + userAllJobtitleIds.clear(); + break; + } + } + + if(!forAllUser) { + for (int sharelevel = 0; sharelevel < 4; sharelevel++) { + if (sharelevel == 0) {//分部 + if (userAllSubCompanyIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".subcompanyid1 in(" + String.join(",", userAllSubCompanyIds) + ")"; + } + } else if (sharelevel == 1) {//部门 + if (userAllDeptIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".departmentid in(" + String.join(",", userAllDeptIds) + ")"; + } + } else if (sharelevel == 2) {//人员 + if (userAllUserIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".id in(" + String.join(",", userAllUserIds) + ")"; + } + } else if (sharelevel == 3) {//岗位 + if (userAllJobtitleIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".jobtitle in(" + String.join(",", userAllJobtitleIds) + ")"; + } + } + } + + //可以看自己和下属的考勤 + String selfSql = " ("+tableExt+".id = "+userId+" or "+tableExt+".managerstr like '%,"+userId+",%')"; + if(rightSql.length()>0){ + rightSql = " and ((" +rightSql+") or "+selfSql+" ) "; + }else{ + rightSql = " and "+selfSql; + } + + } + }catch (Exception e){ + writeLog(e); + } + return rightSql; + } + + public static String getUnitType(KQReportFieldComInfo kqReportFieldComInfo, User user){ + String unitTypeName = ""; + String unitType = Util.null2String(kqReportFieldComInfo.getUnittype()); + String parentid = Util.null2String( kqReportFieldComInfo.getParentid()); + String fieldName = Util.null2String(kqReportFieldComInfo.getFieldname()); + if(kqReportFieldComInfo.getIsLeaveType().equals("1")){ + if(fieldName.equals("businessLeave")){ + unitType = KQTravelRulesBiz.getMinimumUnit().equals("3")?"2":"1";//单位类型 + }else if(fieldName.equals("officialBusiness")){ + unitType = KQExitRulesBiz.getMinimumUnit().equals("3")?"2":"1";//单位类型 + }else if(parentid.equals("overtime") || parentid.equals("overtime_nonleave") || parentid.equals("overtime_4leave")){ + unitType = (KQOvertimeRulesBiz.getMinimumUnit()==3 || KQOvertimeRulesBiz.getMinimumUnit()==5 ||KQOvertimeRulesBiz.getMinimumUnit()==6)?"2":"1";//单位类型 + } + } + if(Util.null2String(unitType).length()>0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + return unitTypeName; + } + + /** + * 为每日统计报表做流程数据查询 + * @param params + * @param user + * @return + */ + public Map getDailyFlowData(Map params, User user){ + Map datas = new HashMap<>();; + try{ + datas.putAll(getDailyFlowLeaveData(params,user)); + datas.putAll(getDailyFlowEvectionOutData(params,user)); + datas.putAll(getDailyFlowOverTimeData(params,user)); + datas.putAll(getDailyFlowLeaveBackData(params,user)); + + datas.putAll(getSignDetailInfoData(params,user)); + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + public Map getFlowData(Map params, User user){ + Map datas = new HashMap<>();; + try{ + datas.putAll(getFlowLeaveData(params,user)); + datas.putAll(getFlowEvectionOutData(params,user)); + datas.putAll(getFlowOverTimeDataNew(params,user)); + datas.putAll(getFlowOtherData(params,user)); + datas.putAll(getFlowLeaveBackData(params,user)); + datas.putAll(getFlowProcessChangeData(params,user)); + + datas.putAll(getCardMap(params,user)); + datas.putAll(getOverTime(params,user)); + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取出差和公出数据 + * @param params + * @param user + * @return + */ + public Map getFlowEvectionOutData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String[] tables = new String[]{KqSplitFlowTypeEnum.EVECTION.getTablename(),//出差 + KqSplitFlowTypeEnum.OUT.getTablename()};//公出 + + String minimumUnit = "";//单位类型 + double proportion = 0.00;//换算关系 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + for(String table : tables){ + sql = " select resourceid, durationrule, sum(duration) as val from hrmresource a, "+table+" b "+ + " where a.id = b.resourceid and (b.status is null or b.status<>1) and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + double value = rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + String flowType = ""; + if(KqSplitFlowTypeEnum.EVECTION.getTablename().equals(table)){ + flowType = "businessLeave"; + minimumUnit = KQTravelRulesBiz.getMinimumUnit();//单位类型 + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//换算关系 + + }else if(KqSplitFlowTypeEnum.OUT.getTablename().equals(table)){ + flowType = "officialBusiness"; + minimumUnit = KQExitRulesBiz.getMinimumUnit();//单位类型 + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//换算关系 + } + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+flowType; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key, format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取每日的出差和公出数据 + * @param params + * @param user + * @return + */ + public Map getDailyFlowEvectionOutData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String[] tables = new String[]{KqSplitFlowTypeEnum.EVECTION.getTablename(),//出差 + KqSplitFlowTypeEnum.OUT.getTablename()};//公出 + + String minimumUnit = "";//单位类型 + double proportion = 0.00;//换算关系 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + for(String table : tables){ + sql = " select resourceid, durationrule, sum(duration) as val,belongdate from hrmresource a, "+table+" b "+ + " where a.id = b.resourceid and (b.status is null or b.status<>1) and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + double value = rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + String flowType = ""; + if(KqSplitFlowTypeEnum.EVECTION.getTablename().equals(table)){ + flowType = "businessLeave"; + minimumUnit = KQTravelRulesBiz.getMinimumUnit();//单位类型 + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//换算关系 + }else if(KqSplitFlowTypeEnum.OUT.getTablename().equals(table)){ + flowType = "officialBusiness"; + minimumUnit = KQExitRulesBiz.getMinimumUnit();//单位类型 + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//换算关系 + } + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|"+flowType; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key, format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取请假数据 + * @param params + * @param user + * @return + */ + public Map getFlowLeaveData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" b "+ + " where a.id = b.resourceid and (b.status is null or b.status != 1) and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype, kqLeaveRulesComInfo)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leaveType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key,format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + + //获取打卡数据用于判断外勤,补卡等信息=============================== + public Map getCardMap(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + //rs.writeLog("getCardMap="+ JSONObject.toJSONString(params)); + try{ + String show_card_source = Util.null2String(params.get("show_card_source")); + if(!"1".equals(show_card_source)){//下面的日历都是实时拼接,这里还是控制下数据库的交互次数,虽然用起来没啥用-.- + return datas; + } + + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + KQTransMethod kqTransMethod = new KQTransMethod(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + rs.writeLog("jsonObj="+ jsonObj.toJSONString()); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + //em7外勤、云桥外勤数据同步、钉钉外勤打卡、微信外勤转考勤(补卡先留一个口子,以防客户要) +// sqlWhere += " and (signfrom like 'card%' or signfrom='e9_mobile_out' or signfrom='EMSyn_out' or signfrom='DingTalk_out' or signfrom='Wechat_out') "; + + sql = " select a.id,b.signdate,b.id as signid,b.signfrom from hrmresource a, hrmschedulesign b "+ + " where a.id = b.userid and b.signdate >='"+fromDate+"' and b.signdate <='"+toDate+"' " +sqlWhere + + " order by a.id,b.signdate "; + rs.execute(sql); +// kqLog.info("card.sql="+sql); + while (rs.next()) { + String resourceid = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signid = Util.null2String(rs.getString("signid")); + String signfrom = Util.null2String(rs.getString("signfrom")); + String signFromShow = kqTransMethod.getSignFromShow(signfrom, ""+user.getLanguage()); + String key = resourceid+"|"+signdate; + + datas.put(signid,signFromShow); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + +//获取打卡数据用于判断外勤,补卡等信息=============================== + + /** + * 获取销假数据 + * @param params + * @param user + * @return + */ + public Map getFlowLeaveBackData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leavebackType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key,format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取考勤变更流程数据 + * @param params + * @param user + * @return + */ + public Map getFlowProcessChangeData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String minimumUnit = "";//单位类型 + double proportion = 0.00;//换算关系 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, durationrule, changetype,sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.PROCESSCHANGE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule,changetype "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + int changetype = Util.getIntValue(rs.getString("changetype")); + + String flowType = ""; + if(KqSplitFlowTypeEnum.EVECTION.getFlowtype() == changetype){ + flowType = "businessLeave_back"; + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//换算关系 + minimumUnit = KQTravelRulesBiz.getMinimumUnit(); + }else if(KqSplitFlowTypeEnum.OUT.getFlowtype() == changetype){ + flowType = "officialBusiness_back"; + minimumUnit = KQExitRulesBiz.getMinimumUnit(); + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//换算关系 + } + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+flowType; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key, format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取每日请假数据 + * @param params + * @param user + * @return + */ + public Map getDailyFlowLeaveData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|leaveType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key,format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + + public Map getSignDetailInfoData(Map params, User user){ + Map data = new HashMap<>(); + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 isneedcal = Util.null2String(params.get("isneedcal")); + if("".equals(isneedcal)){ + isneedcal = KQSettingsBiz.getKqformatAccurate()?"1":"0"; + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + //================================= +// Map data = new HashMap<>(); + Map signStatusInfo = null; + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + sql = " select kqdate,resourceid,day_type,serialid,serialnumber,workbegindate,workbegintime, " + + " workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" + + " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," + + " leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid,flowinfo,on_absenteeismmins,off_absenteeismmins \n" + + " from hrmresource a,kq_format_detail b \n" + + " where a.id = b.resourceid " +sqlWhere+ + " and b.kqdate >='" + fromDate + "' and b.kqdate<='"+toDate+"' \n" + + " order by b.serialnumber \n"; + rs.execute(sql); + while (rs.next()) { + String resourceid = Util.null2String(rs.getString("resourceid")); + String kqdate = Util.null2String(rs.getString("kqdate")); + String serialid = Util.null2String(rs.getString("serialid")); + String day_type = Util.null2s(rs.getString("day_type"),""); + int workMins = rs.getInt("workMins"); + boolean isNonWork = false; + if(day_type.length() > 0){ + if("holiday".equals(day_type) || "playday".equals(day_type)){ + isNonWork = true; + } + if(serialid.length() == 0){ + //弹性班制,会存在dayType是work但是没有班次的情况 + isNonWork = true; + } + }else{ + if(workMins<=0){ + isNonWork = true; + }else{ + if(serialid.length() > 0){ + String isRest = Util.null2s(kqShiftManagementComInfo.getIsRest(serialid),""); + if("1".equals(isRest)){ + isNonWork = true; + } + } + } + } + int serialnumber = rs.getInt("serialnumber")+1; + String workbegindate = Util.null2String(rs.getString("workbegindate")).trim(); + String workbegintime = Util.null2String(rs.getString("workbegintime")).trim(); + String workenddate = Util.null2String(rs.getString("workenddate")).trim(); + String workendtime = Util.null2String(rs.getString("workendtime")).trim(); + String signintime = Util.null2String(rs.getString("signintime")).trim(); + String signouttime = Util.null2String(rs.getString("signouttime")).trim(); + int attendanceMins = rs.getInt("attendanceMins"); + String beLateMins = Util.null2String(rs.getString("beLateMins")).trim(); + String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim(); + String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim(); + String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim(); + String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim(); + String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim(); + String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim(); + String signinid = Util.null2String(rs.getString("signinid")).trim(); + String signoutid = Util.null2String(rs.getString("signoutid")).trim(); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = Util.null2String(rs.getString("leaveInfo")); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + String flowinfo = Util.null2String(rs.getString("flowinfo")); + String on_absenteeismmins = Util.null2String(rs.getString("on_absenteeismmins")); + String off_absenteeismmins = Util.null2String(rs.getString("off_absenteeismmins")); + + String tmpkey = resourceid+"|"+kqdate+"|"; + + + if(!isNonWork){ + if (workbegintime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("resourceId",resourceid); + signStatusInfo.put("kqdate",kqdate); + signStatusInfo.put("workdate",workbegindate); + signStatusInfo.put("worktime",workbegintime); + signStatusInfo.put("beLateMins",beLateMins); + signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins); + signStatusInfo.put("graveBeLateMins",graveBeLateMins); + signStatusInfo.put("absenteeismMins",absenteeismMins); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + signStatusInfo.put("isneedcal",isneedcal); + signStatusInfo.put("flowinfo",flowinfo); + signStatusInfo.put("on_absenteeismmins",on_absenteeismmins); + signStatusInfo.put("off_absenteeismmins",off_absenteeismmins); + + signStatusInfo.put("workbegintime",workbegintime); + signStatusInfo.put("workendtime",workendtime); + + data.put(tmpkey+"signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime); + data.put(tmpkey+"signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + } + + if (workendtime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("resourceId",resourceid); + signStatusInfo.put("kqdate",kqdate); + signStatusInfo.put("workdate",workenddate); + signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime)); + signStatusInfo.put("leaveEarlyMins",leaveEarlyMins); + signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins); + signStatusInfo.put("forgotCheckMins",forgotCheckMins); + signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins); + signStatusInfo.put("absenteeismMins",absenteeismMins); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + signStatusInfo.put("isneedcal",isneedcal); + signStatusInfo.put("flowinfo",flowinfo); + signStatusInfo.put("on_absenteeismmins",on_absenteeismmins); + signStatusInfo.put("off_absenteeismmins",off_absenteeismmins); + + signStatusInfo.put("workbegintime",workbegintime); + signStatusInfo.put("workendtime",workendtime); + + data.put(tmpkey+"signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put(tmpkey+"signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + }else{ + if(workMins>0){ + //弹性工时打卡时间取自签到签退数据 + } + signStatusInfo = new HashMap(); + signStatusInfo.put("resourceId",resourceid); + signStatusInfo.put("kqdate",kqdate); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + signStatusInfo.put("isneedcal",isneedcal); + signStatusInfo.put("flowinfo",flowinfo); + signStatusInfo.put("on_absenteeismmins",on_absenteeismmins); + signStatusInfo.put("off_absenteeismmins",off_absenteeismmins); + + signStatusInfo.put("workbegintime",workbegintime); + signStatusInfo.put("workendtime",workendtime); + + if(signinid.length() > 0){ + data.put(tmpkey+"signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime); + data.put(tmpkey+"signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + if(signoutid.length() > 0){ + data.put(tmpkey+"signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put(tmpkey+"signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + }else if(signoutid.length() > 0){ + data.put(tmpkey+"signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put(tmpkey+"signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + }else{ + data.put(tmpkey+"signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + data.put(tmpkey+"signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + } + } + }catch (Exception e){ + writeLog(e); + } + return data; + } + + /** + * 获取每日销假数据 + * @param params + * @param user + * @return + */ + public Map getDailyFlowLeaveBackData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|leavebackType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key,format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取实际加班数据,包括流程,打卡生成的 + * @return + */ + public Map getFlowOverTimeDataNew(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + + String valueField = ""; + + sql = " select resourceid,changeType, sum(cast(duration_min as decimal(18,4))) as val,paidLeaveEnable "+ + " from hrmresource a, kq_flow_overtime b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " group by resourceid,changeType,paidLeaveEnable "; + rs.execute(sql); + kqLog.info("getFlowOverTimeDataNew:sql:"+sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String paidLeaveEnable = rs.getString("paidLeaveEnable"); + int changeType =rs.getInt("changeType");//1-节假日、2-工作日、3-休息日 + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0)+"")); + }else{//按天计算 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0*hoursToDay)+"")); + } + String flowType = ""; + if(changeType==1){ + flowType = "holidayOvertime"; + }else if(changeType==2){ + flowType = "workingDayOvertime"; + }else if(changeType==3){ + flowType = "restDayOvertime"; + } + if("1".equalsIgnoreCase(paidLeaveEnable)){ + //1表示关联调休 + flowType += "_4leave"; + }else{ + //0表示不关联调休 + flowType += "_nonleave"; + } + String key = resourceid+"|"+flowType; + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + if(datas.containsKey(key)){ + double tmpVal = Util.getDoubleValue(Util.null2String(datas.get(key)),0.0); + tmpVal += value; + datas.put(key,format(tmpVal)); + }else{ + datas.put(key,format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + + /** + * 获取加班数据 + * @return + */ + public Map getFlowOverTimeData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and b.subcompanyid in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and b.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + + String valueField = ""; + if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算 + valueField = "sum( case when durationrule='3' then duration else duration*"+hoursToDay+" end) as val"; + }else{//按天计算 + valueField = "sum( case when durationrule='3' then duration/"+hoursToDay+" else duration end) as val"; + } + + sql = " select resourceid,changeType, " +valueField+ + " from hrmresource a, "+KqSplitFlowTypeEnum.OVERTIME.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " group by resourceid,changeType,durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + int changeType =rs.getInt("changeType");//1-节假日、2-工作日、3-休息日 + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + String flowType = ""; + if(changeType==1){ + flowType = "holidayOvertime"; + }else if(changeType==2){ + flowType = "workingDayOvertime"; + }else if(changeType==3){ + flowType = "restDayOvertime"; + } + String key = resourceid+"|"+flowType; + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + if(datas.containsKey(key)){ + double tmpVal = Util.getDoubleValue(Util.null2String(datas.get(key)),0.0); + tmpVal += value; + datas.put(key,format(tmpVal)); + }else{ + datas.put(key,format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 获取每日加班数据 + * @return + */ + public Map getDailyFlowOverTimeData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + + String valueField = ""; + if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算 + valueField = "sum( case when durationrule='3' then duration else duration*"+hoursToDay+" end) as val"; + }else{//按天计算 + valueField = "sum( case when durationrule='3' then duration/"+hoursToDay+" else duration end) as val"; + } + + sql = " select resourceid,changeType,belongdate,paidLeaveEnable, sum(cast(duration_min as decimal(18,4))) as val "+ + " from hrmresource a, kq_flow_overtime b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " group by resourceid,changeType,paidLeaveEnable,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String paidLeaveEnable = rs.getString("paidLeaveEnable"); + int changeType =rs.getInt("changeType");//1-节假日、2-工作日、3-休息日 + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0)+"")); + }else{//按天计算 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0*hoursToDay)+"")); + } + String flowType = ""; + if(changeType==1){ + flowType = "holidayOvertime"; + }else if(changeType==2){ + flowType = "workingDayOvertime"; + }else if(changeType==3){ + flowType = "restDayOvertime"; + } + if("1".equalsIgnoreCase(paidLeaveEnable)){ + //1表示关联调休 + flowType += "_4leave"; + }else{ + //0表示不关联调休 + flowType += "_nonleave"; + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(resourceid+"|"+belongdate+"|"+flowType,format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 异常冲抵 + * @return + */ + public Map getFlowOtherData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String minimumUnit = "";//单位类型 + double proportion = 0.00;//换算关系 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.OTHER.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//按小时 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//按天 + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leaveDeduction"; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 默认是不四舍五入的 0.125这样的就会直接变成0.12了 + df.setMaximumFractionDigits(5); + datas.put(key, format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + *日报表数据 + * @param resourceId + * @param fromDate + * @param toDate + * @return + */ + public Map getDetialDatas(String resourceId,String fromDate, String toDate, User user){ + return getDetialDatas(resourceId,fromDate,toDate,user,new HashMap(),false,0,"0"); + } + + /** + * 考勤汇总报表上下午显示开关不开启 + * @param resourceId + * @param fromDate + * @param toDate + * @param user + * @param flowData + * @param isWrap + * @param uintType + * @param show_card_source + * @return + */ + public Map getDetialDatasHalfNotOpen(String resourceId,String fromDate, String toDate, User user, + Map flowData,boolean isWrap,int uintType,String show_card_source){ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + Map datas = new HashMap<>(); + Map data = null; + Map tmpdatas = new HashMap<>(); + Map tmpdatass = new HashMap<>(); + Map tmpdata = null; + Map tmpmap = null; + + Map tmpstatusdata = new HashMap<>(); + Map tmpstatus = null; + RecordSet rs = new RecordSet(); + String sql = ""; + + //add + String unit = "小时"; + if(uintType==1 || uintType== 2 || uintType== 4){//按天计算 + unit = "天"; + } + //kqLog.info("detail.flowdata="+JSONObject.toJSONString(flowData)); + + try { + sql = " select resourceid,day_type,serialid, kqdate, workMins,attendanceMins,signindate,signintime,signoutdate,signouttime,signinid,signoutid, belatemins, graveBeLateMins, leaveearlymins, graveLeaveEarlyMins, absenteeismmins, forgotcheckMins, forgotBeginWorkCheckMins, "+ + " leaveMins,leaveInfo,evectionMins,outMins " + + " from kq_format_detail " + + " where resourceid = ? and kqdate>=? and kqdate<=? "+ + " order by resourceid, kqdate, serialnumber "; + rs.executeQuery(sql,resourceId, fromDate,toDate); + while (rs.next()) { + String key = rs.getString("resourceid") + "|" + rs.getString("kqdate"); + int workMins = rs.getInt("workMins"); + + boolean isNonWork = false; + String serialid = Util.null2s(rs.getString("serialid"),""); + String dayType = Util.null2s(rs.getString("day_type"),""); + if(dayType.length() > 0){ + if("holiday".equals(dayType) || "playday".equals(dayType)){ + isNonWork = true; + } + }else{ + if(workMins<=0){ + isNonWork = true; + }else{ + if(serialid.length() > 0){ + String isRest = Util.null2s(kqShiftManagementComInfo.getIsRest(serialid),""); + if("1".equals(isRest)){ + isNonWork = true; + } + } + } + } + String attendanceMins = rs.getString("attendanceMins"); +// String chuqin = "出勤:"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(attendanceMins) / 60.0)))+"小时"; + String overtimekey = key+"|overtime"; + String overtime = Util.null2String(flowData.get(overtimekey)); + boolean hasovertime = Util.getDoubleValue(overtime)>0; + overtime = hasovertime?(SystemEnv.getHtmlLabelName(6151, user.getLanguage())+":"+overtime+unit):"";//显示加班 + + String signinid = ""; + String signoutid = ""; + String signintime = ""; + String signouttime = ""; + if("1".equals(show_card_source)){ + String nosign = SystemEnv.getHtmlLabelName(25994, user.getLanguage());//未打卡 + signinid = Util.null2String(rs.getString("signinid")).trim(); + signintime = Util.null2String(rs.getString("signintime")).trim(); + String tmpin = SystemEnv.getHtmlLabelName(21974, user.getLanguage())+":"; + if(signinid.length()>0){ + String signinfrom = Util.null2String(flowData.get(signinid)); + signintime = tmpin+signintime+" "+signinfrom; + }else{ + signintime = tmpin+nosign; + } +// signintime = isWrap?"\r\n"+signintime:"
"+signintime; + + signoutid = Util.null2String(rs.getString("signoutid")).trim(); + signouttime = Util.null2String(rs.getString("signouttime")).trim(); + String tmpout = SystemEnv.getHtmlLabelName(21975, user.getLanguage())+":"; + if(signoutid.length()>0){ + String signoutfrom = Util.null2String(flowData.get(signoutid)); + signouttime = tmpout+signouttime+" "+signoutfrom; + }else{ + signouttime = tmpout+nosign; + } + signouttime = isWrap?"\r\n"+signouttime:"
"+signouttime; + } + + int beLateMins = rs.getInt("beLateMins"); + int leaveEarlyMins = rs.getInt("leaveEarlyMins"); + int graveBeLateMins = rs.getInt("graveBeLateMins"); + int absenteeismMins = rs.getInt("absenteeismMins"); + int graveLeaveEarlyMins = rs.getInt("graveLeaveEarlyMins"); + int forgotCheckMins = rs.getInt("forgotCheckMins"); + int forgotBeginWorkCheckMins = rs.getInt("forgotBeginWorkCheckMins"); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = rs.getString("leaveInfo"); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + String text = ""; + String tmptext =""; + String flag ="true"; + if(datas.get(key)==null){ + data = new HashMap<>(); + }else{ + data = (Map)datas.get(key); + tmptext = Util.null2String(data.get("text")); + } + tmpdata = new HashMap<>(); + if(tmpdatas.get(key)!=null){ + tmpmap = (Map)tmpdatas.get(key); + flag = Util.null2String(tmpmap.get("text")); + } + + String yichang =""; + if(tmpstatusdata.get(key)!=null){ + yichang = Util.null2String(tmpstatusdata.get(key)); + } + String sign =""; + String signkey = key+"|text"; + if(tmpstatusdata.get(signkey)!=null){ + sign = Util.null2String(tmpstatusdata.get(signkey)); + } + + if (isNonWork) { + if(text.length()>0) text +=" "; + if(sign.indexOf(SystemEnv.getHtmlLabelName(26593, user.getLanguage()))==-1){ + if(text.length()>0) { + text+= isWrap?"\r\n":"
"; + } + text += SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + } + //休息日处理 + if(signinid.length()>0){ + text += (isWrap?"\r\n":"
")+signintime; + } + if(signoutid.length()>0){ + text += signouttime; + } + sign += text; + } else { + //处理打卡数据================== + if(text.length()>0) text+= isWrap?"\r\n":"
"; + text += signintime; + text += signouttime; + if(sign.length()>0) sign+= isWrap?"\r\n":"
"; + sign += text; + //处理打卡数据================== + + if (absenteeismMins > 0) {//旷工 + if(text.length()>0) text+=" "; + text += SystemEnv.getHtmlLabelName(20085, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+absenteeismMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20085, user.getLanguage()))==-1){ + if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + }else { + if (beLateMins > 0) {//迟到 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20081, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+beLateMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20081, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20081, user.getLanguage()); + } + } + if (graveBeLateMins > 0) {//严重迟到 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(500546, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+graveBeLateMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(500546, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(500546, user.getLanguage()); + } + } + if (leaveEarlyMins > 0) {//早退 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20082, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+leaveEarlyMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20082, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20082, user.getLanguage()); + } + } + if (graveLeaveEarlyMins > 0) {//严重早退 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(500547, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+graveLeaveEarlyMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(500547, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(500547, user.getLanguage()); + } + } + if (forgotCheckMins > 0) {//漏签 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20086, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + if (forgotBeginWorkCheckMins > 0) {//漏签 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20086, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + } + if (leaveMins > 0) {//请假 + Map jsonObject = null; + if(leaveInfo.length()>0){ + jsonObject = JSON.parseObject(leaveInfo); + for (Entry entry : jsonObject.entrySet()) { + String newLeaveType = entry.getKey(); + String tmpLeaveMins = Util.null2String(entry.getValue()); + if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ + if (text.length() > 0) text += " "; + //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + text += Util.formatMultiLang( kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+leaveMins) / 60.0)))+"小时"; + if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; + yichang += Util.formatMultiLang( kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); + } + } + }else{ + if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } + } + } + if (evectionMins > 0) {//出差 + if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+evectionMins) / 60.0)))+"小时"; + if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } + } + if (outMins > 0) {//公出 + if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+outMins) / 60.0)))+"小时"; + if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + } + + if(text.length()==0) { + text = "√"; + }else{ + flag = "false";//有其他的异常状态,则表示为false,不需要处理直接全部显示即可 + } + text += overtime; + + + //需要处理下打卡时间和异常状态显示的顺序--start + tmpstatusdata.put(key, yichang); + tmpstatusdata.put(signkey, sign); + boolean hasyichang = tmpstatusdata.get(key).length()>0; + if(tmptext.length()>0){ +// text = tmpstatusdata.get(signkey)+(isWrap?"\r\n":"
")+tmpstatusdata.get(key)+(isWrap?"\r\n":"
"+overtime); + text = tmpstatusdata.get(signkey); + if(hasyichang){ + if(text.length()>0){ + text += (isWrap?"\r\n":"
")+tmpstatusdata.get(key); + }else{ + text += tmpstatusdata.get(key); + } + } + if(hasovertime){ + text += (isWrap?"\r\n":"
")+overtime; + } + }else{ + text = tmpstatusdata.get(signkey); + if(hasyichang){ + if(text.length()>0){ + text += (isWrap?"\r\n":"
")+tmpstatusdata.get(key); + }else{ + text += tmpstatusdata.get(key); + } + } + if(hasovertime){ + text += (isWrap?"\r\n":"
")+overtime; + } + } + //需要处理下打卡时间和异常状态显示的顺序--end + tmpdatass.put(key, (isWrap?"\r\n":"
")+overtime); +// text = tmptext.length()>0?tmptext+" "+text:text;//显示所有的状态 + data.put("text", text); + datas.put(key, data); + + //add + tmpdata.put("text", flag); + tmpdatas.put(key, tmpdata); + //end + } + //全部搞一遍 + if(tmpdatas != null){ +// writeLog(n+">>>tmpdatas="+JSONObject.toJSONString(tmpdatas)); + Map data1 = null; + for(Entry entry : tmpdatas.entrySet()){ + String mapKey = Util.null2String(entry.getKey()); + Map mapValue = (Map)entry.getValue(); + String flag = Util.null2String(mapValue.get("text")); + if("true".equals(flag)){//需要加工的数据 + String overtime = String.valueOf(tmpdatass.get(mapKey)); + data1 = new HashMap<>(); + data1.put("text", "√"+overtime); + datas.put(mapKey, data1); + } + } +// writeLog("datas="+JSONObject.toJSONString(datas)); + } + }catch (Exception e){ + writeLog(e); + } + // 最后针对数据再处理一遍,不然出现2023-01-02: "休息" 形式的错误,导致页面记载报错,应该是2023-01-01: {text: "休息"}格式 + boolean isEnd = false; + for(String currentDate = fromDate; !isEnd;) { + if (currentDate.equals(toDate)) isEnd = true; + String dailyValue = Util.null2String(datas.get(currentDate)); + if(!"".equals(dailyValue) && !dailyValue.contains("text")) { + Map innerMap2 = new HashMap<>(); + innerMap2.put("text", dailyValue); + datas.put(currentDate, innerMap2); + } + currentDate = DateUtil.addDate(currentDate, 1); + } + return datas; + } + + /** + * 考勤汇总报表上下午显示开关开启 + * @param resourceId + * @param fromDate + * @param toDate + * @param user + * @param flowData + * @param isWrap + * @param uintType + * @param show_card_source + * @return + */ + public Map getDetialDatasHalfOpen(String resourceId,String fromDate, String toDate, User user, + Map flowData,boolean isWrap,int uintType,String show_card_source){ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + int split_time_index = kqTimesArrayComInfo.getArrayindexByTimes("13:00"); + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + Map datas = new HashMap<>(); + Map data = null; + Map tmpdatas = new HashMap<>(); + Map tmpdatass = new HashMap<>(); + Map tmpdata = null; + Map tmpmap = null; + + Map tmpstatusdata = new HashMap<>(); + Map tmpstatus = null; + RecordSet rs = new RecordSet(); + String sql = ""; + + //add + String unit = "小时"; + if(uintType==1 || uintType== 2 || uintType== 4){//按天计算 + unit = "天"; + } + //kqLog.info("detail.flowdata="+JSONObject.toJSONString(flowData)); + + try { + sql = " select resourceid,day_type,serialid, kqdate, workMins, workbegintime, workendtime,attendanceMins,signindate,signintime,signoutdate,signouttime,signinid,signoutid, belatemins, graveBeLateMins, leaveearlymins, graveLeaveEarlyMins, absenteeismmins, forgotcheckMins, forgotBeginWorkCheckMins, "+ + " leaveMins,leaveInfo,evectionMins,outMins,flowinfo,on_absenteeismmins,off_absenteeismmins " + + " from kq_format_detail " + + " where resourceid = ? and kqdate>=? and kqdate<=? "+ + " order by resourceid, kqdate, serialnumber "; + rs.executeQuery(sql,resourceId, fromDate,toDate); + while (rs.next()) { + String kqDate = rs.getString("kqdate"); + String key = rs.getString("resourceid") + "|" + kqDate; + int workMins = rs.getInt("workMins"); + + String signinid = ""; + String signoutid = ""; + String signintime = ""; + String signouttime = ""; + if("1".equals(show_card_source)){ + String nosign = SystemEnv.getHtmlLabelName(25994, user.getLanguage());//未打卡 + signinid = Util.null2String(rs.getString("signinid")).trim(); + signintime = Util.null2String(rs.getString("signintime")).trim(); + String tmpin = SystemEnv.getHtmlLabelName(21974, user.getLanguage())+":"; + if(signinid.length()>0){ + String signinfrom = Util.null2String(flowData.get(signinid)); + signintime = tmpin+signintime+" "+signinfrom; + }else{ + signintime = tmpin+nosign; + } + signintime = isWrap?"\r\n"+signintime:"
"+signintime; +// signintime = isWrap?"\r\n"+signintime:"
"+signintime; + + signoutid = Util.null2String(rs.getString("signoutid")).trim(); + signouttime = Util.null2String(rs.getString("signouttime")).trim(); + String tmpout = SystemEnv.getHtmlLabelName(21975, user.getLanguage())+":"; + if(signoutid.length()>0){ + String signoutfrom = Util.null2String(flowData.get(signoutid)); + signouttime = tmpout+signouttime+" "+signoutfrom; + }else{ + signouttime = tmpout+nosign; + } + signouttime = isWrap?"\r\n"+signouttime:"
"+signouttime; + } + + String overtimekey = key+"|overtime"; + String overtime = Util.null2String(flowData.get(overtimekey)); + boolean hasovertime = Util.getDoubleValue(overtime)>0; + overtime = hasovertime? ((isWrap?"\r\n":"
")+(SystemEnv.getHtmlLabelName(6151, user.getLanguage())+":"+overtime+unit)):"";//显示加班 + + + String flowinfo = Util.null2String(rs.getString("flowinfo")); + ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceId, kqDate, false); + boolean isNonWork = false; + String serialid = Util.null2s(rs.getString("serialid"),""); + String dayType = Util.null2s(rs.getString("day_type"),""); + if(dayType.length() > 0){ + if("holiday".equals(dayType) || "playday".equals(dayType)){ + isNonWork = true; + } + }else{ + if(workMins<=0){ + isNonWork = true; + }else{ + if(serialid.length() > 0){ + String isRest = Util.null2s(kqShiftManagementComInfo.getIsRest(serialid),""); + if("1".equals(isRest)){ + isNonWork = true; + } + } + } + } + if(shiftInfoBean == null || isNonWork) { + String textAM = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + String textPM = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + if(datas.get(key)==null){ + data = new HashMap<>(); + }else{ + data = (Map)datas.get(key); + } + if(shiftInfoBean != null) { + List halfWorkIndex = shiftInfoBean.getHalfWorkIndex(); + if (halfWorkIndex != null && !halfWorkIndex.isEmpty()) { + int[] halfWorkIndexs = halfWorkIndex.get(0); + split_time_index = halfWorkIndexs[1];//半天的时间 + } + } + if(flowinfo.length() > 0) { + Map jsonObject = JSON.parseObject(flowinfo); + for (Entry entry : jsonObject.entrySet()) { + String jsonKey = entry.getKey(); + String jsonValue = ""; + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } else if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.EVECTION.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } else if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.OUT.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONArray.parseArray(Util.null2String(entry.getValue())); + if (jsonArray != null && !jsonArray.isEmpty()) { + //客户不存在多个重复流程的情况,只是显示第一个就行 + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject1 = (JSONObject) jsonArray.getJSONObject(i); + if (jsonObject1 != null && !jsonObject1.isEmpty()) { + String newLeaveType = Util.null2s(Util.null2String(jsonObject1.get("newLeaveType")), ""); + String begintime = Util.null2s(Util.null2String(jsonObject1.get("begintime")), ""); + String endtime = Util.null2s(Util.null2String(jsonObject1.get("endtime")), ""); + int beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endIdx = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (newLeaveType.length() > 0) { + jsonValue = kqLeaveRulesComInfo.getLeaveName(newLeaveType); + } + } + if (beginIdx <= split_time_index && endIdx <= split_time_index) { + //上午 + textAM = jsonValue; + } else if (beginIdx >= split_time_index && endIdx >= split_time_index) { + //下午 + textPM = jsonValue; + } else { + //全天 + textAM = jsonValue; + textPM = jsonValue; + } + } + } + } + } + } + if(!"".equals(signintime)) { + textAM+=signintime; + } + if(!"".equals(signouttime)) { + textPM+=signouttime; + } + if(!"".equals(overtime)) { + textPM+=overtime; + } + data.put("text", textAM+""+textPM); + data.put("textAM", textAM); + data.put("textPM", textPM); + datas.put(key, data); + continue; + } + String attendanceMins = rs.getString("attendanceMins"); +// String chuqin = "出勤:"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(attendanceMins) / 60.0)))+"小时"; + + + int beLateMins = rs.getInt("beLateMins"); + int leaveEarlyMins = rs.getInt("leaveEarlyMins"); + int graveBeLateMins = rs.getInt("graveBeLateMins"); + int absenteeismMins = rs.getInt("absenteeismMins"); + int graveLeaveEarlyMins = rs.getInt("graveLeaveEarlyMins"); + int forgotCheckMins = rs.getInt("forgotCheckMins"); + int forgotBeginWorkCheckMins = rs.getInt("forgotBeginWorkCheckMins"); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = rs.getString("leaveInfo"); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + + String workbeigintime = rs.getString("workbegintime"); + String workendtime = rs.getString("workendtime"); + + String halfPoint = shiftInfoBean.getHalfcalpoint(); //1440 + List halfWorkIndex = shiftInfoBean.getHalfWorkIndex(); + if (halfWorkIndex != null && !halfWorkIndex.isEmpty()) { + int[] halfWorkIndexs = halfWorkIndex.get(0); + split_time_index = halfWorkIndexs[1];//半天的时间 + } +// int halfPointIndex = split_time_index; //kqTimesArrayComInfo.getArrayindexByTimes(halfPoint); + + int on_absenteeismmins = Util.getIntValue(Util.null2String(rs.getString("on_absenteeismmins"))); + int off_absenteeismmins = Util.getIntValue(Util.null2String(rs.getString("off_absenteeismmins"))); + + String textAM = ""; + String textPM = ""; + if (workMins<=0) { + if("".equals(flowinfo)) { + textAM = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + textPM = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + } else { + Map jsonObject = JSON.parseObject(flowinfo); + for (Entry entry : jsonObject.entrySet()) { + String jsonKey = entry.getKey(); + String jsonValue = ""; + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } else if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.EVECTION.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } else if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.OUT.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONArray.parseArray(Util.null2String(entry.getValue())); + if (jsonArray != null && !jsonArray.isEmpty()) { + //客户不存在多个重复流程的情况,只是显示第一个就行 + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject1 = (JSONObject) jsonArray.getJSONObject(i); + if (jsonObject1 != null && !jsonObject1.isEmpty()) { + String newLeaveType = Util.null2s(Util.null2String(jsonObject1.get("newLeaveType")), ""); + String begintime = Util.null2s(Util.null2String(jsonObject1.get("begintime")), ""); + String endtime = Util.null2s(Util.null2String(jsonObject1.get("endtime")), ""); + int beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endIdx = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (newLeaveType.length() > 0) { + jsonValue = kqLeaveRulesComInfo.getLeaveName(newLeaveType); + } + } + if (beginIdx <= split_time_index && endIdx <= split_time_index) { + //上午 + textAM = jsonValue; + } else if (beginIdx >= split_time_index && endIdx >= split_time_index) { + //下午 + textPM = jsonValue; + } else { + //全天 + textAM = jsonValue; + textPM = jsonValue; + } + } + } + } + } + } + }else{ + textAM = "√"; + textPM = "√"; + if(on_absenteeismmins > 0) { + textAM = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + if(beLateMins > 0) { + //迟到 + textAM = SystemEnv.getHtmlLabelName(20081, user.getLanguage()); + } + if(graveBeLateMins > 0) { + //严重迟到 + textAM = SystemEnv.getHtmlLabelName(500546, user.getLanguage()); + } + if(forgotBeginWorkCheckMins > 0) { + // 漏签 + textAM = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + if(off_absenteeismmins > 0) { + // 下午旷工 + textPM = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + if (leaveEarlyMins > 0) { + // 早退 + textPM = SystemEnv.getHtmlLabelName(20082, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) { + // 严重早退 + textPM = SystemEnv.getHtmlLabelName(500547, user.getLanguage()); + } + if(forgotCheckMins > 0) { + // 下午漏签 + textPM = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + + if(workMins > 0 && flowinfo.length() > 0){ + Map jsonObject = JSON.parseObject(flowinfo); + for (Entry entry : jsonObject.entrySet()) { + + String jsonKey = entry.getKey(); + String jsonValue = ""; + if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())){ + jsonValue = SystemEnv.getHtmlLabelName(670, user.getLanguage()); + }else if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.EVECTION.getFlowType())){ + jsonValue = SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + }else if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.OUT.getFlowType())){ + jsonValue = SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONArray.parseArray(Util.null2String(entry.getValue())); + if(jsonArray != null && !jsonArray.isEmpty()){ + //客户不存在多个重复流程的情况,只是显示第一个就行 + for(int i = 0 ; i < jsonArray.size() ; i++){ + JSONObject jsonObject1 = (JSONObject) jsonArray.getJSONObject(i); + if(jsonObject1 != null && !jsonObject1.isEmpty()) { + String newLeaveType = Util.null2s(Util.null2String(jsonObject1.get("newLeaveType")), ""); + String begintime = Util.null2s(Util.null2String(jsonObject1.get("begintime")), ""); + String endtime = Util.null2s(Util.null2String(jsonObject1.get("endtime")), ""); + int beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endIdx = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (newLeaveType.length() > 0) { + jsonValue = kqLeaveRulesComInfo.getLeaveName(newLeaveType); + } + } + if (begintime.equals(workbeigintime) && endIdx == split_time_index) { + textAM = jsonValue; + } else if (begintime.equals(workbeigintime) && endtime.equals(workendtime)) { + textAM = jsonValue; + textPM = jsonValue; + } else if (endIdx == split_time_index && endtime.equals(workendtime)) { + textPM = jsonValue; + } else { + if (beginIdx <= split_time_index && endIdx <= split_time_index) { + //上午 + textAM = jsonValue + (("".equals(textAM) || "√".equals(textAM)) ? "" : ", " + textAM); + } else if (beginIdx >= split_time_index && endIdx >= split_time_index) { + //下午 + textPM = jsonValue + (("".equals(textPM) || "√".equals(textPM)) ? "" : ", " + textPM); + } else { + //全天 + textAM = jsonValue + (("".equals(textAM) || "√".equals(textAM)) ? "" : ", " + textAM); + textPM = jsonValue + (("".equals(textPM) || "√".equals(textPM)) ? "" : ", " + textPM); + } + } + } + } + } + } + } + String text = ""; + String tmptext =""; + String flag ="true"; + if(datas.get(key)==null){ + data = new HashMap<>(); + }else{ + data = (Map)datas.get(key); + tmptext = Util.null2String(data.get("text")); + } + tmpdata = new HashMap<>(); + if(tmpdatas.get(key)!=null){ + tmpmap = (Map)tmpdatas.get(key); + flag = Util.null2String(tmpmap.get("text")); + } + + String yichang =""; + if(tmpstatusdata.get(key)!=null){ + yichang = Util.null2String(tmpstatusdata.get(key)); + } + String sign =""; + String signkey = key+"|text"; + if(tmpstatusdata.get(signkey)!=null){ + sign = Util.null2String(tmpstatusdata.get(signkey)); + } + + if (isNonWork) { + if(text.length()>0) text +=" "; + if(sign.indexOf(SystemEnv.getHtmlLabelName(26593, user.getLanguage()))==-1){ + if(text.length()>0) { + text+= isWrap?"\r\n":"
"; + } + text += SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + } + //休息日处理 + if(signinid.length()>0){ + text += (isWrap?"\r\n":"
")+signintime; + } + if(signoutid.length()>0){ + text += signouttime; + } + sign += text; + } else { + //处理打卡数据================== + if(text.length()>0) text+= isWrap?"\r\n":"
"; + text += signintime; + text += signouttime; + if(sign.length()>0) sign+= isWrap?"\r\n":"
"; + sign += text; + //处理打卡数据================== + + if (absenteeismMins > 0) {//旷工 + if(text.length()>0) text+=" "; + text += SystemEnv.getHtmlLabelName(20085, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+absenteeismMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20085, user.getLanguage()))==-1){ + if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + }else { + if (beLateMins > 0) {//迟到 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20081, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+beLateMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20081, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20081, user.getLanguage()); + } + } + if (graveBeLateMins > 0) {//严重迟到 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(500546, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+graveBeLateMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(500546, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(500546, user.getLanguage()); + } + } + if (leaveEarlyMins > 0) {//早退 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20082, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+leaveEarlyMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20082, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20082, user.getLanguage()); + } + } + if (graveLeaveEarlyMins > 0) {//严重早退 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(500547, user.getLanguage()); +// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+graveLeaveEarlyMins) / 60.0)))+"小时"; + if(yichang.indexOf(SystemEnv.getHtmlLabelName(500547, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(500547, user.getLanguage()); + } + } + if (forgotCheckMins > 0) {//漏签 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20086, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + if (forgotBeginWorkCheckMins > 0) {//漏签 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + if(yichang.indexOf(SystemEnv.getHtmlLabelName(20086, user.getLanguage()))==-1) { + if (yichang.length() > 0) yichang += isWrap?"\r\n":"
"; + yichang += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + } +// if (leaveMins > 0) {//请假 +// Map jsonObject = null; +// if(leaveInfo.length()>0){ +// jsonObject = JSON.parseObject(leaveInfo); +// for (Entry entry : jsonObject.entrySet()) { +// String newLeaveType = entry.getKey(); +// String tmpLeaveMins = Util.null2String(entry.getValue()); +// if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ +// if (text.length() > 0) text += " "; +// //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); +// text += Util.formatMultiLang( kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); +//// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+leaveMins) / 60.0)))+"小时"; +// if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; +// yichang += Util.formatMultiLang( kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); +// } +// } +// }else{ +// if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { +// if (text.length() > 0) text += " "; +// text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); +// } +// } +// } +// if (evectionMins > 0) {//出差 +// if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { +// if (text.length() > 0) text += " "; +// text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); +//// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+evectionMins) / 60.0)))+"小时"; +// if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; +// yichang += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); +// } +// } +// if (outMins > 0) {//公出 +// if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { +// if (text.length() > 0) text += " "; +// text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); +//// text += ":"+KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(""+outMins) / 60.0)))+"小时"; +// if(yichang.length()>0) yichang+= isWrap?"\r\n":"
"; +// yichang += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); +// } +// } + + if(text.length()==0) { + text = "√"; + }else{ + flag = "false";//有其他的异常状态,则表示为false,不需要处理直接全部显示即可 + } + text += overtime; + + + //需要处理下打卡时间和异常状态显示的顺序--start + tmpstatusdata.put(key, yichang); + tmpstatusdata.put(signkey, sign); + boolean hasyichang = tmpstatusdata.get(key).length()>0; + if(tmptext.length()>0){ +// text = tmpstatusdata.get(signkey)+(isWrap?"\r\n":"
")+tmpstatusdata.get(key)+(isWrap?"\r\n":"
"+overtime); + text = tmpstatusdata.get(signkey); + if(hasyichang){ + if(text.length()>0){ + text += (isWrap?"\r\n":"
")+tmpstatusdata.get(key); + }else{ + text += tmpstatusdata.get(key); + } + } + if(hasovertime){ + text += (isWrap?"\r\n":"
")+overtime; + } + }else{ + text = tmpstatusdata.get(signkey); + if(hasyichang){ + if(text.length()>0){ + text += (isWrap?"\r\n":"
")+tmpstatusdata.get(key); + }else{ + text += tmpstatusdata.get(key); + } + } + if(hasovertime){ + text += (isWrap?"\r\n":"
")+overtime; + } + } + //需要处理下打卡时间和异常状态显示的顺序--end + tmpdatass.put(key, (isWrap?"\r\n":"
")+overtime); + if(!"".equals(signintime)) { + textAM+=signintime; + } + if(!"".equals(signouttime)) { + textPM+=signouttime; + } + if(!"".equals(overtime)) { + textPM+=overtime; + } + data.put("text", textAM+""+textPM); + data.put("textAM", textAM); + data.put("textPM", textPM); +// text = tmptext.length()>0?tmptext+" "+text:text;//显示所有的状态 +// data.put("text", text); + datas.put(key, data); + + //add + tmpdata.put("text", flag); + tmpdatas.put(key, tmpdata); + //end + } + //全部搞一遍 +// if(tmpdatas != null){ +//// writeLog(n+">>>tmpdatas="+JSONObject.toJSONString(tmpdatas)); +// Map data1 = null; +// for(Entry entry : tmpdatas.entrySet()){ +// String mapKey = Util.null2String(entry.getKey()); +// Map mapValue = (Map)entry.getValue(); +// String flag = Util.null2String(mapValue.get("text")); +// if("true".equals(flag)){//需要加工的数据 +// String overtime = String.valueOf(tmpdatass.get(mapKey)); +// data1 = new HashMap<>(); +// data1.put("text", "√"+overtime); +// datas.put(mapKey, data1); +// } +// } +//// writeLog("datas="+JSONObject.toJSONString(datas)); +// } + }catch (Exception e){ + writeLog(e); + } + // 最后针对数据再处理一遍,不然出现2023-01-02: "休息" 形式的错误,导致页面记载报错,应该是2023-01-01: {text: "休息"}格式 +// boolean isEnd = false; +// for(String currentDate = fromDate; !isEnd;) { +// if (currentDate.equals(toDate)) isEnd = true; +// String dailyValue = Util.null2String(datas.get(currentDate)); +// if(!"".equals(dailyValue) && !dailyValue.contains("text")) { +// Map innerMap2 = new HashMap<>(); +// innerMap2.put("text", dailyValue); +// datas.put(currentDate, innerMap2); +// } +// currentDate = DateUtil.addDate(currentDate, 1); +// } + return datas; + } + + public Map getDetialDatas(String resourceId,String fromDate, String toDate, User user, + Map flowData,boolean isWrap,int uintType,String show_card_source){ + boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + if(isKqReportHalfOpen) { + return getDetialDatasHalfOpen(resourceId, fromDate, toDate, user, flowData, isWrap, uintType, show_card_source); + } + return getDetialDatasHalfNotOpen(resourceId, fromDate, toDate, user, flowData, isWrap, uintType, show_card_source); + } + +// public String getSignStatus(Map data, User user){ +// String result = ""; +// String signtype = Util.null2String(data.get("signtype"));//上班 下班 +// String worktime = Util.null2String(data.get("worktime"));//工作时间 +// String signtime = Util.null2String(data.get("signtime"));//签到时间 +// String abnormalMins = Util.null2String(data.get("abnormalMins"));//异常分钟数 +// String forgotCheck = Util.null2String(data.get("forgotCheck"));//漏签 +// if(worktime.length()>0){ +// if(signtime.length()>0){ +// if(Util.getDoubleValue(abnormalMins)>0){ +// result =SystemEnv.getHtmlLabelName(signtype.equals("1")?20081:20082, user.getLanguage())+abnormalMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage());//迟到 早退 +// }else{ +// result =SystemEnv.getHtmlLabelName(225, user.getLanguage());//正常 +// } +// }else if(forgotCheck.equals("1")){ +// result =SystemEnv.getHtmlLabelName(20086, user.getLanguage());//漏签 +// } +// }else{ +// result = ""; +// } +// +// return result; +// } + + public int getSerialCount(String resourceId, String fromDate, String toDate, String serialId){ + RecordSet rs = new RecordSet(); + String sql = ""; + int serialCount = 0; + try{ + sql = "select count(1) from hrmresource a, kq_format_total b where a.id= b.resourceid and b.resourceid = ? and b.kqdate >=? and b.kqdate <=? and b.serialId = ? "; + rs.executeQuery(sql,resourceId,fromDate,toDate, serialId); + if(rs.next()){ + serialCount = rs.getInt(1); + } + }catch (Exception e){ + writeLog(e); + } + return serialCount; + } + + public static String getSignStatus(Map signInfo, User user){ + return getSignStatus(signInfo,user,""); + } + + public static String getSignStatusHalfNotOpen(Map signInfo, User user,String onOrOff){ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String text = ""; + String isneedcal = Util.null2String(signInfo.get("isneedcal")); + String workdate = Util.null2String(signInfo.get("workdate")); + String worktime = Util.null2String(signInfo.get("worktime")); + if(!new KQFormatBiz().needCal(workdate,worktime,isneedcal)) {//还未到时间无需计算 + return text; + } + int absenteeismMins = Util.getIntValue(Util.null2String(signInfo.get("absenteeismMins"))); + int beLateMins = Util.getIntValue(Util.null2String(signInfo.get("beLateMins"))); + int graveBeLateMins = Util.getIntValue(Util.null2String(signInfo.get("graveBeLateMins"))); + int leaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("leaveEarlyMins"))); + int graveLeaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("graveLeaveEarlyMins"))); + int forgotCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotCheckMins"))); + int forgotBeginWorkCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotBeginWorkCheckMins"))); + int leaveMins = Util.getIntValue(Util.null2String(signInfo.get("leaveMins"))); + String leaveInfo = Util.null2String(signInfo.get("leaveInfo")); + int evectionMins = Util.getIntValue(Util.null2String(signInfo.get("evectionMins"))); + int outMins = Util.getIntValue(Util.null2String(signInfo.get("outMins"))); + + if(worktime.length()>0){ + if (absenteeismMins > 0) {//旷工 + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage())+absenteeismMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + }else { + if (beLateMins > 0) {//迟到 + text = SystemEnv.getHtmlLabelName(20081, user.getLanguage())+beLateMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (graveBeLateMins > 0) {//严重迟到 + text = SystemEnv.getHtmlLabelName( 500546, user.getLanguage())+graveBeLateMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (leaveEarlyMins > 0) {//早退 + text = SystemEnv.getHtmlLabelName(20082, user.getLanguage())+leaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) {//严重早退 + text = SystemEnv.getHtmlLabelName(500547, user.getLanguage())+graveLeaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (forgotCheckMins > 0) {//漏签 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + if(onOrOff.length() > 0 && "on".equalsIgnoreCase(onOrOff)){ + if (forgotBeginWorkCheckMins > 0) {//漏签 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + + if (leaveMins > 0) {//请假 + Map jsonObject = null; + if(leaveInfo.length()>0){ + jsonObject = JSON.parseObject(leaveInfo); + for (Entry entry : jsonObject.entrySet()) { + String newLeaveType = entry.getKey(); + String tmpLeaveMins = Util.null2String(entry.getValue()); + if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ + if (text.length() > 0) text += " "; + //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + text += Util.formatMultiLang(kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); + } + } + }else{ + if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } + } + } + if (evectionMins > 0) {//出差 + if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } + } + if (outMins > 0) {//公出 + if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + } + if(text.equals("")){ + boolean needCal = new KQFormatBiz().needCal(workdate,worktime,isneedcal); + text = needCal?SystemEnv.getHtmlLabelName(225, user.getLanguage()):""; + } + }else{ + if (leaveMins > 0) {//请假 + Map jsonObject = null; + if(leaveInfo.length()>0){ + jsonObject = JSON.parseObject(leaveInfo); + for (Entry entry : jsonObject.entrySet()) { + String newLeaveType = entry.getKey(); + String tmpLeaveMins = Util.null2String(entry.getValue()); + if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ + if (text.length() > 0) text += " "; + //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + text += Util.formatMultiLang(kqLeaveRulesComInfo.getLeaveName(newLeaveType)); + } + } + }else{ + if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } + } + } + if (evectionMins > 0) {//出差 + if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } + } + if (outMins > 0) {//公出 + if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + } + } + return text; + } + + /** + * 应用设置开启了考勤汇总报表半天开关方法 + * @param signInfo + * @param user + * @param onOrOff + * @return + */ + public static String getSignStatusHalfOpen(Map signInfo, User user,String onOrOff){ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + String split_time = Util.null2s(kqTimesArrayComInfo.getPropValue("qc1054152","split_time"),"13:00"); + int split_time_index = kqTimesArrayComInfo.getArrayindexByTimes(split_time); + String text = ""; + String isneedcal = Util.null2String(signInfo.get("isneedcal")); + String workdate = Util.null2String(signInfo.get("workdate")); + String worktime = Util.null2String(signInfo.get("worktime")); + String flowinfo = Util.null2String(signInfo.get("flowinfo")); + boolean isNonWork = Util.str2bool(Util.null2String(signInfo.get("isNonWork"))); + if(!new KQFormatBiz().needCal(workdate,worktime,isneedcal)) {//还未到时间无需计算 + return text; + } + String resourceId = Util.null2String(signInfo.get("resourceId")); + String kqDate = Util.null2String(signInfo.get("kqdate")); + ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceId, kqDate, false); + if(shiftInfoBean == null || isNonWork) { + text = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + if(shiftInfoBean != null) { + List halfWorkIndex = shiftInfoBean.getHalfWorkIndex(); + if (halfWorkIndex != null && !halfWorkIndex.isEmpty()) { + int[] halfWorkIndexs = halfWorkIndex.get(0); + split_time_index = halfWorkIndexs[1];//半天的时间 + } + } + if(flowinfo.length() > 0) { + Map jsonObject = JSON.parseObject(flowinfo); + for (Entry entry : jsonObject.entrySet()) { + String jsonKey = entry.getKey(); + String jsonValue = ""; + if (jsonObject.containsKey(FlowReportTypeEnum.LEAVE.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } else if (jsonObject.containsKey(FlowReportTypeEnum.EVECTION.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } else if (jsonObject.containsKey(FlowReportTypeEnum.OUT.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + if (jsonKey.length() > 0) { + com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONArray.parseArray(Util.null2String(entry.getValue())); + if (jsonArray != null && !jsonArray.isEmpty()) { + //客户不存在多个重复流程的情况,只是显示第一个就行 + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject1 = (JSONObject) jsonArray.getJSONObject(i); + if (jsonObject1 != null && !jsonObject1.isEmpty()) { + String newLeaveType = Util.null2s(Util.null2String(jsonObject1.get("newLeaveType")), ""); + String begintime = Util.null2s(Util.null2String(jsonObject1.get("begintime")), ""); + String endtime = Util.null2s(Util.null2String(jsonObject1.get("endtime")), ""); + int beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endIdx = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (newLeaveType.length() > 0) { + jsonValue = kqLeaveRulesComInfo.getLeaveName(newLeaveType); + } + } + if (beginIdx <= split_time_index && endIdx <= split_time_index) { + //上午 + if ("on".equalsIgnoreCase(onOrOff)) { + text = jsonValue; + } + } else if (beginIdx >= split_time_index && endIdx >= split_time_index) { + //下午 + if ("off".equalsIgnoreCase(onOrOff)) { + text = jsonValue; + } + } else { + //全天 + text = jsonValue; + } + } + } + } + } + } + } + return text; + } + List halfWorkIndex = shiftInfoBean.getHalfWorkIndex(); + if(halfWorkIndex != null && !halfWorkIndex.isEmpty()) { + int[] halfWorkIndexs = halfWorkIndex.get(0); + split_time_index = halfWorkIndexs[1];//半天的时间 + } + int absenteeismMins = Util.getIntValue(Util.null2String(signInfo.get("absenteeismMins"))); + int beLateMins = Util.getIntValue(Util.null2String(signInfo.get("beLateMins"))); + int graveBeLateMins = Util.getIntValue(Util.null2String(signInfo.get("graveBeLateMins"))); + int leaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("leaveEarlyMins"))); + int graveLeaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("graveLeaveEarlyMins"))); + int forgotCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotCheckMins"))); + int forgotBeginWorkCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotBeginWorkCheckMins"))); + int leaveMins = Util.getIntValue(Util.null2String(signInfo.get("leaveMins"))); + String leaveInfo = Util.null2String(signInfo.get("leaveInfo")); + int evectionMins = Util.getIntValue(Util.null2String(signInfo.get("evectionMins"))); + int outMins = Util.getIntValue(Util.null2String(signInfo.get("outMins"))); + + int on_absenteeismmins = Util.getIntValue(Util.null2String(signInfo.get("on_absenteeismmins"))); + int off_absenteeismmins = Util.getIntValue(Util.null2String(signInfo.get("off_absenteeismmins"))); + + String workbeigintime = Util.null2String(signInfo.get("workbegintime")); + String workendtime = Util.null2String(signInfo.get("workendtime")); + String halfPoint = shiftInfoBean.getHalfcalpoint(); + int halfPointIndex = kqTimesArrayComInfo.getArrayindexByTimes(halfPoint); + + if(worktime.length()>0){ +// if (on_absenteeismmins > 0) {//上午旷工 +// text = SystemEnv.getHtmlLabelName(20085, user.getLanguage())+absenteeismMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); +// }else { +// if (beLateMins > 0) {//迟到 +// text = SystemEnv.getHtmlLabelName(20081, user.getLanguage())+beLateMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); +// } +// if (graveBeLateMins > 0) {//严重迟到 +// text = SystemEnv.getHtmlLabelName( 500546, user.getLanguage())+graveBeLateMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); +// } +// if (leaveEarlyMins > 0) {//早退 +// text = SystemEnv.getHtmlLabelName(20082, user.getLanguage())+leaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); +// } +// if (graveLeaveEarlyMins > 0) {//严重早退 +// text = SystemEnv.getHtmlLabelName(500547, user.getLanguage())+graveLeaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); +// } +// if (forgotCheckMins > 0) {//漏签 +// text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); +// } +// if(onOrOff.length() > 0 && "on".equalsIgnoreCase(onOrOff)){ +// if (forgotBeginWorkCheckMins > 0) {//漏签 +// text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); +// } +// } +// } + + if("on".equalsIgnoreCase(onOrOff)) { + if (on_absenteeismmins > 0) { + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + if (beLateMins > 0) {//迟到 + if (text.length() > 0) { + text += " "; + } + text += SystemEnv.getHtmlLabelName(20081, user.getLanguage()) + beLateMins + SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (graveBeLateMins > 0) {//严重迟到 + if (text.length() > 0) { + text += " "; + } + text += SystemEnv.getHtmlLabelName(500546, user.getLanguage()) + graveBeLateMins + SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (forgotBeginWorkCheckMins > 0) {//漏签 + if (text.length() > 0) { + text += " "; + } + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + if("off".equalsIgnoreCase(onOrOff)){ + if(off_absenteeismmins > 0) { + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + if (leaveEarlyMins > 0) {//早退 + if (text.length() > 0) { + text += " "; + } + text += SystemEnv.getHtmlLabelName(20082, user.getLanguage())+leaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) {//严重早退 + if (text.length() > 0) { + text += " "; + } + text += SystemEnv.getHtmlLabelName(500547, user.getLanguage())+graveLeaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (forgotCheckMins > 0) {//漏签 + if (text.length() > 0) { + text += " "; + } + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + + if(flowinfo.length() > 0){ + Map jsonObject = JSON.parseObject(flowinfo); + for (Entry entry : jsonObject.entrySet()) { + String jsonKey = entry.getKey(); + String jsonValue = ""; + if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())){ + jsonValue = SystemEnv.getHtmlLabelName(670, user.getLanguage()); + }else if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.EVECTION.getFlowType())){ + jsonValue = SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + }else if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.OUT.getFlowType())){ + jsonValue = SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + if(jsonKey.length() > 0){ + com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONArray.parseArray(Util.null2String(entry.getValue())); + if(jsonArray != null && !jsonArray.isEmpty()){ + //客户不存在多个重复流程的情况,只是显示第一个就行 + for(int i = 0 ; i < jsonArray.size() ; i++){ + JSONObject jsonObject1 = (JSONObject) jsonArray.getJSONObject(i); + if(jsonObject1 != null && !jsonObject1.isEmpty()){ + String newLeaveType = Util.null2s(Util.null2String(jsonObject1.get("newLeaveType")),""); + String begintime = Util.null2s(Util.null2String(jsonObject1.get("begintime")),""); + String endtime = Util.null2s(Util.null2String(jsonObject1.get("endtime")),""); + int beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endIdx = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + + if(jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())){ + if(newLeaveType.length() > 0){ + jsonValue = kqLeaveRulesComInfo.getLeaveName(newLeaveType); + } + } + if(beginIdx <= split_time_index && endIdx <= split_time_index){ + //上午 + if("on".equalsIgnoreCase(onOrOff)){ + if(begintime.equals(workbeigintime) && endIdx == halfPointIndex) { + text = ""; + } else if(begintime.equals(workbeigintime) && endtime.equals(workendtime)) { + text = ""; + } + text = jsonValue+("".equals(text) ? "":", "+text); + } + }else if(beginIdx >= split_time_index && endIdx >= split_time_index){ + //下午 + if("off".equalsIgnoreCase(onOrOff)){ + if(endIdx == halfPointIndex && endtime.equals(workendtime)) { + text = ""; + } else if(begintime.equals(workbeigintime) && endtime.equals(workendtime)) { + text = ""; + } + text = jsonValue+("".equals(text) ? "":", "+text); + } + }else { + //全天 + if(begintime.equals(workbeigintime) && endtime.equals(workendtime)) { + text = ""; + } + text = jsonValue+("".equals(text) ? "":", "+text); + } + } + if(text.length() > 0){ + break; + } + } + } + } + } + } + + if(text.equals("")){ + boolean needCal = new KQFormatBiz().needCal(workdate,worktime); + text = needCal? SystemEnv.getHtmlLabelName(225, user.getLanguage()):""; + } + }else{ + text = SystemEnv.getHtmlLabelName(225, user.getLanguage()); + if("on".equalsIgnoreCase(onOrOff)){ + if(on_absenteeismmins > 0) { + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + } + if("off".equalsIgnoreCase(onOrOff)){ + if(off_absenteeismmins > 0) { + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } + } + if(flowinfo.length() > 0) { + Map jsonObject = JSON.parseObject(flowinfo); + for (Entry entry : jsonObject.entrySet()) { + String jsonKey = entry.getKey(); + String jsonValue = ""; + if (jsonObject.containsKey(FlowReportTypeEnum.LEAVE.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } else if (jsonObject.containsKey(FlowReportTypeEnum.EVECTION.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } else if (jsonObject.containsKey(FlowReportTypeEnum.OUT.getFlowType())) { + jsonValue = SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + if (jsonKey.length() > 0) { + com.alibaba.fastjson.JSONArray jsonArray = JSONArray.parseArray(Util.null2String(entry.getValue())); + if (jsonArray != null && !jsonArray.isEmpty()) { + //客户不存在多个重复流程的情况,只是显示第一个就行 + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject1 = (JSONObject) jsonArray.getJSONObject(i); + if (jsonObject1 != null && !jsonObject1.isEmpty()) { + String newLeaveType = Util.null2s(Util.null2String(jsonObject1.get("newLeaveType")), ""); + String begintime = Util.null2s(Util.null2String(jsonObject1.get("begintime")), ""); + String endtime = Util.null2s(Util.null2String(jsonObject1.get("endtime")), ""); + int beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endIdx = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if (jsonKey.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (newLeaveType.length() > 0) { + jsonValue = kqLeaveRulesComInfo.getLeaveName(newLeaveType); + } + } + if (beginIdx <= split_time_index && endIdx <= split_time_index) { + //上午 + if ("on".equalsIgnoreCase(onOrOff)) { + text = jsonValue; + } + } else if (beginIdx >= split_time_index && endIdx >= split_time_index) { + //下午 + if ("off".equalsIgnoreCase(onOrOff)) { + text = jsonValue; + } + } else { + //全天 + text = jsonValue; + } + } + } + } + } + } + } + if(text.length() == 0){ + text = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + } + } + return text; + } + + public static String getSignStatus(Map signInfo, User user,String onOrOff){ + boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + if(isKqReportHalfOpen) { + return getSignStatusHalfOpen(signInfo, user, onOrOff); + } + return getSignStatusHalfNotOpen(signInfo, user, onOrOff); + } + + /** + * 获取打卡状态(不包含具体分钟数) + * @param signInfo + * @param user + * @param onOrOff + * @return + */ + public static String getSignStatus2(Map signInfo, User user, String onOrOff) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String text = ""; + String worktime = Util.null2String(signInfo.get("worktime")); + int absenteeismMins = Util.getIntValue(Util.null2String(signInfo.get("absenteeismMins"))); + int beLateMins = Util.getIntValue(Util.null2String(signInfo.get("beLateMins"))); + int graveBeLateMins = Util.getIntValue(Util.null2String(signInfo.get("graveBeLateMins"))); + int leaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("leaveEarlyMins"))); + int graveLeaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("graveLeaveEarlyMins"))); + int forgotCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotCheckMins"))); + int forgotBeginWorkCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotBeginWorkCheckMins"))); + int leaveMins = Util.getIntValue(Util.null2String(signInfo.get("leaveMins"))); + String leaveInfo = Util.null2String(signInfo.get("leaveInfo")); + int evectionMins = Util.getIntValue(Util.null2String(signInfo.get("evectionMins"))); + int outMins = Util.getIntValue(Util.null2String(signInfo.get("outMins"))); + Boolean isNonWork = (Boolean) signInfo.get("isNonWork"); + + if (!isNonWork) { + if (absenteeismMins > 0) {//旷工 + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } else { + if (beLateMins > 0) {//迟到 + text = SystemEnv.getHtmlLabelName(20081, user.getLanguage()); + } + if (graveBeLateMins > 0) {//严重迟到 + text = SystemEnv.getHtmlLabelName(500546, user.getLanguage()); + } + if (leaveEarlyMins > 0) {//早退 + text = SystemEnv.getHtmlLabelName(20082, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) {//严重早退 + text = SystemEnv.getHtmlLabelName(500547, user.getLanguage()); + } + if (forgotCheckMins > 0) {//漏签 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + if (onOrOff.length() > 0 && "on".equalsIgnoreCase(onOrOff)) { + if (forgotBeginWorkCheckMins > 0) {//漏签 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + if (text.equals("") && leaveMins <= 0 && evectionMins <= 0 && outMins <= 0) { + text = SystemEnv.getHtmlLabelName(225, user.getLanguage()); + } + } + return text; + } + + public static boolean getShowFlowText(String leaveInfo,String onOrOff){ + Map jsonObject = null; + jsonObject = JSON.parseObject(leaveInfo); + String flow_signtype = ""; + for (Entry entry : jsonObject.entrySet()) { + String tmpSignType = Util.null2String(entry.getValue()); + flow_signtype += ","+tmpSignType; + } + if(flow_signtype.length() == 0){ + return true; + } + return isShowFlowText(flow_signtype,onOrOff); + } + + public static boolean isShowFlowText(String flow_signtype,String onOrOff){ + boolean showFlowText = true; + + if(flow_signtype.length() > 0){ + flow_signtype = flow_signtype.substring(1); + if("on".equalsIgnoreCase(onOrOff)){ + if((","+flow_signtype+",").indexOf(",1,") > -1){ + //抵扣了上班卡 + }else{ + //上班状态,但是没有上班抵扣流程 + showFlowText = false; + } + } + if("off".equalsIgnoreCase(onOrOff)){ + if((","+flow_signtype+",").indexOf(",2,") > -1){ + //抵扣了下班卡 + }else{ + //下班状态,但是没有下班抵扣流程 + showFlowText = false; + } + } + } + return showFlowText; + } + + public static int getPageSize(String pageSize, String pageUid, int userid){ + String sql = ""; + RecordSet rs = new RecordSet(); + int iPageSize= Util.getIntValue(pageSize,10); + if(iPageSize<10)iPageSize=10; + try{ + if(pageSize.length()>0){ + boolean flag = false; + sql = "select count(1) from ecology_pagesize where pageid = '"+pageUid+"' and userid ="+userid; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>0){ + flag = true; + } + } + if(flag){ + sql = "update ecology_pagesize set pagesize ="+pageSize+" where pageid = '"+pageUid+"' and userid ="+userid; + rs.executeUpdate(sql); + }else{ + sql = "insert into ecology_pagesize (pageid,pagesize,userid) values ('"+pageUid+"',"+pageSize+","+userid+")"; + rs.executeUpdate(sql); + } + }else{ + sql = "select pageSize from ecology_pagesize where pageid = '"+pageUid+"' and userid ="+userid; + rs.executeQuery(sql); + if(rs.next()){ + iPageSize = rs.getInt("pageSize"); + } + } + }catch (Exception e){ + new BaseBean().writeLog("KQReportBiz.getPageSize"+e); + } + + return iPageSize; + } + + //经常遇到申请变更流程或销假流程提示未归档,不胜其烦,所以搞一下 + public void reflow(String requestid){ + try { + requestid = Util.null2String(requestid); + String workflowid = ""; + String currentnodetype = ""; + if(requestid.length() == 0){ + return; + } + RecordSet rs2 = new RecordSet(); + String sql = "select requestid,workflowid,currentnodetype from workflow_requestbase where requestid = '"+requestid+"'"; + rs2.executeQuery(sql); + if(rs2.next()){ + workflowid = Util.null2String(rs2.getString("workflowid")); + currentnodetype = Util.null2String(rs2.getString("currentnodetype")); + } + + boolean isForce1 = false; + boolean isUpgrade1 = false; + if(requestid.length() == 0){ + return ; + } + if(workflowid.length() == 0){ + return ; + } + if(!"3".equals(currentnodetype)){ + return ; + } + long start = System.currentTimeMillis(); + + KQFlowActiontBiz kqFlowActiontBiz = new KQFlowActiontBiz(); + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + String proc_set_sql = "select * from kq_att_proc_set where field001 = ? "; + rs.executeQuery(proc_set_sql, workflowid); + if(rs.next()){ + String proc_set_id = rs.getString("id"); + //得到这个考勤流程设置是否使用明细 + String usedetails = rs.getString("usedetail"); + + int kqtype = Util.getIntValue(rs.getString("field006")); + + Map map = new HashMap(); + if(Util.getIntValue(requestid) > 0){ + map.put("requestId", "and t.requestId = " + requestid); + } + String tablename = ""; + if(kqtype == KqSplitFlowTypeEnum.LEAVE.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.LEAVE.getTablename(); + }else if(kqtype == KqSplitFlowTypeEnum.EVECTION.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.EVECTION.getTablename(); + }else if(kqtype == KqSplitFlowTypeEnum.OUT.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.OUT.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.OVERTIME.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.OVERTIME.getTablename(); + return; + }else if(kqtype == KqSplitFlowTypeEnum.SHIFT.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.SHIFT.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.OTHER.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.OTHER.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.CARD.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.CARD.getTablename();; + return; + }else if(kqtype == KqSplitFlowTypeEnum.LEAVEBACK.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.LEAVEBACK.getTablename();; + }else{ + return; + } + if(null != tablename && tablename.length() > 0){ + String tmpsql = "select * from "+tablename+" where requestId="+requestid; + rs1.executeQuery(tmpsql); + if(rs1.next()){ + return;//表示已经产生了拆分数据 + } + } + + //先根据requestid删除中间表里的数据,再做啥插入操作 + if(kqtype == KqSplitFlowTypeEnum.OVERTIME.getFlowtype()) { + return;//加班就不搞了,有遇到用户销假选择错误流程,选择了加班流程导致这里reflow一次,多余生成了调休 + }else{ + String delSql = "delete from "+tablename+" where requestid = "+requestid; + rs1.executeUpdate(delSql); + Map result = kqFlowActiontBiz.handleKQFlowAction(proc_set_id, usedetails, Util.getIntValue(requestid), kqtype, Util.getIntValue(workflowid), isForce1,isUpgrade1,map); + } + + } + long end = System.currentTimeMillis(); + }catch (Exception e){ + e.printStackTrace();; + } + } + + + //add + public Map getOverTime(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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 subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = Util.getIntValue(Util.null2String(params.get("uintType")));//当前加班单位 + double hoursToDay = Util.getDoubleValue(Util.null2String(params.get("hoursToDay")));//当前天跟小时计算关系 + + String valueField = ""; + + sql = " select resourceid,belongdate,paidLeaveEnable,duration_min "+ + " from hrmresource a, kq_flow_overtime b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " order by resourceid,belongdate "; + rs.execute(sql); +// kqLog.info("getOverTime:sql:"+sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String paidLeaveEnable = rs.getString("paidLeaveEnable"); +// int changeType =rs.getInt("changeType");//1-节假日、2-工作日、3-休息日 + double value = rs.getDouble("duration_min")<0?0:rs.getDouble("duration_min"); + if(uintType==3 || uintType== 5 || uintType== 6){//按小时计算 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0)+"")); + }else{//按天计算 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0*hoursToDay)+"")); + } + String key = resourceid+"|"+belongdate+"|overtime"; + if(value>0){ + df.setMaximumFractionDigits(5); + if(datas.containsKey(key)){ + double tmpVal = Util.getDoubleValue(Util.null2String(datas.get(key)),0.0); + tmpVal += value; + datas.put(key,format(tmpVal)); + }else{ + datas.put(key,format(value)); + } + +// if(datas.containsKey(key)){ +// datas.put(key,"加班"); +//// datas.put(key,SystemEnv.getHtmlLabelName(6151, user.getLanguage())); +// }else{ +// datas.put(key,"加班"); +// } + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } +} diff --git a/src/com/engine/kq/biz/KQShiftManagementComInfo.java b/src/com/engine/kq/biz/KQShiftManagementComInfo.java new file mode 100644 index 0000000..176f4f0 --- /dev/null +++ b/src/com/engine/kq/biz/KQShiftManagementComInfo.java @@ -0,0 +1,814 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.biz.chain.cominfo.HalfShiftComIndex; +import com.engine.kq.biz.chain.cominfo.RestShiftComIndex; +import com.engine.kq.biz.chain.cominfo.ShiftComIndex; +import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean; +import com.engine.kq.biz.chain.cominfo.WorkShiftComIndex; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.log.KQLog; +import java.io.PrintWriter; +import java.io.Serializable; +import java.io.StringWriter; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import org.apache.commons.lang.math.NumberUtils; +import weaver.cache.CacheBase; +import weaver.cache.CacheColumn; +import weaver.cache.CacheColumnType; +import weaver.cache.CacheItem; +import weaver.cache.CacheMap; +import weaver.cache.PKColumn; +import weaver.conn.RecordSet; +import weaver.general.Util; + +/** + * 班次管理缓存类 + */ +public class KQShiftManagementComInfo extends CacheBase implements Serializable { + /* + * 需要关注 : 如果完全在 initCache 自己定义数据初始化, 这个字段可以不定义 + */ + protected static String TABLE_NAME = ""; + + /* + * 需要关注 : 如果完全在 initCache 自己定义数据初始化,或者不需要指定固定的条件, 这个字段可以不定义 + * sql中的where信息,不要以where开始 + */ + protected static String TABLE_WHERE = null; + + /* + * 需要关注 : 如果完全在 initCache 自己定义数据初始化,或者不需要指定顺序, 这个字段可以不定义 sql中的order + * by信息,不要以order by开始 + * + */ + protected static String TABLE_ORDER = null; + + @PKColumn(type = CacheColumnType.NUMBER) + protected static String PK_NAME = "id"; + + @CacheColumn + protected static int shiftbean; + + @CacheColumn + protected static int color; + + @CacheColumn + protected static int isoffdutyfreecheck; + + @CacheColumn + protected static int shiftonoffworkcount; + + @CacheColumn + protected static int serial; + + @CacheColumn + protected static int isresttimeopen; + + @CacheColumn + protected static int worktime; + + @CacheColumn + protected static int punchsetting; + + @CacheColumn + protected static int cardRemind; + + @CacheColumn + protected static int cardRemOfSignIn; + + @CacheColumn + protected static int minsBeforeSignIn; + + @CacheColumn + protected static int cardRemOfSignOut; + + @CacheColumn + protected static int minsAfterSignOut; + + @CacheColumn + protected static int remindMode; + + @CacheColumn + protected static int remindOnPC; + + @CacheColumn + protected static int signoutOnlyoff; + + @CacheColumn + protected static int isRest; + + @CacheColumn + protected static int overtimeRuleId; + + private KQLog kqLog = new KQLog(); + + private boolean isFormat = false; + + @Override + public CacheItem initCache(String key) { + if (key == null || "".equals(key.trim())) { + return null; + } + CacheMap localData = createCacheMap(); + String sql = ""; + kqLog = new KQLog(); + ConcurrentHashMap resourceKQGroups = new ConcurrentHashMap<>(); + //考勤组优先级 + try { + + ConcurrentHashMap shiftInfoBeanMap = new ConcurrentHashMap<>(); + ConcurrentHashMap idMap = new ConcurrentHashMap<>(); + ConcurrentHashMap colorsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isoffdutyfreechecksMap = new ConcurrentHashMap<>(); + ConcurrentHashMap shiftonoffworkcountsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap serialsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isresttimeopensMap = new ConcurrentHashMap<>(); + ConcurrentHashMap worktimesMap = new ConcurrentHashMap<>(); + ConcurrentHashMap punchsettingsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemindMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsBeforeSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsAfterSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindModeMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindOnPCMap = new ConcurrentHashMap<>(); + ConcurrentHashMap signoutOnlyoffMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isResetMap = new ConcurrentHashMap<>(); + ConcurrentHashMap overtimeruleMap = new ConcurrentHashMap<>(); + RecordSet rs = new RecordSet(); + String getShiftInfo = "select * from kq_ShiftManagement where 1=1 and id="+key+" order by id "; + rs.execute(getShiftInfo); + while(rs.next()){ + String serialid = rs.getString("id"); + String isresttimeopen = rs.getString("isresttimeopen"); + String color = rs.getString("color"); + String shiftonoffworkcount = rs.getString("shiftonoffworkcount"); + String worktime = rs.getString("worktime"); + String serial = rs.getString("serial"); + String punchsetting = "1"; + String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck"); + String cardRemind = rs.getString("cardRemind"); + String cardRemOfSignIn = rs.getString("cardRemOfSignIn"); + String minsBeforeSignIn = rs.getString("minsBeforeSignIn"); + String cardRemOfSignOut = rs.getString("cardRemOfSignOut"); + String minsAfterSignOut = rs.getString("minsAfterSignOut"); + String remindMode = rs.getString("remindMode"); + String remindOnPC = rs.getString("remindOnPC"); + String halfcalrule = rs.getString("halfcalrule"); + halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule; + String halfcalpoint = rs.getString("halfcalpoint"); + String halfcalpoint2cross = rs.getString("halfcalpoint2cross"); + String overtimeRuleId = rs.getString("overtime_rule_id"); + String signoutOnlyoff = rs.getString("signoutOnlyoff"); + String isRest = rs.getString("is_rest"); + + getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross,signoutOnlyoff); + + idMap.put(serialid, serialid); + colorsMap.put(serialid, color); + isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck); + shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount); + serialsMap.put(serialid, serial); + isresttimeopensMap.put(serialid, isresttimeopen); + worktimesMap.put(serialid, worktime); + punchsettingsMap.put(serialid, punchsetting); + cardRemindMap.put(serialid,cardRemind); + cardRemOfSignInMap.put(serialid,cardRemOfSignIn); + minsBeforeSignInMap.put(serialid,minsBeforeSignIn); + cardRemOfSignOutMap.put(serialid,cardRemOfSignOut); + minsAfterSignOutMap.put(serialid,minsAfterSignOut); + remindModeMap.put(serialid,remindMode); + remindOnPCMap.put(serialid,remindOnPC); + signoutOnlyoffMap.put(serialid,signoutOnlyoff); + isResetMap.put(serialid,isRest); + overtimeruleMap.put(serialid,overtimeRuleId); + } + + + if(shiftInfoBeanMap.size()>0){ + CacheItem cacheItem = createCacheItem(); + Iterator> iterator = shiftInfoBeanMap.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + String id = entry.getKey(); + Object value = entry.getValue(); + cacheItem.set(PK_INDEX, id); + cacheItem.set(shiftbean, value); + cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id)); + cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id)); + cacheItem.set(serial, serialsMap.get(id)); + cacheItem.set(isresttimeopen, isresttimeopensMap.get(id)); + cacheItem.set(worktime, worktimesMap.get(id)); + cacheItem.set(punchsetting, punchsettingsMap.get(id)); + cacheItem.set(cardRemind,cardRemindMap.get(id)); + cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id)); + cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id)); + cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id)); + cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id)); + cacheItem.set(remindMode,remindModeMap.get(id)); + cacheItem.set(remindOnPC,remindOnPCMap.get(id)); + cacheItem.set(signoutOnlyoff,signoutOnlyoffMap.get(id)); + cacheItem.set(isRest,isResetMap.get(id)); + cacheItem.set(overtimeRuleId,overtimeruleMap.get(id)); + modifyCacheItem(id, cacheItem); + } + return cacheItem; + } + } catch (Exception e) { + kqLog.info(e); + } + return null; + } + + @Override + public CacheMap initCache() { + CacheMap localData = createCacheMap(); + String sql = ""; + kqLog = new KQLog(); + ConcurrentHashMap resourceKQGroups = new ConcurrentHashMap<>(); + //考勤组优先级 + try { + + ConcurrentHashMap shiftInfoBeanMap = new ConcurrentHashMap<>(); + ConcurrentHashMap idMap = new ConcurrentHashMap<>(); + ConcurrentHashMap colorsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isoffdutyfreechecksMap = new ConcurrentHashMap<>(); + ConcurrentHashMap shiftonoffworkcountsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap serialsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isresttimeopensMap = new ConcurrentHashMap<>(); + ConcurrentHashMap worktimesMap = new ConcurrentHashMap<>(); + ConcurrentHashMap punchsettingsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemindMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsBeforeSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsAfterSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindModeMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindOnPCMap = new ConcurrentHashMap<>(); + ConcurrentHashMap signoutOnlyoffMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isResetMap = new ConcurrentHashMap<>(); + ConcurrentHashMap overtimeruleMap = new ConcurrentHashMap<>(); + RecordSet rs = new RecordSet(); + String getShiftInfo = "select * from kq_ShiftManagement where 1=1 order by id "; + rs.execute(getShiftInfo); + while(rs.next()){ + String serialid = rs.getString("id"); + String isresttimeopen = rs.getString("isresttimeopen"); + String color = rs.getString("color"); + String shiftonoffworkcount = rs.getString("shiftonoffworkcount"); + String worktime = rs.getString("worktime"); + String serial = rs.getString("serial"); + String punchsetting = "1"; + String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck"); + String cardRemind = rs.getString("cardRemind"); + String cardRemOfSignIn = rs.getString("cardRemOfSignIn"); + String minsBeforeSignIn = rs.getString("minsBeforeSignIn"); + String cardRemOfSignOut = rs.getString("cardRemOfSignOut"); + String minsAfterSignOut = rs.getString("minsAfterSignOut"); + String remindMode = rs.getString("remindMode"); + String remindOnPC = rs.getString("remindOnPC"); + String halfcalrule = rs.getString("halfcalrule"); + halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule; + String halfcalpoint = rs.getString("halfcalpoint"); + String halfcalpoint2cross = rs.getString("halfcalpoint2cross"); + String signoutOnlyoff = rs.getString("signoutOnlyoff"); + String overtimeRuleId = rs.getString("overtime_rule_id"); + String isRest = rs.getString("is_rest"); + + getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross,signoutOnlyoff); + + idMap.put(serialid, serialid); + colorsMap.put(serialid, color); + isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck); + shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount); + serialsMap.put(serialid, serial); + isresttimeopensMap.put(serialid, isresttimeopen); + worktimesMap.put(serialid, worktime); + punchsettingsMap.put(serialid, punchsetting); + cardRemindMap.put(serialid,cardRemind); + cardRemOfSignInMap.put(serialid,cardRemOfSignIn); + minsBeforeSignInMap.put(serialid,minsBeforeSignIn); + cardRemOfSignOutMap.put(serialid,cardRemOfSignOut); + minsAfterSignOutMap.put(serialid,minsAfterSignOut); + remindModeMap.put(serialid,remindMode); + remindOnPCMap.put(serialid,remindOnPC); + signoutOnlyoffMap.put(serialid,signoutOnlyoff); + isResetMap.put(serialid,isRest); + overtimeruleMap.put(serialid,overtimeRuleId); + } + + + if(shiftInfoBeanMap.size()>0){ + Iterator> iterator = shiftInfoBeanMap.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + String id = entry.getKey(); + Object value = entry.getValue(); + CacheItem cacheItem = createCacheItem(); + cacheItem.set(PK_INDEX, id); + cacheItem.set(shiftbean, value); + cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id)); + cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id)); + cacheItem.set(serial, serialsMap.get(id)); + cacheItem.set(isresttimeopen, isresttimeopensMap.get(id)); + cacheItem.set(worktime, worktimesMap.get(id)); + cacheItem.set(punchsetting, punchsettingsMap.get(id)); + cacheItem.set(cardRemind,cardRemindMap.get(id)); + cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id)); + cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id)); + cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id)); + cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id)); + cacheItem.set(remindMode,remindModeMap.get(id)); + cacheItem.set(remindOnPC,remindOnPCMap.get(id)); + cacheItem.set(signoutOnlyoff,signoutOnlyoffMap.get(id)); + cacheItem.set(isRest,isResetMap.get(id)); + cacheItem.set(overtimeRuleId,overtimeruleMap.get(id)); + modifyCacheItem(id, cacheItem); + localData.put(id, cacheItem); + } + } + } catch (Exception e) { + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + return localData; + } + + public String getId(){ + return (String)getRowValue(PK_INDEX); + } + + public String getColor() { return (String)getRowValue(color); } + + public String getColor(String key) + { + return (String)getValue(color,key); + } + + public String getIsoffdutyfreecheck() { return (String)getRowValue(isoffdutyfreecheck); } + + public String getIsoffdutyfreecheck(String key) + { + return (String)getValue(isoffdutyfreecheck,key); + } + + public String getShiftonoffworkcounts() { return (String)getRowValue(shiftonoffworkcount); } + + public String getShiftonoffworkcounts(String key) + { + return (String)getValue(shiftonoffworkcount,key); + } + + public String getSerial() { return (String)getRowValue(serial); } + + public String getSerial(String key) + { + return (String)getValue(serial,key); + } + + public String getIsresttimeopen() { return (String)getRowValue(isresttimeopen); } + + public String getIsresttimeopen(String key) + { + return (String)getValue(isresttimeopen,key); + } + + public String getWorktime() { return (String)getRowValue(worktime); } + + public String getWorktime(String key) + { + return (String)getValue(worktime,key); + } + + public String getPunchsetting() { + return (String) getRowValue(punchsetting); + } + + public String getPunchsetting(String key) { + return (String) getValue(punchsetting, key); + } + + public String getCardRemind() { + return (String) getRowValue(cardRemind); + } + + public String getCardRemind(String key) { + return (String) getValue(cardRemind,key); + } + + public String getCardRemOfSignIn() { + return (String) getRowValue(cardRemOfSignIn); + } + + public String getCardRemOfSignIn(String key) { + return (String) getValue(cardRemOfSignIn, key); + } + + public String getMinsBeforeSignIn() { + return (String) getRowValue(minsBeforeSignIn); + } + + public String getMinsBeforeSignIn(String key) { + return (String) getValue(minsBeforeSignIn, key); + } + + public String getCardRemOfSignOut() { + return (String) getRowValue(cardRemOfSignOut); + } + + public String getCardRemOfSignOut(String key) { + return (String) getValue(cardRemOfSignOut, key); + } + + public String getMinsAfterSignOut() { + return (String) getRowValue(minsAfterSignOut); + } + + public String getMinsAfterSignOut(String key) { + return (String) getValue(minsAfterSignOut, key); + } + + public String getRemindMode() { + return (String) getRowValue(remindMode); + } + + public String getRemindMode(String key) { + return (String) getValue(remindMode, key); + } + + public String getRemindOnPC() { + return (String) getRowValue(remindOnPC); + } + + public String getRemindOnPC(String key) { + return (String) getValue(remindOnPC, key); + } + + public String getSignoutOnlyoff() { + return (String) getRowValue(signoutOnlyoff); + } + + public String getSignoutOnlyoff(String key) { + return (String) getValue(signoutOnlyoff, key); + } + + public String getIsRest() { + return (String) getRowValue(isRest); + } + + public String getIsRest(String key) { + return (String) getValue(isRest, key); + } + + public String getOvertimeRuleId() { + return (String) getRowValue(overtimeRuleId); + } + + public String getOvertimeRuleId(String key) { + return (String) getValue(overtimeRuleId, key); + } + + private void getShiftInfoBean(String serialid, String isresttimeopen, String worktime, + String punchsettings, + ConcurrentHashMap serialMap, + String halfcalrule,String halfcalpoint,String halfcalpoint2cross, String tmp_signoutOnlyoff) throws Exception { + + Map workTimeMap = new HashMap<>(); + int workmins = 0; + List workTimes = Collections.synchronizedList(new ArrayList<>()); + List restTimes = Collections.synchronizedList(new ArrayList<>()); + KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo(); + KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo(); + + workTimes = kqShiftOnOffWorkSectionComInfo.getWorkSectionTimes(serialid); + if(workTimes != null && !workTimes.isEmpty()){ + if("1".equalsIgnoreCase(isresttimeopen)) { + //如果开启了才去判断 + restTimes = kqShiftRestTimeSectionComInfo.getRestSectionTimes(serialid); + } + if(NumberUtils.isNumber(worktime)){ + if(worktime.indexOf('.') == -1){ + workmins = Util.getIntValue(worktime,0); + }else { + worktime = worktime.substring(0,worktime.indexOf('.')); + workmins = Util.getIntValue(worktime,0); + } + + }else{ + workmins = 0; + kqLog.info("班次有问题,serialid:"+serialid+"工作时长为:"+worktime); + } + workTimeMap.put("workTime", workTimes); + workTimeMap.put("restTime", restTimes); + workTimeMap.put("serialid", serialid); + //工作时长分钟数 + workTimeMap.put("workmins", workmins+""); + workTimeMap.put("punchsettings", punchsettings); + workTimeMap.put("isresttimeopen", isresttimeopen); + workTimeMap.put("halfcalrule", halfcalrule); + workTimeMap.put("halfcalpoint", halfcalpoint); + workTimeMap.put("halfcalpoint2cross", halfcalpoint2cross); + workTimeMap.put("signoutOnlyoff", tmp_signoutOnlyoff.equals("1") ? "1" : "0"); + + ShiftInfoCominfoBean shiftInfoCominfoBean = setShiftInfoBean(workTimeMap); + serialMap.put(serialid, shiftInfoCominfoBean); + } + + } + + private ShiftInfoCominfoBean setShiftInfoBean(Map workTimeMap) throws Exception { + + ShiftComIndex workComIndex = new WorkShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005306,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap); + ShiftComIndex restComIndex = new RestShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005307,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap); + ShiftComIndex halfComIndex = new HalfShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005308,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap); + //创建执行链 + //前一天的都执行完了,去获取当天工作时段,再执行半天的规则 + workComIndex.setDuration(restComIndex); + //执行完了半天的规则,再最后判断休息的时段 + restComIndex.setDuration(halfComIndex); + + ShiftInfoCominfoBean shiftInfoCominfoBean = new ShiftInfoCominfoBean(); + + workComIndex.handleDuration(shiftInfoCominfoBean); + return shiftInfoCominfoBean; + } + + /** + * 考勤按钮 + * @param workdate + * @param serialidInfo + * @param containYesterday + * @return + */ + public Map getWorkButton(String workdate,Map serialidInfo, boolean containYesterday){ + Map shiftMap = new HashMap<>(); + + //考勤按钮还是走缓存 + KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + if(serialidInfo != null && !serialidInfo.isEmpty()){ + LocalDate preLocalDate = LocalDate.parse(workdate); + String preSplitDate = ""; + preLocalDate = preLocalDate.minusDays(1); + preSplitDate = preLocalDate.format(dateFormatter); + String serialid = Util.null2String(serialidInfo.get(workdate)); + String preSerialid = Util.null2String(serialidInfo.get(preSplitDate)); + if(containYesterday){ + if(Util.getIntValue(preSerialid) > 0){ + ShiftInfoCominfoBean pre_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(preSerialid); + List timelineList = pre_shiftInfoCominfoBean.getTimelineList(); + if(timelineList!=null && !timelineList.isEmpty()){ + shiftMap.put("pre_timelineList", timelineList); + } + shiftMap.put("pre_isAcross", pre_shiftInfoCominfoBean.getIsAcross()); + shiftMap.put("pre_allWorkTime", pre_shiftInfoCominfoBean.getAllWorkTime()); + shiftMap.put("pre_allAcrossWorkTime", pre_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftMap.put("pre_signTime", pre_shiftInfoCominfoBean.getSignWorkTime()); + shiftMap.put("pre_restTime", pre_shiftInfoCominfoBean.getRestAcrossLongTime()); + } + } + if(Util.getIntValue(serialid) > 0){ + ShiftInfoCominfoBean cur_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(serialid); + Map shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false); + List timelineList = cur_shiftInfoCominfoBean.getTimelineList(); + if(timelineList!=null && !timelineList.isEmpty()){ + shiftMap.put("timelineList", timelineList); + } + shiftMap.put("isAcross", cur_shiftInfoCominfoBean.getIsAcross()); + shiftMap.put("allWorkTime", cur_shiftInfoCominfoBean.getAllWorkTime()); + shiftMap.put("allAcrossWorkTime", cur_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime()); + shiftMap.put("restTime", cur_shiftInfoCominfoBean.getRestAcrossLongTime()); + if(shiftRuleMap != null && !shiftRuleMap.isEmpty()){ + shiftMap.put("shiftRuleMap", shiftRuleMap); + } + } + } + + return shiftMap; + } + + /** + * 流程计算用的 + * @param workdate + * @param serialidInfo + * @param containYesterday + * @return + * shiftInfoBean 每一天内含有的班次都拆分出来,包含昨天班次在今天的时段0-24小时制的 + * shiftLongInfoBean 当天的班次数据,0-48小时制度的 + */ + public Map getWorkDuration(String workdate,Map serialidInfo,boolean containYesterday){ + + KQWorkTime kqWorkTime = new KQWorkTime(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Map dateWorkTimeMap = new HashMap<>(); + LocalDate preLocalDate = LocalDate.parse(workdate); + String preSplitDate = ""; + preLocalDate = preLocalDate.minusDays(1); + preSplitDate = preLocalDate.format(dateFormatter); + if(serialidInfo != null && !serialidInfo.isEmpty()){ + String preSerialid = Util.null2String(serialidInfo.get(preSplitDate)); + String serialid = Util.null2String(serialidInfo.get(workdate)); + Boolean isNonWork = kqWorkTime.isNonWork(serialidInfo); + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setPreSplitDate(preSplitDate); + shiftInfoBean.setSplitDate(workdate); + shiftInfoBean.setD_Mins(0.0); + shiftInfoBean.setPreSerialid(preSerialid); + shiftInfoBean.setSerialid(serialid); + shiftInfoBean.setRestShift(isNonWork?1:0); + if(containYesterday){ + if(Util.getIntValue(serialid) > 0 || Util.getIntValue(preSerialid) > 0){ + fillShiftInfoBean(shiftInfoBean, preSerialid, serialid); + dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean); + } + }else{ + if(Util.getIntValue(serialid) > 0){ + fillShiftInfoBean(shiftInfoBean, preSerialid, serialid); + dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean); + } + } + } + + return dateWorkTimeMap; + } + + /** + * 根据班次id获取对应日期的上下班时间+休息时间 + * @param workdate + * @param serialidInfo + * @return + */ + public Map getWorkTimeMap(String workdate,Map serialidInfo){ + + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Map dateWorkTimeMap = new HashMap<>(); + LocalDate preLocalDate = LocalDate.parse(workdate); + String preSplitDate = ""; + preLocalDate = preLocalDate.minusDays(1); + preSplitDate = preLocalDate.format(dateFormatter); + if(serialidInfo != null && !serialidInfo.isEmpty()){ + String preSerialid = Util.null2String(serialidInfo.get(preSplitDate)); + String serialid = Util.null2String(serialidInfo.get(workdate)); + getShiftInfoBeanMap(dateWorkTimeMap,preSerialid, serialid); + } + + return dateWorkTimeMap; + } + + /** + * 根据考勤报表需要的 返回相应格式的数据 + * @param dateWorkTimeMap + * @param preSerialid + * @param serialid + */ + private void getShiftInfoBeanMap(Map dateWorkTimeMap,String preSerialid, String serialid) { + ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid); + + if(cur_shiftInfoCominfoBean != null){ + dateWorkTimeMap.put("restTime",cur_shiftInfoCominfoBean.getRestAcrossLongTime()); + dateWorkTimeMap.put("workTime",cur_shiftInfoCominfoBean.getWorkAcrossLongTime()); + dateWorkTimeMap.put("workMins",cur_shiftInfoCominfoBean.getWorkmins()); + dateWorkTimeMap.put("isAcross",cur_shiftInfoCominfoBean.getIsAcross()); + dateWorkTimeMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime()); + dateWorkTimeMap.put("halfWorkTime", cur_shiftInfoCominfoBean.getHalfWorkTime()); + dateWorkTimeMap.put("halfWorkIndex", cur_shiftInfoCominfoBean.getHalfWorkIndex()); + dateWorkTimeMap.put("convertAttendDay", cur_shiftInfoCominfoBean.getConvertAttendDay()); + } + } + + /** + * 每次获取的话都需要获取昨天和今天的班次数据 + * @param shiftInfoBean + * @param preSerialid 昨天的班次 + * @param serialid 今天的班次 + */ + private void fillShiftInfoBean(ShiftInfoBean shiftInfoBean,String preSerialid,String serialid){ + ShiftInfoCominfoBean pre_shiftInfoCominfoBean = getShiftInfoCominfoBean(preSerialid); + ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid); + Map pre_shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(preSerialid,false); + Map shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false); + + //把前一个班次的填充好 + if(pre_shiftInfoCominfoBean != null){ + shiftInfoBean.setPreWorkIndex(pre_shiftInfoCominfoBean.getPreWorkTimeIndex()); + shiftInfoBean.setPreWorkAcrossIndex(pre_shiftInfoCominfoBean.getWorkAcrossTimeIndex()); + shiftInfoBean.setPreWorkMinsAcrossIndex(pre_shiftInfoCominfoBean.getWorkPunchMins()); + shiftInfoBean.setPreRestIndex(pre_shiftInfoCominfoBean.getPreRestTimeIndex()); + shiftInfoBean.setPreHalfWorkIndex(pre_shiftInfoCominfoBean.getHalfWorkIndex()); + shiftInfoBean.setPreWorkmins(pre_shiftInfoCominfoBean.getWorkmins()); + shiftInfoBean.setPreAllWorkTime(pre_shiftInfoCominfoBean.getAllWorkTime()); + shiftInfoBean.setPreAllAcrossWorkTime(pre_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftInfoBean.setPreAllRestTime(pre_shiftInfoCominfoBean.getAllRestTime()); + shiftInfoBean.setPreAllAcrossRestTime(pre_shiftInfoCominfoBean.getAllAcrossRestTime()); + shiftInfoBean.setPreSerialid(preSerialid); + shiftInfoBean.setIsPreAcross(pre_shiftInfoCominfoBean.getIsAcross()); + shiftInfoBean.setShiftRuleMap(pre_shiftRuleMap); + shiftInfoBean.setPreConvertAttendDay(pre_shiftInfoCominfoBean.getConvertAttendDay()); + } + + //把当前班次的填充好 + if(cur_shiftInfoCominfoBean != null){ + shiftInfoBean.setWorkIndex(cur_shiftInfoCominfoBean.getWorkTimeIndex()); + shiftInfoBean.setWorkAcrossIndex(cur_shiftInfoCominfoBean.getWorkAcrossTimeIndex()); + shiftInfoBean.setWorkMinsAcrossIndex(cur_shiftInfoCominfoBean.getWorkPunchMins()); + shiftInfoBean.setRestIndex(cur_shiftInfoCominfoBean.getRestTimeIndex()); + shiftInfoBean.setHalfWorkIndex(cur_shiftInfoCominfoBean.getHalfWorkIndex()); + shiftInfoBean.setWorkmins(cur_shiftInfoCominfoBean.getWorkmins()); + shiftInfoBean.setAllWorkTime(cur_shiftInfoCominfoBean.getAllWorkTime()); + shiftInfoBean.setAllAcrossWorkTime(cur_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftInfoBean.setAllRestTime(cur_shiftInfoCominfoBean.getAllRestTime()); + shiftInfoBean.setAllAcrossRestTime(cur_shiftInfoCominfoBean.getAllAcrossRestTime()); + shiftInfoBean.setAllLongWorkTime(cur_shiftInfoCominfoBean.getAllLongWorkTime()); + shiftInfoBean.setRestLongTimeIndex(cur_shiftInfoCominfoBean.getRestLongTimeIndex()); + shiftInfoBean.setWorkLongTimeIndex(cur_shiftInfoCominfoBean.getWorkLongTimeIndex()); + shiftInfoBean.setIsAcross(cur_shiftInfoCominfoBean.getIsAcross()); + shiftInfoBean.setSerialid(serialid); + shiftInfoBean.setShiftRuleMap(shiftRuleMap); + + if(cur_shiftInfoCominfoBean.getWorkAcrossLongTime() != null){ + List workTime1 = cur_shiftInfoCominfoBean.getWorkAcrossLongTime().stream().collect(Collectors.toList()); + List lsWorkTime = new KQWorkTime().formatTimeScope(workTime1, false); + shiftInfoBean.setWorkTime(lsWorkTime); + } + if(cur_shiftInfoCominfoBean.getSignWorkTime() != null){ + List signTime1 = cur_shiftInfoCominfoBean.getSignWorkTime().stream().collect(Collectors.toList()); + List lsSignTime = new KQWorkTime().formatTimeScope(signTime1, true); + shiftInfoBean.setSignTime(lsSignTime); + } + shiftInfoBean.setHalfcalrule(cur_shiftInfoCominfoBean.getHalfcalrule()); + shiftInfoBean.setHalfcalpoint(cur_shiftInfoCominfoBean.getHalfcalpoint()); + shiftInfoBean.setHalfcalpoint2cross(cur_shiftInfoCominfoBean.getHalfcalpoint2cross()); + shiftInfoBean.setWorkAcrossTime(cur_shiftInfoCominfoBean.getWorkAcrossTime()); + shiftInfoBean.setEachWorkMins(cur_shiftInfoCominfoBean.getEachWorkMins()); + shiftInfoBean.setConvertAttendDay(cur_shiftInfoCominfoBean.getConvertAttendDay()); + } + } + + public void removeShiftManagementCache(){ + KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo(); + KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo(); + kqShiftRestTimeSectionComInfo.removeShiftRestTimeSectionCache(); + kqShiftOnOffWorkSectionComInfo.removeShiftWorkSectionCache(); + super.removeCache(); + //改用redis和staticobj的方式 + KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis(); + kqShiftManagementRedis.resetShiftValWithRedis(); + } + + /** + * 根据班次获取shiftInfoCominfoBean + * @param serialid + * @return + */ + public ShiftInfoCominfoBean getShiftInfoCominfoBean(String serialid){ +// Object object = getObjValue(shiftbean, serialid); +// if(object != null){ +// return (ShiftInfoCominfoBean) object; +// }else{ +// return null; +// } + //改用redis和staticobj的方式 + KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis(); + return kqShiftManagementRedis.getShiftInfoBeanMapBySql(serialid); + } + + /** + * 根据人员和日期获取shiftInfoCominfoBean + * @param workdate + * @param serialidInfo + * @return + */ + public ShiftInfoCominfoBean getShiftInfoCominfoBean(String workdate,Map serialidInfo){ + ShiftInfoCominfoBean shiftInfoCominfoBean = null; + if(serialidInfo != null && !serialidInfo.isEmpty()){ + String serialid = Util.null2String(serialidInfo.get(workdate)); + if(Util.getIntValue(serialid) > 0){ + shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid); + } + } + return shiftInfoCominfoBean; + } + + public boolean isFormat() { + return isFormat; + } + + public void setFormat(boolean format) { + isFormat = format; + } +} diff --git a/src/com/engine/kq/cmd/report/ExportDailyExcelCmd.java b/src/com/engine/kq/cmd/report/ExportDailyExcelCmd.java new file mode 100644 index 0000000..0aa27f9 --- /dev/null +++ b/src/com/engine/kq/cmd/report/ExportDailyExcelCmd.java @@ -0,0 +1,690 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.util.ExcelUtil; +import com.engine.kq.util.KQDurationCalculatorUtil; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.util.*; + +public class ExportDailyExcelCmd extends AbstractCommonCommand> { + + private HttpServletRequest request; + private HttpServletResponse response; + private List lsFieldDataKey; + + public ExportDailyExcelCmd(Map params, HttpServletRequest request, HttpServletResponse response, User user) { + this.user = user; + this.params = params; + this.request = request; + this.response = response; + this.lsFieldDataKey = new ArrayList<>(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + KQWorkTime kqWorkTime = new KQWorkTime(); + KQReportBiz kqReportBiz = new KQReportBiz(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + + new KQReportBiz().insertKqReportExportLog(params, user); + 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")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + List showColumns = Util.splitString2List(Util.null2String(jsonObj.get("showColumns")),","); + showColumns.add("lastname"); + showColumns.add("kqdate"); + showColumns.add("serialid"); + showColumns.removeIf(showColumn->showColumn.trim().equals("")); + + List tmpShowColumns = new ArrayList<>(); + for(String showColumn:showColumns){ + tmpShowColumns.add(showColumn); + String cascadekey = ""; + if(showColumn.equals("signin1")){ + cascadekey = "signout1"; + }else if(showColumn.equals("signin2")){ + cascadekey = "signout2"; + }else if(showColumn.equals("signin3")){ + cascadekey = "signout3"; + }else if(showColumn.equals("beLate")){ + cascadekey = "beLateMins"; + }else if(showColumn.equals("leaveEearly")){ + cascadekey = "leaveEarlyMins"; + }else if(showColumn.equals("graveBeLate")){ + cascadekey = "graveBeLateMins"; + }else if(showColumn.equals("graveLeaveEarly")){ + cascadekey = "graveLeaveEarlyMins"; + }else if(showColumn.equals("absenteeism")){ + cascadekey = "absenteeismMins"; + }else if(showColumn.equals("overtime")){ + tmpShowColumns.add("overtime_4leave"); + tmpShowColumns.add("overtime_nonleave"); + tmpShowColumns.add("workingDayOvertime_nonleave"); + tmpShowColumns.add("workingDayOvertime_4leave"); + tmpShowColumns.add("restDayOvertime_nonleave"); + tmpShowColumns.add("restDayOvertime_4leave"); + tmpShowColumns.add("holidayOvertime_4leave"); + tmpShowColumns.add("holidayOvertime_nonleave"); + } + if(cascadekey.length()>0){ + tmpShowColumns.add(cascadekey); + } + } + showColumns = tmpShowColumns; + + String today = DateUtil.getCurrentDate(); + if(DateUtil.compDate(today, toDate)>0){//结束如期不大于今天 + toDate = today; + } + + String rightSql = new KQReportBiz().getReportRight("2",""+user.getUID(),"a"); + + LinkedHashMap workbook = new LinkedHashMap<>(); + List lsSheet = new ArrayList<>(); + Map sheet = null; + List titleList = new ArrayList<>(); + Map title = null; + List> dataList = new ArrayList<>(); + List data = null; + List> constraintList = null; + Map constraint = null; + + sheet = new HashMap<>(); + sheet.put("sheetName", SystemEnv.getHtmlLabelName( 390352, user.getLanguage())); + sheet.put("sheetTitle", SystemEnv.getHtmlLabelName( 390352, user.getLanguage())); + + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()){ + if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue; + if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily"))continue; + if (!showColumns.contains(kqReportFieldComInfo.getFieldname())&&!showColumns.contains(kqReportFieldComInfo.getParentid())) continue; + if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){ + continue; + } + title = new HashMap<>(); + String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user); + if(unitType.length()>0){ + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ "(" + unitType + ")"); + }else{ + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + } + title.put("width",30*256); + this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user); + childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + title.put("children", childColumns); + title.put("colSpan",childColumns.size()); + }else{ + title.put("rowSpan", 3); + } + titleList.add(title); + } + sheet.put("titleList", titleList); + + // 没有权限的人最大只支持查询本季 + Map getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "2"); + fromDate = getRealDate.get("fromDate"); + toDate = getRealDate.get("toDate"); + if("-1".equals(fromDate) || "-1".equals(toDate)) { + retmap.put("status", "1"); + return retmap; + } + + String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck "; + + if(rs.getDBType().equalsIgnoreCase("oracle")&&!Util.null2String(rs.getOrgindbtype()).equals("dm")&&!Util.null2String(rs.getOrgindbtype()).equals("st")) { + forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) "; + }else { + forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) "; + } + + String backFields = " a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," + + " b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,b.attendanceMins,b.beLate," + + " b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins,b.graveLeaveEarly," + + " b.graveLeaveEarlyMins,b.absenteeism,b.signdays,b.signmins, "+ + " b.absenteeismMins ,(b.forgotCheck+"+forgotBeginWorkCheck_field+") forgotCheck "; + String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'"; + String sqlWhere = rightSql; + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + if(status.length()>0){ + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = "+status+ ""; + }else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + String orderBy = " order by a.dsporder asc, a.lastname asc , b.kqDate asc "; + String descOrderBy = " order by a.dsporder desc, a.lastname desc "; + sql = "select "+backFields + sqlFrom + sqlWhere+orderBy; + + // #1475814-概述:满足考勤报分部部门显示及导出时显示全路径 + String fullPathMainKey = "show_full_path"; + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0"); + + Map serialdata = new HashMap<>(); + boolean isneedcal = KQSettingsBiz.getKqformatAccurate(); + params.put("isneedcal",isneedcal?"1":"0"); + Map flowData = kqReportBiz.getDailyFlowData(params,user); + rs.execute(sql); + while (rs.next()) { + data = new ArrayList<>(); + String id = rs.getString("id"); + String kqdate = rs.getString("kqdate"); + String tmpkey = id+"|"+kqdate+"|"; +// Map signDetailInfo = this.getSignDetailInfo(id,kqdate); + + for (int fieldDataKeyIdx =0;fieldDataKeyIdx0){ +// fieldValue = Util.formatMultiLang(shiftManagementToolKit.getShiftOnOffWorkSections(serialid, user.getLanguage())); + + if(null != serialdata && serialdata.containsKey(serialid)){ + fieldValue = serialdata.get(serialid); + }else{ + String tmpserialname = Util.formatMultiLang(shiftManagementToolKit.getShiftOnOffWorkSections(serialid, user.getLanguage())); + fieldValue = tmpserialname; + serialdata.put(serialid,tmpserialname); + } + } + } else if(fieldName.equals("signin1")){ + fieldValue = Util.null2String(flowData.get(tmpkey+"signintime1")); + data.add(fieldValue); + fieldValue = Util.null2String(flowData.get(tmpkey+"signinstatus1")); + data.add(fieldValue); + continue; + } else if(fieldName.equals("signin2")){ + fieldValue = Util.null2String(flowData.get(tmpkey+"signintime2")); + data.add(fieldValue); + fieldValue = Util.null2String(flowData.get(tmpkey+"signinstatus2")); + data.add(fieldValue); + continue; + } else if(fieldName.equals("signin3")){ + fieldValue = Util.null2String(flowData.get(tmpkey+"signintime3")); + data.add(fieldValue); + fieldValue = Util.null2String(flowData.get(tmpkey+"signinstatus3")); + data.add(fieldValue); + continue; + } else if(fieldName.equals("signout1")){ + fieldValue = Util.null2String(flowData.get(tmpkey+"signouttime1")); + data.add(fieldValue); + fieldValue = Util.null2String(flowData.get(tmpkey+"signoutstatus1")); + data.add(fieldValue); + continue; + } else if(fieldName.equals("signout2")){ + fieldValue = Util.null2String(flowData.get(tmpkey+"signouttime2")); + data.add(fieldValue); + fieldValue = Util.null2String(flowData.get(tmpkey+"signoutstatus2")); + data.add(fieldValue); + continue; + } else if(fieldName.equals("signout3")){ + fieldValue = Util.null2String(flowData.get(tmpkey+"signouttime3")); + data.add(fieldValue); + fieldValue = Util.null2String(flowData.get(tmpkey+"signoutstatus3")); + data.add(fieldValue); + continue; + } else if(fieldName.equals("leave")){ + //请假 + List> allLeaveRules = KQLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = allLeaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = allLeaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + allLeaveRules.remove(i); + } + } + } + Map leaveRule = null; + for(int i=0;allLeaveRules!=null&&i)allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_"+leaveRule.get("id")); + fieldValue = Util.null2String(flowData.get(id+"|"+kqdate+"|"+flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //以防止出现精度问题 + if (fieldValue.length() == 0) { + fieldValue = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + BigDecimal b_leaveData = new BigDecimal(fieldValue); + BigDecimal b_leavebackData = new BigDecimal(leavebackData); + b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString(); + if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){ + b_flowLeaveData = "0.0"; + } + + } catch (Exception e) { + writeLog("ExportDailyExcelCmd:fieldValue" + fieldValue + ":leavebackData:" + leavebackData + ":" + e); + } + //考虑下冻结的数据 + if (b_flowLeaveData.length() > 0) { + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData); + } else { + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(fieldValue, 0.0) - Util.getDoubleValue(leavebackData, 0.0))); + } + fieldValue = flowLeaveData; + + data.add(fieldValue); + } + }else if(fieldName.equals("overtime")){ + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_nonleave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_nonleave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_nonleave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_4leave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_4leave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_4leave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave")))); + + double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_4leave"))); + workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave; + double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_4leave"))); + restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave; + double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_4leave"))); + holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave; + + double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_nonleave"))); + workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave; + double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_nonleave"))); + restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave; + double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_nonleave"))); + holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave; + fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+ + workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave)); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal")))); + continue; + }else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){ + String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+fieldName)),"0.0"); + String backType = fieldName+"_back"; + String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+backType)),"0.0"); + String businessLeave = ""; + try{ + //以防止出现精度问题 + if(businessLeaveData.length() == 0){ + businessLeaveData = "0.0"; + } + if(businessLeavebackData.length() == 0){ + businessLeavebackData = "0.0"; + } + BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData); + BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData); + businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString(); + if(Util.getDoubleValue(businessLeave, -1) < 0){ + businessLeave = "0.0"; + } + }catch (Exception e){ + } + fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave); + }else if(fieldName.equals("kqdate")){ + fieldValue=kqdate+" "+com.engine.portal.util.DateUtil.getDayWeekOfDate1(DateUtil.parseToDate(kqdate)); + } else { + fieldValue = Util.null2String(rs.getString(fieldName)); + fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid)); + } + + if(!fieldName.equals("leave")) { + fieldValue = Util.formatMultiLang(fieldValue, "" + user.getLanguage()); + data.add(fieldValue); + } + } + dataList.add(data); + } + sheet.put("dataList", dataList); + sheet.put("constraintList",constraintList); + sheet.put("createFile", "1"); + lsSheet.add(sheet); + + workbook.put("sheet", lsSheet); + String fileName = SystemEnv.getHtmlLabelName(390352, user.getLanguage())+" "+fromDate+" "+toDate;; + workbook.put("fileName", fileName); + ExcelUtil ExcelUtil = new ExcelUtil(); + Map exportMap= ExcelUtil.export(workbook,request,response); + retmap.putAll(exportMap); + retmap.put("status", "1"); + } catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage())); + writeLog(e); + } + return retmap; + } + + private Map getChildColumnsInfo(String parentid, User user){ + Map returnMap = new HashMap<>(); + List titleList = new ArrayList<>(); + Map title = null; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + if(parentid.equals("leave")){ + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = leaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = leaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + leaveRules.remove(i); + } + } + } + for(int i=0;leaveRules!=null&&i leaveRule = leaveRules.get(i); + String name = Util.formatMultiLang(Util.null2String(leaveRule.get("name")),""+user.getLanguage()); + String unitType = Util.null2String(leaveRule.get("unitType")); + title = new HashMap<>(); + title.put("title",name+"("+ + ((KQUnitBiz.isLeaveHour(unitType))?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage()))+")"); + title.put("width",30*256); + titleList.add(title); + + } + }else if(parentid.equals("overtime")){ + String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"}; + for(int i=0;i0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())+ "(" + unitTypeName + ")"); + } + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + title.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65); + } + title.put("width", childWidth+""); + titleList.add(title); + } + } else{ + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()){ + if(kqReportFieldComInfo.getParentid().equals(parentid)) { + if(!kqReportFieldComInfo.getReportType().equals("daily"))continue; + title = new HashMap<>(); + title.put("title",SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ + (KQReportBiz.getUnitType(kqReportFieldComInfo, user).length()>0?"("+ KQReportBiz.getUnitType(kqReportFieldComInfo, user)+")":"")); + title.put("width",30*256); + titleList.add(title); + } + } + } + returnMap.put("childColumns",titleList); + return returnMap; + } + + public Map getSignDetailInfo(String resourceId, String kqDate){ + Map data = new HashMap<>(); + Map signStatusInfo = null; + RecordSet rs = new RecordSet(); + String sql = ""; + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + try{ + sql = " select kqdate,resourceid,serialid,serialnumber,workbegindate,workbegintime, " + + " workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" + + " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," + + " leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid \n" + + " from kq_format_detail b \n" + + " where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' \n" + + " order by serialnumber \n"; + rs.execute(sql); + while (rs.next()) { + String resourceid = Util.null2String(rs.getString("resourceid")); + String kqdate = Util.null2String(rs.getString("kqdate")); + String serialid = Util.null2String(rs.getString("serialid")); + int serialnumber = rs.getInt("serialnumber")+1; + String workbegindate = Util.null2String(rs.getString("workbegindate")).trim(); + String workbegintime = Util.null2String(rs.getString("workbegintime")).trim(); + String workenddate = Util.null2String(rs.getString("workenddate")).trim(); + String workendtime = Util.null2String(rs.getString("workendtime")).trim(); + int workMins = rs.getInt("workMins"); + String signintime = Util.null2String(rs.getString("signintime")).trim(); + String signouttime = Util.null2String(rs.getString("signouttime")).trim(); + int attendanceMins = rs.getInt("attendanceMins"); + String beLateMins = Util.null2String(rs.getString("beLateMins")).trim(); + String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim(); + String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim(); + String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim(); + String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim(); + String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim(); + String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim(); + String signinid = Util.null2String(rs.getString("signinid")).trim(); + String signoutid = Util.null2String(rs.getString("signoutid")).trim(); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = Util.null2String(rs.getString("leaveInfo")); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + + + if(serialid.length()>0){ + if (workbegintime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("workdate",workbegindate); + signStatusInfo.put("worktime",workbegintime); + signStatusInfo.put("beLateMins",beLateMins); + signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins); + signStatusInfo.put("graveBeLateMins",graveBeLateMins); + signStatusInfo.put("absenteeismMins",absenteeismMins); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + + data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime); + data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + } + + if (workendtime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("workdate",workenddate); + signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime)); + signStatusInfo.put("leaveEarlyMins",leaveEarlyMins); + signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins); + signStatusInfo.put("forgotCheckMins",forgotCheckMins); + signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins); + signStatusInfo.put("absenteeismMins",absenteeismMins); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + + data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + }else{ + if(workMins>0){ + //弹性工时打卡时间取自签到签退数据 + } + signStatusInfo = new HashMap(); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + + if(signinid.length() > 0){ + data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime); + data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + if(signoutid.length() > 0){ + data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + }else{ + data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + } + } + } + }catch (Exception e){ + writeLog(e); + } + return data; + } + + private String getFieldValueByUnitType(String fieldValue,String unittype){ + if (Util.null2String(unittype).length() > 0) { + if (fieldValue.length() == 0) { + fieldValue = "0"; + } else { + if (unittype.equals("2")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + } + } + return fieldValue; + } + + @Override + public BizLogContext getLogContext() { + return null; + } +} diff --git a/src/com/engine/kq/cmd/report/ExportExcelCmd.java b/src/com/engine/kq/cmd/report/ExportExcelCmd.java new file mode 100644 index 0000000..7fa862c --- /dev/null +++ b/src/com/engine/kq/cmd/report/ExportExcelCmd.java @@ -0,0 +1,718 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.engine.kq.util.ExcelUtil; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.UtilKQ; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; +import com.google.common.collect.Lists; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.util.*; + +public class ExportExcelCmd extends AbstractCommonCommand> { + + private HttpServletRequest request; + private HttpServletResponse response; + private List lsFieldDataKey; + + private boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + + public ExportExcelCmd(Map params, HttpServletRequest request, HttpServletResponse response, User user) { + this.user = user; + this.params = params; + this.request = request; + this.response = response; + this.lsFieldDataKey = new ArrayList<>(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + + KQReportBiz kqReportBiz = new KQReportBiz(); + new KQReportBiz().insertKqReportExportLog(params, user); + 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")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + List showColumns = Util.splitString2List(Util.null2String(jsonObj.get("showColumns")), ","); + showColumns.add("lastname"); + showColumns.removeIf(showColumn->showColumn.trim().equals("")); + + List tmpShowColumns = new ArrayList<>(); + for(String showColumn:showColumns){ + tmpShowColumns.add(showColumn); + String cascadekey = ""; + if(showColumn.equals("beLate")){ + cascadekey = "beLateMins"; + }else if(showColumn.equals("leaveEearly")){ + cascadekey = "leaveEarlyMins"; + }else if(showColumn.equals("graveBeLate")){ + cascadekey = "graveBeLateMins"; + }else if(showColumn.equals("graveLeaveEarly")){ + cascadekey = "graveLeaveEarlyMins"; + }else if(showColumn.equals("absenteeism")){ + cascadekey = "absenteeismMins"; + }else if(showColumn.equals("overtime")){ + tmpShowColumns.add("overtime_4leave"); + tmpShowColumns.add("overtime_nonleave"); + tmpShowColumns.add("workingDayOvertime_nonleave"); + tmpShowColumns.add("workingDayOvertime_4leave"); + tmpShowColumns.add("restDayOvertime_nonleave"); + tmpShowColumns.add("restDayOvertime_4leave"); + tmpShowColumns.add("holidayOvertime_4leave"); + tmpShowColumns.add("holidayOvertime_nonleave"); + } + if(cascadekey.length()>0){ + tmpShowColumns.add(cascadekey); + } + } + showColumns = tmpShowColumns; + + String rightSql = new KQReportBiz().getReportRight("1", "" + user.getUID(), "a"); + + LinkedHashMap workbook = new LinkedHashMap<>(); + List lsSheet = new ArrayList<>(); + Map sheet = null; + List titleList = new ArrayList<>(); + Map title = null; + List> dataList = new ArrayList<>(); + List data = null; + List> constraintList = null; + + sheet = new HashMap<>(); + sheet.put("sheetName", SystemEnv.getHtmlLabelName(390351, user.getLanguage())); + sheet.put("sheetTitle", SystemEnv.getHtmlLabelName(390351, user.getLanguage())); + boolean isEnd = false; + Calendar cal = DateUtil.getCalendar(); + + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (Util.null2String(kqReportFieldComInfo.getParentid()).length() > 0) continue; + if(kqReportFieldComInfo.getFieldname().equals("kqCalendar"))continue; + if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue; + if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month")) + continue; + if (!showColumns.contains(kqReportFieldComInfo.getFieldname())&&!showColumns.contains(kqReportFieldComInfo.getParentid())) continue; + if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){ + continue; + } + title = new HashMap<>(); + String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user); + if(unitType.length()>0){ + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ "(" + unitType + ")"); + }else{ + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + } + title.put("width", 30 * 256); + this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(), user); + childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//跨列width取子列的width + title.put("children", childColumns); + title.put("colSpan", childColumns.size()); + } else { + title.put("rowSpan", 3); + } + titleList.add(title); + + titleList.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user)); + } + + String today = DateUtil.getCurrentDate(); +// if (DateUtil.compDate(today, toDate) > 0) {//结束如期不大于今天 +// toDate = today; +// } + + if(showColumns.contains("kqCalendar")) { + childColumns = new ArrayList<>(); + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + title = new HashMap<>(); + title.put("title", UtilKQ.getWeekDayShort(DateUtil.getWeek(date)-1,user.getLanguage()) +"\r\n"+ DateUtil.geDayOfMonth(date)); + title.put("width", 30 * 256); + childColumns.add(title); + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + + title = new HashMap(); + title.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage())); + if (childColumns.size() > 0) {//跨列width取子列的width + title.put("children", childColumns); + title.put("colSpan", childColumns.size()); + } + titleList.add(title); + } + sheet.put("titleList", titleList); + + // 没有权限的人最大只支持查询本季 + Map getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1"); + fromDate = getRealDate.get("fromDate"); + toDate = getRealDate.get("toDate"); + if("-1".equals(fromDate) || "-1".equals(toDate)) { + retmap.put("status", "1"); + return retmap; + } + + String forgotBeginWorkCheck_field = " sum(b.forgotBeginWorkCheck) "; + + if(rs.getDBType().equalsIgnoreCase("oracle")) { + forgotBeginWorkCheck_field = " sum(nvl(b.forgotBeginWorkCheck,0)) "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + forgotBeginWorkCheck_field = " sum(ifnull(b.forgotBeginWorkCheck,0)) "; + }else { + forgotBeginWorkCheck_field = " sum(isnull(b.forgotBeginWorkCheck,0)) "; + } + + Map definedFieldInfo = new KQFormatBiz().getDefinedField(); + String definedFieldSum = Util.null2String(definedFieldInfo.get("definedFieldSum")); + String backFields = " a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," + + " sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," + + " sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " + + " sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," + + " sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " + + " sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " + + " sum(b.signdays) as signdays,sum(b.signmins) as signmins, "+ + " sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+"+forgotBeginWorkCheck_field+" as forgotCheck "+(definedFieldSum.length()>0?","+definedFieldSum+"":""); + if(rs.getDBType().equals("oracle")){ + backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields; + } + String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'"; + String sqlWhere = rightSql; + String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle "; + if (subCompanyId.length() > 0) { + sqlWhere += " and a.subcompanyid1 in(" + subCompanyId + ") "; + } + + if (departmentId.length() > 0) { + sqlWhere += " and a.departmentid in(" + departmentId + ") "; + } + + if (resourceId.length() > 0) { + sqlWhere += " and a.id in(" + resourceId + ") "; + } + + if (viewScope.equals("4")) {//我的下属 + if (allLevel.equals("1")) {//所有下属 + sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'"; + } else { + sqlWhere += " and a.managerid=" + user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' "); + } + + if(status.length()>0){ + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = "+status+ ""; + }else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + String orderBy = " order by a.dsporder asc, a.lastname asc "; + String descOrderBy = " order by a.dsporder desc, a.lastname desc "; + sql = "select " + backFields + sqlFrom + sqlWhere + groupBy + orderBy; + + //System.out.println("start" + DateUtil.getFullDate()); + + + String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源 + params.put("show_card_source",show_card_source); + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + params.put("uintType",uintType); + params.put("hoursToDay",hoursToDay); + Map flowData = new KQReportBiz().getFlowData(params, user); + //System.out.println("end" + DateUtil.getFullDate()); + + // #1475814-概述:满足考勤报分部部门显示及导出时显示全路径 + String fullPathMainKey = "show_full_path"; + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0"); + + + rs.execute(sql); + int calIndex = -1; + while (rs.next()) { + data = new ArrayList<>(); + String id = rs.getString("id"); + for (int fieldDataKeyIdx =0;fieldDataKeyIdx serialIds = null; + if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) { + serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ","); + for(int i=0;serialIds!=null&&i> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = allLeaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = allLeaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + allLeaveRules.remove(i); + } + } + } + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + leaveRule = allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(flowData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //以防止出现精度问题 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + BigDecimal b_leaveData = new BigDecimal(leaveData); + BigDecimal b_leavebackData = new BigDecimal(leavebackData); + b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString(); + if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){ + b_flowLeaveData = "0.0"; + } + } catch (Exception e) { + writeLog("GetKQReportCmd:leaveData" + leaveData + ":leavebackData:" + leavebackData + ":" + e); + } + + if (b_flowLeaveData.length() > 0) { + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData); + } else { + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData, 0.0) - Util.getDoubleValue(leavebackData, 0.0))); + } + data.add(flowLeaveData); + } + continue; + }else if(fieldName.equals("overtime")){ + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_nonleave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_nonleave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_nonleave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_4leave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_4leave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave")))); + + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_4leave"))); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave")))); + + double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leave"))); + workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave; + double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leave"))); + restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave; + double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leave"))); + holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave; + + double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleave"))); + workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave; + double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleave"))); + restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave; + double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleave"))); + holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave; + fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+ + workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave)); + data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal")))); + continue; + }else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){ + String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+fieldName)),"0.0"); + String backType = fieldName+"_back"; + String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+backType)),"0.0"); + String businessLeave = ""; + try{ + //以防止出现精度问题 + if(businessLeaveData.length() == 0){ + businessLeaveData = "0.0"; + } + if(businessLeavebackData.length() == 0){ + businessLeavebackData = "0.0"; + } + BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData); + BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData); + businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString(); + if(Util.getDoubleValue(businessLeave, -1) < 0){ + businessLeave = "0.0"; + } + }catch (Exception e){ + } + fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave); + } else if(Util.null2String(kqReportFieldComInfo.getCascadekey(fieldid)).length()>0){ + fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage()); + data.add(fieldValue); + + List lsCascadekey = Util.splitString2List(kqReportFieldComInfo.getCascadekey(fieldid),","); + for(int i=0;i0){ + fieldid = KQReportFieldComInfo.field2Id.get(lsCascadekey.get(i)); + fieldValue = getFieldValueByUnitType(rs.getString(lsCascadekey.get(i)),kqReportFieldComInfo.getUnittype(fieldid)); + }else{ + fieldValue = "0"; + } + data.add(fieldValue); + } + continue; + }else { + fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage()); + fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid)); + } + fieldValue = Util.formatMultiLang(fieldValue,""+user.getLanguage()); + data.add(fieldValue); + } + + List amData = Lists.newArrayList(); + List pmData = Lists.newArrayList(); + if(isKqReportHalfOpen) { + amData.addAll(data); + pmData.addAll(data); + calIndex = data.size(); + } + + if(showColumns.contains("kqCalendar")) { +// Map detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true); + Map detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true,uintType,show_card_source); + String user_endDate = Util.null2String(resourceComInfo.getEndDate(id)); + String user_status = Util.null2String(resourceComInfo.getStatus(id)); + String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim(); + String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim(); + if(companyStartDate.length()!=10){ + companyStartDate = ""; + } + if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){ + begindate=companyStartDate; + } + isEnd = false; + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + String dismissDate = resourceComInfo.getEndDate(id); + if(!"".equals(dismissDate) && DateUtil.compDate(dismissDate, date)>0) { + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + } else if (DateUtil.compDate(today, date) > 0) { + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + } else { + if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){ + //其他状态 + if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后 + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + } + if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准 + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + if (detialDatas.get(id + "|" + date) != null) { + if(isKqReportHalfOpen) { + amData.add(((Map) detialDatas.get(id + "|" + date)).get("textAM")); + pmData.add(((Map) detialDatas.get(id + "|" + date)).get("textPM")); + } else { + data.add(((Map) detialDatas.get(id + "|" + date)).get("text")); + } + } else { + if(isKqReportHalfOpen) { + amData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + pmData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + } else { + data.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + } + } + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + } + if(isKqReportHalfOpen) { + dataList.add(amData); + dataList.add(pmData); + } else { + dataList.add(data); + } + } + sheet.put("dataList", dataList); + if(isKqReportHalfOpen) { + sheet.put("calIndex", calIndex); + } + sheet.put("constraintList", constraintList); + sheet.put("createFile", "1"); + lsSheet.add(sheet); + + workbook.put("sheet", lsSheet); + String fileName = SystemEnv.getHtmlLabelName(390351, user.getLanguage())+" "+fromDate+" "+toDate; + workbook.put("fileName", fileName); + ExcelUtil ExcelUtil = new ExcelUtil(); + Map exportMap = ExcelUtil.export(workbook, request, response,true); + retmap.putAll(exportMap); + retmap.put("status", "1"); + } catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage())); + writeLog(e); + } + return retmap; + } + + private Map getChildColumnsInfo(String parentid, User user) { + Map returnMap = new HashMap<>(); + List titleList = new ArrayList<>(); + Map title = null; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + if (parentid.equals("attendanceSerial")) {//考勤班次 + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + List serialIds = null; + if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) { + serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ","); + } + for (int i = 0; serialIds != null && i < serialIds.size(); i++) { + title = new HashMap<>(); + title.put("title", Util.formatMultiLang(kqShiftManagementComInfo.getSerial(serialIds.get(i)),""+user.getLanguage())); + title.put("width", 30 * 256); + titleList.add(title); + } + } else if (parentid.equals("leave")) { + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = leaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = leaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + leaveRules.remove(i); + } + } + } + for (int i = 0; leaveRules != null && i < leaveRules.size(); i++) { + Map leaveRule = leaveRules.get(i); + String name = Util.formatMultiLang(Util.null2String(leaveRule.get("name")),""+user.getLanguage()); + String unitType = Util.null2String(leaveRule.get("unitType")); + String unitName = (KQUnitBiz.isLeaveHour(unitType)) ? SystemEnv.getHtmlLabelName(391, user.getLanguage()) : SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + title = new HashMap<>(); + title.put("title", name + "(" + unitName + ")"); + title.put("width", 30 * 256); + titleList.add(title); + } + }else if(parentid.equals("overtime")){ + String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"}; + for(int i=0;i0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())+ "(" + unitTypeName + ")"); + } + + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + title.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65); + } + title.put("width", childWidth+""); + titleList.add(title); + } + } else { + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (kqReportFieldComInfo.getParentid().equals(parentid)) { + if(!kqReportFieldComInfo.getReportType().equals("month"))continue; + title = new HashMap<>(); + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")"); + title.put("width", 30 * 256); + titleList.add(title); + } + } + } + returnMap.put("childColumns", titleList); + return returnMap; + } + + private List getCascadeKeyColumnsInfo(String cascadeKey, User user){ + List titleList = new ArrayList<>(); + Map title = null; + if(Util.null2String(cascadeKey).length()==0){ + return titleList; + } + List lsCascadeKey = Util.splitString2List(cascadeKey,","); + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + for(int i=0;i(); + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")"); + title.put("width", 30 * 256); + + titleList.add(title); + } + } + } + return titleList; + } + + private String getFieldValueByUnitType(String fieldValue,String unittype){ + if (Util.null2String(unittype).length() > 0) { + if (fieldValue.length() == 0) { + fieldValue = "0"; + } else { + if (unittype.equals("2")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + } + } + return fieldValue; + } + @Override + public BizLogContext getLogContext() { + return null; + } +} diff --git a/src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java b/src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java new file mode 100644 index 0000000..ad8ef1e --- /dev/null +++ b/src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java @@ -0,0 +1,696 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.PageUidFactory; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GetKQDailyReportCmd extends AbstractCommonCommand> { + + private KQLog kqLog = new KQLog(); + + public GetKQDailyReportCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String pageUid = PageUidFactory.getHrmPageUid("KQDailyReport"); + + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + KQWorkTime kqWorkTime = new KQWorkTime(); + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + KQReportBiz kqReportBiz = new KQReportBiz(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + + String rightSql = new KQReportBiz().getReportRight("2",""+user.getUID(),"a"); + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + 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")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(typeselect.length()==0)typeselect = "3"; + 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> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + List columns = new ArrayList(); + Map column = null; + List datas = new ArrayList(); + Map data = null; + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()){ + if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue; + boolean isDaily = kqReportFieldComInfo.getReportType().equals("daily"); + if(!kqReportFieldComInfo.getReportType().equals("all") && !isDaily)continue; + if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){ + continue; + } + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user); + childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + column.put("rowSpan", 1); + column.put("width", mapChildColumnInfo.get("sumChildColumnWidth")); + column.put("children", childColumns); + }else{ + column.put("rowSpan", 3); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + } + if(kqReportFieldComInfo.getReportType1().equals("daily")){ + column.put("isdaily", "1"); + } + column.put("showDetial",kqReportFieldComInfo.getShowDetial()); + columns.add(column); + } + +// String today = DateUtil.getCurrentDate(); +// if(DateUtil.compDate(today, toDate)>0){//结束如期不大于今天 +// toDate = today; +// if(DateUtil.compDate(today, fromDate)>0){ +// fromDate = today; +// } +// } + String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck "; + + if(rs.getDBType().equalsIgnoreCase("oracle")&&!Util.null2String(rs.getOrgindbtype()).equals("dm")&&!Util.null2String(rs.getOrgindbtype()).equals("st")&&!Util.null2String(rs.getOrgindbtype()).equals("jc")) { + forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) "; + }else { + forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) "; + } + + String backFields = " a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," + + " b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,b.attendanceMins," + + " b.beLate,b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins," + + " b.signdays,b.signmins, "+ + " b.graveLeaveEarly,b.graveLeaveEarlyMins,b.absenteeism ,b.absenteeismMins ,(b.forgotCheck+"+forgotBeginWorkCheck_field+") forgotCheck "; + String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'"; + String sqlWhere = rightSql; + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + if(status.length()>0){ + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = "+status+ ""; + }else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+") t"; + rs.execute(sql); + if (rs.next()){ + count = rs.getInt("c"); + } + + if (count <= 0) { + pageCount = 0; + } + + pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0); + + isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0; + + isHavePre = (pageIndex - 1 >= 1) ? 1 : 0; + + String orderBy = " order by a.dsporder asc, a.lastname asc, b.kqdate asc "; + String descOrderBy = " order by a.dsporder desc, a.lastname desc, b.kqdate desc "; + sql = backFields + sqlFrom + sqlWhere + orderBy; + + if (pageIndex > 0 && pageSize > 0) { + if (rs.getDBType().equals("oracle")) { + sql = " select " + sql; + sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= " + + (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize); + } else if (rs.getDBType().equals("mysql")) { + sql = " select " + sql; + sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize; + } + else if (rs.getDBType().equals("postgresql")) { + sql = " select " + sql; + sql = "select t1.* from (" + sql + ") t1 limit " + pageSize+ " offset " + ((pageIndex - 1) * pageSize); + } + else { + orderBy = " order by dsporder asc, lastname asc, kqdate asc "; + descOrderBy = " order by dsporder desc, lastname desc, kqdate desc "; + if (pageIndex > 1) { + int topSize = pageSize; + if (pageSize * pageIndex > count) { + topSize = count - (pageSize * (pageIndex - 1)); + } + sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top " + + (pageIndex * pageSize) + sql+" ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy; + } else { + sql = " select top " + pageSize + sql; + } + } + } else { + sql = " select " + sql; + } + boolean isneedcal = KQSettingsBiz.getKqformatAccurate(); + params.put("isneedcal",isneedcal?"1":"0"); + Map flowData = kqReportBiz.getDailyFlowData(params,user); + Map serialdata = new HashMap<>(); + + // #1475814-概述:满足考勤报分部部门显示及导出时显示全路径 + String fullPathMainKey = "show_full_path"; + + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0"); + + rs.execute(sql); + while (rs.next()) { + String id = rs.getString("id"); + String kqdate = rs.getString("kqdate"); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(id, kqdate); + data = new HashMap<>(); + kqReportFieldComInfo.setTofirstRow(); + while (kqReportFieldComInfo.next()) { + if (!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1")) continue; + if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily")) + continue; + String fieldName = kqReportFieldComInfo.getFieldname(); + String fieldValue = ""; + if (fieldName.equals("subcompany")) { + String fieldValueID = rs.getString("subcompanyid"); + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") : + subCompanyComInfo.getSubCompanyname(fieldValueID); + + //fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID); + + if (fieldValue.length() == 0) { + fieldValueID = resourceComInfo.getSubCompanyID(id); + + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") : + subCompanyComInfo.getSubCompanyname(fieldValueID); + + // fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID); + } + data.put(fieldName + "Id", fieldValueID); + data.put(fieldName, fieldValue); + } else if (fieldName.equals("department")) { + String fieldValueID = rs.getString("departmentid"); + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") : + departmentComInfo.getDepartmentname(fieldValueID); + //fieldValue = departmentComInfo.getDepartmentname(fieldValueID); + + if (fieldValue.length() == 0) { + fieldValueID = resourceComInfo.getDepartmentID(id); + + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") : + departmentComInfo.getDepartmentname(fieldValueID); + + // fieldValue = departmentComInfo.getDepartmentname(fieldValueID); + } + data.put(fieldName + "Id", fieldValueID); + data.put(fieldName, fieldValue); + } else if (fieldName.equals("jobtitle")) { + String fieldValueID = rs.getString("jobtitle"); + fieldValue = jobTitlesComInfo.getJobTitlesname(rs.getString("jobtitle")); + if (fieldValue.length() == 0) { + fieldValueID = resourceComInfo.getJobTitle(id); + fieldValue = jobTitlesComInfo.getJobTitlesname(fieldValueID); + } + data.put(fieldName + "Id", fieldValueID); + data.put(fieldName, fieldValue); + } else if (kqReportFieldComInfo.getParentid().equals("overtime") || kqReportFieldComInfo.getParentid().equals("overtime_nonleave") + || kqReportFieldComInfo.getParentid().equals("overtime_4leave") || fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) { + if (fieldName.equals("overtimeTotal")) { + double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_4leave"))); + workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave; + double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_4leave"))); + restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave; + double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_4leave"))); + holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave; + + double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_nonleave"))); + workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave; + double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_nonleave"))); + restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave; + double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_nonleave"))); + holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave; + + fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave + + workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave)); + } else { + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|" + kqdate + "|" + fieldName))); + } + data.put(fieldName, fieldValue); + } else if (fieldName.equals("serialid")) { + fieldValue = Util.null2String(rs.getString(fieldName)); + if (fieldValue.length()>0) {//弹性工作制没有班次 +// data.put("serialid", shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage())); + + if(null != serialdata && serialdata.containsKey(fieldValue)){ + data.put("serialid", serialdata.get(fieldValue)); + }else{ + String tmpserialname = shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage()); + serialdata.put(fieldValue,tmpserialname); + data.put("serialid", tmpserialname); + } + } + }else { + fieldValue = Util.null2String(rs.getString(fieldName)); + if (kqReportFieldComInfo.getUnittype().equals("2") && fieldValue.length() > 0) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + data.put(fieldName, fieldValue); + } + } + data.putAll(this.getSignDetailInfo(id, kqdate)); + + //请假 + List> allLeaveRules = KQLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = allLeaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = allLeaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + allLeaveRules.remove(i); + } + } + } + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //以防止出现精度问题 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + BigDecimal b_leaveData = new BigDecimal(leaveData); + BigDecimal b_leavebackData = new BigDecimal(leavebackData); + b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString(); + if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){ + b_flowLeaveData = "0.0"; + } + + } catch (Exception e) { + kqLog.info("GetKQReportCmd:leaveData" + leaveData + ":leavebackData:" + leavebackData + ":" + e); + } + + //考虑下冻结的数据 + if (b_flowLeaveData.length() > 0) { + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData); + } else { + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData, 0.0) - Util.getDoubleValue(leavebackData, 0.0))); + } + data.put(flowType, flowLeaveData); + } + + data.put("resourceId", id); + data.put("kqdate", kqdate); + datas.add(data); + } + + List lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate); + retmap.put("holidays", lsHolidays); + retmap.put("columns",columns); + retmap.put("datas",datas); + 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){ + writeLog(e); + } + return retmap; + } + + + private String getUnitType(String unitType, User user){ + String unitTypeName = ""; + if(Util.null2String(unitType).length()>0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + return unitTypeName; + } + + private Map getChildColumnsInfo(String parentid, User user){ + Map returnMap = new HashMap<>(); + List lsChildColumns = new ArrayList<>(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + Map column = null; + int sumChildColumnWidth = 0; + if(parentid.equals("leave")){ + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = leaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = leaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + leaveRules.remove(i); + } + } + } + for(int i=0;leaveRules!=null&&i leaveRule = leaveRules.get(i); + String id = "leaveType_"+Util.null2String(leaveRule.get("id")); + String name = Util.null2String(leaveRule.get("name")); + String unitType = Util.null2String(leaveRule.get("unitType")); + column = new HashMap(); + column.put("title", name); + column.put("unit", KQUnitBiz.isLeaveHour(unitType) ?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage())); + column.put("width", 65); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 2); + column.put("colSpan", 1); + column.put("showDetial","1"); + sumChildColumnWidth+=65; + lsChildColumns.add(column); + } + }else if(parentid.equals("overtime")){ + String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"}; + for(int i=0;i0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + column.put("unit", unitTypeName); + } + column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 1); + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + column.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65); + } + column.put("width", childWidth+""); + sumChildColumnWidth+=childWidth; + lsChildColumns.add(column); + } + }else{ + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()){ + if(kqReportFieldComInfo.getParentid().equals(parentid)) { + if(!kqReportFieldComInfo.getReportType().equals("daily"))continue; + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("rowSpan", 2); + column.put("colSpan", 1); + column.put("isdaily", kqReportFieldComInfo.getReportType1().equals("daily")?"1":"0"); + sumChildColumnWidth+=Util.getIntValue(kqReportFieldComInfo.getWidth()); + lsChildColumns.add(column); + } + } + } + returnMap.put("childColumns",lsChildColumns); + returnMap.put("sumChildColumnWidth",sumChildColumnWidth); + return returnMap; + } + + public Map getSignDetailInfo(String resourceId, String kqDate){ + Map data = new HashMap<>(); + Map signStatusInfo = null; + RecordSet rs = new RecordSet(); + String sql = ""; + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + try{ + sql = " select kqdate,resourceid,day_type,serialid,serialnumber,workbegindate,workbegintime, " + + " workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" + + " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," + + " leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid,flowinfo,on_absenteeismmins,off_absenteeismmins \n" + + " from kq_format_detail b \n" + + " where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' \n" + + " order by serialnumber \n"; + rs.execute(sql); + while (rs.next()) { + String resourceid = Util.null2String(rs.getString("resourceid")); + String kqdate = Util.null2String(rs.getString("kqdate")); + String serialid = Util.null2String(rs.getString("serialid")); + String dayType = Util.null2s(rs.getString("day_type"),""); + int workMins = rs.getInt("workMins"); + boolean isNonWork = false; + if(dayType.length() > 0){ + if("holiday".equals(dayType) || "playday".equals(dayType)){ + isNonWork = true; + } + }else{ + if(workMins<=0){ + isNonWork = true; + }else{ + if(serialid.length() > 0){ + String isRest = Util.null2s(kqShiftManagementComInfo.getIsRest(serialid),""); + if("1".equals(isRest)){ + isNonWork = true; + } + } + } + } + int serialnumber = rs.getInt("serialnumber")+1; + String workbegindate = Util.null2String(rs.getString("workbegindate")).trim(); + String workbegintime = Util.null2String(rs.getString("workbegintime")).trim(); + String workenddate = Util.null2String(rs.getString("workenddate")).trim(); + String workendtime = Util.null2String(rs.getString("workendtime")).trim(); + String signintime = Util.null2String(rs.getString("signintime")).trim(); + String signouttime = Util.null2String(rs.getString("signouttime")).trim(); + int attendanceMins = rs.getInt("attendanceMins"); + String beLateMins = Util.null2String(rs.getString("beLateMins")).trim(); + String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim(); + String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim(); + String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim(); + String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim(); + String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim(); + String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim(); + String signinid = Util.null2String(rs.getString("signinid")).trim(); + String signoutid = Util.null2String(rs.getString("signoutid")).trim(); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = Util.null2String(rs.getString("leaveInfo")); + String flowinfo = Util.null2String(rs.getString("flowinfo")); + String on_absenteeismmins = Util.null2String(rs.getString("on_absenteeismmins")); + String off_absenteeismmins = Util.null2String(rs.getString("off_absenteeismmins")); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + + + if(!isNonWork){ + if (workbegintime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("resourceId",resourceid); + signStatusInfo.put("kqdate",kqdate); + signStatusInfo.put("workdate",workbegindate); + signStatusInfo.put("worktime",workbegintime); + signStatusInfo.put("beLateMins",beLateMins); + signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins); + signStatusInfo.put("graveBeLateMins",graveBeLateMins); + signStatusInfo.put("absenteeismMins",absenteeismMins); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + signStatusInfo.put("flowinfo",flowinfo); + signStatusInfo.put("on_absenteeismmins",on_absenteeismmins); + signStatusInfo.put("off_absenteeismmins",off_absenteeismmins); + signStatusInfo.put("workbegintime",workbegintime); + signStatusInfo.put("workendtime",workendtime); + + data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime); + data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + } + + if (workendtime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("resourceId",resourceid); + signStatusInfo.put("kqdate",kqdate); + signStatusInfo.put("workdate",workenddate); + signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime)); + signStatusInfo.put("leaveEarlyMins",leaveEarlyMins); + signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins); + signStatusInfo.put("forgotCheckMins",forgotCheckMins); + signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins); + signStatusInfo.put("absenteeismMins",absenteeismMins); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + signStatusInfo.put("flowinfo",flowinfo); + signStatusInfo.put("on_absenteeismmins",on_absenteeismmins); + signStatusInfo.put("off_absenteeismmins",off_absenteeismmins); + signStatusInfo.put("workbegintime",workbegintime); + signStatusInfo.put("workendtime",workendtime); + + data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + }else{ + if(workMins>0){ + //弹性工时打卡时间取自签到签退数据 + } + signStatusInfo = new HashMap(); + signStatusInfo.put("resourceId",resourceid); + signStatusInfo.put("kqdate",kqdate); + signStatusInfo.put("leaveMins",leaveMins); + signStatusInfo.put("leaveInfo",leaveInfo); + signStatusInfo.put("evectionMins",evectionMins); + signStatusInfo.put("outMins",outMins); + signStatusInfo.put("flowinfo",flowinfo); + signStatusInfo.put("on_absenteeismmins",on_absenteeismmins); + signStatusInfo.put("off_absenteeismmins",off_absenteeismmins); + signStatusInfo.put("workbegintime",workbegintime); + signStatusInfo.put("workendtime",workendtime); + + if(signinid.length() > 0){ + data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime); + data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + if(signoutid.length() > 0){ + data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime); + data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + }else{ + data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + }else if (signoutid.length() > 0) { + data.put("signouttime" + serialnumber, signouttime.length() == 0 ? SystemEnv.getHtmlLabelName(25994, user.getLanguage()) : signouttime); + data.put("signoutstatus" + serialnumber, KQReportBiz.getSignStatus(signStatusInfo, user, "off")); + } else{ + data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on")); + data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off")); + } + } + } + }catch (Exception e){ + writeLog(e); + } + return data; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/report/GetKQReportCmd.java b/src/com/engine/kq/cmd/report/GetKQReportCmd.java new file mode 100644 index 0000000..017342d --- /dev/null +++ b/src/com/engine/kq/cmd/report/GetKQReportCmd.java @@ -0,0 +1,818 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.weaver.file.Prop; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.PageUidFactory; +import com.google.common.collect.Maps; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.math.BigDecimal; +import java.util.*; + +public class GetKQReportCmd extends AbstractCommonCommand> { + + public GetKQReportCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String pageUid = PageUidFactory.getHrmPageUid("KQReport"); + + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + KQReportBiz kqReportBiz = new KQReportBiz(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + + 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")); + 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()); + boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + if(isKqReportHalfOpen) { + pageSize = pageSize/2; + } + int count = 0; + int pageCount = 0; + int isHavePre = 0; + int isHaveNext = 0; + + + String rightSql = kqReportBiz.getReportRight("1",""+user.getUID(),"a"); + if(isFromMyAttendance.equals("1")){ + rightSql = ""; + } + + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + List columns = new ArrayList(); + Map column = null; + List datas = new ArrayList(); + Map data = null; + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()){ + if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue; + if(kqReportFieldComInfo.getFieldname().equals("kqCalendar"))continue; + if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue; + if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))continue; + if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0)continue; + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("type", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("isSystem", kqReportFieldComInfo.getIsSystem()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user); + childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + column.put("rowSpan", 1); + column.put("width", mapChildColumnInfo.get("sumChildColumnWidth")); + column.put("children", childColumns); + }else{ + column.put("rowSpan", 3); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + } + column.put("showDetial",kqReportFieldComInfo.getShowDetial()); + columns.add(column); + columns.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user)); + } + + boolean isEnd = false; + Calendar cal = DateUtil.getCalendar(); + String today = DateUtil.getCurrentDate(); +// if(DateUtil.compDate(today, toDate)>0){//结束日期不大于今天 +// toDate = today; +// if(DateUtil.compDate(today, fromDate)>0){//结束日期不大于今天 +// fromDate = today; +// } +// } + + childColumns = new ArrayList<>(); + for(String date=fromDate; !isEnd;) { + if(date.equals(toDate)) isEnd = true; + column = new HashMap(); + column.put("title", DateUtil.geDayOfMonth(date)); + column.put("dataIndex", date); + column.put("key", date); + column.put("type", date); + column.put("rowSpan", 1); + column.put("width", 90); + column.put("isCalendar", 1); + childColumns.add(column); + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage())); + column.put("dataIndex", "kqCalendar"); + column.put("key", "kqCalendar"); + if(childColumns.size()>0) {//跨列width取子列的width + column.put("rowSpan", 1); + column.put("width", childColumns.size()*90); + column.put("children", childColumns); + } + columns.add(column); + + + // 没有权限的人最大只支持查询本季 + Map getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1"); + fromDate = getRealDate.get("fromDate"); + toDate = getRealDate.get("toDate"); + + String forgotBeginWorkCheck_field = " sum(b.forgotBeginWorkCheck) "; + + if(rs.getDBType().equalsIgnoreCase("oracle")) { + forgotBeginWorkCheck_field = " sum(nvl(b.forgotBeginWorkCheck,0)) "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + forgotBeginWorkCheck_field = " sum(ifnull(b.forgotBeginWorkCheck,0)) "; + }else { + forgotBeginWorkCheck_field = " sum(isnull(b.forgotBeginWorkCheck,0)) "; + } + + Map definedFieldInfo = new KQFormatBiz().getDefinedField(); + String definedFieldSum = Util.null2String(definedFieldInfo.get("definedFieldSum")); + + String backFields = " a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," + + " sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," + + " sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " + + " sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," + + " sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " + + " sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " + + " sum(b.signdays) as signdays,sum(b.signmins) as signmins, "+ + " sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+"+forgotBeginWorkCheck_field+" as forgotCheck "+(definedFieldSum.length()>0?","+definedFieldSum+"":""); + + if(rs.getDBType().equals("oracle")){ + backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields; + } + String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'"; + String sqlWhere = rightSql; + String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle "; + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//我的下属 + if(allLevel.equals("1")){//所有下属 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//直接下属 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + if(status.length()>0){ + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = "+status+ ""; + }else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + if("-1".equals(fromDate) || "-1".equals(toDate)) { + sqlWhere += " and 1=2 "; + } + sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+groupBy+") t"; + rs.execute(sql); + if (rs.next()){ + count = rs.getInt("c"); + } + + if (count <= 0) { + pageCount = 0; + } + + pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0); + + isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0; + + isHavePre = (pageIndex - 1 >= 1) ? 1 : 0; + + String orderBy = " order by t.dsporder asc, t.lastname asc "; + String descOrderBy = " order by t.dsporder desc, t.lastname desc "; + + //默认排序设置 start,有性能问题,先取消,后面再看看有没有好的方式 +// String orderBySql = "select * from kq_report_order where userId=? and sort=1 order by orders"; +// rs.executeQuery(orderBySql, user.getUID()); +// if (rs.getCounts() <= 0) { +// orderBySql = "select * from kq_report_order where userId=0 and sort=1 order by orders"; +// rs.executeQuery(orderBySql); +// } +// while (rs.next()) { +// String dataIndex = rs.getString("dataIndex"); +// String ascOrDesc = rs.getString("ascOrDesc"); +// String ascOrDesc1 = (ascOrDesc.equals("")||ascOrDesc.equals("asc"))?"desc":"asc"; +// if (dataIndex.equals("organization")) { +// orderBy += ",showOrderOfDeptTree " + ascOrDesc + ",dept_id " + ascOrDesc; +// descOrderBy += ",showOrderOfDeptTree " + ascOrDesc1 + ",dept_id " + ascOrDesc1; +// } +// if (dataIndex.equalsIgnoreCase("dspOrder") || dataIndex.equalsIgnoreCase("lastName")) { +// orderBy += "," + dataIndex + " " + ascOrDesc + ",id " + ascOrDesc; +// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",id " + ascOrDesc1; +// } else if (dataIndex.equalsIgnoreCase("deptShowOrder") || dataIndex.equalsIgnoreCase("deptName")) { +// orderBy += "," + dataIndex + " " + ascOrDesc + ",dept_id " + ascOrDesc; +// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",dept_id " + ascOrDesc1; +// } else if (dataIndex.equalsIgnoreCase("subcomShowOrder") || dataIndex.equalsIgnoreCase("subcomName")) { +// orderBy += "," + dataIndex + " " + ascOrDesc + ",subcom_id " + ascOrDesc; +// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",subcom_id " + ascOrDesc1; +// } +// } +// orderBy = orderBy.startsWith(",") ? orderBy.substring(1) : orderBy; +// descOrderBy = descOrderBy.startsWith(",") ? descOrderBy.substring(1) : descOrderBy; +// orderBy = orderBy.equals("") ? " t.dspOrder,t.id " : orderBy; +// descOrderBy = descOrderBy.equals("") ? " t.dspOrder,t.id " : descOrderBy; +// orderBy = "order by "+orderBy; + + sql = backFields + sqlFrom + sqlWhere + groupBy; + + if (pageIndex > 0 && pageSize > 0) { + if (rs.getDBType().equals("oracle")) { + sql = " select * from (select " + sql+") t "+orderBy; + sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= " + + (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize); + } else if (rs.getDBType().equals("mysql")) { + sql = " select * from (select " + sql+") t "+orderBy; + sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize; + } + else if (rs.getDBType().equals("postgresql")) { + sql = " select * from (select " + sql+") t "+orderBy; + sql = "select t1.* from (" + sql + ") t1 limit " +pageSize + " offset " + ((pageIndex - 1) * pageSize); + } + else { + orderBy = " order by dsporder asc, lastname asc "; + descOrderBy = " order by dsporder desc, lastname desc "; + if (pageIndex > 1) { + int topSize = pageSize; + if (pageSize * pageIndex > count) { + topSize = count - (pageSize * (pageIndex - 1)); + } + sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top " + + (pageIndex * pageSize) + sql + orderBy+ " ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy; + } else { + sql = " select top " + pageSize + sql+orderBy; + } + } + } else { + sql = " select " + sql; + } + + + // #1475814-概述:满足考勤报分部部门显示及导出时显示全路径 + String fullPathMainKey = "show_full_path"; + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0"); + + String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源 + params.put("show_card_source",show_card_source); + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + params.put("uintType",uintType); + params.put("hoursToDay",hoursToDay); + Map flowData = kqReportBiz.getFlowData(params,user); + + + rs.execute(sql); + while (rs.next()) { + data = new HashMap<>(); + kqReportFieldComInfo.setTofirstRow(); + String id = rs.getString("id"); + data.put("resourceId",id); + while (kqReportFieldComInfo.next()){ + if(!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1"))continue; + if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))continue; + if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){ + continue; + } + String fieldName = kqReportFieldComInfo.getFieldname(); + String fieldValue = ""; + if(fieldName.equals("subcompany")){ + String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid")); + if(tmpSubcompanyId.length()==0){ + tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id)); + } + data.put("subcompanyId",tmpSubcompanyId); + + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") : + subCompanyComInfo.getSubCompanyname(tmpSubcompanyId); + + // fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId); + }else if(fieldName.equals("department")){ + String tmpDepartmentId = Util.null2String(rs.getString("departmentid")); + if(tmpDepartmentId.length()==0){ + tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id)); + } + data.put("departmentId",tmpDepartmentId); + + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") : + departmentComInfo.getDepartmentname(tmpDepartmentId); + + // fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId); + }else if(fieldName.equals("jobtitle")){ + String tmpJobtitleId = Util.null2String(rs.getString("jobtitle")); + if(tmpJobtitleId.length()==0){ + tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id)); + } + data.put("jobtitleId",tmpJobtitleId); + fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId); + }else if(fieldName.equals("attendanceSerial")){ + List serialIds = null; + if(attendanceSerial.length()>0){ + serialIds = Util.splitString2List(attendanceSerial,","); + } + for(int i=0;serialIds!=null&&i0) { + if(fieldValue.length() == 0){ + fieldValue="0"; + }else{ + if (kqReportFieldComInfo.getUnittype().equals("2")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + } + } + } + data.put(fieldName,fieldValue); + } + + //请假 + List> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if(("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = allLeaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = allLeaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + allLeaveRules.remove(i); + } + } + } + Map leaveRule = null; + for(int i=0;allLeaveRules!=null&&i)allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_"+leaveRule.get("id")); + String leaveData = Util.null2String(flowData.get(id+"|"+flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_"+leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+flowLeaveBackType)),"0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try{ + //以防止出现精度问题 + if(leaveData.length() == 0){ + leaveData = "0.0"; + } + if(leavebackData.length() == 0){ + leavebackData = "0.0"; + } + BigDecimal b_leaveData = new BigDecimal(leaveData); + BigDecimal b_leavebackData = new BigDecimal(leavebackData); + b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString(); + if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){ + b_flowLeaveData = "0.0"; + } + }catch (Exception e){ + writeLog("GetKQReportCmd:leaveData"+leaveData+":leavebackData:"+leavebackData+":"+e); + } + + //考虑下冻结的数据 + if(b_flowLeaveData.length() > 0){ + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData); + }else{ + flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData,0.0)-Util.getDoubleValue(leavebackData,0.0))); + } + data.put(flowType,flowLeaveData); + } + + Map amData = Maps.newHashMap(); + Map pmData = Maps.newHashMap(); + if(isKqReportHalfOpen) { + amData.putAll(data); + pmData.putAll(data); + } + + Map detialDatas = kqReportBiz.getDetialDatas(id,fromDate,toDate,user,flowData,false,uintType,show_card_source); +// new KQLog().info("id:"+id+":detialDatas:"+detialDatas); + String user_endDate = Util.null2String(resourceComInfo.getEndDate(id)); + String user_status = Util.null2String(resourceComInfo.getStatus(id)); + String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim(); + String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim(); + if(companyStartDate.length()!=10){ + companyStartDate = ""; + } + if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){ + begindate=companyStartDate; + } + isEnd = false; + for(String date=fromDate; !isEnd;) { + if(date.equals(toDate)) isEnd = true; + if(DateUtil.compDate(today, date)>0){ + if(isKqReportHalfOpen) { + amData.put(date,""); + pmData.put(date,""); + } else { + data.put(date,""); + } + }else{ + if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){ + //其他状态 + if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后 + if(isKqReportHalfOpen) { + amData.put(date,""); + pmData.put(date,""); + } else { + data.put(date,""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + } + if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准 + if(isKqReportHalfOpen) { + amData.put(date,""); + pmData.put(date,""); + } else { + data.put(date,""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + + if(isKqReportHalfOpen) { + Map tmpData = Maps.newHashMap(); + Object tmpValue = null; + if(detialDatas.get(id+"|"+date)==null){ + tmpValue = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + data.put(date,tmpValue); + amData.put(date,tmpValue); + pmData.put(date,tmpValue); + }else { + tmpData = (Map) detialDatas.get(id+"|"+date); + data.put(date,tmpData); + if(tmpData != null){ + tmpData.put("text",Util.null2String(tmpData.get("textAM"))); + + Map amTmpData = Maps.newHashMap(); + amTmpData.put("text",Util.null2String(tmpData.get("textAM"))); + Map pmTmpData = Maps.newHashMap(); + pmTmpData.put("text",Util.null2String(tmpData.get("textPM"))); + amData.put(date,amTmpData); + pmData.put(date,pmTmpData); + } + } + } else { + data.put(date,detialDatas.get(id+"|"+date)==null?SystemEnv.getHtmlLabelName(26593, user.getLanguage()):detialDatas.get(id+"|"+date)); + } + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + if(isKqReportHalfOpen) { + amData.put("rowSpan", "2"); + pmData.put("rowSpan", "0"); + datas.add(amData); + datas.add(pmData); + } else { + datas.add(data); + } + } + + List lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate); + retmap.put("holidays", lsHolidays); + + retmap.put("columns",columns); + retmap.put("datas",datas); + if(isKqReportHalfOpen) { + retmap.put("pagesize", pageSize*2); + retmap.put("count", count*2); + } else { + retmap.put("pagesize", pageSize); + retmap.put("count", count); + } + retmap.put("pageindex", pageIndex); + retmap.put("pagecount", pageCount); + retmap.put("ishavepre", isHavePre); + retmap.put("ishavenext", isHaveNext); + retmap.put("isKqReportHalfOpen", isKqReportHalfOpen); + }catch (Exception e){ + writeLog(e); + } + return retmap; + } + + private Map getChildColumnsInfo(String parentid, User user){ + Map returnMap = new HashMap<>(); + List lsChildColumns = new ArrayList<>(); + Map column = null; + int sumChildColumnWidth = 0; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + if(parentid.equals("attendanceSerial")){//考勤班次 + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + List serialIds = null; + if(Util.null2String(jsonObj.get("attendanceSerial")).length()>0){ + serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")),","); + } + for(int i=0;serialIds!=null&&i> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = leaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = leaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + leaveRules.remove(i); + } + } + } + for(int i=0;leaveRules!=null&&i leaveRule = leaveRules.get(i); + String id = "leaveType_"+Util.null2String(leaveRule.get("id")); + String name = Util.null2String(leaveRule.get("name")); + String unitType = Util.null2String(leaveRule.get("unitType")); + column = new HashMap(); + column.put("title", name); + column.put("unit", KQUnitBiz.isLeaveHour(unitType) ?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage())); + column.put("width", 65); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 2); + column.put("colSpan", 1); + column.put("showDetial","1"); + sumChildColumnWidth+=65; + lsChildColumns.add(column); + } + }else if(parentid.equals("overtime")){ + String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"}; + for(int i=0;i0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + column.put("unit", unitTypeName); + } + column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 1); + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List)mapChildColumnInfo.get("childColumns"); + if(childColumns.size()>0) {//跨列width取子列的width + column.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65); + } + column.put("width", childWidth+""); + sumChildColumnWidth+=childWidth; + lsChildColumns.add(column); + } + }else{ + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()){ + if(kqReportFieldComInfo.getParentid().equals(parentid)) { + if(!kqReportFieldComInfo.getReportType().equals("month"))continue; + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("rowSpan", 1); + column.put("colSpan", 1); + column.put("showDetial",kqReportFieldComInfo.getShowDetial()); + sumChildColumnWidth+=Util.getIntValue(kqReportFieldComInfo.getWidth()); + lsChildColumns.add(column); + } + } + } + returnMap.put("childColumns",lsChildColumns); + returnMap.put("sumChildColumnWidth",sumChildColumnWidth); + return returnMap; + } + + private List getCascadeKeyColumnsInfo(String cascadeKey, User user){ + List lsChildColumns = new ArrayList<>(); + if(Util.null2String(cascadeKey).length()==0){ + return lsChildColumns; + } + Map column = null; + List lsCascadeKey = Util.splitString2List(cascadeKey,","); + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + for(int i=0;i= ? and jbksrq >= ? and sqr = ?"; + RecordSet rs = new RecordSet(); + rs.executeQuery(sql,fromDate, toDate, userid); + + while (rs.next()) { + String workdate = rs.getString("jbksrq"); + boolean workDay = kqWorkTime.isWorkDay(userid, workdate); + boolean isHoliday = KQHolidaySetBiz.isHoliday(userid,workdate); + double dxsc = rs.getDouble("dxsc"); + dxsc = (double)Math.round(dxsc*100)/100; + BigDecimal bigDecimalDxsc = new BigDecimal(Double.toString(dxsc)); + if(workDay){ + if("1".equals(leaveType)){ + bigDecimal.subtract(bigDecimalDxsc); + } + }else if(isHoliday ){ + if("2".equals(leaveType)){ + bigDecimal.subtract(bigDecimalDxsc); + } + + }else { + if("3".equals(leaveType)){ + bigDecimal.subtract(bigDecimalDxsc); + } + + } + } + return bigDecimal.doubleValue(); + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + public static void main(String[] args) { + String s1 = String.format("%.2f", 1.2); + System.out.println(s1); + + } + +} diff --git a/src/weaver/interfaces/zw/utils/CommonUtil.java b/src/weaver/interfaces/zw/utils/CommonUtil.java new file mode 100644 index 0000000..c07e276 --- /dev/null +++ b/src/weaver/interfaces/zw/utils/CommonUtil.java @@ -0,0 +1,136 @@ +package weaver.interfaces.zw.utils; + +import weaver.general.BaseBean; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.Util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CommonUtil { + + /** + * + * @param sql + * @return + */ + public static List> queryListBySql(String sql){ + RecordSet rs = new RecordSet(); + BaseBean bb = new BaseBean(); + List> list = new ArrayList>(); + try{ + if(StringUtils.isNotBlank(sql)){ + Map map = new HashMap(); + rs.executeQuery(sql); + String[] column = rs.getColumnName(); + while (rs.next()){ + map = new HashMap(); + for(int i=0;i0){ + list.add(map); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog("queryListBySql-e:"+e); + } + return list; + } + + /*** + * + * @param sql + * @return + */ + public static Map queryMapBySql(String sql){ + RecordSet rs = new RecordSet(); + BaseBean bb = new BaseBean(); + Map map = new HashMap(); + try{ + if(StringUtils.isNotBlank(sql)){ + rs.executeQuery(sql); + String[] column = rs.getColumnName(); + if (rs.next()){ + for(int i=0;i> requestList = queryRequestList(billtable,cjrbm,pbyf,workflowid,requestid); + if(!requestList.isEmpty() && requestList.size() >0){ + requestInfo.getRequestManager().setMessageid("1000"); + requestInfo.getRequestManager().setMessagecontent("流程提交接口异常"); + return Action.FAILURE_AND_CONTINUE; + }else{ + List> scheduleList = queryScheduleData(billtable,mainid,pbyf); + if(!scheduleList.isEmpty() && scheduleList.size()>0){ + requestInfo.getRequestManager().setMessageid("1000"); + requestInfo.getRequestManager().setMessagecontent("流程提交接口异常"); + return Action.FAILURE_AND_CONTINUE; + }else{ + int daysInMonth = 0; + if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7){ + LocalDate date = LocalDate.parse(pbyf + "-01"); // 获取当前日期 + daysInMonth = date.lengthOfMonth(); // 获取本月有多少天 + } + bb.writeLog("----mainid------"+mainid); + if(StringUtils.isNotBlank(mainid)) + { + String groupid = getUserActiveGroupId(user.getUID()+""); + bb.writeLog("groupid:"+groupid); + + JSONObject datasJSON = new JSONObject(); + JSONArray datasArray = new JSONArray(); + sql = " select * from "+billtable+"_dt1 where mainid="+mainid; + List> dt1List = CommonUtil.queryListBySql(sql); + for(int i=0;i dt1Map = dt1List.get(i); + String resourceid = Util.null2String(dt1Map.get("yg")); + if(StringUtils.isNotBlank(resourceid)){ + JSONArray kqdata = new JSONArray(); + for(int k=1;k<=daysInMonth;k++){ + String bc = Util.null2String(dt1Map.get("bc"+k)); + JSONObject bcJSON = new JSONObject(); + bcJSON.put("id",""); + bcJSON.put("serialid",bc); + if(k<10){ + bcJSON.put("date",pbyf+"-0"+k); + }else{ + bcJSON.put("date",pbyf+"-"+k); + } + kqdata.add(bcJSON); + } + + JSONObject dataJSON = new JSONObject(); + dataJSON.put("resourceid",resourceid); + dataJSON.put("kqdata",kqdata); + datasArray.add(dataJSON); + } + } + + datasJSON.put("datas",datasArray); + datasJSON.put("groupId", groupid); + + bb.writeLog("data:"+datasJSON.toJSONString()); + + Map params = new HashMap(); + params.put("data",datasJSON.toJSONString()); + Map apidatas = getService(user).save(params, user); + + bb.writeLog("apidatas:"+ JSONObject.toJSONString(apidatas)); + + if(apidatas.containsKey("status")){ + String status = Util.null2String(apidatas.get("status")); + if(!"1".equals(status)){ + String message = Util.null2String(apidatas.get("message")); + requestInfo.getRequestManager().setMessageid("1000"); + requestInfo.getRequestManager().setMessagecontent(message); + return Action.FAILURE_AND_CONTINUE; + } + }else{ + requestInfo.getRequestManager().setMessageid("1000"); + requestInfo.getRequestManager().setMessagecontent("排班保存异常"); + return Action.FAILURE_AND_CONTINUE; + } + }else{ + requestInfo.getRequestManager().setMessageid("1000"); + requestInfo.getRequestManager().setMessagecontent("获取流程数据异常"); + return Action.FAILURE_AND_CONTINUE; + } + } + } + }catch (Exception e){ + requestInfo.getRequestManager().setMessageid("1000"); + requestInfo.getRequestManager().setMessagecontent("流程提交接口异常"); + return Action.FAILURE_AND_CONTINUE; + } + + return Action.SUCCESS; + } + + /** + * + * @param billtable + * @param mainid + * @return + */ + public List> queryScheduleData(String billtable,String mainid,String pbyf){ + + List> scheduleList = new ArrayList>(); + try { + String userids = "" ; + String sql = " select yg from "+billtable+"_dt1 where mainid="+mainid; + List> dt1List = CommonUtil.queryListBySql(sql); + for(int i=0;i dt1Map = dt1List.get(i); + String resourceid = Util.null2String(dt1Map.get("yg")); + userids += StringUtils.isBlank(userids) ? resourceid : ","+resourceid ; + } + if(StringUtils.isNotBlank(userids)){ + sql = " select kqdate,resourceid,serialid,groupid from kq_shiftschedule where left(kqdate,7) = '"+pbyf+"' and resourceid in("+userids+") and (isdelete is null or isdelete = 0)"; + scheduleList = CommonUtil.queryListBySql(sql); + } + + }catch (Exception e){ + + } + return scheduleList; + } + + /*** + * + * @param billtable + * @param cjrbm + * @param pbyf + * @param workflowid + * @param requestid + * @return + */ + public List> queryRequestList(String billtable,String cjrbm,String pbyf,String workflowid,String requestid){ + + List> requestList = new ArrayList>(); + try{ + String sql =" select t.id " + + " from "+billtable+" t " + + " inner join workflow_requestbase r on r.requestid = t.requestid " + + " where t.pbyf ='"+pbyf+"' " + + " and t.cjrbm ='"+cjrbm+"' " + + " and r.currentnodetype in(1,2,3) " + + " and r.workflowid = "+workflowid + + " and t.requestid <> "+requestid; + requestList = CommonUtil.queryListBySql(sql); + }catch (Exception e){ + + } + return requestList; + } + + + private KQShiftScheduleService getService(User user) { + return (KQShiftScheduleService) ServiceUtil.getService(KQShiftScheduleServiceImpl.class, user); + } + + + public String getUserActiveGroupId(String userid){ + BaseBean bb = new BaseBean(); + + KQGroupMemberComInfo kqGroupMemberComInfo = null; + KQGroupComInfo kqGroupComInfo = null ; + String activeGroupId = ""; + try{ + kqGroupMemberComInfo = new KQGroupMemberComInfo(); + kqGroupComInfo = new KQGroupComInfo(); + + Map> groupMemberMap = getUserGroup(); + + String activeGroup = ""; + if(groupMemberMap.containsKey(userid)){ + List groupIds = groupMemberMap.get(userid); + bb.writeLog("groupIds:"+groupIds.size()); + + for(String i : groupIds){ + String isDelete = kqGroupComInfo.getIsdelete(i); + if(!"1".equals(isDelete)) { + String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate())); + if (i.equals(currentGroupId)) { + activeGroupId = i; + } + } + } + } + }catch (Exception e){ + e.printStackTrace(); + bb.writeLog(e); + } + return activeGroupId; + } + + + /*** + * + * @return + */ + public Map> getUserGroup(){ + BaseBean bb = new BaseBean(); + Map> groupMemberMap = new HashMap<>(); + RecordSet rs = new RecordSet(); + String viewScope = "3"; + try { + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + Map groupParams = new HashMap(); + if("3".equals(viewScope)){ + groupParams.put("isNoAccount", "1"); + } + rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams)); + while (rs.next()) { + String id = rs.getString("resourceid"); + String gid = rs.getString("groupid"); + if (!groupMemberMap.containsKey(id)) + groupMemberMap.put(id, new ArrayList<>()); + groupMemberMap.get(id).add(gid); + } + } catch (Exception e) { + } + return groupMemberMap; + } + + + +}