新美光考勤代码第一次拉取svn 不做后续备案文件

新美光HR项目
Chengliang 3 months ago
parent 6733d55725
commit 6efd593e65

@ -1,6 +1,6 @@
<component name="ArtifactManager"> <component name="ArtifactManager">
<artifact type="jar" name="weaver-develop:jar"> <artifact type="jar" name="weaver-develop:jar">
<output-path>$PROJECT_DIR$/out/artifacts/weaver_develop_jar</output-path> <output-path>$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib</output-path>
<root id="archive" name="weaver-develop.jar"> <root id="archive" name="weaver-develop.jar">
<element id="module-output" name="weaver-develop" /> <element id="module-output" name="weaver-develop" />
</root> </root>

@ -0,0 +1,861 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.engine.kq.enums.FlowReportTypeEnum;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.wfset.bean.SplitBean;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
/**
*
*/
public class KQFlowDataBiz {
private String resourceid;
private String fromDate;
private String toDate;
private String fromTime;
private String toTime;
private String belongDate;
private String newLeaveType;
private String orderby_sql;
public KQFlowDataBiz(FlowDataParamBuilder build){
this.resourceid = build.resourceid;
this.fromDate = build.fromDate;
this.toDate = build.toDate;
this.fromTime = build.fromTime;
this.toTime = build.toTime;
this.belongDate = build.belongDate;
this.newLeaveType = build.newLeaveType;
this.orderby_sql = build.orderby_sql;
}
/**
*
*
* @param flowMaps
* @param isAll truefalse
* @return
*/
public List<SplitBean> getAllFlowData(Map<String,Object> flowMaps,boolean isAll){
List<SplitBean> allSplitBeans = new ArrayList<>();
Map<String,String> flowDeductCard = getFlowDeductCard();
allSplitBeans.addAll(getEvectionData(flowMaps,flowDeductCard));
allSplitBeans.addAll(getOutData(flowMaps,flowDeductCard));
allSplitBeans.addAll(getLeaveData(flowMaps,flowDeductCard));
if(isAll){
allSplitBeans.addAll(getOverTimeData(flowMaps));
}
allSplitBeans.addAll(getOtherData(flowMaps));
return allSplitBeans;
}
/**
*
*/
public Map<String,String> getFlowDeductCard() {
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
Map<String,String> flowDeductCard = new HashMap<>();
String flowDeductCardSql = "select * from kq_flow_deduct_card t where 1=1 and (isclear is null or isclear<>1) ";
String sqlWhere = sqlFlowCardParamWhere();
if(sqlWhere.length() > 0){
flowDeductCardSql += sqlWhere;
}
rs.execute(flowDeductCardSql);
while(rs.next()){
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String signtype= rs.getString("signtype");
String serialnumber= rs.getString("serialnumber");
String flowtype= rs.getString("flowtype");
String key = requestId+"_"+resourceid+"_"+flowtype;
String serial_signtype = serialnumber+"_"+signtype;
if(flowDeductCard.containsKey(key)){
String tmpSignType = Util.null2String(flowDeductCard.get(key));
flowDeductCard.put(key, tmpSignType+","+serial_signtype);
}else{
flowDeductCard.put(key, serial_signtype);
}
}
return flowDeductCard;
}
/**
*
*/
public List<SplitBean> getLeaveData(Map<String, Object> flowMaps,
Map<String, String> flowDeductCard){
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
String tablename = "select * from "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" where requestsyncid > 0 ";
// String tablename = "select a.* from "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
tablename += sqlWhere;
}
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
int[] initArrays = kqTimesArrayComInfo.getInitArr();
rs.executeQuery(tablename);
new BaseBean().writeLog("==leaveSql=="+tablename);
while(rs.next()){
new BaseBean().writeLog("==zj1==");
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestid");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
String leavebackrequestid= Util.null2String(rs.getString("leavebackrequestid"));
new BaseBean().writeLog("==zj2==");
String fromtimedb= rs.getString("fromtimedb");
String totimedb= rs.getString("totimedb");
String repeatType = Util.null2String(rs.getString("repeat_type"));
String repeatLate = Util.null2String(rs.getString("repeat_late"));
String repeatEarly = Util.null2String(rs.getString("repeat_early"));
if(Util.getDoubleValue(duration) <= 0){
if(repeatType.length() > 0){
//哺乳假的不需要时长
}else{
// continue;
}
}
new BaseBean().writeLog("==zj3==");
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.LEAVE.getFlowtype();
String serial_signtype = "";
String serial = "";
String signtype = "";
if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){
serial_signtype = Util.null2String(flowDeductCard.get(card_key));
if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){
serial = serial_signtype.split("_")[0];
signtype = serial_signtype.split("_")[1];
}
}
new BaseBean().writeLog("==zj4==");
Map<String,String> infoMap = new HashMap<>();
infoMap.put("requestId", requestId);
infoMap.put(newleavetype, duration);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){
infoMap.put("ishalf", "true");
}else{
infoMap.put("ishalf", "false");
}
infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
infoMap.put("fromtimedb", fromtimedb);
infoMap.put("totimedb", totimedb);
infoMap.put("repeatType", repeatType);
infoMap.put("repeatLate", repeatLate);
infoMap.put("repeatEarly", repeatEarly);
String key = resourceid+"|"+belongdate;
String keyRepeat = resourceid+"|"+belongdate+"|repeat";
new BaseBean().writeLog("==flowMaps=="+ JSON.toJSONString(flowMaps));
if(flowMaps != null){
if(flowMaps.get(key) != null){
if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){
initArrays = kqTimesArrayComInfo.getInitArr();
int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime);
int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime);
Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1);
leavebackrequestid = leavebackrequestid.substring(1);
String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'";
rs1.executeQuery(backSql);
while (rs1.next()){
String back_fromtime = rs1.getString("fromtime");
String back_totime = rs1.getString("totime");
if(repeatType.length() > 0){
//如果是哺乳假似的重复校验,不需要考虑时间
back_fromtime = fromtime;
back_totime = totime;
}
String back_duration= rs.getString("duration");
if(Util.getDoubleValue(back_duration) <= 0){
// continue;
}
if(back_fromtime.equalsIgnoreCase(fromtime)){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1);
}else{
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1);
}
}
List<List<String>> backLists = new ArrayList<>();
List<String> backList = new ArrayList<>();
for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){
if(initArrays[i] == 1){
backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i));
}else{
if(!backList.isEmpty()){
backLists.add(backList);
backList = new ArrayList<>();
}else{
continue;
}
}
}
if(!backList.isEmpty()){
backLists.add(backList);
}
if(backLists != null && !backLists.isEmpty()){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
for(int j = 0 ; j < backLists.size() ;j++){
List<String> backListTmp = backLists.get(j);
String back_tmp_fromtime = backListTmp.get(0);
String back_tmp_totime = backListTmp.get(backListTmp.size()-1);
infoMap = new HashMap<>();
infoMap.put("requestId", requestId);
infoMap.put(newleavetype, duration);
infoMap.put("begintime", back_tmp_fromtime);
infoMap.put("endtime", back_tmp_totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule)){
infoMap.put("ishalf", "true");
}
infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
infoMap.put("repeatType", repeatType);
infoMap.put("repeatLate", repeatLate);
infoMap.put("repeatEarly", repeatEarly);
time_list_tmp.add(infoMap);
}
if(repeatType.length() > 0) {
if (flowMaps.containsKey(keyRepeat)) {
List<Map<String,String>> time_list_tmp1 = (List<Map<String,String>>)flowMaps.get(keyRepeat);
time_list_tmp1.add(infoMap);
}
}
}
}else{
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}
}else{
if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){
initArrays = kqTimesArrayComInfo.getInitArr();
int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime);
int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime);
Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1);
leavebackrequestid = leavebackrequestid.substring(1);
String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'";
rs1.executeQuery(backSql);
while (rs1.next()){
String back_fromtime = rs1.getString("fromtime");
String back_totime = rs1.getString("totime");
if(repeatType.length() > 0){
//如果是哺乳假似的重复校验,不需要考虑时间
back_fromtime = fromtime;
back_totime = totime;
}
if(back_fromtime.equalsIgnoreCase(fromtime)){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1);
}else{
if(back_fromtime.compareTo(back_totime) < 0){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1);
}
}
}
List<List<String>> backLists = new ArrayList<>();
List<String> backList = new ArrayList<>();
for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){
if(initArrays[i] == 1){
backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i));
}else{
if(!backList.isEmpty()){
backLists.add(backList);
backList = new ArrayList<>();
}else{
continue;
}
}
}
if(!backList.isEmpty()){
backLists.add(backList);
}
if(backLists != null && !backLists.isEmpty()){
List<Map<String,String>> time_list = new ArrayList<>();
for(int j = 0 ; j < backLists.size() ;j++){
List<String> backListTmp = backLists.get(j);
String back_tmp_fromtime = backListTmp.get(0);
String back_tmp_totime = backListTmp.get(backListTmp.size()-1);
infoMap = new HashMap<>();
infoMap.put("requestId", requestId);
infoMap.put(newleavetype, duration);
infoMap.put("begintime", back_tmp_fromtime);
infoMap.put("endtime", back_tmp_totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule)){
infoMap.put("ishalf", "true");
}
infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
infoMap.put("repeatType", repeatType);
infoMap.put("repeatLate", repeatLate);
infoMap.put("repeatEarly", repeatEarly);
time_list.add(infoMap);
}
flowMaps.put(key, time_list);
if(repeatType.length() > 0){
//单独存一份哺乳假的重复校验
flowMaps.put(keyRepeat, time_list);
}
}
}else{
new BaseBean().writeLog("==infoMap=="+JSON.toJSONString(infoMap));
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
if(repeatType.length() > 0){
//单独存一份哺乳假的重复校验
flowMaps.put(keyRepeat, time_list);
}
}
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getEvectionData(Map<String, Object> flowMaps,
Map<String, String> flowDeductCard){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.EVECTION.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
tablename += sqlWhere;
}
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBeans.add(splitBean);
if(Util.getDoubleValue(duration) <= 0){
// continue;
}
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.EVECTION.getFlowtype();
String serial_signtype = "";
String serial = "";
String signtype = "";
if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){
serial_signtype = Util.null2String(flowDeductCard.get(card_key));
if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){
serial = serial_signtype.split("_")[0];
signtype = serial_signtype.split("_")[1];
}
}
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration);
infoMap.put("requestId", requestId);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){
infoMap.put("ishalf", "true");
}else{
infoMap.put("ishalf", "false");
}
infoMap.put("duration", duration);
infoMap.put("flowtype", FlowReportTypeEnum.EVECTION.getFlowType());
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getOutData(Map<String, Object> flowMaps,
Map<String, String> flowDeductCard){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.OUT.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
tablename += sqlWhere;
}
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBeans.add(splitBean);
if(Util.getDoubleValue(duration) <= 0){
// continue;
}
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.OUT.getFlowtype();
String serial_signtype = "";
String serial = "";
String signtype = "";
if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){
serial_signtype = Util.null2String(flowDeductCard.get(card_key));
if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){
serial = serial_signtype.split("_")[0];
signtype = serial_signtype.split("_")[1];
}
}
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.officialBusiness.getFlowType(), duration);
infoMap.put("requestId", requestId);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("durationrule", durationrule);
if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){
infoMap.put("ishalf", "true");
}else{
infoMap.put("ishalf", "false");
}
infoMap.put("duration", duration);
infoMap.put("flowtype", FlowReportTypeEnum.OUT.getFlowType());
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getOverTimeData(Map<String,Object> flowMaps){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.OVERTIME.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
tablename += sqlWhere;
}
String leaveSql = "select * from ("+tablename+") t where 1=1 ";
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
if(orderby_sql.length() > 0){
leaveSql = leaveSql+orderby_sql;
}
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String dataid= rs.getString("dataid");
String detailid= rs.getString("detailid");
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
String changetype= rs.getString("changetype");
String d_mins= rs.getString("d_mins");
String overtime_type= rs.getString("overtime_type");
String fromdatedb= rs.getString("fromdatedb");
String fromtimedb= rs.getString("fromtimedb");
String todatedb= rs.getString("todatedb");
String totimedb= rs.getString("totimedb");
splitBean.setDataId(dataid);
splitBean.setDetailId(detailid);
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBean.setChangeType(Util.getIntValue(changetype));
splitBean.setD_Mins(Util.getDoubleValue(d_mins));
splitBean.setOvertime_type(overtime_type);
splitBean.setFromdatedb(fromdatedb);
splitBean.setFromtimedb(fromtimedb);
splitBean.setTodatedb(todatedb);
splitBean.setTotimedb(totimedb);
splitBeans.add(splitBean);
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
unitType = "2".equalsIgnoreCase(durationrule)?"1":"2";
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
infoMap.put("duration", duration);
infoMap.put("flowtype", FlowReportTypeEnum.OVERTIME.getFlowType());
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
*/
public List<SplitBean> getOtherData(Map<String,Object> flowMaps){
RecordSet rs = new RecordSet();
String tablename = "select a.* from "+KqSplitFlowTypeEnum.OTHER.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
tablename += sqlWhere;
}
String leaveSql = "select * from ("+tablename+") t where 1=1 ";
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
rs.execute(leaveSql);
while(rs.next()){
SplitBean splitBean = new SplitBean();
String requestId= rs.getString("requestId");
String resourceid= rs.getString("resourceid");
String fromdate= rs.getString("fromdate");
String belongdate= rs.getString("belongdate");
String fromtime= rs.getString("fromtime");
String todate= rs.getString("todate");
String totime= rs.getString("totime");
String newleavetype= rs.getString("newleavetype");
String duration= rs.getString("duration");
String durationrule= rs.getString("durationrule");
splitBean.setRequestId(requestId);
splitBean.setResourceId(resourceid);
splitBean.setFromDate(fromdate);
splitBean.setFromTime(fromtime);
splitBean.setToDate(todate);
splitBean.setToTime(totime);
splitBean.setNewLeaveType(newleavetype);
splitBean.setDuration(duration);
splitBean.setDurationrule(durationrule);
splitBeans.add(splitBean);
//计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2";
Map<String,String> infoMap = new HashMap<>();
infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration);
infoMap.put("begintime", fromtime);
infoMap.put("endtime", totime);
infoMap.put("unitType", unitType);
String key = resourceid+"|"+belongdate;
if(flowMaps != null){
if(flowMaps.get(key) != null){
List<Map<String,String>> time_list_tmp = (List<Map<String,String>>)flowMaps.get(key);
time_list_tmp.add(infoMap);
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, time_list);
}
}
}
return splitBeans;
}
/**
*
* @param ruleid
* @return true
*/
public static boolean leaveTypeUsed(String ruleid){
KQFlowDataBiz kqFlowDataBiz = new FlowDataParamBuilder().newLeaveTypeParam(ruleid).build();
List<SplitBean> splitBeans = kqFlowDataBiz.getLeaveData(null, new HashMap<>());
if(!splitBeans.isEmpty()){
return true;
}else{
return false;
}
}
/**
*
* @return
*/
private String sqlParamWhere() {
String sqlWhere = "";
if(resourceid.length() > 0){
sqlWhere += " and resourceid in ( "+resourceid+" )";
}
if(fromDate.length() > 0 && toDate.length() > 0){
sqlWhere += " and ( fromdate between '"+fromDate+"' and '"+toDate+"' or todate between '"+fromDate+"' and '"+toDate+"' )";
}else{
if(fromDate.length() > 0){
sqlWhere += " and fromdate between '"+fromDate+"' and '"+fromDate+"' ";
}
if(toDate.length() > 0){
sqlWhere += " and todate between '"+toDate+"' and '"+toDate+"' ";
}
}
if(belongDate.length() > 0){
sqlWhere += " and belongdate = '"+belongDate+"' ";
}
if(fromTime.length() > 0){
sqlWhere += " and fromtime >= '"+fromTime+"' ";
}
if(toTime.length() > 0){
sqlWhere += " and totime <= '"+toTime+"' ";
}
if(newLeaveType.length() > 0){
sqlWhere += " and newleavetype in ( "+newLeaveType+" )";
}
return sqlWhere;
}
private String sqlFlowCardParamWhere() {
String sqlWhere = "";
if(resourceid.length() > 0){
sqlWhere += " and resourceid in ( "+resourceid+" )";
}
if(fromDate.length() > 0 && toDate.length() > 0){
sqlWhere += " and ( fromdate between '"+fromDate+"' and '"+toDate+"' or todate between '"+fromDate+"' and '"+toDate+"' )";
}else{
if(fromDate.length() > 0){
sqlWhere += " and fromdate between '"+fromDate+"' and '"+fromDate+"' ";
}
if(toDate.length() > 0){
sqlWhere += " and todate between '"+toDate+"' and '"+toDate+"' ";
}
}
if(belongDate.length() > 0){
sqlWhere += " and belongdate = '"+belongDate+"' ";
}
if(fromTime.length() > 0){
sqlWhere += " and fromtime >= '"+fromTime+"' ";
}
if(toTime.length() > 0){
sqlWhere += " and totime <= '"+toTime+"' ";
}
return sqlWhere;
}
/**
* Builder
*/
public static class FlowDataParamBuilder {
private String resourceid = "";
private String fromDate = "";
private String toDate = "";
private String fromTime = "";
private String toTime = "";
private String belongDate = "";
/**
*
*/
private String newLeaveType = "";
private String orderby_sql = "";
public FlowDataParamBuilder() {
this.resourceid = "";
//初始化的时候需要把其他参数先清空下
this.fromDate = "";
this.toDate = "";
this.fromTime = "";
this.toTime = "";
this.newLeaveType = "";
this.belongDate = "";
this.orderby_sql = "";
}
//成员方法返回其自身,所以可以链式调用
public FlowDataParamBuilder resourceidParam(final String resourceid) {
this.resourceid = resourceid;
return this;
}
public FlowDataParamBuilder fromDateParam(final String fromDate) {
this.fromDate = fromDate;
return this;
}
public FlowDataParamBuilder toDateParam(final String toDate) {
this.toDate = toDate;
return this;
}
public FlowDataParamBuilder fromTimeParam(final String fromTime) {
this.fromTime = fromTime;
return this;
}
public FlowDataParamBuilder toTimeParam(final String toTime) {
this.toTime = toTime;
return this;
}
public FlowDataParamBuilder newLeaveTypeParam(final String newLeaveType) {
this.newLeaveType = newLeaveType;
return this;
}
public FlowDataParamBuilder belongDateParam(final String belongDate) {
this.belongDate = belongDate;
return this;
}
public FlowDataParamBuilder orderby_sqlParam(final String orderby_sql) {
this.orderby_sql = orderby_sql;
return this;
}
//Builder的build方法返回外部类的实例
public KQFlowDataBiz build() {
return new KQFlowDataBiz(this);
}
}
}

