From f81928788cff7ab9b8d107f82464246b5f2dea91 Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Wed, 14 May 2025 18:40:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E7=A0=81=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E4=BB=85=E4=BF=AE=E6=94=B9=20GetKqReportCmd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/kq/biz/KQGroupMemberComInfo.java | 1000 +++++ src/com/engine/kq/biz/KQReportBiz.java | 3669 +++++++++++++++++ .../engine/kq/biz/KQReportFieldComInfo.java | 239 ++ .../engine/kq/cmd/report/GetKQReportCmd.java | 20 +- .../SaveBatchShiftScheduleCmd.java | 694 +++- .../xmgsecond/entity/KqFormatTotal.java | 59 + .../engine/xmgsecond/util/KqCalulateUtil.java | 98 + 7 files changed, 5588 insertions(+), 191 deletions(-) create mode 100644 src/com/engine/kq/biz/KQGroupMemberComInfo.java create mode 100644 src/com/engine/kq/biz/KQReportBiz.java create mode 100644 src/com/engine/kq/biz/KQReportFieldComInfo.java create mode 100644 src/com/engine/xmgsecond/entity/KqFormatTotal.java create mode 100644 src/com/engine/xmgsecond/util/KqCalulateUtil.java diff --git a/src/com/engine/kq/biz/KQGroupMemberComInfo.java b/src/com/engine/kq/biz/KQGroupMemberComInfo.java new file mode 100644 index 0000000..6ce6b1e --- /dev/null +++ b/src/com/engine/kq/biz/KQGroupMemberComInfo.java @@ -0,0 +1,1000 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.entity.KQGroupEntity; +import com.engine.kq.log.KQLog; +import weaver.cache.*; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.StaticObj; +import weaver.general.Util; +import weaver.hrm.resource.ResourceComInfo; +import java.io.PrintWriter; +import java.io.Serializable; +import java.io.StringWriter; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class KQGroupMemberComInfo 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 group; + + private KQLog kqLog = new KQLog(); + + private boolean isFormat = false; + + @Override + protected boolean autoInitIfNotFound() { + return false; + } + + private StaticObj staticobj = null; + + @Override + public CacheItem initCache(String key) { + + if (key == null || "".equals(key.trim())) { + return null; + } + + RecordSet rs = new RecordSet(); + String sql = ""; + kqLog = new KQLog(); + ConcurrentHashMap resourceKQGroups = new ConcurrentHashMap<>(); + //考勤组优先级 + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + + String subcompanyid = Util.null2String(resourceComInfo.getSubCompanyID(key));//分部 + String departmentid = Util.null2String(resourceComInfo.getDepartmentID(key));//部门 + String jobtitle = Util.null2String(resourceComInfo.getJobTitle(key));//岗位 + + //人员 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.id=b.typevalue and b.type =1 and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1')" + + " and a.id = "+key+ + " order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + //部门 + if(departmentid.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b , kq_group c" + + " WHERE a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.departmentid = " + departmentid + + " and a.id="+key+ + " order by b.groupid desc"; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + } + + //分部 + if(subcompanyid.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.subcompanyid1 = " + subcompanyid + + " and a.id="+key+ + " order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + } + + //岗位 + if(jobtitle.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.jobtitle = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=5 " + + " AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))) " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.jobtitle = " + jobtitle + + " and a.id="+key+ + " order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + } + + //所有人 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE (b.type=6 AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto) and b.groupid=c.id " + + " and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.id = "+key+ + " order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + if(resourceKQGroups.size()>0){ + CacheItem cacheItem = createCacheItem(); + Iterator> iterator = resourceKQGroups.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + String id = entry.getKey(); + List value = entry.getValue(); + cacheItem.set(PK_INDEX, id); + cacheItem.set(group, value); + modifyCacheItem(key, cacheItem); + } + return cacheItem; + } + } catch (Exception e) { + kqLog.info(e); + } + return null; + } + + private void getHasValidateGroupInfo() { + RecordSet rs = new RecordSet(); + String backFields = " b.groupid, b.typevalue, b.validatefrom as validatefrom, b.validateto as validateto,b.seclevel as groupseclevel,b.seclevelto as groupseclevelto, b.jobtitlelevel as jobtitlelevel, b.jobtitlelevelvalue as jobtitlelevelvalue "; + String sqlWhere = " and ((validatefrom <>'"+KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE+"') or (validateto <>'"+KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE+"'))"; + //人员 + String sql = " SELECT "+backFields+" FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.id=b.typevalue and b.type =1 and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1')" + + sqlWhere + " order by b.groupid desc "; + rs.executeQuery(sql); +// rs.writeLog("sql:::::::::"+sql); + List userGroupList = null; + while (rs.next()) { + String param = "type#1#"+rs.getString("typevalue"); + String groupId = rs.getString("groupid"); + String validatefrom = Util.null2String(rs.getString("validatefrom"), KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); + String validateto = Util.null2String(rs.getString("validateto"), KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); + String valueParam = groupId+"#"+validatefrom+"#"+validateto; + if(staticobj.getObject("User&GroupMember") == null) { + userGroupList = new ArrayList<>(); + } else { + userGroupList = (List)staticobj.getRecordFromObj("User&GroupMember",param); + if(userGroupList == null) { + userGroupList = new ArrayList<>(); + } + } + if(!userGroupList.contains(valueParam)) { + userGroupList.add(valueParam); + staticobj.putRecordToObj("User&GroupMember",param,userGroupList); + } +// rs.writeLog("userGroupList:::::::::"+JSON.toJSONString(userGroupList)); + } + //部门 + sql = " SELECT "+backFields+" FROM HrmResource a, kq_groupmember b , kq_group c" + + " WHERE a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + sqlWhere + + " order by b.groupid desc"; + rs.executeQuery(sql); + List departGroupList = null; + while (rs.next()) { + String param = "type#3#"+rs.getString("typevalue"); + String groupId = rs.getString("groupid"); + String validatefrom = Util.null2String(rs.getString("validatefrom"), KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); + String validateto = Util.null2String(rs.getString("validateto"), KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); + String groupseclevel = Util.null2String(rs.getString("groupseclevel")); + String groupseclevelto = Util.null2String(rs.getString("groupseclevelto")); + String valueParam = groupId+"#"+validatefrom+"#"+validateto+"#"+groupseclevel+"#"+groupseclevelto; + if(staticobj.getObject("Department&GroupMember") == null) { + departGroupList = new ArrayList<>(); + } else { + departGroupList = (List)staticobj.getRecordFromObj("Department&GroupMember",param); + if(departGroupList == null) { + departGroupList = new ArrayList<>(); + } + } + if(!departGroupList.contains(valueParam)) { + departGroupList.add(valueParam); + staticobj.putRecordToObj("Department&GroupMember",param,departGroupList); + } + } + //分部 + sql = " SELECT "+backFields+" FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + sqlWhere + + " order by b.groupid desc "; + rs.executeQuery(sql); + List subCompanyGroupList = null; + while (rs.next()) { + String param = "type#2#"+rs.getString("typevalue"); + String groupId = rs.getString("groupid"); + String validatefrom = Util.null2String(rs.getString("validatefrom"), KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); + String validateto = Util.null2String(rs.getString("validateto"), KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); + String groupseclevel = Util.null2String(rs.getString("groupseclevel")); + String groupseclevelto = Util.null2String(rs.getString("groupseclevelto")); + String valueParam = groupId+"#"+validatefrom+"#"+validateto+"#"+groupseclevel+"#"+groupseclevelto; + if(staticobj.getObject("SubCompany&GroupMember") == null) { + subCompanyGroupList = new ArrayList<>(); + } else { + subCompanyGroupList = (List)staticobj.getRecordFromObj("SubCompany&GroupMember",param); + if(subCompanyGroupList == null) { + subCompanyGroupList = new ArrayList<>(); + } + } + if(!subCompanyGroupList.contains(valueParam)) { + subCompanyGroupList.add(valueParam); + staticobj.putRecordToObj("SubCompany&GroupMember",param,subCompanyGroupList); + } + } + //岗位 + sql = " SELECT "+backFields+" FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.jobtitle = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=5 " + + " AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))) " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + sqlWhere + + " order by b.groupid desc "; + rs.executeQuery(sql); + List jobtitleGroupList = null; + while (rs.next()) { + String param = "type#5#"+rs.getString("typevalue"); + String groupId = rs.getString("groupid"); + String validatefrom = Util.null2String(rs.getString("validatefrom"), KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); + String validateto = Util.null2String(rs.getString("validateto"), KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); + String groupseclevel = Util.null2String(rs.getString("groupseclevel")); + String groupseclevelto = Util.null2String(rs.getString("groupseclevelto")); + String jobtitlelevel = Util.null2String(rs.getString("jobtitlelevel")); + jobtitlelevel = "".equals(jobtitlelevel) ? "-1" : jobtitlelevel; + String jobtitlelevelvalue = Util.null2String(rs.getString("jobtitlelevelvalue")); + jobtitlelevelvalue = "".equals(jobtitlelevelvalue) ? "-1" : ","+jobtitlelevelvalue+","; + String valueParam = groupId+"#"+validatefrom+"#"+validateto+"#"+groupseclevel+"#"+groupseclevelto+"#"+jobtitlelevel+"#"+jobtitlelevelvalue; + if(staticobj.getObject("Jobtitle&GroupMember") == null) { + jobtitleGroupList = new ArrayList<>(); + } else { + jobtitleGroupList = (List)staticobj.getRecordFromObj("Jobtitle&GroupMember",param); + if(jobtitleGroupList == null) { + jobtitleGroupList = new ArrayList<>(); + } + } + if(!jobtitleGroupList.contains(valueParam)) { + jobtitleGroupList.add(valueParam); + staticobj.putRecordToObj("Jobtitle&GroupMember",param,jobtitleGroupList); + } + } + //所有人 + sql = " SELECT "+backFields+" FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE (b.type=6 AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto) and b.groupid=c.id " + + " and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + sqlWhere + + " order by b.groupid desc "; + rs.executeQuery(sql); + rs.executeQuery(sql); + List allGroupList = null; + while (rs.next()) { + String param = "type#6#"+rs.getString("typevalue"); + String groupId = rs.getString("groupid"); + String validatefrom = Util.null2String(rs.getString("validatefrom"), KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); + String validateto = Util.null2String(rs.getString("validateto"), KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); + String groupseclevel = Util.null2String(rs.getString("groupseclevel")); + String groupseclevelto = Util.null2String(rs.getString("groupseclevelto")); + String valueParam = groupId+"#"+validatefrom+"#"+validateto+"#"+groupseclevel+"#"+groupseclevelto; + if(staticobj.getObject("All&GroupMember") == null) { + allGroupList = new ArrayList<>(); + } else { + allGroupList = (List)staticobj.getRecordFromObj("All&GroupMember",param); + if(allGroupList == null) { + allGroupList = new ArrayList<>(); + } + } + if(!allGroupList.contains(valueParam)) { + allGroupList.add(valueParam); + staticobj.putRecordToObj("All&GroupMember",param,allGroupList); + } + } + } + + @Override + public CacheMap initCache() { +// writeLog("KQGroupMemberComInfo::::::in:::::::2222::::::"); + staticobj = StaticObj.getInstance(); + staticobj.removeObject("User&GroupMember"); + staticobj.removeObject("Department&GroupMember"); + staticobj.removeObject("SubCompany&GroupMember"); + staticobj.removeObject("Jobtitle&GroupMember"); + staticobj.removeObject("All&GroupMember"); + getHasValidateGroupInfo(); + + CacheMap localData = createCacheMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + kqLog = new KQLog(); + ConcurrentHashMap resourceKQGroups = new ConcurrentHashMap<>(); + //考勤组优先级 + try { + //人员 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.id=b.typevalue and b.type =1 and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + //部门 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b , kq_group c" + + " WHERE a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') order by b.groupid desc"; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + //分部 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + //岗位 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.jobtitle = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=5 " + + " AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))) " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + //所有人 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE (b.type=6 AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto) and b.groupid=c.id " + + " and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') order by b.groupid desc "; + rs.executeQuery(sql); + while (rs.next()) { + setMemberGroup(resourceKQGroups, rs.getString("resourceid"), rs.getString("groupid")); + } + + if(resourceKQGroups.size()>0) { + Iterator> iterator = resourceKQGroups.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + String id = entry.getKey(); + List value = entry.getValue(); + CacheItem cacheItem = createCacheItem(); + cacheItem.set(PK_INDEX, id); + cacheItem.set(group, value); + modifyCacheItem(id, cacheItem); + localData.put(id, cacheItem); + } + } + } catch (Exception e) { + kqLog.writeLog(e); + } + return localData; + } + + private void setMemberGroup(ConcurrentHashMap resourceKQGroups, String resourceid, String groupid) { + try { + List kqGroups = null; + if (resourceKQGroups.get(resourceid) == null) { + kqGroups = new ArrayList<>(); + } else { + kqGroups = (List) resourceKQGroups.get(resourceid); + } + kqGroups.add(groupid); + resourceKQGroups.put(resourceid, kqGroups); + } catch (Exception e) { + kqLog.info(e); + } + } + + public String getKQGroupId(String userId) { + String workDate = DateUtil.getCurrentDate(); + return getKQGroupId(userId, workDate); + } + + /** + * 根据user获取考勤组id + * + * @param userId + * @return + */ + public String getKQGroupId(String userId, String workDate) { + return getKQGroupId(userId, workDate, true); + } + + /** + * 是否在考勤组的有效期范围内 + * @param tmpGroupId + * @param workDate + * @return + */ + private boolean isInKqGroupValidate(String tmpGroupId, String workDate) { + boolean flag = true; + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + String kqtype = kqGroupComInfo.getKqtype(tmpGroupId); + String validity = kqGroupComInfo.getValidity(tmpGroupId); + String validityfromdate = kqGroupComInfo.getValidityfromdate(tmpGroupId); + String validityenddate = kqGroupComInfo.getValidityenddate(tmpGroupId); + if (validity.equals("1")) { + if (!DateUtil.isInDateRange(workDate, validityfromdate, validityenddate)) { + flag = false; + } + } + return flag; + } + /*** + * 根据user获取考勤组id + * @param userId + * @param workDate + * @param containFixed 取不到排班取固定班 + * @return + */ + public String getKQGroupId(String userId, String workDate, boolean containFixed) { + String groupId = ""; + Map> allKqGroupsExceptSql = new HashMap<>(); + List kqGroups = getGroupBefore(userId, workDate, allKqGroupsExceptSql); + if(kqGroups.size() > 0) { + String tmpGroupId = kqGroups.get(0); + if(isInKqGroupValidate(tmpGroupId, workDate)) { + return tmpGroupId; + } + } + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + List lsGroupIds = this.getKQGroups(userId, workDate); + lsGroupIds.removeIf(allKqGroupsExceptSql::containsKey); + for (int i = 0; i < lsGroupIds.size(); i++) { + String tmpGroupId = Util.null2String((String) lsGroupIds.get(i)); + if(isInKqGroupValidate(tmpGroupId, workDate)) { + groupId = tmpGroupId; + } else { + continue; + } + String kqtype = kqGroupComInfo.getKqtype(tmpGroupId); +// String validity = kqGroupComInfo.getValidity(tmpGroupId); +// String validityfromdate = kqGroupComInfo.getValidityfromdate(tmpGroupId); +// String validityenddate = kqGroupComInfo.getValidityenddate(tmpGroupId); +// if (validity.equals("1")) { +// if (DateUtil.isInDateRange(workDate, validityfromdate, validityenddate)) { +// groupId = tmpGroupId; +// }else{ +// //超过有效期 +// continue; +// } +// } else { +// groupId = tmpGroupId; +// } + + //考勤组如果排班为空,取下一个考勤组 + if (groupId.length() > 0) { + if (containFixed && kqtype.equals("2")) { + KQShiftScheduleComInfo kqShiftScheduleComInfo = new KQShiftScheduleComInfo(); + kqShiftScheduleComInfo.setShiftGroupId(Util.getIntValue(groupId)); + if (Util.null2String(kqShiftScheduleComInfo.getSerialId(userId, workDate)).length() > 0 && + Util.null2String(kqShiftScheduleComInfo.getGroupId(userId, workDate)).equals(groupId)) { + break; + } + } else { + break; + } + } + } + return groupId; + } + + public List getKQGroups(String userId, String kqDate) { +// if(!this.isFormat){ +// return (List) getObjValue(group, userId); +// } + RecordSet rs = new RecordSet(); + String sql = ""; + kqLog = new KQLog(); + List kqGroups = new ArrayList<>(); +// Map> allKqGroupsExceptSql = new HashMap<>(); + //考勤组优先级 + try { +// Map> sqlWhereMap = sqlWhereMap(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); +// kqGroups = getGroupBefore(userId, kqDate, allKqGroupsExceptSql); +// if(kqGroups.size() > 0) { +// return kqGroups; +// } + String subcompanyid = Util.null2String(resourceComInfo.getSubCompanyID(userId));//分部 + String departmentid = Util.null2String(resourceComInfo.getDepartmentID(userId));//部门 + String jobtitle = Util.null2String(resourceComInfo.getJobTitle(userId));//岗位 + String sqlWhere = " and ('"+kqDate+"' between b.validatefrom and b.validateto) "; +// if(rs.getDBType().equalsIgnoreCase("oracle")) { +// sqlWhere = " and ('"+kqDate+"' between nvl(b.validatefrom,'2000-01-01') and nvl(b.validateto,'2999-12-31')) "; +// }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ +// sqlWhere = " and ('"+kqDate+"' between ifnull(b.validatefrom,'2000-01-01') and ifnull(b.validateto,'2999-12-31')) "; +// }else { +// sqlWhere = " and ('"+kqDate+"' between isnull(b.validatefrom,'2000-01-01') and isnull(b.validateto,'2999-12-31')) "; +// } + + //人员 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.id=b.typevalue and b.type =1 and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1')" + + " and a.id = ?"+sqlWhere+ + " order by b.groupid desc "; + rs.executeQuery(sql,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + + //部门 + if(departmentid.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b , kq_group c" + + " WHERE a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.departmentid = ? "+ + " and a.id= ? "+sqlWhere+ + " order by b.groupid desc"; + rs.executeQuery(sql,departmentid,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } + + //分部 + if(subcompanyid.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.subcompanyid1 = ? " + + " and a.id= ? "+sqlWhere+ + " order by b.groupid desc "; + rs.executeQuery(sql,subcompanyid,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } + + //岗位 + if(jobtitle.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.jobtitle = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=5 " + + " AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))) " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.jobtitle = ? " + + " and a.id= ? "+sqlWhere+ + " order by b.groupid desc "; + rs.executeQuery(sql,jobtitle,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } + + //所有人 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE (b.type=6 AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto) and b.groupid=c.id " + + " and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.id = ? "+sqlWhere+ + " order by b.groupid desc "; + rs.executeQuery(sql,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } catch (Exception e) { + kqLog.info(e); + } +// kqGroups.removeIf(allKqGroupsExceptSql::containsKey); + return kqGroups; + } + + /** + * 如果设置了有效期,且查询在有效期范围内的,直接用 + * @return + */ + private List getGroupBefore(String userId, String kqDate, Map> allKqGroupsExceptSql) { + StaticObj groupMemberStaticObj = StaticObj.getInstance(); + RecordSet rs = new RecordSet(); + List kqGroups = new ArrayList<>(); + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subcompanyid = Util.null2String(resourceComInfo.getSubCompanyID(userId));//分部 + String departmentid = Util.null2String(resourceComInfo.getDepartmentID(userId));//部门 + String jobtitle = Util.null2String(resourceComInfo.getJobTitle(userId));//岗位 + // 人员 + String param = "type#1#"+userId; + if(groupMemberStaticObj.getObject("User&GroupMember") != null) { + List userGroupList = (List)groupMemberStaticObj.getRecordFromObj("User&GroupMember",param); +// writeLog("userGroupList::::"+ JSON.toJSONString(userGroupList)); + if(userGroupList != null) { + for (String userGourp : userGroupList) { + String groupId = userGourp.split("#")[0]; + handle(allKqGroupsExceptSql, groupId, userId, "resourceId"); + String validateFrom = userGourp.split("#")[1]; + String validateTo = userGourp.split("#")[2]; + if (kqDate.compareTo(validateFrom) >= 0 && kqDate.compareTo(validateTo) <= 0) { + kqGroups.add(groupId); + } + } + if (kqGroups.size() > 0) { + return kqGroups; + } + } + } + //部门 + if (departmentid.length() > 0) { + param = "type#3#" + departmentid; + if (groupMemberStaticObj.getObject("Department&GroupMember") != null) { + List departGroupList = (List) groupMemberStaticObj.getRecordFromObj("Department&GroupMember", param); +// writeLog("departGroupList::::" + JSON.toJSONString(departGroupList)); + if (departGroupList != null) { + for (String departGroup : departGroupList) { + String groupId = departGroup.split("#")[0]; + String validateFrom = departGroup.split("#")[1]; + String validateTo = departGroup.split("#")[2]; + String groupseclevel = departGroup.split("#")[3]; + String groupseclevelto = departGroup.split("#")[4]; + int userSeclevel = Util.getIntValue(resourceComInfo.getSeclevel(userId)); + if (kqDate.compareTo(validateFrom) >= 0 && kqDate.compareTo(validateTo) <= 0 && userSeclevel>=Util.getIntValue(groupseclevel) + && userSeclevel<=Util.getIntValue(groupseclevelto)) { + if (allKqGroupsExceptSql.containsKey(groupId)) { + continue; + } + handle(allKqGroupsExceptSql, groupId, departmentid, "departmentId"); + kqGroups.add(groupId); + } + } + } + if (kqGroups.size() > 0) { + return kqGroups; + } + } + } + + //分部 + if (subcompanyid.length() > 0) { + param = "type#2#" + subcompanyid; + if (groupMemberStaticObj.getObject("SubCompany&GroupMember") != null) { + List subCompanyGroupList = (List) groupMemberStaticObj.getRecordFromObj("SubCompany&GroupMember", param); +// writeLog("subCompanyGroupList::::" + JSON.toJSONString(subCompanyGroupList)); + if (subCompanyGroupList != null) { + for (String subCompanyGroup : subCompanyGroupList) { + String groupId = subCompanyGroup.split("#")[0]; + String validateFrom = subCompanyGroup.split("#")[1]; + String validateTo = subCompanyGroup.split("#")[2]; + String groupseclevel = subCompanyGroup.split("#")[3]; + String groupseclevelto = subCompanyGroup.split("#")[4]; + int userSeclevel = Util.getIntValue(resourceComInfo.getSeclevel(userId)); + if (kqDate.compareTo(validateFrom) >= 0 && kqDate.compareTo(validateTo) <= 0 && userSeclevel>=Util.getIntValue(groupseclevel) + && userSeclevel<=Util.getIntValue(groupseclevelto)) { + if (allKqGroupsExceptSql.containsKey(groupId)) { + continue; + } + handle(allKqGroupsExceptSql, groupId, subcompanyid, "subcompanyId"); + kqGroups.add(groupId); + } + } + } + if (kqGroups.size() > 0) { + return kqGroups; + } + } + } + + //岗位 + if (jobtitle.length() > 0) { + param = "type#5#" + jobtitle; + if (groupMemberStaticObj.getObject("Jobtitle&GroupMember") != null) { + List jobtitleGroupList = (List) groupMemberStaticObj.getRecordFromObj("Jobtitle&GroupMember", param); +// writeLog("jobtitleGroupList::::" + JSON.toJSONString(jobtitleGroupList)); + if (jobtitleGroupList != null) { + for (String jobtitleGroup : jobtitleGroupList) { + String groupId = jobtitleGroup.split("#")[0]; + String validateFrom = jobtitleGroup.split("#")[1]; + String validateTo = jobtitleGroup.split("#")[2]; + String groupseclevel = jobtitleGroup.split("#")[3]; + String groupseclevelto = jobtitleGroup.split("#")[4]; + String jobtitlelevel = jobtitleGroup.split("#")[5]; + String jobtitlelevelvalue = jobtitleGroup.split("#")[6]; + int userSeclevel = Util.getIntValue(resourceComInfo.getSeclevel(userId)); + if("2".equals(jobtitlelevel)) { // 分部 + String subcompanyId = ","+resourceComInfo.getSubCompanyID(userId)+","; + if(!jobtitlelevelvalue.contains(subcompanyId)) { + continue; + } + } else if("3".equals(jobtitlelevel)) { // 部门 + String departmentId = ","+resourceComInfo.getDepartmentID(userId)+","; + if(!jobtitlelevelvalue.contains(departmentId)) { + continue; + } + } + if (kqDate.compareTo(validateFrom) >= 0 && kqDate.compareTo(validateTo) <= 0 && userSeclevel>=Util.getIntValue(groupseclevel) + && userSeclevel<=Util.getIntValue(groupseclevelto)) { + if (allKqGroupsExceptSql.containsKey(groupId)) { + continue; + } + handle(allKqGroupsExceptSql, groupId, jobtitle, "jobtitleId"); + kqGroups.add(groupId); + } + } + } + if (kqGroups.size() > 0) { + return kqGroups; + } + } + } + + //所有人 + param = "type#6#0"; + if (groupMemberStaticObj.getObject("All&GroupMember") != null) { + List allGroupList = (List) groupMemberStaticObj.getRecordFromObj("All&GroupMember", param); +// writeLog("allGroupList::::" + JSON.toJSONString(allGroupList)); + if (allGroupList != null) { + for (String allGroup : allGroupList) { + String groupId = allGroup.split("#")[0]; + String validateFrom = allGroup.split("#")[1]; + String validateTo = allGroup.split("#")[2]; + String groupseclevel = allGroup.split("#")[3]; + String groupseclevelto = allGroup.split("#")[4]; + int userSeclevel = Util.getIntValue(resourceComInfo.getSeclevel(userId)); + if (kqDate.compareTo(validateFrom) >= 0 && kqDate.compareTo(validateTo) <= 0 && userSeclevel>=Util.getIntValue(groupseclevel) + && userSeclevel<=Util.getIntValue(groupseclevelto)) { + if (allKqGroupsExceptSql.containsKey(groupId)) { + continue; + } + handle(allKqGroupsExceptSql, groupId, "0", "all"); + kqGroups.add(groupId); + } + } + if (kqGroups.size() > 0) { + return kqGroups; + } + } + } + }catch (Exception e) { + writeLog(e); + } + return kqGroups; + } + + private Map> sqlWhereMap() { + // 先把所有的groupid找到 + RecordSet rs = new RecordSet(); + Map> allKqGroupsExceptSql = new HashMap<>(); + String sql = "select * from kq_groupmember where (isDelete is null or isDelete<>1)"; + rs.executeQuery(sql); + while (rs.next()) { + String groupId = rs.getString("id"); + int groupType = rs.getInt("type"); + String groupTypeValue = rs.getString("typevalue"); + + switch (groupType) { + case 1: + handle(allKqGroupsExceptSql, groupId, groupTypeValue, "resourceId"); + break; + case 2: + handle(allKqGroupsExceptSql, groupId, groupTypeValue, "subcompanyId"); + break; + case 3: + handle(allKqGroupsExceptSql, groupId, groupTypeValue, "departmentId"); + break; + case 5: + handle(allKqGroupsExceptSql, groupId, groupTypeValue, "jobTitleId"); + break; + case 6: + handle(allKqGroupsExceptSql, groupId, groupTypeValue, "all"); + break; + default: + break; + } + + } + return allKqGroupsExceptSql; + } + + private void handle(Map> allKqGroupsExceptSql, String groupId, String groupTypeValue, String key) { + Map sqlWhereMap = null; + String sqlWhereValue = groupTypeValue; + if(allKqGroupsExceptSql.containsKey(groupId)) { + sqlWhereMap = allKqGroupsExceptSql.get(groupId); + if (sqlWhereMap.containsKey(key)) { + sqlWhereValue = sqlWhereMap.get(key) + "," + groupTypeValue; + } + } else { + sqlWhereMap = new HashMap<>(); + } + sqlWhereMap.put(key, sqlWhereValue); + allKqGroupsExceptSql.put(groupId, sqlWhereMap); + } + /** + * 根据user获取所有考勤组 + * + * @param userId + * @return + */ + private List getKQGroups(String userId) { + if(!this.isFormat){ + return (List) getObjValue(group, userId); + } + RecordSet rs = new RecordSet(); + String sql = ""; + kqLog = new KQLog(); + List kqGroups = new ArrayList<>(); + //考勤组优先级 + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + + String subcompanyid = Util.null2String(resourceComInfo.getSubCompanyID(userId));//分部 + String departmentid = Util.null2String(resourceComInfo.getDepartmentID(userId));//部门 + String jobtitle = Util.null2String(resourceComInfo.getJobTitle(userId));//岗位 + + //人员 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.id=b.typevalue and b.type =1 and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1')" + + " and a.id = ?"+ + " order by b.groupid desc "; + rs.executeQuery(sql,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + + //部门 + if(departmentid.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b , kq_group c" + + " WHERE a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.departmentid = ? "+ + " and a.id= ? "+ + " order by b.groupid desc"; + rs.executeQuery(sql,departmentid,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } + + //分部 + if(subcompanyid.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.subcompanyid1 = ? " + + " and a.id= ? "+ + " order by b.groupid desc "; + rs.executeQuery(sql,subcompanyid,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } + + //岗位 + if(jobtitle.length()>0) { + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE a.jobtitle = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=5 " + + " AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))) " + + " and b.groupid=c.id and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.jobtitle = ? " + + " and a.id= ? "+ + " order by b.groupid desc "; + rs.executeQuery(sql,jobtitle,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } + + //所有人 + sql = " SELECT distinct a.id AS resourceid, b.groupid, a.status FROM HrmResource a, kq_groupmember b, kq_group c " + + " WHERE (b.type=6 AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto) and b.groupid=c.id " + + " and (c.isdelete is null or c.isdelete <> '1') and (b.isdelete is null or b.isdelete <> '1') " + + " and a.id = ? "+ + " order by b.groupid desc "; + rs.executeQuery(sql,userId); + while (rs.next()) { + kqGroups.add(rs.getString("groupid")); + } + } catch (Exception e) { + kqLog.info(e); + } + return kqGroups; + } + + /** + * 根据user获取所有考勤组id + * + * @param userId + * @return + */ + public String getKQGroupIds(String userId) { + String groupId = ""; + String kqDate = DateUtil.getCurrentDate(); + List lsGroupIds = this.getKQGroups(userId, kqDate); + if (lsGroupIds != null) { + groupId = String.join(",", lsGroupIds); + } + return groupId; + } + + public String getKQGroupIds(String userId, String kqDate) { + String groupId = ""; + List lsGroupIds = this.getKQGroups(userId, kqDate); + if (lsGroupIds != null) { + groupId = String.join(",", lsGroupIds); + } + return groupId; + } + + + public KQGroupEntity getUserKQGroupInfo(String userId) { + String workDate = DateUtil.getCurrentDate(); + return getUserKQGroupInfo(userId, workDate); + } + + /** + * 获取考勤组相关信息 + * + * @param userId + * @return + */ + public KQGroupEntity getUserKQGroupInfo(String userId, String workDate) { + return getUserKQGroupInfo(userId, workDate, true); + } + + /*** + * 获取考勤组相关信息 + * @param userId + * @param workDate + * @param containFixed 取不到排班取固定班 + * @return + */ + public KQGroupEntity getUserKQGroupInfo(String userId, String workDate, boolean containFixed) { + KQGroupEntity kqGroupEntity = null; + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + try { + String groupid = Util.null2String(this.getKQGroupId(userId, workDate, containFixed)); + if (groupid.length() > 0) { + kqGroupEntity = new KQGroupEntity(); + kqGroupEntity.setId(groupid); + kqGroupEntity.setGroupname(kqGroupComInfo.getGroupname(groupid)); + kqGroupEntity.setExcludeid(kqGroupComInfo.getExcludeid(groupid)); + kqGroupEntity.setSubcompanyid(kqGroupComInfo.getSubcompanyid(groupid)); + kqGroupEntity.setKqtype(kqGroupComInfo.getKqtype(groupid)); + kqGroupEntity.setSerialids(kqGroupComInfo.getSerialids(groupid)); + kqGroupEntity.setWeekday(kqGroupComInfo.getWeekday(groupid)); + kqGroupEntity.setSignstart(kqGroupComInfo.getSignstart(groupid)); + kqGroupEntity.setWorkhour(kqGroupComInfo.getWorkhour(groupid)); + kqGroupEntity.setIsdelete(kqGroupComInfo.getIsdelete(groupid)); + kqGroupEntity.setSignintype(kqGroupComInfo.getSignintype(groupid)); + kqGroupEntity.setIpscope(kqGroupComInfo.getIpscope(groupid)); + kqGroupEntity.setLocationcheck(kqGroupComInfo.getLocationcheck(groupid)); + kqGroupEntity.setLocationcheckscope(kqGroupComInfo.getLocationcheckscope(groupid)); + kqGroupEntity.setWificheck(kqGroupComInfo.getWificheck(groupid)); + kqGroupEntity.setOutsidesign(kqGroupComInfo.getOutsidesign(groupid)); + kqGroupEntity.setOutsignapprove(kqGroupComInfo.getOutsignApprove(groupid)); + kqGroupEntity.setCalmethod(kqGroupComInfo.getCalmethod(groupid)); + kqGroupEntity.setLocationshowaddress(kqGroupComInfo.getLocationshowaddress(groupid)); + kqGroupEntity.setAbnormalremind(kqGroupComInfo.getAbnormalremind(groupid)); + } + } catch (Exception e) { + kqLog.info(e); + } + return kqGroupEntity; + } + + public void removeCache() { + super.removeCache(); + + } + + public void setIsFormat(boolean isFormat){ + this.isFormat = isFormat; + } +} \ No newline at end of file diff --git a/src/com/engine/kq/biz/KQReportBiz.java b/src/com/engine/kq/biz/KQReportBiz.java new file mode 100644 index 0000000..ede4627 --- /dev/null +++ b/src/com/engine/kq/biz/KQReportBiz.java @@ -0,0 +1,3669 @@ +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()); + } + 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) { + //上午 + 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()); + } + 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) { + //上午 + 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()); + } + 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 (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) { + 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; + } + } + } + } + } + } + } + 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){ + 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)){ + 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) { + 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(); + } + } + + public static String splitParamStr(String params) { + StringBuilder inClauseValues = new StringBuilder(); + String[] paramStr = params.split(","); + if(params.contains(",")) { + for (int i = 0; i < paramStr.length; i++) { + inClauseValues.append("?"); + if (i < paramStr.length - 1) { + inClauseValues.append(","); + } + } + } else { + inClauseValues.append("?"); + } + return inClauseValues.toString(); + } + + + //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/KQReportFieldComInfo.java b/src/com/engine/kq/biz/KQReportFieldComInfo.java new file mode 100644 index 0000000..a637ec7 --- /dev/null +++ b/src/com/engine/kq/biz/KQReportFieldComInfo.java @@ -0,0 +1,239 @@ +package com.engine.kq.biz; + +import weaver.cache.*; +import weaver.conn.RecordSet; +import weaver.general.Util; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 报表自定义字段 + */ +public class KQReportFieldComInfo extends CacheBase{ + protected static String TABLE_NAME = "kq_report_field"; + /** sql中的where信息,不要以where开始 */ + protected static String TABLE_WHERE = null; + /** sql中的order by信息,不要以order by开始 */ + protected static String TABLE_ORDER = "showorder"; + + @PKColumn(type = CacheColumnType.NUMBER) + protected static String PK_NAME = "id"; + + @CacheColumn(name = "fieldname") + protected static int fieldname; + + @CacheColumn(name = "fieldlabel") + protected static int fieldlabel; + + @CacheColumn(name = "unittype") + protected static int unittype; + + @CacheColumn(name = "width") + protected static int width; + + @CacheColumn(name = "parentid") + protected static int parentid; + + @CacheColumn(name = "isdefinedcolumn") + protected static int isdefinedcolumn; + + @CacheColumn(name = "defaultshow") + protected static int defaultshow; + + @CacheColumn(name = "isleavetype") + protected static int isleavetype; + + @CacheColumn(name = "reporttype") + protected static int reporttype; + + @CacheColumn(name = "reporttype1") + protected static int reporttype1; + + @CacheColumn(name = "isdataColumn") + protected static int isdataColumn; + + @CacheColumn(name = "showDetial") + protected static int showDetial; + + @CacheColumn(name = "groupid") + protected static int groupid; + + @CacheColumn(name = "isenable") + protected static int isenable; + + // #1276494 概述:满足薪酬指标项关联考勤报表列数据需求 By T.W + @CacheColumn(name = "if_salary_need") + protected static int ifSalaryNeed; + + @CacheColumn(name = "formula") + protected static int formula; + + @CacheColumn(name = "issystem") + protected static int issystem; + + @CacheColumn(name = "cascadekey") + protected static int cascadekey; + + @CacheColumn(name = "dailyShowOrder") + protected static int dailyShowOrder; + + public static ConcurrentHashMap cascadekey2fieldname = new ConcurrentHashMap(); + public static ConcurrentHashMap field2Id = new ConcurrentHashMap(); + + @Override + protected CacheMap initCache() throws Exception { + CacheMap localData = createCacheMap(); + RecordSet rs = new RecordSet(); + cascadekey2fieldname.clear(); + field2Id.clear(); +// String sql = " select a.id,fieldname,fieldlabel,width,unittype,parentid,isdefinedcolumn,defaultshow,isleavetype," + +// " reporttype,isdatacolumn,showdetial,a.showorder,groupid,isenable,formula,issystem,cascadekey " + +// " from kq_report_field a left join kq_report_field_group b on a.groupid = b.id " + +// " order by b.showorder asc, a.showorder asc "; + + // #1276494 概述:满足薪酬指标项关联考勤报表列数据需求 By T.W + String sql = " SELECT id, fieldname,fieldlabel, unittype,width,parentid,isdefinedcolumn,defaultshow,isleavetype,'month' as reporttype, reporttype as reporttype1,isdataColumn," + + " showDetial,groupid,isenable,if_salary_need,formula,issystem,cascadekey,dailyShowOrder FROM kq_report_field where fieldname= 'lastname' "; + rs.executeQuery(sql); + while (rs.next()) { + if(Util.null2String(rs.getString("cascadekey")).length()>0){ + String[] arrCascadekey = Util.splitString(rs.getString("cascadekey"),","); + for(int i=0;i0){ + String[] arrCascadekey = Util.splitString(rs.getString("cascadekey"),","); + for(int i=0;i> { List childColumns = null; KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); while (kqReportFieldComInfo.next()){ + //QC3685035 考勤汇总表去除严重迟到,严重早退(+对应时长)4列 + if ("graveBeLate".equals(kqReportFieldComInfo.getFieldname())) continue; + if ("graveLeaveEarly".equals(kqReportFieldComInfo.getFieldname())) continue; + if ("graveBeLateMins".equals(kqReportFieldComInfo.getFieldname())) continue; + if ("graveLeaveEarlyMins".equals(kqReportFieldComInfo.getFieldname())) continue; + if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue; if(kqReportFieldComInfo.getFieldname().equals("kqCalendar"))continue; if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue; @@ -398,7 +406,17 @@ public class GetKQReportCmd extends AbstractCommonCommand> { } data.put("jobtitleId",tmpJobtitleId); fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId); - }else if(fieldName.equals("rlzqqxs")){ + }else if("kqGroup".equals(fieldName)){ + //QC3685035 考勤月度报表增加所属所属考勤组 + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(id, toDate); + fieldValue = kqGroupComInfo.getGroupname(groupId); + }else if("absenteeismDays".equals(fieldName)){ + //QC3685035 考勤月度报表增加缺勤天数 + List kqFormatTotalList = KqCalulateUtil.abnormalAttendance(id, fromDate, toDate); + fieldValue = String.format("%.1f", kqFormatTotalList.stream().mapToDouble(KqFormatTotal::getAbsenceDays).sum()); + } else if(fieldName.equals("rlzqqxs")){ String rlzqqxsTime = getXcqts(fromDate,id); fieldValue = rlzqqxsTime; }else if(fieldName.equals("attendanceSerial")){ diff --git a/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java b/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java index cffd6f7..b78f4c7 100644 --- a/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java +++ b/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java @@ -1,17 +1,25 @@ package com.engine.kq.cmd.shiftschedule; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.engine.common.biz.AbstractCommonCommand; import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.constant.BizLogSmallType4Hrm; +import com.engine.common.constant.BizLogType; import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; -import com.engine.kq.bean.KqShiftscheduleOperateLog; import com.engine.kq.biz.*; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.util.UtilKQ; +import com.ibm.db2.jcc.uw.bb; +import org.apache.commons.lang3.StringUtils; import weaver.common.DateUtil; import weaver.conn.BatchRecordSet; import weaver.conn.DBUtil; import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; import weaver.general.Util; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; @@ -23,15 +31,30 @@ import java.util.*; public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand> { private SimpleBizLogger logger; - // 添加日志功能 - private List> operateLogParams = new ArrayList<>(); - // 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id - private List operateLogParam = null; public SaveBatchShiftScheduleCmd(Map params, User user) { this.user = user; this.params = params; this.logger = new SimpleBizLogger(); + + String data = Util.null2String(params.get("data")); + JSONObject jsonObj = JSON.parseObject(data); + String groupId = Util.null2String(jsonObj.get("groupId"));//考勤组id + BizLogContext bizLogContext = new BizLogContext(); + bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型 + bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_Schedule_Set);//所属大类型 + bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_Schedule_Set);//当前小类型 + bizLogContext.setParams(params);//当前request请求参数 + logger.setUser(user);//当前操作人 + String mainSql = "select * from kq_group where id = " + groupId + " and (isdelete is null or isdelete <> '1') "; + logger.setMainSql(mainSql, "id");//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("groupname"); + SimpleBizLogger.SubLogInfo subLogInfo1 = logger.getNewSubLogInfo(); + String subSql1 = "select * from kq_shiftschedule where groupid = " + groupId + " and (isdelete is null or isdelete <> '1') "; + subLogInfo1.setSubSql(subSql1,"id"); + logger.addSubLogInfo(subLogInfo1); + logger.before(bizLogContext); } @Override @@ -67,6 +90,12 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand managerRoleUserIdList = new KqShiftScheduleRoleBiz().getUfKqShiftScheduleRoleValue(""+user.getUID(), groupId); KqMembersValidateBiz kqMembersValidateBiz = new KqMembersValidateBiz(); @@ -108,111 +137,84 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand mapShiftSchedule = new HashMap<>(); - sql = " select id, resourceid, kqdate, serialid from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? "; + Map mapShiftScheduleOri = new HashMap<>(); + sql = " select id, resourceid, kqdate from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? "; //有客户提下面的sql有性能问题,在表数据较多,并且该表数据改动较为频率不适合建索引,所以对mapShiftSchedule先缓存的数据范围过滤下,没必要全表缓存 if("1".equals(shiftScheduleType)){//按天排班 sql += " and kqdate='"+shiftScheduleDate+"' "; + oriDate = shiftScheduleDate; }else if("2".equals(shiftScheduleType)){ sql += " and kqdate>='"+shiftScheduleBeginDate+"' and kqdate<='"+shiftScheduleEndDate+"' "; + oriDate = shiftScheduleBeginDate; } rs.executeQuery(sql,groupId); while(rs.next()){ - mapShiftSchedule.put(rs.getString("kqdate")+"|"+Util.null2String(rs.getString("resourceid")), Util.null2String(rs.getString("id"))+"#"+Util.null2String(rs.getString("serialid"))); + mapShiftSchedule.put(rs.getString("kqdate")+"|"+rs.getString("resourceid"),rs.getString("id")); } String id = ""; - String oldSerialid = ""; - boolean needChange = false; - KQShiftManagementComInfo kqShiftScheduleComInfo = new KQShiftManagementComInfo(); - ResourceComInfo rci = new ResourceComInfo(); - KqShiftscheduleOperateLog bean = null; if(shiftScheduleType.equals("1")){//按天排班 - if(SaveShiftScheduleCmd.isDate(shiftScheduleDate)) { - for (String resourceid : lsGroupMembers) { - // 排除无需考勤人员 - if (excludeidList != null && excludeidList.contains(resourceid)) { - continue; - } - if (!managerRoleUserIdList.isEmpty()) { - if (!managerRoleUserIdList.contains(resourceid)) { - continue; - } - } - String shiftScheduleValue = Util.null2String(mapShiftSchedule.get(shiftScheduleDate + "|" + resourceid)); - if (!"".equals(shiftScheduleValue)) { - id = shiftScheduleValue.split("#")[0]; - oldSerialid = shiftScheduleValue.split("#")[1]; - } - // 如果超过了有效期,就不存储数据 - List validateList = validateResult.get(resourceid); - boolean isInRange = kqMembersValidateBiz.isInRange(shiftScheduleDate, validateList); - if (!isInRange && oldSerialid.length() > 0) { - if (delIds.length() > 0) { - delIds += ","; - } - delIds += id; - bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - shiftScheduleDate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "", user.getLanguage()); - addLog(bean); + for(String resourceid:lsGroupMembers){ + // 排除无需考勤人员 + if(excludeidList != null && excludeidList.contains(resourceid)) { + continue; + } + if(!managerRoleUserIdList.isEmpty()) { + if(!managerRoleUserIdList.contains(resourceid)) { continue; } - //if(weaver.common.DateUtil.timeInterval(shiftScheduleDate,today)>0)continue;//今天之前的无需处理 - if (id.length() > 0) { - if (serialId.length() == 0 && oldSerialid.length() > 0) { - if (delIds.length() > 0) { - delIds += ","; - } - delIds += id; - bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - shiftScheduleDate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "", user.getLanguage()); - addLog(bean); - } else { - if (!oldSerialid.equals(serialId) && oldSerialid.length() > 0) { - needChange = true; - params = new ArrayList(); - params.add(serialId); - params.add(id); - paramUpdate.add(params); - bean = new KqShiftscheduleOperateLog(1, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - shiftScheduleDate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); - addLog(bean); - } - } - } else { - if (serialId.length() == 0) continue; - if(!oldSerialid.equals(serialId)) { - needChange = true; - params = new ArrayList(); - params.add(shiftScheduleDate); - params.add(serialId); - params.add(resourceid); - params.add(groupId); - paramInsert.add(params); - bean = new KqShiftscheduleOperateLog(0, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - shiftScheduleDate, "", id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); - addLog(bean); - } + } + id = Util.null2String(mapShiftSchedule.get(shiftScheduleDate+"|"+resourceid)); + // 如果超过了有效期,就不存储数据 + List validateList = validateResult.get(resourceid); + boolean isInRange = kqMembersValidateBiz.isInRange(shiftScheduleDate, validateList); + if(!isInRange) { + if(delIds.length()>0)delIds+=","; + delIds+=id; + continue; + } + //if(weaver.common.DateUtil.timeInterval(shiftScheduleDate,today)>0)continue;//今天之前的无需处理 + if(id.length()>0){ + if(serialId.length()==0){ + if(delIds.length()>0)delIds+=","; + delIds+=id; + }else { + params = new ArrayList(); + params.add(serialId); + params.add(id); + params.add(shiftScheduleDate); + params.add(resourceid); + paramUpdate.add(params); } - if (needChange) { - if (DateUtil.timeInterval(shiftScheduleDate, today) >= 0) { - formatParams = new ArrayList<>(); - formatParams.add(resourceid); - formatParams.add(shiftScheduleDate); - lsFormatParams.add(formatParams); - } - - deleteParams = new ArrayList<>(); - deleteParams.add(resourceid); - deleteParams.add(shiftScheduleDate); - lsDeleteParams.add(deleteParams); + }else{ + if(serialId.length()==0)continue;; + params = new ArrayList(); + params.add(shiftScheduleDate); + params.add(serialId); + params.add(resourceid); + params.add(groupId); + paramInsert.add(params); + } - checkSerialParams = new ArrayList<>(); - checkSerialParams.add(resourceid); - checkSerialParams.add(shiftScheduleDate); - checkSerialParams.add(serialId); - lscheckSerialParams.add(checkSerialParams); - } + if(DateUtil.timeInterval(shiftScheduleDate,today)>=0) { + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(shiftScheduleDate); + lsFormatParams.add(formatParams); } + + deleteParams = new ArrayList<>(); + deleteParams.add(resourceid); + deleteParams.add(shiftScheduleDate); + lsDeleteParams.add(deleteParams); + + checkSerialParams = new ArrayList<>(); + checkSerialParams.add(resourceid); + checkSerialParams.add(shiftScheduleDate); + checkSerialParams.add(serialId); + lscheckSerialParams.add(checkSerialParams); + mapShiftScheduleOri.put(shiftScheduleDate+"|"+resourceid,serialId); } }else if(shiftScheduleType.equals("2")){//按周期排班 List lsDate = new ArrayList<>(); @@ -255,55 +257,44 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand0)continue;//今天之前的无需处理 String date = lsDate.get(i); - if(!SaveShiftScheduleCmd.isDate(date)) { - continue; - } - String shiftScheduleValue = Util.null2String(mapShiftSchedule.get(date+"|"+resourceid)); - if(!"".equals(shiftScheduleValue)) { - id = shiftScheduleValue.split("#")[0]; - oldSerialid = shiftScheduleValue.split("#")[1]; - } + id = Util.null2String(mapShiftSchedule.get(date+"|"+resourceid)); // 如果超过了有效期,就不存储数据 List validateList = validateResult.get(resourceid); boolean isInRange = kqMembersValidateBiz.isInRange(date, validateList); if(!isInRange) { - if(oldSerialid.length() > 0) { - if (delIds.length() > 0) { - delIds += ","; - } - delIds += id; - bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "", user.getLanguage()); - addLog(bean); - } + if(delIds.length()>0)delIds+=","; + delIds+=id; continue; } needShiftSchedule = true; int changeType= KQHolidaySetBiz.getChangeType(groupId, date); - if (changeType != 1 && changeType != 3 && !holidayType.equals("1")) {//遇双休日继续排班 + if (changeType != 1 && changeType != 3 && holidayType.equals("2")) {//遇双休日继续排班 int weekDay = DateUtil.getWeek(date); if(weekDay>5){ needShiftSchedule = false; } } - if(!meetHolidays.equals("1")){//遇节假日继续排班 + if(meetHolidays.equals("2")){//遇节假日继续排班 if(changeType==1){ needShiftSchedule = false; } } - if(!meetRestDays.equals("1")){//遇调配休息日继续排班 + if(meetRestDays.equals("2")){//遇调配休息日继续排班 if(changeType==3){ needShiftSchedule = false; } } + if(meetworkDays.equals("2")){//遇调配工作日日继续排班 + if(changeType==2){ + needShiftSchedule = false; + } + } + if(needShiftSchedule){ dayCount++; int idx = dayCount % shiftcycleday; @@ -312,83 +303,323 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand5){ + serialId = serialIdSx; + } + } + if(meetHolidays.equals("3")){//遇节假日指定排班 + if(changeType == 1){ + serialId = serialIdJjr; + } + } + if(meetRestDays.equals("3")){//遇调配休息日指定排班 + if(changeType == 3){ + serialId = serialIdXxr; + } + } + if(meetworkDays.equals("3")){//遇调配工作日指定排班 + if(changeType == 2){ + serialId = serialIdGzr; + } + } + new BaseBean().writeLog("serialId后"+serialId); if(id.length()>0){ - if(serialId.length()==0 && oldSerialid.length() > 0){ - if(delIds.length()>0) { - delIds+=","; - } + if(serialId.length()==0){ + if(delIds.length()>0)delIds+=","; delIds+=id; - bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "",user.getLanguage()); - addLog(bean); }else { - if(!oldSerialid.equals(serialId) && oldSerialid.length() > 0) { - needChange = true; - params = new ArrayList(); - params.add(serialId); - params.add(id); - paramUpdate.add(params); - bean = new KqShiftscheduleOperateLog(1,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceid), - date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid)+"(id:"+oldSerialid+")"), id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId)+"(id:"+serialId+")"),user.getLanguage()); - addLog(bean); - } + params = new ArrayList(); + params.add(serialId); + params.add(id); + params.add(date); + params.add(resourceid); + paramUpdate.add(params); } }else{ if(serialId.length()>0){ - if(!oldSerialid.equals(serialId)) { - needChange = true; - params = new ArrayList(); - params.add(date); - params.add(serialId); - params.add(resourceid); - params.add(groupId); - paramInsert.add(params); - bean = new KqShiftscheduleOperateLog(0, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - date, "", id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); - addLog(bean); - } + params = new ArrayList(); + params.add(date); + params.add(serialId); + params.add(resourceid); + params.add(groupId); + paramInsert.add(params); } } + mapShiftScheduleOri.put(date+"|"+resourceid,serialId); }else{ - if(oldSerialid.length() > 0) { - deleteCancelParams = new ArrayList<>(); - deleteCancelParams.add(resourceid); - deleteCancelParams.add(date); - lsDeleteCancelParams.add(deleteCancelParams); - bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), - date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "",user.getLanguage()); - addLog(bean); - } + deleteCancelParams = new ArrayList<>(); + deleteCancelParams.add(resourceid); + deleteCancelParams.add(date); + lsDeleteCancelParams.add(deleteCancelParams); + } + if(DateUtil.timeInterval(date,today)>=0) { + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(date); + lsFormatParams.add(formatParams); } - if(needChange) { - if(DateUtil.timeInterval(date,today)>=0) { - formatParams = new ArrayList<>(); - formatParams.add(resourceid); - formatParams.add(date); - lsFormatParams.add(formatParams); - } - deleteParams = new ArrayList<>(); - deleteParams.add(resourceid); - deleteParams.add(date); - lsDeleteParams.add(deleteParams); + deleteParams = new ArrayList<>(); + deleteParams.add(resourceid); + deleteParams.add(date); + lsDeleteParams.add(deleteParams); + + checkSerialParams = new ArrayList<>(); + checkSerialParams.add(resourceid); + checkSerialParams.add(shiftScheduleDate); + checkSerialParams.add(serialId); + lscheckSerialParams.add(checkSerialParams); - checkSerialParams = new ArrayList<>(); - checkSerialParams.add(resourceid); - checkSerialParams.add(shiftScheduleDate); - checkSerialParams.add(serialId); - lscheckSerialParams.add(checkSerialParams); - } } } } + //二开获取排班校验规则 + String getPbCheckValue = getpbCheckValue(groupId); + + BaseBean bb = new BaseBean(); + String fromDate = TimeUtil.getMonthBeginDay(oriDate); + String toDate = TimeUtil.getMonthEndDay(oriDate); + List lsDateNew = new ArrayList<>(); + Calendar calNew = DateUtil.getCalendar(); + boolean isEndNew = false; + for(String date=fromDate; !isEndNew;) { + if(date.equals(toDate)) isEndNew = true; + lsDateNew.add(date); + calNew.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(calNew.getTime(), 1); + } + Map mapShiftScheduleAll = new HashMap<>(); + Set unSavePerson = new HashSet<>(); + + if("3".equals(getPbCheckValue) || "2".equals(getPbCheckValue)){ + //上四休二校验,生成预排班数据结构 + for(String resourceid:lsGroupMembers){ + Map mapShiftScheduleChild = new HashMap<>(); + String sqlChild = " select id, resourceid, kqdate,serialid from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? "; + //有客户提下面的sql有性能问题,在表数据较多,并且该表数据改动较为频率不适合建索引,所以对mapShiftSchedule先缓存的数据范围过滤下,没必要全表缓存 + sqlChild += " and kqdate>='"+fromDate+"' and kqdate<='"+toDate+"' "; + rs.executeQuery(sqlChild,groupId); + while(rs.next()){ + mapShiftScheduleChild.put(rs.getString("kqdate")+"|"+rs.getString("resourceid"),rs.getString("serialid")); + } + //生成这个人员这个月的预生成排班 + for(int i=0;i=0){ + findNextXxb1 = false; + } + } + //将date作为一个锚点,往前找并判断是否满足上四休二 + boolean findBefore = true; + Integer dayB = -1; + //工作班数量 + Integer gzbnum = 0; + //判断前面是否还有休息班标识 + Integer xxbNo = 0; + while (findBefore){ + calNew.setTime(DateUtil.parseToDate(date)); + String dateBefore = DateUtil.getDate(calNew.getTime(), dayB); + dayB--; + String bcidBefore = Util.null2String(mapShiftScheduleAll.get(dateBefore+"|"+resourceid)); + bb.writeLog("bcidBefore"+bcidBefore+"dateBefore"+dateBefore+"dayB"+dayB); + if(StringUtils.isNotBlank(bcidBefore)){ + boolean checkXxbBefore = checkXxr(bcidBefore); + if(checkXxbBefore){ + //找到了第一个休息班,判断间隔了多少个非休息班,不再找了 + bb.writeLog("找到了第一个休息班,判断间隔了多少个非休息班,不再找了"); + findBefore = false; + xxbNo = 1; + }else{ + gzbnum ++; + } + } + //找到月初一号了,不找了 + if(DateUtil.timeInterval(dateBefore,fromDate)>=0){ + findBefore = false; + } + } + bb.writeLog("gzbnum"+gzbnum); + if(xxbNo == 1){ + //当前锚点前面有休息班,若间隔工作班数量不为4,则不符合 + if(gzbnum != 4){ + bb.writeLog("当前锚点前面有休息班,若间隔工作班数量不为4,则不符合"); + unSavePerson.add(resourceid); + } + }else{ + //当前锚点是第一个休息班 + if(gzbnum>4){ + //锚点往前有超过四个工作班,不符合 + bb.writeLog("当前锚点是第一个休息班,锚点往前有超过四个工作班,不符合"); + unSavePerson.add(resourceid); + } + } + + }else{ + //找到的不是休息班,也认为不符合上四休二 + bb.writeLog("找到的不是休息班,也认为不符合上四休二"); + unSavePerson.add(resourceid); + } + }else{ + i++; + } + + //到最后一天也没找到,暂不处理 + if(DateUtil.timeInterval(toDate,dateNext)>=0){ + findNextXxb = false; + } + } + } + } + } + } + bb.writeLog("unSavePerson"+JSONObject.toJSONString(unSavePerson)); + } + + } + bb.writeLog("paramUpdate"+JSONObject.toJSONString(paramUpdate)); sql = " update kq_shiftschedule set serialid=?,isDelete=0 where id = ? "; for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) { List update_params = paramUpdate.get(i); String serialid = Util.null2String(update_params.get(0)); String tmp_id = Util.null2String(update_params.get(1)); - rs.executeUpdate(sql, serialid,tmp_id); + String resourceid = Util.null2String(update_params.get(3)); + if(unSavePerson.contains(resourceid) && !"1".equals(getPbCheckValue)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, serialid,tmp_id); + } } sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)"; @@ -398,7 +629,12 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand0){ @@ -413,7 +649,11 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand delete_params = lsDeleteCancelParams.get(i); String resourceid = Util.null2String(delete_params.get(0)); String kqdate = Util.null2String(delete_params.get(1)); - rs.executeUpdate(sql, resourceid,kqdate); + if(unSavePerson.contains(resourceid) && !"1".equals(getPbCheckValue)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid,kqdate); + } } //删除之前的排的班次,一天只能有一个班次 @@ -422,7 +662,11 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand delete_params = lsDeleteParams.get(i); String resourceid = Util.null2String(delete_params.get(0)); String kqdate = Util.null2String(delete_params.get(1)); - rs.executeUpdate(sql, resourceid,kqdate); + if(unSavePerson.contains(resourceid) && !"1".equals(getPbCheckValue)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid,kqdate); + } } sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and serialid != ? "; @@ -431,16 +675,33 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand0 && !"1".equals(getPbCheckValue)){ + List personNameList = new ArrayList<>(); + for(String personid:unSavePerson){ + personNameList.add(resourceComInfo.getLastname(personid)); + } + String msg = ""; + if("2".equals(getPbCheckValue)){ + msg = "做五休二"; + }else if("3".equals(getPbCheckValue)){ + msg = "做四休二"; + } + retmap.put("status", "-1"); + retmap.put("message", "【"+StringUtils.join(personNameList,",")+"】上述员工当前月份排班不符合"+msg+"规则或存在未排班日期"); + return retmap; + } retmap.put("status", "1"); retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage())); @@ -452,16 +713,69 @@ public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand(); - operateLogParam.add(bean.getOperatetype()); - operateLogParam.add(bean.getOperator()); - operateLogParam.add(bean.getKqgroupname()); - operateLogParam.add(bean.getChangeduser()); - operateLogParam.add(bean.getChangedshiftdate()); - operateLogParam.add(bean.getChangedshiftname()); - operateLogParam.add(bean.getKqshiftid()); - operateLogParams.add(operateLogParam); + /** + * 判断是否是休息班 + * @param serialid + * @return + */ + private static Boolean checkXxr(String serialid){ + RecordSet rs = new RecordSet(); + String sql = "select * from kq_ShiftManagement where id = "+serialid+" and is_rest = 1"; + rs.execute(sql); + Boolean check = false; + if (rs.getCounts()>0){ + check = true; + } + return check; + } + + /** + * 获取当前日期是何种类型(这里只考虑节假日设置) + * + * @param groupId 考勤组ID + * @param date 指定日期 + * @return 1-节假日、2-工作日、3-休息日、-1-没有设置过数据 + */ + public static int getChangeType(String groupId, String date) { + int changeType = -1;//默认没有设置过节假日(节假日设置的类型:1-公众假日、2-调配工作日、3-调配休息日) + KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo(); + String tmpChangetype = kqHolidaySetComInfo.getChangeType(groupId, date); + if(null != tmpChangetype){ + changeType = Util.getIntValue(tmpChangetype, -1); + } + + return changeType; + } + + /** + * 获取排班校验规则 + * @param groupid + * @return + */ + private static String getpbCheckValue(String groupid){ + RecordSet rs = new RecordSet(); + String sql = "select pbcheck from kq_group where id = "+groupid; + rs.execute(sql); + String pbcheck = ""; + if (rs.next()){ + pbcheck = Util.null2String(rs.getString("pbcheck")); + } + return pbcheck; + } + + public static void main(String[] args) { + String fromDate = TimeUtil.getMonthBeginDay("2025-04-07"); + String toDate = TimeUtil.getMonthEndDay("2025-04-07"); + List lsDate = new ArrayList<>(); + Calendar cal = DateUtil.getCalendar(); + boolean isEnd = false; + for(String date=toDate; !isEnd;) { + if(date.equals(fromDate)) isEnd = true; + lsDate.add(date); + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), -1); + } + System.out.println(lsDate); } @Override diff --git a/src/com/engine/xmgsecond/entity/KqFormatTotal.java b/src/com/engine/xmgsecond/entity/KqFormatTotal.java new file mode 100644 index 0000000..3c896b3 --- /dev/null +++ b/src/com/engine/xmgsecond/entity/KqFormatTotal.java @@ -0,0 +1,59 @@ +package com.engine.xmgsecond.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author liang.cheng + * @Date 2025/5/14 16:11 + * @Description: + * @Version 1.0 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class KqFormatTotal { + + private Integer resourceId; + + private Integer absenteeism; + + private Integer forgotCheck; + + private Integer beLateMins; + + private Integer gravebeLateMins; + + private Integer leaveEearly; + + private Integer graveLeaveEarly; + + /** + * 是否统计缺勤 + */ + private boolean isAbsence; + + /** + * 缺勤天数 + */ + private double absenceDays; + + + @Override + public String toString() { + return "KqFormatTotal{" + + "resourceId=" + resourceId + + ", absenteeism=" + absenteeism + + ", forgotCheck=" + forgotCheck + + ", beLateMins=" + beLateMins + + ", gravebeLateMins=" + gravebeLateMins + + ", leaveEearly=" + leaveEearly + + ", graveLeaveEarly=" + graveLeaveEarly + + ", isAbsence=" + isAbsence + + ", absenceDays=" + absenceDays + + '}'; + } +} diff --git a/src/com/engine/xmgsecond/util/KqCalulateUtil.java b/src/com/engine/xmgsecond/util/KqCalulateUtil.java new file mode 100644 index 0000000..b93a3cd --- /dev/null +++ b/src/com/engine/xmgsecond/util/KqCalulateUtil.java @@ -0,0 +1,98 @@ +package com.engine.xmgsecond.util; + +import com.engine.xmgsecond.entity.KqFormatTotal; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @Author liang.cheng + * @Date 2025/5/14 16:16 + * @Description: + * @Version 1.0 + */ +public class KqCalulateUtil { + + + /** + * @Description: 时间范围内 考勤异常汇总成缺勤天数 + * @Author: liang.cheng + * @Date: 2025/5/14 16:22 + * @param: [resourceId, fromDate, toDate] + * @return: java.util.List + */ + public static List abnormalAttendance(String resourceId,String fromDate,String toDate) { + RecordSet rs = new RecordSet(); + List kqFormatTotalList = new ArrayList<>(); + rs.executeQuery("select resourceid, forgotCheck, absenteeism, beLateMins, gravebeLateMins, leaveEearly, " + + " graveLeaveEarly from kq_format_total where resourceid = ? and kqdate >= '"+fromDate+"' and kqdate <= '"+toDate+"'",resourceId); + while (rs.next()) { + boolean isAbsence; + int absenteeism = Util.getIntValue(rs.getString("absenteeism")); + int forgotCheck = Util.getIntValue(rs.getString("forgotCheck")); + int beLateMins = Util.getIntValue(rs.getString("beLateMins"),0); + int gravebeLateMins = Util.getIntValue(rs.getString("gravebeLateMins"),0); + int leaveEearly = Util.getIntValue(rs.getString("leaveEearly")); + int graveLeaveEarly = Util.getIntValue(rs.getString("graveLeaveEarly")); + + //规则1 + isAbsence = isPositive(absenteeism) || + isPositive(forgotCheck) || + sumPositive(leaveEearly, graveLeaveEarly) > 0; + + kqFormatTotalList.add(KqFormatTotal.builder() + .resourceId(Util.getIntValue(rs.getString("resourceid"))) + .beLateMins(beLateMins) + .gravebeLateMins(gravebeLateMins) + .isAbsence(isAbsence) + .absenceDays(isAbsence ? 1 : 0) + .build()); + } + + + //规则2 + AtomicInteger graceCounter = new AtomicInteger(0); + kqFormatTotalList.forEach(record -> { + if (!record.isAbsence()) { + int lateMinutes = sumNullSafe(record.getBeLateMins(), record.getGravebeLateMins()); + record.setAbsenceDays(calculateAbsenceDays(lateMinutes, graceCounter)); + } + }); + + rs.writeLog("kqFormatTotalList2:"+kqFormatTotalList.toString()); + + return kqFormatTotalList; + + } + + public static boolean isPositive(Integer num) { + return Optional.ofNullable(num).orElse(0) > 0; + } + + // 辅助方法:安全求和(处理 null 情况) + public static int sumPositive(Integer a, Integer b) { + return Optional.ofNullable(a).orElse(0) + Optional.ofNullable(b).orElse(0); + } + + private static double calculateAbsenceDays(int lateMinutes, AtomicInteger graceCounter) { + if (lateMinutes <= 0) { + return 0; + } + if (graceCounter.get() < 3 && lateMinutes > 0 && lateMinutes <= 15) { + graceCounter.incrementAndGet(); + return 0; + } + return (lateMinutes > 0 && lateMinutes <= 240) ? 0.5 : 1; + } + + private static int sumNullSafe(Integer a, Integer b) { + return Optional.ofNullable(a).orElse(0) + Optional.ofNullable(b).orElse(0); + } + + +}