package com.engine.kq.biz; import com.engine.kq.cmd.hrmAttProcSet.KqTempletEnum; import com.engine.kq.log.KQLog; import com.engine.kq.wfset.attendance.manager.HrmAttProcSetManager; import weaver.common.DateUtil; import weaver.common.StringUtil; import weaver.conn.RecordSet; import weaver.general.BaseBean; import weaver.general.Util; import weaver.hrm.User; import weaver.hrm.attendance.domain.HrmPaidLeaveTime; import weaver.hrm.attendance.manager.HrmPaidLeaveTimeManager; import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.SubCompanyComInfo; import weaver.hrm.moduledetach.ManageDetachComInfo; import weaver.hrm.resource.ResourceComInfo; import weaver.systeminfo.SystemEnv; import weaver.workflow.action.WorkflowActionManager; import weaver.workflow.workflow.WorkflowBillComInfo; import java.time.Duration; import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; /** * E9新考勤 兼容升级E8考勤数据 */ public class KQOneStopUp { public String separator = "#"; public static KQLog kqLog = new KQLog(); /** * 根据新版考勤的请假类型更新旧版本的考勤请假类型 */ public void upFlowLeaveType() { WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo(); RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); String sql = "select * from hrm_att_proc_set where field006=0 "; Map tableMap = new HashMap<>(); rs.executeQuery(sql); while(rs.next()){ String setid = rs.getString("id"); String formid = rs.getString("field002"); String tablename = workflowBillComInfo.getTablename(formid); String fieldnameSql = " select * from hrm_att_proc_relation where field002 in(select id from hrm_att_proc_fields where field001 = 180 and field002='newLeaveType') and field001 = "+setid; String fieldname = ""; rs1.executeQuery(fieldnameSql); if(rs1.next()){ fieldname = rs1.getString("field004"); } if(tablename.length() > 0 && fieldname.length() > 0){ tableMap.put(tablename, fieldname); } } List updateSqls = new ArrayList<>(); String leavetypeSql = "select * from hrm_to_kq_LeaveRules "; rs2.executeQuery(leavetypeSql); while(rs2.next()){ String hrmleaveid = rs2.getString("hrmleaveid"); String kqleaveid = rs2.getString("kqleaveid"); for(Map.Entry me: tableMap.entrySet()){ String upSql = "update "+me.getKey()+" set "+me.getValue()+" = " +kqleaveid+ " where "+me.getValue()+"="+hrmleaveid; updateSqls.add(upSql); } } for(String upSql : updateSqls){ rs.executeUpdate(upSql); } } /** * 在流程數據拆分前,需要初始化出差规则、公出规则和加班规则 * @return */ public boolean upFLowRule() { boolean isDone = false; isDone = upEvectionRule(); if(!isDone){ return isDone; } isDone = upOutRule(); if(!isDone){ return isDone; } isDone = upOvertimeRuleUnit(); if(!isDone){ return isDone; } isDone = upOvertimeRule("",null,""); if(!isDone){ return isDone; } return isDone; } /** * 初始化加班规则单位 * @return */ public boolean upOvertimeRuleUnit() { int id = 1;////暂为备用字段,加班单位ID,固定为1 int organizationType = 0;//暂为备用字段,所属机构类型:0-总部、1-分部、2-部门 int organizationId = -1;//暂为备用字段,所属机构的ID(机构类型为分部时为分部ID) int minimumUnit = 1;//最小加班单位:1-按天加班、2-按半天加班、3-按小时加班、4-按整天加班 double hoursToday = 8.00;//日折算时长 boolean flag = true; String sql = "update kq_OvertimeUnit set minimumUnit=?,hoursToday=? where id=?"; RecordSet recordSet = new RecordSet(); flag = recordSet.executeUpdate(sql, minimumUnit, hoursToday, id); return flag; } /** * 升级初始化加班规则 */ public boolean upOvertimeRule(String groupids, User user,String rulefrom) { RecordSet rs = new RecordSet(); if(groupids.length() > 0){ groupids = groupids.substring(1); Map params = new HashMap<>(); if("scheduleset".equalsIgnoreCase(rulefrom)){ params.put("name", "一般工作时间升级加班规则"); }else{ params.put("name", "排班升级加班规则"); } params.put("groupIds", groupids); params.put("minimumLen2", "1"); params.put("startTime2", "0"); params.put("minimumLen3", "1"); params.put("minimumLen1", "1"); params.put("paidLeaveEnableType2", "2"); params.put("paidLeaveEnableType3", "2"); params.put("paidLeaveEnableType1", "2"); params.put("paidLeaveEnableFlowType2", "1"); params.put("paidLeaveEnableFlowType3", "1"); params.put("paidLeaveEnableFlowType1", "1"); int ruleId = KQOvertimeRulesBiz.addOvertimeRules(params, user); if(ruleId > 0){ String overRuleSql = "insert into hrm_to_kq_OverRules(kqid,rulefrom) values(?,?)"; return rs.executeUpdate(overRuleSql, ruleId,rulefrom); }else{ kqLog.info("upOvertimeRule 生成加班规则失败 :"+params); return false; } }else{ kqLog.info("upOvertimeRule 生成加班规则失败 :groupids为空"); return false; } } /** * 升级初始化公出规则 */ public boolean upOutRule() { RecordSet recordSet = new RecordSet(); String exit_ruleId = "1";//暂为备用字段,规则ID,固定为1 String exit_name = "出差";//暂为备用字段,规则名称,目前固定为出差 int exit_organizationType = 0;//暂为备用字段,所属机构类型:0-总部、1-分部、2-部门 int exit_organizationId = 0;//暂为备用字段,所属机构的ID(机构类型为分部时为分部ID) int exit_minimumUnit = 1;//最小公出单位:1-按天公出、2-按半天公出、3-按小时公出、4-按整天公出 double exit_proportion = 8.00;//换算比例(当单位由天、半天、整天切换成小时或者由小时切换成天、半天、整天时,历史数据的转换比例) int exit_computingMode = 1;//计算公出时长方式:1-按工作日计算公出时长、2-按自然日计算公出时长 double exit_hoursToDay = 8.00;//日折算时长(当按天公出、按半天公出且按自然日计算公出时长时有效) String sql = "update kq_exitRules set minimumUnit=?,proportion=?,computingMode=?,hoursToDay=? where id=?"; boolean flag = recordSet.executeUpdate(sql, exit_minimumUnit, exit_proportion, exit_computingMode, exit_hoursToDay, exit_ruleId); return flag; } /** * 升级初始化出差规则 */ public boolean upEvectionRule() { String ruleId = "1";//暂为备用字段,规则ID,固定为1 String name = "出差";//暂为备用字段,规则名称,目前固定为出差 int organizationType = 0;//暂为备用字段,所属机构类型:0-总部、1-分部、2-部门 int organizationId = 0;//暂为备用字段,所属机构的ID(机构类型为分部时为分部ID) int minimumUnit = 1;//最小出差单位:1-按天出差、2-按半天出差、3-按小时出差、4-按整天出差 double proportion = 8.00;//换算比例(当单位由天、半天、整天切换成小时或者由小时切换成天、半天、整天时,历史数据的转换比例) int computingMode = 1;//计算公出时长方式:1-按工作日计算出差时长、2-按自然日计算出差时长 double hoursToDay = 8.00;//折算时长(当按天出差、按半天出差且按自然日计算出差时长时有效) boolean flag = true; String sql = "update kq_travelRules set minimumUnit=?,proportion=?,computingMode=?,hoursToDay=? where id=?"; RecordSet recordSet = new RecordSet(); flag = recordSet.executeUpdate(sql, minimumUnit, proportion, computingMode, hoursToDay, ruleId); return flag; } /** * 所有相關的緩存需要刷新下 */ public void refreshCominfo() { try{ SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); subCompanyComInfo.removeCompanyCache(); DepartmentComInfo departmentComInfo = new DepartmentComInfo(); departmentComInfo.removeCompanyCache(); ResourceComInfo resourceComInfo = new ResourceComInfo(); resourceComInfo.removeResourceCache(); }catch (Exception e){ } KQAttFlowSetComInfo kqAttFlowSetComInfo = new KQAttFlowSetComInfo(); KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); KQShiftOnOffWorkSectionComInfo onOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo(); KQShiftRestTimeSectionComInfo restTimeSectionComInfo = new KQShiftRestTimeSectionComInfo(); KQGroupMemberComInfo groupMemberComInfo = new KQGroupMemberComInfo(); KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo(); KQShiftScheduleComInfo kqShiftScheduleComInfo = new KQShiftScheduleComInfo(); KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); KQTravelRulesComInfo travelRulesComInfo = new KQTravelRulesComInfo(); KQExitRulesComInfo exitRulesComInfo = new KQExitRulesComInfo(); KQLeaveRulesDetailComInfo rulesDetailComInfo = new KQLeaveRulesDetailComInfo(); KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); kqShiftManagementComInfo.removeShiftManagementCache(); onOffWorkSectionComInfo.removeShiftWorkSectionCache(); restTimeSectionComInfo.removeShiftRestTimeSectionCache(); groupMemberComInfo.removeCache(); kqFixedSchedulceComInfo.removeCache(); kqShiftScheduleComInfo.removeCache(); kqLeaveRulesComInfo.removeCache(); holidaySetComInfo.removeCache(); travelRulesComInfo.removeCache(); exitRulesComInfo.removeCache(); kqAttFlowSetComInfo.removeKQAttFlowSetComInfoCache(); kqLeaveRulesComInfo.removeCache(); rulesDetailComInfo.removeCache(); kqGroupComInfo.removeCache(); } public void upReportData(String startdate,String enddate) { KQFormatData kqFormatData = new KQFormatData(); LocalDate localFromDate = LocalDate.parse(startdate); LocalDate localToDate = LocalDate.parse(enddate); DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); long betweenDays = localToDate.toEpochDay() - localFromDate.toEpochDay(); for (int i = 0; i <= betweenDays; i++) { LocalDate curLocalDate = localFromDate.plusDays(i); String kqDate = curLocalDate.format(dateFormatter); new KQFormatBiz().formatDateByKQDate(kqDate); } } /** * 升級流程數據 對流程數據進行拆分 * @param startdate * @param enddate * @return */ public void upFlowData(String startdate,String enddate) { try{ RecordSet rs = new RecordSet(); KQFlowActiontBiz kqFlowActiontBiz = new KQFlowActiontBiz(); String sql1 = " select * from kq_ATT_PROC_SET where id in(select kqid from hrm_to_attSet) "; rs.executeQuery(sql1); while(rs.next()){ String proc_set_id = rs.getString("id"); //得到这个考勤流程设置是否使用明细 String usedetails = rs.getString("usedetail"); String workflowid = rs.getString("field001"); int kqtype = Util.getIntValue(rs.getString("field006")); String valueWhere = " and ( fromDate between '"+startdate+"' and '"+enddate+"' or toDate between '"+startdate+"' and '"+enddate+"' " + " or '"+startdate+"' between fromDate and toDate or '"+enddate+"' between fromDate and toDate) "; Map map = new HashMap(); if(kqtype != 5 && kqtype != 6 && kqtype != 7){ map.put("fromDate", valueWhere); map.put("currentNodeType", " and currentNodeType = '3' "); } Map result = kqFlowActiontBiz.handleKQFlowAction(proc_set_id, usedetails, 0, kqtype, Util.getIntValue(workflowid), false,true,map); if(!result.isEmpty()){ String error = Util.null2String(result.get("message")); kqLog.info("升级考勤流程拆分:"+error); continue; } } }catch (Exception e){ e.printStackTrace(); } } /** * 生成处理的sql * @param proc_set_id * @param usedetails * @param kqtype * @return */ public Map handleSql(String proc_set_id,String usedetails,int kqtype) { HrmAttProcSetManager hrmAttProcSetManager= new HrmAttProcSetManager(); Map map = new HashMap(); Map sqlMap = new HashMap<>(); sqlMap = hrmAttProcSetManager.getSQLByField006Map(kqtype, map, true, true, proc_set_id,usedetails); return sqlMap; } /** * 升级考勤流程设置 */ public boolean upAttSet() { boolean isDone = false; try{ //1、考勤流程基本信息 upAttProcSet(); //2、新/老 考勤流程字段生成映射 upAttProcField(); //3、新考勤流程字段對應 isDone = upKQAttProcField(); //4、考勤流程動作設置 isDone = upAttProcAction(); }catch (Exception e){ isDone = false; e.printStackTrace(); } return isDone; } /** * 考勤流程動作設置對應 */ public boolean upAttProcAction() throws Exception{ RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); RecordSet rs3 = new RecordSet(); boolean isDone = false; //请假加班的先做一下 String sql4 = "select a.*,b.field001 as workflowid,b.field006 as kqtype from hrm_ATT_PROC_ACTION a left join HRM_ATT_PROC_SET b on a.FIELD001=b.id where a.FIELD001 >0 and b.FIELD006 in (0,3) "; rs.executeQuery(sql4); while(rs.next()){ String att_proc_action_id = rs.getString("id"); String field001 = rs.getString("field001"); String field002 = rs.getString("field002"); String field003 = rs.getString("field003"); String field004 = rs.getString("field004"); String field005 = rs.getString("field005"); String field006 = rs.getString("field006"); String field007 = rs.getString("field007"); String field008 = rs.getString("field008"); String kqtype = rs.getString("kqtype"); String workflowid = rs.getString("workflowid"); long mfid = UUID.randomUUID().getMostSignificantBits(); String att_proc_set_id = ""; String attsetIdSql = "select * from hrm_to_attSet where hrmid="+field001; rs2.executeQuery(attsetIdSql); if(rs2.next()){ att_proc_set_id = Util.null2String(rs2.getString("kqid")); } if(att_proc_set_id.length() == 0){ continue; } String actionname = ""; switch (field002){ case "deduction": actionname ="KqDeductionVacationAction"; break; case "freeze": actionname ="KqFreezeVacationAction"; break; case "release": actionname ="KqReleaseVacationAction"; break; case "HrmScheduleShift": actionname ="KqSplitShiftAction"; break; case "HrmPaidLeaveAction": actionname ="KqPaidLeaveAction"; break; default: break; } if(actionname.length() > 0){ String updateSql = "update kq_ATT_PROC_ACTION set field003=?,field004=?,field005=?,field006=?,field007=?,field008=? where field001=? and field002= ? "; isDone = rs1.executeUpdate(updateSql,field003,field004,field005,field006,field007,field008,att_proc_set_id,actionname); if(!isDone){ break; } rs2.executeSql("delete from workflowactionset where workflowid = "+workflowid+" and interfaceid in ('"+actionname+"')"); int preoperator = 0; if(StringUtil.parseToInt(field005) == 2){ preoperator = 1; } String field003Name = SystemEnv.getHtmlLabelNames(field003,7); WorkflowActionManager workflowActionManager = new WorkflowActionManager(); workflowActionManager.setActionid(0); workflowActionManager.setActionname(field003Name); workflowActionManager.setWorkflowid(StringUtil.parseToInt(workflowid)); workflowActionManager.setNodeid(StringUtil.parseToInt(field006)); workflowActionManager.setNodelinkid(0); workflowActionManager.setIspreoperator(preoperator); workflowActionManager.setActionorder(1); workflowActionManager.setInterfaceid(actionname); workflowActionManager.setInterfacetype(3); workflowActionManager.setIsused(1); if(field007.equalsIgnoreCase("1")){ workflowActionManager.setDrawbackflag(1); } workflowActionManager.doSaveWsAction(); } if(workflowid.length() > 0){ String nodeid = ""; String getNodeSql = "select * from workflow_flownode where workflowid = ? and nodetype=3 "; rs3.executeQuery(getNodeSql, workflowid); if(rs3.next()){ nodeid = rs3.getString("nodeid"); String updateSql = "update kq_ATT_PROC_ACTION set field005=?,field006=?,field007=?,field008=? where field001=? and field002= ? "; isDone = rs1.executeUpdate(updateSql,"2",nodeid,"1","1",att_proc_set_id,"KqSplitAction"); int preoperator = 0; if(StringUtil.parseToInt(field005) == 2){ preoperator = 1; } rs2.executeSql("delete from workflowactionset where workflowid = "+workflowid+" and interfaceid in ('KqSplitAction')"); String field003Name = SystemEnv.getHtmlLabelName(81543, Util.getIntValue(7)); WorkflowActionManager workflowActionManager = new WorkflowActionManager(); workflowActionManager.setActionid(0); workflowActionManager.setActionname(field003Name); workflowActionManager.setWorkflowid(StringUtil.parseToInt(workflowid)); workflowActionManager.setNodeid(StringUtil.parseToInt(nodeid)); workflowActionManager.setNodelinkid(0); workflowActionManager.setIspreoperator(preoperator); workflowActionManager.setActionorder(1); workflowActionManager.setInterfaceid("KqSplitAction"); workflowActionManager.setInterfacetype(3); workflowActionManager.setIsused(1); workflowActionManager.doSaveWsAction(); } } } //再处理下出差,公出和异常流程的 String sql_5 = "select * from HRM_ATT_PROC_SET where FIELD006 in (1,2,4) "; rs.executeQuery(sql_5); while(rs.next()){ String workflowid = rs.getString("field001"); String attid = rs.getString("id"); String att_proc_set_id = ""; String attsetIdSql = "select * from hrm_to_attSet where hrmid="+attid; rs2.executeQuery(attsetIdSql); if(rs2.next()){ att_proc_set_id = Util.null2String(rs2.getString("kqid")); } if(att_proc_set_id.length() == 0){ continue; } if(workflowid.length() > 0){ String nodeid = ""; String getNodeSql = "select * from workflow_flownode where workflowid = ? and nodetype=3 "; rs3.executeQuery(getNodeSql, workflowid); if(rs3.next()){ nodeid = rs3.getString("nodeid"); } String updateSql = "update kq_ATT_PROC_ACTION set field005=?,field006=?,field007=?,field008=? where field001=? and field002= ? "; isDone = rs1.executeUpdate(updateSql,"2",nodeid,"1","1",att_proc_set_id,"KqSplitAction"); rs2.executeSql("delete from workflowactionset where workflowid = "+workflowid+" and interfaceid in ('KqSplitAction')"); String field003Name = SystemEnv.getHtmlLabelName(81543, Util.getIntValue(7)); WorkflowActionManager workflowActionManager = new WorkflowActionManager(); workflowActionManager.setActionid(0); workflowActionManager.setActionname(field003Name); workflowActionManager.setWorkflowid(StringUtil.parseToInt(workflowid)); workflowActionManager.setNodeid(StringUtil.parseToInt(nodeid)); workflowActionManager.setNodelinkid(0); workflowActionManager.setIspreoperator(1); workflowActionManager.setActionorder(1); workflowActionManager.setInterfaceid("KqSplitAction"); workflowActionManager.setInterfacetype(3); workflowActionManager.setIsused(1); workflowActionManager.doSaveWsAction(); } } return isDone; } /** * 新考勤流程字段對應 */ public boolean upKQAttProcField() throws Exception{ RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); boolean isDone = false; String sql3 = "select * from hrm_ATT_PROC_RELATION "; rs.executeQuery(sql3); while(rs.next()){ String att_proc_relation_id = rs.getString("id"); String field001 = rs.getString("field001"); String field002 = rs.getString("field002"); String field003 = rs.getString("field003"); String field004 = rs.getString("field004"); long mfid = UUID.randomUUID().getMostSignificantBits(); String att_proc_set_id = ""; String attsetIdSql = "select * from hrm_to_attSet where hrmid="+field001; rs2.executeQuery(attsetIdSql); if(rs2.next()){ att_proc_set_id = Util.null2String(rs2.getString("kqid")); } String att_proc_field_id = ""; String attfieldIdSql = "select * from hrm_to_attfield where hrmid="+field002; rs2.executeQuery(attfieldIdSql); if(rs2.next()){ att_proc_field_id = Util.null2String(rs2.getString("kqid")); } if(att_proc_set_id.length() == 0 || att_proc_field_id.length() == 0){ continue; } String insertSql = "insert into kq_ATT_PROC_RELATION(mfid,field001,field002,field003,field004) " + " values(?,?,?,?,?) "; isDone = rs1.executeUpdate(insertSql,mfid,att_proc_set_id,att_proc_field_id,field003,field004); if(!isDone){ break; } } return isDone; } /** * 新/老 考勤流程字段生成映射 */ public void upAttProcField() throws Exception{ Map fieldMap = new HashMap<>(); RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); String sql2 = "select * from HRM_ATT_PROC_FIELDS "; rs.executeQuery(sql2); while(rs.next()){ String att_proc_field_id = rs.getString("id"); String field001 = rs.getString("field001"); String field002 = rs.getString("field002"); if("leaveDays".equalsIgnoreCase(field002)){ field002 = "duration"; } if("tilldate".equalsIgnoreCase(field002)){ field002 = "toDate"; } if("tilltime".equalsIgnoreCase(field002)){ field002 = "toTime"; } if("overtimeDays".equalsIgnoreCase(field002)){ field002 = "duration"; } if("otype".equalsIgnoreCase(field002)){ field002 = "overtime_type"; } field001 = field001.toLowerCase(); field002 = field002.toLowerCase(); String key = field001+"_"+field002; fieldMap.put(key, att_proc_field_id); } sql2 = "select * from kq_ATT_PROC_FIELDS "; rs.executeQuery(sql2); while(rs.next()){ String att_proc_field_kqid = rs.getString("id"); String field001 = rs.getString("field001"); String field002 = rs.getString("field002"); field001 = field001.toLowerCase(); field002 = field002.toLowerCase(); String key = field001+"_"+field002; if(fieldMap.get(key) != null){ String att_proc_field_id = fieldMap.get(key); String bindSql = "insert into hrm_to_attfield(hrmid,kqid) values("+att_proc_field_id+","+att_proc_field_kqid+") "; boolean isBinded = rs1.executeUpdate(bindSql); } } } /** * 考勤流程設置基本信息 */ public void upAttProcSet() throws Exception{ RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); RecordSet rs3 = new RecordSet(); RecordSet rs4 = new RecordSet(); Map tableMap = new HashMap<>(); String tablenameSql = "select * from workflow_bill where id in(select field002 from hrm_att_proc_set)"; rs4.execute(tablenameSql); while(rs4.next()){ String formid = rs4.getString("id"); String tablename = rs4.getString("tablename"); tableMap.put(formid, tablename); } String sql1 = "select * from hrm_att_proc_set "; rs.executeQuery(sql1); while(rs.next()){ String att_proc_set_id = rs.getString("id"); String field001 = rs.getString("field001"); String field002 = rs.getString("field002"); String field003 = rs.getString("field003"); String field004 = rs.getString("field004"); String field005 = rs.getString("field005"); String field006 = rs.getString("field006"); String field007 = rs.getString("field007"); String field008 = rs.getString("field008"); String field009 = rs.getString("field009"); String field010 = rs.getString("field010"); String field011 = rs.getString("field011"); String field012 = rs.getString("field012"); String field013 = rs.getString("field013"); String field014 = rs.getString("field014"); String field015 = rs.getString("field015"); long mfid = UUID.randomUUID().getLeastSignificantBits(); int ishalfday = Util.getIntValue(rs.getString("ishalfday"),-1); String tablename = Util.null2String(tableMap.get(field002)); String usedetail = "0"; String custompage = ""; String custompage4Emoble = ""; String templetroute = ""; switch (field006){ case "0" : custompage = KqTempletEnum.LEAVE.getTempletfile(); custompage4Emoble = KqTempletEnum.LEAVE.getTempletmobilefile(); templetroute = KqTempletEnum.LEAVE.getTempletroute(); break; case "1" : custompage = KqTempletEnum.EVECTION.getTempletfile(); custompage4Emoble = KqTempletEnum.EVECTION.getTempletmobilefile(); templetroute = KqTempletEnum.EVECTION.getTempletroute(); break; case "2" : custompage = KqTempletEnum.OUT.getTempletfile(); custompage4Emoble = KqTempletEnum.OUT.getTempletmobilefile(); templetroute = KqTempletEnum.OUT.getTempletroute(); break; case "3" : custompage = KqTempletEnum.OVERTIME.getTempletfile(); custompage4Emoble = KqTempletEnum.OVERTIME.getTempletmobilefile(); templetroute = KqTempletEnum.OVERTIME.getTempletroute(); break; case "4" : custompage = KqTempletEnum.OTHER.getTempletfile(); custompage4Emoble = KqTempletEnum.OTHER.getTempletmobilefile(); templetroute = KqTempletEnum.OTHER.getTempletroute(); break; case "5" : custompage = KqTempletEnum.SHIFT.getTempletfile(); custompage4Emoble = KqTempletEnum.SHIFT.getTempletmobilefile(); templetroute = KqTempletEnum.SHIFT.getTempletroute(); break; case "6" : custompage = KqTempletEnum.LEAVEBACK.getTempletfile(); custompage4Emoble = KqTempletEnum.LEAVEBACK.getTempletmobilefile(); templetroute = KqTempletEnum.LEAVEBACK.getTempletroute(); break; default: break; } String insertSql = "insert into kq_ATT_PROC_SET(field001,field002,field003,field004,field005," + "field006,field007,field008,field009,field010,field011,field012,field013,field014,field015," + "mfid,ishalfday,usedetail,templetroute,templetmobilefile,templetfile,tablename) " + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; boolean isUpdated = rs1.executeUpdate(insertSql,field001,field002,field003,field004,field005, field006,field007,field008,field009,field010,field011,field012, field013,field014,field015,mfid,ishalfday,usedetail,templetroute, custompage4Emoble,custompage,tablename); if(isUpdated){ rs2.executeQuery("select max(id) from kq_ATT_PROC_SET "); if(rs2.next()){ String kq_att_set_id = rs2.getString(1); String actionSql = ""; String actionSql1 = ""; String actionSql2 = ""; String actionSql3 = ""; switch (field006){ case "0" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','81543',0,-1,-1,1,4)"; actionSql1 = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqDeductionVacationAction','82823,25842',0,-1,-1,1,1)"; actionSql2 = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqFreezeVacationAction','1232,25842',0,-1,-1,1,2)"; actionSql3 = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqReleaseVacationAction','82824,25842',0,-1,-1,1,3)"; break; case "1" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','81543',0,-1,-1,1,1)"; break; case "2" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','81543',0,-1,-1,1,1)"; break; case "3" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','81543',0,-1,-1,1,2)"; actionSql1 = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqPaidLeaveAction','126739',0,-1,-1,1,1)"; break; case "4" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','81543',0,-1,-1,1,1)"; break; case "5" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','390737',0,-1,-1,1,1)"; break; case "6" : actionSql = "insert into kq_ATT_PROC_ACTION(mfid,field001,field002,field003,field004,field005,field006,field007,field008) values(-1,"+kq_att_set_id+",'KqSplitAction','81543',0,-1,-1,1,1)"; break; default: break; } if(actionSql.length() > 0){ rs3.execute(actionSql); } if(actionSql1.length() > 0){ rs3.execute(actionSql1); } if(actionSql2.length() > 0){ rs3.execute(actionSql2); } if(actionSql3.length() > 0){ rs3.execute(actionSql3); } HrmAttProcSetManager attProcSetManager = new HrmAttProcSetManager(); attProcSetManager.welcomeToSet(Util.getIntValue(field001), Util.getIntValue(field006),custompage,custompage4Emoble,templetroute); String bindSql = "insert into hrm_to_attSet(hrmid,kqid) values("+att_proc_set_id+","+kq_att_set_id+") "; boolean isBinded = rs4.executeUpdate(bindSql); } } } } /** * 请假类型数据迁移 * @param year */ public boolean upLeave(String year) { boolean isLeaveDone = true; try { Map leaveMap = new HashMap<>(); upLeaveRule(); //TODO 正式系统的历史数据excel导入,这里不做处理 if(!leaveMap.isEmpty() && false){ isLeaveDone = upLeaveData(leaveMap,year); } }catch (Exception e){ isLeaveDone = false; e.printStackTrace(); } return isLeaveDone; } /** * 根据假期规则生成相应的假期数据 * @param leaveMap * @param year */ public boolean upLeaveData(Map leaveMap,String year) throws Exception{ boolean isLeaveDataDone = true; for(Map.Entry me : leaveMap.entrySet()){ String leaveid = me.getKey(); String leavecode = me.getValue(); switch (leavecode){ case "annualLeave": upAnnual(); break; case "vacationLeave": upOvertimePiad(); break; default: upPaid(); break; } } return isLeaveDataDone; } /** * 迁移带薪数据 */ public void upPaid() { RecordSet rs = new RecordSet(); String insertSql = "insert into kq_BalanceOfLeave(leaverulesid,resourceid,belongyear,extraAmount,status) select leavetype,resourceid,pslyear,psldays,0 from hrmpslmanagement where status = 1 and pslyear is not null or pslyear !='' "; rs.executeUpdate(insertSql); } /** * 迁移调休数据 */ public void upOvertimePiad() { RecordSet rs = new RecordSet(); String curYear = DateUtil.getYear(DateUtil.getCalendar()); String firstdate = DateUtil.getFirstDayOfYear(DateUtil.getCurrentDate()); String enddate = DateUtil.getLastDayOfYear(DateUtil.getCurrentDate()); String insertSql = "insert into kq_BalanceOfLeave(leaverulesid,resourceid,belongyear,extraAmount,status) values(?,?,?,?,?)"; List params = new ArrayList(); HrmPaidLeaveTimeManager paidLeaveTimeManager = new HrmPaidLeaveTimeManager(); Map otherparams = new HashMap<>(); otherparams.put("fromdate", firstdate); otherparams.put("enddate", enddate); otherparams.put("sql_field001", " and field001 >0 "); Map paramMap = new HashMap(); Iterator it = otherparams.entrySet().iterator(); while(it.hasNext()){ Map.Entry entry = (Map.Entry) it.next(); paramMap.put((String)entry.getKey(), (String)entry.getValue()); } List tList = paidLeaveTimeManager.find(paramMap); for(HrmPaidLeaveTime paidLeaveTime : tList){ Long resourceid = paidLeaveTime.getId(); String extraVal = String.valueOf(paidLeaveTime.getField004()); List beanParams = new ArrayList(); beanParams.add("-13"); beanParams.add(resourceid); beanParams.add(curYear); beanParams.add(extraVal); beanParams.add("0"); params.add(beanParams); } boolean isOk = rs.executeBatchSql(insertSql, params); } /** * 迁移年假数据 */ public void upAnnual() { RecordSet rs = new RecordSet(); String insertSql = "insert into kq_BalanceOfLeave(leaverulesid,resourceid,belongyear,extraAmount,status) select -6,resourceid,annualyear,annualdays,0 from HrmAnnualManagement where status = 1 and resourceid is not null "; rs.executeUpdate(insertSql); } /** * 升级假期规则 * @return * @throws Exception */ public void upLeaveRule() throws Exception{ RecordSet rs = new RecordSet(); RecordSet recordSet = new RecordSet(); //请假类型 数据迁移 String leaveSql = " select * from hrmleavetypecolor order by field006 "; rs.execute(leaveSql); while (rs.next()) { String leaveid = rs.getString("id"); String leaveName = ""+Util.formatMultiLang(rs.getString("field001"),"7")+""; String isuse = rs.getString("field002"); String leavecode = rs.getString("field004"); String iscalworkday = rs.getString("iscalworkday"); //自然日调配按照周几计算时长无法迁移,这个地方定死一个值吧 hoursToDay int relateweekday = Util.getIntValue(rs.getString("relateweekday")); String ispaidleave = rs.getString("ispaidleave"); String leavecodeRule = ""; int scopeType = 0; String scopeValue = ""; int minimumUnit = 1; int hoursToDay = 8; int computingMode = 1; int isEnable = 1; int balanceEnable = 0; int distributionMode = 1; int annualAmount = 0; int priority = 1; int validityRule = 0;//不限制 String expirationMonth = ""; String expirationDay = ""; int extensionEnable = 0; int extendedDays = 0; int releaseRule = 0; if (!"1".equalsIgnoreCase(isuse)) { isEnable = 0; } if ("0".equalsIgnoreCase(iscalworkday)) { computingMode = 2; } if ("1".equalsIgnoreCase(ispaidleave)) { balanceEnable = 1; } if ("-6".equalsIgnoreCase(leavecode)) { balanceEnable = 1; leavecodeRule = "annualLeave"; } if ("-12".equalsIgnoreCase(leavecode)) { leavecodeRule = "paidSickLeave"; balanceEnable = 1; } if ("-13".equalsIgnoreCase(leavecode)) { balanceEnable = 1; leavecodeRule = "vacationLeave"; distributionMode = 5; minimumUnit = 3; } boolean flag = false;//数据是否插入成功 String sql = "insert into kq_LeaveRules(Id,leaveName,scopeType,scopeValue,minimumUnit,computingMode,hoursToDay,balanceEnable,isEnable,isDelete,leavecode) values(?,?,?,?,?,?,?,?,?,?,?)"; flag = recordSet.executeUpdate(sql, leavecode, leaveName, scopeType, scopeValue, minimumUnit, computingMode, hoursToDay, balanceEnable, isEnable, 0,leavecodeRule); if (!flag) { kqLog.info("升级假期规则 upLeaveRule 失败 :hrmleavetypecolor:field004: "+leavecode); break; } String bindSql = "insert into hrm_to_kq_LeaveRules(hrmid,kqid) values(?,?) "; boolean isBind = recordSet.executeUpdate(bindSql,leaveid,leavecode); if(isBind && balanceEnable == 1){ //带薪假和系统假期都需要处理下请假类型明细设置 sql = "insert into kq_LeaveRulesDetail(ruleId,ruleName,scopeType,scopeValue," + "distributionMode,annualAmount,priority,validityRule,expirationMonth,expirationDay,extensionEnable,extendedDays,releaseRule,calcMethod,isDelete) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)"; flag = recordSet.executeUpdate(sql, leavecode, leaveName+"规则", scopeType, scopeValue, distributionMode, annualAmount, priority, validityRule, expirationMonth, expirationDay, extensionEnable, extendedDays, releaseRule, 0); } } refreshCominfo(); } /** * 如果升级错了,或者需要重新升级需要先删除数据 * @return */ public boolean refreshData(){ try{ List delSql = new ArrayList<>(); delSql.add("delete from kq_group "); delSql.add("delete from kq_fixedschedulce "); delSql.add("delete from kq_groupmember "); delSql.add("delete from kq_ShiftManagement "); delSql.add("delete from kq_ShiftRestTimeSections "); delSql.add("delete from kq_ShiftOnOffWorkSections "); delSql.add("delete from kq_shiftschedule "); delSql.add("delete from kq_LeaveRules "); delSql.add("delete from kq_balanceOfLeave "); delSql.add("delete from KQ_HOLIDAYSET "); delSql.add("delete from kq_OvertimeRules "); delSql.add("delete from kq_OvertimeRulesDetail "); delSql.add("delete from kq_att_proc_set "); delSql.add("delete from kq_ATT_PROC_RELATION "); delSql.add("delete from kq_ATT_PROC_ACTION where field001 <>'-1' "); delSql.add("delete from kq_flow_split_leave "); delSql.add("delete from kq_flow_split_evection "); delSql.add("delete from kq_flow_split_out "); delSql.add("delete from kq_flow_split_overtime "); RecordSet rs = new RecordSet(); for(String del : delSql){ rs.executeUpdate(del); } return true; }catch (Exception e){ e.printStackTrace(); return false; } } /** * 排班人员升级 * 升级 考勤组+班次 * @return */ public void upScheduleGroupData() throws Exception{ RecordSet rs0 = new RecordSet(); RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); RecordSet rs3 = new RecordSet(); RecordSet rs4 = new RecordSet(); RecordSet rs5 = new RecordSet(); RecordSet rs6 = new RecordSet(); RecordSet rs7 = new RecordSet(); RecordSet rs8 = new RecordSet(); RecordSet rs9 = new RecordSet(); ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo(); boolean hrmdetachable = manageDetachComInfo.isUseHrmManageDetach();//是否开启了人力资源模块的管理分权 String hrmdftsubcomid = manageDetachComInfo.getHrmdftsubcomid();//分权默认分部 String shiftsetSql = "select * from hrm_schedule_shifts_set where delflag=0 "; rs0.executeQuery(shiftsetSql); while (rs0.next()) { String shifts_set_id = rs0.getString("id"); String groupname = "排班("+Util.formatMultiLang(rs0.getString("field001"),"7")+")"; int subcompanyid = Util.getIntValue(rs0.getString("field002"), 0); if(hrmdetachable){ subcompanyid = Util.getIntValue(hrmdftsubcomid); } boolean is4worklen = false; String shiftOnOffWorkCount = "1"; String isresttimeopen = "0"; String[] worktimeids = null; String getworkTimeSql = "select * from hrm_schedule_shifts_detail where field001='" + shifts_set_id + "' and delflag=0 "; rs1.executeQuery(getworkTimeSql); kqLog.info("upScheduleGroupData getworkTimeSql:"+getworkTimeSql); if (rs1.next()) { String worktimeid = rs1.getString("field002"); worktimeids = worktimeid.split(";"); if (worktimeids.length == 1) { shiftOnOffWorkCount = "1"; }else if(worktimeids.length == 2){ shiftOnOffWorkCount = "2"; }else if(worktimeids.length == 3){ shiftOnOffWorkCount = "3"; }else{ is4worklen = true; } } if(is4worklen){ continue; } String worktimes = ""; if(worktimeids != null){ for(String workid : worktimeids){ worktimes += ","+workid; } } if(worktimes.length() > 0){ worktimes = worktimes.substring(1); } if(worktimes.length() > 0){ List timesList = new ArrayList<>(); String uuid = UUID.randomUUID().toString(); int worktime = 0; String serials = "排班"; String serialname= ""; String serialcontent= ""; String punchsettings= "1"; String isoffdutyfreecheck= "0"; String worktimeSql = "select * from hrm_schedule_worktime where delflag=0 and id in ("+worktimes+") order by field002"; rs.execute(worktimeSql); while(rs.next()) { String worktimename = Util.null2s(rs.getString("field001"),""); String starttime = Util.null2s(rs.getString("field002"),""); String endtime = Util.null2s(rs.getString("field003"),""); String starttime_min = Util.null2s(rs.getString("field004"),""); String endtime_min = Util.null2s(rs.getString("field005"),""); String workhour = Util.null2s(rs.getString("field007"),""); worktime += Util.getDoubleValue(workhour)*60; if(serialname.length() > 0){ serialname += ";"+worktimename; serialcontent += ";"+(starttime+"-"+endtime); }else { serialname += worktimename; serialcontent += (starttime+"-"+endtime); } Map timeMap = new HashMap<>(); timeMap.put("starttime", starttime); timeMap.put("endtime", endtime); timeMap.put("starttime_min", starttime_min); timeMap.put("endtime_min", endtime_min); timesList.add(timeMap); } if(serialname.length() > 0){ serials += "("+Util.formatMultiLang(serialname,"7")+")"; } String serialSql = "insert into kq_ShiftManagement(serial,subcompanyid,shiftonoffworkcount,punchsettings,isoffdutyfreecheck,isresttimeopen,worktime,uuid,color)" + " values('"+serials+"',"+subcompanyid+","+shiftOnOffWorkCount+","+punchsettings+","+isoffdutyfreecheck+","+isresttimeopen+","+worktime+",'"+uuid+"',null)"; boolean isSerial = rs2.executeUpdate(serialSql); kqLog.info("upScheduleGroupData serialSql:"+serialSql+":isSerial:"+isSerial); if(isSerial) { int serialid = 0; String getSerialIdSql = "select max(id) from kq_ShiftManagement "; rs4.execute(getSerialIdSql); if(rs4.next()) { serialid = Util.getIntValue(rs4.getString(1)); if(serialid > 0){ String bindSql = "insert into hrm_to_kq_serial(hrmid,kqid,serial,serialfrom) values(" + shifts_set_id + "," + serialid + ",'"+serialcontent+"','shiftset') "; boolean isBinded = rs3.executeUpdate(bindSql); kqLog.info("upScheduleGroupData bindSql:"+bindSql+":isBinded:"+isBinded); for(int i = 0 ; i < timesList.size() ; i++){ Map tmpTimeMap = (Map) timesList.get(i); String starttime = Util.null2s(tmpTimeMap.get("starttime"),""); String endtime = Util.null2s(tmpTimeMap.get("endtime"),""); String starttime_min = Util.null2s(tmpTimeMap.get("starttime_min"),"30"); String endtime_min = Util.null2s(tmpTimeMap.get("endtime_min"),"30"); String across = "0"; String workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+","+across+","+starttime_min+",'"+starttime+"','start',"+i+",0)"; boolean isSection = rs3.executeUpdate(workSql); kqLog.info("upScheduleGroupData workSql:"+workSql+":isSection:"+isSection); if(starttime.compareTo(endtime) > 0){ across = "1"; } workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+","+across+","+endtime_min+",'"+endtime+"','end',"+i+",0)"; isSection = rs3.executeUpdate(workSql); kqLog.info("upScheduleGroupData workSql:"+workSql+":isSection:"+isSection); } String groupSql = " insert into kq_group (" + " groupname,subcompanyid,excludeid,kqtype,shiftcyclename,shiftcycleday,shiftcycleserialids,serialids," + " weekday,signstart,workhour,signintype,validity,validityfromdate,validityenddate,locationcheckscope) " + " values('"+groupname+"',"+subcompanyid+",null,2,null,null,null,'"+serialid+"',null,null,null,1,0,null,null,300)"; boolean isOk = rs5.executeUpdate(groupSql); kqLog.info("groupSql:"+groupSql); if(isOk){ int groupid = 0; String getGroupIdSql = "select max(id) from kq_group "; rs6.execute(getGroupIdSql); if(rs6.next()){ groupid = Util.getIntValue(rs6.getString(1)); } if(groupid > 0) { bindSql ="insert into hrm_to_kq_group(hrmid,kqid,groupfrom) values(" + shifts_set_id + "," + groupid + ",'shiftset') "; isBinded = rs6.executeUpdate(bindSql); if (isBinded) { String memSql = " INSERT INTO kq_groupmember ( groupid ,typevalue ,type ,alllevel ," + " seclevel ,seclevelto ,jobtitlelevelvalue ,jobtitlelevel,validatefrom,validateto) " + " VALUES (? ,? ,? ,?,? ,? ,? ,?, ?, ?)"; List params = new ArrayList(); List resourceids = new ArrayList<>(); String shiftDetail =" select * from hrm_schedule_set_detail where delflag=0 and field001 = '" + shifts_set_id + "'";; rs7.executeQuery(shiftDetail); kqLog.info("shiftDetail:"+shiftDetail); while (rs7.next()) { String resourceid = rs7.getString("field002"); if (!resourceids.contains(resourceid)) { List beanParams = new ArrayList(); beanParams.add(groupid); beanParams.add(resourceid); beanParams.add(1); beanParams.add(null); beanParams.add(0); beanParams.add(100); beanParams.add(null); beanParams.add(null); beanParams.add(KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); beanParams.add(KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); params.add(beanParams); resourceids.add(resourceid); } } kqLog.info("params:"+params); boolean isMemDone = rs8.executeBatchSql(memSql, params); if (isMemDone) { String detailsql = ""; if(rs.getDBType().equals("oracle")){ detailsql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid) " + "select field003,(case when nvl(FIELD005,'-1')='-1' then '-1' when nvl(FIELD005,'')='' then '-1' else '"+serialid+"' end ),field002," + groupid + " from hrm_schedule_set_detail where delflag=0 and field001 = '" + shifts_set_id + "'"; }else if(rs.getDBType().equals("mysql")){ detailsql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid) " + "select field003,(case when ifnull(FIELD005,'-1')='-1' then '-1' when ifnull(FIELD005,'')='' then '-1' else '"+serialid+"' end ),field002," + groupid + " from hrm_schedule_set_detail where delflag=0 and field001 = '" + shifts_set_id + "'"; }else{ detailsql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid) " + "select field003,(case when isnull(FIELD005,'-1')='-1' then '-1' when isnull(FIELD005,'')='' then '-1' else '"+serialid+"' end ),field002," + groupid + " from hrm_schedule_set_detail where delflag=0 and field001 = '" + shifts_set_id + "'"; } kqLog.info("detailsql:"+detailsql); boolean isDetailDone = rs8.executeUpdate(detailsql); } } } } } } } } } refreshCominfo(); } /** * 排班人员 更新考勤组成员和具体设置排班数据 * @param groupidMap * @param year */ public boolean upScheduleGroupMem(Map groupidMap,Map groupSerialMap,String year) { RecordSet rs_shiftdetail = new RecordSet(); RecordSet rs_groupmem = new RecordSet(); RecordSet rs_scheduledetail = new RecordSet(); String firstdate = DateUtil.getFirstDayOfYear(year + "-01-01"); String enddate = DateUtil.getLastDayOfYear(year + "-01-01"); boolean isDetailDone = true; //3、考勤组成员搞一波 for (Map.Entry groupdetail : groupidMap.entrySet()) { List params = new ArrayList(); List resourceids = new ArrayList<>(); String groupid = groupdetail.getKey(); String shifts_set_id = groupdetail.getValue(); String shiftDetail = " select * from hrm_schedule_set_detail where delflag=0 and field003 between '" + firstdate + "' and '" + enddate + "'"; if (shifts_set_id.length() == 0) { continue; } String serialid = Util.null2String(groupSerialMap.get(groupid), "-1"); shiftDetail += " and field001 = '" + shifts_set_id + "'"; rs_shiftdetail.executeQuery(shiftDetail); while (rs_shiftdetail.next()) { String resourceid = rs_shiftdetail.getString("field002"); if (!resourceids.contains(resourceid)) { List beanParams = new ArrayList(); beanParams.add(groupid); beanParams.add(resourceid); beanParams.add(1); beanParams.add(null); beanParams.add(0); beanParams.add(100); beanParams.add(null); beanParams.add(null); beanParams.add(KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE); beanParams.add(KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); params.add(beanParams); resourceids.add(resourceid); } } String memSql = " INSERT INTO kq_groupmember ( groupid ,typevalue ,type ,alllevel ," + " seclevel ,seclevelto ,jobtitlelevelvalue ,jobtitlelevel,validatefrom,validateto) " + " VALUES (? ,? ,? ,?,? ,? ,? ,?,?,?)"; if (!params.isEmpty()) { boolean isMemDone = rs_groupmem.executeBatchSql(memSql, params); if (isMemDone) { String detailsql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid) " + "select field003," + serialid + ",field002," + groupid + " from hrm_schedule_set_detail where delflag=0 and field003 between '" + firstdate + "' and '" + enddate + "' and field001 = '" + shifts_set_id + "'"; isDetailDone = rs_scheduledetail.executeUpdate(detailsql); if (!isDetailDone) { break; } } } } return isDetailDone; } /** * 排班人员 考勤组里设置下班次 * @param groupSerialMap * @return */ public boolean upScheduleGroupSerial(Map groupSerialMap) { RecordSet rs_groupschedule = new RecordSet(); boolean isUpGroupDone = true; for (Map.Entry me : groupSerialMap.entrySet()) { String groupid = me.getKey(); String serialid = me.getValue(); String updteGroupSrial = "update kq_group set serialids = ? where id= ? "; isUpGroupDone = rs_groupschedule.executeUpdate(updteGroupSrial, serialid, groupid); if (!isUpGroupDone) { break; } } return isUpGroupDone; } /** * 升级排班人员 班次数据 * @param groupidMap * @param groupidShiftMap * @param groupSerialMap * @param worktimeSerialMap * @param year * @param upSignSql */ public void upScheduleSerial(Map groupidMap,Map groupidShiftMap, Map groupSerialMap, Map worktimeSerialMap, String year,List upSignSql) { String worktimeSep = ";"; RecordSet rs = new RecordSet(); RecordSet rs_shift = new RecordSet(); RecordSet rs_shift1 = new RecordSet(); RecordSet rs_shift2 = new RecordSet(); RecordSet rs_shift3 = new RecordSet(); String mainSql = "insert into kq_ShiftManagement(serial,subcompanyid,shiftonoffworkcount,punchsettings,isoffdutyfreecheck,isresttimeopen,worktime,uuid,color)" + " values(?,?,?,?,?,?,?,?,?)"; String shiftOnOffWorkCount = "1"; //针对考勤组 然后对应班次 for (Map.Entry me : groupidShiftMap.entrySet()) { String groupid = me.getKey(); String worktimeid = me.getValue(); String shifts_set_id = groupidMap.get(groupid); String[] worktimeids = worktimeid.split(worktimeSep); String shiftworktimeSql = "select * from hrm_schedule_worktime where delflag=0 "; if (worktimeids.length == 3) { String worktimeid1 = worktimeids[0]; String worktimeid2 = worktimeids[1]; String worktimeid3 = worktimeids[2]; shiftworktimeSql += " and id in (" + worktimeid1 + "," + worktimeid2 + "," + worktimeid3 + ") "; shiftOnOffWorkCount = "3"; } else if (worktimeids.length == 2) { String worktimeid1 = worktimeids[0]; String worktimeid2 = worktimeids[1]; shiftworktimeSql += " and id in (" + worktimeid1 + "," + worktimeid2 + ") "; shiftOnOffWorkCount = "2"; } else if (worktimeids.length == 1) { String worktimeid1 = worktimeids[0]; shiftworktimeSql += " and id in (" + worktimeid1 + ") "; shiftOnOffWorkCount = "1"; } else { //当前E9就支持最多三个班次 rs.writeLog("班次创建失败,当前E9就支持最多三个班次"); } shiftworktimeSql += " order by field002 "; List> workserctionList = new ArrayList<>(); String serailname = ""; int workminTotal = 0; rs.executeQuery(shiftworktimeSql); while (rs.next()) { Map workserctionMap = new HashMap<>(); String serial = rs.getString("field001"); serailname += "," + serial; String starttime = rs.getString("field002"); String endtime = rs.getString("field003"); String starttime_min = rs.getString("field004"); String endtime_min = rs.getString("field005"); String workhour = rs.getString("field007"); workminTotal += (Util.getDoubleValue(workhour, 0.0) * 60.0); String startacross = "0"; String endacross = "0"; if (starttime.compareTo(endtime) > 0) { endacross = "1"; } workserctionMap.put("starttime", starttime); workserctionMap.put("endtime", endtime); workserctionMap.put("starttime_min", starttime_min); workserctionMap.put("endtime_min", endtime_min); workserctionMap.put("startacross", startacross); workserctionMap.put("endacross", endacross); workserctionList.add(workserctionMap); } //获取更新签到签退的sql upScheduleSignSql(workserctionList,year,upSignSql,shifts_set_id); if (serailname.length() > 0) { serailname = serailname.substring(1); } String subcompanyid = null; String punchSettings = null; String isOffDutyFreeCheck = null; String isRestTimeOpen = null; String uuid = UUID.randomUUID().toString(); String color = null; String worktime = workminTotal + ""; boolean isUpdated = rs_shift .executeUpdate(mainSql, serailname, subcompanyid, shiftOnOffWorkCount, punchSettings, isOffDutyFreeCheck, isRestTimeOpen, worktime, uuid, color); if (isUpdated) { int serialid = 0; String idSql = "select id from kq_ShiftManagement where uuid=? "; rs_shift1.executeQuery(idSql, uuid); if (rs_shift1.next()) { serialid = rs_shift1.getInt("id"); } if (serialid > 0) { String workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) values(?,?,?,?,?,?,?)"; int record = 0; for (Map workMap : workserctionList) { String starttime = workMap.get("starttime"); String endtime = workMap.get("endtime"); String starttime_min = workMap.get("starttime_min"); String endtime_min = workMap.get("endtime_min"); String startacross = workMap.get("startacross"); String endacross = workMap.get("endacross"); boolean issectionOK = rs_shift3 .executeUpdate(workSql, serialid, startacross, starttime_min, starttime, "start", record + "",0); if (issectionOK) { issectionOK = rs_shift3 .executeUpdate(workSql, serialid, endacross, endtime_min, endtime, "end", record + "",0); } record++; } groupSerialMap.put(groupid, serialid + ""); worktimeSerialMap.put(worktimeid, serialid + ""); } } } } /** * 更新排班人员的签到签退数据 * @param workserctionList * @param year * @param upSignSql * @param shifts_set_id */ public void upScheduleSignSql(List> workserctionList, String year, List upSignSql, String shifts_set_id) { String firstdate = DateUtil.getFirstDayOfYear(year + "-01-01"); String enddate = DateUtil.getLastDayOfYear(year + "-01-01"); int cnt = workserctionList.size(); for(int i = 0 ; i < cnt ;i++){ Map workserctionMap = workserctionList.get(i); String starttime = workserctionMap.get("starttime"); String endtime = workserctionMap.get("endtime"); int starttime_min = Util.getIntValue(workserctionMap.get("starttime_min"),0); int endtime_min = Util.getIntValue(workserctionMap.get("endtime_min"),0); String startacross = workserctionMap.get("startacross"); String endacross = workserctionMap.get("endacross"); if("1".equalsIgnoreCase(endacross)){ new BaseBean().writeLog("排班数据存在跨天,不处理跨天的签到签退数据!"); } if(endtime.length() == 0){ return ; } String worksection = starttime + "-" + endtime; DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); LocalTime canStartTime = LocalTime.parse(starttime+":00",dateTimeFormatter).minusMinutes(starttime_min); LocalTime canEndTime = LocalTime.parse(endtime+":00",dateTimeFormatter).plusMinutes(endtime_min); String canSignInTime = canStartTime.format(dateTimeFormatter); String canSignOutTime = canEndTime.format(dateTimeFormatter); String signWhere = " and userid in (select field002 from hrm_schedule_set_detail where delflag=0 and field001 in(select id from hrm_schedule_shifts_set where delflag=0 and id='"+shifts_set_id+"') and field003 between '"+firstdate+"' and '"+enddate+"') and signdate between '"+firstdate+"' and '"+enddate+"'"; String signSql1 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection+"' , belongtime='"+starttime+"' where signtype=1 and signtime >= '"+canSignInTime+"' and signtime <= '"+canSignOutTime+"' "+signWhere; upSignSql.add(signSql1); String signSql2 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection+"' , belongtime='"+endtime+"' where signtype=2 and signtime >= '"+canSignInTime+"' and signtime <= '"+canSignOutTime+"' "+signWhere; upSignSql.add(signSql2); } } /** * 一般工作时间 * 升级三类数据 考勤组 + 班次 * @return */ public void upCommonGroupData() throws Exception{ RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); RecordSet rs4 = new RecordSet(); RecordSet rs5 = new RecordSet(); SubCompanyComInfo sci = new SubCompanyComInfo(); ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo(); boolean hrmdetachable = manageDetachComInfo.isUseHrmManageDetach();//是否开启了人力资源模块的管理分权 String hrmdftsubcomid = manageDetachComInfo.getHrmdftsubcomid();//分权默认分部 String scheduleSql = "select * from hrmschedule where scheduletype >= 3 ORDER BY scheduletype "; rs.execute(scheduleSql); while(rs.next()) { String id = rs.getString("id"); String scheduletype = rs.getString("scheduletype"); String relatedid = Util.null2String(rs.getString("relatedid"), "0"); String validedatefrom = rs.getString("validedatefrom"); String validedateto = rs.getString("validedateto"); String needsign = rs.getString("needsign"); String onlyworkday = rs.getString("onlyworkday"); String signtimescope = rs.getString("signtimescope"); String signipscope = rs.getString("signipscope"); String sign_type = rs.getString("sign_type"); String sign_start_time = rs.getString("sign_start_time"); String subcompanyid = "0"; if(hrmdetachable){ subcompanyid = hrmdftsubcomid; } // 0周一 1周二 2周三 3周四 4周五 5周六 6周日 String monstarttime1 = rs.getString("monstarttime1"); String monendtime1 = rs.getString("monendtime1"); String monstarttime2 = rs.getString("monstarttime2"); String monendtime2 = rs.getString("monendtime2"); if(monstarttime1.length() > 0 && monendtime1.length() > 0 && monstarttime2.length() > 0 && monendtime2.length() > 0){ setSerial(monstarttime1, monendtime1, monstarttime2, monendtime2, subcompanyid, sign_type, id, "0",sign_start_time); } String tuestarttime1 = rs.getString("tuestarttime1"); String tueendtime1 = rs.getString("tueendtime1"); String tuestarttime2 = rs.getString("tuestarttime2"); String tueendtime2 = rs.getString("tueendtime2"); if(tuestarttime1.length() > 0 && tueendtime1.length() > 0 && tuestarttime2.length() > 0 && tueendtime2.length() > 0){ setSerial(tuestarttime1, tueendtime1, tuestarttime2, tueendtime2, subcompanyid, sign_type, id, "1",sign_start_time); } String wedstarttime1 = rs.getString("wedstarttime1"); String wedendtime1 = rs.getString("wedendtime1"); String wedstarttime2 = rs.getString("wedstarttime2"); String wedendtime2 = rs.getString("wedendtime2"); if(wedstarttime1.length() > 0 && wedendtime1.length() > 0 && wedstarttime2.length() > 0 && wedendtime2.length() > 0){ setSerial(wedstarttime1, wedendtime1, wedstarttime2, wedendtime2, subcompanyid, sign_type, id, "2",sign_start_time); } String thustarttime1 = rs.getString("thustarttime1"); String thuendtime1 = rs.getString("thuendtime1"); String thustarttime2 = rs.getString("thustarttime2"); String thuendtime2 = rs.getString("thuendtime2"); if(thustarttime1.length() > 0 && thuendtime1.length() > 0 && thustarttime2.length() > 0 && thuendtime2.length() > 0){ setSerial(thustarttime1, thuendtime1, thustarttime2, thuendtime2, subcompanyid, sign_type, id, "3",sign_start_time); } String fristarttime1 = rs.getString("fristarttime1"); String friendtime1 = rs.getString("friendtime1"); String fristarttime2 = rs.getString("fristarttime2"); String friendtime2 = rs.getString("friendtime2"); if(fristarttime1.length() > 0 && friendtime1.length() > 0 && fristarttime2.length() > 0 && friendtime2.length() > 0){ setSerial(fristarttime1, friendtime1, fristarttime2, friendtime2, subcompanyid, sign_type, id, "4",sign_start_time); } String satstarttime1 = rs.getString("satstarttime1"); String satendtime1 = rs.getString("satendtime1"); String satstarttime2 = rs.getString("satstarttime2"); String satendtime2 = rs.getString("satendtime2"); if(satstarttime1.length() > 0 && satendtime1.length() > 0 && satstarttime2.length() > 0 && satendtime2.length() > 0){ setSerial(satstarttime1, satendtime1, satstarttime2, satendtime2, subcompanyid, sign_type, id, "5",sign_start_time); } String sunstarttime1 = rs.getString("sunstarttime1"); String sunendtime1 = rs.getString("sunendtime1"); String sunstarttime2 = rs.getString("sunstarttime2"); String sunendtime2 = rs.getString("sunendtime2"); if(sunstarttime1.length() > 0 && sunendtime1.length() > 0 && sunstarttime2.length() > 0 && sunendtime2.length() > 0){ setSerial(sunstarttime1, sunendtime1, sunstarttime2, sunendtime2, subcompanyid, sign_type, id, "6",sign_start_time); } String groupname = ""; if ("3".equalsIgnoreCase(scheduletype)) { groupname += "一般工作时间:总部" + "(" + validedatefrom + "到" + validedateto + ")"; } else { groupname += "一般工作时间:分部" + "(" + Util.formatMultiLang(sci.getSubcompanyname(relatedid),"7") + ")" + "(" + validedatefrom + "到" + validedateto + ")"; } String groupSql = " insert into kq_group (" + " groupname,subcompanyid,excludeid,kqtype,shiftcyclename,shiftcycleday,shiftcycleserialids,serialids," + " weekday,signstart,workhour,signintype,validity,validityfromdate,validityenddate,locationcheckscope) " + " values('"+groupname+"',"+subcompanyid+",null,1,null,null,null,null,null,null,null,1,1,'"+validedatefrom+"','"+validedateto+"',300)"; boolean isOk = rs1.executeUpdate(groupSql); if(isOk){ int groupid = 0; String getGroupIdSql = "select max(id) from kq_group "; rs1.execute(getGroupIdSql); if(rs1.next()){ groupid = Util.getIntValue(rs1.getString(1)); } if(groupid > 0){ String bindSql = "insert into hrm_to_kq_group(hrmid,kqid,groupfrom) values("+id+","+groupid+",'scheduleset') "; boolean isBinded = rs2.executeUpdate(bindSql); if(isBinded){ String kq_signintype = "1".equalsIgnoreCase(needsign)?"1":"4"; String updateGroupInfo = " update kq_group set signintype="+kq_signintype+", ipscope='"+signipscope+"',locationcheck=null,locationcheckscope=300,wificheck=null,outsidesign=null where id= "+groupid; boolean isUpdated = rs2.executeUpdate(updateGroupInfo); if(isUpdated){ String weekSql = "select * from hrm_to_kq_group_weekday where hrmid = "+id+" order by weekday "; rs4.executeQuery(weekSql); while (rs4.next()){ String weekday = Util.null2s(rs4.getString("weekday"),""); String serialid = Util.null2s(rs4.getString("serialid"),""); String connectSql = "insert into kq_fixedschedulce(weekday,serialid,groupid) values("+weekday+","+serialid+","+groupid+")"; rs5.executeUpdate(connectSql); } String type = ""; if("3".equalsIgnoreCase(scheduletype)){ //所有人 type = "6"; }else if("4".equalsIgnoreCase(scheduletype)){ //分部 type = "2"; } String memSql = " INSERT INTO kq_groupmember ( groupid ,typevalue ,type ,alllevel ," + " seclevel ,seclevelto ,jobtitlelevelvalue ,jobtitlelevel,validatefrom,validateto) " + " VALUES ("+groupid+" ,"+relatedid+" ,"+type+" ,null,0 ,100 ,null ,null,'"+KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE+"','"+KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE+"')"; rs4.executeUpdate(memSql); } } } } } refreshCominfo(); } /** * 升级班次数据 * @param starttime1 * @param endtime1 * @param starttime2 * @param endtime2 * @param subcompanyid * @param sign_type * @param id * @param weekday * @param sign_start_time 打二次打卡时间 * @throws Exception */ public void setSerial(String starttime1,String endtime1,String starttime2,String endtime2,String subcompanyid,String sign_type,String id,String weekday,String sign_start_time) throws Exception{ try{ DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); LocalTime localTime_0 = LocalTime.parse("00:00", timeFormatter); LocalTime localTime_24 = LocalTime.parse("23:59", timeFormatter); LocalTime localTime_sign_start = null; if(sign_start_time.length() > 0){ localTime_sign_start = LocalTime.parse(sign_start_time, timeFormatter); } boolean isBinded = false; RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); RecordSet rs3 = new RecordSet(); RecordSet rs4 = new RecordSet(); RecordSet rs5 = new RecordSet(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); Duration duration1 = Duration.between( LocalTime.parse(starttime1, dtf), LocalTime.parse(endtime1, dtf)); Duration duration2 = Duration.between(LocalTime.parse(starttime2, dtf), LocalTime.parse(endtime2, dtf)); String worktime = ""+(duration1.toMinutes()+duration2.toMinutes()); String shiftOnOffWorkCount = "1"; String isresttimeopen = "1"; if("2".equalsIgnoreCase(sign_type)){ shiftOnOffWorkCount = "2"; isresttimeopen = "0"; } String uuid = UUID.randomUUID().toString(); String serial = starttime1+"-"+endtime1+" "+starttime2+"-"+endtime2; String serialContent = serial+"_"+shiftOnOffWorkCount; String checkSerial = "select * from hrm_to_kq_serial where serial='"+serialContent+"' and serialfrom ='scheduleset' "; rs4.executeQuery(checkSerial); if(rs4.next()){ String serialid = rs4.getString("kqid"); if(Util.getIntValue(serialid) > 0){ String bindSql = "insert into hrm_to_kq_group_weekday(hrmid,weekday,serialid) values(" + id + ",'"+weekday+"',"+serialid+") "; isBinded = rs2.executeUpdate(bindSql); } }else{ String serialname = "一般工作时间("+Util.formatMultiLang(serial,"7")+")"; String serialSql = "insert into kq_ShiftManagement(serial,subcompanyid,shiftonoffworkcount,punchsettings,isoffdutyfreecheck,isresttimeopen,worktime,uuid,color)" + " values('"+serialname+"',"+subcompanyid+","+shiftOnOffWorkCount+",0,0,"+isresttimeopen+","+worktime+",'"+uuid+"',null)"; boolean isSerial = rs3.executeUpdate(serialSql); if(isSerial){ int serialid = 0; String getSerialIdSql = "select max(id) from kq_ShiftManagement "; rs1.execute(getSerialIdSql); if(rs1.next()){ serialid = Util.getIntValue(rs1.getString(1)); if(serialid > 0) { int mins = 30; String bindSql = "insert into hrm_to_kq_serial(hrmid,kqid,serial,serialfrom) values(" + id + "," + serialid + ",'"+serialContent+"','scheduleset') "; isBinded = rs2.executeUpdate(bindSql); if(isBinded){ bindSql = "insert into hrm_to_kq_group_weekday(hrmid,weekday,serialid) values(" + id + ",'"+weekday+"',"+serialid+") "; isBinded = rs2.executeUpdate(bindSql); if(isBinded){ if(!"2".equalsIgnoreCase(sign_type)){ LocalTime localTime = LocalTime.parse(starttime1, timeFormatter); long start_mins = Duration.between(localTime_0, localTime).toMinutes(); String workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+",0,"+start_mins+",'"+starttime1+"','start',0,0)"; boolean isSection = rs5.executeUpdate(workSql); if(isSection){ LocalTime localTime2 = LocalTime.parse(endtime2, timeFormatter); long end_mins = Duration.between(localTime2, localTime_24).toMinutes(); workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+",0,"+end_mins+",'"+endtime2+"','end',0,0)"; rs5.executeUpdate(workSql); } }else{ LocalTime localTime = LocalTime.parse(starttime1, timeFormatter); long start_mins1 = Duration.between(localTime_0, localTime).toMinutes(); String workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+",0,"+start_mins1+",'"+starttime1+"','start',0,0)"; boolean isSection = rs5.executeUpdate(workSql); if(isSection){ LocalTime localTime2 = LocalTime.parse(endtime1, timeFormatter); long end_mins1 = Duration.between(localTime2, localTime_sign_start).toMinutes(); workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+",0,"+end_mins1+",'"+endtime1+"','end',0,0)"; isSection = rs5.executeUpdate(workSql); if(isSection){ LocalTime localTime3 = LocalTime.parse(starttime2, timeFormatter); long start_mins2 = Duration.between(localTime_sign_start, localTime3).toMinutes(); workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+",0,"+start_mins2+",'"+starttime2+"','start',1,0)"; isSection = rs5.executeUpdate(workSql); if(isSection){ LocalTime localTime4 = LocalTime.parse(endtime2, timeFormatter); long end_mins2 = Duration.between(localTime4, localTime_24).toMinutes(); workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) " + "values("+serialid+",0,"+end_mins2+",'"+endtime2+"','end',1,0)"; isSection = rs5.executeUpdate(workSql); } } } } if(!"2".equalsIgnoreCase(sign_type)){ String restSql = "insert into kq_ShiftRestTimeSections(serialid,resttype,time,across) values("+serialid+",'start','"+endtime1+"',0)"; rs5.executeUpdate(restSql); restSql = "insert into kq_ShiftRestTimeSections(serialid,resttype,time,across) values("+serialid+",'end','"+starttime2+"',0)"; rs5.executeUpdate(restSql); } } } } } } } }catch (Exception e){ e.printStackTrace(); } } /** * 工作日期调整迁移 * @return */ public void upPub() { RecordSet rs = new RecordSet(); RecordSet rs1 = new RecordSet(); RecordSet rs2 = new RecordSet(); RecordSet rs3 = new RecordSet(); RecordSet rs4 = new RecordSet(); String pubSql = "select * from hrmpubholiday"; String groupSql = " select * from hrm_to_kq_group where groupfrom = 'scheduleset' and hrmid in( select id from hrmschedule) "; rs.executeQuery(groupSql); while (rs.next()){ String groupid = Util.null2s(rs.getString("kqid"),""); if(groupid.length() >0){ rs1.executeQuery(pubSql); while (rs1.next()){ String id = Util.null2s(rs1.getString("id"),""); String holidaydate = Util.null2s(rs1.getString("holidaydate"),""); String holidayname = Util.null2s(rs1.getString("holidayname"),""); String changetype = Util.null2s(rs1.getString("changetype"),""); int relateweekday = Util.getIntValue(Util.null2s(rs1.getString("relateweekday"),"0"),0); String insertSql = "insert into KQ_HOLIDAYSET(holidaydate,holidaydesc,changetype,relatedday,groupid) " + " values('"+holidaydate+"','"+Util.formatMultiLang(holidayname,"7")+"','"+changetype+"','"+relateweekday+"','"+groupid+"')"; boolean isOk = rs2.executeUpdate(insertSql); if(isOk){ int pubid = 0; String getPubIdSql = "select max(id) from KQ_HOLIDAYSET "; rs3.execute(getPubIdSql); if(rs3.next()){ pubid = Util.getIntValue(rs3.getString(1)); } if(pubid > 0){ String bindSql = "insert into hrm_to_kq_pub(hrmid,kqid) values("+id+","+pubid+")"; rs4.executeUpdate(bindSql); } } } } } refreshCominfo(); } /** * 一般工作时间 更新签到签退数据 * @param upSignSql */ public void updateSign(List upSignSql) throws Exception{ RecordSet rs1 = new RecordSet(); for(int i = 0 ; i < upSignSql.size() ; i++){ String signSql = upSignSql.get(i); rs1.executeUpdate(signSql); } } /** * 按照E9新考勤规则 更新签到签退数据 * @param relatedid * @param signFromDate * @param signtoDate * @param sign_start_time * @param scheduletype * @param sign_type * @param worktime1s * @param upSignSql */ public void upSignSql(String relatedid, String signFromDate,String signtoDate,String sign_start_time, String scheduletype, String sign_type, String[] worktime1s, List upSignSql) { if("2".equalsIgnoreCase(sign_type)){ if(worktime1s.length == 5){ String worksection1 = worktime1s[0]+"-"+worktime1s[1]; String worksection2 = worktime1s[2]+"-"+worktime1s[3]; if("3".equalsIgnoreCase(scheduletype)){ String signSql1 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection1+"' , belongtime='"+worktime1s[0]+"' where signtype=1 and signtime <= '"+sign_start_time+"' and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql1); String signSql2 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection1+"' , belongtime='"+worktime1s[1]+"' where signtype=2 and signtime <= '"+sign_start_time+"' and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql2); String signSql3 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection2+"' , belongtime='"+worktime1s[2]+"' where signtype=1 and signtime >= '"+sign_start_time+"' and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql3); String signSql4 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection2+"' , belongtime='"+worktime1s[3]+"' where signtype=2 and signtime >= '"+sign_start_time+"' and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql4); }else if("4".equalsIgnoreCase(scheduletype)){ String signSql1 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection1+"' , belongtime='"+worktime1s[0]+"' where signtype=1 and signtime <= '"+sign_start_time+"' and userid in (select id from hrmresource where subcompanyid1 in ("+relatedid+")) and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql1); String signSql2 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection1+"' , belongtime='"+worktime1s[1]+"' where signtype=2 and signtime <= '"+sign_start_time+"' and userid in (select id from hrmresource where subcompanyid1 in ("+relatedid+")) and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql2); String signSql3 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection2+"' , belongtime='"+worktime1s[2]+"' where signtype=1 and signtime >= '"+sign_start_time+"' and userid in (select id from hrmresource where subcompanyid1 in ("+relatedid+")) and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql3); String signSql4 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection2+"' , belongtime='"+worktime1s[3]+"' where signtype=2 and signtime >= '"+sign_start_time+"' and userid in (select id from hrmresource where subcompanyid1 in ("+relatedid+")) and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql4); } } }else{ if(worktime1s.length == 5) { String worksection = worktime1s[0] + "-" + worktime1s[3]; if("3".equalsIgnoreCase(scheduletype)){ String signSql1 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection+"' , belongtime='"+worktime1s[0]+"' where signtype=1 and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql1); String signSql2 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection+"' , belongtime='"+worktime1s[3]+"' where signtype=2 and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql2); }else if("4".equalsIgnoreCase(scheduletype)){ String signSql1 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection+"' , belongtime='"+worktime1s[0]+"' where signtype=1 and userid in (select id from hrmresource where subcompanyid1 in ("+relatedid+")) and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql1); String signSql2 = "update hrmschedulesign set belongdate=signdate,worksection='"+worksection+"' , belongtime='"+worktime1s[3]+"' where signtype=2 and userid in (select id from hrmresource where subcompanyid1 in ("+relatedid+")) and signdate between '"+signFromDate+"' and '"+signtoDate+"'"; upSignSql.add(signSql2); } } } } /** * 升级关联考勤组成员 * @param memMap * @throws Exception */ public void upGroupMem(Map memMap) throws Exception{ RecordSet rs_groupmem = new RecordSet(); for(Map.Entry me : memMap.entrySet()){ String groupid = me.getKey(); String mems = me.getValue(); String[] memsArr = mems.split(separator); if(memsArr.length == 2){ String scheduletype = memsArr[0]; String type = ""; if("3".equalsIgnoreCase(scheduletype)){ //所有人 type = "6"; }else if("4".equalsIgnoreCase(scheduletype)){ //分部 type = "2"; } String relatedid = memsArr[1]; String memSql = " INSERT INTO kq_groupmember ( groupid ,typevalue ,type ,alllevel ," + " seclevel ,seclevelto ,jobtitlelevelvalue ,jobtitlelevel,validatefrom,validateto) " + " VALUES (? ,? ,? ,?,? ,? ,? ,?, ?,?)"; rs_groupmem.executeUpdate(memSql,groupid,relatedid,type,null,0,100,null,null,KQGroupBiz.GROUPMEMBER_VALIDATE_FROMDATE, KQGroupBiz.GROUPMEMBER_VALIDATE_TODATE); } } } /** * 班次生成完成,绑定考勤组和班次 * @param weekMap * @param serialMap */ public void upGroupSerial(Map weekMap, Map serialMap) throws Exception{ RecordSet rs_groupfixed = new RecordSet(); for(Map.Entry me : weekMap.entrySet()){ String groupid = me.getKey(); List fixedList = (List) me.getValue(); if(fixedList != null && !fixedList.isEmpty()){ for(int i = 0 ; i < fixedList.size() ; i++){ String worktimeKey = fixedList.get(i); String weekday = ""+i;//星期几 String serialid = ""; if(serialMap.get(worktimeKey) != null){ serialid = serialMap.get(worktimeKey); } String connectSql = "insert into kq_fixedschedulce(weekday,serialid,groupid) values(?,?,?)"; rs_groupfixed.executeUpdate(connectSql,weekday,serialid.length()==0?null:serialid,groupid); } } } } /** * 生成班次数据 * @param serialMap * @param worktimeLists */ public void upSerial(Map serialMap, List worktimeLists) throws Exception{ RecordSet rs_shift = new RecordSet(); RecordSet rs_shift1 = new RecordSet(); RecordSet rs_shift2 = new RecordSet(); RecordSet rs_shift3 = new RecordSet(); for(int i = 0 ; i < worktimeLists.size() ; i++){ String mainSql = "insert into kq_ShiftManagement(serial,subcompanyid,shiftonoffworkcount,punchsettings,isoffdutyfreecheck,isresttimeopen,worktime,uuid,color)" + " values(?,?,?,?,?,?,?,?,?)"; String times = worktimeLists.get(i); String[] timeArr = times.split(separator); if(timeArr.length == 5){ List list_work = new ArrayList<>(); List list_rest = new ArrayList<>(); String serial = "历史考勤数据:"; String worktime = ""; String subcompanyid = null; String shiftOnOffWorkCount = "1"; String punchSettings = null; String isOffDutyFreeCheck = null; String isRestTimeOpen = "1"; String uuid = UUID.randomUUID().toString(); String color = null; String work1 = timeArr[0]; String work2 = timeArr[1]; String work3 = timeArr[2]; String work4 = timeArr[3]; String sign_type = timeArr[4]; if(work1.length() == 0 || work2.length() == 0 && work3.length() == 0 && work4.length() == 0){ continue; } DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); if("2".equalsIgnoreCase(sign_type)){ list_work.add(work1+separator+work2); list_work.add(work3+separator+work4); isRestTimeOpen = "0"; serial += work1+"-"+work2+" "+work3+"-"+work4; //二次考勤 shiftOnOffWorkCount = "2"; }else{ list_work.add(work1+separator+work4); list_rest.add(work2+separator+work3); serial += work1+"-"+work4; } if(work1.length() > 0 && work2.length() > 0 && work3.length() > 0 && work4.length() > 0){ Duration duration1 = Duration.between(LocalTime.parse(work1, dtf), LocalTime.parse(work2, dtf)); Duration duration2 = Duration.between(LocalTime.parse(work3, dtf), LocalTime.parse(work4, dtf)); worktime = ""+(duration1.toMinutes()+duration2.toMinutes()); } boolean isUpdated = rs_shift.executeUpdate(mainSql, serial,subcompanyid,shiftOnOffWorkCount,punchSettings,isOffDutyFreeCheck,isRestTimeOpen,worktime,uuid,color); if(isUpdated){ int serialid = 0; String idSql = "select id from kq_ShiftManagement where uuid=? "; rs_shift1.executeQuery(idSql,uuid); if(rs_shift1.next()) { serialid = rs_shift1.getInt("id"); } if(serialid > 0){ if("1".equalsIgnoreCase(isRestTimeOpen)){ String restSql = "insert into kq_ShiftRestTimeSections(serialid,resttype,time) values(?,?,?)"; for(String rest : list_rest){ String[] rests = rest.split(separator); if(rests.length == 2){ rs_shift2.executeUpdate(restSql, serialid,"start",rests[0]); rs_shift2.executeUpdate(restSql, serialid,"end",rests[1]); } } } String workSql = "insert into kq_ShiftOnOffWorkSections(serialid,across,mins,times,onoffworktype,record,clockinnot) values(?,?,?,?,?,?,?)"; int record = 0; for(String work : list_work){ String[] works = work.split(separator); if(works.length == 2){ rs_shift3.executeUpdate(workSql, serialid,"0","",works[0],"start",record+"",0); rs_shift3.executeUpdate(workSql, serialid,"0","",works[1],"end",record+"",0); } record++; } } serialMap.put(times, serialid+""); } } } } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空一般工作时间里的升级数据 */ public void clearCommonGroupData() { RecordSet rs = new RecordSet(); String sql_1 = " delete from kq_shiftmanagement where id in(select kqid from hrm_to_kq_serial where serialfrom ='scheduleset')"; rs.executeUpdate(sql_1); String sql_2 = "delete from kq_ShiftOnOffWorkSections where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='scheduleset')"; rs.executeUpdate(sql_2); String sql_3 = "delete from kq_ShiftRestTimeSections where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='scheduleset')" ; rs.executeUpdate(sql_3); String sql_5 = "delete from hrm_to_kq_group_weekday where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='scheduleset') "; rs.executeUpdate(sql_5); String sql_6 ="delete from kq_group where id in( select kqid from hrm_to_kq_group where groupfrom = 'scheduleset')"; rs.executeUpdate(sql_6); String sql_7 ="delete from kq_fixedschedulce where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'scheduleset')"; rs.executeUpdate(sql_7); String sql_8 = "delete from kq_shiftschedule where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'scheduleset')"; rs.executeUpdate(sql_8); String sql_9 = "delete from kq_groupmember where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'scheduleset')"; rs.executeUpdate(sql_9); String sql_10 ="delete from hrm_to_kq_group where groupfrom = 'scheduleset'"; rs.executeUpdate(sql_10); String sql_4 = "delete from hrm_to_kq_serial where serialfrom ='scheduleset' "; rs.executeUpdate(sql_4); String sql_11 = "delete from kq_OvertimeRulesDetail where ruleId in(select kqid from hrm_to_kq_OverRules where rulefrom ='scheduleset') "; rs.executeUpdate(sql_11); String sql_12 = "delete from kq_OvertimeRules where id in( select kqid from hrm_to_kq_OverRules where rulefrom ='scheduleset' )"; rs.executeUpdate(sql_12); String sql_13 = "delete from hrm_to_kq_OverRules where rulefrom ='scheduleset' "; rs.executeUpdate(sql_13); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空排班时间里的升级数据 */ public void clearScheduleGroupData() { RecordSet rs = new RecordSet(); String sql_1 = " delete from kq_shiftmanagement where id in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset')"; rs.executeUpdate(sql_1); String sql_2 = "delete from kq_ShiftOnOffWorkSections where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset')"; rs.executeUpdate(sql_2); String sql_3 = "delete from kq_ShiftRestTimeSections where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset')" ; rs.executeUpdate(sql_3); String sql_5 = "delete from hrm_to_kq_group_weekday where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset') "; rs.executeUpdate(sql_5); String sql_6 ="delete from kq_group where id in( select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_6); String sql_7 ="delete from kq_fixedschedulce where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_7); String sql_8 = "delete from kq_shiftschedule where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_8); String sql_9 = "delete from kq_groupmember where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_9); String sql_10 ="delete from hrm_to_kq_group where groupfrom = 'shiftset'"; rs.executeUpdate(sql_10); String sql_4 = "delete from hrm_to_kq_serial where serialfrom ='shiftset'"; rs.executeUpdate(sql_4); String sql_11 = "delete from kq_OvertimeRulesDetail where ruleId in(select kqid from hrm_to_kq_OverRules where rulefrom ='shiftset') "; rs.executeUpdate(sql_11); String sql_12 = "delete from kq_OvertimeRules where id in( select kqid from hrm_to_kq_OverRules where rulefrom ='shiftset' )"; rs.executeUpdate(sql_12); String sql_13 = "delete from hrm_to_kq_OverRules where rulefrom ='shiftset' "; rs.executeUpdate(sql_13); } /** * 清空加班规则 */ public void clearPaidRule() { RecordSet rs = new RecordSet(); String sql_1 = " delete from kq_OvertimeRules where id in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset')"; rs.executeUpdate(sql_1); String sql_2 = "delete from kq_ShiftOnOffWorkSections where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset')"; rs.executeUpdate(sql_2); String sql_3 = "delete from kq_ShiftRestTimeSections where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset')" ; rs.executeUpdate(sql_3); String sql_5 = "delete from hrm_to_kq_group_weekday where serialid in(select kqid from hrm_to_kq_serial where serialfrom ='shiftset') "; rs.executeUpdate(sql_5); String sql_6 ="delete from kq_group where id in( select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_6); String sql_7 ="delete from kq_fixedschedulce where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_7); String sql_8 = "delete from kq_shiftschedule where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_8); String sql_9 = "delete from kq_groupmember where groupid in(select kqid from hrm_to_kq_group where groupfrom = 'shiftset')"; rs.executeUpdate(sql_9); String sql_10 ="delete from hrm_to_kq_group where groupfrom = 'shiftset'"; rs.executeUpdate(sql_10); String sql_4 = "delete from hrm_to_kq_serial where serialfrom ='shiftset'"; rs.executeUpdate(sql_4); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空请假类型的升级数据 */ public void clearLeaveRule() { RecordSet rs = new RecordSet(); String sql_1 = " delete from kq_LeaveRules where id in(select kqid from hrm_to_kq_LeaveRules)"; rs.executeUpdate(sql_1); String sql_2 = " delete from kq_LeaveRulesDetail where ruleid in(select kqid from hrm_to_kq_LeaveRules)"; rs.executeUpdate(sql_2); String sql_3 = " delete from hrm_to_kq_LeaveRules"; rs.executeUpdate(sql_3); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空工作日期调整的升级数据 */ public void clearPub() { RecordSet rs = new RecordSet(); String sql_1 = " delete from KQ_HOLIDAYSET where id in(select kqid from hrm_to_kq_pub)"; rs.executeUpdate(sql_1); String sql_2 = " delete from hrm_to_kq_pub"; rs.executeUpdate(sql_2); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空假期余额的升级数据 */ public void clearBalance(String rulesql) { RecordSet rs = new RecordSet(); String sql_1 = "delete from kq_BalanceOfLeave where leaverulesid in ("+rulesql+")"; rs.executeUpdate(sql_1); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空考勤流程设置的升级数据 */ public void clearAttSet() { RecordSet rs = new RecordSet(); String sql_1 = "delete from kq_ATT_PROC_SET where id in(select kqid from hrm_to_attSet) "; rs.executeUpdate(sql_1); String sql_2 = "delete from kq_ATT_PROC_RELATION where field001 in(select kqid from hrm_to_attSet) "; rs.executeUpdate(sql_2); String sql_3 = "delete from kq_ATT_PROC_ACTION where field001 in(select kqid from hrm_to_attSet) "; rs.executeUpdate(sql_3); String sql_4 = "delete from hrm_to_attfield "; rs.executeUpdate(sql_4); String sql_5 = "delete from hrm_to_attSet "; rs.executeUpdate(sql_5); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空考勤流程的升级数据 */ public void clearFlowData(String startdate, String enddate) { RecordSet rs = new RecordSet(); String sql_11 = "delete from hrm_to_flow_split where splitid in (select requestid from kq_flow_split_overtime where fromdate >='"+startdate+"' and todate <='"+enddate+"')"; rs.executeUpdate(sql_11); String sql_12 = "delete from hrm_to_flow_split where splitid in (select requestid from kq_flow_split_out where fromdate >='"+startdate+"' and todate <='"+enddate+"')"; rs.executeUpdate(sql_12); String sql_13 = "delete from hrm_to_flow_split where splitid in (select requestid from kq_flow_split_evection where fromdate >='"+startdate+"' and todate <='"+enddate+"')"; rs.executeUpdate(sql_13); String sql_14 = "delete from hrm_to_flow_split where splitid in (select requestid from kq_flow_split_leave where fromdate >='"+startdate+"' and todate <='"+enddate+"')"; rs.executeUpdate(sql_14); String sql_15 = "delete from hrm_to_flow_split where splitid in (select requestid from kq_flow_split_other where fromdate >='"+startdate+"' and todate <='"+enddate+"')"; rs.executeUpdate(sql_15); String sql_1 = "delete from kq_flow_split_overtime where fromdate >='"+startdate+"' and todate <='"+enddate+"' "; rs.executeUpdate(sql_1); String sql_111 = "delete from kq_flow_overtime where belongdate >='"+startdate+"' and belongdate <='"+enddate+"' "; rs.executeUpdate(sql_111); String sql_2 = "delete from kq_flow_split_out where fromdate >='"+startdate+"' and todate <='"+enddate+"' "; rs.executeUpdate(sql_2); String sql_3 = "delete from kq_flow_split_evection where fromdate >='"+startdate+"' and todate <='"+enddate+"' "; rs.executeUpdate(sql_3); String sql_4 = "delete from kq_flow_split_leave where fromdate >='"+startdate+"' and todate <='"+enddate+"' "; rs.executeUpdate(sql_4); String sql_5 = "delete from kq_flow_split_other where fromdate >='"+startdate+"' and todate <='"+enddate+"' "; rs.executeUpdate(sql_5); } /** * 可以重复升级数据 那就是需要升级之前先清空数据 * 清空考勤报表的升级数据 */ public void clearReportData(String startdate, String enddate) { RecordSet rs = new RecordSet(); String sql_1 = "delete from kq_format_pool where kqdate between '"+startdate+"' and '"+enddate+"'"; rs.executeUpdate(sql_1); String sql_2 = "delete from kq_format_detail where kqdate between '"+startdate+"' and '"+enddate+"'"; rs.executeUpdate(sql_2); String sql_3 = "delete from kq_format_total where kqdate between '"+startdate+"' and '"+enddate+"'"; rs.executeUpdate(sql_3); } }