@ -0,0 +1,499 @@
package com.engine.kq.biz;
import com.engine.integration.util.MyX509TrustManager;
import com.engine.kq.log.KQLog;
import net.sf.json.JSONObject;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.file.Prop;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.*;
/**
*
*/
public class KQHolidaySetBiz {
private static KQLog logger = new KQLog();
/**
* ID
*
* @param resourceId ID
* @param year
* @param month
* @return
*/
public static List getGroupHolidaySetList(String groupId, String year, String month) {
List<Map<String, Object>> valueList = new ArrayList<Map<String, Object>>();
Map<String, Object> valueMap = new HashMap<String, Object>();
/*指定年月*/
String startDate = year;
String endDate = month;
if (month.length() == 0) {
startDate = year + "-01" + "-01";
endDate = year + "-12" + "-31";
} else if (month.length() == 1) {
startDate = year + "-0" + month + "-01";
endDate = year + "-0" + month + "-31";
} else if (month.length() == 2) {
startDate = year + "-" + month + "-01";
endDate = year + "-" + month + "-31";
}
RecordSet recordSet = new RecordSet();
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo();
boolean isEnd = false;
for (String date = startDate; !isEnd; ) {
if (date.compareTo(endDate) >= 0) {
isEnd = true;
}
String changeType = holidaySetComInfo.getChangeType(groupId, date);
String holidayDesc = holidaySetComInfo.getHolidayDesc(groupId, date);
if (!changeType.equals("")) {
valueMap = new HashMap<String, Object>();
valueMap.put("date", date);
valueMap.put("name", holidayDesc);
valueMap.put("type", changeType);
valueList.add(valueMap);
}
date = DateUtil.getDate(date, 1);
}
return valueList;
}
/**
* ID
*
* @param resourceId ID
* @param year
* @param month
* @return
*/
public static List getKQHolidaySetList(String resourceId, String year, String month) {
List<Map<String, Object>> valueList = new ArrayList<Map<String, Object>>();
/*指定年月*/
String startDate = year;
String endDate = month;
if (month.length() == 0) {
startDate = year + "-01" + "-01";
endDate = year + "-12" + "-31";
} else if (month.length() == 1) {
startDate = year + "-0" + month + "-01";
endDate = year + "-0" + month + "-31";
} else if (month.length() == 2) {
startDate = year + "-" + month + "-01";
endDate = year + "-" + month + "-31";
}
valueList = getHolidaySetListByScope(resourceId, startDate, endDate);
return valueList;
}
/**
*
*
* @param resourceId ID
* @param startDate
* @param endDate
* @return
*/
public static List getHolidaySetListByScope(String resourceId, String startDate, String endDate) {
Map<String, Object> valueMap = new HashMap<String, Object>();
List<Map<String, Object>> valueList = new ArrayList<Map<String, Object>>();
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo();
boolean isEnd = false;
for (String date = startDate; !isEnd; ) {
if (date.compareTo(endDate) >= 0) {
isEnd = true;
}
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date);
String changeType = holidaySetComInfo.getChangeType(groupId, date);
String holidayDesc = holidaySetComInfo.getHolidayDesc(groupId, date);
if (!changeType.equals("")&&!getWorkDay(resourceId, date)) {
valueMap = new HashMap<String, Object>();
valueMap.put("date", date);
valueMap.put("name", holidayDesc);
valueMap.put("type", changeType);
valueList.add(valueMap);
}
date = DateUtil.getDate(date, 1);
}
return valueList;
}
/**
* +
*
* @param resourceId ID
* @param date
* @return true-false
*/
public static boolean isHoliday(String resourceId, String date) {
return isHoliday(resourceId, date, false);
}
/**
* ++
*
* @param resourceId ID
* @param date
* @param containWeekend truefalse
* @return true-false
*/
public static boolean isHoliday(String resourceId, String date, boolean containWeekend) {
boolean flag = false;
if(getWorkDay(resourceId, date)){
return flag;
}
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date);
int changeType = getChangeType(groupId, date);
/*如果需要包含周末,判断传入的日期是不是周末*/
if (containWeekend && changeType != 2 && (DateUtil.getWeek(date) == 6 || DateUtil.getWeek(date) == 7)) {
flag = true;
}
if (changeType == 1 || changeType == 3) {
flag = true;
}
return flag;
}
/**
* ++
*
* @param resourceId ID
* @param date
* @return true-false
*/
public static boolean isDouble(String resourceId, String date) {
boolean flag = false;
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date);
int changeType = getChangeType(groupId, date);
if (changeType == 1 || changeType == 3) {
flag = true;
}
return flag;
}
/**
* ()
*
* @param resourceId ID
* @param date
* @return
*/
public static boolean getWorkDay(String resourceId, String date) {
boolean flag = false;
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date);
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String holiday_is_priority = Util.null2String(kqSettingsComInfo.getMain_val("holiday_is_priority"),"0");
if("0".equals(holiday_is_priority)) {
return flag;
}
/*排班制不支持调配节假日数据*/
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
String KQType = kqGroupComInfo.getKqtype(groupId);//考勤类型1-固定班制、2-排班制、3-自由班制
if (KQType.equals("2")) {
flag = true;
}
return flag;
}
/**
* ()
*
* @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 resourceId ID
* @param date
* @return
*/
public static int getRelatedDay(String resourceId, String date) {
int relatedDay = -1;
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date);
/*排班制不支持调配节假日数据*/
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
String KQType = kqGroupComInfo.getKqtype(groupId);//考勤类型1-固定班制、2-排班制、3-自由班制
if (KQType.equals("2")) {
return relatedDay;
}
/*只有当调配工作日时才有对应工作日*/
KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo();
int changeType = Util.getIntValue(kqHolidaySetComInfo.getChangeType(groupId, date), -1);
if (changeType == 2) {
relatedDay = Util.getIntValue(kqHolidaySetComInfo.getRelatedDay(groupId, date), 0);
}
return relatedDay;
}
/**
* ()
*
* @param groupIds ID(ID,)
* @param year
* @return
*/
public static Map<String, Object> initHolidaySet(String groupIds, String year, User user) {
Map<String, Object> resultMap = new HashMap<String, Object>();
List<String> errInfoList = new ArrayList<String>();//错误信息集合
/**
* API(JSON)(APIAPI)
* status1-0-
* sketch''
* holidayList[{holidayDate:'',changeType:'',holidayDesc:''},,{holidayDate:'',changeType:'',holidayDesc:''}]
*/
String url = Prop.getInstance().getPropValue("kq_settings", "KQHolidaySetUrl");
Map<String, Object> tempMap = httpRequest(url +"?year="+year+"&key="+Util.getEncrypt(Util.getRandom()), user);
if ("0".equals((String) tempMap.get("status"))) {
resultMap.put("status", "0");
resultMap.put("sketch", (String) tempMap.get("sketch"));
return resultMap;
}
List<String> holidayDateList = new ArrayList<String>();
try {
List<String> groupIdList = Util.TokenizerString(groupIds, ",");//考勤组ID集合
for (int i = 0; i < groupIdList.size(); i++) {
String groupId = groupIdList.get(i);
/**
*
*/
List<String> dateList = new ArrayList<String>();
KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo();
kqHolidaySetComInfo.setTofirstRow();
while (kqHolidaySetComInfo.next()) {
if (kqHolidaySetComInfo.getGroupId().equals(groupId)) {
dateList.add(kqHolidaySetComInfo.getHolidayDate());
}
}
/**
* ~
*/
int relatedDay = 0;
for (int x = 0; x < 7; x++) {
KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo();
String serialId = Util.null2String(kqFixedSchedulceComInfo.getSerialid(groupId, x));
if (!serialId.equals("")) {
relatedDay = x;
break;
}
}
/**
* ()
*/
boolean flag = true;
RecordSet recordSet = new RecordSet();
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
List<Map<String, Object>> holidayList = (List<Map<String, Object>>) tempMap.get("holidayList");
Map<String, Object> holidayMap = new HashMap<String, Object>();
if(holidayList.size()>0){
String tmpsql = "delete from kq_HolidaySet where groupId='"+groupId+"' and holidayDate>='"+year+"-01-01' and holidayDate<='"+year+"-12-31' ";
recordSet.executeUpdate(tmpsql);
}
for (int j = 0; j < holidayList.size(); j++) {
holidayMap = holidayList.get(j);
String holidayDate = year + "-" + (String) holidayMap.get("holidayDate");
if (!holidayDateList.contains(holidayDate)) {
holidayDateList.add(holidayDate);
}
int changeType = (int) holidayMap.get("changeType");
if (kqGroupComInfo.getKqtype(groupId).equals("2")&&changeType == 2 ) {
//排班制的考勤组不能初始化调配工作日
continue;
}
String holidayDesc = (String) holidayMap.get("holidayDesc");
if (dateList.contains(holidayDate)) {
String deleteSql = "delete from kq_HolidaySet where groupId=? and holidayDate=?";
recordSet.executeUpdate(deleteSql, groupId, holidayDate);
}
String sql = "insert into kq_HolidaySet(groupId,holidayDate,changeType,holidayDesc,relatedDay) values(?,?,?,?,?)";
flag = recordSet.executeUpdate(sql, groupId, holidayDate, changeType, holidayDesc, relatedDay);
if (!flag) {
errInfoList.add(SystemEnv.getHtmlLabelName(5056701, user.getLanguage()).replace("$groupName$", kqGroupComInfo.getGroupname(groupId)).replace("$holidayDate$", holidayDate));
}
}
}
/**
*
*/
if (errInfoList.size() > 0) {
resultMap.put("status", "0");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(125960, user.getLanguage()));
resultMap.put("description", errInfoList);
} else {
resultMap.put("status", "1");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(20196, user.getLanguage()));
}
} catch (Exception e) {
resultMap.put("status", "0");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(382661, user.getLanguage()));
resultMap.put("desscription", errInfoList);
} finally {
/*刷新缓存*/
KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo();
kqHolidaySetComInfo.removeCache();
/*刷新考勤报表*/
logger.info("初始化节假日数据格式化考勤报表。groupIdList=" + com.alibaba.fastjson.JSONObject.toJSONString(groupIds) +
"。holidayDateList=" + com.alibaba.fastjson.JSONObject.toJSONString(holidayDateList));
List<String> groupIdList = Util.TokenizerString(groupIds, ",");//考勤组ID集合
new KQHolidaySetThread(groupIdList,holidayDateList).start();
}
return resultMap;
}
/**
* API
*
* @param requestUrl
* @return
*/
private static Map<String, Object> httpRequest(String requestUrl, User user) {
Map<String, Object> resultMap = new HashMap<String, Object>();
//buffer用于接受返回的字符
StringBuffer buffer = new StringBuffer();
try {
TrustManager[] tm = {new MyX509TrustManager()};
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url= new URL(null, requestUrl, new sun.net.www.protocol.https.Handler());
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setSSLSocketFactory(ssf);
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
httpUrlConn.setRequestMethod("GET");
httpUrlConn.connect();
//获得输入
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
//将bufferReader的值给放到buffer里
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
//关闭bufferReader和输入流
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
inputStream = null;
//断开连接
httpUrlConn.disconnect();
/**
* JSON
*/
String jsonStr = buffer.toString();
JSONObject jsonObject = JSONObject.fromObject(jsonStr).getJSONObject("data");
int code = jsonObject.optInt("code");//0服务正常。-1服务出错
if (code != 0) {
//初始化节假日失败,获取网络服务出错
resultMap.put("status", "0");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(520011, user.getLanguage()));
return resultMap;
}
JSONObject holiday = jsonObject.getJSONObject("holiday");
if (holiday.size() == 0) {
//初始化节假日失败,暂未获取到所选年份的节假日数据
resultMap.put("status", "0");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(505673, user.getLanguage()));
return resultMap;
}
Map<String, Object> holidayMap = new HashMap<String, Object>();
List<Map<String, Object>> holidayList = new ArrayList<Map<String, Object>>();
Iterator iterator = holiday.keys();
while (iterator.hasNext()) {
holidayMap = new HashMap<String, Object>();
String holidayDate = (String) iterator.next();
holidayMap.put("holidayDate", holidayDate);//日期
JSONObject detailInfo = holiday.getJSONObject(holidayDate);
int wage = detailInfo.optInt("wage");
if (wage == 1) {
holidayMap.put("changeType", 2);//调配工作日
} else if (wage == 2) {
holidayMap.put("changeType", 3);//调配休息日
} else if (wage == 3) {
holidayMap.put("changeType", 1);//公众假日
}
String holidayDesc = detailInfo.getString("name");
holidayMap.put("holidayDesc", holidayDesc);//说明
holidayList.add(holidayMap);
}
resultMap.put("status", "1");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(505674, user.getLanguage()));
resultMap.put("holidayList", holidayList);
} catch (Exception e) {
e.printStackTrace();
resultMap.put("status", "0");
resultMap.put("sketch", SystemEnv.getHtmlLabelName(520011, user.getLanguage()));
return resultMap;
}
return resultMap;
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,979 @@
package com.engine.kq.cmd.group;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.cloudstore.dev.api.util.Util_TableMap;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQGroupComInfo;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.util.PageUidFactory;
import com.engine.kq.util.UtilKQ;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.moduledetach.ManageDetachComInfo;
import weaver.hrm.settings.ChgPasswdReminder;
import weaver.hrm.settings.RemindSettings;
import weaver.proj.util.SQLUtil;
import weaver.systeminfo.SystemEnv;
import weaver.systeminfo.systemright.CheckSubCompanyRight;
import java.util.*;
public class GetGroupFormCmd extends AbstractCommonCommand<Map<String, Object>> {
public GetGroupFormCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String,Object> retmap = new HashMap<String,Object>();
List<Map<String,Object>> grouplist = new ArrayList<Map<String,Object>>();
Map<String,Object> groupitem = null;
List<Object> itemlist = null;
Map<String, Object> otherparam = null;
RecordSet rs = new RecordSet();
String sql = "";
try{
//必要的权限判断
if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return retmap;
}
ChgPasswdReminder reminder=new ChgPasswdReminder();
RemindSettings settings=reminder.getRemindSettings();
KQGroupComInfo kQGroupComInfo = new KQGroupComInfo();
ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo();
boolean hrmdetachable = manageDetachComInfo.isUseHrmManageDetach();//是否开启了人力资源模块的管理分权
String id = Util.null2String(params.get("id"));
String subcompanyid = Util.null2String(params.get("subcompanyid"));//所属分部
String tabKey = Util.null2String(params.get("tabKey"));
Map<String, List<HrmFieldBean>> fieldGroups= new LinkedHashMap<String, List<HrmFieldBean>>();
List<HrmFieldBean> lsField = new ArrayList<HrmFieldBean>();
HrmFieldBean hrmFieldBean = null;
List<SearchConditionOption> options = null;
String groupname = "";//考勤组名称
String kqtype = "1";//考勤类型 默认固定班制
String excludeid = "";//考勤组排除人员
String excludecount = "";//考勤组排除人员是否参与统计
String serialids = "";//考勤班次
String overtimeRuleId = "";//加班班次
String overtimeType = "0";//加班类型
List<Integer> lsWeekday = new ArrayList<>();//考勤工作日
String weekday = "";
String signstart = "";//考勤开始时间
String workhour = "";//工作时长
String signintype = "1";//打卡方式
String ipscope = "";//应用IP范围
String ipscope_v4_pc = "";//应用IP范围 v4 pc端
String ipscope_v4_em = "";//应用IP范围 v4 移动端
String ipscope_v6_pc = "";//应用IP范围 v6 pc端
String ipscope_v6_em = "";//应用IP范围 v6 移动端
String locationcheck = "";//启用办公地点考勤
//String locationcheckscope = "300";//有效范围
String wificheck = "";//启用wifi考勤
String outsidesign = "";//允许外勤打卡
String outsignapprove = "";//545427 外勤打卡需要审批
String validity = "";//考勤组有效期
String validityfromdate = "";//考勤组有效期开始时间
String validityenddate = "";//考勤组有效期结束时间
String locationfacecheck = "";//办公地点启用人脸识别拍照打卡
String locationfacechecktype = "";//办公地点启用人脸识别拍照打卡方式
String locationshowaddress = "";//有效识别半径内显示同一地址
String wififacecheck = "";//wifi启用人脸识别拍照打卡
String wififacechecktype = "";//wifi启用人脸识别拍照打卡方式
String self_shift = "0";//启用员工自我排班
String auto_checkin = "0";//允许客户端设置自动考勤 上班卡
String auto_checkin_before = "30";//允许客户端设置自动考勤 上班卡开始分钟数
String auto_checkin_after = "30";//允许客户端设置自动考勤 上班卡结束分钟时
String auto_checkout = "0";//允许客户端设置自动考勤 下班卡
String auto_checkout_before = "5";//允许客户端设置自动考勤 下班卡 下班卡开始分钟数
String auto_checkout_after = "60";//允许客户端设置自动考勤 下班卡 下班卡结束分钟时
String calmethod = "1";//工作时长计算方式 1是打卡时间累加计算 2是打卡时间成对计算
String abnormalremind = "0";//考勤异常提醒 1是打开 0是关闭
String isPhotoPunchEnabled = "0";//启用考勤拍照打卡
List<Map<String,Object>> replaceDatas = new ArrayList<Map<String,Object>>();
if(id.length()>0){
sql = "select * from kq_group where id=?";
rs.executeQuery(sql,id);
if(rs.next()){
groupname = Util.null2String(rs.getString("groupname"));
excludeid = Util.null2String(rs.getString("excludeid"));
excludecount = Util.null2String(rs.getString("excludecount"));
subcompanyid = Util.null2String(rs.getString("subcompanyid"));
kqtype = Util.null2String(rs.getString("kqtype"));
serialids=Util.null2String(rs.getString("serialids"));
overtimeType=Util.null2s(rs.getString("overtime_type"),"0");
weekday = Util.null2String(rs.getString("weekday"));
signstart = Util.null2String(rs.getString("signstart"));
workhour = Util.null2String(rs.getString("workhour"));
signintype = Util.null2String(rs.getString("signintype"));
ipscope = Util.null2String(rs.getString("ipscope"));
ipscope_v4_pc = Util.null2String(rs.getString("ipscope_v4_pc"));
ipscope_v4_em = Util.null2String(rs.getString("ipscope_v4_em"));
ipscope_v6_pc = Util.null2String(rs.getString("ipscope_v6_pc"));
ipscope_v6_em = Util.null2String(rs.getString("ipscope_v6_em"));
locationcheck = Util.null2String(rs.getString("locationcheck"));
//locationcheckscope = Util.null2String(rs.getString("locationcheckscope"));
wificheck = Util.null2String(rs.getString("wificheck"));
outsidesign = Util.null2String(rs.getString("outsidesign"));
outsignapprove = Util.null2String(rs.getString("outsignapprove"));
validity = Util.null2String(rs.getString("validity"));
validityfromdate = Util.null2String(rs.getString("validityfromdate"));
validityenddate = Util.null2String(rs.getString("validityenddate"));
locationfacecheck = Util.null2String(rs.getString("locationfacecheck"));
locationfacechecktype = Util.null2String(rs.getString("locationfacechecktype"));
locationshowaddress = Util.null2String(rs.getString("locationshowaddress"));
wififacecheck = Util.null2String(rs.getString("wififacecheck"));
wififacechecktype = Util.null2String(rs.getString("wififacechecktype"));
self_shift = Util.null2String(rs.getString("self_shift"));
auto_checkin = Util.null2String(rs.getString("auto_checkin"),"0");
auto_checkin_before = Util.null2String(rs.getString("auto_checkin_before"),"30");
auto_checkin_after = Util.null2String(rs.getString("auto_checkin_after"),"30");
auto_checkout = Util.null2String(rs.getString("auto_checkout"),"0");
auto_checkout_before = Util.null2String(rs.getString("auto_checkout_before"),"5");
auto_checkout_after = Util.null2String(rs.getString("auto_checkout_after"),"60");
calmethod = Util.null2s(rs.getString("calmethod"),"1");
isPhotoPunchEnabled = Util.null2s(rs.getString("isPhotoPunchEnabled"),"0");
abnormalremind = Util.null2String(rs.getString("abnormalremind"));
}
if("0".equals(overtimeType)){
String dbtype = rs.getDBType();
String overSql = "select * from kq_overtimerules where ','+convert(varchar(2000),groupids)+',' like '%," + id + ",%' and (isDelete is null or isDelete!=1) ";
if ("oracle".equalsIgnoreCase(dbtype)) {
overSql = "select * from kq_overtimerules where "+SQLUtil.filteSql(rs.getDBType(), " ','+groupids+',' like '%," + id + ",%' and (isDelete is null or isDelete!=1) ");
}else if("mysql".equalsIgnoreCase(dbtype)){
overSql = "select * from kq_overtimerules where CONCAT(',',cast(groupids as char),',') like '%,"+id+",%' and (isDelete is null or isDelete!=1) ";
}else if ("postgresql".equalsIgnoreCase(dbtype)) {
overSql = "select * from kq_overtimerules where CONCAT(',',groupids,',') like '%,"+id+",%' and (isDelete is null or isDelete!=1) ";
}
Map<String,Object> map = new HashMap<String,Object>();
rs.execute(overSql);
if(rs.next()){
String oId = rs.getString("id");
overtimeRuleId = oId;
String name = rs.getString("name");
map.put("id", oId);
map.put("name", name);
replaceDatas.add(map);
}
}
}
if(tabKey.equals("1")){
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("groupname");
hrmFieldBean.setFieldlabel("388700");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(groupname);
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setRules("required|string");
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("excludeid");
hrmFieldBean.setFieldlabel("388703");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("17");
hrmFieldBean.setFieldvalue(excludeid);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("overtime_type");
hrmFieldBean.setFieldlabel("388881");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("3");
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("0",SystemEnv.getHtmlLabelName(126821, user.getLanguage()),overtimeType.equals("0")));
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(546276, user.getLanguage()),overtimeType.equals("1")));
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setFieldvalue(overtimeType);
hrmFieldBean.setViewAttr(2);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("overtime_rule_id");
hrmFieldBean.setFieldlabel("388881");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("kqovertimerule");
hrmFieldBean.setFieldvalue(overtimeRuleId);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("excludecount");
hrmFieldBean.setFieldlabel("507794");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(excludecount);
lsField.add(hrmFieldBean);
//增加有效期设置
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("validity");
hrmFieldBean.setFieldlabel("15030");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(validity);
lsField.add(hrmFieldBean);
//考勤异常提醒
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("abnormalremind");
hrmFieldBean.setFieldlabel("547511");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(abnormalremind);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("validityfromdate");
hrmFieldBean.setFieldlabel("742");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(validityfromdate);
hrmFieldBean.setRules("required|string");
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setIsFormField(true);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("validityenddate");
hrmFieldBean.setFieldlabel("743");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(validityenddate);
hrmFieldBean.setRules("required|string");
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setIsFormField(true);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("self_shift");
hrmFieldBean.setFieldlabel("517026");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(self_shift);
lsField.add(hrmFieldBean);
String defaultSubcompanyid = "";
if(hrmdetachable){
CheckSubCompanyRight newCheck=new CheckSubCompanyRight();
int[] subcomids = newCheck.getSubComByUserRightId(user.getUID(),"HrmKQGroup:Add",0);
ManageDetachComInfo detachComInfo = new ManageDetachComInfo();
if(detachComInfo.isUseHrmManageDetach()){
defaultSubcompanyid = detachComInfo.getHrmdftsubcomid();
}else{
rs.executeProc("SystemSet_Select","");
if(rs.next()){
if(subcompanyid.length()==0||subcompanyid.equals("0")){
defaultSubcompanyid = Util.null2String(rs.getString("dftsubcomid"));
}
}
}
boolean hasRight = false;
for (int i = 0; subcomids!=null&& i < subcomids.length; i++) {
if((""+subcomids[i]).equals(defaultSubcompanyid)){
hasRight = true;
break;
}
}
if(!hasRight){
defaultSubcompanyid = "";
}
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("subcompanyid");
hrmFieldBean.setFieldlabel("19799");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("169");
hrmFieldBean.setFieldvalue(subcompanyid.length()==0&&id.length()==0?defaultSubcompanyid:subcompanyid);
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setRules("required|integer");
lsField.add(hrmFieldBean);
}
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("kqtype");
hrmFieldBean.setFieldlabel("388704");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("3");
hrmFieldBean.setFieldvalue(kqtype);
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(500385, user.getLanguage()),kqtype.equals("1")));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(500386, user.getLanguage()),kqtype.equals("2")));
options.add(new SearchConditionOption("3",SystemEnv.getHtmlLabelName(500387, user.getLanguage()),kqtype.equals("3")));
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setViewAttr(id.length()>0?1:2);
lsField.add(hrmFieldBean);
//固定班制
retmap.put("fixedSchedulce",getFixedSchedulce());
//排班制
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("serialids");
hrmFieldBean.setFieldlabel("389098");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("mkqshift");
hrmFieldBean.setFieldvalue(serialids);
lsField.add(hrmFieldBean);
retmap.put("shiftSchedulceTable",getShiftSchedulceTable());
//自由班制
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("weekday");
hrmFieldBean.setFieldlabel("389097");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(weekday);
options = new ArrayList<SearchConditionOption>();
for(int i=0;i<7;i++){
options.add(new SearchConditionOption(""+i,UtilKQ.getWeekDay(i,user.getLanguage()),lsWeekday.contains(i)));
}
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("signstart");
hrmFieldBean.setFieldlabel("16039");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("19");
hrmFieldBean.setFieldvalue(signstart);
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setRules("required|string");
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("workhour");
hrmFieldBean.setFieldlabel("390053");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(workhour);
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setRules("required|numeric");
otherparam = new HashMap<String, Object>();
otherparam.put("min","1");
otherparam.put("precision",1);
otherparam.put("max","24");
hrmFieldBean.setOtherparam(otherparam);
lsField.add(hrmFieldBean);
if(id.length()>0){
// 编辑的时候只有弹性的显示这个说明
if(kqtype.equals("3")){
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("calmethod");
hrmFieldBean.setFieldlabel("529683");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("3");
hrmFieldBean.setFieldvalue(calmethod);
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(529686, user.getLanguage()),calmethod.equals("1")));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(529685, user.getLanguage()),calmethod.equals("2")));
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setViewAttr(3);
lsField.add(hrmFieldBean);
}
}else{
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("calmethod");
hrmFieldBean.setFieldlabel("529683");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("3");
hrmFieldBean.setFieldvalue(calmethod);
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(529686, user.getLanguage()),calmethod.equals("1")));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(529685, user.getLanguage()),calmethod.equals("2")));
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setViewAttr(3);
lsField.add(hrmFieldBean);
}
if(id.length()>0){
// 编辑的时候只有弹性的显示这个说明
if(kqtype.equals("3")){
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("desc");
hrmFieldBean.setFieldlabel("85");
hrmFieldBean.setFieldhtmltype("8");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(SystemEnv.getHtmlLabelName(520468, Util.getIntValue(user.getLanguage()))
+"<br/>"+SystemEnv.getHtmlLabelName(520469, Util.getIntValue(user.getLanguage()))
+"<br/>"+SystemEnv.getHtmlLabelName(520859, Util.getIntValue(user.getLanguage())));
hrmFieldBean.setViewAttr(1);
lsField.add(hrmFieldBean);
}
}else{
//新增的时候需要前端控制显示这个字段
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("desc");
hrmFieldBean.setFieldlabel("85");
hrmFieldBean.setFieldhtmltype("8");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(SystemEnv.getHtmlLabelName(520468, Util.getIntValue(user.getLanguage()))
+"<br/>"+SystemEnv.getHtmlLabelName(520469, Util.getIntValue(user.getLanguage()))
+"<br/>"+SystemEnv.getHtmlLabelName(520859, Util.getIntValue(user.getLanguage())));
hrmFieldBean.setViewAttr(1);
lsField.add(hrmFieldBean);
}
fieldGroups.put("1361", lsField);
}else if(tabKey.equals("2")){
//signintype,ipscope,locationcheck,locationcheckscope,wificheck
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("signintype");
hrmFieldBean.setFieldlabel("388708");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("3");
hrmFieldBean.setFieldvalue(signintype);
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(389938, user.getLanguage()),signintype.equals("1")));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(388710, user.getLanguage()),signintype.equals("2")));
options.add(new SearchConditionOption("3",SystemEnv.getHtmlLabelName(389939, user.getLanguage()),signintype.equals("3")));
options.add(new SearchConditionOption("4",SystemEnv.getHtmlLabelName(502765, user.getLanguage()),signintype.equals("4")));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("ipscope_v4_pc");
hrmFieldBean.setFieldlabel("388712");
hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712, Util.getIntValue(user.getLanguage()))+"( ipv4 )");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(ipscope_v4_pc);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("ipscope_v4_em");
hrmFieldBean.setFieldlabel("388712");
hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712, Util.getIntValue(user.getLanguage()))+"( ipv4 )");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(ipscope_v4_em);
lsField.add(hrmFieldBean);
// hrmFieldBean = new HrmFieldBean();
// hrmFieldBean.setFieldname("ipscope_v6_pc");
// hrmFieldBean.setFieldlabel("388712");
// hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712,weaver.general.Util.getIntValue(user.getLanguage()))+"( ipv6 )");
// hrmFieldBean.setFieldhtmltype("1");
// hrmFieldBean.setType("1");
// hrmFieldBean.setFieldvalue(ipscope_v6_pc);
// lsField.add(hrmFieldBean);
//
// hrmFieldBean = new HrmFieldBean();
// hrmFieldBean.setFieldname("ipscope_v6_em");
// hrmFieldBean.setFieldlabel("388712");
// hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712,weaver.general.Util.getIntValue(user.getLanguage()))+"( ipv6 )");
// hrmFieldBean.setFieldhtmltype("1");
// hrmFieldBean.setType("1");
// hrmFieldBean.setFieldvalue(ipscope_v6_em);
// lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("outsidesign");
hrmFieldBean.setFieldlabel("390302");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setTip(SystemEnv.getHtmlLabelNames("545433,545434,545435" ,user.getLanguage()));
hrmFieldBean.setFieldvalue(outsidesign);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("isPhotoPunchEnabled");
hrmFieldBean.setFieldlabel("547013");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(isPhotoPunchEnabled);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("outsignapprove");
hrmFieldBean.setFieldlabel("545427");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(545466,user.getLanguage()));
hrmFieldBean.setFieldvalue(outsignapprove);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("locationcheck");
hrmFieldBean.setFieldlabel("388713");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(locationcheck);
lsField.add(hrmFieldBean);
// hrmFieldBean = new HrmFieldBean();
// hrmFieldBean.setFieldname("locationcheckscope");
// hrmFieldBean.setFieldlabel("388714");
// hrmFieldBean.setFieldhtmltype("5");
// hrmFieldBean.setType("1");
// hrmFieldBean.setFieldvalue(locationcheckscope);
// options = new ArrayList<SearchConditionOption>();
// options.add(new SearchConditionOption("50","50"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("50")));
// options.add(new SearchConditionOption("100","100"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("100")));
// options.add(new SearchConditionOption("200","200"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("200")));
// options.add(new SearchConditionOption("300","300"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("300")));
// options.add(new SearchConditionOption("400","400"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("400")));
// options.add(new SearchConditionOption("500","500"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("500")));
// options.add(new SearchConditionOption("600","600"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("600")));
// options.add(new SearchConditionOption("700","700"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("700")));
// options.add(new SearchConditionOption("800","800"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("800")));
// options.add(new SearchConditionOption("900","900"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("900")));
// options.add(new SearchConditionOption("1000","1000"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("1000")));
// hrmFieldBean.setSelectOption(options);
// lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("locationfacecheck");
hrmFieldBean.setFieldlabel("507921");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(locationfacecheck);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("locationfacechecktype");
hrmFieldBean.setFieldlabel("537091");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(locationfacechecktype);
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(537092,user.getLanguage()),true));
if("1".equals(settings.getSecondCL())){
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(537093,user.getLanguage())));
}
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(537095,user.getLanguage()));
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("locationshowaddress");
hrmFieldBean.setFieldlabel("507922");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(locationshowaddress);
hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(507990,user.getLanguage()));
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("wificheck");
hrmFieldBean.setFieldlabel("388715");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(wificheck);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("wififacecheck");
hrmFieldBean.setFieldlabel("507921");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(wififacecheck);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("wififacechecktype");
hrmFieldBean.setFieldlabel("537091");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(wififacechecktype);
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(537092,user.getLanguage())));
if("1".equals(settings.getSecondCL())){
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(537093,user.getLanguage())));
}
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(537095,user.getLanguage()));
lsField.add(hrmFieldBean);
if(!"3".equalsIgnoreCase(kqtype)){
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("auto_checkin");
hrmFieldBean.setFieldlabel("518736");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(Util.null2s(auto_checkin,"0"));
hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(521383,user.getLanguage()));
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("auto_checkin_before");
hrmFieldBean.setFieldlabel("518737");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(Util.null2s(auto_checkin_before,"30"));
hrmFieldBean.setRules("required|integer");
otherparam = new HashMap<String, Object>();
otherparam.put("min","1");
hrmFieldBean.setOtherparam(otherparam);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("auto_checkin_after");
hrmFieldBean.setFieldlabel("518737");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(Util.null2s(auto_checkin_after,"30"));
hrmFieldBean.setRules("required|integer");
otherparam = new HashMap<String, Object>();
otherparam.put("min","0");
hrmFieldBean.setOtherparam(otherparam);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("auto_checkout");
hrmFieldBean.setFieldlabel("518738");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(Util.null2s(auto_checkout,"0"));
hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(521383,user.getLanguage()));
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("auto_checkout_before");
hrmFieldBean.setFieldlabel("518739");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(Util.null2s(auto_checkout_before,"5"));
hrmFieldBean.setRules("required|integer");
otherparam = new HashMap<String, Object>();
otherparam.put("min","0");
hrmFieldBean.setOtherparam(otherparam);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("auto_checkout_after");
hrmFieldBean.setFieldlabel("518739");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(Util.null2s(auto_checkout_after,"60"));
hrmFieldBean.setRules("required|integer");
otherparam = new HashMap<String, Object>();
otherparam.put("min","0");
hrmFieldBean.setOtherparam(otherparam);
lsField.add(hrmFieldBean);
}
//排班校验下拉框
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("pbcheck");
hrmFieldBean.setFieldlabel("-85230");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue("1");
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1", "不校验"));
options.add(new SearchConditionOption("2", "做五休二"));
options.add(new SearchConditionOption("3", "做四休二"));
hrmFieldBean.setSelectOption(options);
hrmFieldBean.setViewAttr(id.length()>0?1:2);
fieldGroups.put("20331", lsField);
retmap.put("locationSessionKey",getKQLocationList(""));
retmap.put("wifiSessionKey",getKQWifiList(""));
Map<String,Object> helpTipMap = Maps.newHashMap();
helpTipMap.put("auto_checkin_before", SystemEnv.getHtmlLabelName(521211, user.getLanguage()));
helpTipMap.put("auto_checkout_before", SystemEnv.getHtmlLabelName(521211, user.getLanguage()));
retmap.put("helpTipMap",helpTipMap);
}
HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
SearchConditionItem searchConditionItem = null;
Iterator<Map.Entry<String, List<HrmFieldBean>>> iter = fieldGroups.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, List<HrmFieldBean>> entry = iter.next();
String grouplabel = entry.getKey();
List<HrmFieldBean> fields = entry.getValue();
groupitem = new HashMap<String, Object>();
groupitem.put("title", SystemEnv.getHtmlLabelNames(grouplabel, user.getLanguage()));
groupitem.put("defaultshow", true);
itemlist = new ArrayList<Object>();
for (int j = 0; j < fields.size(); j++) {
hrmFieldBean = fields.get(j);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
if(hrmFieldBean.getFieldname().equals("subcompanyid")){
searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "HrmKQGroup:Add");
searchConditionItem.getBrowserConditionParam().getCompleteParams().put("rightStr", "HrmKQGroup:Add");
}
if(hrmFieldBean.getFieldname().equals("overtime_rule_id")){
if(CollectionUtils.isNotEmpty(replaceDatas)){
searchConditionItem.getBrowserConditionParam().setReplaceDatas(replaceDatas);
}
}
if(hrmFieldBean.getFieldname().equals("overtime_type")){
searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(546300, user.getLanguage()));
}
itemlist.add(searchConditionItem);
}
groupitem.put("items", itemlist);
grouplist.add(groupitem);
}
retmap.put("formField", grouplist);
retmap.put("status", "1");
int operatelevel = -1;
if(hrmdetachable){
if(subcompanyid.length()>0 && !subcompanyid.equalsIgnoreCase("0")){
CheckSubCompanyRight checkSubCompanyRight = new CheckSubCompanyRight();
operatelevel=checkSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(),"HrmKQGroup:Add",Util.getIntValue(subcompanyid,-1));
}
}else{
operatelevel = 2;
}
if(user.getUID() == 1 || subcompanyid.length()==0 || subcompanyid.equalsIgnoreCase("0")){
operatelevel = 2;
}
if(operatelevel > 0){
retmap.put("canAdd", true);
}else{
retmap.put("canAdd", false);
}
retmap.put("kqtype", kqtype);
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
return retmap;
}
public String getKQLocationList(String locationname){
String sessionKey = "";
String groupId = Util.null2String(params.get("id"));
String backFields = " id,locationname,longitude,latitude,address,checkscope ";
String sqlFrom = " kq_location ";
String sqlWhere = " where groupid= "+groupId;
String orderby = " id " ;
String tableString = "";
if (locationname.length() > 0){
sqlWhere += " and locationname like '%"+locationname+"%' ";
}
String pageUid = PageUidFactory.getHrmPageUid("KQLocationList");
tableString=""+
"<table pageUid=\""+pageUid+"\" pagesize=\"10\" tabletype=\"checkbox\">"+
"<sql backfields=\""+backFields+"\" sqlform=\""+sqlFrom+"\" sqlprimarykey=\"id\" sqlorderby=\""+orderby+"\" sqlsortway=\"asc\" sqldistinct=\"true\" sqlwhere=\""+Util.toHtmlForSplitPage(sqlWhere)+"\"/>"+
"<head>"+
" <col width=\"20%\" text=\""+SystemEnv.getHtmlLabelName(388717,user.getLanguage())+"\" column=\"locationname\"/>"+
" <col width=\"20%\" text=\""+SystemEnv.getHtmlLabelName(801,user.getLanguage())+"\" column=\"longitude\" orderkey=\"longitude\"/>"+
" <col width=\"20%\" text=\""+SystemEnv.getHtmlLabelName(802,user.getLanguage())+"\" column=\"latitude\" orderkey=\"latitude\"/>"+
" <col width=\"20%\" text=\""+SystemEnv.getHtmlLabelName(507863,user.getLanguage())+"\" column=\"checkscope\" orderkey=\"checkscope\"/>"+
" <col width=\"20%\" text=\""+SystemEnv.getHtmlLabelName(104,user.getLanguage())+"\" column=\"id\" orderkey=\"id\"/>"+
" <col width=\"0%\" hide=\"true\" display=\"true\" text=\"\" column=\"address\"/>"+
"</head>"+
"</table>";
//主要用于 显示定制列以及 表格 每页展示记录数选择
sessionKey = pageUid + "_" + Util.getEncrypt(Util.getRandom());
Util_TableMap.setVal(sessionKey, tableString);
return sessionKey;
}
public String getKQWifiList(String wifiname){
String sessionKey = "";
String groupId = Util.null2String(params.get("id"));
String backFields = " id,wifiname,mac ";
String sqlFrom = " kq_wifi ";
String sqlWhere = " where groupid= "+groupId;
String orderby = " id " ;
String tableString = "";
if (wifiname.length() > 0){
sqlWhere += " and wifiname like '%"+wifiname+"%' ";
}
String pageUid = PageUidFactory.getHrmPageUid("KQLocationList");
tableString=""+
"<table pageUid=\""+pageUid+"\" pagesize=\"10\" tabletype=\"checkbox\">"+
"<sql backfields=\""+backFields+"\" sqlform=\""+sqlFrom+"\" sqlprimarykey=\"id\" sqlorderby=\""+orderby+"\" sqlsortway=\"asc\" sqldistinct=\"true\" sqlwhere=\""+Util.toHtmlForSplitPage(sqlWhere)+"\"/>"+
"<head>"+
" <col width=\"35%\" text=\""+SystemEnv.getHtmlLabelName(195,user.getLanguage())+"\" column=\"wifiname\"/>"+
" <col width=\"35%\" text=\""+SystemEnv.getHtmlLabelName(32072,user.getLanguage())+"\" column=\"mac\"/>"+
" <col width=\"30%\" text=\""+SystemEnv.getHtmlLabelName(104,user.getLanguage())+"\" column=\"id\" orderkey=\"id\"/>"+
"</head>"+
"</table>";
//主要用于 显示定制列以及 表格 每页展示记录数选择
sessionKey = pageUid + "_" + Util.getEncrypt(Util.getRandom());
Util_TableMap.setVal(sessionKey, tableString);
return sessionKey;
}
/**
*
* @return
*/
public Map<String,Object> getFixedSchedulce(){
Map<String,Object> fixedSchedulce = new HashMap<>();
RecordSet rs = new RecordSet();
String sql = "";
try{
String groupid = Util.null2String(params.get("id"));
//固定班次
Map<String, Object> table = new HashMap<String, Object>();
List<Object> columns = new ArrayList<Object>();
Map<String, Object> column = null;
LinkedList<Map<String, Object>> datas = new LinkedList<Map<String, Object>>();
Map<String, Object> data = null;
ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit();
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(28387, user.getLanguage()));
column.put("dataIndex", "weekday");
column.put("width", "30%");
columns.add(column);
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(388984, user.getLanguage()));
column.put("dataIndex", "serialinfo");
column.put("width", "40%");
columns.add(column);
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(104, user.getLanguage()));
column.put("dataIndex", "operate");
column.put("width", "30%");
columns.add(column);
if(groupid.length()>0){
List<Integer> lsWeeks = new ArrayList<>();
sql = " select * from kq_fixedschedulce where groupid = ? order by weekday asc ";
rs.executeQuery(sql,groupid);
while(rs.next()){
data = new HashMap<String, Object>();
data.put("id",rs.getString("id"));
data.put("weekday",UtilKQ.getWeekDay(rs.getInt("weekday"),user.getLanguage()));
data.put("serialid",rs.getString("serialid"));
data.put("serialinfo",shiftManagementToolKit.getShiftOnOffWorkSections(rs.getString("serialid"),user.getLanguage()));
datas.add(data);
lsWeeks.add(rs.getInt("weekday"));
}
//加强性修改
for(int i=0;i<7;i++){
if(!lsWeeks.contains(i)){
data = new HashMap<String, Object>();
data.put("id",i);
data.put("weekday",UtilKQ.getWeekDay(i,user.getLanguage()));
data.put("serialid","");
data.put("serialinfo",SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
datas.add(data);
}
}
}else{
for(int i=0;i<7;i++){
data = new HashMap<String, Object>();
data.put("id",i);
data.put("weekday",UtilKQ.getWeekDay(i,user.getLanguage()));
data.put("serialid","");
data.put("serialinfo",SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
datas.add(data);
}
}
fixedSchedulce.put("columns",columns);
fixedSchedulce.put("datas",datas);
}catch (Exception e){
writeLog(e);
}
return fixedSchedulce;
}
/**
*
* @return
*/
public Map<String,Object> getShiftSchedulceTable(){
Map<String,Object> shiftSchedulce = new HashMap<>();
RecordSet rs = new RecordSet();
String sql = "";
try{
String groupid = Util.null2String(params.get("id"));
//排班制
List<Object> columns = new ArrayList<Object>();
Map<String, Object> column = null;
LinkedList<Map<String, Object>> datas = new LinkedList<Map<String, Object>>();
Map<String, Object> data = null;
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(388722, user.getLanguage()));
column.put("dataIndex", "shiftcyclename");
column.put("width", "30%");
columns.add(column);
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(500480, user.getLanguage()));
column.put("dataIndex", "serial");
column.put("width", "30%");
columns.add(column);
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(500481, user.getLanguage()));
column.put("dataIndex", "shiftcycleday");
column.put("width", "20%");
columns.add(column);
column = new HashMap<String, Object>();
column.put("title", SystemEnv.getHtmlLabelName(30585, user.getLanguage()));
column.put("dataIndex", "operate");
column.put("width", "20%");
columns.add(column);
if(groupid.length()>0){
sql = " select id,shiftcyclename,shiftcycleserialids,groupid from kq_group_shiftcycle where groupid = ? order by id asc ";
rs.executeQuery(sql,groupid);
while(rs.next()){
data = new HashMap<String, Object>();
data.put("id",rs.getString("id"));
data.put("shiftcyclename",rs.getString("shiftcyclename"));
data.put("serial",rs.getString("shiftcycleserialids"));
data.put("shiftcycleday",Util.splitString(Util.null2String(rs.getString("shiftcycleserialids")),",").length);
datas.add(data);
}
}
shiftSchedulce.put("columns",columns);
shiftSchedulce.put("datas",datas);
}catch (Exception e){
writeLog(e);
}
return shiftSchedulce;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,618 @@
package com.engine.kq.cmd.group;
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.biz.KQAutoCheckComInfo;
import com.engine.kq.biz.KQFixedSchedulceComInfo;
import com.engine.kq.biz.KQGroupComInfo;
import com.engine.kq.log.KQLog;
import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.proj.util.SQLUtil;
import weaver.systeminfo.SystemEnv;
import java.util.*;
public class SaveGroupCmd extends AbstractCommonCommand<Map<String, Object>> {
private SimpleBizLogger logger;
SimpleBizLogger.SubLogInfo subLogInfo;
SimpleBizLogger.SubLogInfo subLogInfo1;
public SaveGroupCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
if (params != null && params.containsKey("data")) {
String datas = Util.null2String(params.get("data"));
JSONObject jsonObj = JSON.parseObject(datas);
String id = Util.null2String(jsonObj.get("id"));
if(id.length()==0) {
id = "-1";
}
this.logger = new SimpleBizLogger();
BizLogContext logContext = new BizLogContext();
logContext.setDateObject(new Date());
logContext.setLogType(BizLogType.HRM_ENGINE);
logContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_KQGROUP);
logContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_KQGROUP);
logContext.setParams(params);
logger.setUser(user);//当前操作人
String mainSql = " select * from kq_group where id= "+id;
logger.setMainSql(mainSql);//主表sql
logger.setMainPrimarykey("id");//主日志表唯一key
logger.setMainTargetNameColumn("groupname");
subLogInfo1 = logger.getNewSubLogInfo();
String subSql1 = "select * from kq_fixedschedulce where groupid="+id;
subLogInfo1.setSubPrimarykey("id");
subLogInfo1.setSubTargetNameColumn("weekday");
subLogInfo1.setGroupId("0"); //所属分组, 按照groupid排序显示在详情中 不设置默认按照add的顺序。
subLogInfo1.setSubGroupNameLabel(505654); //在详情中显示的分组名称不设置默认显示明细x
subLogInfo1.setSubSql(subSql1);
logger.addSubLogInfo(subLogInfo1);
subLogInfo = logger.getNewSubLogInfo();
String subSql = " select * from kq_group_shiftcycle where groupid = "+id;
subLogInfo.setSubSql(subSql);
subLogInfo.setSubPrimarykey("id");
subLogInfo.setSubTargetNameColumn("shiftcyclename");
subLogInfo.setGroupId("1"); //所属分组, 按照groupid排序显示在详情中 不设置默认按照add的顺序。
subLogInfo.setSubGroupNameLabel(389225); //在详情中显示的分组名称不设置默认显示明细x
logger.addSubLogInfo(subLogInfo);
logger.before(logContext);
}
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
String sql = "";
try{
//必要的权限判断
if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return retmap;
}
KQGroupComInfo kQGroupComInfo = new KQGroupComInfo();
KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo();
new KQLog().info("SaveGroupCmd params:"+params);
String datas = Util.null2String(params.get("data"));
JSONObject jsonObj = JSON.parseObject(datas);
String tabKey = Util.null2String(params.get("tabKey"));//分组id
String id = Util.null2String(jsonObj.get("id"));//考勤组id
String groupname = Util.null2String(jsonObj.get("groupname"));//考勤组名称
String overtimeType = Util.null2String(jsonObj.get("overtime_type"));//加班类型
String overtimeRuleId = Util.null2String(jsonObj.get("overtime_rule_id"));//加班id
String kqtype = Util.null2String(jsonObj.get("kqtype"));//考勤类型
String subcompanyid = Util.null2String(jsonObj.get("subcompanyid"));//所属分部
String excludeid = Util.null2String(jsonObj.get("excludeid"));//考勤组排除人员
String excludecount = Util.null2String(jsonObj.get("excludecount"));//考勤组排除人员是否参与统计
String abnormalremind = Util.null2String(jsonObj.get("abnormalremind"));//考勤异常提醒
String signintype = Util.null2String(jsonObj.get("signintype"));//打卡方式
String serialids = Util.null2String(jsonObj.get("serialids"));//考勤班次
String weekday = Util.null2String(jsonObj.get("weekday"));//考勤类型
String signstart = Util.null2String(jsonObj.get("signstart"));//考勤类型
String workhour = Util.null2String(jsonObj.get("workhour"));//工作时长
String ipscope =Util.null2String( jsonObj.get("ipscope"));//应用IP范围
String calmethod = Util.null2s(Util.null2String(jsonObj.get("calmethod")),"1");//工作时长计算方式 1是打卡时间累加计算 2是打卡时间成对计算
String ipscope_v4_pc =Util.null2String( jsonObj.get("ipscope_v4_pc"));//应用IP范围 ipv4 pc端
String ipscope_v4_em =Util.null2String( jsonObj.get("ipscope_v4_em"));//应用IP范围 ipv4 移动端
String ipscope_v6_pc =Util.null2String( jsonObj.get("ipscope_v6_pc"));//应用IP范围 ipv6 pc端
String ipscope_v6_em =Util.null2String( jsonObj.get("ipscope_v6_em"));//应用IP范围 ipv6 移动端
String locationcheck = Util.null2String(jsonObj.get("locationcheck"));//启用办公地点考勤
//String locationcheckscope = Util.null2String(jsonObj.get("locationcheckscope"));//有效范围
String wificheck = Util.null2String(jsonObj.get("wificheck"));//启用wifi考勤
String outsidesign = Util.null2String(jsonObj.get("outsidesign"));//允许外勤打卡
String outsignapprove = Util.null2String(jsonObj.get("outsignapprove"));//外勤打卡需要审批
String validity = Util.null2String(jsonObj.get("validity"));//考勤组有效期
String validityfromdate = Util.null2String(jsonObj.get("validityfromdate"));//考勤组有效期开始时间
String validityenddate = Util.null2String(jsonObj.get("validityenddate"));//考勤组有效期结束时间
String locationfacecheck = Util.null2String(jsonObj.getString("locationfacecheck"));//办公地点启用人脸识别拍照打卡
String locationfacechecktype = Util.null2String(jsonObj.getString("locationfacechecktype"));//办公地点启用人脸识别拍照打卡方式
String locationshowaddress = Util.null2String(jsonObj.getString("locationshowaddress"));//有效识别半径内显示同一地址
String wififacecheck = Util.null2String(jsonObj.getString("wififacecheck"));//wifi启用人脸识别拍照打卡
String wififacechecktype = Util.null2String(jsonObj.getString("wififacechecktype"));//wifi启用人脸识别拍照打卡方式
String self_shift = Util.null2String(jsonObj.getString("self_shift"));//启用员工自我排班
String auto_checkin = Util.null2String(jsonObj.getString("auto_checkin"));//允许客户端设置自动考勤 上班卡
String auto_checkout = Util.null2String(jsonObj.getString("auto_checkout"));//允许客户端设置自动考勤 下班卡
String auto_checkin_before = Util.null2String(jsonObj.getString("auto_checkin_before"));//允许客户端设置自动考勤 上班卡开始分钟数
String auto_checkin_after = Util.null2String(jsonObj.getString("auto_checkin_after"));//允许客户端设置自动考勤 上班卡结束分钟时
String auto_checkout_before = Util.null2String(jsonObj.getString("auto_checkout_before"));//允许客户端设置自动考勤 下班卡 下班卡开始分钟数
String auto_checkout_after = Util.null2String(jsonObj.getString("auto_checkout_after"));//允许客户端设置自动考勤 下班卡 下班卡结束分钟时
String isPhotoPunchEnabled = Util.null2String(jsonObj.getString("isPhotoPunchEnabled"));//启用考勤拍照打卡
String pbcheck = Util.null2String(jsonObj.getString("pbcheck"));//启用考勤拍照打卡
if("".equals(id)) {
sql = "select * from kq_group where groupname=? and (isDelete is null or isDelete !=1) ";
rs.executeQuery(sql, groupname);
} else {
sql = "select * from kq_group where groupname=? and id != ? and (isDelete is null or isDelete !=1) ";
rs.executeQuery(sql, groupname, id);
}
if(rs.next()) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(531673, user.getLanguage()));
return retmap;
}
if("1".equalsIgnoreCase(signintype) || "3".equalsIgnoreCase(signintype)){
//如果有移动端打卡但是办公地点和wifi都没开启也把自动打卡重置
if(!"1".equalsIgnoreCase(locationcheck) && !"1".equalsIgnoreCase(wificheck)){
auto_checkin = "0";
auto_checkout = "0";
auto_checkin_before = "30";
auto_checkin_after = "30";
auto_checkout_before = "5";
auto_checkout_after = "60";
}
}else{
//如果不是移动端打卡,需要把自动打卡重置
auto_checkin = "0";
auto_checkout = "0";
auto_checkin_before = "30";
auto_checkin_after = "30";
auto_checkout_before = "5";
auto_checkout_after = "60";
}
List<Object> lsParams = new ArrayList<>();
if(tabKey.equals("1")){
if(id.length()>0) {
sql = " update kq_group set groupname=?,subcompanyid=?,excludeid=?,excludecount=?,abnormalremind=?,kqtype=?," +
" serialids=?,weekday=?,signstart=?,workhour=?,validity=?,validityfromdate=?,validityenddate=?,self_shift=?,calmethod=?,overtime_type=?,pbcheck=? " +
" where id=? ";
lsParams.add(groupname.length()==0?null:groupname);
lsParams.add(subcompanyid.length()==0?null:subcompanyid);
lsParams.add(excludeid.length()==0?null:excludeid);
lsParams.add(excludecount.length()==0?null:excludecount);
lsParams.add(abnormalremind.length()==0?null:abnormalremind);
lsParams.add(kqtype.length()==0?null:kqtype);
lsParams.add(serialids.length()==0?null:serialids);
lsParams.add(weekday.length()==0?null:weekday);
lsParams.add(signstart.length()==0?null:signstart);
lsParams.add(workhour.length()==0?null:workhour);
lsParams.add(validity.length()==0?null:validity);
lsParams.add(validityfromdate.length()==0?null:validityfromdate);
lsParams.add(validityenddate.length()==0?null:validityenddate);
lsParams.add(self_shift.length()==0?0:self_shift);
lsParams.add(calmethod.length()==0?"1":calmethod);
lsParams.add(overtimeType.length()==0?"0":overtimeType);
lsParams.add(pbcheck.length()==0?"1":pbcheck);
lsParams.add(id);
rs.executeUpdate(sql,lsParams);
if(kqtype.equals("2")){
this.saveKqTypeInfo();
}
}else {
sql = " insert into kq_group (" +
" groupname,subcompanyid,excludeid,excludecount,abnormalremind,kqtype,serialids," +
" weekday,signstart,workhour,signintype,validity,validityfromdate,validityenddate,locationcheckscope,calmethod,overtime_type,self_shift,pbcheck) " +
" values(?,?,?,?,?,?,?, ?,?,?,1,?,?,?,300,?,?,?,?)";
lsParams.add(groupname.length()==0?null:groupname);
lsParams.add(subcompanyid.length()==0?null:subcompanyid);
lsParams.add(excludeid.length()==0?null:excludeid);
lsParams.add(excludecount.length()==0?null:excludecount);
lsParams.add(abnormalremind.length()==0?null:abnormalremind);
lsParams.add(kqtype.length()==0?null:kqtype);
lsParams.add(serialids.length()==0?null:serialids);
lsParams.add(weekday.length()==0?null:weekday);
lsParams.add(signstart.length()==0?null:signstart);
lsParams.add(workhour.length()==0?null:workhour);
lsParams.add(validity.length()==0?null:validity);
lsParams.add(validityfromdate.length()==0?null:validityfromdate);
lsParams.add(validityenddate.length()==0?null:validityenddate);
lsParams.add(calmethod.length()==0?"1":calmethod);
lsParams.add(overtimeType.length()==0?"0":overtimeType);
lsParams.add(self_shift.length()==0?"0":self_shift);
lsParams.add(pbcheck.length()==0?"1":pbcheck);
rs.executeUpdate(sql,lsParams);
rs.executeQuery("select max(id) from kq_group") ;
if(rs.next()){
id = rs.getString(1);
}
}
params.put("id",id);
this.saveKqTypeInfo();
updateOverByGroupId(id,overtimeRuleId,overtimeType);
}else if(tabKey.equals("2")){
sql = " update kq_group set signintype=?, ipscope_v4_pc=?,ipscope_v4_em=?,ipscope_v6_pc=?,ipscope_v6_em=?,locationcheck=?,wificheck=?,outsidesign=?,outsignapprove=?, " +//locationcheckscope=?,
" locationfacecheck=?,locationfacechecktype=?,locationshowaddress=?,wififacecheck=?,wififacechecktype=?,auto_checkin=?,auto_checkout=?,"
+ " auto_checkin_before=?,auto_checkin_after=?,auto_checkout_before=?,auto_checkout_after=?,isPhotoPunchEnabled=? where id=? ";
lsParams.add(signintype.length()==0?null:signintype);
lsParams.add(ipscope_v4_pc.length()==0?null:ipscope_v4_pc);
lsParams.add(ipscope_v4_em.length()==0?null:ipscope_v4_em);
lsParams.add(ipscope_v6_pc.length()==0?null:ipscope_v6_pc);
lsParams.add(ipscope_v6_em.length()==0?null:ipscope_v6_em);
lsParams.add(locationcheck.length()==0?null:locationcheck);
//lsParams.add(locationcheckscope.length()==0?null:locationcheckscope);
lsParams.add(wificheck.length()==0?null:wificheck);
lsParams.add(outsidesign.length()==0?null:outsidesign);
lsParams.add(outsignapprove.length()==0?null:outsignapprove);
lsParams.add(locationfacecheck.length()==0?null:locationfacecheck);
lsParams.add(locationfacechecktype.length()==0?null:locationfacechecktype);
lsParams.add(locationshowaddress.length()==0?null:locationshowaddress);
lsParams.add(wififacecheck.length()==0?null:wififacecheck);
lsParams.add(wififacechecktype.length()==0?null:wififacechecktype);
lsParams.add(auto_checkin.length()==0?0:auto_checkin);
lsParams.add(auto_checkout.length()==0?0:auto_checkout);
lsParams.add(auto_checkin_before.length()==0?30:auto_checkin_before);
lsParams.add(auto_checkin_after.length()==0?30:auto_checkin_after);
lsParams.add(auto_checkout_before.length()==0?5:auto_checkout_before);
lsParams.add(auto_checkout_after.length()==0?60:auto_checkout_after);
lsParams.add(isPhotoPunchEnabled.length()==0?0:isPhotoPunchEnabled);
String ori_auto_checkin = kQGroupComInfo.getAuto_checkin(id);
String ori_auto_checkout = kQGroupComInfo.getAuto_checkout(id);
//关于自动打卡开启或者关闭后的一些逻辑处理
group_auto_check(id,auto_checkin,auto_checkout,ori_auto_checkin,ori_auto_checkout,retmap,kQGroupComInfo,locationcheck,wificheck,locationfacecheck,wififacecheck);
if(!retmap.isEmpty()){
return retmap;
}
lsParams.add(id);
rs.executeUpdate(sql,lsParams);
}
kQGroupComInfo.removeCache();
if(kqtype.equals("1")){
kqFixedSchedulceComInfo.removeCache();
}
String mainSql = " select * from kq_group where id= "+id;
logger.setMainSql(mainSql);//主表sql
String subSql1 = "select * from kq_fixedschedulce where groupid= "+id;
subLogInfo1.setSubSql(subSql1);
String subSql = " select * from kq_group_shiftcycle where groupid = "+id;
subLogInfo.setSubSql(subSql);
retmap.put("id", id);
retmap.put("status", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage()));
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
return retmap;
}
/**
*
*/
private void updateOverByGroupId(String id, String overtimeRuleId, String overtimeType) {
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
if(id.length() > 0){
//更新的情况
//先根据考勤规则id查询一下原加班规则
String dbtype = rs.getDBType();
String overSql = "select * from kq_overtimerules where ','+convert(varchar(2000),groupids)+',' like ? and (isDelete is null or isDelete!=1) ";
if ("oracle".equalsIgnoreCase(dbtype)) {
overSql = "select * from kq_overtimerules where "+ SQLUtil.filteSql(rs.getDBType(), " ','+groupids+',' like ? and (isDelete is null or isDelete!=1) ");
}else if("mysql".equalsIgnoreCase(dbtype)){
overSql = "select * from kq_overtimerules where CONCAT(',',cast(groupids as char),',') like ? and (isDelete is null or isDelete!=1) ";
}else if ("postgresql".equalsIgnoreCase(dbtype)) {
overSql = "select * from kq_overtimerules where CONCAT(',',groupids,',') like ? and (isDelete is null or isDelete!=1) ";
}
rs.executeQuery(overSql,"%,"+id+",%");
String preOverId = "";
String overGroupIds = "";
if(rs.next()) {
preOverId = rs.getString("id");
String groupids = rs.getString("groupids");
if(groupids.length() > 0){
String[] groupidsArr = groupids.split(",");
if(groupidsArr.length > 0){
for (int i = 0; i < groupidsArr.length; i++) {
String gId = groupidsArr[i];
if(gId.equals(id)){
continue;
}
if(overGroupIds.length() == 0){
overGroupIds = gId;
}else{
overGroupIds += ","+gId;
}
}
}
}
}
//先把原加班规则里的当前考勤规则剔除掉
if(preOverId.length() > 0){
String updateOverSql = "update kq_overtimerules set groupids=? where id = ?";
rs1.executeUpdate(updateOverSql,overGroupIds,preOverId);
}
}else{
//新增的情况
}
//再根据传入的新的加班规则查一下有的考勤规则id
if("0".equals(overtimeType)){
//只有是考勤组关联加班规则的时候才有这个逻辑
if(overtimeRuleId.length() > 0){
String getSql = "select * from kq_overtimerules where id=?";
rs.executeQuery(getSql,overtimeRuleId);
if(rs.next()){
String groupids = Util.null2s(rs.getString("groupids"),"");
if(groupids.length() > 0){
groupids += ","+id;
}else {
groupids = id;
}
String updateOverSql = "update kq_overtimerules set groupids=? where id = ?";
rs1.executeUpdate(updateOverSql,groupids,overtimeRuleId);
}
}
}
}
/**
*
* @param id
* @param auto_checkin
* @param auto_checkout
* @param ori_auto_checkin
* @param ori_auto_checkout
* @param retmap
* @param kQGroupComInfo
* @param locationcheck
* @param wificheck
*/
public void group_auto_check(String id, String auto_checkin, String auto_checkout,
String ori_auto_checkin, String ori_auto_checkout,
Map<String, Object> retmap, KQGroupComInfo kQGroupComInfo, String locationcheck,
String wificheck, String locationfacecheck, String wififacecheck) {
KQAutoCheckComInfo kqAutoCheckComInfo = new KQAutoCheckComInfo();
RecordSet rs = new RecordSet();
if(!"1".equalsIgnoreCase(auto_checkin) && !"1".equalsIgnoreCase(auto_checkout)){
//如果自动打卡 都关闭了,那么自定义设置的也需要被清空
String del_cus_autoset = "delete from kq_autocheck_set where groupid = ? ";
rs.executeUpdate(del_cus_autoset,id);
kqAutoCheckComInfo.removeCache();
}else{
String tmp_kqtype = kQGroupComInfo.getKqtype(id);
if("3".equalsIgnoreCase(tmp_kqtype)){
//如果是弹性工作制
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(519990,user.getLanguage()));
}
boolean has_location_list = has_location_list(id);
boolean has_wifi_list = has_wifi_list(id);
if("1".equalsIgnoreCase(locationcheck)){
//地理位置的开关开启了
if("1".equalsIgnoreCase(wificheck)){
//wifi的开关开启了
if(!has_location_list && !has_wifi_list){
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(519989,user.getLanguage()));
}
if("1".equalsIgnoreCase(wififacecheck)){
//如果开启了人脸打卡
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(521384,user.getLanguage()));
}
}else{
if(!has_location_list){
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(519989,user.getLanguage()));
}
}
if("1".equalsIgnoreCase(locationfacecheck)){
//如果开启了人脸打卡
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(521384,user.getLanguage()));
}
}else{
//地理位置没开启
if("1".equalsIgnoreCase(wificheck)){
//wifi的开关开启了
if(!has_wifi_list){
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(519989,user.getLanguage()));
}
if("1".equalsIgnoreCase(wififacecheck)){
//如果开启了人脸打卡
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(521384,user.getLanguage()));
}
}
}
if(!ori_auto_checkin.equalsIgnoreCase(auto_checkin)){
//如果上班自动打卡变化了,需要去更新掉自定义的设置
String up_cus_autoset = "update kq_autocheck_set set auto_checkin=? where groupid = ? ";
rs.executeUpdate(up_cus_autoset, auto_checkin,id);
}
if(!ori_auto_checkout.equalsIgnoreCase(ori_auto_checkout)){
//如果下班自动打卡变化了,需要去更新掉自定义的设置
String up_cus_autoset = "update kq_autocheck_set set auto_checkout=? where groupid = ? ";
rs.executeUpdate(up_cus_autoset, auto_checkout,id);
}
kqAutoCheckComInfo.removeCache();
}
}
/**
* wifi
* @param id
* @return
*/
public boolean has_wifi_list(String id) {
RecordSet rs = new RecordSet();
String wifi_list_sql = "select 1 from kq_wifi where groupid = ? ";
rs.executeQuery(wifi_list_sql,id);
if(!rs.next()){
return false;
}
return true;
}
/**
*
* @param id
* @return
*/
public boolean has_location_list(String id) {
RecordSet rs = new RecordSet();
String location_list_sql = "select 1 from kq_location where groupid = ? ";
rs.executeQuery(location_list_sql,id);
if(!rs.next()){
return false;
}
return true;
}
private Map<String,Object> saveKqTypeInfo(){
Map<String,Object> kqTypeInfo = new HashMap<>();
RecordSet rs = new RecordSet();
BatchRecordSet batchRecordSet = new BatchRecordSet();
String sql = "";
try{
String groupid = Util.null2String(params.get("id"));
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String kqtype = Util.null2String(jsonObj.get("kqtype"));//考勤类型
if(kqtype.equals("1")){//固定班次
JSONArray fixedSchedulce = jsonObj.getJSONArray("fixedSchedulce");//固定班次明细表
if(fixedSchedulce==null || fixedSchedulce.size()>7) return kqTypeInfo;
for(int i=0;fixedSchedulce!=null&&i<fixedSchedulce.size();i++){
jsonObj = (JSONObject)fixedSchedulce.get(i);
String weekday = ""+i;//星期几
String serialid = Util.null2String(jsonObj.get("serialid"));
int id = 0;
sql = " select id from kq_fixedschedulce where weekday = ? and groupid = ? ";
rs.executeQuery(sql, weekday, groupid);
if (rs.next()) {
id = rs.getInt("id");
}
if(id>0){
sql = "update kq_fixedschedulce set serialid =? where id=? ";
rs.executeUpdate(sql,serialid.length()==0?null:serialid,id);
}else{
sql = "insert into kq_fixedschedulce(weekday,serialid,groupid) values(?,?,?)";
rs.executeUpdate(sql,weekday,serialid.length()==0?null:serialid,groupid);
}
}
}
else if(kqtype.equals("2")){//排班制
JSONArray shiftSchedulce = jsonObj.getJSONArray("shiftSchedulce");//固定班次明细表
List<String> lsDelete = new ArrayList<>();
sql = " select id from kq_group_shiftcycle where groupid = ? ";
rs.executeQuery(sql, groupid);
while(rs.next()){
lsDelete.add(rs.getString("id"));
}
List<List<Object>> paramUpdate = new ArrayList<>();
List<List<Object>> paramInsert = new ArrayList<>();
List<Object> shiftSchedulceParams = null;
for(int i=0;shiftSchedulce!=null&&i<shiftSchedulce.size();i++){
jsonObj = (JSONObject)shiftSchedulce.get(i);
String id = Util.null2String(jsonObj.get("id"));
String shiftcyclename = Util.null2String(jsonObj.get("shiftcyclename"));
String shiftcycleday = Util.null2String(jsonObj.get("shiftcycleday"));
String shiftcycleserialids = Util.null2String(jsonObj.get("serial"));
shiftSchedulceParams = new ArrayList<>();
if(id.length()>0){
shiftSchedulceParams.add(shiftcyclename);
shiftSchedulceParams.add(shiftcycleday);
shiftSchedulceParams.add(shiftcycleserialids);
shiftSchedulceParams.add(id);
paramUpdate.add(shiftSchedulceParams);
lsDelete.remove(id);
}else{
shiftSchedulceParams.add(shiftcyclename);
shiftSchedulceParams.add(shiftcycleday);
shiftSchedulceParams.add(shiftcycleserialids);
shiftSchedulceParams.add(groupid);
paramInsert.add(shiftSchedulceParams);
}
}
sql = " update kq_group_shiftcycle set shiftcyclename=?, shiftcycleday=?,shiftcycleserialids=? where id = ? ";
batchRecordSet.executeBatchSql(sql, paramUpdate);
sql = " insert into kq_group_shiftcycle (shiftcyclename, shiftcycleday, shiftcycleserialids,groupid) values (?,?,?,?)";
batchRecordSet.executeBatchSql(sql, paramInsert);
for(int i=0;i<lsDelete.size();i++) {
sql = " delete from kq_group_shiftcycle where id = ? ";
rs.executeUpdate(sql, lsDelete.get(i));
}
}
// else if(kqtype.equals("3")){//自由班制
// String weekday = Util.null2String(jsonObj.get("weekday"));//考勤类型
// String signstart = Util.null2String(jsonObj.get("signstart"));//考勤类型
// String[] weekdays = Util.splitString(weekday,",");
//
// //删除取消的星期
// sql = "delete from kq_freeschedulce where weekday not in (?) and groupid=?";
// rs.executeUpdate(sql,weekday,groupid);
//
// //更新开始时间
// sql = "update kq_freeschedulce set signstart=? where weekday in (?) and groupid=?";
// rs.executeUpdate(sql,signstart,weekday,groupid);
//
// List<List<Object>> lsParams = new ArrayList<List<Object>>();
// for(int i=0;i<weekdays.length;i++){
// sql = "select count(1) from kq_freeschedulce where weekday=? and groupid=?";
// rs.executeQuery(sql,weekdays[i],groupid);
// if(rs.next()){
// if(rs.getInt(1)<=0){
// List<Object> params = new ArrayList<Object>();
// params.add(weekdays[i]);
// params.add(signstart);
// params.add(groupid);
// lsParams.add(params);
// }
// }
// }
// if(lsParams.size()>0){
// sql = "insert into kq_freeschedulce(weekday,signstart,groupid) values(?,?,?)";
// rs.executeUpdate(sql,lsParams);
// }
// }
}catch (Exception e){
writeLog(e);
}
return kqTypeInfo;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public List<BizLogContext> getLogContexts() {
return logger.getBizLogContexts();
}
}

@ -0,0 +1,238 @@
package com.engine.kq.cmd.holidaySet;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQGroupComInfo;
import weaver.conn.RecordSet;
import weaver.filter.XssUtil;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.country.CountryComInfo;
import weaver.hrm.moduledetach.ManageDetachComInfo;
import weaver.systeminfo.SystemEnv;
import weaver.systeminfo.systemright.CheckSubCompanyRight;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* --
*/
public class GetHolidaySetFormCmd extends AbstractCommonCommand<Map<String, Object>> {
public GetHolidaySetFormCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> resultMap = new HashMap<String, Object>();
String id = Util.null2String(params.get("id"));//ID
String groupId = Util.null2String(params.get("groupId"));//考勤组的ID
String holidayDate = Util.null2String(params.get("holidayDate"));//节假日日期
String holidayDesc = "";//说明
String changeType = "1";//类型1-公众假日、2-调配工作日、3-调配休息日
String relatedDay = "";//对应工作日0-星期一、1-星期二、2-星期三、3-星期四、4-星期五、5-星期六、6-星期日
String shiftId = "";//班次ID
/*参数有误*/
if (id.equals("") && groupId.equals("")) {
resultMap.put("status", "-1");
resultMap.put("message", SystemEnv.getHtmlLabelName(388858, user.getLanguage()));
return resultMap;
}
/*是否具有编辑的权限*/
boolean canEdit = HrmUserVarify.checkUserRight("KQHolidaySetEdit:Edit", user);
if (!canEdit) {
resultMap.put("status", "-1");
resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return resultMap;
}
List<Map<String, Object>> groupList = new ArrayList<Map<String, Object>>();
Map<String, Object> groupItem = new HashMap<String, Object>();
List<Object> itemList = new ArrayList<Object>();
HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
SearchConditionItem searchConditionItem = null;
HrmFieldBean hrmFieldBean = null;
List<Map<String, Object>> replaceDatas = new ArrayList<Map<String, Object>>();
Map<String, Object> datas = new HashMap<String, Object>();
boolean isEdit = false;
if (!id.equals("")) {
String sql = "select * from kq_HolidaySet where id=" + id;
RecordSet recordSet = new RecordSet();
recordSet.executeQuery(sql);
if (recordSet.next()) {
isEdit = true;
holidayDate = recordSet.getString("holidayDate");
groupId = recordSet.getString("groupId");
holidayDesc = recordSet.getString("holidayDesc");
changeType = recordSet.getString("changeType");
relatedDay = recordSet.getString("relatedDay");
shiftId = recordSet.getString("shiftId");
}
}
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("groupId");//考勤组
hrmFieldBean.setFieldlabel("390221");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("kqgroup");
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setViewAttr(1);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
replaceDatas = new ArrayList<Map<String, Object>>();
datas = new HashMap<String, Object>();
datas.put("id", groupId);
datas.put("name", kqGroupComInfo.getGroupname(groupId));
replaceDatas.add(datas);
searchConditionItem.getBrowserConditionParam().setReplaceDatas(replaceDatas);
Map<String, Object> OtherParamsMap = new HashMap<String, Object>();
OtherParamsMap.put("hasBorder", true);
searchConditionItem.setOtherParams(OtherParamsMap);
searchConditionItem.setRules("required|string");
itemList.add(searchConditionItem);
if (isEdit) {
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("holidayDate");//日期
hrmFieldBean.setFieldlabel("97");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(holidayDate);
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setViewAttr(1);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
OtherParamsMap = new HashMap<String, Object>();
OtherParamsMap.put("hasBorder", true);
searchConditionItem.setOtherParams(OtherParamsMap);
searchConditionItem.setRules("required|string");
itemList.add(searchConditionItem);
} else {
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("startDate");//开始日期
hrmFieldBean.setFieldlabel("740");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(holidayDate);
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setViewAttr(3);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
searchConditionItem.setRules("required|string");
itemList.add(searchConditionItem);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("endDate");//结束日期
hrmFieldBean.setFieldlabel("741");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setFieldvalue(holidayDate);
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setViewAttr(3);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
searchConditionItem.setRules("required|string");
itemList.add(searchConditionItem);
}
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("holidayDesc");//说明
hrmFieldBean.setFieldlabel("85");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(holidayDesc);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
if (hrmFieldBean.getViewAttr() == 1) {
OtherParamsMap = new HashMap<String, Object>();
OtherParamsMap.put("hasBorder", true);
searchConditionItem.setOtherParams(OtherParamsMap);
}
itemList.add(searchConditionItem);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("changeType");//类型
hrmFieldBean.setFieldlabel("132033");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(changeType);
hrmFieldBean.setIsFormField(true);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
List statusOptions = new ArrayList<SearchConditionOption>();
statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(16478, user.getLanguage()), changeType.equals("1")));
statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(16752, user.getLanguage()), changeType.equals("3")));
if (!Util.null2String(kqGroupComInfo.getKqtype(groupId)).equals("2")) {
statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(16751, user.getLanguage()), changeType.equals("2")));
}
searchConditionItem.setOptions(statusOptions);
searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(529901, user.getLanguage()));
searchConditionItem.setDetailtype(3);
itemList.add(searchConditionItem);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("relatedDay");//对应工作日
hrmFieldBean.setFieldlabel("16754");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue(relatedDay);
hrmFieldBean.setIsFormField(true);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
statusOptions = new ArrayList<SearchConditionOption>();
statusOptions.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(392, user.getLanguage()), relatedDay.equals("0") || relatedDay.equals("")));
statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(393, user.getLanguage()), relatedDay.equals("1")));
statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(394, user.getLanguage()), relatedDay.equals("2")));
statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(395, user.getLanguage()), relatedDay.equals("3")));
statusOptions.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(396, user.getLanguage()), relatedDay.equals("4")));
statusOptions.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(397, user.getLanguage()), relatedDay.equals("5")));
statusOptions.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(398, user.getLanguage()), relatedDay.equals("6")));
searchConditionItem.setOptions(statusOptions);
itemList.add(searchConditionItem);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("isSync");//同步到其他考勤组
hrmFieldBean.setFieldlabel("506392");
hrmFieldBean.setFieldhtmltype("4");
hrmFieldBean.setType("1");
hrmFieldBean.setIsFormField(true);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
Map<String, Object> otherParamsMap = new HashMap<String, Object>();
otherParamsMap.put("display", "switch");
searchConditionItem.setOtherParams(otherParamsMap);
itemList.add(searchConditionItem);
// XssUtil xssUtil = new XssUtil();
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("syncGroupIds");//同步到考勤组--多选
hrmFieldBean.setFieldlabel("390664");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("mkqgroup");
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setViewAttr(3);
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
searchConditionItem.setRules("required|string");
Map<String,Object> dataMap = new HashMap<String,Object>();
// dataMap.put("sqlWhere",xssUtil.put(" kqtype!=2 "));
searchConditionItem.getBrowserConditionParam().setDataParams(dataMap);
itemList.add(searchConditionItem);
groupItem.put("items", itemList);
groupList.add(groupItem);
resultMap.put("condition", groupList);
return resultMap;
}
}

@ -0,0 +1,446 @@
package com.engine.kq.cmd.myattendance;
import com.alibaba.fastjson.JSON;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.*;
import com.engine.kq.entity.WorkTimeEntity;
import weaver.common.DateUtil;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
/**
* ----
*/
public class GetHrmKQReportInfoCmd extends AbstractCommonCommand<Map<String, Object>> {
public GetHrmKQReportInfoCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public BizLogContext getLogContext() {
return null;
}
private static boolean isIndirectSuperId(String id,String checkSuperId,ResourceComInfo info){
int loopBreakTimes = 20 ;
for(String loopId = id;
isRightResourceId(loopId) && (loopBreakTimes--)>0 ;
loopId = info.getManagerID(loopId)){
if(isDirectSuperId(loopId,checkSuperId,info)) return true ;
}
return false ;
}
private static boolean isDirectSuperId(String id,String checkSuperId,ResourceComInfo info){
String superId = Util.null2String(info.getManagerID(id)) ;
return isRightResourceId(superId) && superId.equals(checkSuperId) ;
}
private static boolean isRightResourceId(String id){
return StringUtils.isNotBlank(id) && !"0".equals(id) ;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
ResourceComInfo resourceComInfo = new ResourceComInfo();
/**
*
*/
int subCompanyId = Util.getIntValue((String) params.get("subCompanyId"), 0);
int departmentId = Util.getIntValue((String) params.get("departmentId"), 0);
String resourceId = Util.null2String(params.get("resourceId"));
if (resourceId.equals("")) {
resourceId = "" + user.getUID();
}
String lastName = resourceComInfo.getResourcename(resourceId);
if (resourceId.equals("" + user.getUID())) {
resultMap.put("title", SystemEnv.getHtmlLabelName(513095, user.getLanguage()));
} else {
resultMap.put("title", SystemEnv.getHtmlLabelName(515562, user.getLanguage()).replace("{name}", lastName));
}
if (subCompanyId == 0 || departmentId == 0) {
subCompanyId = Util.getIntValue(resourceComInfo.getSubCompanyID(resourceId), 0);
departmentId = Util.getIntValue(resourceComInfo.getDepartmentID(resourceId), 0);
}
if (!resourceId.equals("" + user.getUID()) && !isIndirectSuperId(resourceId, user.getUID() + "", resourceComInfo) && !HrmUserVarify.checkUserRight("HrmResource:Absense", user, departmentId)) {
resultMap.put("status", "-1");
resultMap.put("hasRight", false);
return resultMap;
}
String fromDate = Util.null2String(params.get("fromDate"));
String toDate = Util.null2String(params.get("toDate"));
// 没有权限的人最大只支持查询本季
Map<String, String> getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1");
String realFromDate = getRealDate.get("fromDate");
String realToDate = getRealDate.get("toDate");
if("-1".equals(realFromDate) || "-1".equals(realToDate)) {
resultMap.put("status", "-1");
resultMap.put("message", SystemEnv.getHtmlLabelName(543747, user.getLanguage()));
return resultMap;
}
Calendar today = Calendar.getInstance();
/**今年*/
String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
+ Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
+ Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);
/**上一年*/
String lastYearDate = Util.add0(today.get(Calendar.YEAR) - 1, 4) + "-12-31";
String currentYear = currentDate.substring(0,4);
String balanceDate = currentDate;
String typevalue = Util.null2String(params.get("typevalue"));//指定的年份或者指定的月份
String type = Util.null2String(params.get("type"));//是查看一年的数据还是一月的数据1-年、2-月
if (type.equals("1")) {//年
if (typevalue.length() == 0 || typevalue.length() != 4) {
typevalue = DateUtil.getYear();
}
if(typevalue.compareTo(currentYear)<0){
balanceDate = typevalue + "-12-31";
}else if(typevalue.compareTo(currentYear)==0){
balanceDate = currentDate;
}else if(typevalue.compareTo(currentYear)>0){
balanceDate = typevalue + "-01-01";
}
} else if (type.equals("2")) {//月
if (typevalue.length() == 0) {
typevalue = DateUtil.getYear() + "-" + DateUtil.getMonth();
}
balanceDate = typevalue + "-01";
}
/**
*
*/
Map<String, Object> groupMap = new HashMap<String, Object>();
List<Object> groupItemList = new ArrayList<Object>();
Map<String, Object> groupItem = new HashMap<String, Object>();
List<Object> itemList = new ArrayList<Object>();
Map<String, Object> itemMap = new HashMap<String, Object>();
List<Object> itemList5 = new ArrayList<Object>();
Map<String, Object> groupItem5 = new HashMap<String, Object>();
/**
*
* workDays
* realWorkDays
* leaveDays
*/
double workDays = 0.00;
double realWorkDays = 0.00;
double leaveDays = 0.00;
/**
* beLate
* graveBeLate
* leaveEearly退
* graveLeaveEarly
* absenteeism
* forgotCheck
*/
int beLate = 0;
int graveBeLate = 0;
int leaveEearly = 0;
int graveLeaveEarly = 0;
int absenteeism = 0;
int forgotCheck = 0;
/**
* or_minimumUnit
* or_unitName()/()
* tr_minimumUnit
* tr_unitName()/()
* er_minimumUnit
* er_unitName()/()
*/
int or_minimumUnit = KQOvertimeRulesBiz.getMinimumUnit();//最小加班单位
String or_unitName = (or_minimumUnit == 3 || or_minimumUnit == 5 || or_minimumUnit == 6) ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage());
KQTravelRulesComInfo kqTravelRulesComInfo = new KQTravelRulesComInfo();
int tr_minimumUnit = Util.getIntValue(kqTravelRulesComInfo.getMinimumUnit("1"));//最小出差单位
String tr_unitName = tr_minimumUnit == 3 ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage());
KQExitRulesComInfo kqExitRulesComInfo = new KQExitRulesComInfo();
int er_minimumUnit = Util.getIntValue(kqExitRulesComInfo.getMinimumUnit("1"));//最小公出单位
String er_unitName = er_minimumUnit == 3 ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage());
/**
* overtimeTotal
* businessLeave
* officialBusiness
*/
double overtimeTotal = 0.00;//加班时长
double businessLeave = 0.00;//出差时长
double officialBusiness = 0.00;//公出时长
/**
* ()
*/
KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo();
Map<String, Object> leaveMap = new HashMap<String, Object>();
/**
* service
* com/engine/kq/cmd/report/GetKQReportCmd.java
*/
List<Map<String, Object>> datasList = new ArrayList<Map<String, Object>>();
Map<String, Object> datasMap = new HashMap<>();
datasList = (List<Map<String, Object>>) params.get("datas");
boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half"));
for (int i = 0; datasList != null && i < datasList.size(); i++) {
datasMap = (Map<String, Object>) datasList.get(i);
//String rowSpan = Util.null2String(datasMap.get("rowSpan"));
//if ("2".equalsIgnoreCase(rowSpan)) {
// 如果是开启了半天开关,那么就不可能是一天多次上下班,所以这里直接显示第一次结果就行了
if(isKqReportHalfOpen && i>0) {
break;
}
workDays += Util.getDoubleValue((String) datasMap.get("workdays"), 0.00);//应出勤天数
realWorkDays += Util.getDoubleValue((String) datasMap.get("attendancedays"), 0.00);//实际出勤天数
leaveDays = workDays - realWorkDays;//缺勤天数
beLate += Util.getIntValue((String) datasMap.get("beLate"), 0);//迟到次数
graveBeLate += Util.getIntValue((String) datasMap.get("graveBeLate"), 0);//严重迟到次数
leaveEearly += Util.getIntValue((String) datasMap.get("leaveEearly"), 0);//早退次数
graveLeaveEarly += Util.getIntValue((String) datasMap.get("graveLeaveEarly"), 0);//严重迟到次数
absenteeism += Util.getIntValue((String) datasMap.get("absenteeism"), 0);//旷工次数
forgotCheck += Util.getIntValue((String) datasMap.get("forgotCheck"), 0);//漏签次数
overtimeTotal += Util.getDoubleValue((String) datasMap.get("overtimeTotal"), 0.00);//加班时长
businessLeave += Util.getDoubleValue((String) datasMap.get("businessLeave"), 0.00);//出差时长
officialBusiness += Util.getDoubleValue((String) datasMap.get("officialBusiness"), 0.00);//公出时长
rulesComInfo.setTofirstRow();
while (i == 0 && rulesComInfo.next()) {
double value = Util.getDoubleValue(String.valueOf(leaveMap.get("leaveType_" + rulesComInfo.getId())), 0.00);
value += Util.getDoubleValue((String) datasMap.get("leaveType_" + rulesComInfo.getId()), 0.00);//请假时长
leaveMap.put("leaveType_" + rulesComInfo.getId(), value);
}
//}
}
/**统计应出勤天数*/
KQWorkTime kqWorkTime = new KQWorkTime();
if (!toDate.equals("") && toDate.compareTo(currentDate) > 0 && Util.getIntValue(resourceComInfo.getStatus(resourceId), 0) < 4) {
workDays = 0.00;
if (!fromDate.equals("") && fromDate.compareTo(currentDate) > 0) {
//查询没有到的月份缺勤天数以及出勤天数应该都为0
realWorkDays = 0.00;
leaveDays = 0.00;
}
boolean isEnd = false;
for (String date = fromDate; !isEnd; ) {
if (date.compareTo(toDate)>=0) {
isEnd = true;
}
WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(resourceId, date);
String dayType = workTimeEntity.getDayType();
String convertAttendDay = Util.null2s(workTimeEntity.getConvertAttendDay(),"1.0");
boolean isWorkDay = "work".equalsIgnoreCase(dayType);
if (isWorkDay) {
workDays += (1.00*Util.getDoubleValue(convertAttendDay, 1.0));
}
date = DateUtil.getDate(date, 1);
}
}
/**********************************************************************************************************/
itemList = new ArrayList<Object>();
itemMap = new HashMap<String, Object>();
itemMap.put("id", "leaveDays");
itemMap.put("name", SystemEnv.getHtmlLabelName(506345, user.getLanguage()));//未出勤
itemMap.put("title", SystemEnv.getHtmlLabelName(506345, user.getLanguage()));
itemMap.put("type", "ABSENT");
itemMap.put("value", String.format("%.2f", leaveDays));
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("id", "realWorkDays");
itemMap.put("name", SystemEnv.getHtmlLabelName(130566, user.getLanguage()));//实际出勤
itemMap.put("title", SystemEnv.getHtmlLabelName(130566, user.getLanguage()));
itemMap.put("type", "REALWORKDAYS");
itemMap.put("value", String.format("%.2f", realWorkDays));
itemList.add(itemMap);
groupItem = new HashMap<String, Object>();
groupItem.put("id", "workDays");
groupItem.put("name", SystemEnv.getHtmlLabelName(513089, user.getLanguage()));//应出勤(天)
groupItem.put("title", SystemEnv.getHtmlLabelName(16732, user.getLanguage()));
groupItem.put("value", String.format("%.2f", workDays));
groupItem.put("items", itemList);
resultMap.put("groupitem1", groupItem);
/**********************************************************************************************************/
itemList = new ArrayList<Object>();
itemMap = new HashMap<String, Object>();
itemMap.put("name", "evection");
itemMap.put("title", SystemEnv.getHtmlLabelName(20084, user.getLanguage()) + tr_unitName);//出差
itemMap.put("type", "EVECTION");
itemMap.put("value", String.format("%.2f",businessLeave));
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "outDays");
itemMap.put("title", SystemEnv.getHtmlLabelName(24058, user.getLanguage()) + er_unitName);//公出
itemMap.put("type", "OUTDAYS");
itemMap.put("value",String.format("%.2f",officialBusiness));
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "overTimes");
itemMap.put("title", SystemEnv.getHtmlLabelName(6151, user.getLanguage()) + or_unitName);//加班
itemMap.put("type", "OVERTIME");
itemMap.put("value", String.format("%.2f",overtimeTotal));
itemList.add(itemMap);
groupItem = new HashMap<String, Object>();
groupItem.put("items", itemList);
resultMap.put("groupitem2", groupItem);
/**********************************************************************************************************/
itemList = new ArrayList<Object>();
itemMap = new HashMap<String, Object>();
itemMap.put("name", "beLate");
itemMap.put("title", SystemEnv.getHtmlLabelName(34089, user.getLanguage()));//迟到
itemMap.put("type", "BELATE");
itemMap.put("value", beLate);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "graveBeLate");
itemMap.put("title", SystemEnv.getHtmlLabelName(535131, user.getLanguage()));//严重迟到
itemMap.put("type", "graveBeLate");
itemMap.put("value", graveBeLate);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "leaveEarly");
itemMap.put("title", SystemEnv.getHtmlLabelName(34098, user.getLanguage()));//早退
itemMap.put("type", "LEAVEEARLY");
itemMap.put("value", leaveEearly);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "graveLeaveEarly");
itemMap.put("title", SystemEnv.getHtmlLabelName(535132, user.getLanguage()));//严重早退
itemMap.put("type", "graveLeaveEarly");
itemMap.put("value", graveLeaveEarly);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "absentFromWork");
itemMap.put("title", SystemEnv.getHtmlLabelName(10000344, user.getLanguage()));//旷工
itemMap.put("type", "ABSENT");
itemMap.put("value", absenteeism);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("name", "noSign");
itemMap.put("title", SystemEnv.getHtmlLabelName(34099, user.getLanguage()));//漏签
itemMap.put("type", "noSign");
itemMap.put("value", forgotCheck);
itemList.add(itemMap);
groupItem = new HashMap<String, Object>();
groupItem.put("items", itemList);
resultMap.put("groupitem3", groupItem);
/**********************************************************************************************************/
rulesComInfo.setTofirstRow();
while (rulesComInfo.next()) {
if (!rulesComInfo.getIsEnable().equals("1") || !rulesComInfo.getBalanceEnable().equals("1")) {
continue;
}
// writeLog("lxr2018>.resourceId="+resourceId+
// ";getScopeType="+rulesComInfo.getScopeType()+
// ";getScopeValue="+rulesComInfo.getScopeValue());
boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(resourceId, rulesComInfo.getScopeType(), rulesComInfo.getScopeValue(), subCompanyId+"", departmentId+"");
if (flag) {
continue;
}
// writeLog("lxr2018>.flag="+flag);
String allRestAmount = KQBalanceOfLeaveBiz.getRestAmount("" + resourceId, rulesComInfo.getId(), balanceDate, true, true);
String currentRestAmount = KQBalanceOfLeaveBiz.getRestAmount("" + resourceId, rulesComInfo.getId(), balanceDate, true, false);
String beforeRestAmount = String.format("%.2f", Util.getDoubleValue(allRestAmount, 0) - Util.getDoubleValue(currentRestAmount, 0));
itemList = new ArrayList<Object>();
if(KQSettingsBiz.show_split_balance()) {
itemMap = new HashMap<String, Object>();
itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(513286, user.getLanguage()) : SystemEnv.getHtmlLabelName(513287, user.getLanguage()));
itemMap.put("value", beforeRestAmount);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(504395, user.getLanguage()) : SystemEnv.getHtmlLabelName(504394, user.getLanguage()));
itemMap.put("value", currentRestAmount);
itemList.add(itemMap);
itemMap = new HashMap<String, Object>();
itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(513288, user.getLanguage()) : SystemEnv.getHtmlLabelName(513289, user.getLanguage()));
itemMap.put("value", allRestAmount);
itemList.add(itemMap);
}else{
itemMap = new HashMap<String, Object>();
itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(513288, user.getLanguage()) : SystemEnv.getHtmlLabelName(513289, user.getLanguage()));
itemMap.put("value", allRestAmount);
itemList.add(itemMap);
}
groupItem = new HashMap<String, Object>();
groupItem.put("color", "#25C6DA");
groupItem.put("icon", "icon-Human-resources-adjustment");
groupItem.put("title", rulesComInfo.getLeaveName());
groupItem.put("item", itemList);
groupItemList.add(groupItem);
}
groupMap.put("items", groupItemList);
groupMap.put("title", SystemEnv.getHtmlLabelName(132058, user.getLanguage()));
resultMap.put("groupitem4", groupMap);
/**********************************************************************************************************/
rulesComInfo.setTofirstRow();
while (rulesComInfo.next()) {
boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(resourceId, rulesComInfo.getScopeType(), rulesComInfo.getScopeValue(), subCompanyId+"", departmentId+"");
if (flag) {
continue;
}
double value = Util.getDoubleValue(String.valueOf(leaveMap.get("leaveType_" + rulesComInfo.getId())), 0.00);//请假时长
if (value > 0) {
String leaveName = Util.formatMultiLang(rulesComInfo.getLeaveName(), "" + user.getLanguage());
int le_minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(), 1);//最小请假单位
String le_unitName = (le_minimumUnit == 3 || le_minimumUnit == 5 || le_minimumUnit == 6) ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage());
itemMap = new HashMap<String, Object>();
itemMap.put("name", "leaveType_" + rulesComInfo.getId());
itemMap.put("title", leaveName + le_unitName);
itemMap.put("type", "leaveType_" + rulesComInfo.getId());
itemMap.put("value", Util.toDecimalDigits("" + value, 2));
itemList5.add(itemMap);
}
}
groupItem5.put("items", itemList5);
resultMap.put("groupitem5", groupItem5);
resultMap.put("status", "1");
} catch (Exception e) {
writeLog(e);
}
return resultMap;
}
}

@ -0,0 +1,902 @@
package com.engine.kq.cmd.report;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.*;
import com.engine.kq.util.ExcelUtil;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.UtilKQ;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import com.google.common.collect.Lists;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class ExportExcelCmd extends AbstractCommonCommand<Map<String, Object>> {
private HttpServletRequest request;
private HttpServletResponse response;
private List<String> lsFieldDataKey;
private boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half"));
public ExportExcelCmd(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, User user) {
this.user = user;
this.params = params;
this.request = request;
this.response = response;
this.lsFieldDataKey = new ArrayList<>();
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
String sql = "";
try {
SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
KQReportBiz kqReportBiz = new KQReportBiz();
new KQReportBiz().insertKqReportExportLog(params, user);
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial"));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect = Util.null2String(jsonObj.get("typeselect"));
if (typeselect.length() == 0) typeselect = "3";
if (!typeselect.equals("") && !typeselect.equals("0") && !typeselect.equals("6")) {
if (typeselect.equals("1")) {
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
} else {
fromDate = TimeUtil.getDateByOption(typeselect, "0");
toDate = TimeUtil.getDateByOption(typeselect, "1");
}
}
//人员状态
String status = Util.null2String(jsonObj.get("status"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String allLevel = Util.null2String(jsonObj.get("allLevel"));
String isNoAccount = Util.null2String(jsonObj.get("isNoAccount"));
String viewScope = Util.null2String(jsonObj.get("viewScope"));
List<String> showColumns = Util.splitString2List(Util.null2String(jsonObj.get("showColumns")), ",");
showColumns.add("lastname");
showColumns.removeIf(showColumn->showColumn.trim().equals(""));
List<String> tmpShowColumns = new ArrayList<>();
for(String showColumn:showColumns){
tmpShowColumns.add(showColumn);
String cascadekey = "";
if(showColumn.equals("beLate")){
cascadekey = "beLateMins";
}else if(showColumn.equals("leaveEearly")){
cascadekey = "leaveEarlyMins";
}else if(showColumn.equals("graveBeLate")){
cascadekey = "graveBeLateMins";
}else if(showColumn.equals("graveLeaveEarly")){
cascadekey = "graveLeaveEarlyMins";
}else if(showColumn.equals("absenteeism")){
cascadekey = "absenteeismMins";
}else if(showColumn.equals("overtime")){
tmpShowColumns.add("overtime_4leave");
tmpShowColumns.add("overtime_nonleave");
tmpShowColumns.add("workingDayOvertime_nonleave");
tmpShowColumns.add("workingDayOvertime_4leave");
tmpShowColumns.add("restDayOvertime_nonleave");
tmpShowColumns.add("restDayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_nonleave");
}
if(cascadekey.length()>0){
tmpShowColumns.add(cascadekey);
}
}
showColumns = tmpShowColumns;
String rightSql = new KQReportBiz().getReportRight("1", "" + user.getUID(), "a");
LinkedHashMap<String, Object> workbook = new LinkedHashMap<>();
List<Object> lsSheet = new ArrayList<>();
Map<String, Object> sheet = null;
List<Object> titleList = new ArrayList<>();
Map<String, Object> title = null;
List<List<Object>> dataList = new ArrayList<>();
List<Object> data = null;
List<Map<String, Object>> constraintList = null;
sheet = new HashMap<>();
sheet.put("sheetName", SystemEnv.getHtmlLabelName(390351, user.getLanguage()));
sheet.put("sheetTitle", SystemEnv.getHtmlLabelName(390351, user.getLanguage()));
boolean isEnd = false;
Calendar cal = DateUtil.getCalendar();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
Map<String, Object> mapChildColumnInfo = null;
List<Object> childColumns = null;
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()) {
if (Util.null2String(kqReportFieldComInfo.getParentid()).length() > 0) continue;
if(kqReportFieldComInfo.getFieldname().equals("kqCalendar"))continue;
if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue;
if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))
continue;
if (!showColumns.contains(kqReportFieldComInfo.getFieldname())&&!showColumns.contains(kqReportFieldComInfo.getParentid())) continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
title = new HashMap<>();
String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user);
if(unitType.length()>0){
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ "(" + unitType + ")");
}else{
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
}
title.put("width", 30 * 256);
this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(), user);
childColumns = (List<Object>) mapChildColumnInfo.get("childColumns");
if (childColumns.size() > 0) {//跨列width取子列的width
title.put("children", childColumns);
title.put("colSpan", childColumns.size());
} else {
title.put("rowSpan", 3);
}
titleList.add(title);
titleList.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user));
}
String today = DateUtil.getCurrentDate();
// if (DateUtil.compDate(today, toDate) > 0) {//结束如期不大于今天
// toDate = today;
// }
if(showColumns.contains("kqCalendar")) {
childColumns = new ArrayList<>();
for (String date = fromDate; !isEnd; ) {
if (date.equals(toDate)) isEnd = true;
title = new HashMap<>();
title.put("title", UtilKQ.getWeekDayShort(DateUtil.getWeek(date)-1,user.getLanguage()) +"\r\n"+ DateUtil.geDayOfMonth(date));
title.put("width", 30 * 256);
childColumns.add(title);
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
title = new HashMap();
title.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage()));
if (childColumns.size() > 0) {//跨列width取子列的width
title.put("children", childColumns);
title.put("colSpan", childColumns.size());
}
titleList.add(title);
}
sheet.put("titleList", titleList);
// 没有权限的人最大只支持查询本季
Map<String, String> getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1");
fromDate = getRealDate.get("fromDate");
toDate = getRealDate.get("toDate");
if("-1".equals(fromDate) || "-1".equals(toDate)) {
retmap.put("status", "1");
return retmap;
}
List<List> paramLists = new ArrayList<>();
List<Object> paramList = null;
String forgotBeginWorkCheck_field = " sum(b.forgotBeginWorkCheck) ";
if(rs.getDBType().equalsIgnoreCase("oracle")) {
forgotBeginWorkCheck_field = " sum(nvl(b.forgotBeginWorkCheck,0)) ";
}else if((rs.getDBType()).equalsIgnoreCase("mysql")){
forgotBeginWorkCheck_field = " sum(ifnull(b.forgotBeginWorkCheck,0)) ";
}else {
forgotBeginWorkCheck_field = " sum(isnull(b.forgotBeginWorkCheck,0)) ";
}
Map<String,Object> definedFieldInfo = new KQFormatBiz().getDefinedField();
String definedFieldSum = Util.null2String(definedFieldInfo.get("definedFieldSum"));
String backFields = " a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," +
" sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," +
" sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " +
" sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," +
" sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " +
" sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " +
" sum(b.signdays) as signdays,sum(b.signmins) as signmins, "+
" sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+"+forgotBeginWorkCheck_field+" as forgotCheck "+(definedFieldSum.length()>0?","+definedFieldSum+"":"");
if(rs.getDBType().equals("oracle")){
backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields;
}
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'";
String sqlWhere = rightSql;
String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle ";
if (subCompanyId.length() > 0) {
sqlWhere +=" and a.subcompanyid1 in("+KQReportBiz.splitParamStr(subCompanyId)+") ";
for(String bean : subCompanyId.split(",")) {
paramList = new ArrayList<>();
paramList.add(bean);
paramLists.add(paramList);
}
}
if (departmentId.length() > 0) {
sqlWhere +=" and a.departmentid in("+KQReportBiz.splitParamStr(departmentId)+") ";
for(String bean : departmentId.split(",")) {
paramList = new ArrayList<>();
paramList.add(bean);
paramLists.add(paramList);
}
}
if (resourceId.length() > 0) {
sqlWhere +=" and a.id in("+KQReportBiz.splitParamStr(resourceId)+") ";
for(String bean : resourceId.split(",")) {
paramList = new ArrayList<>();
paramList.add(bean);
paramLists.add(paramList);
}
}
if (viewScope.equals("4")) {//我的下属
if (allLevel.equals("1")) {//所有下属
sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'";
} else {
sqlWhere += " and a.managerid=" + user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = ?";
paramList = new ArrayList<>();
paramList.add(status);
paramLists.add(paramList);
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
String orderBy = " order by a.dsporder asc, a.lastname asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc ";
sql = "select " + backFields + sqlFrom + sqlWhere + groupBy + orderBy;
//System.out.println("start" + DateUtil.getFullDate());
String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源
params.put("show_card_source",show_card_source);
KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz();
int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位
double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系
params.put("uintType",uintType);
params.put("hoursToDay",hoursToDay);
Map<String, Object> flowData = new KQReportBiz().getFlowData(params, user);
//System.out.println("end" + DateUtil.getFullDate());
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
rs.executeQuery(sql, paramLists);
int calIndex = -1;
while (rs.next()) {
data = new ArrayList<>();
String id = rs.getString("id");
for (int fieldDataKeyIdx =0;fieldDataKeyIdx<lsFieldDataKey.size();fieldDataKeyIdx++) {
String fieldName = lsFieldDataKey.get(fieldDataKeyIdx);
String fieldid = KQReportFieldComInfo.field2Id.get(fieldName);
String fieldValue = "";
if (fieldName.equals("subcompany")) {
String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid"));
if (tmpSubcompanyId.length() == 0) {
tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id));
}
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") :
subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
// fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
} else if (fieldName.equals("department")) {
String tmpDepartmentId = Util.null2String(rs.getString("departmentid"));
if (tmpDepartmentId.length() == 0) {
tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id));
}
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") :
departmentComInfo.getDepartmentname(tmpDepartmentId);
// fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId);
} else if(fieldName.equals("zcgzts")){
String rlzqqxsTime = getXcqts(fromDate,id);
fieldValue = rlzqqxsTime;
} else if (fieldName.equals("jobtitle")) {
String tmpJobtitleId = Util.null2String(rs.getString("jobtitle"));
if (tmpJobtitleId.length() == 0) {
tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id));
}
fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId);
} else if (fieldName.equals("attendanceSerial")) {
List<String> serialIds = null;
if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) {
serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ",");
for(int i=0;serialIds!=null&&i<serialIds.size();i++){
data.add(kqReportBiz.getSerialCount(id,fromDate,toDate,serialIds.get(i)));
}
}else{
data.add("");
}
continue;
} else if (fieldName.equals("leave")) {//请假
List<Map<String, Object>> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = allLeaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = allLeaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
allLeaveRules.remove(i);
}
}
}
Map<String, Object> leaveRule = null;
for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) {
leaveRule = allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_" + leaveRule.get("id"));
String leaveData = Util.null2String(flowData.get(id + "|" + flowType));
String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + flowLeaveBackType)), "0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try {
//以防止出现精度问题
if (leaveData.length() == 0) {
leaveData = "0.0";
}
if (leavebackData.length() == 0) {
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(leaveData);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
} catch (Exception e) {
writeLog("GetKQReportCmd:leaveData" + leaveData + ":leavebackData:" + leavebackData + ":" + e);
}
if (b_flowLeaveData.length() > 0) {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
} else {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData, 0.0) - Util.getDoubleValue(leavebackData, 0.0)));
}
data.add(flowLeaveData);
}
continue;
}else if(fieldName.equals("overtime")){
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave"))));
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal"))));
continue;
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
} else if(Util.null2String(kqReportFieldComInfo.getCascadekey(fieldid)).length()>0){
fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage());
data.add(fieldValue);
List<String> lsCascadekey = Util.splitString2List(kqReportFieldComInfo.getCascadekey(fieldid),",");
for(int i=0;i<lsCascadekey.size();i++){
if(Util.null2String(rs.getString(lsCascadekey.get(i))).length()>0){
fieldid = KQReportFieldComInfo.field2Id.get(lsCascadekey.get(i));
fieldValue = getFieldValueByUnitType(rs.getString(lsCascadekey.get(i)),kqReportFieldComInfo.getUnittype(fieldid));
}else{
fieldValue = "0";
}
data.add(fieldValue);
}
continue;
}else {
fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage());
fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid));
}
fieldValue = Util.formatMultiLang(fieldValue,""+user.getLanguage());
data.add(fieldValue);
}
List<Object> amData = Lists.newArrayList();
List<Object> pmData = Lists.newArrayList();
if(isKqReportHalfOpen) {
amData.addAll(data);
pmData.addAll(data);
calIndex = data.size();
}
if(showColumns.contains("kqCalendar")) {
// Map<String, Object> detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true);
Map<String, Object> detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true,uintType,show_card_source);
String user_endDate = Util.null2String(resourceComInfo.getEndDate(id));
String user_status = Util.null2String(resourceComInfo.getStatus(id));
String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim();
String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim();
if(companyStartDate.length()!=10){
companyStartDate = "";
}
if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){
begindate=companyStartDate;
}
isEnd = false;
for (String date = fromDate; !isEnd; ) {
if (date.equals(toDate)) isEnd = true;
if(DateUtil.compDate(today, date)>0){
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
}else{
if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){
//其他状态
if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
continue;
}
}
if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
continue;
}
if (detialDatas.get(id + "|" + date) != null) {
if(isKqReportHalfOpen) {
amData.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("textAM"));
pmData.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("textPM"));
} else {
data.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("text"));
}
} else {
if(isKqReportHalfOpen) {
amData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
pmData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
} else {
data.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
}
}
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
}
if(isKqReportHalfOpen) {
dataList.add(amData);
dataList.add(pmData);
} else {
dataList.add(data);
}
}
sheet.put("dataList", dataList);
if(isKqReportHalfOpen) {
sheet.put("calIndex", calIndex);
}
sheet.put("constraintList", constraintList);
sheet.put("createFile", "1");
lsSheet.add(sheet);
workbook.put("sheet", lsSheet);
String fileName = SystemEnv.getHtmlLabelName(390351, user.getLanguage())+" "+fromDate+" "+toDate;
workbook.put("fileName", fileName);
ExcelUtil ExcelUtil = new ExcelUtil();
Map<String, Object> exportMap = ExcelUtil.export(workbook, request, response,true);
retmap.putAll(exportMap);
retmap.put("status", "1");
} catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage()));
writeLog(e);
}
return retmap;
}
private Map<String, Object> getChildColumnsInfo(String parentid, User user) {
Map<String, Object> returnMap = new HashMap<>();
List<Object> titleList = new ArrayList<>();
Map<String, Object> title = null;
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
if (parentid.equals("attendanceSerial")) {//考勤班次
KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo();
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
List<String> serialIds = null;
if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) {
serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ",");
}
for (int i = 0; serialIds != null && i < serialIds.size(); i++) {
title = new HashMap<>();
title.put("title", Util.formatMultiLang(kqShiftManagementComInfo.getSerial(serialIds.get(i)),""+user.getLanguage()));
title.put("width", 30 * 256);
titleList.add(title);
}
} else if (parentid.equals("leave")) {
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = leaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = leaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
leaveRules.remove(i);
}
}
}
for (int i = 0; leaveRules != null && i < leaveRules.size(); i++) {
Map<String, Object> leaveRule = leaveRules.get(i);
String name = Util.formatMultiLang(Util.null2String(leaveRule.get("name")),""+user.getLanguage());
String unitType = Util.null2String(leaveRule.get("unitType"));
String unitName = (KQUnitBiz.isLeaveHour(unitType)) ? SystemEnv.getHtmlLabelName(391, user.getLanguage()) : SystemEnv.getHtmlLabelName(1925, user.getLanguage());
title = new HashMap<>();
title.put("title", name + "(" + unitName + ")");
title.put("width", 30 * 256);
titleList.add(title);
}
}else if(parentid.equals("overtime")){
String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"};
for(int i=0;i<overtimeChild.length;i++){
String id = overtimeChild[i];
title = new HashMap();
String fieldlabel = "";
if("overtime_nonleave".equalsIgnoreCase(id)){
fieldlabel = "125805";
title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
title.put("rowSpan","2");
}else if("overtime_4leave".equalsIgnoreCase(id)){
fieldlabel = "125804";
title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
title.put("rowSpan","2");
}else{
fieldlabel = "523";
title.put("showDetial","1");
String unitType = (KQOvertimeRulesBiz.getMinimumUnit()==3 || KQOvertimeRulesBiz.getMinimumUnit()==5 ||KQOvertimeRulesBiz.getMinimumUnit()==6)?"2":"1";
String unitTypeName = "";
if(Util.null2String(unitType).length()>0){
if(unitType.equals("1")){
unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage());
}else if(unitType.equals("2")){
unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage());
}else if(unitType.equals("3")){
unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage());
}
}
title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())+ "(" + unitTypeName + ")");
}
Map<String,Object> mapChildColumnInfo = getChildColumnsInfo(id, user);
int childWidth = 65;
List<Object> childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
title.put("children", childColumns);
childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65);
}
title.put("width", childWidth+"");
titleList.add(title);
}
} else {
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()) {
if (kqReportFieldComInfo.getParentid().equals(parentid)) {
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
title = new HashMap<>();
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")");
title.put("width", 30 * 256);
titleList.add(title);
}
}
}
returnMap.put("childColumns", titleList);
return returnMap;
}
private List<Object> getCascadeKeyColumnsInfo(String cascadeKey, User user){
List<Object> titleList = new ArrayList<>();
Map<String, Object> title = null;
if(Util.null2String(cascadeKey).length()==0){
return titleList;
}
List<String> lsCascadeKey = Util.splitString2List(cascadeKey,",");
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
for(int i=0;i<lsCascadeKey.size();i++){
kqReportFieldComInfo.setTofirstRow();
while (kqReportFieldComInfo.next()) {
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
if (kqReportFieldComInfo.getFieldname().equals(lsCascadeKey.get(i))){
title = new HashMap<>();
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")");
title.put("width", 30 * 256);
titleList.add(title);
}
}
}
return titleList;
}
private String getFieldValueByUnitType(String fieldValue,String unittype){
if (Util.null2String(unittype).length() > 0) {
if (fieldValue.length() == 0) {
fieldValue = "0";
} else {
if (unittype.equals("2")) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
}
}
return fieldValue;
}
@Override
public BizLogContext getLogContext() {
return null;
}
/**
*
*
* @return
*/
public static String findRzrq(String jbr) {
RecordSet rs = new RecordSet();
String sql = "select id,companystartdate from hrmresource where id ="+jbr;
rs.executeQuery(sql);
String companystartdate = "";
if (rs.next()) {
companystartdate = Util.null2String(rs.getString("companystartdate"));
}
return companystartdate;
}
/**
*
*
* @return
*/
public static String findLzrq(String jbr) {
RecordSet rs = new RecordSet();
String sql = "select changedate from HrmStatusHistory where RESOURCEID ="+jbr+" and type_n = 5";
rs.executeQuery(sql);
String changedate = "";
if (rs.next()) {
changedate = Util.null2String(rs.getString("changedate"));
}
return changedate;
}
/**
*
* @param dateOri
* @param userId
* @return
*/
public String getXcqts(String dateOri,String userId){
//需出勤天数
Integer xcqtsAll = 0;
//获取员工的入职日期
String rzrq = findRzrq(userId);
//获取员工的离职日期
String lzrq = findLzrq(userId);
String dateOriSub = dateOri.substring(0,7);
//本月第一天
String fromDate = TimeUtil.getMonthBeginDay(dateOri);
//本月最后一天
String toDate = TimeUtil.getMonthEndDay(dateOri);
//入职日期处理
if(StringUtils.isNotBlank(rzrq)){
String rzrqSub = rzrq.substring(0,7);
if(rzrqSub.equals(dateOriSub)){
//入职日期在当月
Set<String> all = new HashSet<>();
all.add(fromDate);
List<String> back = days(fromDate,rzrq);
all.addAll(back);
for (String date : all) {
Integer zcgzts = 0;
KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo();
String changeTypeNew = holidaySetComInfo.getChangeType("1", date);
// if("2".equals(changeTypeNew)){
// //调配工作日计正常工作天数
// zcgzts = 1;
// }
if(DateUtil.getWeek(date) != 6 && DateUtil.getWeek(date) != 7){
//不为周六周日
if(!"3".equals(changeTypeNew)){
//不为休息日
zcgzts = 1;
}
}
xcqtsAll = xcqtsAll+zcgzts;
}
}
}
//离职日期处理
if(StringUtils.isNotBlank(lzrq)){
String lzrqSub = lzrq.substring(0,7);
if(lzrqSub.equals(dateOriSub)){
//离职日期在当月
Set<String> all = new HashSet<>();
List<String> back = days(lzrq,toDate);
all.addAll(back);
all.add(toDate);
for (String date : all) {
Integer zcgzts = 0;
KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo();
String changeTypeNew = holidaySetComInfo.getChangeType("1", date);
// if("2".equals(changeTypeNew)){
// //调配工作日计正常工作天数
// zcgzts = 1;
// }
if(DateUtil.getWeek(date) != 6 && DateUtil.getWeek(date) != 7){
//不为周六周日
if(!"3".equals(changeTypeNew)){
//不为休息日
zcgzts = 1;
}
}
xcqtsAll = xcqtsAll+zcgzts;
}
}
}
Integer newXcqTime = xcqtsAll * 8;
new BaseBean().writeLog(userId+"newXcqTime"+newXcqTime);
return String.valueOf(newXcqTime);
}
/**
*
* @param date1
* @param date2
* @return
*/
public static ArrayList days(String date1, String date2) {
String dateFormat = "yyyy-MM-dd";
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
ArrayList L = new ArrayList();
if (date1.equals(date2)) {
System.out.println("两个日期相等!");
return L;
}
String tmp;
if (date1.compareTo(date2) > 0) { // 确保 date1的日期不晚于date2
tmp = date1;
date1 = date2;
date2 = tmp;
}
tmp = format.format(str2Date(date1).getTime() + 3600 * 24 * 1000);
int num = 0;
while (tmp.compareTo(date2) < 0) {
L.add(tmp);
num++;
tmp = format.format(str2Date(tmp).getTime() + 3600 * 24 * 1000);
}
if (num == 0)
System.out.println("两个日期相邻!");
return L;
}
private static Date str2Date(String str) {
String dateFormat = "yyyy-MM-dd";
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
if (str == null)
return null;
try {
return format.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,407 @@
package com.engine.kq.cmd.shiftschedule;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.bean.SelectOption;
import com.api.hrm.bean.WeaRadioGroup;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.cloudstore.dev.api.util.Util_TableMap;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQGroupBiz;
import com.engine.kq.biz.KQGroupComInfo;
import com.engine.kq.biz.KQHolidaySetBiz;
import com.engine.kq.biz.KQShiftManagementComInfo;
import com.engine.kq.util.PageUidFactory;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.filter.XssUtil;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.util.*;
public class GetBatchShiftScheduleFromCmd extends AbstractCommonCommand<Map<String, Object>> {
public GetBatchShiftScheduleFromCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
String sql = "";
List<HrmFieldBean> lsField = new ArrayList<HrmFieldBean>();
HrmFieldBean hrmFieldBean = null;
List<SearchConditionOption> options = null;
Map<String,SearchConditionItem> mapItem = new HashMap<>();
try{
//必要的权限判断
if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return retmap;
}
KQGroupComInfo kQGroupComInfo = new KQGroupComInfo();
KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo();
String groupId = Util.null2String(params.get("groupId"));//考勤组id
//排班类型、排班日期、排班人员、班次
//排班类型、排班开始日期、排班人员、遇节假日、排班周期
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("shiftScheduleType");
hrmFieldBean.setFieldlabel("389494");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
hrmFieldBean.setFieldvalue("1");
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(389506, user.getLanguage()),true));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(389507, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("shiftScheduleDate");
hrmFieldBean.setFieldlabel("16694");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setViewAttr(3);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("shiftScheduleBeginDate");
hrmFieldBean.setFieldlabel("16694");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setIsFormField(true);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("shiftScheduleEndDate");
hrmFieldBean.setFieldlabel("16694");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("2");
hrmFieldBean.setViewAttr(3);
hrmFieldBean.setIsFormField(true);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("shiftScheduleMember");
hrmFieldBean.setFieldlabel("125839");
hrmFieldBean.setFieldhtmltype("3");
hrmFieldBean.setType("17");
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("holidayType");
hrmFieldBean.setFieldlabel("500436");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("meetHolidays");
hrmFieldBean.setFieldlabel("529182");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("meetRestDays");
hrmFieldBean.setFieldlabel("528922");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("serialId");
hrmFieldBean.setFieldlabel("24803");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
String[] serialids = Util.splitString(Util.null2String(kQGroupComInfo.getSerialids(groupId)),",");
for(int i=0;serialids!=null&&i<serialids.length;i++){
options.add(new SearchConditionOption(serialids[i],kQShiftManagementComInfo.getSerial(serialids[i]),i==0));
}
options.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(26593, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("serialIdSx");
hrmFieldBean.setFieldlabel("24803");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
for(int i=0;serialids!=null&&i<serialids.length;i++){
options.add(new SearchConditionOption(serialids[i],kQShiftManagementComInfo.getSerial(serialids[i]),i==0));
}
options.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(26593, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("serialIdJjr");
hrmFieldBean.setFieldlabel("24803");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
for(int i=0;serialids!=null&&i<serialids.length;i++){
options.add(new SearchConditionOption(serialids[i],kQShiftManagementComInfo.getSerial(serialids[i]),i==0));
}
options.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(26593, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("serialIdXxr");
hrmFieldBean.setFieldlabel("24803");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
for(int i=0;serialids!=null&&i<serialids.length;i++){
options.add(new SearchConditionOption(serialids[i],kQShiftManagementComInfo.getSerial(serialids[i]),i==0));
}
options.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(26593, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("serialIdGzr");
hrmFieldBean.setFieldlabel("24803");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
for(int i=0;serialids!=null&&i<serialids.length;i++){
options.add(new SearchConditionOption(serialids[i],kQShiftManagementComInfo.getSerial(serialids[i]),i==0));
}
options.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(26593, user.getLanguage())));
hrmFieldBean.setSelectOption(options);
lsField.add(hrmFieldBean);
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("shiftcycleId");
hrmFieldBean.setFieldlabel("389103");
hrmFieldBean.setFieldhtmltype("5");
hrmFieldBean.setType("1");
options = new ArrayList<SearchConditionOption>();
sql = "select id,shiftcyclename,shiftcycleserialids from kq_group_shiftcycle where groupid = ? order by id asc ";
rs.executeQuery(sql,groupId);
while(rs.next()){
options.add(new SearchConditionOption(Util.null2String(rs.getString("id")),Util.null2String(rs.getString("shiftcyclename")),true));
hrmFieldBean.setSelectOption(options);
}
lsField.add(hrmFieldBean);
HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
SearchConditionItem searchConditionItem = null;
for (int i = 0; i < lsField.size(); i++) {
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(lsField.get(i), user);
if(lsField.get(i).getFieldname().equals("shiftScheduleMember")){
XssUtil xssUtil = new XssUtil();
Map<String,Object> tmpParams = new HashMap<>();
tmpParams.put("groupId",groupId);
tmpParams.put("isNoAccount",1);
String groupMemberSql = new KQGroupBiz().getGroupMemberSql(tmpParams);
String inSqlWhere = " hr.id in (select resourceid from (" + groupMemberSql + ") t1)";
String inSqlWhere1 = " t1.id in (select resourceid from (" + groupMemberSql + ") t1)";
if(!Util.null2String(kQGroupComInfo.getExcludecount(groupId)).equals("1")) {
//剔除无需排班人员
String excludeid = Util.null2String(kQGroupComInfo.getExcludeid(groupId));
if (excludeid.length() > 0) {
inSqlWhere += " and hr.id not in (" + excludeid + ")";
inSqlWhere1 += " and t1.id not in (" + excludeid + ")";
}
}
searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlwhere", xssUtil.put(inSqlWhere));
searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlwhere", xssUtil.put(inSqlWhere1));
}
mapItem.put(lsField.get(i).getFieldname(),searchConditionItem);
}
//下拉
List<Object> condition = new ArrayList<Object>();
condition.add(mapItem.get("shiftScheduleType"));
//按天排班
Map<String,Object> conditionMap = new HashMap<String, Object>();
List<Object> conditionlist = null;
List<Object> conditionlist2 = null;
conditionlist = new ArrayList<Object>();
conditionlist2 = new ArrayList<Object>();
conditionlist2.add(mapItem.get("shiftScheduleDate"));
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
WeaRadioGroup wrg = new WeaRadioGroup();
wrg.setLabel(SystemEnv.getHtmlLabelName(125839, user.getLanguage()));
List<Object> option = new ArrayList<>();
Map<String, Object> selectLinkageDatas = new HashMap<String, Object>();
selectLinkageDatas.put("2" ,mapItem.get("shiftScheduleMember"));
wrg.setSelectLinkageDatas(selectLinkageDatas);
option.add(new SelectOption("1",SystemEnv.getHtmlLabelName(389496, user.getLanguage()),true));
option.add(new SelectOption("2",SystemEnv.getHtmlLabelName(33210, user.getLanguage())));
List<String> domkey = new ArrayList<String>();
wrg.setOptions(option);
wrg.setConditionType("SELECT_LINKAGE");
wrg.setFieldcol(18);
wrg.setLabelcol(6);
domkey.add("shiftScheduleMemberType");
wrg.setDomkey(domkey);
conditionlist2.add(wrg);
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
conditionlist2.add(mapItem.get("serialId"));
conditionlist.add(conditionlist2);
conditionMap.put("1",conditionlist);
//按周期排班
conditionlist = new ArrayList<Object>();
conditionlist2 = new ArrayList<Object>();
conditionlist2.add(mapItem.get("shiftScheduleBeginDate"));
conditionlist2.add(mapItem.get("shiftScheduleEndDate"));
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
conditionlist2.add(wrg);
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
WeaRadioGroup wrgH = new WeaRadioGroup();
wrgH.setLabel(SystemEnv.getHtmlLabelName(500436, user.getLanguage()));
List<Object> optionH = new ArrayList<>();
Map<String, Object> selectLinkageDatasH = new HashMap<String, Object>();
selectLinkageDatasH.put("3" ,mapItem.get("serialIdSx"));
wrgH.setSelectLinkageDatas(selectLinkageDatasH);
optionH.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
optionH.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
optionH.add(new SelectOption("3","替换为指定班次"));
List<String> domkeyH = new ArrayList<String>();
wrgH.setOptions(optionH);
wrgH.setConditionType("SELECT_LINKAGE");
wrgH.setFieldcol(18);
wrgH.setLabelcol(6);
domkeyH.add("holidayType");
wrgH.setDomkey(domkeyH);
conditionlist2.add(wrgH);
// conditionlist2.add(mapItem.get("holidayType"));
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
WeaRadioGroup wrgJ = new WeaRadioGroup();
wrgJ.setLabel(SystemEnv.getHtmlLabelName(529182, user.getLanguage()));
List<Object> optionJ = new ArrayList<>();
Map<String, Object> selectLinkageDatasJ = new HashMap<String, Object>();
selectLinkageDatasJ.put("3" ,mapItem.get("serialIdJjr"));
wrgJ.setSelectLinkageDatas(selectLinkageDatasJ);
optionJ.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
optionJ.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
optionJ.add(new SelectOption("3","替换为指定班次"));
List<String> domkeyJ = new ArrayList<String>();
wrgJ.setOptions(optionJ);
wrgJ.setConditionType("SELECT_LINKAGE");
wrgJ.setFieldcol(18);
wrgJ.setLabelcol(6);
domkeyJ.add("meetHolidays");
wrgJ.setDomkey(domkeyJ);
conditionlist2.add(wrgJ);
// conditionlist2.add(mapItem.get("meetHolidays"));
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
WeaRadioGroup wrgX = new WeaRadioGroup();
wrgX.setLabel(SystemEnv.getHtmlLabelName(528922, user.getLanguage()));
List<Object> optionX = new ArrayList<>();
Map<String, Object> selectLinkageDatasX = new HashMap<String, Object>();
selectLinkageDatasX.put("3" ,mapItem.get("serialIdXxr"));
wrgX.setSelectLinkageDatas(selectLinkageDatasX);
optionX.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
optionX.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
optionX.add(new SelectOption("3","替换为指定班次"));
List<String> domkeyX = new ArrayList<String>();
wrgX.setOptions(optionX);
wrgX.setConditionType("SELECT_LINKAGE");
wrgX.setFieldcol(18);
wrgX.setLabelcol(6);
domkeyX.add("meetRestDays");
wrgX.setDomkey(domkeyX);
conditionlist2.add(wrgX);
// conditionlist2.add(mapItem.get("meetRestDays"));
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
WeaRadioGroup wrgG = new WeaRadioGroup();
wrgG.setLabel("遇调配工作日");
List<Object> optionG = new ArrayList<>();
Map<String, Object> selectLinkageDatasG = new HashMap<String, Object>();
selectLinkageDatasG.put("3" ,mapItem.get("serialIdGzr"));
wrgG.setSelectLinkageDatas(selectLinkageDatasG);
optionG.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true));
optionG.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage())));
optionG.add(new SelectOption("3","替换为指定班次"));
List<String> domkeyG = new ArrayList<String>();
wrgG.setOptions(optionG);
wrgG.setConditionType("SELECT_LINKAGE");
wrgG.setFieldcol(18);
wrgG.setLabelcol(6);
domkeyG.add("meetworkDays");
wrgG.setDomkey(domkeyG);
conditionlist2.add(wrgG);
// conditionlist2.add(mapItem.get("meetRestDays"));
conditionlist.add(conditionlist2);
conditionlist2 = new ArrayList<Object>();
conditionlist2.add(mapItem.get("shiftcycleId"));
conditionlist.add(conditionlist2);
conditionMap.put("2",conditionlist);
condition.add(conditionMap);
retmap.put("conditions", condition);
retmap.put("status", "1");
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
return retmap;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,630 @@
package com.engine.kq.cmd.shiftschedule;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.bean.KqShiftscheduleOperateLog;
import com.engine.kq.biz.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.file.ImageFileManager;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.Reminder.KQAutoCardTask;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.text.SimpleDateFormat;
import java.util.*;
public class ImportExcelCmd extends AbstractCommonCommand<Map<String, Object>> {
private String today = weaver.common.DateUtil.getCurrentDate();
private SimpleBizLogger logger;
// 添加日志功能
private List<List<Object>> operateLogParams = new ArrayList<>();
// 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id
private List<Object> operateLogParam = null;
public ImportExcelCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
this.logger = new SimpleBizLogger();
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
BatchRecordSet bRs = new BatchRecordSet();
String sql = "";
try {
//必要的权限判断
if (!HrmUserVarify.checkUserRight("HrmKQGroup:Add", user)) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return retmap;
}
ResourceComInfo resourceComInfo = new ResourceComInfo();
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
KQGroupBiz kqGroupBiz = new KQGroupBiz();
KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo();
String groupId = Util.null2String(params.get("groupId"));
List<String> managerRoleUserIdList = new KqShiftScheduleRoleBiz().getUfKqShiftScheduleRoleValue(""+user.getUID(), groupId);
String filename = Util.null2String(params.get("filename"));
List lsColumn = null;
List<List<Object>> paramInsert = new ArrayList<List<Object>>();
List<List<Object>> paramUpdate = new ArrayList<List<Object>>();
List<Object> param = null;
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
List<List<Object>> delValidateParams = new ArrayList<>();
List<Object> validateParams = null;
List<List<Object>> lscheckSerialParams = new ArrayList<>();
List<Object> checkSerialParams = null;
Map<String,Object> mapShiftSchedule = new HashMap<>();
Map<String,String> mapSerial = new HashMap<>();
Map<String,String> mapGroupMembersWorkCode = new HashMap<>();
Map<String,String> mapGroupMembersLastName = new HashMap<>();
List<String> serialids=Util.splitString2List(kqGroupComInfo.getSerialids(groupId),",");
if(!serialids.contains("-1"))serialids.add("-1");
for(String serialid : serialids){
if(serialid.equals("-1")){
String restLabel = SystemEnv.getHtmlLabelName(26593, user.getLanguage()).trim();
mapSerial.put(restLabel,serialid);
}else{
mapSerial.put(Util.formatMultiLang(kqShiftManagementComInfo.getSerial(serialid),""+user.getLanguage()),serialid);
}
}
Map<String,Object> params = new HashMap<>();
params.put("groupId",groupId);
params.put("isNoAccount","1");
List<String> kqGroupMembers = kqGroupBiz.getGroupMembers(params);
KqMembersValidateBiz kqMembersValidateBiz = new KqMembersValidateBiz();
Map<String, List<String>> validateResult = new KqMembersValidateBiz(params, user).getKqMembersValidateList();
List<String> excludeidList = new ArrayList<>();
KqShiftscheduleOperateLog bean = null;
boolean needChange = false;
ResourceComInfo rci = new ResourceComInfo();
if(!Util.null2String(kqGroupComInfo.getExcludecount(groupId)).equals("1")) {
String excludeid = Util.null2String(kqGroupComInfo.getExcludeid(groupId));
if (excludeid.length() > 0) {
excludeidList = Util.splitString2List(excludeid,",");
}
}
for(String resourceid : kqGroupMembers){
// 排除无需考勤人员
if(excludeidList != null && excludeidList.contains(resourceid)) {
continue;
}
String workCode = Util.formatMultiLang(Util.null2String(resourceComInfo.getWorkcode(resourceid)),""+user.getLanguage());
String lastName = Util.formatMultiLang(Util.null2String(resourceComInfo.getLastname(resourceid)),""+user.getLanguage());
if(workCode.length()>0){
mapGroupMembersWorkCode.put(workCode,resourceid);
}else if(lastName.length()>0){
mapGroupMembersLastName.put(lastName,resourceid);
}
}
sql = " select id, resourceid, kqdate, serialid from kq_shiftschedule where groupid=? and (isdelete is null or isdelete <> '1') ";
rs.executeQuery(sql,groupId);
while(rs.next()){
mapShiftSchedule.put(rs.getString("kqdate")+"|"+rs.getString("resourceid"),Util.null2String(rs.getString("id"))+"#"+Util.null2String(rs.getString("serialid")));
}
String ssyfDate = "";
List<String> lsGroupMembers = new ArrayList<>();
Map<String,Object> mapShiftScheduleOri = new HashMap<>();
Set<String> unSavePersonAll = new HashSet<>();
int firstRow = 6;
int firstCol = 3;
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(Util.getIntValue(filename));
//Workbook workbook = WorkbookFactory.create(manager.getInputStream());
Workbook workbook = new XSSFWorkbook(manager.getInputStream());
for (int idx = 0; idx < workbook.getNumberOfSheets(); idx++) {
Sheet sheet = workbook.getSheetAt(idx);
if(sheet.getSheetName().indexOf("constraintDataSheet")>-1)continue;
Row row = null;
Cell cell = null;
row = sheet.getRow(firstRow);
lsColumn = new ArrayList();
for (int cellIndex = firstCol; cellIndex < row.getLastCellNum(); cellIndex++) {
cell = row.getCell((short) cellIndex);
lsColumn.add(Util.null2String(getCellValue(cell)).trim());
}
firstRow++;
for (int i = firstRow; firstRow<=sheet.getLastRowNum() && i <= sheet.getLastRowNum(); i++) {
row = sheet.getRow(i);
if (row == null) {
continue;
}
String workCode = Util.null2String(row.getCell(1));//编号
String lastName = Util.null2String(row.getCell(2));//姓名
if(workCode.length()==0 && lastName.length()==0){
continue;
}
String resourceId = Util.null2String(mapGroupMembersWorkCode.get(workCode));//人员id
if(resourceId.length()==0){
resourceId = Util.null2String(mapGroupMembersLastName.get(lastName));//人员id
}
if(resourceId.length()==0)continue;
if(!managerRoleUserIdList.isEmpty()) {
if(!managerRoleUserIdList.contains(resourceId)) continue;
}
lsGroupMembers.add(resourceId);
for (int cellIndex = firstCol; cellIndex < row.getLastCellNum(); cellIndex++) {
cell = row.getCell((short) cellIndex);
if (cell == null) continue;
String serialId = "";
String serialName = Util.null2String(getCellValue(cell)).trim();
if(serialName.length()==0)continue;
String kqdate = Util.null2String(lsColumn.get(cellIndex-firstCol));
kqdate = kqdate.trim().replace(String.valueOf((char)10), "#");
kqdate = kqdate.split("#")[0];
if(!SaveShiftScheduleCmd.isDate(kqdate)) {
continue;
}
//if(weaver.common.DateUtil.timeInterval(kqdate,today)>0)continue;//今天之前的无需处理
serialId = Util.null2String(mapSerial.get(serialName));
if(serialId.length()==0)continue;
String shiftScheduleValue = Util.null2String(mapShiftSchedule.get(kqdate+"|"+resourceId));
String id = "";
String oldSerialid = "";
if(!"".equals(shiftScheduleValue)) {
id = shiftScheduleValue.split("#")[0];
oldSerialid = shiftScheduleValue.split("#")[1];
}
// 如果超过了有效期,就不存储数据
List<String> validateList = validateResult.get(resourceId);
boolean isInRange = kqMembersValidateBiz.isInRange(kqdate, validateList);
if(!isInRange && oldSerialid.length() > 0) {
validateParams = new ArrayList<>();
validateParams.add(resourceId);
validateParams.add(kqdate);
delValidateParams.add(validateParams);
lsFormatParams.add(validateParams);
bean = new KqShiftscheduleOperateLog(2,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceId),
kqdate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(oldSerialid)+"(id:"+oldSerialid+")"), id, "",user.getLanguage());
addLog(bean);
}
if(id.length()>0 && !oldSerialid.equals(serialId) && oldSerialid.length() > 0){
needChange = true;
param = new ArrayList<Object>();
param.add(serialId);
param.add(id);
param.add(resourceId);
paramUpdate.add(param);
bean = new KqShiftscheduleOperateLog(1, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceId),
kqdate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(serialId) + "(id:" + serialId + ")"),user.getLanguage());
addLog(bean);
ssyfDate = kqdate;
mapShiftScheduleOri.put(kqdate+"|"+resourceId,serialId);
}else{
if(!oldSerialid.equals(serialId)) {
needChange = true;
param = new ArrayList<Object>();
param.add(kqdate);
param.add(serialId);
param.add(resourceId);
param.add(groupId);
paramInsert.add(param);
bean = new KqShiftscheduleOperateLog(0, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceId),
kqdate, "", id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage());
addLog(bean);
ssyfDate = kqdate;
mapShiftScheduleOri.put(kqdate+"|"+resourceId,serialId);
}
}
if(needChange) {
formatParams = new ArrayList<>();
formatParams.add(resourceId);
formatParams.add(kqdate);
lsFormatParams.add(formatParams);
checkSerialParams = new ArrayList<>();
checkSerialParams.add(resourceId);
checkSerialParams.add(kqdate);
checkSerialParams.add(serialId);
lscheckSerialParams.add(checkSerialParams);
}
}
}
BaseBean bb = new BaseBean();
String fromDate = TimeUtil.getMonthBeginDay(ssyfDate);
String toDate = TimeUtil.getMonthEndDay(ssyfDate);
List<String> lsDateNew = new ArrayList<>();
Calendar calNew = weaver.common.DateUtil.getCalendar();
boolean isEndNew = false;
for(String date=fromDate; !isEndNew;) {
if(date.equals(toDate)) isEndNew = true;
lsDateNew.add(date);
calNew.setTime(weaver.common.DateUtil.parseToDate(date));
date = weaver.common.DateUtil.getDate(calNew.getTime(), 1);
}
Map<String,Object> mapShiftScheduleAll = new HashMap<>();
Set<String> unSavePerson = new HashSet<>();
//上四休二校验,生成预排班数据结构
for(String resourceid:lsGroupMembers){
Map<String,Object> 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<lsDateNew.size();i++) {
String date = lsDateNew.get(i);
String bcidNew = Util.null2String(mapShiftScheduleOri.get(date+"|"+resourceid));
if(StringUtils.isNotBlank(bcidNew)){
//本次排班预生成班次id
mapShiftScheduleAll.put(date+"|"+resourceid,bcidNew);
}else{
//本次排班未预生成id检查历史生成的班次id若历史也没有生效班次且当天不是节假日则不让保存
String bcidOld = Util.null2String(mapShiftScheduleChild.get(date+"|"+resourceid));
if(StringUtils.isNotBlank(bcidOld)){
mapShiftScheduleAll.put(date+"|"+resourceid,bcidOld);
}else{
int changeType = getChangeType(groupId, date);
if(changeType != 1){
//该人员不让保存
unSavePerson.add(resourceid);
}
}
}
}
}
bb.writeLog("unSavePerson"+ JSONObject.toJSONString(unSavePerson));
bb.writeLog("mapShiftScheduleAll"+JSONObject.toJSONString(mapShiftScheduleAll));
// 校验是否满足上四休二规则从当月第一个连续两天的休息班作为锚点判断此休息班前后排班是否满足固定4天工作+2天休息的模式
// 如果当月存在法定节假日则默认跳过后继续排班。例如:周三为节假日,且当周一为第一天工作日,那么当周的排班结果为:周一~周二:
// 2天工作日、周三跳过、周四~周五2天工作日、周六周日2天休息班
for(String resourceid:lsGroupMembers){
bb.writeLog("resourceid"+resourceid);
//遍历这个人员这个月的预生成排班
for(int i=0;i<lsDateNew.size();i++) {
String date = lsDateNew.get(i);
String bcid = Util.null2String(mapShiftScheduleAll.get(date+"|"+resourceid));
bb.writeLog("date"+date+"bcid"+bcid);
if(StringUtils.isNotBlank(bcid)){
//班次是否是休息班,是的话往后判断是否是两个连续休息班
boolean checkXxb = checkXxr(bcid);
if(checkXxb){
//是休息班,往后找
bb.writeLog("是休息班,往后找");
boolean findNextXxb = true;
Integer day = 1;
while (findNextXxb){
calNew.setTime(weaver.common.DateUtil.parseToDate(date));
String dateNext = weaver.common.DateUtil.getDate(calNew.getTime(), day);
day++;
String bcidNext = Util.null2String(mapShiftScheduleAll.get(dateNext+"|"+resourceid));
bb.writeLog("dateNext"+dateNext+"day"+day+"bcidNext"+bcidNext);
if(StringUtils.isNotBlank(bcidNext)){
//找到了第一个有班次的
bb.writeLog("找到了第一个有班次的");
findNextXxb = false;
boolean checkXxbNext = checkXxr(bcidNext);
if(checkXxbNext){
//再往后找一个班次,该班次需要为工作日
//是休息班,往后找
bb.writeLog("也是休息班,再往后找");
boolean findNextXxb1 = true;
Integer day1 = 1;
while (findNextXxb1){
calNew.setTime(weaver.common.DateUtil.parseToDate(dateNext));
String dateNext1 = weaver.common.DateUtil.getDate(calNew.getTime(), day1);
day1++;
String bcidNext1 = Util.null2String(mapShiftScheduleAll.get(dateNext1+"|"+resourceid));
bb.writeLog("bcidNext1"+bcidNext1+"dateNext1"+dateNext1+"day1"+day1);
if(StringUtils.isNotBlank(bcidNext1)){
//不往后找了
boolean checkXxbNext1 = checkXxr(bcidNext1);
findNextXxb1 = false;
bb.writeLog("checkXxbNext1"+checkXxbNext1);
if(checkXxbNext1){
//存在三个连续的休息班,不符合上四休二
bb.writeLog("存在三个连续的休息班,不符合上四休二");
unSavePerson.add(resourceid);
}else{
i++;
}
}else{
i++;
}
//到最后一天也没找到,暂不处理
if(weaver.common.DateUtil.timeInterval(toDate,dateNext1)>=0){
findNextXxb1 = false;
}
}
//将date作为一个锚点往前找并判断是否满足上四休二
boolean findBefore = true;
Integer dayB = -1;
//工作班数量
Integer gzbnum = 0;
//判断前面是否还有休息班标识
Integer xxbNo = 0;
while (findBefore){
calNew.setTime(weaver.common.DateUtil.parseToDate(date));
String dateBefore = weaver.common.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(weaver.common.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(weaver.common.DateUtil.timeInterval(toDate,dateNext)>=0){
findNextXxb = false;
}
}
}
}
}
}
bb.writeLog("unSavePerson"+JSONObject.toJSONString(unSavePerson));
unSavePersonAll.addAll(unSavePerson);
sql = " update kq_shiftschedule set serialid=?, isDelete=0 where id = ? ";
for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) {
List<Object> update_params = paramUpdate.get(i);
String serialid = Util.null2String(update_params.get(0));
String id = Util.null2String(update_params.get(1));
String resourceid = Util.null2String(update_params.get(2));
if(unSavePerson.contains(resourceid)){
//该人员不符合规则,不生效
}else{
rs.executeUpdate(sql, serialid,id);
}
}
sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)";
for (int i = 0; paramInsert != null && i < paramInsert.size(); i++) {
List<Object> insert_params = paramInsert.get(i);
String kqdate = Util.null2String(insert_params.get(0));
String serialid = Util.null2String(insert_params.get(1));
String resourceid = Util.null2String(insert_params.get(2));
String groupid = Util.null2String(insert_params.get(3));
if(unSavePerson.contains(resourceid)){
//该人员不符合规则,不生效
}else{
rs.executeUpdate(sql, kqdate,serialid,resourceid,groupid);
}
}
}
// 删除一些有效期之后的排班
sql = " update kq_shiftschedule set isdelete =1 where resourceid = ? and kqdate = ? and groupid = "+groupId;
for (List<Object> delete_params : delValidateParams) {
String resourceid = Util.null2String(delete_params.get(0));
String kqdate = Util.null2String(delete_params.get(1));
if(unSavePersonAll.contains(resourceid)){
//该人员不符合规则,不生效
}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 groupid != "+groupId;
for (int i = 0; lsFormatParams != null && i < lsFormatParams.size(); i++) {
List<Object> delete_params = lsFormatParams.get(i);
String resourceid = Util.null2String(delete_params.get(0));
String kqdate = Util.null2String(delete_params.get(1));
if(unSavePersonAll.contains(resourceid)){
//该人员不符合规则,不生效
}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 != ? ";
for (int i = 0; lscheckSerialParams != null && i < lscheckSerialParams.size(); i++) {
List<Object> check_params = lscheckSerialParams.get(i);
String resourceid = Util.null2String(check_params.get(0));
String kqdate = Util.null2String(check_params.get(1));
String serialid = Util.null2String(check_params.get(2));
if(unSavePersonAll.contains(resourceid)){
//该人员不符合规则,不生效
}else{
rs.executeUpdate(sql, resourceid,kqdate,serialid);
}
}
sql = "insert into kq_shiftscheduleoperate_log(operatetype,operator,kqgroupname,changeduser,changedshiftdate,changedshiftname,kqshiftid) values(?,?,?,?,?,?,?)";
bRs.executeBatchSqlNew(sql, operateLogParams);
new KQShiftScheduleComInfo().removeCache();
//刷新报表数据
// sql = " insert into kq_format_pool (resourceid, kqdate) values (?,?)";
// bRs.executeBatchSql(sql, lsFormatParams);
new KQFormatBiz().format(lsFormatParams,16);
KQGroupComInfo kQGroupComInfo = new KQGroupComInfo();
String auto_checkout = kQGroupComInfo.getAuto_checkout(groupId);
String auto_checkin = kQGroupComInfo.getAuto_checkin(groupId);
if("1".equalsIgnoreCase(auto_checkin) || "1".equalsIgnoreCase(auto_checkout)){
//如果开启了自动打卡,保存考勤组成员之后需要格式化下缓存
KQAutoCardTask kqAutoCardTask = new KQAutoCardTask();
kqAutoCardTask.initAutoCardTask(groupId);
}
if(unSavePersonAll.size()>0){
List<String> personNameList = new ArrayList<>();
for(String personid:unSavePersonAll){
personNameList.add(resourceComInfo.getLastname(personid));
}
retmap.put("status", "-1");
retmap.put("message", "【"+StringUtils.join(personNameList,",")+"】上述员工当前月份排班不符合做四休二规则或存在班次为空的日期");
return retmap;
}
retmap.put("status", "1");
} catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage()));
writeLog(e);
}
return retmap;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public List<BizLogContext> getLogContexts() {
return logger.getBizLogContexts();
}
/**
* /**
* excel
*
* @param cell
* @return
*/
public String getCellValue(Cell cell) {
String cellValue = "";
if (cell == null)
return "";
switch (cell.getCellType()) {
case BOOLEAN: // 得到Boolean对象的方法
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {// 先看是否是日期格式
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
cellValue = String.valueOf(sft.format(cell.getDateCellValue())); // 读取日期格式
} else {
cellValue = String.valueOf(new Double(cell.getNumericCellValue())); // 读取数字
if (cellValue.endsWith(".0"))
cellValue = cellValue.substring(0, cellValue.indexOf("."));
}
break;
case FORMULA: // 读取公式
cellValue = cell.getCellFormula();
break;
case STRING: // 读取String
cellValue = cell.getStringCellValue();
break;
}
return cellValue;
}
private void addLog(KqShiftscheduleOperateLog bean) {
operateLogParam = new ArrayList<>();
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 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 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;
}
}

@ -0,0 +1,475 @@
package com.engine.kq.cmd.shiftschedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.bean.KqShiftscheduleOperateLog;
import com.engine.kq.biz.*;
import weaver.common.DateUtil;
import weaver.conn.BatchRecordSet;
import weaver.conn.DBUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.util.*;
public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand<Map<String, Object>> {
private SimpleBizLogger logger;
// 添加日志功能
private List<List<Object>> operateLogParams = new ArrayList<>();
// 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id
private List<Object> operateLogParam = null;
public SaveBatchShiftScheduleCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
this.logger = new SimpleBizLogger();
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
BatchRecordSet bRs = new BatchRecordSet();
String today = DateUtil.getCurrentDate();
String sql = "";
try{
//必要的权限判断
if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return retmap;
}
ResourceComInfo resourceComInfo = new ResourceComInfo();
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
KQGroupBiz kqGroupBiz = new KQGroupBiz();
String data = Util.null2String(params.get("data"));
JSONObject jsonObj = JSON.parseObject(data);
String groupId = Util.null2String(jsonObj.get("groupId"));//考勤组id
String shiftScheduleType = Util.null2String(jsonObj.get("shiftScheduleType"));//排班类型
String shiftScheduleDate = Util.null2String(jsonObj.get("shiftScheduleDate"));//排班日期
String shiftScheduleBeginDate = Util.null2String(jsonObj.get("shiftScheduleBeginDate"));//排班开始日期
String shiftScheduleEndDate = Util.null2String(jsonObj.get("shiftScheduleEndDate"));//排班结束日期
String shiftScheduleMemberType = Util.null2String(jsonObj.get("shiftScheduleMemberType"));//排班人员类型
String shiftScheduleMember = Util.null2String(jsonObj.get("shiftScheduleMember"));//排班人员
String holidayType = Util.null2String(jsonObj.get("holidayType"));//遇双休日
String meetHolidays = Util.null2String(jsonObj.get("meetHolidays"));//遇节假日
String meetRestDays = Util.null2String(jsonObj.get("meetRestDays"));//遇调配休息日
String serialId = Util.null2String(jsonObj.get("serialId"));//班次
String shiftcycleId = Util.null2String(jsonObj.get("shiftcycleId"));//排班周期Id
// 某个管理员所拥有的维护人员的权限
List<String> managerRoleUserIdList = new KqShiftScheduleRoleBiz().getUfKqShiftScheduleRoleValue(""+user.getUID(), groupId);
KqMembersValidateBiz kqMembersValidateBiz = new KqMembersValidateBiz();
Map<String, Object> paramsValidate = new HashMap<>();
paramsValidate.put("groupId",groupId);
paramsValidate.put("isNoAccount","1");
if("2".equals(shiftScheduleMemberType)) { // 按人员排班
paramsValidate.put("resourceId",shiftScheduleMember);
}
Map<String, List<String>> validateResult = new KqMembersValidateBiz(paramsValidate, user).getKqMembersValidateList();
List<List<Object>> paramInsert = new ArrayList<List<Object>>();
List<List<Object>> paramUpdate = new ArrayList<List<Object>>();
List<Object> params = null;
String delIds = "";
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = new ArrayList<>();
List<List<Object>> lsDeleteParams = new ArrayList<>();
List<Object> deleteParams = null;
List<List<Object>> lscheckSerialParams = new ArrayList<>();
List<Object> checkSerialParams = new ArrayList<>();
List<List<Object>> lsDeleteCancelParams = new ArrayList<>();
List<Object> deleteCancelParams = null;
List<String> lsGroupMembers = null;
if(shiftScheduleMemberType.equals("1")){//所有考勤组成员
lsGroupMembers = kqGroupBiz.getGroupMembers(groupId);
}else{//考勤组成员
lsGroupMembers = Util.splitString2List(shiftScheduleMember,",");
}
List<String> excludeidList = new ArrayList<>();
if(!Util.null2String(kqGroupComInfo.getExcludecount(groupId)).equals("1")) {
String excludeid = Util.null2String(kqGroupComInfo.getExcludeid(groupId));
if (excludeid.length() > 0) {
excludeidList = Util.splitString2List(excludeid,",");
}
}
Map<String,Object> mapShiftSchedule = new HashMap<>();
sql = " select id, resourceid, kqdate, serialid from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? ";
//有客户提下面的sql有性能问题在表数据较多并且该表数据改动较为频率不适合建索引所以对mapShiftSchedule先缓存的数据范围过滤下没必要全表缓存
if("1".equals(shiftScheduleType)){//按天排班
sql += " and kqdate='"+shiftScheduleDate+"' ";
}else if("2".equals(shiftScheduleType)){
sql += " and kqdate>='"+shiftScheduleBeginDate+"' and kqdate<='"+shiftScheduleEndDate+"' ";
}
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")));
}
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<String> 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);
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<Object>();
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<Object>();
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);
}
}
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);
checkSerialParams = new ArrayList<>();
checkSerialParams.add(resourceid);
checkSerialParams.add(shiftScheduleDate);
checkSerialParams.add(serialId);
lscheckSerialParams.add(checkSerialParams);
}
}
}
}else if(shiftScheduleType.equals("2")){//按周期排班
List<String> lsDate = new ArrayList<>();
Calendar cal = DateUtil.getCalendar();
writeLog("shiftScheduleBeginDate==" + shiftScheduleBeginDate + "shiftScheduleEndDate==" + shiftScheduleEndDate);
if (DateUtil.timeInterval(shiftScheduleEndDate, shiftScheduleBeginDate) > 0)
{
retmap.put("status", "-1");
retmap.put("message", ""+ SystemEnv.getHtmlLabelName(10005344,weaver.general.ThreadVarLanguage.getLang())+"");
return retmap;
}
int shiftcycleday = 0;
String[] shiftcycleserialids = null;
sql = "select shiftcycleday,shiftcycleserialids from kq_group_shiftcycle where id = ? order by id asc ";
rs.executeQuery(sql,shiftcycleId);
if(rs.next()){
shiftcycleday = rs.getInt("shiftcycleday");
shiftcycleserialids = Util.splitString(Util.null2String(rs.getString("shiftcycleserialids")), ",");
}
boolean isEnd = false;
for(String date=shiftScheduleBeginDate; !isEnd;) {
if(date.equals(shiftScheduleEndDate)) isEnd = true;
lsDate.add(date);
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
for(String resourceid:lsGroupMembers){
// 排除无需考勤人员
if(excludeidList != null && excludeidList.contains(resourceid)) {
continue;
}
if(!managerRoleUserIdList.isEmpty()) {
if(!managerRoleUserIdList.contains(resourceid)) {
continue;
}
}
boolean needShiftSchedule = false;
int dayCount = 0;
for(int i=0;i<lsDate.size();i++) {
needChange = false;
id= "";
oldSerialid = "";
//if(weaver.common.DateUtil.timeInterval(date,today)>0)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];
}
// 如果超过了有效期,就不存储数据
List<String> 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);
}
continue;
}
needShiftSchedule = true;
int changeType= KQHolidaySetBiz.getChangeType(groupId, date);
if (changeType != 1 && changeType != 3 && !holidayType.equals("1")) {//遇双休日继续排班
int weekDay = DateUtil.getWeek(date);
if(weekDay>5){
needShiftSchedule = false;
}
}
if(!meetHolidays.equals("1")){//遇节假日继续排班
if(changeType==1){
needShiftSchedule = false;
}
}
if(!meetRestDays.equals("1")){//遇调配休息日继续排班
if(changeType==3){
needShiftSchedule = false;
}
}
if(needShiftSchedule){
dayCount++;
int idx = dayCount % shiftcycleday;
if (idx == 0) {//周期最后一天
serialId = Util.null2String(shiftcycleserialids[shiftcycleserialids.length - 1]);
} else {
serialId = Util.null2String(shiftcycleserialids[idx-1]);
}
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),
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<Object>();
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);
}
}
}else{
if(serialId.length()>0){
if(!oldSerialid.equals(serialId)) {
needChange = true;
params = new ArrayList<Object>();
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);
}
}
}
}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);
}
}
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);
checkSerialParams = new ArrayList<>();
checkSerialParams.add(resourceid);
checkSerialParams.add(shiftScheduleDate);
checkSerialParams.add(serialId);
lscheckSerialParams.add(checkSerialParams);
}
}
}
}
sql = " update kq_shiftschedule set serialid=?,isDelete=0 where id = ? ";
for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) {
List<Object> 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);
}
sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)";
for (int i = 0; paramInsert != null && i < paramInsert.size(); i++) {
List<Object> insert_params = paramInsert.get(i);
String kqdate = Util.null2String(insert_params.get(0));
String serialid = Util.null2String(insert_params.get(1));
String resourceid = Util.null2String(insert_params.get(2));
String groupid = Util.null2String(insert_params.get(3));
rs.executeUpdate(sql, kqdate,serialid,resourceid,groupid);
}
if(delIds.length()>0){
List sqlParams = new ArrayList();
Object[] objects= DBUtil.transListIn(delIds,sqlParams);
sql = "update kq_shiftschedule set isdelete =1 where id in("+objects[0]+") ";
rs.executeUpdate(sql, sqlParams);
}
//删除批量排班,遇双休日、节假日、调配工作日的取消排班
sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? ";
for (int i = 0; lsDeleteCancelParams != null && i < lsDeleteCancelParams.size(); i++) {
List<Object> 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);
}
//删除之前的排的班次,一天只能有一个班次
sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and groupid != "+groupId;
for (int i = 0; lsDeleteParams != null && i < lsDeleteParams.size(); i++) {
List<Object> 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);
}
sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and serialid != ? ";
for (int i = 0; lscheckSerialParams != null && i < lscheckSerialParams.size(); i++) {
List<Object> check_params = lscheckSerialParams.get(i);
String resourceid = Util.null2String(check_params.get(0));
String kqdate = Util.null2String(check_params.get(1));
String serialid = Util.null2String(check_params.get(2));
rs.executeUpdate(sql, resourceid,kqdate,serialid);
}
sql = "insert into kq_shiftscheduleoperate_log(operatetype,operator,kqgroupname,changeduser,changedshiftdate,changedshiftname,kqshiftid) values(?,?,?,?,?,?,?)";
bRs.executeBatchSqlNew(sql, operateLogParams);
new KQShiftScheduleComInfo().removeCache();
//刷新报表数据
new KQFormatBiz().format(lsFormatParams,16);
retmap.put("status", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage()));
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
return retmap;
}
private void addLog(KqShiftscheduleOperateLog bean) {
operateLogParam = new ArrayList<>();
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);
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public List<BizLogContext> getLogContexts() {
return logger.getBizLogContexts();
}
}

@ -0,0 +1,510 @@
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.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.bean.KqShiftscheduleOperateLog;
import com.engine.kq.biz.*;
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.Reminder.KQAutoCardTask;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class SaveShiftScheduleCmd extends AbstractCommonCommand<Map<String, Object>> {
private SimpleBizLogger logger;
// 添加日志功能
private List<List<Object>> operateLogParams = new ArrayList<>();
// 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id
private List<Object> operateLogParam = null;
public SaveShiftScheduleCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
this.logger = new SimpleBizLogger();
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
BatchRecordSet bRs = new BatchRecordSet();
String today = DateUtil.getCurrentDate();
String sql = "";
try{
//必要的权限判断
if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
return retmap;
}
String data = Util.null2String(params.get("data"));
JSONObject jsonObj = JSON.parseObject(data);
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
KQShiftManagementComInfo kqShiftScheduleComInfo = new KQShiftManagementComInfo();
ResourceComInfo rci = new ResourceComInfo();
String groupId = Util.null2String(jsonObj.get("groupId"));
JSONArray datas = jsonObj.getJSONArray("datas");
List<List<Object>> paramInsert = new ArrayList<List<Object>>();
List<List<Object>> paramUpdate = new ArrayList<List<Object>>();
List<Object> params = null;
String delIds = "";
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
List<List<Object>> lsDeleteParams = new ArrayList<>();
List<Object> deleteParams = null;
List<List<Object>> lscheckSerialParams = new ArrayList<>();
List<Object> checkSerialParams = null;
JSONObject resourceDataObj = null;
JSONArray arrKqDataObj = null;
JSONObject kqDataObj = null;
KqShiftscheduleOperateLog bean = null;
//获取所属月份用日期
String ssyfDate = "";
List<String> lsGroupMembers = new ArrayList<>();
Map<String,Object> mapShiftScheduleOri = new HashMap<>();
for(int i=0;datas!=null&&i<datas.size();i++){
resourceDataObj = (JSONObject)datas.get(i);
String resourceid = Util.null2String(resourceDataObj.get("resourceid"));
lsGroupMembers.add(resourceid);
arrKqDataObj = resourceDataObj.getJSONArray("kqdata");
for(int j=0;arrKqDataObj!=null&&j<arrKqDataObj.size();j++) {
kqDataObj = (JSONObject) arrKqDataObj.get(j);
// 如果id为空则代表原先是空白单元格
String id = Util.null2String(kqDataObj.get("id"));
String date = Util.null2String(kqDataObj.get("date"));
if(!SaveShiftScheduleCmd.isDate(date)) {
continue;
}
// 原先排班的班次id
String oldSerialid = Util.null2String(kqDataObj.get("oldValue"));
// 新班次id 如果 serialid是-999 oldValue是班次id那么就是原先是有班次的后面把班次删除了
String serialid = Util.null2String(kqDataObj.get("serialid"));
if(serialid.equals("-999"))serialid="";
boolean needChange = false;
//if(weaver.common.DateUtil.timeInterval(date,today)>0)continue;//今天之前的无需处理
if(id.length()>0){ // 更新
ssyfDate = date;
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),
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<Object>();
params.add(serialid);
params.add(id);
params.add(resourceid);
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);
}
}
mapShiftScheduleOri.put(date+"|"+resourceid,serialid);
}else{ //新建
if(serialid.length()==0)continue;
if(!oldSerialid.equals(serialid)) {
ssyfDate = date;
needChange = true;
params = new ArrayList<Object>();
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);
mapShiftScheduleOri.put(date+"|"+resourceid,serialid);
}
}
if(needChange) {
deleteParams = new ArrayList<>();
deleteParams.add(resourceid);
deleteParams.add(date);
lsDeleteParams.add(deleteParams);
checkSerialParams = new ArrayList<>();
checkSerialParams.add(resourceid);
checkSerialParams.add(date);
checkSerialParams.add(serialid);
lscheckSerialParams.add(checkSerialParams);
if(DateUtil.timeInterval(date,today)>=0) {
formatParams = new ArrayList<>();
formatParams.add(resourceid);
formatParams.add(date);
lsFormatParams.add(formatParams);
}
}
}
}
BaseBean bb = new BaseBean();
String fromDate = TimeUtil.getMonthBeginDay(ssyfDate);
String toDate = TimeUtil.getMonthEndDay(ssyfDate);
List<String> 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<String,Object> mapShiftScheduleAll = new HashMap<>();
Set<String> unSavePerson = new HashSet<>();
//上四休二校验,生成预排班数据结构
for(String resourceid:lsGroupMembers){
Map<String,Object> 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<lsDateNew.size();i++) {
String date = lsDateNew.get(i);
String bcidNew = Util.null2String(mapShiftScheduleOri.get(date+"|"+resourceid));
if(StringUtils.isNotBlank(bcidNew)){
//本次排班预生成班次id
mapShiftScheduleAll.put(date+"|"+resourceid,bcidNew);
}else{
//本次排班未预生成id检查历史生成的班次id若历史也没有生效班次且当天不是节假日则不让保存
String bcidOld = Util.null2String(mapShiftScheduleChild.get(date+"|"+resourceid));
if(StringUtils.isNotBlank(bcidOld)){
mapShiftScheduleAll.put(date+"|"+resourceid,bcidOld);
}else{
int changeType = getChangeType(groupId, date);
if(changeType != 1){
//该人员不让保存
unSavePerson.add(resourceid);
}
}
}
}
}
bb.writeLog("unSavePerson"+JSONObject.toJSONString(unSavePerson));
bb.writeLog("mapShiftScheduleAll"+JSONObject.toJSONString(mapShiftScheduleAll));
// 校验是否满足上四休二规则从当月第一个连续两天的休息班作为锚点判断此休息班前后排班是否满足固定4天工作+2天休息的模式
// 如果当月存在法定节假日则默认跳过后继续排班。例如:周三为节假日,且当周一为第一天工作日,那么当周的排班结果为:周一~周二:
// 2天工作日、周三跳过、周四~周五2天工作日、周六周日2天休息班
for(String resourceid:lsGroupMembers){
bb.writeLog("resourceid"+resourceid);
//遍历这个人员这个月的预生成排班
for(int i=0;i<lsDateNew.size();i++) {
String date = lsDateNew.get(i);
String bcid = Util.null2String(mapShiftScheduleAll.get(date+"|"+resourceid));
bb.writeLog("date"+date+"bcid"+bcid);
if(StringUtils.isNotBlank(bcid)){
//班次是否是休息班,是的话往后判断是否是两个连续休息班
boolean checkXxb = checkXxr(bcid);
if(checkXxb){
//是休息班,往后找
bb.writeLog("是休息班,往后找");
boolean findNextXxb = true;
Integer day = 1;
while (findNextXxb){
calNew.setTime(DateUtil.parseToDate(date));
String dateNext = DateUtil.getDate(calNew.getTime(), day);
day++;
String bcidNext = Util.null2String(mapShiftScheduleAll.get(dateNext+"|"+resourceid));
bb.writeLog("dateNext"+dateNext+"day"+day+"bcidNext"+bcidNext);
if(StringUtils.isNotBlank(bcidNext)){
//找到了第一个有班次的
bb.writeLog("找到了第一个有班次的");
findNextXxb = false;
boolean checkXxbNext = checkXxr(bcidNext);
if(checkXxbNext){
//再往后找一个班次,该班次需要为工作日
//是休息班,往后找
bb.writeLog("也是休息班,再往后找");
boolean findNextXxb1 = true;
Integer day1 = 1;
while (findNextXxb1){
calNew.setTime(DateUtil.parseToDate(dateNext));
String dateNext1 = DateUtil.getDate(calNew.getTime(), day1);
day1++;
String bcidNext1 = Util.null2String(mapShiftScheduleAll.get(dateNext1+"|"+resourceid));
bb.writeLog("bcidNext1"+bcidNext1+"dateNext1"+dateNext1+"day1"+day1);
if(StringUtils.isNotBlank(bcidNext1)){
//不往后找了
boolean checkXxbNext1 = checkXxr(bcidNext1);
findNextXxb1 = false;
bb.writeLog("checkXxbNext1"+checkXxbNext1);
if(checkXxbNext1){
//存在三个连续的休息班,不符合上四休二
bb.writeLog("存在三个连续的休息班,不符合上四休二");
unSavePerson.add(resourceid);
}else{
i++;
}
}else{
i++;
}
//到最后一天也没找到,暂不处理
if(DateUtil.timeInterval(toDate,dateNext1)>=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));
sql = " update kq_shiftschedule set serialid=?,isDelete=0 where id = ? ";
for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) {
List<Object> update_params = paramUpdate.get(i);
String serialid = Util.null2String(update_params.get(0));
String id = Util.null2String(update_params.get(1));
String resourceid = Util.null2String(update_params.get(2));
if(unSavePerson.contains(resourceid)){
//该人员不符合规则,不生效
}else{
rs.executeUpdate(sql, serialid,id);
}
}
sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)";
for (int i = 0; paramInsert != null && i < paramInsert.size(); i++) {
List<Object> insert_params = paramInsert.get(i);
String kqdate = Util.null2String(insert_params.get(0));
String serialid = Util.null2String(insert_params.get(1));
String resourceid = Util.null2String(insert_params.get(2));
String groupid = Util.null2String(insert_params.get(3));
if(unSavePerson.contains(resourceid)){
//该人员不符合规则,不生效
}else{
rs.executeUpdate(sql, kqdate,serialid,resourceid,groupid);
}
}
if(delIds.length()>0){
List sqlParams = new ArrayList();
Object[] objects= DBUtil.transListIn(delIds,sqlParams);
sql = "update kq_shiftschedule set isdelete =1 where id in("+objects[0]+") ";
rs.executeUpdate(sql, sqlParams);
}
//删除之前的排的班次,一天只能有一个班次
sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and groupid != "+groupId;
for (int i = 0; lsDeleteParams != null && i < lsDeleteParams.size(); i++) {
List<Object> delete_params = lsDeleteParams.get(i);
String resourceid = Util.null2String(delete_params.get(0));
String kqdate = Util.null2String(delete_params.get(1));
if(unSavePerson.contains(resourceid)){
//该人员不符合规则,不生效
}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 != ? ";
for (int i = 0; lscheckSerialParams != null && i < lscheckSerialParams.size(); i++) {
List<Object> check_params = lscheckSerialParams.get(i);
String resourceid = Util.null2String(check_params.get(0));
String kqdate = Util.null2String(check_params.get(1));
String serialid = Util.null2String(check_params.get(2));
if(unSavePerson.contains(resourceid)){
//该人员不符合规则,不生效
}else{
rs.executeUpdate(sql, resourceid,kqdate,serialid);
}
}
sql = "insert into kq_shiftscheduleoperate_log(operatetype,operator,kqgroupname,changeduser,changedshiftdate,changedshiftname,kqshiftid) values(?,?,?,?,?,?,?)";
bRs.executeBatchSqlNew(sql, operateLogParams);
new KQShiftScheduleComInfo().removeCache();
//刷新报表数据
new KQFormatBiz().format(lsFormatParams,16);
KQGroupComInfo kQGroupComInfo = new KQGroupComInfo();
String auto_checkout = kQGroupComInfo.getAuto_checkout(groupId);
String auto_checkin = kQGroupComInfo.getAuto_checkin(groupId);
if("1".equalsIgnoreCase(auto_checkin) || "1".equalsIgnoreCase(auto_checkout)){
//如果开启了自动打卡,保存考勤组成员之后需要格式化下缓存
KQAutoCardTask kqAutoCardTask = new KQAutoCardTask();
kqAutoCardTask.initAutoCardTask(groupId);
}
if(unSavePerson.size()>0){
ResourceComInfo resourceComInfo = new ResourceComInfo();
List<String> personNameList = new ArrayList<>();
for(String personid:unSavePerson){
personNameList.add(resourceComInfo.getLastname(personid));
}
retmap.put("status", "-1");
retmap.put("message", "【"+StringUtils.join(personNameList,",")+"】上述员工当前月份排班不符合做四休二规则或存在班次为空的日期");
return retmap;
}
retmap.put("status", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage()));
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
return retmap;
}
private void addLog(KqShiftscheduleOperateLog bean) {
operateLogParam = new ArrayList<>();
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);
}
public static boolean isDate(String str) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setLenient(false); // 严格匹配
try {
sdf.parse(str);
return true;
} catch (ParseException e) {
return false;
}
}
/**
* ()
*
* @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 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;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public List<BizLogContext> getLogContexts() {
return logger.getBizLogContexts();
}
}

@ -0,0 +1,692 @@
package com.engine.kq.util;
import com.engine.kq.bean.KQRepeatBean;
import com.engine.kq.biz.KQLeaveRulesBiz;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import com.engine.kq.biz.KQRepeatLengthContext;
import com.engine.kq.biz.KQWorkTime;
import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean;
import com.engine.kq.biz.chain.duration.NonDayUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonHalfUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonHourUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonWholeUnitSplitChain;
import com.engine.kq.biz.chain.duration.NonWorkDurationChain;
import com.engine.kq.biz.chain.duration.WorkDayUnitSplitChain;
import com.engine.kq.biz.chain.duration.WorkDurationChain;
import com.engine.kq.biz.chain.duration.WorkHalfUnitSplitChain;
import com.engine.kq.biz.chain.duration.WorkHourUnitSplitChain;
import com.engine.kq.biz.chain.duration.WorkWholeUnitSplitChain;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.enums.DurationTypeEnum;
import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.bean.SplitBean;
import com.engine.kq.wfset.util.KQFlowUtil;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.report.schedulediff.HrmScheduleDiffUtil;
import weaver.hrm.resource.SptmForLeave;
public class KQDurationCalculatorUtil extends BaseBean {
private KQLog kqLog = new KQLog();
private final String resourceid;
private String fromDate;
private String toDate;
private String fromTime;
private String toTime;
private String newLeaveType;
/**
*
* 1-
* 2-
* 3-
* 4-
*/
private String durationrule;
/**
* 1-
* 2-
*/
private String computingMode;
/**
*
*/
private String overtime_type;
private DurationTypeEnum durationTypeEnum;
//外部类的构造函数
private KQDurationCalculatorUtil(DurationParamBuilder build){
this.resourceid = build.resourceid;
this.fromDate = build.fromDate;
this.toDate = build.toDate;
this.fromTime = build.fromTime;
this.toTime = build.toTime;
this.newLeaveType = build.newLeaveType;
this.durationrule = build.durationrule;
this.computingMode = build.computingMode;
this.durationTypeEnum = build.durationTypeEnum;
this.overtime_type = build.overtime_type;
}
/**
*
* @param resourceid
* @param date
* @param containYesterday
* @return
*/
public static ShiftInfoBean getWorkTime(String resourceid, String date,boolean containYesterday){
User user = User.getUser(Util.getIntValue(resourceid), 0);
if(user == null){
return null;
}
return getWorkTime(user, date,containYesterday);
}
/**
*
* @param resourceid
* @param date
* @param containYesterday
* @param isLog
* @return
*/
public static ShiftInfoBean getWorkTime(String resourceid, String date,boolean containYesterday,boolean isLog){
User user = User.getUser(Util.getIntValue(resourceid), 0);
if(user == null){
return null;
}
return getWorkTime(user, date,containYesterday,isLog);
}
public static ShiftInfoCominfoBean getShiftInfoCominfoBean(String resourceid, String date){
KQWorkTime kqWorkTime = new KQWorkTime();
Map<String, Object> kqWorkTimeMap = new HashMap<>();
ShiftInfoCominfoBean shiftInfoCominfoBean = kqWorkTime.getShiftInfoCominfoBean(resourceid, date);
return shiftInfoCominfoBean;
}
/**
* user
* @param user
* @param date
* @param containYesterday
* @param isLog
* @return
*/
public static ShiftInfoBean getWorkTime(User user, String date,boolean containYesterday,boolean isLog){
KQWorkTime kqWorkTime = new KQWorkTime();
Map<String, Object> kqWorkTimeMap = new HashMap<>();
kqWorkTimeMap = kqWorkTime.getWorkDuration(""+user.getUID(), date,containYesterday,isLog);
boolean isfree = "1".equalsIgnoreCase(Util.null2String(kqWorkTimeMap.get("isfree")));
if(isfree){
ShiftInfoBean shiftInfoBean = new ShiftInfoBean();
shiftInfoBean.setIsfree(true);
String signStart = Util.null2String(kqWorkTimeMap.get("signStart"));
String workMins = Util.null2String(kqWorkTimeMap.get("workMins"));
shiftInfoBean.setFreeSignStart(signStart);
shiftInfoBean.setFreeWorkMins(workMins);
shiftInfoBean.setSplitDate(date);
if(signStart.length() > 0 && workMins.length() > 0){
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime signLocalTime = LocalTime.parse(signStart, dateTimeFormatter);
shiftInfoBean.setFreeSignEnd(signLocalTime.plusMinutes(Util.getIntValue(workMins)).format(dateTimeFormatter));
shiftInfoBean.setFreeSignMiddle(signLocalTime.plusMinutes(Util.getIntValue(workMins)/2).format(dateTimeFormatter));
}
return shiftInfoBean;
}else{
if(kqWorkTimeMap.get("shiftInfoBean") != null){
ShiftInfoBean shiftInfoBean = (ShiftInfoBean)kqWorkTimeMap.get("shiftInfoBean");
return shiftInfoBean;
}else{
return null;
}
}
}
/**
* user
* @param user
* @param date
* @param containYesterday
* @return
*/
public static ShiftInfoBean getWorkTime(User user, String date,boolean containYesterday){
return getWorkTime(user, date, containYesterday, true);
}
public static Map<String, Object> getWorkButton(String resourceid, String date, boolean containYesterday){
User user = User.getUser(Util.getIntValue(resourceid), 0);
return getWorkButton(user,date,containYesterday);
}
public static Map<String, Object> getWorkButton(User user, String date, boolean containYesterday){
KQWorkTime kqWorkTime = new KQWorkTime();
Map<String, Object> kqWorkTimeMap = new HashMap<>();
kqWorkTimeMap = kqWorkTime.getWorkButton(""+user.getUID(), date,containYesterday);
return kqWorkTimeMap;
}
/**
*
* @return
*/
public Map<String,Object> getNonWorkDuration(){
Map<String,Object> durationMap = new HashMap<>();
try{
double D_Duration = 0.0;
double Min_Duration = 0.0;
//公众假日加班时长
double D_Pub_Duration = 0.0;
double D_Pub_Mins = 0.0;
//工作日加班时长
double D_Work_Duration = 0.0;
double D_Work_Mins = 0.0;
//休息日加班时长
double D_Rest_Duration = 0.0;
double D_Rest_Mins = 0.0;
SplitBean splitBean = new SplitBean();
splitBean.setFromDate(fromDate);
splitBean.setFromTime(fromTime);
splitBean.setToDate(toDate);
splitBean.setToTime(toTime);
splitBean.setResourceId(resourceid);
splitBean.setFromdatedb(fromDate);
splitBean.setTodatedb(toDate);
splitBean.setFromtimedb(fromTime);
splitBean.setTotimedb(toTime);
splitBean.setDurationrule(durationrule);
splitBean.setComputingMode(computingMode);
splitBean.setDurationTypeEnum(DurationTypeEnum.OVERTIME);
splitBean.setOvertime_type(overtime_type);
List<SplitBean> splitBeans = new ArrayList<>();
NonWorkDurationChain hourUnitSplitChain = new NonHourUnitSplitChain(splitBeans);
NonWorkDurationChain dayUnitSplitChain = new NonDayUnitSplitChain(splitBeans);
NonWorkDurationChain halfUnitSplitChain = new NonHalfUnitSplitChain(splitBeans);
NonWorkDurationChain wholeUnitSplitChain = new NonWholeUnitSplitChain(splitBeans);
//设置执行链
hourUnitSplitChain.setDurationChain(dayUnitSplitChain);
dayUnitSplitChain.setDurationChain(halfUnitSplitChain);
halfUnitSplitChain.setDurationChain(wholeUnitSplitChain);
//把初始数据设置进去
hourUnitSplitChain.handleDuration(splitBean);
//每一天的流程时长都在这里了,搞吧
for(SplitBean sb : splitBeans){
// * 1-公众假日、2-工作日、3-休息日
int changeType = sb.getChangeType();
double durations = Util.getDoubleValue(sb.getDuration(), 0.0);
double durationMins = sb.getD_Mins();
if(1 == changeType){
D_Pub_Duration += durations;
D_Pub_Mins += durationMins;
}
if(2 == changeType){
D_Work_Duration += durations;
D_Work_Mins += durationMins;
}
if(3 == changeType){
D_Rest_Duration += durations;
D_Rest_Mins += durationMins;
}
}
Min_Duration = D_Pub_Mins+D_Work_Mins+D_Rest_Mins;
if("3".equalsIgnoreCase(durationrule) || "5".equalsIgnoreCase(durationrule) || "6".equalsIgnoreCase(durationrule)){
double d_hour = Min_Duration/60.0;
durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound(""+d_hour));
}else {
double oneDayHour = KQFlowUtil.getOneDayHour(DurationTypeEnum.OVERTIME,"");
double d_day = Min_Duration/(oneDayHour * 60);
durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound(""+d_day));
}
durationMap.put("min_duration", KQDurationCalculatorUtil.getDurationRound(""+Min_Duration));
}catch (Exception e){
e.printStackTrace();
}
return durationMap;
}
/**
*
* @return
*/
public Map<String,Object> getWorkDuration(){
Map<String,Object> durationMap = new HashMap<>();
try{
if(!isValidate(fromDate,toDate,fromTime,toTime)){
durationMap.put("duration", "0.0");
return durationMap;
}
if(durationTypeEnum != DurationTypeEnum.COMMON_CAL){
kqLog.info("getWorkDuration:"+durationTypeEnum.getDurationType()+":fromDate:"+fromDate+":toDate:"+toDate+":fromTime:"+fromTime+":toTime:"+toTime+":durationrule:"+durationrule+":computingMode:"+computingMode);
}
//如果是加班
if(durationTypeEnum ==DurationTypeEnum.OVERTIME){
return getNonWorkDuration();
}
//时长
double D_Duration = 0.0;
//分钟数
double Min_Duration = 0.0;
SplitBean splitBean = new SplitBean();
splitBean.setFromDate(fromDate);
splitBean.setFromTime(fromTime);
splitBean.setToDate(toDate);
splitBean.setToTime(toTime);
splitBean.setResourceId(resourceid);
splitBean.setFromdatedb(fromDate);
splitBean.setTodatedb(toDate);
splitBean.setFromtimedb(fromTime);
splitBean.setTotimedb(toTime);
splitBean.setDurationrule(durationrule);
splitBean.setDurationTypeEnum(durationTypeEnum);
splitBean.setComputingMode(computingMode);
splitBean.setNewLeaveType(newLeaveType);
if("2".equalsIgnoreCase(computingMode)){
double oneDayHour = KQFlowUtil.getOneDayHour(durationTypeEnum,newLeaveType);
splitBean.setOneDayHour(oneDayHour);
if(durationTypeEnum == DurationTypeEnum.LEAVE){
//只有自然日 请假才有这个排除节假日、休息日的功能
splitBean.setFilterholidays(KQLeaveRulesBiz.getFilterHolidays(splitBean.getNewLeaveType()));
}
}
if(durationTypeEnum ==DurationTypeEnum.LEAVE || durationTypeEnum ==DurationTypeEnum.LEAVEBACK){
if(newLeaveType.length() > 0){
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
String conversion = kqLeaveRulesComInfo.getConversion(newLeaveType);
String repeatTime = kqLeaveRulesComInfo.getRepeatTime(newLeaveType);
splitBean.setConversion(conversion);
splitBean.setRepeatTime(repeatTime);
}
}
List<SplitBean> splitBeans = new ArrayList<>();
WorkDurationChain hourUnitSplitChain = new WorkHourUnitSplitChain(splitBeans);
WorkDurationChain dayUnitSplitChain = new WorkDayUnitSplitChain(splitBeans);
WorkDurationChain halfUnitSplitChain = new WorkHalfUnitSplitChain(splitBeans);
WorkDurationChain wholeUnitSplitChain = new WorkWholeUnitSplitChain(splitBeans);
//设置执行链
hourUnitSplitChain.setDurationChain(dayUnitSplitChain);
dayUnitSplitChain.setDurationChain(halfUnitSplitChain);
halfUnitSplitChain.setDurationChain(wholeUnitSplitChain);
//把初始数据设置进去
hourUnitSplitChain.handleDuration(splitBean);
//每一天的流程时长都在这里了,搞吧
for(SplitBean sb : splitBeans){
double durations = Util.getDoubleValue(sb.getDuration(), 0.0);
double min_durations = sb.getD_Mins();
D_Duration += durations;
Min_Duration += min_durations;
}
durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound(""+D_Duration));
durationMap.put("min_duration", KQDurationCalculatorUtil.getDurationRound(""+Min_Duration));
}catch (Exception e){
e.printStackTrace();
}
return durationMap;
}
/**
*
* @return
*/
public List<SplitBean> getWorkDurationCustom(){
List<SplitBean> splitBeans = new ArrayList<>();
try{
if(!isValidate(fromDate,toDate,fromTime,toTime)){
return splitBeans;
}
if(durationTypeEnum != DurationTypeEnum.COMMON_CAL){
kqLog.info("getWorkDuration:"+durationTypeEnum.getDurationType()+":fromDate:"+fromDate+":toDate:"+toDate+":fromTime:"+fromTime+":toTime:"+toTime+":durationrule:"+durationrule+":computingMode:"+computingMode);
}
//如果是加班
if(durationTypeEnum ==DurationTypeEnum.OVERTIME){
return splitBeans;
}
//时长
double D_Duration = 0.0;
//分钟数
double Min_Duration = 0.0;
SplitBean splitBean = new SplitBean();
splitBean.setFromDate(fromDate);
splitBean.setFromTime(fromTime);
splitBean.setToDate(toDate);
splitBean.setToTime(toTime);
splitBean.setResourceId(resourceid);
splitBean.setFromdatedb(fromDate);
splitBean.setTodatedb(toDate);
splitBean.setFromtimedb(fromTime);
splitBean.setTotimedb(toTime);
splitBean.setDurationrule(durationrule);
splitBean.setDurationTypeEnum(durationTypeEnum);
splitBean.setComputingMode(computingMode);
splitBean.setNewLeaveType(newLeaveType);
if("2".equalsIgnoreCase(computingMode)){
double oneDayHour = KQFlowUtil.getOneDayHour(durationTypeEnum,newLeaveType);
splitBean.setOneDayHour(oneDayHour);
if(durationTypeEnum == DurationTypeEnum.LEAVE){
//只有自然日 请假才有这个排除节假日、休息日的功能
splitBean.setFilterholidays(KQLeaveRulesBiz.getFilterHolidays(splitBean.getNewLeaveType()));
}
}
if(durationTypeEnum ==DurationTypeEnum.LEAVE || durationTypeEnum ==DurationTypeEnum.LEAVEBACK){
if(newLeaveType.length() > 0){
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
String conversion = kqLeaveRulesComInfo.getConversion(newLeaveType);
String repeatTime = kqLeaveRulesComInfo.getRepeatTime(newLeaveType);
splitBean.setConversion(conversion);
splitBean.setRepeatTime(repeatTime);
}
}
WorkDurationChain hourUnitSplitChain = new WorkHourUnitSplitChain(splitBeans);
WorkDurationChain dayUnitSplitChain = new WorkDayUnitSplitChain(splitBeans);
WorkDurationChain halfUnitSplitChain = new WorkHalfUnitSplitChain(splitBeans);
WorkDurationChain wholeUnitSplitChain = new WorkWholeUnitSplitChain(splitBeans);
//设置执行链
hourUnitSplitChain.setDurationChain(dayUnitSplitChain);
dayUnitSplitChain.setDurationChain(halfUnitSplitChain);
halfUnitSplitChain.setDurationChain(wholeUnitSplitChain);
//把初始数据设置进去
hourUnitSplitChain.handleDuration(splitBean);
}catch (Exception e){
e.printStackTrace();
}
return splitBeans;
}
/**
*
* @return false
*/
private boolean isValidate(String fromDate,String toDate,String fromTime,String toTime) {
KQRepeatBean kqRepeatBean = KQRepeatLengthContext.getRepeatBean();
if(kqRepeatBean != null){
return true;
}
if(fromDate.length() == 0 || toDate.length() == 0){
return false;
}
if(fromTime.length() == 0 || toTime.length() == 0){
return false;
}
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String fromDateTime = fromDate+" "+fromTime+":00";
String toDateTime = toDate+" "+toTime+":00";
LocalDateTime localFromDateTime = LocalDateTime.parse(fromDateTime,fullFormatter);
LocalDateTime localToDateTime = LocalDateTime.parse(toDateTime,fullFormatter);
if(localFromDateTime.isAfter(localToDateTime) || localFromDateTime.isEqual(localToDateTime)){
return false;
}
return true;
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public Map<String,Object> getTotalWorkingDurations(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
KQDurationCalculatorUtil kqDurationCalculatorUtil =new DurationParamBuilder(resourceid).
fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).durationRuleParam("1")
.computingModeParam("1").durationTypeEnumParam(DurationTypeEnum.COMMON_CAL).build();
Map<String,Object> durationMap = kqDurationCalculatorUtil.getWorkDuration();
return durationMap;
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalWorkingDays(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
Map<String,Object> durationMap = getTotalWorkingDurations(fromDate,fromTime,toDate,toTime,resourceid);
String duration4day = Util.null2s(Util.null2String(durationMap.get("duration")),"0");
return KQDurationCalculatorUtil.getDurationRound(duration4day);
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalWorkingHours(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
Map<String,Object> durationMap = getTotalWorkingDurations(fromDate,fromTime,toDate,toTime,resourceid);
String duration4min = Util.null2s(Util.null2String(durationMap.get("min_duration")),"0");
double duration4hour = Util.getDoubleValue(duration4min)/60.0;
return KQDurationCalculatorUtil.getDurationRound(duration4hour+"");
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalWorkingMins(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
Map<String,Object> durationMap = getTotalWorkingDurations(fromDate,fromTime,toDate,toTime,resourceid);
String duration4min = Util.null2s(Util.null2String(durationMap.get("min_duration")),"0");
return KQDurationCalculatorUtil.getDurationRound(duration4min+"");
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalNonWorkingDays(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
KQDurationCalculatorUtil kqDurationCalculatorUtil =new DurationParamBuilder(resourceid).
fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1").
durationRuleParam("1").durationTypeEnumParam(DurationTypeEnum.OVERTIME).build();
Map<String,Object> durationMap = kqDurationCalculatorUtil.getNonWorkDuration();
String duration = Util.null2String(durationMap.get("duration"));
return KQDurationCalculatorUtil.getDurationRound(duration);
}
/**
*
* @param fromDate
* @param fromTime
* @param toDate
* @param toTime
* @param resourceid
* @return
*/
public String getTotalNonWorkingHours(String fromDate,String fromTime,String toDate,String toTime,String resourceid){
KQDurationCalculatorUtil kqDurationCalculatorUtil =new DurationParamBuilder(resourceid).
fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1").
durationRuleParam("3").durationTypeEnumParam(DurationTypeEnum.OVERTIME).build();
Map<String,Object> durationMap = kqDurationCalculatorUtil.getNonWorkDuration();
String duration = Util.null2String(durationMap.get("duration"));
return KQDurationCalculatorUtil.getDurationRound(duration);
}
/**
* 2
* @param duration
* @return
*/
public static String getDurationRound(String duration){
if(HrmScheduleDiffUtil.isFromFlow()){
return Util.round(duration,5) ;
}
return Util.round(duration, 2);
}
/**
* 5
* @param duration
* @return
*/
public static String getDurationRound5(String duration){
return Util.round(duration, 5);
}
/**
* Builder
*/
public static class DurationParamBuilder {
//必选变量 人员看怎么都是需要的
private final String resourceid;
//可选变量
private String fromDate = "";
private String toDate = "";
private String fromTime = "";
private String toTime = "";
/**
*
*/
private String newLeaveType = "";
/**
*
* 1-
* 2-
* 3-
* 4-
*/
private String durationrule = "";
/**
*
* 1-
* 2-
*/
private String computingMode = "";
/**
*
*/
private String overtime_type = "";
/**
*
*/
private DurationTypeEnum durationTypeEnum;
public DurationParamBuilder(String resourceid) {
this.resourceid = resourceid;
//初始化的时候需要把其他参数先清空下
this.fromDate = "";
this.toDate = "";
this.fromTime = "";
this.toTime = "";
this.newLeaveType = "";
this.durationrule = "";
this.computingMode = "";
this.overtime_type = "";
}
//成员方法返回其自身,所以可以链式调用
public DurationParamBuilder fromDateParam(final String fromDate) {
this.fromDate = fromDate;
return this;
}
public DurationParamBuilder toDateParam(final String toDate) {
this.toDate = toDate;
return this;
}
public DurationParamBuilder fromTimeParam(final String fromTime) {
this.fromTime = fromTime;
return this;
}
public DurationParamBuilder toTimeParam(final String toTime) {
this.toTime = toTime;
return this;
}
public DurationParamBuilder newLeaveTypeParam(final String newLeaveType) {
this.newLeaveType = newLeaveType;
return this;
}
public DurationParamBuilder durationRuleParam(final String durationrule) {
this.durationrule = durationrule;
return this;
}
public DurationParamBuilder computingModeParam(final String computingMode) {
this.computingMode = computingMode;
return this;
}
public DurationParamBuilder overtime_typeParam(final String overtime_type) {
this.overtime_type = overtime_type;
return this;
}
public DurationParamBuilder durationTypeEnumParam(final DurationTypeEnum durationTypeEnum) {
this.durationTypeEnum = durationTypeEnum;
return this;
}
//Builder的build方法返回外部类的实例
public KQDurationCalculatorUtil build() {
return new KQDurationCalculatorUtil(this);
}
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save