Compare commits

...

50 Commits

Author SHA1 Message Date
Administrator a4cfa1d307 安防接口对接 1 year ago
Administrator fb8689160d Merge remote-tracking branch 'origin/dev' into dev 1 year ago
zhangming 280bd6d7fe 外出actionBUG修复 1 year ago
Administrator 8a94de0d05 责任制下月默认排班设置 1 year ago
Administrator 3727c0a5db Merge remote-tracking branch 'origin/dev' into dev 1 year ago
zhangming a5de914ee9 外出actionBUG修复 1 year ago
zhangming 2fa5df47ab Merge branch 'dev' of http://221.226.25.34:3000/chenwei/weaver-hostar into dev-zm
 Conflicts:
	src/com/engine/kq/cmd/report/ExportDailyExcelCmd.java
1 year ago
zhangming e445596114 生产代码 1 year ago
Administrator c4b72324cb 去除格式化对班代码 1 year ago
Administrator 29e8b1151f Merge remote-tracking branch 'origin/dev' into dev 1 year ago
李栋 99f62328cf 考勤报表导出bug-v1.0待验证 1 year ago
李栋 36601a10fb 外出出差action 1 year ago
Administrator 60ca792a56 Merge remote-tracking branch 'origin/dev' into dev 1 year ago
zhangming 5015d873d6 Merge branch 'dev' of http://221.226.25.34:3000/chenwei/weaver-hostar into dev-zm 1 year ago
李栋 677e414802 Revert "每日报表导出bug"
This reverts commit 04b390e0
1 year ago
李栋 52e0d2f699 Revert "每日报表导出bug"
This reverts commit 04b390e0
1 year ago
李栋 04b390e056 每日报表导出bug 1 year ago
zhangming ac4574470e 餐补报表优化 1 year ago
zhangming 7bef807a51 餐补报表优化 1 year ago
zhangming 33722523d3 餐补报表优化 1 year ago
zhangming 93a9d1f237 餐补优化 1 year ago
zhangming 9285635aee 驻点餐补BUG修复 1 year ago
Administrator 623fc926d2 打卡自动对班 1 year ago
Administrator e853bde2d5 Merge remote-tracking branch 'origin/dev' into dev 1 year ago
zhangming 30ebc44bb8 日报优化-去除不必要日志 1 year ago
zhangming dd07f9838e Merge branch 'dev' of http://221.226.25.34:3000/chenwei/weaver-hostar into dev-zm 1 year ago
zhangming bf0c6a2b46 日报优化-去除不必要日志 1 year ago
chenwei 39c8d460cb 新增打卡地址 1 year ago
Administrator 08f0477879 考勤对班 1 year ago
chenwei 435ac5bbfa 新增打卡地址 1 year ago
chenwei 43dad8ee44 新增打卡地址 1 year ago
chenwei ccfbb426ac 新增打卡地址 1 year ago
chenwei 15ab092f8b 考勤上线后问题处理 1 year ago
chenwei 2066506e17 Merge branch 'dev' into dev-chenwnj 1 year ago
chenwei 5337fba611 考勤上线后问题处理 1 year ago
Administrator 60659fe90d 考勤格式化版本代码合并 1 year ago
Administrator 2a6faf096e 自动对班 1 year ago
chenwei ae383628d5 考勤上线后问题处理 1 year ago
chenwei 7cb5afa79d 考勤上线后问题处理 1 year ago
chenwei 98b6e1847f 考勤上线后问题处理 1 year ago
chenwei 7a0a3e889c 考勤上线后问题处理 1 year ago
chenwei f581a7d9da 删除test文件 1 year ago
chenwei 24212fc10b Merge branch 'dev-chenwnj' into dev 1 year ago
chenwei c808c6d907 考勤上线后问题处理 1 year ago
fage d2cf61fbb7 加班时长根据整点、半点计算代码修改0117 1 year ago
chenwei 81ac13a7b2 实际出勤,打卡地址 1 year ago
chenwei 4faaec7639 三种餐补 1 year ago
chenwei 321a7878d2 餐补 1 year ago
chenwei 88991c41f1 出差 1 year ago
chenwei b1fc77100f 出差流程结合外勤打卡计算考勤数据 1 year ago

@ -0,0 +1,2 @@
# 餐补信息记录模块ID
cbxxjl_modeid=82

File diff suppressed because it is too large Load Diff

@ -4,8 +4,6 @@ import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.hostar.service.KqDevService;
import com.engine.hostar.service.impl.KqDevServiceImpl;
import com.engine.sskj.service.EntryService;
import com.engine.sskj.service.impl.EntryServiceImpl;
import com.google.gson.Gson;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
@ -35,4 +33,34 @@ public class KqDevController {
return new Gson().toJson(resultDatas);
}
@POST
@Path("/getEndWorkDate")
@Produces(MediaType.APPLICATION_JSON)
public String getEndWorkDate(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
Map<String, Object> resultDatas = getKqDevService(user).getEndWorkDate(params);
return new Gson().toJson(resultDatas);
}
@POST
@Path("/signDelete")
@Produces(MediaType.APPLICATION_JSON)
public String signDelete(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
Map<String, Object> resultDatas = getKqDevService(user).signDelete(params);
return new Gson().toJson(resultDatas);
}
@POST
@Path("/updateCbInfo")
@Produces(MediaType.APPLICATION_JSON)
public String updateCbInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
Map<String, Object> resultDatas = getKqDevService(user).updateCbInfo(params);
return new Gson().toJson(resultDatas);
}
}

@ -8,5 +8,12 @@ import java.util.Map;
* @description
**/
public interface KqDevService {
/*获取考勤日期的类型*/
Map<String, Object> getKqType(Map<String, Object> params);
/*根据开始日期和偏移量计算结束日期--工作日*/
Map<String, Object> getEndWorkDate(Map<String, Object> params);
/*删除原始打卡记录*/
Map<String, Object> signDelete(Map<String, Object> params);
Map<String, Object> updateCbInfo(Map<String, Object> params);
}

@ -1,14 +1,24 @@
package com.engine.hostar.service.impl;
import cn.hutool.core.date.DateUtil;
import com.engine.core.impl.Service;
import com.engine.hostar.service.KqDevService;
import com.engine.hostar.thread.HandleCBDataThread;
import com.engine.hostar.util.HostarUtil;
import com.engine.kq.biz.KQHolidaySetBiz;
import com.engine.kq.biz.KQOvertimeRulesBiz;
import com.engine.kq.biz.KQWorkTime;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.ThreadPoolUtil;
import weaver.general.Util;
import java.util.HashMap;
import java.util.Map;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
/**
* @author chenwnj
@ -40,9 +50,12 @@ public class KqDevServiceImpl extends Service implements KqDevService {
return result;
}
int changeType = -1;
try {
//1-节假日、2-工作日、3-休息日、-1-数据异常,无效数据
changeType = KQOvertimeRulesBiz.getChangeType(resourceId, kqDate);
bb.writeLog("changeType: " + changeType);
@ -62,4 +75,267 @@ public class KqDevServiceImpl extends Service implements KqDevService {
}
}
@Override
public Map<String, Object> getEndWorkDate(Map<String, Object> params) {
bb.writeLog("---checkApplyDate start---");
Map<String, Object> result = new HashMap<>();
String resourceId = Util.null2String(params.get("resourceId"));//申请人
bb.writeLog("resourceId: " + resourceId);
String kqDate = Util.null2String(params.get("kqDate"));//申请日期
bb.writeLog("kqDate: " + kqDate);
String offsetStr = Util.null2String(params.get("offset"));//允许的偏移量
bb.writeLog("offsetStr: " + offsetStr);
if ( StringUtils.isBlank(resourceId)) {
result.put("code",500);
result.put("msg","请先选择人员");
return result;
}
if ( StringUtils.isBlank(kqDate)) {
result.put("code",500);
result.put("msg","请先选择申请日期");
return result;
}
if ( StringUtils.isBlank(offsetStr)) {
result.put("code",500);
result.put("msg","请先设置偏移量");
return result;
}
Integer offset = Util.getIntValue(offsetStr);
bb.writeLog("offset: " + offset);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate start = LocalDate.parse(kqDate, formatter);
if (offset > 0 ) {
for (int i = 0 ; i < offset ; ) {
start = start.plusDays(1);
boolean holiday = KQHolidaySetBiz.isHoliday(resourceId, start.format(formatter), true);
if ( !holiday) {
i++;
}
}
} else if (offset < 0 ) {
for (int i = 0 ; i > offset ; ) {
start = start.minusDays(1);
boolean holiday = KQHolidaySetBiz.isHoliday(resourceId, start.format(formatter), true);
if ( !holiday) {
i--;
}
}
}
String endDate = start.format(formatter);
result.put("code",200);
result.put("msg","请求成功");
result.put("data",endDate);
return result;
}
@Override
public Map<String, Object> signDelete(Map<String, Object> params) {
bb.writeLog("---signDelete start---");
Map<String, Object> result = new HashMap<>();
try {
String dataid = Util.null2String(params.get("id"));//申请人
bb.writeLog("dataid: " + dataid);
if ( StringUtils.isBlank(dataid)) {
result.put("code",500);
result.put("msg","请先选择要删除的数据");
return result;
}
//将需要删除的打卡数据记录到日志表后再执行删除
RecordSet rs = new RecordSet();
List<String> deleteParams = new ArrayList<>();
List<List> logParams = new ArrayList<>();
String signDelLogModeId = bb.getPropValue("project_hostar", "signDelLogModeId");
bb.writeLog("signDelLogModeId: " + signDelLogModeId);
Integer modedatacreater = user.getUID();
Integer modedatacreatertype = user.getType();
String modedatacreatedate = DateUtil.format(new Date(), "yyyy-MM-dd");
String modedatacreatetime = DateUtil.format(new Date(), "HH:mm:ss");
String acqMaxIdSql = " select max(id) as id from uf_schsigndellog";
String logSignSql = "insert into uf_schsigndellog (userid, usertype, signtype, signdate, signtime, clientaddress, isincom, " +
" signfrom, longitude, latitude, addr, isimport, suuid, timezone, belongdate, memo, deviceinfo, showaddress, " +
" formmodeid, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime ) " +
" values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
String acqSchSignSql = "select userid, usertype, signtype, signdate, signtime, clientaddress, isincom," +
" signfrom, longitude, latitude, addr, isimport, suuid, timezone, belongdate, memo, " +
" deviceinfo, showaddress from hrmschedulesign where id in (" + dataid + ")";
rs.executeQuery(acqSchSignSql);
while (rs.next()) {
String userid = Util.null2String(rs.getString("userid"));
String usertype = Util.null2String(rs.getString("usertype"));
String signtype = Util.null2String(rs.getString("signtype"));
String signdate = Util.null2String(rs.getString("signdate"));
String signtime = Util.null2String(rs.getString("signtime"));
String clientaddress = Util.null2String(rs.getString("clientaddress"));
String isincom = Util.null2String(rs.getString("isincom"));
String signfrom = Util.null2String(rs.getString("signfrom"));
String longitude = Util.null2String(rs.getString("longitude"));
String latitude = Util.null2String(rs.getString("latitude"));
String addr = Util.null2String(rs.getString("addr"));
String isimport = Util.null2String(rs.getString("isimport"));
String suuid = Util.null2String(rs.getString("suuid"));
String timezone = Util.null2String(rs.getString("timezone"));
String belongdate = Util.null2String(rs.getString("belongdate"));
String memo = Util.null2String(rs.getString("memo"));
String deviceinfo = Util.null2String(rs.getString("deviceinfo"));
String showaddress = Util.null2String(rs.getString("showaddress"));
List logPa = new ArrayList<>();
logPa.add(userid);
logPa.add(usertype);
logPa.add(signtype);
logPa.add(signdate);
logPa.add(signtime);
logPa.add(clientaddress);
logPa.add(isincom);
logPa.add(signfrom);
logPa.add(longitude);
logPa.add(latitude);
logPa.add(addr);
logPa.add(isimport);
logPa.add(suuid);
logPa.add(timezone);
logPa.add(belongdate);
logPa.add(memo);
logPa.add(deviceinfo);
logPa.add(showaddress);
logPa.add(signDelLogModeId);
logPa.add(modedatacreater);
logPa.add(modedatacreatertype);
logPa.add(modedatacreatedate);
logPa.add(modedatacreatetime);
logParams.add(logPa);
}
int maxLogId = -1;
rs.executeQuery(acqMaxIdSql);
while (rs.next()) {
maxLogId = Util.getIntValue(Util.null2String(rs.getString("id")));
}
bb.writeLog("maxLogId: " + maxLogId);
boolean addLogFlag = rs.executeBatchSql(logSignSql, logParams);
bb.writeLog("addLogFlag: " + addLogFlag);
if (addLogFlag) {
List<Integer> billids = new ArrayList<>();
Map<Integer,Integer> billidCreator = new HashMap<>();
String acqBillidsSql = "select id from uf_schsigndellog where id > ?";
rs.executeQuery(acqBillidsSql, maxLogId);
while (rs.next()) {
Integer id = Util.getIntValue(Util.null2String(rs.getString("id")));
billids.add(id);
billidCreator.put(id, 1);
}
bb.writeLog("billids: " + billids);
bb.writeLog("billidCreator: " + billidCreator);
if (billids != null && billids.size() > 0) {
HostarUtil hsutil = new HostarUtil();
hsutil.modePerReconBatch(billidCreator, signDelLogModeId, billids);
}
} else {
result.put("code",500);
result.put("msg","删除失败");
return result;
}
boolean delFlag = rs.executeUpdate("delete from hrmschedulesign where id in (" + dataid + ")");
if (delFlag) {
result.put("code",200);
result.put("msg","删除成功");
return result;
} else {
result.put("code",500);
result.put("msg","删除失败");
return result;
}
}catch (Exception e ) {
bb.writeLog("signDelete Exception: " + e);
}
result.put("code",500);
result.put("msg","删除失败");
return result;
}
@Override
public Map<String, Object> updateCbInfo(Map<String, Object> params) {
bb.writeLog("---updateCbInfo start---");
Map<String, Object> result = new HashMap<>();
try {
String ryParam = Util.null2String(params.get("name"));
String startDate = Util.null2String(params.get("startdate"));
String endDate = Util.null2String(params.get("enddate"));
String today = DateUtil.format(new Date(), "yyyy-MM-dd");
if (org.apache.commons.lang3.StringUtils.isEmpty(endDate)) {
endDate = today;
}
if (org.apache.commons.lang3.StringUtils.isEmpty(startDate)) {
startDate = today;
}
List<String> allDates = getAllDates(startDate, endDate);
RecordSet rs = new RecordSet();
List<String> userIds = new ArrayList<>();
if (org.apache.commons.lang3.StringUtils.isEmpty(ryParam)) {
bb.writeLog("1111.");
rs.executeQuery("select id from hrmresource");
while (rs.next()) {
userIds.add(rs.getString("id"));
}
} else {
String[] ryParamTemp = ryParam.split(",");
userIds.addAll(Arrays.asList(ryParamTemp));
}
bb.writeLog("userIds:" + userIds);
if (CollectionUtils.isEmpty(userIds) || CollectionUtils.isEmpty(allDates)) {
bb.writeLog("no user or date.");
result.put("mes", "没有数据需要更新!");
result.put("code", "200");
return result;
}
ExecutorService executorService = ThreadPoolUtil.getThreadPool(null, null);
for (String userId : userIds) {
for (String kqDate : allDates) {
executorService.execute(new HandleCBDataThread(userId, kqDate));
}
}
if (executorService.isTerminated()) {
executorService.shutdown();
}
} catch (Exception e) {
bb.writeLog("updateCbInfo error:" + e.getMessage());
result.put("mes", "系统错误,请联系管理员!");
result.put("code", "400");
}
result.put("mes", "已开始计算,请稍等!");
result.put("code", "200");
return result;
}
public List<String> getAllDates(String startDate, String endDate) {
List<String> result = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate start = LocalDate.parse(startDate, formatter);
LocalDate end = LocalDate.parse(endDate, formatter);
while (!start.isAfter(end)) {
result.add(start.format(formatter));
start = start.plusDays(1);
}
return result;
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,120 @@
package com.engine.hostar.util;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author chenwnj
* @date 2023/12/14
* @description
**/
public class HostarUtil {
BaseBean bb = new BaseBean();
// 地球半径,单位:米
private static final int EARTH_RADIUS = 6371000;
/**
*
* @params startDate
* @params endDate
*/
public List<String> getAllDates(String startDate, String endDate) {
List<String> result = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate start = LocalDate.parse(startDate, formatter);
LocalDate end = LocalDate.parse(endDate, formatter);
while (!start.isAfter(end)) {
result.add(start.format(formatter));
start = start.plusDays(1);
}
return result;
}
/**
*
* @params lat1 1
* @params lon1 1
* @params lat2 2
* @params lon2 2
* @return 12
*/
public Double calculateDistance(Double lat1, Double lon1, Double lat2, Double lon2) {
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
double a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return EARTH_RADIUS * c;
}
/**
*
* @param userId
* @param modeId
* @param billid
*/
public void modePerRecon(Integer userId, String modeId, String billid) {
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare( userId, Integer.parseInt(modeId), Integer.parseInt(billid));
}
/**
*
* @param billid_creator
* @param modeId
* @param billids
*/
public void modePerReconBatch(Map<Integer,Integer> billid_creator, String modeId, List<Integer> billids) {
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare( billid_creator, Integer.parseInt(modeId), billids);
}
/**
* mapmapkey
*/
public Map<String, Object> parseMapForFilter(Map<String, Object> map, String filters) {
if (map == null) {
return null;
} else {
map = map.entrySet().stream()
.filter((e) -> checkKey(e.getKey(),filters))
.collect(Collectors.toMap(
(e) -> (String) e.getKey(),
(e) -> e.getValue()
));
}
return map;
}
/**
* indexof
*/
private boolean checkKey(String key,String filters) {
if (key.indexOf(filters)>-1){
return true;
}else {
return false;
}
}
}

@ -0,0 +1,815 @@
package com.engine.kq.biz;
import com.engine.kq.enums.FlowReportTypeEnum;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.wfset.bean.SplitBean;
import net.qiyuesuo.sdk.common.utils.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
*
*/
public class KQFlowDataBiz {
BaseBean bb = new BaseBean();
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(getLeaveData(flowMaps,flowDeductCard));
// allSplitBeans.addAll(getEvectionData(flowMaps,flowDeductCard));
// allSplitBeans.addAll(getOutData(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 a.* from "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 ";
String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
List<SplitBean> splitBeans = new ArrayList<>();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
int[] initArrays = kqTimesArrayComInfo.getInitArr();
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");
String leavebackrequestid= Util.null2String(rs.getString("leavebackrequestid"));
if(Util.getDoubleValue(duration) <= 0){
continue;
}
//计算规则 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];
}
}
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("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
infoMap.put("signtype", signtype);
infoMap.put("serial", serial);
String key = resourceid+"|"+belongdate;
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(back_fromtime.equalsIgnoreCase(fromtime)){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
}else{
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -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("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
time_list_tmp.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(back_fromtime.equalsIgnoreCase(fromtime)){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -1);
}else{
if(back_fromtime.compareTo(back_totime) < 0){
Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime), -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("flowtype", FlowReportTypeEnum.LEAVE.getFlowType());
infoMap.put("newleavetype", newleavetype);
time_list.add(infoMap);
}
flowMaps.put(key, time_list);
}
}else{
List<Map<String,String>> time_list = new ArrayList<>();
time_list.add(infoMap);
flowMaps.put(key, 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 leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
leaveSql += sqlWhere;
}
// /*考勤二开--出差公出流程结合外勤打卡计算考勤数据start*/
// //先获取考勤班次开始时间
// String startTime = "";
// Map<String, Object> serialInfo = new KQWorkTime().getSerialInfo(resourceid, fromDate, false);
// bb.writeLog("serialInfo: " + serialInfo);
//
// String serialid = Util.null2String(serialInfo.get(fromDate));
// if (StringUtils.isNotBlank(serialid)) {
// //根据班次获取班次开始时间
// String acqOnOffSql = "select times, onoffworktype from kq_shiftonoffworksections where (isdelete = 0 or isdelete is null) and serialid = ? ";
// rs.executeQuery(acqOnOffSql, serialid);
// while ( rs.next()) {
// String times = Util.null2String(rs.getString("times"));
// String onoffworktype = Util.null2String(rs.getString("onoffworktype"));
//
// if (onoffworktype.equals("start")) {
// startTime = times + ":00";
// }
// }
// }
// //只取班次开始时间前一个小时开始的打卡
// LocalTime specifiedLocalTime = LocalTime.parse(startTime);
//
// // 获取前一个小时
// LocalTime previousHour = specifiedLocalTime.minusHours(1);
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); // 定义时间格式
// startTime = previousHour.format(formatter);
//
// bb.writeLog("startTime: " + startTime);
//
// String sqlLeWhere = sqlLeWhere(startTime);
// String acqLegworkSql = "select * from mobile_sign where 1=1 " + sqlLeWhere;
// bb.writeLog("acqLegworkSql: " + acqLegworkSql);
//
// /*考勤二开--出差公出流程结合外勤打卡计算考勤数据end*/
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("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 leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') ";
String sqlWhere = sqlParamWhere();
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("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 leaveSql = "select * from ("+tablename+") t where 1=1 ";
String sqlWhere = sqlParamWhere();
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 leaveSql = "select * from ("+tablename+") t where 1=1 ";
String sqlWhere = sqlParamWhere();
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 sqlLeWhere( String startTime) {
// String sqlWhere = "";
// sqlWhere += " and operate_type = 'mobile_sign' and operate_time >='" + startTime + "' and operate_time <='23:59:59' ";
// if(resourceid.length() > 0){
// sqlWhere += " and operater in ( "+resourceid+" )";
// }
// if(belongDate.length() > 0){
// sqlWhere += " and operate_date = '"+belongDate+"' ";
// }
//
// return sqlWhere;
// }
/**
*
* @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);
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,898 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.entity.TimeSignScopeEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.util.UtilKQ;
import com.engine.kq.wfset.util.KQSignUtil;
import com.google.common.collect.Lists;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.util.*;
/**
*
*/
public class KQFormatSignData extends BaseBean {
private KQLog kqLog = new KQLog();
BaseBean bb = new BaseBean();
public List<Object> getSignInfo(String userId, TimeScopeEntity signTimeScope,
TimeScopeEntity workTimeScope, String kqDate, String preDate,
String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo) {
return getSignInfo(userId, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo,
Lists.newArrayList(), "");
}
public List<Object> getSignInfo(String userId, TimeScopeEntity signTimeScope,
TimeScopeEntity workTimeScope, String kqDate, String preDate,
String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,ArrayList<String> hostIps,String uuid) {
return getSignInfo(userId, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo, hostIps, uuid, 0, 0);
}
/***
*
* @param userId
* @param signTimeScope
* @param workTimeScope
* @param kqDate
* @param preDate
* @param nextDate
* @param kqTimesArrayComInfo
* @return
*/
public List<Object> getSignInfo(String userId, TimeScopeEntity signTimeScope,
TimeScopeEntity workTimeScope, String kqDate, String preDate,
String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,ArrayList<String> hostIps,String uuid, int shiftCount, int shiftI) {
kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+" in ");
List<Object> lsCheckInfo = new ArrayList<>();
String count4NoonStartDateTime = "";
String count4NoonEndDateTime = "";
try{
bb.writeLog("getSignInfo start");
Map<String, Object> checkInfo = null;
String base_sql = "";
RecordSet rs = new RecordSet();
String dbtype = rs.getDBType();
//获取工作上下班时间
String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? nextDate : kqDate;
workBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime())+":00";
kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::workBeginDateTime::"+workBeginDateTime);
//获取工作上下班时间
String workEndDateTime = workTimeScope.getEndTimeAcross() ? nextDate : kqDate;
workEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime())+":00";
kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::workEndDateTime::"+workEndDateTime);
Map<String,String> flow_deduct_card_map = getflowDeductCardSql(userId,kqDate,workTimeScope.getBeginTime(),workTimeScope.getEndTime());
kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::flow_deduct_card_map::"+flow_deduct_card_map);
List<Map<String,String>> sqlConditions = getCanSignInfo(signTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo,workTimeScope, shiftCount, shiftI);
base_sql = signSignSql(rs);
new KQLog().info("sqlConditions:(userId:"+userId+":base_sql"+base_sql+":::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::flow_deduct_card_map::"+flow_deduct_card_map);
if(sqlConditions != null && !sqlConditions.isEmpty()){
if(shiftCount == 2) {
String fieldName = "";
if(shiftI == 0) {
fieldName = "signEndDateTime";
} else if(shiftI == 1) {
fieldName = "signBeginDateTime";
}
Map<String, String> sqlMap = sqlConditions.get(0);
count4NoonStartDateTime = Util.null2String(sqlMap.get(fieldName));
if (count4NoonStartDateTime.length() == 19) {
count4NoonStartDateTime = count4NoonStartDateTime.substring(0, 17) + "00";
}
sqlMap = sqlConditions.get(0);
count4NoonEndDateTime = Util.null2String(sqlMap.get(fieldName));
if (sqlConditions.size() >= 2) {
sqlMap = sqlConditions.get(1);
count4NoonEndDateTime = Util.null2String(sqlMap.get(fieldName));
}
}
for(Map<String,String> sqlMap : sqlConditions){
String sql = "";
String orderSql = "";
int idx = 0;
String signBeginDateTime = Util.null2String(sqlMap.get("signBeginDateTime"));
String signEndDateTime = Util.null2String(sqlMap.get("signEndDateTime"));
String type = Util.null2String(sqlMap.get("type"));
if(type.length() > 0){
if("signoff".equalsIgnoreCase(type)){
orderSql = " order by signdate desc, signtime desc ";
}else if("signin".equalsIgnoreCase(type)){
orderSql = " order by signdate asc, signtime asc ";
}
if("oracle".equalsIgnoreCase(dbtype)){
sql = "select * from ("+base_sql+" "+orderSql+") a where rownum=1";
}else if("mysql".equalsIgnoreCase(dbtype)){
sql = "select * from ("+base_sql+" "+orderSql+") a limit 0,1";
}
else if("postgresql".equalsIgnoreCase(dbtype)){
sql = "select * from ("+base_sql+" "+orderSql+") a limit 1 offset 0";
}
else if("sqlserver".equalsIgnoreCase(dbtype)){
sql = "select top 1 * from ("+base_sql+") a "+" "+orderSql;
}else{
sql = "select * from ("+base_sql+" "+orderSql+") a where rownum=1";
}
}else{
orderSql = " order by signdate asc, signtime asc ";
sql = base_sql+" "+orderSql;
}
rs.executeQuery(sql, userId, signBeginDateTime, signEndDateTime);
new KQLog().info("getSignInfo:(userId:"+userId+":signBeginDateTime:"+
signBeginDateTime+":signEndDateTime:"+signEndDateTime+"):sql"+sql+":counts:"+rs.getCounts()+":::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::flow_deduct_card_map::"+flow_deduct_card_map);
while (rs.next()) {
String signId = Util.null2String(rs.getString("id"));
String signdate = Util.null2String(rs.getString("signdate"));
String signtime = Util.null2String(rs.getString("signtime"));
checkInfo = new HashMap<>();
checkInfo.put("signId", signId);//签到签退标识
checkInfo.put("signDate", signdate);//签到签退日期
checkInfo.put("signTime", signtime);//签到签退时间
String signDateTime = signdate + " " + signtime;
idx++;
if(type.length() > 0){
if("signin".equalsIgnoreCase(type)){
checkInfo.put("signType", "1");
if(workBeginDateTime.length()>0) {
checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime));
}
if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){
if(flow_deduct_card_map.containsKey("signin")){
String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin"));
if(deduct_signintime.length() > 0){
signDateTime = signdate + " " + deduct_signintime;
checkInfo.put("deduct_signintime", deduct_signintime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime));
}
}
}
lsCheckInfo.add(checkInfo);
}else {
checkInfo.put("signType", "2");
if(workEndDateTime.length()>0) {
checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime));
}
if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){
if(flow_deduct_card_map.containsKey("signoff")){
String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff"));
if(deduct_signofftime.length() > 0){
signDateTime = signdate + " " + deduct_signofftime;
checkInfo.put("deduct_signofftime", deduct_signofftime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime));
}
}
}
lsCheckInfo.add(checkInfo);
}
}else{
if(idx==1){//第一条算签到
checkInfo.put("signType", "1");
if(workBeginDateTime.length()>0) {
checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime));
}
if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){
if(flow_deduct_card_map.containsKey("signin")){
String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin"));
if(deduct_signintime.length() > 0){
signDateTime = signdate + " " + deduct_signintime;
checkInfo.put("deduct_signintime", deduct_signintime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime));
}
}
}
lsCheckInfo.add(checkInfo);
}else if(idx==rs.getCounts()){//最后一条算签退
checkInfo.put("signType", "2");
if(workEndDateTime.length()>0) {
checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime));
}
if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){
if(flow_deduct_card_map.containsKey("signoff")){
String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff"));
if(deduct_signofftime.length() > 0){
signDateTime = signdate + " " + deduct_signofftime;
checkInfo.put("deduct_signofftime", deduct_signofftime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime));
}
}
}
lsCheckInfo.add(checkInfo);
}
}
}
}
}
//如果签到,签退不成对,流程抵扣异常存在,那么需要判断下是不是可以补足
if(lsCheckInfo.size() < 2 && !flow_deduct_card_map.isEmpty()){
if(lsCheckInfo.isEmpty()){
if(flow_deduct_card_map.containsKey("signin")){
String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin"));
if(deduct_signintime.length() > 0){
checkInfo = new HashMap<>();
String[] workBeginDateTimes = workBeginDateTime.split(" ");
String tmp_workBeginDate = workBeginDateTimes[0];
String tmp_workBeginTime = workBeginDateTimes[1];
checkInfo.put("signType", "1");
checkInfo.put("signDate", tmp_workBeginDate);//签到签退日期
checkInfo.put("signTime", "");//签到签退时间
checkInfo.put("deduct_signintime", tmp_workBeginTime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
lsCheckInfo.add(checkInfo);
}
}
if(flow_deduct_card_map.containsKey("signoff")){
String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff"));
if(deduct_signofftime.length() > 0){
checkInfo = new HashMap<>();
String[] workEndDateTimes = workEndDateTime.split(" ");
String tmp_workEndDate = workEndDateTimes[0];
String tmp_workEndTime = workEndDateTimes[1];
checkInfo.put("signType", "2");
checkInfo.put("signDate", tmp_workEndDate);//签到签退日期
checkInfo.put("signTime", "");//签到签退时间
checkInfo.put("deduct_signofftime", tmp_workEndTime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
lsCheckInfo.add(checkInfo);
}
}
}else{
Map<String, Object> checkCardMap = (Map<String, Object>) lsCheckInfo.get(0);
if(!checkCardMap.isEmpty()){
String signType = Util.null2String(checkCardMap.get("signType"));
if("1".equalsIgnoreCase(signType)){
//如果签到数据有了,检测下是不是有签退的流程抵扣打卡
if(flow_deduct_card_map.containsKey("signoff")){
String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff"));
if(deduct_signofftime.length() > 0){
checkInfo = new HashMap<>();
String[] workEndDateTimes = workEndDateTime.split(" ");
String tmp_workEndDate = workEndDateTimes[0];
String tmp_workEndTime = workEndDateTimes[1];
checkInfo.put("signType", "2");
checkInfo.put("signDate", tmp_workEndDate);//签到签退日期
checkInfo.put("signTime", "");//签到签退时间
checkInfo.put("deduct_signofftime", tmp_workEndTime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
lsCheckInfo.add(checkInfo);
}
}
}else{
if(flow_deduct_card_map.containsKey("signin")){
String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin"));
if(deduct_signintime.length() > 0){
checkInfo = new HashMap<>();
String[] workBeginDateTimes = workBeginDateTime.split(" ");
String tmp_workBeginDate = workBeginDateTimes[0];
String tmp_workBeginTime = workBeginDateTimes[1];
checkInfo.put("signType", "1");
checkInfo.put("signDate", tmp_workBeginDate);//签到签退日期
checkInfo.put("signTime", "");//签到签退时间
checkInfo.put("deduct_signintime", tmp_workBeginTime);//流程抵扣作为打卡时间
checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
lsCheckInfo.add(checkInfo);
}
}
}
}
}
}
// 上午的签退取中间时段的第一次打卡
if(shiftCount == 2 && shiftI == 0) {
String noonSignTimeSql = KQSignUtil.buildSignSql(count4NoonStartDateTime,count4NoonEndDateTime);
String baseSql = "select * from hrmschedulesign where 1=1 and isInCom='1' and userid="+userId+" ";
String sql = baseSql;
sql += " and "+noonSignTimeSql + " order by signdate, signtime";
rs.executeQuery(sql);
if(rs.next()) {
String signId = Util.null2String(rs.getString("id"));
String signDate = Util.null2String(rs.getString("signdate"));
String signTime = Util.null2String(rs.getString("signtime"));
String signDateTime = signDate+" "+signTime;
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> checkInfoInner = (Map<String, Object>) lsCheckInfo.get(j);
if (checkInfoInner.get("signType").equals("2")) {//签退
String signDateInner = Util.null2String(checkInfoInner.get("signDate"));
String signTimeInner = Util.null2String(checkInfoInner.get("signTime"));
String deduct_signofftime = Util.null2String(checkInfoInner.get("deduct_signofftime"));
if(!"".equals(signTimeInner)) {
String signDateTimeInner = signDateInner+" "+signTimeInner;
if(signDateTime.compareTo(signDateTimeInner) < 0) {
checkInfoInner.put("signId", signId);//签到签退标识
checkInfoInner.put("signType", "2");
checkInfoInner.put("signDate", signDateInner);//签到签退日期
checkInfoInner.put("signTime", signTime);//签到签退时间
checkInfoInner.put("deduct_signofftime", deduct_signofftime);//流程抵扣作为打卡时间
checkInfoInner.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
}
}
}
}
}
} else if(shiftCount == 2 && shiftI == 1) { // 下午的签到取中间时段的第二次打卡
String noonSignTimeSql = KQSignUtil.buildSignSql(count4NoonStartDateTime,count4NoonEndDateTime);
String baseSql = "select * from hrmschedulesign where 1=1 and isInCom='1' and userid="+userId+" ";
String sql = baseSql;
sql += " and "+noonSignTimeSql + " order by signdate, signtime";
rs.executeQuery(sql);
int count=0;
int counts=rs.getCounts();
if(counts==1){
lsCheckInfo.clear();
}
while (rs.next()) {
if(count == 0) {
count++;
continue;
}
String signId = Util.null2String(rs.getString("id"));
String signTime = Util.null2String(rs.getString("signtime"));
for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) {
Map<String, Object> checkInfoInner = (Map<String, Object>) lsCheckInfo.get(j);
if (checkInfoInner.get("signType").equals("1")) {//签退
String signDateInner = Util.null2String(checkInfoInner.get("signDate"));
String signTimeInner = Util.null2String(checkInfoInner.get("signTime"));
String deduct_signofftime = Util.null2String(checkInfoInner.get("deduct_signofftime"));
checkInfoInner.put("signId", signId);//签到签退标识
checkInfoInner.put("signType", "1");
checkInfoInner.put("signDate", signDateInner);//签到签退日期
checkInfoInner.put("signTime", signTime);//签到签退时间
checkInfoInner.put("deduct_signofftime", deduct_signofftime);//流程抵扣作为打卡时间
checkInfoInner.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
}
}
break;
}
}
}catch (Exception e){
kqLog.info("报表错:getSignInfo:");
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
/*考勤二开--出差公出流程获取外勤打卡数据start*/
// BaseBean bb = new BaseBean();
//
// bb.writeLog("+-出差公出流程获取外勤打卡数据start");
// bb.writeLog("lsCheckInfo: " + lsCheckInfo);
// bb.writeLog("lsCheckInfo.size(): " + lsCheckInfo.size());
// //获取外勤打卡的前提是已经有归档的出差、公出流程
// String evectionTableName = Util.null2String(bb.getPropValue("project_hostar","evectionTableName"));
//// bb.writeLog("evectionTableName: " + evectionTableName);
//
// String outTableName = Util.null2String(bb.getPropValue("project_hostar","outTableName"));
//// bb.writeLog("outTableName: " + outTableName);
//
// if ( StringUtils.isNotBlank(evectionTableName) && StringUtils.isNotBlank(outTableName) ) {
// RecordSet rs = new RecordSet();
// Integer number = -1;
// String acqEvecAndOutSql = " select sum(a.number) as number " +
// " from ( " +
// " SELECT " +
// " count(*) as number " +
// " FROM " +
// " workflow_requestbase " +
// " WHERE " +
// " requestid IN ( SELECT requestid FROM "+evectionTableName+" WHERE sqr = '"+userId+"' and ksrq <='"+kqDate+"' and yjjsrq >='"+kqDate+"' ) " +
// " AND currentnodetype = 3 " +
// " UNION all " +
// " SELECT " +
// " count(*) as number " +
// " FROM " +
// " workflow_requestbase " +
// " WHERE " +
// " requestid IN ( SELECT requestid FROM "+outTableName+" WHERE sqr = '"+userId+"' and ksrq <='"+kqDate+"' and yjjsrq >='"+kqDate+"') " +
//// " AND currentnodetype = 3 " +
// ") a ";
// rs.executeQuery(acqEvecAndOutSql);
//// bb.writeLog("acqEvecAndOutSql: " + acqEvecAndOutSql);
//
// while (rs.next()) {
// number = Util.getIntValue(Util.null2String(rs.getString("number")));
// }
// bb.writeLog("number: " + number);
//
// if (lsCheckInfo.size() < 2 && number > 0) {//只考虑每天一次上下班,原始打卡记录没有取到两次打卡记录则考虑外勤打卡
// List<String> legWorkInfos = new ArrayList<>();
// //获取允许打卡时间
// String signBeginTime = signTimeScope.getBeginTime();
//// bb.writeLog("signBeginTime: " + signBeginTime);
// if (StringUtils.isNotBlank(signBeginTime)) {
// signBeginTime = signBeginTime + ":00";
// }
//// bb.writeLog("signBeginTime: " + signBeginTime);
// //获取上班时间
// String workBeginTime = workTimeScope.getBeginTime();
//// bb.writeLog("workBeginTime: " + workBeginTime);
// if (StringUtils.isNotBlank(workBeginTime)) {
// workBeginTime = workBeginTime + ":00";
// }
//// bb.writeLog("workBeginTime: " + workBeginTime);
//
// String acqLegWorkSignSql = "select operate_time from mobile_sign where operater = ? and operate_date = '" + kqDate + "' and operate_time >='" + signBeginTime + "' order by operate_time asc ";
// bb.writeLog("acqLegWorkSignSql: " + acqLegWorkSignSql);
//// bb.writeLog("userId: " + userId);
// rs.executeQuery(acqLegWorkSignSql, userId);
// while ( rs.next()) {
// String operateTime = Util.null2String(rs.getString("operate_time"));
// if ( StringUtils.isNotBlank(operateTime) ) {
// legWorkInfos.add(operateTime);
// }
// }
// bb.writeLog("legWorkInfos: " + legWorkInfos);
//
// if (legWorkInfos != null && legWorkInfos.size() > 0 ) {
// boolean onFlag = false;//上班卡
// boolean offFlag = false;//下班卡
//
// //判断需要获取的打卡
// for(Object obj: lsCheckInfo) {
// if (obj != null) {
// Map<String, Object> checkInfo = (Map<String, Object> ) obj;
// Integer signType = Util.getIntValue(Util.null2String(checkInfo.get("signType")));
// if (signType == 1) {
// onFlag = true;
// }
// if (signType == 2) {
// offFlag = true;
// }
// }
// }
//
// String tempSignIn = "";
// String tempSignOut = "";
// Map<String, Object> checkInfo = new HashMap<>();
// if ( legWorkInfos.size() == 1) {//只有一笔外勤卡直接算上班
// if ( onFlag && !offFlag ) {
// checkInfo.put("signType", "2");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", legWorkInfos.get(0));//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
// }
// if ( !onFlag && offFlag ) {
// checkInfo.put("signType", "1");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", legWorkInfos.get(0));//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
// }
//
// } else {
// for ( String signTime : legWorkInfos) {
// if (signTime.compareTo(workBeginTime) < 0) {//获取上班时间点之前最早的一笔卡
// if (StringUtils.isBlank(tempSignIn)) {
// tempSignIn = signTime;
// } else {
// if ( signTime.compareTo(tempSignIn) < 0 ) {
// tempSignIn = signTime;
// }
// }
// }
// if ( signTime.compareTo(workBeginTime) > 0) {//下班卡取最晚的一笔
// if (StringUtils.isBlank(tempSignIn)) {
// tempSignOut = signTime;
// } else {
// if ( signTime.compareTo(tempSignOut) > 0 ) {
// tempSignOut = signTime;
// }
// }
// }
// }
// if (offFlag && !onFlag ) {
// checkInfo.put("signType", "1");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", tempSignIn);//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
// }
// if (onFlag && !offFlag ) {
// checkInfo = new HashMap<>();
// checkInfo.put("signType", "2");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", tempSignOut);//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
// }
// }
// }
// } else if ( lsCheckInfo.size() == 2) {
// List<String> legWorkInfos = new ArrayList<>();
// //获取允许打卡时间
// String signBeginTime = signTimeScope.getBeginTime();
//// bb.writeLog("signBeginTime: " + signBeginTime);
// if (StringUtils.isNotBlank(signBeginTime)) {
// signBeginTime = signBeginTime + ":00";
// }
//// bb.writeLog("signBeginTime: " + signBeginTime);
// //获取上班时间
// String workBeginTime = workTimeScope.getBeginTime();
//// bb.writeLog("workBeginTime: " + workBeginTime);
// if (StringUtils.isNotBlank(workBeginTime)) {
// workBeginTime = workBeginTime + ":00";
// }
//// bb.writeLog("workBeginTime: " + workBeginTime);
//
// String acqLegWorkSignSql = "select operate_time from mobile_sign where operater = ? and operate_date = '" + kqDate + "' and operate_time >='" + signBeginTime + "' order by operate_time asc ";
// bb.writeLog("acqLegWorkSignSql: " + acqLegWorkSignSql);
// bb.writeLog("userId: " + userId);
// rs.executeQuery(acqLegWorkSignSql, userId);
// while ( rs.next()) {
// String operateTime = Util.null2String(rs.getString("operate_time"));
// if ( StringUtils.isNotBlank(operateTime) ) {
// legWorkInfos.add(operateTime);
// }
// }
//// bb.writeLog("legWorkInfos: " + legWorkInfos);
//
// if (legWorkInfos != null && legWorkInfos.size() > 0 ) {
//
// String tempSignIn = "";
// String tempSignOut = "";
// Map<String, Object> checkInfo = new HashMap<>();
// if ( legWorkInfos.size() == 1) {//只有一笔外勤卡直接算上班
//
// checkInfo.put("signType", "1");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", legWorkInfos.get(0));//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
//
//
// } else {
// for ( String signTime : legWorkInfos) {
// if (signTime.compareTo(workBeginTime) < 0) {//获取上班时间点之前最早的一笔卡
// if (StringUtils.isBlank(tempSignIn)) {
// tempSignIn = signTime;
// } else {
// if ( signTime.compareTo(tempSignIn) < 0 ) {
// tempSignIn = signTime;
// }
// }
// }
// if ( signTime.compareTo(workBeginTime) > 0) {//下班卡取最晚的一笔
// if (StringUtils.isBlank(tempSignOut)) {
// tempSignOut = signTime;
// } else {
// if ( signTime.compareTo(tempSignOut) > 0 ) {
// tempSignOut = signTime;
// }
// }
// }
// }
//
// if(StringUtils.isNotBlank(tempSignIn)) {
// checkInfo.put("signType", "1");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", tempSignIn);//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
// }
//
// if(StringUtils.isNotBlank(tempSignIn)) {
// checkInfo = new HashMap<>();
// checkInfo.put("signType", "2");
// checkInfo.put("signDate", kqDate);//签到签退日期
// checkInfo.put("signTime", tempSignOut);//签到签退时间
// checkInfo.put("deduct_signintime", "");//流程抵扣作为打卡时间
// checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode());
// lsCheckInfo.add(checkInfo);
// }
//
// }
// }
// }
// }
// bb.writeLog("lsCheckInfo: " + lsCheckInfo);
/*考勤二开--出差公出流程获取外勤打卡数据end*/
//writeLog(sql,userId +"=="+ signBeginDateTime+"=="+signEndDateTime);
return lsCheckInfo;
}
/**
*
* @param userId
* @param kqDate
* @param workBeginDateTime
* @param workEndDateTime
*/
public Map<String,String> getflowDeductCardSql(String userId, String kqDate, String workBeginDateTime, String workEndDateTime) {
Map<String,String> flow_deduct_card_map = new HashMap<>();
RecordSet rs = new RecordSet();
String flow_deduct_card_sql = "select * from kq_flow_deduct_card where 1=1 and (isclear is null or isclear<>1) ";
if(userId.length() > 0){
flow_deduct_card_sql += " and resourceid="+userId;
}
if(kqDate.length() > 0){
flow_deduct_card_sql += " and belongDate='"+kqDate+"'";
}
if(workBeginDateTime.length() > 0){
flow_deduct_card_sql += " and workBeginTime='"+workBeginDateTime+"'";
}
if(workEndDateTime.length() > 0){
flow_deduct_card_sql += " and workEndTime='"+workEndDateTime+"'";
}
rs.executeQuery(flow_deduct_card_sql);
while (rs.next()){
String signtype = rs.getString("signtype");
if("1".equalsIgnoreCase(signtype)){
flow_deduct_card_map.put("signin",workBeginDateTime);
}
if("2".equalsIgnoreCase(signtype)){
flow_deduct_card_map.put("signoff",workEndDateTime);
}
}
return flow_deduct_card_map;
}
/**
* sql
* @param signTimeScope
* @param kqDate
* @param preDate
* @param nextDate
* @param kqTimesArrayComInfo
* @return
*/
public List<Map<String,String>> getCanSignInfo(TimeScopeEntity signTimeScope, String kqDate, String preDate, String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo) {
return getCanSignInfo(signTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo,null);
}
public List<Map<String,String>> getCanSignInfo(TimeScopeEntity signTimeScope, String kqDate, String preDate, String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,TimeScopeEntity workTimeScope) {
return getCanSignInfo(signTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo,workTimeScope, 0, 0);
}
public List<Map<String,String>> getCanSignInfo(TimeScopeEntity signTimeScope, String kqDate, String preDate, String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,TimeScopeEntity workTimeScope, int shiftCount, int shiftI) {
List<Map<String,String>> sqlConditions = new ArrayList<>();
Map<String,String> conditionMap = new HashMap<>();
TimeSignScopeEntity timeSignScopeEntity = signTimeScope.getTimeSignScopeEntity();
String signBeginDateTime = "";
String signEndDateTime = "";
signBeginDateTime = signTimeScope.getBeginTimeAcross() ? nextDate : kqDate;
if(signTimeScope.isBeginTimePreAcross()){
signBeginDateTime = preDate;
}
signBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(signTimeScope.getBeginTime())+":00";
signEndDateTime = signTimeScope.getEndTimeAcross() ? nextDate : kqDate;
if (workTimeScope != null && workTimeScope.getEndTimeAcross() && signTimeScope.getEndTimeAcross() ) {
if(workTimeScope.getEndTime().compareTo(signTimeScope.getEndTime())>=0){
signEndDateTime = DateUtil.addDate(kqDate, 2);//下下一天日期;
}
}
signEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(signTimeScope.getEndTime())+":59";
if(timeSignScopeEntity == null){
//没有设置 签到最晚时间和签退最早时间
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signBeginDateTime);
conditionMap.put("signEndDateTime", signEndDateTime);
sqlConditions.add(conditionMap);
}else{
String beginTimeEnd = timeSignScopeEntity.getBeginTimeEnd();
boolean beginTimeEndAcross = timeSignScopeEntity.isBeginTimeEndAcross();
String endTimeStart = timeSignScopeEntity.getEndTimeStart();
boolean endTimeStartAcross = timeSignScopeEntity.isEndTimeStartAcross();
if(beginTimeEnd.length() > 0){
//如果设置了 上班结束时间
if(endTimeStart.length() > 0){
//设置了下班开始时间
String signBeginDateEndTime = "";
String signEndDateStartTime = "";
signBeginDateEndTime = beginTimeEndAcross ? nextDate : kqDate;
signBeginDateEndTime+=" "+kqTimesArrayComInfo.turn48to24Time(beginTimeEnd)+":59";
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signBeginDateTime);
conditionMap.put("signEndDateTime", signBeginDateEndTime);
conditionMap.put("type", "signin");
sqlConditions.add(conditionMap);
signEndDateStartTime = endTimeStartAcross ? nextDate : kqDate;
signEndDateStartTime+=" "+kqTimesArrayComInfo.turn48to24Time(endTimeStart)+":00";
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signEndDateStartTime);
conditionMap.put("signEndDateTime", signEndDateTime);
conditionMap.put("type", "signoff");
sqlConditions.add(conditionMap);
}else{
//没有设置下班开始时间
String signBeginDateEndTime = "";
String signEndDateStartTime = "";
signBeginDateEndTime = beginTimeEndAcross ? nextDate : kqDate;
signBeginDateEndTime+=" "+kqTimesArrayComInfo.turn48to24Time(beginTimeEnd)+":59";
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signBeginDateTime);
conditionMap.put("signEndDateTime", signBeginDateEndTime);
conditionMap.put("type", "signin");
sqlConditions.add(conditionMap);
//如果设置了上班结束时间,相当于下班开始时间也被限定了
String endTimeByBeginTime = kqTimesArrayComInfo.getTimesByArrayindex(kqTimesArrayComInfo.getArrayindexByTimes(beginTimeEnd)+1);
signEndDateStartTime = beginTimeEndAcross ? nextDate : kqDate;
signEndDateStartTime+=" "+kqTimesArrayComInfo.turn48to24Time(endTimeByBeginTime)+":00";
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signEndDateStartTime);
conditionMap.put("signEndDateTime", signEndDateTime);
conditionMap.put("type", "signoff");
sqlConditions.add(conditionMap);
}
}else if(endTimeStart.length() > 0){
//如果没有设置上班结束时间,设置了下班开始时间
String signBeginDateEndTime = "";
String signEndDateStartTime = "";
//如果设置了下班开始时间,相当于上班结束时间也被限定了
String BeginTimeByendTime = kqTimesArrayComInfo.getTimesByArrayindex(kqTimesArrayComInfo.getArrayindexByTimes(endTimeStart)-1);
signBeginDateEndTime = endTimeStartAcross ? nextDate : kqDate;
signBeginDateEndTime+=" "+kqTimesArrayComInfo.turn48to24Time(BeginTimeByendTime)+":59";
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signBeginDateTime);
conditionMap.put("signEndDateTime", signBeginDateEndTime);
conditionMap.put("type", "signin");
sqlConditions.add(conditionMap);
signEndDateStartTime = endTimeStartAcross ? nextDate : kqDate;
signEndDateStartTime+=" "+kqTimesArrayComInfo.turn48to24Time(endTimeStart)+":00";
conditionMap = new HashMap<>();
conditionMap.put("signBeginDateTime", signEndDateStartTime);
conditionMap.put("signEndDateTime", signEndDateTime);
conditionMap.put("type", "signoff");
sqlConditions.add(conditionMap);
}
}
return sqlConditions;
}
public String signSignSql(RecordSet rs){
String sql = "";
if(rs.getDBType().equals("oracle")){
sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate||' '||signtime >= ? and signdate||' '||signtime <= ? " +
" ";
}else if("sqlserver".equals(rs.getDBType())){
sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate + ' ' + signtime >= ? and signdate + ' ' + signtime <= ? " +
" ";
}else{
sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and concat(signdate,' ',signtime) >= ? and concat(signdate,' ',signtime) <= ? " +
" ";
}
return sql;
}
public List<Object> getSignInfoForAll(String userId, String signBeginDateTime, String signEndDateTime, String workBeginDateTime, String workEndDateTime) {
List<Object> lsCheckInfo = new ArrayList<>();
Map<String, Object> checkInfo = null;
String sql = "";
RecordSet rs = new RecordSet();
int idx = 0;
if(rs.getDBType().equals("oracle")){
sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate||' '||signtime >= ? and signdate||' '||signtime <= ? " +
" order by signdate asc, signtime asc ";
}else if("sqlserver".equals(rs.getDBType())){
sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate + ' ' + signtime >= ? and signdate + ' ' + signtime <= ? " +
" order by signdate asc, signtime asc ";
}else{
sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and concat(signdate,' ',signtime) >= ? and concat(signdate,' ',signtime) <= ? " +
" order by signdate asc, signtime asc ";
}
rs.executeQuery(sql, userId, signBeginDateTime, signEndDateTime);
//writeLog(sql,userId +"=="+ signBeginDateTime+"=="+signEndDateTime);
while (rs.next()) {
String signId = Util.null2String(rs.getString("id"));
String signdate = Util.null2String(rs.getString("signdate"));
String signtime = Util.null2String(rs.getString("signtime"));
checkInfo = new HashMap<>();
checkInfo.put("signId", signId);//签到签退标识
checkInfo.put("signDate", signdate);//签到签退日期
checkInfo.put("signTime", signtime);//签到签退时间
String signDateTime = signdate + " " + signtime;
idx++;
if(idx%2==1){
checkInfo.put("signType", "1");
}else{
checkInfo.put("signType", "2");
}
lsCheckInfo.add(checkInfo);
}
return lsCheckInfo;
}
public List<Object> getNonWorkSignInfo(String userId, String preDate, String kqDate,
List<TimeScopeEntity> pre_lsSignTime,
List<TimeScopeEntity> next_lsSignTime) {
List<Object> lsCheckInfo = new ArrayList<>();
Map<String, Object> checkInfo = null;
RecordSet rs = new RecordSet();
String pre_Worktime4Today = "";
if(!pre_lsSignTime.isEmpty()){
TimeScopeEntity pre_signTimeScope = pre_lsSignTime.get(pre_lsSignTime.size()-1);
if(pre_signTimeScope.getEndTimeAcross()){
pre_Worktime4Today = pre_signTimeScope.getEndTime();
}
}
String next_Worktime4Today = "";
if(!next_lsSignTime.isEmpty()){
TimeScopeEntity next_signTimeScope = next_lsSignTime.get(next_lsSignTime.size()-1);
if(next_signTimeScope.isBeginTimePreAcross()){
next_Worktime4Today = next_signTimeScope.getBeginTime();
}
}
String sql = "select * from hrmschedulesign where userid="+userId+" and signdate = '"+kqDate+"' ";
if(pre_Worktime4Today.length() > 0){
if(pre_Worktime4Today.length() == 5){
pre_Worktime4Today += ":59";
}
sql += " and signtime > '"+pre_Worktime4Today+"'";
}
if(next_Worktime4Today.length() > 0){
if(next_Worktime4Today.length() == 5){
next_Worktime4Today += ":00";
}
sql += " and signtime < '"+next_Worktime4Today+"'";
}
sql += " order by signdate asc,signtime asc ";
rs.executeQuery(sql);
int idx = 0;
while (rs.next()){
String signId = Util.null2String(rs.getString("id"));
String signdate = Util.null2String(rs.getString("signdate"));
String signtime = Util.null2String(rs.getString("signtime"));
checkInfo = new HashMap<>();
checkInfo.put("signId", signId);//签到签退标识
checkInfo.put("signDate", signdate);//签到签退日期
checkInfo.put("signTime", signtime);//签到签退时间
idx++;
if(idx==1){//第一条算签到
checkInfo.put("signType", "1");
lsCheckInfo.add(checkInfo);
}else if(idx==rs.getCounts()){//最后一条算签退
checkInfo.put("signType", "2");
lsCheckInfo.add(checkInfo);
}
}
return lsCheckInfo;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,548 @@
package com.engine.kq.biz;
import com.engine.kq.bean.KQHrmScheduleSign;
import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.util.KQSignUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 退
*/
public class KQScheduleSignBiz {
private KQLog kqLog = new KQLog();
private String resourceid;
private String userType;
private String signDate;
private String signTime;
private String worksection;
/**
*
*/
private String belongdate;
private String signtype;
private String signDateTimeSql;
/**
*
*/
private String signSectionTime;
/**
*
*/
private String signSectionEndTime;
/**
*
*/
private String signSectionBeginTime;
/**
*
*/
private String offSignSectionTime;
private int shiftCount;
private int shiftI;
private String count4NoonStartDateTime;
private String count4NoonEndDateTime;
private KQScheduleSignBiz(KQScheduleSignParamBuilder build){
this.resourceid = build.resourceid;
this.userType = build.userType;
this.signDate = build.signDate;
this.signTime = build.signTime;
this.belongdate = build.belongdate;
this.signtype = build.signtype;
this.worksection = build.worksection;
this.signDateTimeSql = build.signDateTimeSql;
this.signSectionTime = build.signSectionTime;
this.signSectionEndTime = build.signSectionEndTime;
this.signSectionBeginTime = build.signSectionBeginTime;
this.offSignSectionTime = build.offSignSectionTime;
this.shiftCount = build.shiftCount;
this.shiftI = build.shiftI;
this.count4NoonStartDateTime = build.count4NoonStartDateTime;
this.count4NoonEndDateTime = build.count4NoonEndDateTime;
}
/**
* 退
* @return
*/
public List<KQHrmScheduleSign> getFreeScheduleSignInfo() {
RecordSet rs = new RecordSet();
String signSql = "select * from hrmschedulesign where 1=1 and isInCom='1' ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
signSql += sqlWhere;
}
signSql += " order by signdate,signtime";
List<KQHrmScheduleSign> kqHrmScheduleSigns = new ArrayList<>();
try{
rs.execute(signSql);
while (rs.next()){
KQHrmScheduleSign kqHrmScheduleSign = getSignBean(rs);
kqHrmScheduleSigns.add(kqHrmScheduleSign);
}
}catch (Exception e){
e.printStackTrace();
}
return kqHrmScheduleSigns;
}
/**
*
* 退
* @return
*/
public Map<String,KQHrmScheduleSign> getScheduleSignInfoWithCardRange(){
String signSql = "";
Map<String,KQHrmScheduleSign> signMap = new HashMap<>();
RecordSet rs = new RecordSet();
String dbtype = rs.getDBType();
String baseSql = "select * from hrmschedulesign where 1=1 and isInCom='1' ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
baseSql += sqlWhere;
}
if(signSectionEndTime.length() == 0 && signSectionBeginTime.length() == 0){
//如果没设置上班后,下班前打卡
String signTimeSql = KQSignUtil.buildSignSql(signSectionTime,offSignSectionTime);
if(signTimeSql.length() > 0){
baseSql += " and "+signTimeSql;
}
if(baseSql.length() > 0){
signSql = baseSql;
signSql += " order by signdate,signtime";
kqLog.info("signSql:"+signSql);
try{
rs.execute(signSql);
while (rs.next()){
getScheduleSignBean(rs,signMap);
}
}catch (Exception e){
e.printStackTrace();
}
}
}else {
if(shiftCount == 4 && shiftI==2) {
String signSectionEndTime2 = count4NoonStartDateTime.substring(0, count4NoonStartDateTime.length() - 2) + "00";
String noonSignTimeSql = KQSignUtil.buildSignSql(signSectionEndTime2, count4NoonEndDateTime);
String sql = baseSql;
if (sqlWhere.length() > 0) {
sql += sqlWhere + " and " + noonSignTimeSql + " order by signdate, signtime";
}
rs.executeQuery(sql);
int count = 0;
while (rs.next()) {
if(count == 0) {
count ++;
continue;
}
// 午休时段如果有打卡的话,取第二次打卡算作下午第一次签到
KQHrmScheduleSign kqHrmScheduleSign = getSignBean(rs);
signMap.put("signin", kqHrmScheduleSign);
signMap.put("signinNoon", kqHrmScheduleSign);
if (count == 1) {
break;
}
}
}
String onSignTimeSql = "";
if(shiftCount == 4 && shiftI==2) {
onSignTimeSql = KQSignUtil.buildSignSql(count4NoonEndDateTime,signSectionEndTime);
} else {
onSignTimeSql = KQSignUtil.buildSignSql(signSectionTime,signSectionEndTime);
}
String offSignTimeSql = KQSignUtil.buildSignSql(signSectionBeginTime,offSignSectionTime);
String onSql = "";
String orderSql = "";
if(onSignTimeSql.length() > 0){
orderSql = " order by signdate asc, signtime asc ";
onSql += "select 'on' as belongtype,t.* from ("+baseSql+" and "+onSignTimeSql+") t";
if("oracle".equalsIgnoreCase(dbtype)){
onSql = "select * from ("+onSql+" "+orderSql+" ) a where rownum=1";
}else if("mysql".equalsIgnoreCase(dbtype)){
onSql = "select * from (select * from ("+onSql+" "+orderSql+" ) a limit 0,1) a ";
}
else if("postgresql".equalsIgnoreCase(dbtype)){
onSql = "select * from (select * from ("+onSql+" "+orderSql+" ) a limit 1 offset 0) a ";
}
else if("sqlserver".equalsIgnoreCase(dbtype)){
onSql = "select top 1 * from ("+onSql+" ) a "+" "+orderSql ;
}
}
String offSql = "";
if(offSignTimeSql.length() > 0){
orderSql = " order by signdate desc, signtime desc ";
offSql += "select 'off' as belongtype,t.* from ("+baseSql+" and "+offSignTimeSql+") t";
if("oracle".equalsIgnoreCase(dbtype)){
offSql = "select * from ("+offSql+" "+orderSql+" ) a where rownum=1";
}else if("mysql".equalsIgnoreCase(dbtype)){
offSql = "select * from (select * from ("+offSql+" "+orderSql+" ) a limit 0,1) a ";
}
else if("postgresql".equalsIgnoreCase(dbtype)){
offSql = "select * from (select * from ("+offSql+" "+orderSql+" ) a limit 1 offset 0) a ";
}
else if("sqlserver".equalsIgnoreCase(dbtype)){
offSql = "select top 1 * from ("+offSql+" ) a "+" "+orderSql ;
}
}
if(onSql.length() > 0 && offSql.length() > 0){
signSql = "select * from ("+onSql+" UNION ALL "+offSql+") s ";
kqLog.info("signSql:"+signSql);
try{
Map<String,KQHrmScheduleSign> checkMap = new HashMap<>();
rs.execute(signSql);
while (rs.next()){
getScheduleSignCardRangeBean(rs,signMap,checkMap);
}
}catch (Exception e){
e.printStackTrace();
}
}
if(shiftCount == 4 && shiftI==0) { // 一天4次卡的上午签退卡的统计
String signSectionEndTime2 = signSectionEndTime.substring(0, signSectionEndTime.length()-2)+"00";
String noonSignTimeSql = KQSignUtil.buildSignSql(signSectionEndTime2,offSignSectionTime);
String sql = baseSql;
if(sqlWhere.length() > 0){
sql += sqlWhere+" and "+noonSignTimeSql + " order by signdate, signtime";
}
rs.executeQuery(sql);
if (rs.next()) {
String signTime = rs.getString("signtime");
KQHrmScheduleSign kqHrmScheduleSignOut = signMap.get("signout");
String oldSignTime = kqHrmScheduleSignOut.getSigntime();
// 午休时段如果有打卡的话,取第一次打卡算作签退
if(signTime.compareTo(oldSignTime) < 0) {
kqHrmScheduleSignOut.setSigntime(signTime);
}
}
}
}
return signMap;
}
/**
* 退
* @param rs
* @param signMap
* @param checkMap
*/
public void getScheduleSignCardRangeBean(RecordSet rs, Map<String, KQHrmScheduleSign> signMap,
Map<String, KQHrmScheduleSign> checkMap){
String belongtype =Util.null2String(rs.getString("belongtype"));
if(shiftCount == 4 && shiftI==2) {
if(!signMap.isEmpty()) {
KQHrmScheduleSign kqHrmScheduleSignNoon = signMap.get("signinNoon");
KQHrmScheduleSign kqHrmScheduleSignOn = signMap.get("signin");
if(kqHrmScheduleSignNoon != null) {
if("on".equalsIgnoreCase(belongtype)) {
return;
} else {
KQHrmScheduleSign kqHrmScheduleSign = getSignBean(rs);
if(kqHrmScheduleSign != null && kqHrmScheduleSignOn.equals(kqHrmScheduleSign)) {
return;
}
signMap.put("signout",kqHrmScheduleSign);
return;
}
}
}
}
KQHrmScheduleSign kqHrmScheduleSign = getSignBean(rs);
if("on".equalsIgnoreCase(belongtype)){
if(!checkMap.containsKey("on")){
signMap.put("signin",kqHrmScheduleSign);
}
}else{
KQHrmScheduleSign kqHrmScheduleSignOn = signMap.get("signin");
if(kqHrmScheduleSignOn != null && kqHrmScheduleSign != null && kqHrmScheduleSignOn.equals(kqHrmScheduleSign)) {
return;
}
signMap.put("signout",kqHrmScheduleSign);
}
}
/**
* 退
* @param rs
* @param signMap
*/
public void getScheduleSignBean(RecordSet rs,Map<String,KQHrmScheduleSign> signMap){
KQHrmScheduleSign kqHrmScheduleSign = getSignBean(rs);
if(signMap.isEmpty()){
signMap.put("signin",kqHrmScheduleSign);
}else {
signMap.put("signout",kqHrmScheduleSign);
}
}
public KQHrmScheduleSign getSignBean(RecordSet rs){
BaseBean bb = new BaseBean();
KQHrmScheduleSign kqHrmScheduleSign = new KQHrmScheduleSign();
String id=Util.null2String(rs.getString("id"));
String userid=Util.null2String(rs.getString("userid"));
String usertype =Util.null2String(rs.getString("usertype"));
String signtype=Util.null2String(rs.getString("signtype"));
String signdate=Util.null2String(rs.getString("signdate"));
String signtime=Util.null2String(rs.getString("signtime"));
String clientaddress=Util.null2String(rs.getString("clientaddress"));
String signfrom=Util.null2String(rs.getString("signfrom"));
String longitude=Util.null2String(rs.getString("longitude"));
String latitude=Util.null2String(rs.getString("latitude"));
/*考勤二开--打卡地址改为办公地点start*/
// String addr=Util.null2String(rs.getString("addr"));
String addr=Util.null2String(rs.getString("showaddress"));
bb.writeLog("打卡地址: " + addr);
/*考勤二开--打卡地址改为办公地点end*/
String isincom=Util.null2String(rs.getString("isincom"));
String isimport=Util.null2String(rs.getString("isimport"));
String importsql=Util.null2String(rs.getString("importsql"));
String belongdate=Util.null2String(rs.getString("belongdate"));
String serialid=Util.null2String(rs.getString("serialid"));
String worksections=Util.null2String(rs.getString("worksection"));
String signstatus=Util.null2String(rs.getString("signstatus"));
kqHrmScheduleSign.setId(id);
kqHrmScheduleSign.setUserid(userid);
kqHrmScheduleSign.setUsertype(usertype);
kqHrmScheduleSign.setSigntype(signtype);
kqHrmScheduleSign.setSigndate(signdate);
kqHrmScheduleSign.setSigntime(signtime);
kqHrmScheduleSign.setClientaddress(clientaddress);
kqHrmScheduleSign.setSignfrom(signfrom);
kqHrmScheduleSign.setLongitude(longitude);
kqHrmScheduleSign.setLatitude(latitude);
kqHrmScheduleSign.setAddr(addr);
kqHrmScheduleSign.setIsincom(isincom);
kqHrmScheduleSign.setIsimport(isimport);
kqHrmScheduleSign.setImportsql(importsql);
kqHrmScheduleSign.setBelongdate(belongdate);
kqHrmScheduleSign.setSerialid(serialid);
kqHrmScheduleSign.setWorksections(worksections);
kqHrmScheduleSign.setSignstatus(signstatus);
return kqHrmScheduleSign;
}
/**
*
* @return
*/
public Map<String,KQHrmScheduleSign> getScheduleSignInfo(){
RecordSet rs = new RecordSet();
String signSql = "select * from hrmschedulesign where 1=1 and isInCom='1' ";
String sqlWhere = sqlParamWhere();
if(sqlWhere.length() > 0){
signSql += sqlWhere;
}
signSql += " order by signdate,signtime";
Map<String,KQHrmScheduleSign> signMap = new HashMap<>();
try{
kqLog.info("signSql:"+signSql);
rs.execute(signSql);
while (rs.next()){
getScheduleSignBean(rs,signMap);
}
}catch (Exception e){
e.printStackTrace();
}
return signMap;
}
/**
*
* @return
*/
private String sqlParamWhere() {
String sqlWhere = "";
if(resourceid.length() > 0){
sqlWhere += " and userid in ( "+resourceid+" )";
}
if(signDate.length() > 0){
sqlWhere += " and signDate = '"+signDate+"' ";
}
if(signTime.length() > 0){
sqlWhere += " and signTime = '"+signTime+"' ";
}
if(signDateTimeSql.length() > 0){
sqlWhere += " and "+signDateTimeSql;
}
if(belongdate.length() > 0){
sqlWhere += " and belongdate = '"+belongdate+"' ";
}
if(signtype.length() > 0){
sqlWhere += " and signtype = '"+signtype+"' ";
}
//不需要userType没啥用
// if(userType.length() > 0){
// sqlWhere += " and userType = '"+userType+"' ";
// }
if(worksection.length() > 0){
sqlWhere += " and worksection = '"+worksection+"' ";
}
return sqlWhere;
}
public static class KQScheduleSignParamBuilder{
private String resourceid;
private String userType;
private String signDate;
private String signTime;
private String belongdate;
private String signtype;
private String worksection;
private int shiftCount;
private int shiftI;
private String count4NoonStartDateTime;
private String count4NoonEndDateTime;
/**
* sql
*/
private String signDateTimeSql;
/**
*
*/
private String signSectionTime;
/**
*
*/
private String signSectionEndTime;
/**
*
*/
private String signSectionBeginTime;
/**
*
*/
private String offSignSectionTime;
public KQScheduleSignParamBuilder() {
this.resourceid = resourceid;
//初始化的时候需要把其他参数先清空下
this.userType = "";
this.signDate = "";
this.signTime = "";
this.belongdate = "";
this.signtype = "";
this.worksection = "";
this.signDateTimeSql = "";
this.signSectionTime = "";
this.signSectionEndTime = "";
this.signSectionBeginTime = "";
this.offSignSectionTime = "";
this.shiftCount = 0;
this.shiftI = 0;
this.count4NoonStartDateTime = "";
this.count4NoonEndDateTime = "";
}
//成员方法返回其自身,所以可以链式调用
public KQScheduleSignParamBuilder resourceidParam(final String resourceid) {
this.resourceid = resourceid;
return this;
}
public KQScheduleSignParamBuilder userTypeParam(final String userType) {
this.userType = userType;
return this;
}
public KQScheduleSignParamBuilder shiftCountParam(final int shiftCount) {
this.shiftCount = shiftCount;
return this;
}
public KQScheduleSignParamBuilder count4NoonStartDateTimeParam(final String count4NoonStartDateTime) {
this.count4NoonStartDateTime = count4NoonStartDateTime;
return this;
}
public KQScheduleSignParamBuilder count4NoonEndDateTimeParam(final String count4NoonEndDateTime) {
this.count4NoonEndDateTime = count4NoonEndDateTime;
return this;
}
public KQScheduleSignParamBuilder shiftIParam(final int shiftI) {
this.shiftI = shiftI;
return this;
}
public KQScheduleSignParamBuilder signDateParam(final String signDate) {
this.signDate = signDate;
return this;
}
public KQScheduleSignParamBuilder signTimeParam(final String signTime) {
this.signTime = signTime;
return this;
}
public KQScheduleSignParamBuilder belongDateParam(final String belongdate) {
this.belongdate = belongdate;
return this;
}
public KQScheduleSignParamBuilder signtypeParam(final String signtype) {
this.signtype = signtype;
return this;
}
public KQScheduleSignParamBuilder worksectionParam(final String worksection) {
this.worksection = worksection;
return this;
}
public KQScheduleSignParamBuilder signDateTimeSqlParam(final String signDateTimeSql) {
this.signDateTimeSql = signDateTimeSql;
return this;
}
public KQScheduleSignParamBuilder signSectionTimeParam(final String signSectionTime) {
this.signSectionTime = signSectionTime;
return this;
}
public KQScheduleSignParamBuilder signSectionEndTimeParam(final String signSectionEndTime) {
this.signSectionEndTime = signSectionEndTime;
return this;
}
public KQScheduleSignParamBuilder signSectionBeginTimeParam(final String signSectionBeginTime) {
this.signSectionBeginTime = signSectionBeginTime;
return this;
}
public KQScheduleSignParamBuilder offSignSectionTimeParam(final String offSignSectionTime) {
this.offSignSectionTime = offSignSectionTime;
return this;
}
//Builder的build方法返回外部类的实例
public KQScheduleSignBiz build() {
return new KQScheduleSignBiz(this);
}
}
}

@ -0,0 +1,672 @@
package com.engine.kq.cmd.attendanceButton;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudstore.dev.api.util.EMManager;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.hostar.util.HostarUtil;
import com.engine.kq.biz.*;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.entity.KQGroupEntity;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.timer.KQQueue;
import com.engine.kq.timer.KQTaskBean;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.wfset.util.SplitActionUtil;
import com.google.common.collect.Maps;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.dateformat.DateTransformer;
import weaver.dateformat.TimeZoneVar;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
/**
* 退
*/
public class PunchButtonCmd extends AbstractCommonCommand<Map<String, Object>> {
public KQLog kqLog = new KQLog();
private HttpServletRequest request;
private Map<String,Object> logMap = Maps.newHashMap();
private Map<String,Object> workTimeEntityLogMap = Maps.newHashMap();
private final List<String> LIST = new ArrayList<>();
public PunchButtonCmd(HttpServletRequest request,Map<String, Object> params, User user) {
this.request = request;
this.user = user;
this.params = params;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
try{
insertSign(retmap);
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
kqLog.info(user.getLastname()+":PunchButtonCmd:retmap:"+retmap);
KQCardLogBiz.logCardInfo(user.getUID()+"", logMap, workTimeEntityLogMap, "punchButton");
return retmap;
}
/**
* ip
* @param ismobile
*/
private boolean checkIsInIp(String ismobile) {
// if("1".equalsIgnoreCase(ismobile)){
// return true;
// }
KQGroupBiz kqGroupBiz = new KQGroupBiz();
String clientAddress = Util.getIpAddr(request);
kqLog.info("PunchButtonCmd:clientAddress:"+clientAddress);
return kqGroupBiz.getIsInScopeV4V6(user.getUID()+"", clientAddress,ismobile);
}
public void insertSign(Map<String, Object> retmap) throws Exception{
logMap.put("lastname", user.getLastname());
logMap.put("params", params);
kqLog.info(user.getLastname()+":PunchButtonCmd:params:"+params);
RecordSet rs = new RecordSet();
String deviceInfo = Util.null2String(params.get("deviceInfo"));
JSONObject jsonObject = null;
if(deviceInfo.length() > 0){
jsonObject = JSON.parseObject(deviceInfo);
JSONObject jsonObject1 = new JSONObject();
Set<Entry<String, Object>> jsonSet = jsonObject.entrySet();
for(Entry<String, Object> js : jsonSet){
String key = js.getKey();
String value = Util.null2String(js.getValue());
jsonObject1.put(key, value);
}
if(!jsonObject1.isEmpty()){
deviceInfo = jsonObject1.toJSONString();
}
}
//应上班 工作时间点
String time = Util.null2String(params.get("time"));
//应上班 工作时间 带日期
String datetime = Util.null2String(params.get("datetime"));
//允许打卡时段 带日期
String signSectionTime = Util.null2String(params.get("signSectionTime"));
//上传照片
String attachment = Util.null2String(params.get("fileids"));
//打卡所属worksection的对应的点
String type = Util.null2String(params.get("type"));
//所属打卡日期
String belongdate = Util.null2String(params.get("belongdate"));
belongdate = belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate;
String islastsign = Util.null2String(params.get("islastsign"));
String isfirstsign = Util.null2String(params.get("isfirstsign"));
String workmins = Util.null2String(params.get("workmins"));
//针对非工作时段 签退的时候记录的签到数据 用于计算加班
String signInTime4Out = Util.null2String(params.get("signInTime4Out"));
//允许打卡的范围
String signsection = Util.null2String(params.get("signSection"));
//手机打卡部分
String longitude = Util.null2String(params.get("longitude"));
String latitude = Util.null2String(params.get("latitude"));
double d_longitude = Util.getDoubleValue(longitude);
double d_latitude = Util.getDoubleValue(latitude);
if(d_latitude <= 0){
latitude = "";
}
if(d_longitude <= 0){
longitude = "";
}
//wifi用的
String mac = Util.null2String(params.get("mac"));
String sid = Util.null2String(params.get("sid"));
String addr = Util.null2String(params.get("position"));
String ismobile = Util.null2String(params.get("ismobile"));
//区分是来自于钉钉还是EM7
String browser = Util.null2String(params.get("browser"));
//自由班制处理
String isfree = Util.null2String(Util.null2String(params.get("isfree")),"0");
//上班打卡 允许最晚打卡时间
String signSectionEndTime = Util.null2String(params.get("signSectionEndTime"));
//下班打卡 允许最早打卡时间
String signSectionBeginTime = Util.null2String(params.get("signSectionBeginTime"));
String locationshowaddress = Util.null2String(params.get("locationshowaddress"));
if(locationshowaddress.equals("1")){//记录统一地址
String locationid = Util.null2String(params.get("locationid"));//办公地点id
if(locationid.length()>0){//如果开启统一显示,就用配置的地址
KQLoactionComInfo kqLoactionComInfo = new KQLoactionComInfo();
addr = kqLoactionComInfo.getLocationname(locationid);
}
}
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime localTime = LocalTime.now();
String signTime =localTime.format(dateTimeFormatter);
String signDate = LocalDate.now().format(dateFormatter);
String timeZone = Util.null2String(TimeZoneVar.getTimeZone(),"");
//处理多时区
String timeZoneConversion = Util.null2String(new weaver.general.BaseBean().getPropValue("weaver_timezone_conversion","timeZoneConversion")).trim();
logMap.put("timeZoneConversion", timeZoneConversion);
if("1".equals(timeZoneConversion)) {
DateTransformer dateTransformer=new DateTransformer();
String[] zone_localTime = dateTransformer.getLocaleDateAndTime(signDate,signTime);
kqLog.info(user.getLastname()+":TimeZoneVar.getTimeZone():"+TimeZoneVar.getTimeZone()+":zone_localTime:"+JSON.toJSONString(zone_localTime));
if(zone_localTime != null && zone_localTime.length == 2){
signDate = zone_localTime[0];
signTime = zone_localTime[1];
}
}
int userId = user.getUID();
String userType = user.getLogintype();
String signType = "on".equalsIgnoreCase(type) ? "1" : "2";
String clientAddress = Util.getIpAddr(request);
boolean isInIp = checkIsInIp(ismobile);
logMap.put("clientAddress", clientAddress);
if(!isInIp){
retmap.put("message", SystemEnv.getHtmlLabelName(20157,user.getLanguage()));
retmap.put("isInIp", "0");
}
String isInCom = isInIp ? "1" : "0";
//是否是考勤例外人员
boolean isExclude = false;
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
KQWorkTime kqWorkTime = new KQWorkTime();
WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(user.getUID()+"", signDate);
String userinfo = "#userid#"+user.getUID()+"#getUserSubCompany1#"+user.getUserSubCompany1()+"#getUserSubCompany1#"+user.getUserDepartment()
+"#getJobtitle#"+user.getJobtitle();
workTimeEntityLogMap.put("resourceid", userinfo);
workTimeEntityLogMap.put("splitDate", signDate);
workTimeEntityLogMap.put("workTimeEntity", workTimeEntity);
String groupid = workTimeEntity.getGroupId();
logMap.put("groupid", groupid);
KQGroupEntity kqGroupEntity = kqGroupMemberComInfo.getUserKQGroupInfo(user.getUID()+"");
String kqGroupEntityInfo = kqGroupEntity != null ? JSON.toJSONString(kqGroupEntity): "";
logMap.put("kqGroupEntityInfo", kqGroupEntityInfo);
if (kqGroupEntity != null && ("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + user.getUID() + ",")>-1) {//排除人员无需计算考勤时间
isExclude = true;
}
String[] signsections = signsection.split("#");
if(!"1".equalsIgnoreCase(isfree)){
if(signsections != null && signsections.length == 2){
//判断是未签到直接签退
String signedMsg = signedMsg(userId+"", signType, user,signsections,signSectionBeginTime,signSectionEndTime);
if(signedMsg.length() > 0){
retmap.put("status", "1");
retmap.put("message", signedMsg);
isInCom = "0";
}
}
}
String datetime_timezone = signDate+" "+signTime;
LocalDateTime nowDateTime = LocalDateTime.parse(datetime_timezone,fullFormatter);
kqLog.info("timeZone:"+timeZone+":signDate:"+signDate+":signTime:"+signTime+":nowDateTime:"+nowDateTime);
if("1".equalsIgnoreCase(signType) && signSectionTime.length() > 0 ){
LocalDateTime startWorkDateTime = LocalDateTime.parse(signSectionTime,fullFormatter);
if(nowDateTime.isBefore(startWorkDateTime)){
Duration duration = Duration.between(nowDateTime, startWorkDateTime);
retmap.put("status", "1");
retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005326,weaver.general.ThreadVarLanguage.getLang())+""+duration.toMinutes()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(15049,weaver.general.ThreadVarLanguage.getLang())+"");
isInCom = "0";
}
}else if("2".equalsIgnoreCase(signType) && signSectionTime.length() > 0 ){
LocalDateTime endWorkDateTime = LocalDateTime.parse(signSectionTime,fullFormatter);
if(nowDateTime.isAfter(endWorkDateTime)){
Duration duration = Duration.between(endWorkDateTime, nowDateTime);
retmap.put("status", "1");
retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005327,weaver.general.ThreadVarLanguage.getLang())+""+duration.toMinutes()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(15049,weaver.general.ThreadVarLanguage.getLang())+"");
isInCom = "0";
}
}
//记录下是来自于E9的pc端签到
String signfrom = "e9pc";
if("1".equalsIgnoreCase(ismobile)){
signfrom = "e9mobile";
boolean needLocationRange = false;
boolean needWifiRange = false;
boolean isLocationRange = false;
boolean isWifiRange = false;
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String,Object> locationMap = kqGroupBiz.checkLocationScope(userId+"",longitude,latitude);
logMap.put("locationMap", locationMap);
String locationNeedCheck = Util.null2String(locationMap.get("needCheck"));
boolean locationInScope = Boolean.parseBoolean(Util.null2String(locationMap.get("inScope")));
if("1".equalsIgnoreCase(locationNeedCheck)){
needLocationRange = true;
if(locationInScope){
isLocationRange = true;
}
}
String wifiNeedCheck = "";
Map<String,Object> wifiMap = kqGroupBiz.checkWifiScope(userId+"", sid, mac);
logMap.put("wifiMap", wifiMap);
wifiNeedCheck = Util.null2String(wifiMap.get("needCheck"));
boolean wifiInScope = Boolean.parseBoolean(Util.null2String(wifiMap.get("inScope")));
if("1".equalsIgnoreCase(wifiNeedCheck)){
needWifiRange = true;
if(wifiInScope){
isWifiRange = true;
}
}
if(needLocationRange){
if(isLocationRange){
}else{
if(needWifiRange){
if(isWifiRange){
}else{
//地理位置开启而且不在范围内且开启wifi验证,不在范围内
retmap.put("message", SystemEnv.getHtmlLabelName(507524, user.getLanguage()));
isInCom = "0";
}
}else {
//地理位置开启而且不在范围内且未开启wifi验证
retmap.put("message", SystemEnv.getHtmlLabelName(500510, user.getLanguage()));
isInCom = "0";
}
}
}else{
if(needWifiRange) {
if (isWifiRange) {
} else {
//地理位置未开启且开启wifi验证,不在范围内
retmap.put("message", SystemEnv.getHtmlLabelName(507524, user.getLanguage()));
isInCom = "0";
}
}
}
if("DingTalk".equalsIgnoreCase(browser)){
signfrom = "DingTalk";
}else if("Wechat".equalsIgnoreCase(browser)){
signfrom = "Wechat";
String weChat_deviceid = Util.null2String(request.getSession().getAttribute(EMManager.DeviceId));
logMap.put("weChat_deviceid", weChat_deviceid);
kqLog.info("EMManager.DeviceId:"+EMManager.DeviceId+":weChat_deviceid:"+weChat_deviceid);
if(weChat_deviceid.length() > 0){
//微信打卡的设备号需要单独处理
if(jsonObject != null){
jsonObject.put("deviceId", weChat_deviceid);
}else{
jsonObject = new JSONObject();
jsonObject.put("deviceId", weChat_deviceid);
}
if(!jsonObject.isEmpty()){
deviceInfo = jsonObject.toJSONString();
}
}
}
}
String signStatus = "";
if(!"1".equalsIgnoreCase(isfree) && datetime.length() > 0){
signStatus = getSignStatus(signType,datetime,user.getUID()+"",belongdate,nowDateTime);
logMap.put("signStatus", signStatus);
}
if(isExclude){
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
String punchSql = "insert into HrmScheduleSign(userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo) "+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
boolean isOk = rs.executeUpdate(punchSql,userId,userType,signType,signDate,signTime,clientAddress,isInCom,
timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo);
if(!isOk){
retmap.put("status", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
return ;
}
logMap.put("punchSql", punchSql);
logMap.put("punchSql_isOk", isOk);
kqLog.info(user.getLastname()+":PunchButtonCmd:punchSql:"+punchSql+":isOk:"+isOk);
//打卡提醒处理
String remindSql = "insert into hrmschedulesign_remind(userId,signType,signDate,signTime,belongdate) values(?,?,?,?,?)";
isOk = rs.executeUpdate(remindSql, userId,signType,signDate,signTime,belongdate);
kqLog.info(user.getLastname()+":PunchButtonCmd:remindSql:"+remindSql+":isOk:"+isOk);
//增加自动排班
kqLog.info("PunchButtonCmd.format in >>>>>userId" + userId + "kqDate==" + signDate+"format.groupId:"+groupid+"format.serialId:"+workTimeEntity.getSerialId());
//责任制考勤组id收集
rs.executeQuery("select kqzid from uf_zrzkqz");
while (rs.next()){
LIST.add(Util.null2String(rs.getString("kqzid")));
}
kqLog.info("PunchButtonCmd.LIST"+LIST);
if(LIST.contains(groupid)) {
RecordSet rt = new RecordSet();
BaseBean bb = new BaseBean();
//休息日或节假日给休息班次
//int changeType = KQOvertimeRulesBiz.getChangeType(Util.null2String(userId), signDate);
String fixedSerialid = Util.null2String(bb.getPropValue("project_hostar", "fixedSerialid"));
String weekendDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "weekendDefaultSerialid"));
String holidayDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "holidayDefaultSerialid"));
String fixedUserId = "";
//查询指定和考勤组成员
String query_sql = "select distinct typevalue from kq_groupmember where groupid = ? ";
rs.executeQuery(query_sql, fixedSerialid);
if (rs.next()) {
fixedUserId = rs.getString("typevalue");
}
boolean holiday = KQHolidaySetBiz.isHoliday(fixedUserId, signDate, true);
kqLog.info("format.holiday:" + holiday);
//String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)";
String sql = "update kq_shiftschedule set serialid = ? where resourceid = ? and kqdate= ? and groupid = ? and isdelete = 0 ";
//考勤当天是节假日或者休息日
if (holiday) {
//节假日休息班
boolean b = rt.executeUpdate(sql, holidayDefaultSerialid, Util.null2String(userId), signDate, groupid);
kqLog.info("PunchButtonCmd.b1:" + b);
} else {
//周末休息班
// if (DateUtil.getWeek(signDate) == 6 || DateUtil.getWeek(signDate) == 7) {
// boolean b = rt.executeUpdate(sql, weekendDefaultSerialid, Util.null2String(userId), signDate, groupid);
// kqLog.info("PunchButtonCmd.b1:" + b);
// } else {
String dybc = "";
//正常打卡,排对应打卡地点对应班次
//2.查询指定打卡地点的经纬度及范围的list
List<Map<String, String>> list2 = new ArrayList<>();
//2.1查询出打卡地点经纬度建模list
String sql2 = "select jd,wd,bj,dybc from uf_jwdbj";
rt.execute(sql2);
while (rt.next()) {
Map<String, String> map = new HashMap<>();
map.put("jd", Util.null2String(rt.getString("jd")));
map.put("wd", Util.null2String(rt.getString("wd")));
map.put("bj", Util.null2String(rt.getString("bj")));
map.put("dybc", Util.null2String(rt.getString("dybc")));
list2.add(map);
}
kqLog.info("PunchButtonCmd.list2:" + list2);
for (Map<String, String> map : list2) {
Double distance = new HostarUtil().calculateDistance(d_latitude, d_longitude, Util.getDoubleValue(map.get("wd")), Util.getDoubleValue(map.get("jd")));
if (distance <= Util.getDoubleValue(map.get("bj"))) {
dybc = map.get("dybc");
}
}
kqLog.info("PunchButtonCmd.dybc:" + dybc);
//设置考勤班次为对应班次
if (StringUtils.isNotBlank(dybc)) {
boolean b = rt.executeUpdate(sql, dybc, Util.null2String(userId), signDate, groupid);
kqLog.info("PunchButtonCmd.b2:" + b);
}
// }
}
}
//同步更新考勤数据到考勤报表
new KQFormatBiz().formatDate(""+userId,(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
//点击签退的时候,可能存在加班数据生成的情况
if("2".equalsIgnoreCase(signType)){
if("1".equalsIgnoreCase(islastsign)){
List<KQTaskBean> tasks = new ArrayList<>();
List<KQTaskBean> after_tasks = new ArrayList<>();
SplitActionUtil.pushOverTimeTasks(belongdate, belongdate, ""+userId,tasks);
if(!tasks.isEmpty()){
for(KQTaskBean kqTaskBean : tasks){
after_tasks.add(kqTaskBean);
}
}
logMap.put("after_tasks", after_tasks);
if(!after_tasks.isEmpty()){
KQQueue.writeTasks(after_tasks);
}
}
}
if("1".equalsIgnoreCase(signType)){
if("1".equalsIgnoreCase(isfirstsign)){
List<KQTaskBean> tasks = new ArrayList<>();
List<KQTaskBean> before_tasks = new ArrayList<>();
SplitActionUtil.pushOverTimeTasks(belongdate, belongdate, ""+userId,tasks);
if(!tasks.isEmpty()){
for(KQTaskBean kqTaskBean : tasks){
kqTaskBean.setTasktype("punchcard");
before_tasks.add(kqTaskBean);
}
}
logMap.put("before_tasks", before_tasks);
if(!before_tasks.isEmpty()){
KQQueue.writeTasks(before_tasks);
}
}
}
String reSignStatus = reSignStatus(user.getUID()+"",signType,nowDateTime,belongdate);
if(Util.null2String(reSignStatus,"").length() > 0){
signStatus = reSignStatus;
}
retmap.put("status", "1");
retmap.put("signdate", signDate);
retmap.put("signtime", signTime);
retmap.put("kqstatus", signStatus);
if(!"1".equalsIgnoreCase(signStatus) && !"2".equalsIgnoreCase(signStatus)){
if("".equalsIgnoreCase(Util.null2String(retmap.get("message")))){
retmap.put("success", "1");
retmap.put("message", SystemEnv.getHtmlLabelName(512596,weaver.general.Util.getIntValue(user.getLanguage())));
}
}
logMap.put("retmap", retmap);
}
public String reSignStatus(String userid, String signType, LocalDateTime nowDateTime,
String workdate) {
String signStatus = "";
String shift_begindateworktime = "";
String shift_enddateworktime = "";
ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(userid, workdate,false);
if(shiftInfoBean == null){
return signStatus;
}
Map<String,String> shifRuleMap = Maps.newHashMap();
KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean,userid,shifRuleMap);
KQTimesArrayComInfo arrayComInfo = new KQTimesArrayComInfo();
if(!shifRuleMap.isEmpty()) {
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String datetime = "";
if (shifRuleMap.containsKey("shift_beginworktime")) {
String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime"));
if (shift_beginworktime.length() > 0) {
int shift_beginworktime_index = -1;
shift_beginworktime_index = arrayComInfo.getArrayindexByTimes(shift_beginworktime);
datetime = workdate+" "+shift_beginworktime+":00";
if(shift_beginworktime_index >= 1440){
//跨天了
datetime = DateUtil.addDate(workdate, 1)+" "+arrayComInfo.turn48to24Time(shift_beginworktime)+":00";
}
}
}
if (shifRuleMap.containsKey("shift_endworktime")) {
String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime"));
if (shift_endworktime.length() > 0) {
int shift_endworktime_index = -1;
shift_endworktime_index = arrayComInfo.getArrayindexByTimes(shift_endworktime);
datetime = workdate+" "+shift_endworktime+":00";
if(shift_endworktime_index >= 1440) {
//跨天了
datetime = DateUtil.addDate(workdate, 1)+" "+arrayComInfo.turn48to24Time(shift_endworktime)+":00";
}
}
}
if (datetime.length() > 0) {
if("1".equalsIgnoreCase(signType)) {
LocalDateTime startWorkDateTime = LocalDateTime.parse(datetime, fullFormatter);
//打卡时间比上班时间晚,迟到了
if (nowDateTime.isAfter(startWorkDateTime)) {
signStatus = ButtonStatusEnum.BELATE.getStatusCode();
} else {
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
} else if ("2".equalsIgnoreCase(signType)) {
LocalDateTime endWorkDateTime = LocalDateTime.parse(datetime, fullFormatter);
//签退的话
if (nowDateTime.isBefore(endWorkDateTime)) {
signStatus = ButtonStatusEnum.LEAVEERALY.getStatusCode();
} else {
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
} else {
writeLog(user.getLastname() + nowDateTime + ":竟然没有传:" + signType);
return "";
}
}
}
return signStatus;
}
/**
*
* @param resourceid
* @param pre_splitDate
* @param signtime
* @param pre_bengintime
* @param signdate
*/
public void doBeforeAcrossOvertime(String resourceid,String pre_splitDate,String signtime,String pre_bengintime,String signdate) {
KQTaskBean kqTaskBean = new KQTaskBean();
kqTaskBean.setResourceId(resourceid);
kqTaskBean.setTaskDate(pre_splitDate);
kqTaskBean.setLastWorkTime(signtime);
if(pre_bengintime.length() == 5){
kqTaskBean.setTaskSignTime(pre_bengintime+":00");
}else{
kqTaskBean.setTaskSignTime(pre_bengintime);
}
kqTaskBean.setSignDate(signdate);
kqTaskBean.setSignEndDate(signdate);
kqTaskBean.setTimesource("before");
KQQueue.writeTask(kqTaskBean);
}
/**
*
* @param userid
* @param signtype
* @param curUser
* @param signsections
* @param signSectionBeginTime
* @param signSectionEndTime
* @return
*/
public String signedMsg(String userid, String signtype, User curUser, String[] signsections,
String signSectionBeginTime, String signSectionEndTime) throws Exception{
String signedMsg = "";
RecordSet rs = new RecordSet();
boolean hasSigned = false;
String onSignSectionTime = signsections[0];
String offSignSectionTime = signsections[1];
if(onSignSectionTime.length() > 0 && offSignSectionTime.length() > 0){
String hasSign = "select 1 from hrmschedulesign where 1 = 1 and isInCom = '1' and userid = ? ";
StringBuffer sql = new StringBuffer();
if(rs.getDBType().equals("oracle")||rs.getDBType().equals("postgresql")){
sql.append(" AND signDate||' '||signTime>=? ");
sql.append(" AND signDate||' '||signTime<=? ");
}else if(rs.getDBType().equals("mysql")){
sql.append(" AND concat(signDate,' ',signTime)>=? ");
sql.append(" AND concat(signDate,' ',signTime)<=? ");
}else{
sql.append(" AND signDate+' '+signTime>=? ");
sql.append(" AND signDate+' '+signTime<=? ");
}
hasSign += sql.toString();
rs.executeQuery(hasSign, userid,onSignSectionTime,offSignSectionTime);
if(rs.next()){
hasSigned = true;
}
if("1".equalsIgnoreCase(signtype)){
if(signSectionBeginTime.length() > 0 || signSectionEndTime.length() > 0){
}else{
if(hasSigned){
signedMsg = SystemEnv.getHtmlLabelName(129706, curUser.getLanguage());
}
}
}else if("2".equalsIgnoreCase(signtype)){
if(signSectionBeginTime.length() > 0 || signSectionEndTime.length() > 0){
}else{
if(!hasSigned){
signedMsg = SystemEnv.getHtmlLabelName(501301, curUser.getLanguage());
}
}
}
}
return signedMsg;
}
/**
* 退
* 退
* @return
*/
public String getSignStatus(String signType, String datetime, String userid, String workdate,
LocalDateTime nowDateTime) {
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String signStatus = "";
//签到的话
if("1".equalsIgnoreCase(signType)){
LocalDateTime startWorkDateTime = LocalDateTime.parse(datetime,fullFormatter);
//打卡时间比上班时间晚,迟到了
if(nowDateTime.isAfter(startWorkDateTime)){
signStatus = ButtonStatusEnum.BELATE.getStatusCode();
}else{
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
}else if("2".equalsIgnoreCase(signType)){
LocalDateTime endWorkDateTime = LocalDateTime.parse(datetime,fullFormatter);
//签退的话
if(nowDateTime.isBefore(endWorkDateTime)){
signStatus = ButtonStatusEnum.LEAVEERALY.getStatusCode();
}else{
signStatus = ButtonStatusEnum.NORMAL.getStatusCode();
}
}else{
writeLog(user.getLastname()+nowDateTime+":竟然没有传:"+signType);
return "";
}
return signStatus;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,501 @@
package com.engine.kq.cmd.attendanceButton;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudstore.dev.api.util.EMManager;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.hostar.util.HostarUtil;
import com.engine.kq.biz.*;
import com.engine.kq.entity.KQGroupEntity;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.util.SplitActionUtil;
import com.google.common.collect.Maps;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.dateformat.DateTransformer;
import weaver.dateformat.TimeZoneVar;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map.Entry;
/**
* 退
*/
public class PunchOutButtonCmd extends AbstractCommonCommand<Map<String, Object>> {
private HttpServletRequest request;
public KQLog kqLog = new KQLog();
BaseBean bb = new BaseBean();
private Map<String,Object> logMap = Maps.newHashMap();
private Map<String,Object> workTimeEntityLogMap = Maps.newHashMap();
private final List<String> LIST = new ArrayList<>();
public PunchOutButtonCmd(HttpServletRequest request, Map<String, Object> params, User user) {
this.request = request;
this.user = user;
this.params = params;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
try{
insertSign(retmap);
}catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
writeLog(e);
}
KQCardLogBiz.logCardInfo(user.getUID()+"", logMap, workTimeEntityLogMap, "punchOutButton");
return retmap;
}
/**
* ip
*/
private boolean checkIsInIp() {
KQGroupBiz kqGroupBiz = new KQGroupBiz();
String clientAddress = Util.getIpAddr(request);
return kqGroupBiz.getIsInScope(user.getUID()+"", clientAddress);
}
private void insertSign(Map<String, Object> retmap) {
logMap.put("lastname", user.getLastname());
logMap.put("params", params);
// signSection: 2019-03-20 08:30#2019-03-20 18:30
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
String serialid = Util.null2String(params.get("serialid"));
//应上班 工作时间点
String time = Util.null2String(params.get("time"));
//应上班 工作时间 带日期
String datetime = Util.null2String(params.get("datetime"));
//允许打卡时段 带日期
String signSectionTime = Util.null2String(params.get("signSectionTime"));
//打卡所属worksection的对应的点
String type = Util.null2String(params.get("type"));
//所属打卡日期
String belongdate = Util.null2String(params.get("belongdate"));
boolean belongdateIsNull = belongdate.length()==0;
String islastsign = Util.null2String(params.get("islastsign"));
String isPunchOpen = Util.null2String(params.get("isPunchOpen"));
String workmins = Util.null2String(params.get("workmins"));
//针对非工作时段 签退的时候记录的签到数据 用于计算加班
String signInTime4Out = Util.null2String(params.get("signInTime4Out"));
//允许打卡的范围
String signsection = Util.null2String(params.get("signSection"));
//手机打卡部分
String longitude = Util.null2String(params.get("longitude"));
String latitude = Util.null2String(params.get("latitude"));
double d_longitude = Util.getDoubleValue(longitude);
double d_latitude = Util.getDoubleValue(latitude);
if(d_latitude <= 0){
latitude = "";
}
if(d_longitude <= 0){
longitude = "";
}
String address = Util.null2String(params.get("address"));
String ismobile = Util.null2String(params.get("ismobile"));
String remark = Util.null2String(params.get("remark"));
String attachment = Util.null2String(params.get("fileids"));
//区分是来自于钉钉还是EM7
String browser = Util.null2String(params.get("browser"));
//客户
String crm = Util.null2String(params.get("crm"));
//是否开启外勤签到转考勤
String outsidesign = "";
KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo();
KQGroupEntity kqGroupEntity = kqGroupMemberComInfo.getUserKQGroupInfo(user.getUID()+"");
String kqGroupEntityInfo = kqGroupEntity != null ? JSON.toJSONString(kqGroupEntity): "";
logMap.put("kqGroupEntityInfo", kqGroupEntityInfo);
if (kqGroupEntity != null) {
outsidesign = kqGroupEntity.getOutsidesign();
}
kqLog.info(user.getLastname()+":params:"+params+":outsidesign:"+outsidesign);
int userId = user.getUID();
String signfrom = "e9_mobile_out";
DateTimeFormatter allFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalDateTime localTime = LocalDateTime.now();
String signTime =localTime.format(dateTimeFormatter);
String signDate = localTime.format(dateFormatter);
KQWorkTime kqWorkTime = new KQWorkTime();
WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(user.getUID()+"", signDate);
String userinfo = "#userid#"+user.getUID()+"#getUserSubCompany1#"+user.getUserSubCompany1()+"#getUserSubCompany1#"+user.getUserDepartment()
+"#getJobtitle#"+user.getJobtitle();
workTimeEntityLogMap.put("resourceid", userinfo);
workTimeEntityLogMap.put("splitDate", signDate);
workTimeEntityLogMap.put("workTimeEntity", workTimeEntity);
//处理多时区
String timeZoneConversion = Util.null2String(new weaver.general.BaseBean().getPropValue("weaver_timezone_conversion","timeZoneConversion")).trim();
logMap.put("timeZoneConversion", timeZoneConversion);
if("1".equals(timeZoneConversion)) {
DateTransformer dateTransformer=new DateTransformer();
String[] zone_localTime = dateTransformer.getLocaleDateAndTime(signDate,signTime);
if(zone_localTime != null && zone_localTime.length == 2){
signDate = zone_localTime[0];
signTime = zone_localTime[1];
}
}
String timeZone = Util.null2String(TimeZoneVar.getTimeZone(),"");
String signData = Util.null2String(params.get("signData"));
String groupid = workTimeEntity.getGroupId();
String text ="wea"+ userId + groupid;
kqLog.writeLog("PunchOutButtonCmd>text=" + text);
String ma5Text = DigestUtils.md5Hex(text)+"ver";
kqLog.writeLog("PunchOutButtonCmd>ma5Text=" + ma5Text+";signData=" + signData);
if(!signData.equals(ma5Text)){
retmap.put("status", "0");
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
return ;
}
String mobile_sign_sql = "insert into mobile_sign(operater,operate_type,operate_date,operate_time,longitude,latitude,address,remark,attachment,crm,timezone) "
+ " values(?,?,?,?,?,?,?,?,?,?,?) ";
rs1.executeUpdate(mobile_sign_sql, userId,signfrom,signDate,signTime,longitude,latitude,address,remark,attachment,crm,timeZone);
logMap.put("outsidesign", outsidesign);
if("1".equalsIgnoreCase(outsidesign)){
JSONObject jsonObject = null;
String deviceInfo = Util.null2String(params.get("deviceInfo"));
if(deviceInfo.length() > 0){
jsonObject = JSON.parseObject(deviceInfo);
JSONObject jsonObject1 = new JSONObject();
Set<Entry<String, Object>> jsonSet = jsonObject.entrySet();
for(Entry<String, Object> js : jsonSet){
String key = js.getKey();
String value = Util.null2String(js.getValue());
jsonObject1.put(key, value);
}
if(!jsonObject1.isEmpty()){
deviceInfo = jsonObject1.toJSONString();
}
}
if("DingTalk".equalsIgnoreCase(browser)){
signfrom = "DingTalk_out";
}else if("Wechat".equalsIgnoreCase(browser)){
signfrom = "Wechat_out";
String weChat_deviceid = Util.null2String(request.getSession().getAttribute(EMManager.DeviceId));
kqLog.info("EMManager.DeviceId:"+EMManager.DeviceId+":weChat_deviceid:"+weChat_deviceid);
logMap.put("weChat_deviceid", weChat_deviceid);
if(weChat_deviceid.length() > 0){
//微信打卡的设备号需要单独处理
if(jsonObject != null){
jsonObject.put("deviceId", weChat_deviceid);
}else{
jsonObject = new JSONObject();
jsonObject.put("deviceId", weChat_deviceid);
}
if(!jsonObject.isEmpty()){
deviceInfo = jsonObject.toJSONString();
}
}
}
//自由班制处理
String isfree = Util.null2String(params.get("isfree"));
String userType = user.getLogintype();
String signType = "on".equalsIgnoreCase(type) ? "1" : "2";
String clientAddress = Util.getIpAddr(request);
boolean isInIp = true;
String isInCom = isInIp ? "1" : "0";
String datetime_timezone = signDate+" "+signTime;
LocalDateTime nowDateTime = LocalDateTime.parse(datetime_timezone,allFormatter);
kqLog.info("timeZone:"+timeZone+":signDate:"+signDate+":signTime:"+signTime+":nowDateTime:"+nowDateTime);
boolean isInScope = true;
if(signsection != null && signsection.length() > 0){
List<String> signsectionList = Util.TokenizerString(signsection, ",");
for(int i = 0 ; i < signsectionList.size() ; i++){
String signsections = Util.null2String(signsectionList.get(i));
String[] signsection_arr = signsections.split("#");
if(signsection_arr != null && signsection_arr.length == 2){
String canStart = signsection_arr[0];
String canEnd = signsection_arr[1];
LocalDateTime startSignDateTime = LocalDateTime.parse(canStart,allFormatter);
LocalDateTime endSignDateTime = LocalDateTime.parse(canEnd,allFormatter);
if(nowDateTime.isBefore(startSignDateTime) || nowDateTime.isAfter(endSignDateTime)){
isInScope = false;
}else{
isInScope = true;
break;
}
}
}
}
if(!isInScope){
//外勤的不在范围内也不管,全部计入考勤表
// retmap.put("status", "1");
// retmap.put("message", SystemEnv.getHtmlLabelName(503597 , user.getLanguage()));
// return ;
}
if(belongdate.length() == 0){
belongdate = signDate;
}
deviceInfo = deviceInfo.replaceAll("\\?", "");
String punchSql = "insert into HrmScheduleSign(userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo) "+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
boolean isok = rs.executeUpdate(punchSql,userId,userType,signType,signDate,signTime,clientAddress,isInCom,
timeZone,belongdate,signfrom,longitude,latitude,address,deviceInfo);
logMap.put("punchSql", punchSql);
logMap.put("punchSql_isok", isok);
//同步更新考勤数据到考勤报表
if(belongdateIsNull){
//外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤
kqLog.info("PunchOutButtonCmd:userId:"+userId+":belongdate:"+DateUtil.getYesterday());
new KQFormatBiz().formatDate(""+userId,DateUtil.getYesterday());
}
kqLog.info("PunchOutButtonCmd:userId:"+userId+":belongdate:"+(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
if(belongdate.length()==0){
//外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤
new KQFormatBiz().formatDate(""+userId,DateUtil.getYesterday());
}
new KQFormatBiz().formatDate(""+userId,(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
//外勤签到转的考勤 处理加班规则
SplitActionUtil.pushOverTimeTasksAll(belongdate,belongdate,""+userId);
}
/*考勤二开--外出出差流程外勤打卡start*/
else {
bb.writeLog("外勤打卡转考勤卡start");
bb.writeLog("params: " + params);
bb.writeLog("signdate: " + signDate);
//先判断是否有外出出差流程
String evectionTableName = Util.null2String(bb.getPropValue("project_hostar","evectionTableName"));
String outTableName = Util.null2String(bb.getPropValue("project_hostar","outTableName"));
if ( StringUtils.isNotBlank(evectionTableName) && StringUtils.isNotBlank(outTableName) ) {
Integer number = -1;
String sqlDate = "";
if (StringUtils.isNotBlank(belongdate)) {
sqlDate = belongdate;
} else {
sqlDate = signDate;
}
String acqEvecAndOutSql = " select sum(a.number) as number " +
" from ( " +
" SELECT " +
" count(*) as number " +
" FROM " +
" workflow_requestbase " +
" WHERE " +
" requestid IN ( SELECT requestid FROM " + evectionTableName + " WHERE (sqr = '" + userId + "' or ','+CAST(nbtxr AS varchar(max))+',' like '%,'+CAST("+userId+" AS varchar(10))+',%') and ksrq <='" + sqlDate + "' and (((sjjsrq is null or sjjsrq = '') and yjjsrq >= '" + sqlDate + "') or (sjjsrq is not null and sjjsrq != '' and sjjsrq >= '" + sqlDate + "'))) " +
// " AND currentnodetype = 3 " +
" UNION all " +
" SELECT " +
" count(*) as number " +
" FROM " +
" workflow_requestbase " +
" WHERE " +
" requestid IN ( SELECT requestid FROM " + outTableName + " WHERE (sqr = '" + userId + "' or ','+CAST(nbtxr AS varchar(max))+',' like '%,'+CAST("+userId+" AS varchar(10))+',%') and ksrq <='" + sqlDate + "' and (((sjjsrq is null or sjjsrq = '') and yjjsrq >= '" + sqlDate + "') or (sjjsrq is not null and sjjsrq != '' and sjjsrq >= '" + sqlDate + "'))) " +
// " AND currentnodetype = 3 " +
") a ";
bb.writeLog("acqEvecAndOutSql: " + acqEvecAndOutSql);
rs.executeQuery(acqEvecAndOutSql);
while (rs.next()) {
number = Util.getIntValue(Util.null2String(rs.getString("number")));
}
bb.writeLog("number: " + number);
if (number > 0) {
boolean isInIp = true;
String userType = user.getLogintype();
String signType = "on".equalsIgnoreCase(type) ? "1" : "2";
String clientAddress = Util.getIpAddr(request);
String isInCom = isInIp ? "1" : "0";
JSONObject jsonObject = null;
String deviceInfo = Util.null2String(params.get("deviceInfo"));
if(deviceInfo.length() > 0){
jsonObject = JSON.parseObject(deviceInfo);
JSONObject jsonObject1 = new JSONObject();
Set<Entry<String, Object>> jsonSet = jsonObject.entrySet();
for(Entry<String, Object> js : jsonSet){
String key = js.getKey();
String value = Util.null2String(js.getValue());
jsonObject1.put(key, value);
}
if(!jsonObject1.isEmpty()){
deviceInfo = jsonObject1.toJSONString();
}
}
String punchSql = "insert into HrmScheduleSign(userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo,isdev) "+
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
boolean isok = rs.executeUpdate(punchSql,userId,userType,signType,signDate,signTime,clientAddress,isInCom,
timeZone,belongdate,signfrom,longitude,latitude,address,deviceInfo,"1");
bb.writeLog("isok: " + isok);
//自动对班
kqLog.info("PunchOutButtonCmd.format in >>>>>userId" + userId + "kqDate==" + signDate+"format.groupId:"+groupid+"format.serialId:"+workTimeEntity.getSerialId());
//责任制考勤组id收集
rs.executeQuery("select kqzid from uf_zrzkqz");
while (rs.next()){
LIST.add(Util.null2String(rs.getString("kqzid")));
}
kqLog.info("PunchOutButtonCmd.LIST"+LIST);
if(LIST.contains(groupid)) {
RecordSet rt = new RecordSet();
boolean b;
BaseBean bb= new BaseBean();
//休息日或节假日给休息班次
//int changeType = KQOvertimeRulesBiz.getChangeType(Util.null2String(userId), signDate);
String fixedSerialid = Util.null2String(bb.getPropValue("project_hostar", "fixedSerialid"));
String defaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "defaultSerialid"));
String weekendDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "weekendDefaultSerialid"));
String holidayDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "holidayDefaultSerialid"));
String fixedUserId = "";
//查询指定和考勤组成员
String query_sql = "select distinct typevalue from kq_groupmember where groupid = ? ";
rs.executeQuery(query_sql,fixedSerialid);
if (rs.next()) {
fixedUserId = rs.getString("typevalue");
}
boolean holiday = KQHolidaySetBiz.isHoliday(fixedUserId, signDate,true);
kqLog.info("format.holiday:" + holiday);
//String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)";
String sql = "update kq_shiftschedule set serialid = ? where resourceid = ? and kqdate= ? and groupid = ? and isdelete = 0 ";
//考勤当天是节假日或者休息日
if (holiday) {
//节假日休息班
b = rt.executeUpdate(sql, signDate, holidayDefaultSerialid, Util.null2String(userId),signDate,groupid);
kqLog.info("PunchOutButtonCmd.b1:" + b);
}else{
//周末休息班
// if(DateUtil.getWeek(signDate) == 6 || DateUtil.getWeek(signDate) == 7){
// b = rt.executeUpdate(sql,weekendDefaultSerialid, Util.null2String(userId), signDate,groupid);
// kqLog.info("PunchOutButtonCmd.b2:"+b);
// }else{
//设置考勤班次为对应班次
b = rt.executeUpdate(sql,defaultSerialid, Util.null2String(userId), signDate,groupid);
kqLog.info("PunchOutButtonCmd.b3:"+b);
//}
}
}
//同步更新考勤数据到考勤报表
if(belongdateIsNull){
//外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤
bb.writeLog("PunchOutButtonCmd:userId:"+userId+":belongdate:"+DateUtil.getYesterday());
new KQFormatBiz().formatDate(""+userId,DateUtil.getYesterday());
}
bb.writeLog("PunchOutButtonCmd:userId:"+userId+":belongdate:"+(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
if(belongdate.length()==0){
//外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤
new KQFormatBiz().formatDate(""+userId,DateUtil.getYesterday());
}
new KQFormatBiz().formatDate(""+userId,(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
//外勤签到转的考勤 处理加班规则
SplitActionUtil.pushOverTimeTasksAll(belongdate,belongdate,""+userId);
} else {
String acqSql = "select id from mobile_sign where operater = ? and operate_date = ? and operate_time = ? ";
rs.executeQuery(acqSql, userId, signDate, signTime);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
if (StringUtils.isNotBlank(id)) {
//整理原始打卡信息
Map<String, Object> signInfo = new HashMap<>();
boolean isInIp = true;
String userType = user.getLogintype();
String signType = "on".equalsIgnoreCase(type) ? "1" : "2";
String clientAddress = Util.getIpAddr(request);
String isInCom = isInIp ? "1" : "0";
JSONObject jsonObject = null;
String deviceInfo = Util.null2String(params.get("deviceInfo"));
if(deviceInfo.length() > 0){
jsonObject = JSON.parseObject(deviceInfo);
JSONObject jsonObject1 = new JSONObject();
Set<Entry<String, Object>> jsonSet = jsonObject.entrySet();
for(Entry<String, Object> js : jsonSet){
String key = js.getKey();
String value = Util.null2String(js.getValue());
jsonObject1.put(key, value);
}
if(!jsonObject1.isEmpty()){
deviceInfo = jsonObject1.toJSONString();
}
}
signInfo.put("userId", userId);
signInfo.put("userType", userType);
signInfo.put("signType", signType);
signInfo.put("signDate", signDate);
signInfo.put("signTime", signTime);
signInfo.put("clientAddress", clientAddress);
signInfo.put("isInCom", isInCom);
signInfo.put("timeZone", timeZone);
signInfo.put("belongdate", belongdate);
signInfo.put("signfrom", signfrom);
signInfo.put("longitude", longitude);
signInfo.put("latitude", latitude);
signInfo.put("address", address);
signInfo.put("deviceInfo", deviceInfo);
signInfo.put("isdev", "1");
signInfo.put("belongdateIsNull", belongdateIsNull);
String signInfoString = signInfo.toString();
String outSignTypeModeId = bb.getPropValue("project_hostar", "outSignTypeModeId");
Integer modedatacreater = 1;
Integer modedatacreatertype = 0;
String modedatacreatedate = cn.hutool.core.date.DateUtil.format(new Date(), "yyyy-MM-dd");
String modedatacreatetime = cn.hutool.core.date.DateUtil.format(new Date(), "HH:mm:ss");
String abnUuid = UUID.randomUUID().toString();
String syncSql = "insert into uf_outsigntype (outsignid, signinfo, formmodeid, modedatacreater, " +
"modedatacreatertype, modedatacreatedate, modedatacreatetime, MODEUUID) values (?, ?, ?, ?, ?, ?, ?, ?)";
boolean b = rs.executeUpdate(syncSql, id, signInfoString, outSignTypeModeId, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime, abnUuid);
if (b) {
String billid = "-1";
String acqModeIdSql = "select id from uf_outsigntype where MODEUUID = ?";
rs.executeQuery(acqModeIdSql, abnUuid);
while (rs.next()) {
billid = Util.null2String(rs.getString("id"));
}
bb.writeLog("billid" + billid);
new HostarUtil().modePerRecon(modedatacreater, outSignTypeModeId, billid);
}
}
}
}
}
bb.writeLog("外勤打卡转考勤卡end");
}
/*考勤二开--外出出差流程外勤打卡end*/
retmap.put("status", "1");
retmap.put("signdate", signDate);
retmap.put("signtime", signTime);
logMap.put("retmap", retmap);
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,792 @@
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.hostar.util.HostarUtil;
import com.engine.kq.biz.*;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.util.ExcelUtil;
import com.engine.kq.util.KQDurationCalculatorUtil;
import 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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
public class ExportDailyExcelCmd extends AbstractCommonCommand<Map<String, Object>> {
private HttpServletRequest request;
private HttpServletResponse response;
private List<String> lsFieldDataKey;
BaseBean bb = new BaseBean();
public ExportDailyExcelCmd(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 {
bb.writeLog("ExportDailyExcelCmd start.");
SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit();
KQWorkTime kqWorkTime = new KQWorkTime();
KQReportBiz kqReportBiz = new KQReportBiz();
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
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.add("kqdate");
showColumns.add("serialid");
showColumns.removeIf(showColumn->showColumn.trim().equals(""));
List<String> tmpShowColumns = new ArrayList<>();
for(String showColumn:showColumns){
tmpShowColumns.add(showColumn);
String cascadekey = "";
if(showColumn.equals("signin1")){
cascadekey = "signout1";
}else if(showColumn.equals("signin2")){
cascadekey = "signout2";
}else if(showColumn.equals("signin3")){
cascadekey = "signout3";
}else if(showColumn.equals("beLate")){
cascadekey = "beLateMins";
}else if(showColumn.equals("leaveEearly")){
cascadekey = "leaveEarlyMins";
}else if(showColumn.equals("graveBeLate")){
cascadekey = "graveBeLateMins";
}else if(showColumn.equals("graveLeaveEarly")){
cascadekey = "graveLeaveEarlyMins";
}else if(showColumn.equals("absenteeism")){
cascadekey = "absenteeismMins";
}else if(showColumn.equals("overtime")){
tmpShowColumns.add("overtime_4leave");
tmpShowColumns.add("overtime_nonleave");
tmpShowColumns.add("workingDayOvertime_nonleave");
tmpShowColumns.add("workingDayOvertime_4leave");
tmpShowColumns.add("restDayOvertime_nonleave");
tmpShowColumns.add("restDayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_nonleave");
}
if(cascadekey.length()>0){
tmpShowColumns.add(cascadekey);
}
}
showColumns = tmpShowColumns;
String today = DateUtil.getCurrentDate();
if(DateUtil.compDate(today, toDate)>0){//结束如期不大于今天
toDate = today;
}
String rightSql = new KQReportBiz().getReportRight("2",""+user.getUID(),"a");
LinkedHashMap<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;
Map<String,Object> constraint = null;
sheet = new HashMap<>();
sheet.put("sheetName", SystemEnv.getHtmlLabelName( 390352, user.getLanguage()));
sheet.put("sheetTitle", SystemEnv.getHtmlLabelName( 390352, user.getLanguage()));
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.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily"))continue;
if (!showColumns.contains(kqReportFieldComInfo.getFieldname())&&!showColumns.contains(kqReportFieldComInfo.getParentid())) continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
title = new HashMap<>();
String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user);
if(unitType.length()>0){
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ "(" + unitType + ")");
}else{
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
}
title.put("width",30*256);
this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user);
childColumns = (List<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);
}
sheet.put("titleList", titleList);
String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck ";
if(rs.getDBType().equalsIgnoreCase("oracle")&&!Util.null2String(rs.getOrgindbtype()).equals("dm")&&!Util.null2String(rs.getOrgindbtype()).equals("st")) {
forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) ";
}else if((rs.getDBType()).equalsIgnoreCase("mysql")){
forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) ";
}else {
forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) ";
}
String backFields = " zm.cccb as mealAllowance," +
" zm.zdcb as statAllowance," +
" zm.jmybcb as nightAllowance," +
" zm.hrzdcb as otherStatAllowance," +
" zm.ybbz as nightShiftSubsidy, "+
" a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," +
" b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,FLOOR( b.attendanceMins / 30 ) * 30 AS attendanceMins ,b.beLate," +
" b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins,b.graveLeaveEarly," +
" b.graveLeaveEarlyMins,b.absenteeism,b.signdays,b.signmins, "+
" b.absenteeismMins ,(b.forgotCheck+"+forgotBeginWorkCheck_field+") forgotCheck,zeropoint ";
String sqlFrom = " from hrmresource a, kq_format_total b,uf_cbxxjlb zm " +
"where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"' and zm.xm=a.id and zm.rq = b.kqdate ";
String sqlWhere = rightSql;
if(subCompanyId.length()>0){
sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and a.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and a.id in("+resourceId+") ";
}
if(viewScope.equals("4")){//我的下属
if(allLevel.equals("1")){//所有下属
sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'";
}else{
sqlWhere+=" and a.managerid="+user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
String orderBy = " order by a.dsporder asc, a.lastname asc , b.kqDate asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc ";
sql = "select "+backFields + sqlFrom + sqlWhere+orderBy;
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
long startTime = System.currentTimeMillis();
Map<String,Object> flowData = kqReportBiz.getDailyFlowData(params,user);
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime; // 执行时间
bb.writeLog("getDailyMealAllowanceData执行时间" + elapsedTime/1000 + "秒");
// /*考勤二开--驻点餐补start*/
// HostarUtil hostarUtil = new HostarUtil();
// List<String> subComoanyList = new ArrayList<>();
// String acqNoStatAllSql = "select subcompany from uf_NoStatAllSubCom where isdelete = 0 or isdelete is null";
// rs.executeQuery(acqNoStatAllSql);
// while (rs.next()) {
// String subcompany = Util.null2String(rs.getString("subcompany"));
// if (StringUtils.isNotBlank(subcompany)) {
// subComoanyList.add(subcompany);
// }
// }
// bb.writeLog("subComoanyList: " + subComoanyList);
// /*考勤二开--驻点餐补end*/
// /*考勤二开--夜班餐补start*/
// String nightshiftsub = Util.null2String(bb.getPropValue("project_hostar", "nightshiftsubcompany"));
// List<String> nightshifts = new ArrayList<String>();
// String acqSerialSql = " select shift from uf_nightshiftmanage where isdelete is null or isdelete = 0";
// rs.executeQuery(acqSerialSql);
// while (rs.next()) {
// String serial = Util.null2String(rs.getString("shift"));
// if (StringUtils.isNotBlank(serial)) {
// nightshifts.add(serial);
// }
// }
// /*考勤二开--夜班餐补end*/
bb.writeLog("ExportDailyExcelCmd sql:" + sql);
rs.execute(sql);
while (rs.next()) {
data = new ArrayList<>();
String id = rs.getString("id");
String kqdate = rs.getString("kqdate");
Map<String,Object> signDetailInfo = this.getSignDetailInfo(id,kqdate);
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("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("serialid")){
String serialid = Util.null2String(rs.getString("serialid"));
if(serialid.length()>0){
fieldValue = Util.formatMultiLang(shiftManagementToolKit.getShiftOnOffWorkSections(serialid, user.getLanguage()));
}
} else if(fieldName.equals("signin1")){
fieldValue = Util.null2String(signDetailInfo.get("signintime1"));
data.add(fieldValue);
//考勤二开
fieldValue = Util.null2String(signDetailInfo.get("signinaddress1"));
data.add(fieldValue);
fieldValue = Util.null2String(signDetailInfo.get("signinstatus1"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signin2")){
fieldValue = Util.null2String(signDetailInfo.get("signintime2"));
data.add(fieldValue);
fieldValue = Util.null2String(signDetailInfo.get("signinstatus2"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signin3")){
fieldValue = Util.null2String(signDetailInfo.get("signintime3"));
data.add(fieldValue);
fieldValue = Util.null2String(signDetailInfo.get("signinstatus3"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signout1")){
fieldValue = Util.null2String(signDetailInfo.get("signouttime1"));
data.add(fieldValue);
//考勤二开
fieldValue = Util.null2String(signDetailInfo.get("signoutaddress1"));
data.add(fieldValue);
fieldValue = Util.null2String(signDetailInfo.get("signoutstatus1"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signout2")){
fieldValue = Util.null2String(signDetailInfo.get("signouttime2"));
data.add(fieldValue);
fieldValue = Util.null2String(signDetailInfo.get("signoutstatus2"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signout3")){
fieldValue = Util.null2String(signDetailInfo.get("signouttime3"));
data.add(fieldValue);
fieldValue = Util.null2String(signDetailInfo.get("signoutstatus3"));
data.add(fieldValue);
continue;
// } else if (fieldName.equals("mealAllowance")) {//考勤二开--出差餐补
// int intValue = Util.getIntValue(Util.null2String(flowData.get("DailyMealAllow|" + resourceId + "|" + kqdate)));
// if (intValue < 0) {
// intValue = 0;
// }
// data.add(intValue);
// continue;
} else if(fieldName.equals("leave")){
//请假
List<Map<String, Object>> allLeaveRules = KQLeaveRulesBiz.getAllLeaveRules();
Map<String, Object> leaveRule = null;
for(int i=0;allLeaveRules!=null&&i<allLeaveRules.size();i++){
leaveRule = (Map<String, Object>)allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_"+leaveRule.get("id"));
fieldValue = Util.null2String(flowData.get(id+"|"+kqdate+"|"+flowType));
String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try {
//以防止出现精度问题
if (fieldValue.length() == 0) {
fieldValue = "0.0";
}
if (leavebackData.length() == 0) {
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(fieldValue);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
} catch (Exception e) {
writeLog("ExportDailyExcelCmd:fieldValue" + fieldValue + ":leavebackData:" + leavebackData + ":" + e);
}
//考虑下冻结的数据
if (b_flowLeaveData.length() > 0) {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
} else {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(fieldValue, 0.0) - Util.getDoubleValue(leavebackData, 0.0)));
}
fieldValue = flowLeaveData;
data.add(fieldValue);
}
}else if(fieldName.equals("overtime")){
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave"))));
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal"))));
continue;
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
// } else if ( "mealAllowance".equals(fieldName)) {//考勤二开--出差餐补
// int intValue = Util.getIntValue(Util.null2String(flowData.get("DailyMealAllow|" + resourceId + "|" + kqdate)));
// if (intValue < 0) {
// intValue = 0;
// }
// data.add(intValue);
// continue;
// } else if ("statAllowance".equals(fieldName)) {//考勤二开--驻点餐补
//
// String subcompanyId = Util.null2String(rs.getString("subcompanyid"));
// if ( !subComoanyList.contains(subcompanyId)) {
//
// params.put("statUser", id);
// params.put("kqdate", kqdate);
//// bb.writeLog("params: " + params );
//
// long startTime = System.currentTimeMillis();
// Map<String, Object> dailyStatAllowanceData = kqReportBiz.getDailyStatAllowanceData(params, user);
// long endTime = System.currentTimeMillis();
// long elapsedTime = endTime - startTime; // 执行时间
// bb.writeLog("执行时间:" + elapsedTime/1000 + "秒");
//
// if (dailyStatAllowanceData == null || dailyStatAllowanceData.size() == 0) {
// fieldValue = "0";
// } else {
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(dailyStatAllowanceData, id + "|DailyStatAllowance");
//
// double temp = Util.getDoubleValue(Util.null2String(tempMap.get(id + "|DailyStatAllowance" + "|" + kqdate )));
// if (temp <= 0) {
// fieldValue = "0";
// } else {
// fieldValue = String.valueOf(temp);
// }
// }
//
//// bb.writeLog("fieldValue: " + fieldValue);
// }
// data.add(fieldValue);
// continue;
// } else if ("nightAllowance".equals(fieldName)) {//考勤二开--夜班餐补
// String subcompanyId = Util.null2String(rs.getString("subcompanyid"));
// String serialid = Util.null2String(rs.getString("serialid"));
// if ( !subComoanyList.contains(subcompanyId) && nightshifts.contains(serialid)) {
// int temp = Util.getIntValue(Util.null2String(flowData.get(id + "|DailyNightShiftAllowanceData" + "|" + kqdate )));
// if (temp <= 0) {
// fieldValue = "0";
// } else {
// fieldValue = String.valueOf(temp);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// }
// data.add( fieldValue);
// continue;
// } else if ("nightShiftSubsidy".equals(fieldName)) {//考勤二开--夜班补助
// params.put("subUserId", id);
//// bb.writeLog("params: " + params );
//
// Map<String, Object> temp = kqReportBiz.getDailyNightShiftSubsidyData(params, user);
// if (temp == null || temp.size() == 0) {
// data.add( "0");
// } else {
// int intValue = Math.max(Util.getIntValue(Util.null2String(temp.get(id + "|DailyStatAllowance" + kqdate))) , 0);
// data.add( intValue);
// }
//
// } else if ("otherStatAllowance".equals(fieldName)) {//考勤二开--鸿仁驻点餐补
// int temp = Util.getIntValue(Util.null2String(flowData.get(id + "|DailyOtherStatAllowance" + "|" + kqdate )));
// if (temp <= 0) {
// fieldValue = "0";
// } else {
// fieldValue = String.valueOf(temp);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.add(fieldValue);
// continue;
} else if(fieldName.equals("kqdate")){
fieldValue=kqdate+" "+com.engine.portal.util.DateUtil.getDayWeekOfDate1(DateUtil.parseToDate(kqdate));
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid));
}
if(!fieldName.equals("leave")) {
fieldValue = Util.formatMultiLang(fieldValue, "" + user.getLanguage());
data.add(fieldValue);
}
}
dataList.add(data);
}
sheet.put("dataList", dataList);
sheet.put("constraintList",constraintList);
sheet.put("createFile", "1");
lsSheet.add(sheet);
workbook.put("sheet", lsSheet);
String fileName = SystemEnv.getHtmlLabelName(390352, user.getLanguage())+" "+fromDate+" "+toDate;;
workbook.put("fileName", fileName);
ExcelUtil ExcelUtil = new ExcelUtil();
Map<String,Object> exportMap= ExcelUtil.export(workbook,request,response);
retmap.putAll(exportMap);
retmap.put("status", "1");
} catch (Exception e) {
bb.writeLog("ExportDailyExcelCmd error:" + e.getMessage());
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;
if(parentid.equals("leave")){
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
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"));
title = new HashMap<>();
title.put("title",name+"("+
((KQUnitBiz.isLeaveHour(unitType))?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage()))+")");
title.put("width",30*256);
titleList.add(title);
}
}else if(parentid.equals("overtime")){
String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"};
for(int i=0;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("daily"))continue;
title = new HashMap<>();
title.put("title",SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+
(KQReportBiz.getUnitType(kqReportFieldComInfo, user).length()>0?"("+ KQReportBiz.getUnitType(kqReportFieldComInfo, user)+")":""));
title.put("width",30*256);
titleList.add(title);
}
}
}
returnMap.put("childColumns",titleList);
return returnMap;
}
public Map<String, Object> getSignDetailInfo(String resourceId, String kqDate){
Map<String, Object> data = new HashMap<>();
Map<String,Object> signStatusInfo = null;
RecordSet rs = new RecordSet();
String sql = "";
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
try{
// sql = " select kqdate,resourceid,serialid,serialnumber,workbegindate,workbegintime, " +
// " workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" +
// " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," +
// " leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid \n" +
// " from kq_format_detail b \n" +
// " where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' \n" +
// " order by serialnumber \n";
/*考勤二开--增加打卡地址start*/
sql = " select a.kqdate,a.resourceid,a.serialid,a.serialnumber,a.workbegindate,a.workbegintime, " +
" a.workenddate,a.workendtime,a.workmins,a.signindate,a.signintime,a.signoutdate,a.signouttime, \n" +
" a.attendanceMins,a.belatemins,a.graveBeLateMins,a.leaveearlymins,a.graveLeaveEarlyMins,a.absenteeismmins,a.forgotcheckMins,a.forgotBeginWorkCheckMins," +
" a.leaveMins,a.leaveInfo,a.evectionMins,a.outMins,a.signinid,a.signoutid, b.addr as signinaddr, c.addr as signoutaddr \n" +
" from kq_format_detail a " +
" left join hrmschedulesign b on b.id = a.signinid \n" +
" left join hrmschedulesign c on c.id = a.signoutid \n" +
" where a.resourceid = " + resourceId + " and a.kqdate ='" + kqDate + "' \n" +
" order by a.serialnumber \n";
/*考勤二开--增加打卡地址end*/
rs.execute(sql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
String kqdate = Util.null2String(rs.getString("kqdate"));
String serialid = Util.null2String(rs.getString("serialid"));
int serialnumber = rs.getInt("serialnumber")+1;
String workbegindate = Util.null2String(rs.getString("workbegindate")).trim();
String workbegintime = Util.null2String(rs.getString("workbegintime")).trim();
String workenddate = Util.null2String(rs.getString("workenddate")).trim();
String workendtime = Util.null2String(rs.getString("workendtime")).trim();
int workMins = rs.getInt("workMins");
String signintime = Util.null2String(rs.getString("signintime")).trim();
String signouttime = Util.null2String(rs.getString("signouttime")).trim();
int attendanceMins = rs.getInt("attendanceMins");
String beLateMins = Util.null2String(rs.getString("beLateMins")).trim();
String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim();
String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim();
String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim();
String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim();
String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim();
String signinid = Util.null2String(rs.getString("signinid")).trim();
String signoutid = Util.null2String(rs.getString("signoutid")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
String signInAddr = Util.null2String(rs.getString("signinaddr"));
String signOutAddr = Util.null2String(rs.getString("signoutaddr"));
bb.writeLog("signInAddr: " + signInAddr);
bb.writeLog("signOutAddr: " + signOutAddr);
if(serialid.length()>0){
if (workbegintime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workbegindate);
signStatusInfo.put("worktime",workbegintime);
signStatusInfo.put("beLateMins",beLateMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("graveBeLateMins",graveBeLateMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime);
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
data.put("signinaddress"+serialnumber, signInAddr);
}
if (workendtime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workenddate);
signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime));
signStatusInfo.put("leaveEarlyMins",leaveEarlyMins);
signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins);
signStatusInfo.put("forgotCheckMins",forgotCheckMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime);
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
data.put("signoutaddress"+serialnumber, signOutAddr);
}
}else{
if(workMins>0){
//弹性工时打卡时间取自签到签退数据
}
signStatusInfo = new HashMap();
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
if(signinid.length() > 0){
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime);
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
data.put("signinaddress"+serialnumber, signInAddr);
if(signoutid.length() > 0){
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime);
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
data.put("signoutaddress"+serialnumber, signOutAddr);
}
}else{
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
}
}
}
}catch (Exception e){
writeLog(e);
}
return data;
}
private String getFieldValueByUnitType(String fieldValue,String unittype){
if (Util.null2String(unittype).length() > 0) {
if (fieldValue.length() == 0) {
fieldValue = "0";
} else {
if (unittype.equals("2")) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
}
}
return fieldValue;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,723 @@
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.hostar.util.HostarUtil;
import com.engine.kq.biz.*;
import com.engine.kq.util.ExcelUtil;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.UtilKQ;
import weaver.common.DateUtil;
import weaver.common.StringUtil;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
public class ExportExcelCmd extends AbstractCommonCommand<Map<String, Object>> {
private HttpServletRequest request;
private HttpServletResponse response;
private List<String> lsFieldDataKey;
BaseBean bb = new BaseBean();
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();
KQReportBiz kqReportBiz = new KQReportBiz();
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);
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 = " (select sum(zm.cccb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as mealAllowance," +
" (select sum(zm.zdcb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as statAllowance," +
" (select sum(zm.jmybcb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as nightAllowance," +
" (select sum(zm.hrzdcb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as otherStatAllowance," +
" (select sum(zm.ybbz) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as nightShiftSubsidy," +
" 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(FLOOR( b.attendanceMins / 30 ) * 30 ) 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,sum(b.zeropoint) as zeropoint "+(definedFieldSum.length()>0?","+definedFieldSum+"":"");
if(rs.getDBType().equals("oracle")){
backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields;
}
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'";
String sqlWhere = rightSql;
String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle ";
if (subCompanyId.length() > 0) {
sqlWhere += " and a.subcompanyid1 in(" + subCompanyId + ") ";
}
if (departmentId.length() > 0) {
sqlWhere += " and a.departmentid in(" + departmentId + ") ";
}
if (resourceId.length() > 0) {
sqlWhere += " and a.id in(" + resourceId + ") ";
}
if (viewScope.equals("4")) {//我的下属
if (allLevel.equals("1")) {//所有下属
sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'";
} else {
sqlWhere += " and a.managerid=" + user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
String orderBy = " order by a.dsporder asc, a.lastname asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc ";
sql = "select " + backFields + sqlFrom + sqlWhere + groupBy + orderBy;
//System.out.println("start" + DateUtil.getFullDate());
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
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");
/*考勤二开--驻点餐补start*/
HostarUtil hostarUtil = new HostarUtil();
Map<String, Double> attendanceMap = new HashMap<>();
String acqAttendanceSql = "select a.id, b.attendanceMins, b.kqdate from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"' "+sqlWhere;
bb.writeLog("acqAttendanceSql: " + acqAttendanceSql);
rs.executeQuery(acqAttendanceSql);
while (rs.next()) {
double attendanceMins = Util.getDoubleValue(Util.null2String(rs.getString("attendanceMins")));
String id = Util.null2String(rs.getString("id"));
String kqdate = Util.null2String(rs.getString("kqdate"));
if (attendanceMins >= 0.00) {
attendanceMap.put(id + "|DailyStatAllowance" +"|" + kqdate, attendanceMins);
}
}
bb.writeLog("attendanceMap: " + attendanceMap);
/*考勤二开--驻点餐补end*/
rs.execute(sql);
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("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();
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 ("mealAllowance".equals(fieldName)) {//考勤二开--出差餐补
//// bb.writeLog("mealAllowance");
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, "DailyMealAllow|" + resourceId);
//// bb.writeLog("tempMap: " + tempMap);
//
// if ( !tempMap.isEmpty()) {
// int tempValue = 0;
// for (String key: tempMap.keySet()) {
// int intValue = Util.getIntValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(intValue, 0));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.add(fieldValue);
// continue;
// } else if ("statAllowance".equals(fieldName)) {//考勤二开--驻点餐补
//// bb.writeLog("statAllowance");
//// bb.writeLog("flowData: " + flowData);
// params.put("statUser", id);
// bb.writeLog("params: " + params );
//
// Map<String, Object> temp = kqReportBiz.getStatAllowanceData(params, user);
// if (temp == null || temp.size() == 0) {
// data.add( "0");
// } else {
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(temp, id + "|StatAllowance");
//
//// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, id + "|DailyStatAllowance");
//// bb.writeLog("tempMap: " + tempMap);
// if ( !tempMap.isEmpty()) {
// double tempValue = 0.00;
// for (String key: tempMap.keySet()) {
// double doubleValue = Util.getDoubleValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(doubleValue, 0.00));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.add( fieldValue);
// }
// continue;
// } else if ("nightAllowance".equals(fieldName)) {//考勤二开--精密夜班餐补
//// bb.writeLog("nightAllowance");
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, id + "|DailyNightShiftAllowanceData");
//// bb.writeLog("tempMap: " + tempMap);
// if ( !tempMap.isEmpty()) {
// double tempValue = 0.00;
// for (String key: tempMap.keySet()) {
// double doubleValue = Util.getDoubleValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(doubleValue, 0.00));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.add(fieldValue);
// continue;
// } else if ("nightShiftSubsidy".equals(fieldName)) {//考勤二开--夜班补助
// params.put("subUserId", id);
// bb.writeLog("params: " + params );
//
// Map<String, Object> temp = kqReportBiz.getDailyNightShiftSubsidyData(params, user);
// if (temp == null || temp.size() == 0) {
// data.add( "0");
// } else {
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(temp, id + "|DailyNightShiftSubsidyData");
//
// if ( !tempMap.isEmpty()) {
// int tempValue = 0;
// for (String key: tempMap.keySet()) {
// int intValue = Util.getIntValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(intValue, 0));
// }
// fieldValue = String.valueOf(tempValue);
// }
// data.add( fieldValue);
// }
// continue;
// } else if ("otherStatAllowance".equals(fieldName)) {//考勤二开--鸿仁驻点餐补
//// bb.writeLog("otherStatAllowance");
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, id + "|DailyOtherStatAllowance");
//// bb.writeLog("tempMap: " + tempMap);
// if ( !tempMap.isEmpty()) {
// double tempValue = 0.00;
// for (String key: tempMap.keySet()) {
// double doubleValue = Util.getDoubleValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (doubleValue < 0.00 ? 0.00 : doubleValue);
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.add(fieldValue);
// continue;
} 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);
}
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);
isEnd = false;
for (String date = fromDate; !isEnd; ) {
if (date.equals(toDate)) isEnd = true;
if (DateUtil.compDate(today, date) > 0) {
data.add("");
} else {
if (detialDatas.get(id + "|" + date) != null) {
data.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("text"));
} else {
data.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
}
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
}
dataList.add(data);
}
sheet.put("dataList", dataList);
sheet.put("constraintList", constraintList);
sheet.put("createFile", "1");
lsSheet.add(sheet);
workbook.put("sheet", lsSheet);
String fileName = SystemEnv.getHtmlLabelName(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;
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();
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;
}
}

@ -0,0 +1,760 @@
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.hostar.util.HostarUtil;
import com.engine.kq.biz.*;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.PageUidFactory;
import java.math.BigDecimal;
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.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.util.*;
public class GetKQDailyReportCmd extends AbstractCommonCommand<Map<String, Object>> {
private KQLog kqLog = new KQLog();
BaseBean bb = new BaseBean();
public GetKQDailyReportCmd(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 = "";
try{
bb.writeLog("GetKQDailyReportCmd start.");
String pageUid = PageUidFactory.getHrmPageUid("KQDailyReport");
SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
KQWorkTime kqWorkTime = new KQWorkTime();
ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit();
KQReportBiz kqReportBiz = new KQReportBiz();
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
String rightSql = new KQReportBiz().getReportRight("2",""+user.getUID(),"a");
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect =Util.null2String(jsonObj.get("typeselect"));
if(typeselect.length()==0)typeselect = "3";
if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){
if(typeselect.equals("1")){
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
}else{
fromDate = TimeUtil.getDateByOption(typeselect,"0");
toDate = TimeUtil.getDateByOption(typeselect,"1");
}
}
//人员状态
String status = Util.null2String(jsonObj.get("status"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String allLevel = Util.null2String(jsonObj.get("allLevel"));
String isNoAccount = Util.null2String(jsonObj.get("isNoAccount"));
String viewScope = Util.null2String(jsonObj.get("viewScope"));
if(typeselect.length()==0)typeselect = "3";
int pageIndex = Util.getIntValue(Util.null2String(jsonObj.get("pageIndex")), 1);
int pageSize = KQReportBiz.getPageSize(Util.null2String(jsonObj.get("pageSize")),pageUid,user.getUID());
int count = 0;
int pageCount = 0;
int isHavePre = 0;
int isHaveNext = 0;
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
List<Object> columns = new ArrayList();
Map<String,Object> column = null;
List<Object> datas = new ArrayList();
Map<String,Object> data = null;
Map<String,Object> mapChildColumnInfo = null;
List<Object> childColumns = null;
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()){
if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue;
boolean isDaily = kqReportFieldComInfo.getReportType().equals("daily");
if(!kqReportFieldComInfo.getReportType().equals("all") && !isDaily)continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user);
childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("rowSpan", 1);
column.put("width", mapChildColumnInfo.get("sumChildColumnWidth"));
column.put("children", childColumns);
}else{
column.put("rowSpan", 3);
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
}
if(kqReportFieldComInfo.getReportType1().equals("daily")){
column.put("isdaily", "1");
}
column.put("showDetial",kqReportFieldComInfo.getShowDetial());
columns.add(column);
}
// String today = DateUtil.getCurrentDate();
// if(DateUtil.compDate(today, toDate)>0){//结束如期不大于今天
// toDate = today;
// if(DateUtil.compDate(today, fromDate)>0){
// fromDate = today;
// }
// }
String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck ";
if(rs.getDBType().equalsIgnoreCase("oracle")&&!Util.null2String(rs.getOrgindbtype()).equals("dm")&&!Util.null2String(rs.getOrgindbtype()).equals("st")&&!Util.null2String(rs.getOrgindbtype()).equals("jc")) {
forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) ";
}else if((rs.getDBType()).equalsIgnoreCase("mysql")){
forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) ";
}else {
forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) ";
}
String backFields = " (select zm.cccb from uf_cbxxjlb zm where zm.xm = a.id and zm.rq = b.kqdate) as mealAllowance," +
" (select zm.zdcb from uf_cbxxjlb zm where zm.xm = a.id and zm.rq = b.kqdate) as statAllowance," +
" (select zm.jmybcb from uf_cbxxjlb zm where zm.xm = a.id and zm.rq = b.kqdate) as nightAllowance," +
" (select zm.hrzdcb from uf_cbxxjlb zm where zm.xm = a.id and zm.rq = b.kqdate) as otherStatAllowance," +
" (select zm.ybbz from uf_cbxxjlb zm where zm.xm = a.id and zm.rq = b.kqdate) as nightShiftSubsidy," +
" a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," +
" b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,FLOOR( b.attendanceMins / 30 ) * 30 AS attendanceMins," +
" b.beLate,b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins," +
" b.signdays,b.signmins, "+
" b.graveLeaveEarly,b.graveLeaveEarlyMins,b.absenteeism , b.absenteeismMins ,(b.forgotCheck+"+forgotBeginWorkCheck_field+") forgotCheck,zeropoint ";
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'";
String sqlWhere = rightSql;
if(subCompanyId.length()>0){
sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and a.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and a.id in("+resourceId+") ";
}
if(viewScope.equals("4")){//我的下属
if(allLevel.equals("1")){//所有下属
sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'";
}else{
sqlWhere+=" and a.managerid="+user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+") t";
rs.execute(sql);
if (rs.next()){
count = rs.getInt("c");
}
if (count <= 0) {
pageCount = 0;
}
pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0);
isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0;
isHavePre = (pageIndex - 1 >= 1) ? 1 : 0;
String orderBy = " order by a.dsporder asc, a.lastname asc, b.kqdate asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc, b.kqdate desc ";
sql = backFields + sqlFrom + sqlWhere + orderBy;
if (pageIndex > 0 && pageSize > 0) {
if (rs.getDBType().equals("oracle")) {
sql = " select " + sql;
sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= "
+ (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize);
} else if (rs.getDBType().equals("mysql")) {
sql = " select " + sql;
sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize;
} else if (rs.getDBType().equals("postgresql")) {
sql = " select " + sql;
sql = "select t1.* from (" + sql + ") t1 limit " + pageSize+ " offset " + ((pageIndex - 1) * pageSize);
} else {
orderBy = " order by dsporder asc, lastname asc, kqdate asc ";
descOrderBy = " order by dsporder desc, lastname desc, kqdate desc ";
if (pageIndex > 1) {
int topSize = pageSize;
if (pageSize * pageIndex > count) {
topSize = count - (pageSize * (pageIndex - 1));
}
sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top "
+ (pageIndex * pageSize) + sql+" ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy;
} else {
sql = " select top " + pageSize + sql;
}
}
} else {
sql = " select " + sql;
}
long startTime = System.currentTimeMillis();
Map<String,Object> flowData = kqReportBiz.getDailyFlowData(params,user);
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime; // 执行时间
bb.writeLog("flowData执行时间" + elapsedTime/1000 + "秒");
// bb.writeLog("=-=-flowData: " + flowData);
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
// /*考勤二开--驻点餐补start*/
// HostarUtil hostarUtil = new HostarUtil();
// List<String> subComoanyList = new ArrayList<>();
// String acqNoStatAllSql = "select subcompany from uf_NoStatAllSubCom where isdelete = 0 or isdelete is null";
// rs.executeQuery(acqNoStatAllSql);
// while (rs.next()) {
// String subcompany = Util.null2String(rs.getString("subcompany"));
// if (StringUtils.isNotBlank(subcompany)) {
// subComoanyList.add(subcompany);
// }
// }
// bb.writeLog("subComoanyList: " + subComoanyList);
// /*考勤二开--驻点餐补end*/
// /*考勤二开--夜班餐补start*/
// String nightshiftsub = Util.null2String(bb.getPropValue("project_hostar", "nightshiftsubcompany"));
// List<String> nightshifts = new ArrayList<String>();
// String acqSerialSql = " select shift from uf_nightshiftmanage where isdelete is null or isdelete = 0";
// rs.executeQuery(acqSerialSql);
// while (rs.next()) {
// String serial = Util.null2String(rs.getString("shift"));
// if (StringUtils.isNotBlank(serial)) {
// nightshifts.add(serial);
// }
// }
// /*考勤二开--夜班餐补end*/
bb.writeLog("每日报表sql: " + sql);
rs.execute(sql);
while (rs.next()) {
String id = rs.getString("id");
String kqdate = rs.getString("kqdate");
WorkTimeEntity workTime = kqWorkTime.getWorkTime(id, kqdate);
data = new HashMap<>();
kqReportFieldComInfo.setTofirstRow();
while (kqReportFieldComInfo.next()) {
if (!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1")) continue;
if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily"))
continue;
String fieldName = kqReportFieldComInfo.getFieldname();
String fieldValue = "";
if (fieldName.equals("subcompany")) {
String fieldValueID = rs.getString("subcompanyid");
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") :
subCompanyComInfo.getSubCompanyname(fieldValueID);
//fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID);
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getSubCompanyID(id);
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") :
subCompanyComInfo.getSubCompanyname(fieldValueID);
// fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (fieldName.equals("department")) {
String fieldValueID = rs.getString("departmentid");
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") :
departmentComInfo.getDepartmentname(fieldValueID);
//fieldValue = departmentComInfo.getDepartmentname(fieldValueID);
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getDepartmentID(id);
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") :
departmentComInfo.getDepartmentname(fieldValueID);
// fieldValue = departmentComInfo.getDepartmentname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (fieldName.equals("jobtitle")) {
String fieldValueID = rs.getString("jobtitle");
fieldValue = jobTitlesComInfo.getJobTitlesname(rs.getString("jobtitle"));
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getJobTitle(id);
fieldValue = jobTitlesComInfo.getJobTitlesname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (kqReportFieldComInfo.getParentid().equals("overtime") || kqReportFieldComInfo.getParentid().equals("overtime_nonleave")
|| kqReportFieldComInfo.getParentid().equals("overtime_4leave") || fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) {
if (fieldName.equals("overtimeTotal")) {
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave +
workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave));
} else {
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|" + kqdate + "|" + fieldName)));
}
data.put(fieldName, fieldValue);
} else if (fieldName.equals("serialid")) {
fieldValue = Util.null2String(rs.getString(fieldName));
if (fieldValue.length()>0) {//弹性工作制没有班次
data.put("serialid", shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage()));
}
// } else if (fieldName.equals("mealAllowance")) {//考勤二开--出差餐补
// int intValue = Util.getIntValue(Util.null2String(flowData.get("DailyMealAllow|" + resourceId + "|" + kqdate)));
// if (intValue < 0) {
// intValue = 0;
// }
// data.put(fieldName, intValue);
// } else if (fieldName.equals("statAllowance")) {//考勤二开--驻点餐补
// String subcompanyId = Util.null2String(rs.getString("subcompanyid"));
//
// if ( !subComoanyList.contains(subcompanyId)) {
//
// params.put("statUser", id);
// params.put("kqdate", kqdate);
// bb.writeLog("params: " + params );
//
//// long startTime = System.currentTimeMillis();
// Map<String, Object> dailyStatAllowanceData = kqReportBiz.getDailyStatAllowanceData(params, user);
//// long endTime = System.currentTimeMillis();
//// long elapsedTime = endTime - startTime; // 执行时间
//// bb.writeLog("执行时间:" + elapsedTime/1000 + "秒");
//
// if (dailyStatAllowanceData == null || dailyStatAllowanceData.size() == 0) {
// fieldValue = "0";
// } else {
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(dailyStatAllowanceData, id + "|DailyStatAllowance");
//// bb.writeLog("-=-=tempMap: " + tempMap);
//// bb.writeLog("-=-=tempMap.key: " + id + "|DailyStatAllowance" + "|" + kqdate);
// double temp = Util.getDoubleValue(Util.null2String(tempMap.get(id + "|DailyStatAllowance" + "|" + kqdate )));
//// bb.writeLog("-=-=temp: " + temp);
// if (temp <= 0) {
// fieldValue = "0";
// } else {
// fieldValue = String.valueOf(temp);
// }
// }
//
// bb.writeLog("-=-=fieldValue: " + fieldValue);
// }
// data.put(fieldName, fieldValue);
// } else if (fieldName.equals("nightAllowance")) {//考勤二开--精密夜班餐补
// String subcompanyId = Util.null2String(rs.getString("subcompanyid"));
// String serialid = Util.null2String(rs.getString("serialid"));
// if ( subcompanyId.equals(nightshiftsub) && nightshifts.contains(serialid)) {
//// String key= id + "|DailyNightShiftAllowanceData" + "|" + kqdate;
//// bb.writeLog("nightAllowance key: " + key );
// double temp = Util.getDoubleValue(Util.null2String(flowData.get(id + "|DailyNightShiftAllowanceData" + "|" + kqdate )));
//// bb.writeLog("nightAllowance temp: " + temp );
//// bb.writeLog("nightAllowance kqdate: " + kqdate );
// if (temp <= 0.00) {
// fieldValue = "0";
// } else {
// fieldValue = String.valueOf(temp);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// }
// data.put(fieldName, fieldValue);
// } else if ("nightShiftSubsidy".equals(fieldName)) {//考勤二开--夜班补助
// params.put("subUserId", id);
// bb.writeLog("params: " + params );
//
// Map<String, Object> temp = kqReportBiz.getDailyNightShiftSubsidyData(params, user);
//// bb.writeLog("nightShiftSubsidy temp: " + temp );
//// bb.writeLog("nightShiftSubsidy temp.size: " + temp.size() );
//// String key = id + "|DailyNightShiftSubsidyData" + kqdate;
//// bb.writeLog("nightShiftSubsidy key: " + key );
// if (temp == null || temp.size() == 0) {
// data.put(fieldName, "0");
// } else {
// double doubleValue = Math.max(Util.getDoubleValue(Util.null2String(temp.get(id + "|DailyNightShiftSubsidyData|" + kqdate))) , 0.00);
//// bb.writeLog("nightShiftSubsidy doubleValue: " + doubleValue );
//// bb.writeLog("nightShiftSubsidy kqdate: " + kqdate );
// data.put(fieldName, doubleValue);
// }
//
// } else if (fieldName.equals("otherStatAllowance")) {//考勤二开--鸿仁驻点餐补
// double temp = Util.getDoubleValue(Util.null2String(flowData.get(id + "|DailyOtherStatAllowance" + "|" + kqdate )));
// if (temp <= 0.00) {
// fieldValue = "0";
// } else {
// fieldValue = String.valueOf(temp);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.put(fieldName, fieldValue);
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
if (kqReportFieldComInfo.getUnittype().equals("2") && fieldValue.length() > 0) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
data.put(fieldName, fieldValue);
}
}
// data.putAll(this.getSignDetailInfo(id, kqdate));
Map<String, Object> signDetailInfo = this.getSignDetailInfo(id, kqdate);
bb.writeLog("signDetailInfo: " + signDetailInfo);
data.putAll(signDetailInfo);
//请假
List<Map<String, Object>> allLeaveRules = KQLeaveRulesBiz.getAllLeaveRules();
Map<String, Object> leaveRule = null;
for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) {
leaveRule = (Map<String, Object>) allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_" + leaveRule.get("id"));
String leaveData = Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowType));
String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try {
//以防止出现精度问题
if (leaveData.length() == 0) {
leaveData = "0.0";
}
if (leavebackData.length() == 0) {
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(leaveData);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
} catch (Exception e) {
kqLog.info("GetKQReportCmd:leaveData" + leaveData + ":leavebackData:" + leavebackData + ":" + e);
}
//考虑下冻结的数据
if (b_flowLeaveData.length() > 0) {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
} else {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData, 0.0) - Util.getDoubleValue(leavebackData, 0.0)));
}
data.put(flowType, flowLeaveData);
}
data.put("resourceId", id);
data.put("kqdate", kqdate);
datas.add(data);
}
List<Object> lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate);
retmap.put("holidays", lsHolidays);
retmap.put("columns",columns);
retmap.put("datas",datas);
retmap.put("pagesize", pageSize);
retmap.put("pageindex", pageIndex);
retmap.put("count", count);
retmap.put("pagecount", pageCount);
retmap.put("ishavepre", isHavePre);
retmap.put("ishavenext", isHaveNext);
}catch (Exception e){
bb.writeLog("GetKQDailyReportCmd error:" + e.getMessage());
}
bb.writeLog("GetKQDailyReportCmd end.");
return retmap;
}
private String getUnitType(String unitType, User user){
String unitTypeName = "";
if(Util.null2String(unitType).length()>0){
if(unitType.equals("1")){
unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage());
}else if(unitType.equals("2")){
unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage());
}else if(unitType.equals("3")){
unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage());
}
}
return unitTypeName;
}
private Map<String,Object> getChildColumnsInfo(String parentid, User user){
Map<String,Object> returnMap = new HashMap<>();
List<Object> lsChildColumns = new ArrayList<>();
Map column = null;
int sumChildColumnWidth = 0;
if(parentid.equals("leave")){
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
for(int i=0;leaveRules!=null&&i<leaveRules.size();i++){
Map<String, Object> leaveRule = leaveRules.get(i);
String id = "leaveType_"+Util.null2String(leaveRule.get("id"));
String name = Util.null2String(leaveRule.get("name"));
String unitType = Util.null2String(leaveRule.get("unitType"));
column = new HashMap();
column.put("title", name);
column.put("unit", KQUnitBiz.isLeaveHour(unitType) ?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage()));
column.put("width", 65);
column.put("dataIndex", id);
column.put("key", id);
column.put("rowSpan", 2);
column.put("colSpan", 1);
column.put("showDetial","1");
sumChildColumnWidth+=65;
lsChildColumns.add(column);
}
}else if(parentid.equals("overtime")){
String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"};
for(int i=0;i<overtimeChild.length;i++){
String id = overtimeChild[i];
column = new HashMap();
String fieldlabel = "";
column.put("unit", "");
if("overtime_nonleave".equalsIgnoreCase(id)){
fieldlabel = "125805";
}else if("overtime_4leave".equalsIgnoreCase(id)){
fieldlabel = "125804";
}else{
fieldlabel = "523";
column.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());
}
}
column.put("unit", unitTypeName);
}
column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
column.put("dataIndex", id);
column.put("key", id);
column.put("rowSpan", 1);
Map<String,Object> mapChildColumnInfo = getChildColumnsInfo(id, user);
int childWidth = 65;
List<Object> childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("children", childColumns);
childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65);
}
column.put("width", childWidth+"");
sumChildColumnWidth+=childWidth;
lsChildColumns.add(column);
}
}else{
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()){
if(kqReportFieldComInfo.getParentid().equals(parentid)) {
if(!kqReportFieldComInfo.getReportType().equals("daily"))continue;
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
column.put("rowSpan", 2);
column.put("colSpan", 1);
column.put("isdaily", kqReportFieldComInfo.getReportType1().equals("daily")?"1":"0");
sumChildColumnWidth+=Util.getIntValue(kqReportFieldComInfo.getWidth());
lsChildColumns.add(column);
}
}
}
returnMap.put("childColumns",lsChildColumns);
returnMap.put("sumChildColumnWidth",sumChildColumnWidth);
return returnMap;
}
public Map<String, Object> getSignDetailInfo(String resourceId, String kqDate){
Map<String, Object> data = new HashMap<>();
Map<String,Object> signStatusInfo = null;
RecordSet rs = new RecordSet();
String sql = "";
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
try{
// sql = " select kqdate,resourceid,serialid,serialnumber,workbegindate,workbegintime, " +
// " workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" +
// " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," +
// " leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid \n" +
// " from kq_format_detail b \n" +
// " where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' \n" +
// " order by serialnumber \n";
/*考勤二开--增加打卡地址start*/
sql = " select a.kqdate,a.resourceid,a.serialid,a.serialnumber,a.workbegindate,a.workbegintime, " +
" a.workenddate,a.workendtime,a.workmins,a.signindate,a.signintime,a.signoutdate,a.signouttime, \n" +
" a.attendanceMins,a.belatemins,a.graveBeLateMins,a.leaveearlymins,a.graveLeaveEarlyMins,a.absenteeismmins,a.forgotcheckMins,a.forgotBeginWorkCheckMins," +
" a.leaveMins,a.leaveInfo,a.evectionMins,a.outMins,a.signinid,a.signoutid, b.addr as signinaddr, c.addr as signoutaddr \n" +
" from kq_format_detail a " +
" left join hrmschedulesign b on b.id = a.signinid \n" +
" left join hrmschedulesign c on c.id = a.signoutid \n" +
" where a.resourceid = " + resourceId + " and a.kqdate ='" + kqDate + "' \n" +
" order by a.serialnumber \n";
/*考勤二开--增加打卡地址end*/
rs.execute(sql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
String kqdate = Util.null2String(rs.getString("kqdate"));
String serialid = Util.null2String(rs.getString("serialid"));
int serialnumber = rs.getInt("serialnumber")+1;
String workbegindate = Util.null2String(rs.getString("workbegindate")).trim();
String workbegintime = Util.null2String(rs.getString("workbegintime")).trim();
String workenddate = Util.null2String(rs.getString("workenddate")).trim();
String workendtime = Util.null2String(rs.getString("workendtime")).trim();
int workMins = rs.getInt("workMins");
String signintime = Util.null2String(rs.getString("signintime")).trim();
String signouttime = Util.null2String(rs.getString("signouttime")).trim();
int attendanceMins = rs.getInt("attendanceMins");
String beLateMins = Util.null2String(rs.getString("beLateMins")).trim();
String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim();
String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim();
String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim();
String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim();
String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim();
String signinid = Util.null2String(rs.getString("signinid")).trim();
String signoutid = Util.null2String(rs.getString("signoutid")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
String signInAddr = Util.null2String(rs.getString("signinaddr"));
String signOutAddr = Util.null2String(rs.getString("signoutaddr"));
bb.writeLog("signInAddr: " + signInAddr);
bb.writeLog("signOutAddr: " + signOutAddr);
if(serialid.length()>0){
if (workbegintime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workbegindate);
signStatusInfo.put("worktime",workbegintime);
signStatusInfo.put("beLateMins",beLateMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("graveBeLateMins",graveBeLateMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime );
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
data.put("signinaddress"+serialnumber, signInAddr);
}
if (workendtime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workenddate);
signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime));
signStatusInfo.put("leaveEarlyMins",leaveEarlyMins);
signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins);
signStatusInfo.put("forgotCheckMins",forgotCheckMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime );
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
data.put("signoutaddress"+serialnumber, signOutAddr);
}
}else{
if(workMins>0){
//弹性工时打卡时间取自签到签退数据
}
signStatusInfo = new HashMap();
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
if(signinid.length() > 0){
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime );
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
data.put("signinaddress"+serialnumber, signInAddr);
if(signoutid.length() > 0){
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime );
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
data.put("signoutaddress"+serialnumber, signOutAddr);
}
}else{
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
}
}
}
}catch (Exception e){
writeLog(e);
}
return data;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,770 @@
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.hostar.util.HostarUtil;
import com.engine.kq.biz.*;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.PageUidFactory;
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 java.math.BigDecimal;
import java.util.*;
public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
BaseBean bb = new BaseBean();
public GetKQReportCmd(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 = "";
try{
bb.writeLog("GetKQReportCmd start.");
String pageUid = PageUidFactory.getHrmPageUid("KQReport");
SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
KQReportBiz kqReportBiz = new KQReportBiz();
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial"));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect =Util.null2String(jsonObj.get("typeselect"));
if(typeselect.length()==0)typeselect = "3";
if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){
if(typeselect.equals("1")){
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
}else{
fromDate = TimeUtil.getDateByOption(typeselect,"0");
toDate = TimeUtil.getDateByOption(typeselect,"1");
}
}
//人员状态
String status = Util.null2String(jsonObj.get("status"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String allLevel = Util.null2String(jsonObj.get("allLevel"));
String isNoAccount = Util.null2String(jsonObj.get("isNoAccount"));
String viewScope = Util.null2String(jsonObj.get("viewScope"));
String isFromMyAttendance = Util.null2String(jsonObj.get("isFromMyAttendance"));//是否是来自我的考勤的请求,如果是,不加载考勤报表权限共享的限制,不然我的考勤会提示无权限
int pageIndex = Util.getIntValue(Util.null2String(jsonObj.get("pageIndex")), 1);
int pageSize = KQReportBiz.getPageSize(Util.null2String(jsonObj.get("pageSize")),pageUid,user.getUID());
int count = 0;
int pageCount = 0;
int isHavePre = 0;
int isHaveNext = 0;
String rightSql = kqReportBiz.getReportRight("1",""+user.getUID(),"a");
if(isFromMyAttendance.equals("1")){
rightSql = "";
}
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
List<Object> columns = new ArrayList();
Map<String,Object> column = null;
List<Object> datas = new ArrayList();
Map<String,Object> data = null;
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("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0)continue;
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("type", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
column.put("isSystem", kqReportFieldComInfo.getIsSystem());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user);
childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("rowSpan", 1);
column.put("width", mapChildColumnInfo.get("sumChildColumnWidth"));
column.put("children", childColumns);
}else{
column.put("rowSpan", 3);
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
}
column.put("showDetial",kqReportFieldComInfo.getShowDetial());
columns.add(column);
columns.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user));
}
boolean isEnd = false;
Calendar cal = DateUtil.getCalendar();
String today = DateUtil.getCurrentDate();
// if(DateUtil.compDate(today, toDate)>0){//结束日期不大于今天
// toDate = today;
// if(DateUtil.compDate(today, fromDate)>0){//结束日期不大于今天
// fromDate = today;
// }
// }
childColumns = new ArrayList<>();
for(String date=fromDate; !isEnd;) {
if(date.equals(toDate)) isEnd = true;
column = new HashMap();
column.put("title", DateUtil.geDayOfMonth(date));
column.put("dataIndex", date);
column.put("key", date);
column.put("type", date);
column.put("rowSpan", 1);
column.put("width", 90);
column.put("isCalendar", 1);
childColumns.add(column);
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage()));
column.put("dataIndex", "kqCalendar");
column.put("key", "kqCalendar");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("rowSpan", 1);
column.put("width", childColumns.size()*90);
column.put("children", childColumns);
}
columns.add(column);
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 = " (select sum(zm.cccb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as mealAllowance," +
" (select sum(zm.zdcb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as statAllowance," +
" (select sum(zm.jmybcb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as nightAllowance," +
" (select sum(zm.hrzdcb) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as otherStatAllowance," +
" (select sum(zm.ybbz) from uf_cbxxjlb zm where zm.xm = a.id and zm.rq >= '" + fromDate + "' and zm.rq <= '" + toDate + "') as nightShiftSubsidy," +
" 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(FLOOR( b.attendanceMins / 30 ) * 30 ) 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, sum(b.zeropoint) as zeropoint "+(definedFieldSum.length()>0?","+definedFieldSum+"":"");
if(rs.getDBType().equals("oracle")){
backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields;
}
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'";
String sqlWhere = rightSql;
String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle ";
if(subCompanyId.length()>0){
sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and a.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and a.id in("+resourceId+") ";
}
if(viewScope.equals("4")){//我的下属
if(allLevel.equals("1")){//所有下属
sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'";
}else{
sqlWhere+=" and a.managerid="+user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+groupBy+") t";
rs.execute(sql);
if (rs.next()){
count = rs.getInt("c");
}
if (count <= 0) {
pageCount = 0;
}
pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0);
isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0;
isHavePre = (pageIndex - 1 >= 1) ? 1 : 0;
String orderBy = " order by t.dsporder asc, t.lastname asc ";
String descOrderBy = " order by t.dsporder desc, t.lastname desc ";
//默认排序设置 start有性能问题先取消后面再看看有没有好的方式
// String orderBySql = "select * from kq_report_order where userId=? and sort=1 order by orders";
// rs.executeQuery(orderBySql, user.getUID());
// if (rs.getCounts() <= 0) {
// orderBySql = "select * from kq_report_order where userId=0 and sort=1 order by orders";
// rs.executeQuery(orderBySql);
// }
// while (rs.next()) {
// String dataIndex = rs.getString("dataIndex");
// String ascOrDesc = rs.getString("ascOrDesc");
// String ascOrDesc1 = (ascOrDesc.equals("")||ascOrDesc.equals("asc"))?"desc":"asc";
// if (dataIndex.equals("organization")) {
// orderBy += ",showOrderOfDeptTree " + ascOrDesc + ",dept_id " + ascOrDesc;
// descOrderBy += ",showOrderOfDeptTree " + ascOrDesc1 + ",dept_id " + ascOrDesc1;
// }
// if (dataIndex.equalsIgnoreCase("dspOrder") || dataIndex.equalsIgnoreCase("lastName")) {
// orderBy += "," + dataIndex + " " + ascOrDesc + ",id " + ascOrDesc;
// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",id " + ascOrDesc1;
// } else if (dataIndex.equalsIgnoreCase("deptShowOrder") || dataIndex.equalsIgnoreCase("deptName")) {
// orderBy += "," + dataIndex + " " + ascOrDesc + ",dept_id " + ascOrDesc;
// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",dept_id " + ascOrDesc1;
// } else if (dataIndex.equalsIgnoreCase("subcomShowOrder") || dataIndex.equalsIgnoreCase("subcomName")) {
// orderBy += "," + dataIndex + " " + ascOrDesc + ",subcom_id " + ascOrDesc;
// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",subcom_id " + ascOrDesc1;
// }
// }
// orderBy = orderBy.startsWith(",") ? orderBy.substring(1) : orderBy;
// descOrderBy = descOrderBy.startsWith(",") ? descOrderBy.substring(1) : descOrderBy;
// orderBy = orderBy.equals("") ? " t.dspOrder,t.id " : orderBy;
// descOrderBy = descOrderBy.equals("") ? " t.dspOrder,t.id " : descOrderBy;
// orderBy = "order by "+orderBy;
sql = backFields + sqlFrom + sqlWhere + groupBy;
if (pageIndex > 0 && pageSize > 0) {
if (rs.getDBType().equals("oracle")) {
sql = " select * from (select " + sql+") t "+orderBy;
sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= "
+ (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize);
} else if (rs.getDBType().equals("mysql")) {
sql = " select * from (select " + sql+") t "+orderBy;
sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize;
} else if (rs.getDBType().equals("postgresql")) {
sql = " select * from (select " + sql+") t "+orderBy;
sql = "select t1.* from (" + sql + ") t1 limit " +pageSize + " offset " + ((pageIndex - 1) * pageSize);
} else {
orderBy = " order by dsporder asc, lastname asc ";
descOrderBy = " order by dsporder desc, lastname desc ";
if (pageIndex > 1) {
int topSize = pageSize;
if (pageSize * pageIndex > count) {
topSize = count - (pageSize * (pageIndex - 1));
}
sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top "
+ (pageIndex * pageSize) + sql + orderBy+ " ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy;
} else {
sql = " select top " + pageSize + sql+orderBy;
}
}
} else {
sql = " select " + sql;
}
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源
params.put("show_card_source",show_card_source);
KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz();
int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位
double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系
params.put("uintType",uintType);
params.put("hoursToDay",hoursToDay);
long startTime = System.currentTimeMillis();
Map<String,Object> flowData = kqReportBiz.getFlowData(params,user);
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime; // 执行时间
bb.writeLog("执行时间:" + elapsedTime + "毫秒" );
// /*考勤二开--驻点餐补start*/
HostarUtil hostarUtil = new HostarUtil();
// Map<String, Double> attendanceMap = new HashMap<>();
// String acqAttendanceSql = "select a.id, b.attendanceMins, b.kqdate from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"' "+sqlWhere;
// bb.writeLog("acqAttendanceSql: " + acqAttendanceSql);
// rs.executeQuery(acqAttendanceSql);
// while (rs.next()) {
// double attendanceMins = Util.getDoubleValue(Util.null2String(rs.getString("attendanceMins")));
// String id = Util.null2String(rs.getString("id"));
// String kqdate = Util.null2String(rs.getString("kqdate"));
// if (attendanceMins >= 0.00) {
// attendanceMap.put(id + "|DailyAllowance" +"|" + kqdate, attendanceMins);
// }
// }
// bb.writeLog("attendanceMap: " + attendanceMap);
// /*考勤二开--驻点餐补end*/
bb.writeLog("汇总报表--sql: " + sql);
rs.execute(sql);
while (rs.next()) {
data = new HashMap<>();
kqReportFieldComInfo.setTofirstRow();
String id = rs.getString("id");
data.put("resourceId",id);
while (kqReportFieldComInfo.next()){
if(!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1"))continue;
if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
String fieldName = kqReportFieldComInfo.getFieldname();
String fieldValue = "";
if(fieldName.equals("subcompany")){
String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid"));
if(tmpSubcompanyId.length()==0){
tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id));
}
data.put("subcompanyId",tmpSubcompanyId);
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") :
subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
// fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
}else if(fieldName.equals("department")){
String tmpDepartmentId = Util.null2String(rs.getString("departmentid"));
if(tmpDepartmentId.length()==0){
tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id));
}
data.put("departmentId",tmpDepartmentId);
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") :
departmentComInfo.getDepartmentname(tmpDepartmentId);
// fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId);
}else if(fieldName.equals("jobtitle")){
String tmpJobtitleId = Util.null2String(rs.getString("jobtitle"));
if(tmpJobtitleId.length()==0){
tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id));
}
data.put("jobtitleId",tmpJobtitleId);
fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId);
}else if(fieldName.equals("attendanceSerial")){
List<String> serialIds = null;
if(attendanceSerial.length()>0){
serialIds = Util.splitString2List(attendanceSerial,",");
}
for(int i=0;serialIds!=null&&i<serialIds.size();i++){
data.put(serialIds.get(i), kqReportBiz.getSerialCount(id,fromDate,toDate,serialIds.get(i)));
}
}else if(kqReportFieldComInfo.getParentid().equals("overtime")||kqReportFieldComInfo.getParentid().equals("overtime_nonleave")
||kqReportFieldComInfo.getParentid().equals("overtime_4leave")||fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
if(fieldName.equals("overtimeTotal")){
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|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));
}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{
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id+"|"+fieldName)));
}
// } else if ("mealAllowance".equals(fieldName)) {//考勤二开--出差餐补
//// bb.writeLog("mealAllowance");
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, "DailyMealAllow|" + resourceId);
//// bb.writeLog("tempMap: " + tempMap);
//
// if ( !tempMap.isEmpty()) {
// int tempValue = 0;
// for (String key: tempMap.keySet()) {
// int intValue = Util.getIntValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(intValue, 0));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.put(fieldName, fieldValue);
// } else if ("statAllowance".equals(fieldName)) {//考勤二开--驻点餐补
// bb.writeLog("statAllowance");
//
// params.put("statUser", id);
// bb.writeLog("params: " + params );
//
// Map<String, Object> temp = kqReportBiz.getStatAllowanceData(params, user);
// if (temp == null || temp.size() == 0) {
// data.put(fieldName, "0");
// } else {
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(temp, id + "|StatAllowance");
//
//// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, id + "|DailyStatAllowance");
//// bb.writeLog("tempMap: " + tempMap);
// if ( !tempMap.isEmpty()) {
// double tempValue = 0.00;
// for (String key: tempMap.keySet()) {
// double doubleValue = Util.getDoubleValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(doubleValue, 0.00));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.put(fieldName, fieldValue);
// }
//
//
// } else if ("nightAllowance".equals(fieldName)) {//考勤二开--精密夜班餐补
//// bb.writeLog("nightAllowance");
//// bb.writeLog("flowData: " + flowData);
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, id + "|DailyNightShiftAllowanceData");
//// bb.writeLog("tempMap: " + tempMap);
// if ( !tempMap.isEmpty()) {
// double tempValue = 0.00;
// for (String key: tempMap.keySet()) {
// double doubleValue = Util.getDoubleValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(doubleValue, 0.00));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.put(fieldName, fieldValue);
// } else if ("nightShiftSubsidy".equals(fieldName)) {//考勤二开--夜班补助
// params.put("subUserId", id);
// bb.writeLog("params: " + params );
//
// Map<String, Object> temp = kqReportBiz.getDailyNightShiftSubsidyData(params, user);
// if (temp == null || temp.size() == 0) {
// data.put(fieldName, "0");
// } else {
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(temp, id + "|DailyNightShiftSubsidyData");
//
// if ( !tempMap.isEmpty()) {
// int tempValue = 0;
// for (String key: tempMap.keySet()) {
// int intValue = Util.getIntValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(intValue, 0));
// }
// fieldValue = String.valueOf(tempValue);
// }
// data.put(fieldName, fieldValue);
// }
//
// } else if ("otherStatAllowance".equals(fieldName)) {//考勤二开--鸿仁驻点餐补
//// bb.writeLog("otherStatAllowance");
//// bb.writeLog("flowData: " + flowData);
// Map<String, Object> tempMap = hostarUtil.parseMapForFilter(flowData, id + "|DailyOtherStatAllowance");
//// bb.writeLog("tempMap: " + tempMap);
// if ( !tempMap.isEmpty()) {
// double tempValue = 0.00;
// for (String key: tempMap.keySet()) {
// double doubleValue = Util.getDoubleValue(Util.null2String(tempMap.get(key)));
// tempValue = tempValue + (Math.max(doubleValue, 0.00));
// }
// fieldValue = String.valueOf(tempValue);
// }
//// bb.writeLog("fieldValue: " + fieldValue);
// data.put(fieldName, fieldValue);
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
if(Util.null2String(kqReportFieldComInfo.getUnittype()).length()>0) {
if(fieldValue.length() == 0){
fieldValue="0";
}else{
if (kqReportFieldComInfo.getUnittype().equals("2")) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
}
}
}
data.put(fieldName,fieldValue);
}
//请假
List<Map<String, Object>> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules();
Map<String, Object> leaveRule = null;
for(int i=0;allLeaveRules!=null&&i<allLeaveRules.size();i++){
leaveRule = (Map<String, Object>)allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_"+leaveRule.get("id"));
String leaveData = Util.null2String(flowData.get(id+"|"+flowType));
String flowLeaveBackType = Util.null2String("leavebackType_"+leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+flowLeaveBackType)),"0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try{
//以防止出现精度问题
if(leaveData.length() == 0){
leaveData = "0.0";
}
if(leavebackData.length() == 0){
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(leaveData);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
}catch (Exception e){
writeLog("GetKQReportCmd:leaveData"+leaveData+":leavebackData:"+leavebackData+":"+e);
}
//考虑下冻结的数据
if(b_flowLeaveData.length() > 0){
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
}else{
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData,0.0)-Util.getDoubleValue(leavebackData,0.0)));
}
data.put(flowType,flowLeaveData);
}
Map<String,Object> detialDatas = kqReportBiz.getDetialDatas(id,fromDate,toDate,user,flowData,false,uintType,show_card_source);
// new KQLog().info("id:"+id+":detialDatas:"+detialDatas);
isEnd = false;
for(String date=fromDate; !isEnd;) {
if(date.equals(toDate)) isEnd = true;
if(DateUtil.compDate(today, date)>0){
data.put(date,"");
}else{
// new KQLog().info("id:date:"+(id+"|"+date)+":detialDatas.get:"+detialDatas.get(id+"|"+date));
data.put(date,detialDatas.get(id+"|"+date)==null?SystemEnv.getHtmlLabelName(26593, user.getLanguage()):detialDatas.get(id+"|"+date));
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
datas.add(data);
}
List<Object> lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate);
retmap.put("holidays", lsHolidays);
retmap.put("columns",columns);
retmap.put("datas",datas);
retmap.put("pagesize", pageSize);
retmap.put("pageindex", pageIndex);
retmap.put("count", count);
retmap.put("pagecount", pageCount);
retmap.put("ishavepre", isHavePre);
retmap.put("ishavenext", isHaveNext);
}catch (Exception e){
writeLog(e);
bb.writeLog("GetKQReportCmd Exception: " + e.getMessage());
}
return retmap;
}
private Map<String,Object> getChildColumnsInfo(String parentid, User user){
Map<String,Object> returnMap = new HashMap<>();
List<Object> lsChildColumns = new ArrayList<>();
Map column = null;
int sumChildColumnWidth = 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++){
column = new HashMap();
column.put("title", kqShiftManagementComInfo.getSerial(serialIds.get(i)));
column.put("unit", "");
column.put("width", 65);
column.put("dataIndex", serialIds.get(i));
column.put("key", serialIds.get(i));
column.put("rowSpan", 2);
column.put("colSpan", 1);
sumChildColumnWidth+=65;
lsChildColumns.add(column);
}
}else if(parentid.equals("leave")){
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
for(int i=0;leaveRules!=null&&i<leaveRules.size();i++){
Map<String, Object> leaveRule = leaveRules.get(i);
String id = "leaveType_"+Util.null2String(leaveRule.get("id"));
String name = Util.null2String(leaveRule.get("name"));
String unitType = Util.null2String(leaveRule.get("unitType"));
column = new HashMap();
column.put("title", name);
column.put("unit", KQUnitBiz.isLeaveHour(unitType) ?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage()));
column.put("width", 65);
column.put("dataIndex", id);
column.put("key", id);
column.put("rowSpan", 2);
column.put("colSpan", 1);
column.put("showDetial","1");
sumChildColumnWidth+=65;
lsChildColumns.add(column);
}
}else if(parentid.equals("overtime")){
String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"};
for(int i=0;i<overtimeChild.length;i++){
String id = overtimeChild[i];
column = new HashMap();
String fieldlabel = "";
column.put("unit", "");
if("overtime_nonleave".equalsIgnoreCase(id)){
fieldlabel = "125805";
}else if("overtime_4leave".equalsIgnoreCase(id)){
fieldlabel = "125804";
}else{
fieldlabel = "523";
column.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());
}
}
column.put("unit", unitTypeName);
}
column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
column.put("dataIndex", id);
column.put("key", id);
column.put("rowSpan", 1);
Map<String,Object> mapChildColumnInfo = getChildColumnsInfo(id, user);
int childWidth = 65;
List<Object> childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("children", childColumns);
childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65);
}
column.put("width", childWidth+"");
sumChildColumnWidth+=childWidth;
lsChildColumns.add(column);
}
}else{
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()){
if(kqReportFieldComInfo.getParentid().equals(parentid)) {
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
column.put("rowSpan", 1);
column.put("colSpan", 1);
column.put("showDetial",kqReportFieldComInfo.getShowDetial());
sumChildColumnWidth+=Util.getIntValue(kqReportFieldComInfo.getWidth());
lsChildColumns.add(column);
}
}
}
returnMap.put("childColumns",lsChildColumns);
returnMap.put("sumChildColumnWidth",sumChildColumnWidth);
return returnMap;
}
private List<Object> getCascadeKeyColumnsInfo(String cascadeKey, User user){
List<Object> lsChildColumns = new ArrayList<>();
if(Util.null2String(cascadeKey).length()==0){
return lsChildColumns;
}
Map<String,Object> column = null;
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))){
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
column.put("rowSpan", 1);
column.put("colSpan", 1);
column.put("showDetial",kqReportFieldComInfo.getShowDetial());
column.put("isSystem", kqReportFieldComInfo.getIsSystem());
lsChildColumns.add(column);
}
}
}
return lsChildColumns;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,202 @@
package weaver.formmode.customjavacode.modeexpand;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.engine.kq.biz.KQFormatBiz;
import com.engine.kq.timer.KQQueue;
import com.engine.kq.timer.KQTaskBean;
import com.engine.kq.wfset.util.SplitActionUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;
/**
*
*/
public class AddScheduleSign extends AbstractModeExpandJavaCodeNew {
/**
*
* @param param
* param()
* user
* importtype () 1 2,3(int)param.get("importtype")
* ()a=1param.get("a")
* b=2,param.get("b")
* @return
*/
public Map<String, String> doModeExpand(Map<String, Object> param) {
Map<String, String> result = new HashMap<String, String>();
try {
User user = (User)param.get("user");
int billid = -1;//数据id
int modeid = -1;//模块id
RequestInfo requestInfo = (RequestInfo)param.get("RequestInfo");
if(requestInfo!=null){
billid = Util.getIntValue(requestInfo.getRequestid());
modeid = Util.getIntValue(requestInfo.getWorkflowid());
if(billid>0&&modeid>0){
//------请在下面编写业务逻辑代码------
BaseBean bb = new BaseBean();
bb.writeLog("AddScheduleSign Start");
RecordSet rs = new RecordSet();
List<List> addParams = new ArrayList<>();
List<String> lsFormatData = new ArrayList<>();
Map<String, String> signFromMap = new HashMap<String, String>();
signFromMap.put( "0","e9pc");
signFromMap.put( "1","e9mobile");
signFromMap.put( "2","e9e");
signFromMap.put( "3","e9ewx");
signFromMap.put( "4","card");
signFromMap.put( "5","e9_mobile_out");
signFromMap.put( "6","importExcel");
signFromMap.put( "7","EMSyn");
signFromMap.put( "8","OutDataSourceSyn");
signFromMap.put( "9","DingTalk");
signFromMap.put( "10","DingTalk_out");
signFromMap.put( "11","Wechat_out");
signFromMap.put( "12","Wechat");
//获取新插入的数据
String acqSignDataSql = "select userid, usertype, signtype, signdate, signtime, clientaddress, isincom," +
" signfrom, longitude, latitude, addr, isimport, suuid, timezone, belongdate, memo, deviceinfo, showaddress " +
" from uf_schsignaddlog where id = ?";
bb.writeLog("acqSignDataSql: " + acqSignDataSql);
rs.executeQuery(acqSignDataSql, billid);
while (rs.next()) {
String userid = Util.null2String(rs.getString("userid"));
String usertype = Util.null2String(rs.getString("usertype"));
String signtype = Util.null2String(rs.getString("signtype"));
String signdate = Util.null2String(rs.getString("signdate"));
String signtime = Util.null2String(rs.getString("signtime"));
String clientaddress = Util.null2String(rs.getString("clientaddress"));
String isincom = Util.null2String(rs.getString("isincom"));
String signfrom = Util.null2String(rs.getString("signfrom"));
String longitude = Util.null2String(rs.getString("longitude"));
String latitude = Util.null2String(rs.getString("latitude"));
String addr = Util.null2String(rs.getString("addr"));
String isimport = Util.null2String(rs.getString("isimport"));
String suuid = Util.null2String(rs.getString("suuid"));
String timezone = Util.null2String(rs.getString("timezone"));
String belongdate = Util.null2String(rs.getString("belongdate"));
String memo = Util.null2String(rs.getString("memo"));
String deviceinfo = Util.null2String(rs.getString("deviceinfo"));
String showaddress = Util.null2String(rs.getString("showaddress"));
if (signtime.length() == 5) {
signtime = signtime + ":00";
}
bb.writeLog("signfrom: " + signfrom);
if (StringUtils.isNotBlank(signfrom)) {
signfrom = signFromMap.get(signfrom);
}
bb.writeLog("--signfrom: " + signfrom);
List addPa = new ArrayList<>();
addPa.add(userid);
addPa.add(usertype);
addPa.add(signtype);
addPa.add(signdate);
addPa.add(signtime);
addPa.add(clientaddress);
addPa.add(isincom);
addPa.add(signfrom);
addPa.add(longitude);
addPa.add(latitude);
addPa.add(addr);
addPa.add(isimport);
addPa.add(suuid);
addPa.add(timezone);
addPa.add(belongdate);
addPa.add(memo);
addPa.add(deviceinfo);
addPa.add(showaddress);
addParams.add(addPa);
String formatData = userid + "|" + signdate + "|" + signtime;
if (!lsFormatData.contains(formatData)) {
lsFormatData.add(formatData);
}
}
bb.writeLog("addParams: " + addParams);
String addSchSignSql = "insert into hrmschedulesign (userid, usertype, signtype, signdate, signtime, clientaddress, isincom, " +
" signfrom, longitude, latitude, addr, isimport, suuid, timezone, belongdate, memo, deviceinfo, showaddress ) values " +
" (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
bb.writeLog("addSchSignSql: " + addSchSignSql);
rs.executeBatchSql(addSchSignSql, addParams);
//触发考勤格式化计算和加班
//刷新报表数据
List<Object> formatParams = null;
List<List<Object>> lsFormatParams = new ArrayList<>();
Map<String,List<String>> overtimeMap = Maps.newHashMap();
List<String> overtimeList = Lists.newArrayList();
bb.writeLog("开始处理考勤数据生成");
for(int i=0;lsFormatData!=null&&i<lsFormatData.size();i++){
formatParams = new ArrayList<>();
String[] formatData = Util.splitString(lsFormatData.get(i),"|");
String date_1 = weaver.common.DateUtil.addDate(formatData[1], -1);
formatParams.add(formatData[0]);
formatParams.add(date_1);
lsFormatParams.add(formatParams);
formatParams = new ArrayList<>();
formatParams.add(formatData[0]);
formatParams.add(formatData[1]);
lsFormatParams.add(formatParams);
String resourceId = formatData[0];
String kqdate = formatData[1];
if(overtimeMap.containsKey(resourceId)){
List<String> tmp_overtimeList = overtimeMap.get(resourceId);
if(!tmp_overtimeList.contains(kqdate)){
tmp_overtimeList.add(kqdate);
}
}else{
if(!overtimeList.contains(kqdate)){
overtimeList.add(kqdate);
}
overtimeMap.put(resourceId, overtimeList);
}
}
new KQFormatBiz().format(lsFormatParams);
bb.writeLog("开始处理加班生成");
//处理加班生成
List<KQTaskBean> tasks = new ArrayList<>();
for(Map.Entry<String, List<String>> mme: overtimeMap.entrySet()){
String resid = mme.getKey();
List<String> overList = mme.getValue();
for(String date : overList){
SplitActionUtil.pushOverTimeTasks(date,date,resid,tasks);
}
}
if(!tasks.isEmpty()){
KQQueue.writeTasks(tasks);
}
}
}
} catch (Exception e) {
result.put("errmsg","手动添加原始打卡记录失败!");
result.put("flag", "false");
}
return result;
}
}

@ -0,0 +1,94 @@
package weaver.interfaces.hostar.action;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.hutool.http.Method.POST;
/**
* action
*
*
* @author xuxy
* @version 1.00
* @Date 2024/4/1
*/
@Slf4j
public class EmployeeDeleteAction implements Action {
@Override
public String execute(RequestInfo requestInfo) {
BaseBean bb = new BaseBean();
//获取主表数据
Map mainInfo = getMainInfo(requestInfo);
log.info("-EmployeeDeleteAction-主表数据是:"+ JSONObject.toJSONString(mainInfo));
//此处获取主表字段信息
String gh = Util.null2String(mainInfo.get("gh"));//工号
Map<String,String> map = new HashMap<>();
String jsonParam;
String url = Util.null2String(bb.getPropValue("project_hostar", "employeeDelete"));
map.put("jobNo",gh);
jsonParam = JSONObject.toJSONString(map);
String res = callPost(url, jsonParam);
log.info("-EmployeeDeleteAction-接口返回结果res{}",res);
Map mapTypes = new HashMap<>();
if(StringUtils.isNotBlank(res)){
mapTypes = JSON.parseObject(res);
log.info("-EmployeeDeleteAction-mapTypes{}",mapTypes);
}
if(mapTypes.get("code").equals(200)){
log.info("安防接口删除人员信息接口返回成功!");
requestInfo.getRequestManager().setMessagecontent("安防接口删除人员信息接口返回成功!");
return Action.SUCCESS;
}
log.error("接口异常!");
requestInfo.getRequestManager().setMessagecontent("接口异常!");
return Action.FAILURE_AND_CONTINUE;
}
public static String callPost(String url,String jsonParam){
return HttpRequest.post(url).method(POST).header("Content-Type","application/json").body(jsonParam).execute().body();
}
/**
* requestInfo
* */
public static Map<String,Object> getMainInfo(RequestInfo requestInfo){
Map<String,Object> map = new HashMap();
Property[] property = requestInfo.getMainTableInfo().getProperty();
for (int i = 0; i < property.length; i++) {
map.put(property[i].getName().toLowerCase(), Util.null2String(property[i].getValue()));
}
return map;
}
/**
* requestInfo
* */
public static List getDetailInfo(RequestInfo requestInfo, int num){
DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(num);
//dtltable数组中的行数据集合
Row[] rows = detailTable.getRow();
List sublist = new ArrayList();
for (int i = 0; i < rows.length; i++) {
Row row = rows[i];
Map onerow = new HashMap();
sublist.add(onerow);
Cell[] cells = row.getCell();
for (int j = 0; j < cells.length; j++) {
Cell cell = cells[j];
onerow.put(cell.getName(), Util.null2String(cell.getValue()));
}
}
return sublist;
}
}

@ -0,0 +1,106 @@
package weaver.interfaces.hostar.action;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.hutool.http.Method.POST;
/**
* action
*
*
* @author xuxy
* @version 1.00
* @Date 2024/4/1
*/
@Slf4j
public class EmployeeInsertAction implements Action {
@Override
public String execute(RequestInfo requestInfo) {
BaseBean bb = new BaseBean();
//获取主表数据
Map mainInfo = getMainInfo(requestInfo);
log.info("-EmployeeInsertAction-主表数据是:"+ JSONObject.toJSONString(mainInfo));
//此处获取主表字段信息
String xm = Util.null2String(mainInfo.get("xm"));//姓名
String xb = Util.null2String(mainInfo.get("xb"));//性别
String bm = Util.null2String(mainInfo.get("bm"));//部门
String sjhm = Util.null2String(mainInfo.get("sjhm"));//手机号
String zjhm = Util.null2String(mainInfo.get("zjhm"));//身份证号
String rybh = Util.null2String(mainInfo.get("rybh"));//人员编号
Map<String,String> map = new HashMap<>();
String jsonParam;
String url = Util.null2String(bb.getPropValue("project_hostar", "employeeInsert"));
map.put("personName",xm);
map.put("gender","0".equals(xb)?"1":"2");
map.put("orgIndexCode",bm);
map.put("phoneNo",sjhm);
map.put("certificateType","111");
map.put("certificateNo",zjhm);
map.put("jobNo",rybh);
jsonParam = JSONObject.toJSONString(map);
String res = callPost(url, jsonParam);
log.info("-EmployeeInsertAction-接口返回结果res{}",res);
Map mapTypes = new HashMap<>();
if(StringUtils.isNotBlank(res)){
mapTypes = JSON.parseObject(res);
log.info("-EmployeeInsertAction-mapTypes{}",mapTypes);
}
if(mapTypes.get("code").equals(200)){
log.info("安防接口同步人员信息接口返回成功!");
requestInfo.getRequestManager().setMessagecontent("安防接口同步人员信息接口返回成功!");
return Action.SUCCESS;
}
log.error("接口异常!");
requestInfo.getRequestManager().setMessagecontent("接口异常!");
return Action.FAILURE_AND_CONTINUE;
}
public static String callPost(String url,String jsonParam){
return HttpRequest.post(url).method(POST).header("Content-Type","application/json").body(jsonParam).execute().body();
}
/**
* requestInfo
* */
public static Map<String,Object> getMainInfo(RequestInfo requestInfo){
Map<String,Object> map = new HashMap();
Property[] property = requestInfo.getMainTableInfo().getProperty();
for (int i = 0; i < property.length; i++) {
map.put(property[i].getName().toLowerCase(), Util.null2String(property[i].getValue()));
}
return map;
}
/**
* requestInfo
* */
public static List getDetailInfo(RequestInfo requestInfo, int num){
DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(num);
//dtltable数组中的行数据集合
Row[] rows = detailTable.getRow();
List sublist = new ArrayList();
for (int i = 0; i < rows.length; i++) {
Row row = rows[i];
Map onerow = new HashMap();
sublist.add(onerow);
Cell[] cells = row.getCell();
for (int j = 0; j < cells.length; j++) {
Cell cell = cells[j];
onerow.put(cell.getName(), Util.null2String(cell.getValue()));
}
}
return sublist;
}
}

@ -0,0 +1,167 @@
package weaver.interfaces.hostar.action;
import com.engine.kq.biz.KQFormatBiz;
import com.engine.kq.wfset.util.SplitActionUtil;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class OutSignSyncAction implements Action {
BaseBean bb = new BaseBean();
@Override
public String execute(RequestInfo requestInfo) {
bb.writeLog("OutSignSyncAction-start");
String startDate = "";
String endDate = "";
String resourceid = "";
String nbtxr = "";
String sjjsrq = "";
try {
Property[] properties = requestInfo.getMainTableInfo().getProperty();
for (Property property : properties) {
if ("ksrq".equals(property.getName())) {
startDate = Util.null2String(property.getValue());
}
if ("yjjsrq".equals(property.getName())) {
endDate = Util.null2String(property.getValue());
}
if ("sjccr".equals(property.getName())) {
resourceid = Util.null2String(property.getValue());
}
if ("nbtxr".equals(property.getName())) {
nbtxr = Util.null2String(property.getValue());
}
if ("sjjsrq".equals(property.getName())) {
sjjsrq = Util.null2String(property.getValue());
}
}
// 如果实际结束日期不为空,则用实际结束日期
if (StringUtils.isNotBlank(sjjsrq)) {
endDate = sjjsrq;
}
bb.writeLog("start to handle data.");
if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(resourceid)) {
// 内部同行人也要考虑
if (StringUtils.isNotBlank(nbtxr)) {
resourceid = resourceid + "," + nbtxr;
}
RecordSet rs = new RecordSet();
List<String> infos = new ArrayList<>();
String acqOutSignSql = "select a.id, c.signinfo " +
"from mobile_sign a " +
"left join uf_outsigntype c " +
"on c.outsignid = a.id " +
"where operate_date >= '" + startDate + "' and operate_date <= '" + endDate + "' and operater in (?) ";
rs.executeQuery(acqOutSignSql, resourceid);
while (rs.next()) {
String signinfo = Util.null2String(rs.getString("signinfo"));
infos.add(signinfo);
}
bb.writeLog("infos is:" + infos);
for (String inf : infos) {
if (StringUtils.isNotEmpty(inf)) {
Map<String, Object> in = mapStringToMap(inf);
String userId = Util.null2String(in.get("userId"));
String userType = Util.null2String(in.get("userType"));
String signType = Util.null2String(in.get("signType"));
String signDate = Util.null2String(in.get("signDate"));
String signTime = Util.null2String(in.get("signTime"));
String clientAddress = Util.null2String(in.get("clientAddress"));
String isInCom = Util.null2String(in.get("isInCom"));
String timeZone = Util.null2String(in.get("timeZone"));
String belongdate = Util.null2String(in.get("belongdate"));
String signfrom = Util.null2String(in.get("signfrom"));
String longitude = Util.null2String(in.get("longitude"));
String latitude = Util.null2String(in.get("latitude"));
String address = Util.null2String(in.get("address"));
String deviceInfo = Util.null2String(in.get("deviceInfo"));
String belongdateIsNull = Util.null2String(in.get("belongdateIsNull"));
String punchSql = "insert into HrmScheduleSign(userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo,isdev) " +
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
boolean isok = rs.executeUpdate(punchSql, resourceid, userType, signType, signDate, signTime, clientAddress, isInCom,
timeZone, belongdate, signfrom, longitude, latitude, address, deviceInfo, "1");
bb.writeLog("isok: " + isok);
//同步更新考勤数据到考勤报表
if ("true".equals(belongdateIsNull)) {
//外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤
bb.writeLog("PunchOutButtonCmd:userId:" + userId + ":belongdate:" + DateUtil.getYesterday());
new KQFormatBiz().formatDate("" + userId, DateUtil.getYesterday());
}
bb.writeLog("PunchOutButtonCmd:userId:" + userId + ":belongdate:" + (belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
if (belongdate.length() == 0) {
//外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤
new KQFormatBiz().formatDate("" + userId, DateUtil.getYesterday());
}
new KQFormatBiz().formatDate("" + userId, (belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate));
//外勤签到转的考勤 处理加班规则
SplitActionUtil.pushOverTimeTasksAll(belongdate, belongdate, "" + userId);
}
}
}
} catch (Exception e) {
bb.writeLog("OutSignSyncAction Exception: " + e.getMessage());
return Action.FAILURE_AND_CONTINUE;
}
return Action.SUCCESS;
}
public static Map<String, Object> mapStringToMap(String str) {
str = str.substring(1, str.length() - 1);
List<String> strs = splitString(str);
Map<String, Object> map = new HashMap<>();
for (String string : strs) {
String[] splits = string.split("=");
String key = splits[0];
String value = "";
if (splits.length > 1) {
value = splits[1];
}
// 去掉头部空格
String key1 = key.trim();
String value1 = value.trim();
map.put(key1, value1);
}
return map;
}
public static List<String> splitString(String input) {
List<String> result = new ArrayList<>();
int braceLevel = 0;
int startIndex = 0;
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (ch == '{') {
braceLevel++;
} else if (ch == '}') {
braceLevel--;
} else if (ch == ',' && braceLevel == 0) {
result.add(input.substring(startIndex, i));
startIndex = i + 1;
}
}
if (startIndex < input.length()) {
result.add(input.substring(startIndex));
}
return result;
}
}

@ -0,0 +1,173 @@
package weaver.interfaces.hostar.job;
import com.engine.hostar.util.HostarUtil;
import com.engine.kq.biz.KQGroupMemberComInfo;
import com.engine.kq.biz.KQHolidaySetBiz;
import com.engine.kq.biz.KQOvertimeRulesBiz;
import jdk.management.resource.ResourceId;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.util.DateUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
public class AddOvertimeSignJob extends BaseCronJob {
private String fromDate;
private String toDate;
public String getFromDate() {
return fromDate;
}
public String getToDate() {
return toDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
BaseBean bb= new BaseBean();
@Override
public void execute() {
bb.writeLog("AddOvertimeSignJob Start");
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
bb.writeLog("fromDate: " + fromDate);
bb.writeLog("toDate: " + toDate);
if ( StringUtils.isBlank(fromDate) || StringUtils.isBlank(toDate)) {
toDate = DateUtils.format(new Date(), "yyyy-MM-dd");
LocalDate specifiedDate = LocalDate.parse(toDate, formatter);
// 获取三天前的日期
LocalDate threeDaysAgo = specifiedDate.minusDays(3);
fromDate = threeDaysAgo.format(formatter);
}
bb.writeLog("--fromDate: " + fromDate);
bb.writeLog("--toDate: " + toDate);
RecordSet rs = new RecordSet();
String overtimeWorkflow = Util.null2String(bb.getPropValue("project_hostar", "overtimeWorkflow"));
bb.writeLog("overtimeWorkflow: " + overtimeWorkflow);
if (StringUtils.isNotBlank(overtimeWorkflow)) {
HostarUtil hostarUtil = new HostarUtil();
List<String> allDates = hostarUtil.getAllDates(fromDate, toDate);
bb.writeLog("allDates: " + allDates);
for (String date: allDates) {
List<Map<String, Object>> overtimeInfo = new ArrayList<>();
//获取加班流程
String acqOvertimeSql = "select a.resourceId, a.fromDate, a.toDate, a.fromTime, a.toTime from " + overtimeWorkflow + " a " +
" left join workflow_requestbase b" +
" on b.requestid = a.requestid and b.currentnodetype = 3" +
" where a.fromDate = '" + date + "'";
bb.writeLog("acqOvertimeSql: " + acqOvertimeSql);
rs.executeQuery(acqOvertimeSql);
while (rs.next()) {
String resourceId = Util.null2String(rs.getString("resourceId"));
String fromDate = Util.null2String(rs.getString("fromDate"));
String fromTime = Util.null2String(rs.getString("fromTime"));
String toDate = Util.null2String(rs.getString("toDate"));
String toTime = Util.null2String(rs.getString("toTime"));
if (StringUtils.isNotBlank(fromDate) && StringUtils.isNotBlank(toDate) && StringUtils.isNotBlank(resourceId)) {
if (toDate.compareTo(fromDate) > 0 ) {
KQOvertimeRulesBiz kb = new KQOvertimeRulesBiz();
int changeType = kb.getChangeType(resourceId, fromDate);
bb.writeLog("changeType: " + changeType);
if (changeType != -1) {
Map<String, Object> temp = new HashMap<>();
temp.put("resourceId", resourceId);
temp.put("fromDate", fromDate);
temp.put("fromTime", fromTime);
temp.put("toDate", toDate);
temp.put("toTime", toTime);
overtimeInfo.add(temp);
}
}
}
}
bb.writeLog("overtimeInfo: " + overtimeInfo);
//根据加班流程信息取打卡信息
for ( Map<String, Object> info: overtimeInfo) {
String resourceId = Util.null2String(info.get("resourceId"));
String fromDate = Util.null2String(info.get("fromDate"));
String fromTime = Util.null2String(info.get("fromTime"));
String toDate = Util.null2String(info.get("toDate"));
String toTime = Util.null2String(info.get("toTime"));
bb.writeLog("resourceId: " + resourceId + ", fromDate: " + fromDate + ", fromTime: " + fromTime + ", toDate: " + toDate + ", toTime: " + toTime);
// 将字符串时间转换为LocalDateTime对象
if (toTime.length() == 5) {
toTime = toTime + ":00";
}
LocalDateTime dateTime = LocalDateTime.parse(toDate + " " + toTime, formatter2);
// 获取指定时间前后三小时的时间范围
LocalDateTime startDateTimeL = dateTime.minus(3, ChronoUnit.HOURS);
LocalDateTime endDateTimeL = dateTime.plus(3, ChronoUnit.HOURS);
String startDateTime = startDateTimeL.format(formatter2);
bb.writeLog("startDateTime: " + startDateTime);
String endDateTime = endDateTimeL.format(formatter2);
bb.writeLog("endDateTime: " + endDateTime);
Integer number = -1;
String acqSignSql = "select count(*) as number from hrmschedulesign " +
" where signdate + ' '+signTime >='"+startDateTime+"' and signdate + ' '+signTime <='"+endDateTime+"' " +
" and userid = ? and signtype = 2 ";
bb.writeLog("--acqSignSql: " + acqSignSql);
rs.executeQuery(acqSignSql, resourceId);
while (rs.next()) {
number = Util.getIntValue(Util.null2String(rs.getString("number")));
}
bb.writeLog("number: " + number);
if (number > 0) {
//插入0点打卡
String addSign1Sql = "insert into hrmschedulesign (userId,userType,signType,signDate,signTime,isInCom,signfrom,timeZone,belongDate) " +
" values (?,?,?,?,?,?,?,?,?)";
boolean b1 = rs.executeUpdate(addSign1Sql, resourceId, "1", "2", fromDate, "23:59:59", "1", "e9pc", "GMT+8", date);
bb.writeLog("插入23点59分打卡: " + b1);
//插入0点打卡
String addSign2Sql = "insert into hrmschedulesign (userId,userType,signType,signDate,signTime,isInCom,signfrom,timeZone,belongDate) " +
" values (?,?,?,?,?,?,?,?,?)";
boolean b2 = rs.executeUpdate(addSign2Sql, resourceId, "1", "2", toDate, "00:00:00", "1", "e9pc", "GMT+8", date);
bb.writeLog("插入0点打卡: " + b2);
} else {
bb.writeLog("没有在指定时间范围内打下班卡无法插入0点卡");
}
}
}
} else {
bb.writeLog("没有设置加班流程");
}
}catch (Exception e) {
bb.writeLog("AddOvertimeSignJob Exception: " + e);
}
}
}

@ -0,0 +1,133 @@
package weaver.interfaces.hostar.job;
import com.engine.kq.biz.KQHolidaySetBiz;
import com.engine.kq.biz.KQWorkTime;
import com.engine.kq.entity.WorkTimeEntity;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class AutoScheduNextMonthJob extends BaseCronJob {
private String fromDate;
private String toDate;
public String getFromDate() {
return fromDate;
}
public String getToDate() {
return toDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
BaseBean bb= new BaseBean();
private final List<String> LIST = new ArrayList<>();
@Override
public void execute() {
bb.writeLog("AutoSchedulJob Start");
try {
//DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//bb.writeLog("fromDate: " + fromDate);
//bb.writeLog("toDate: " + toDate);
//当前日期
//toDate = DateUtils.format(new Date(), "yyyy-MM-dd");
RecordSet rs = new RecordSet();
boolean b = false;
String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)";
//责任制考勤组id收集
rs.executeQuery("select kqzid from uf_zrzkqz");
while (rs.next()) {
LIST.add(Util.null2String(rs.getString("kqzid")));
}
bb.writeLog("AutoScheduNextMonthJob.LIST" + LIST);
List<String> userList = new ArrayList<>();
//查询指定和考勤组成员
String query_sql = "select distinct typevalue from kq_groupmember where groupid in" + "('" + String.join("','", LIST) + "')";
rs.execute(query_sql);
while (rs.next()) {
userList.add(Util.null2String(rs.getString("typevalue")));
}
bb.writeLog("AutoScheduNextMonthJob.userList: " + userList);
//查询固班制人员节假日设置
String fixedSerialid = Util.null2String(bb.getPropValue("project_hostar", "fixedSerialid"));
String defaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "defaultSerialid"));
String weekendDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "weekendDefaultSerialid"));
String holidayDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "holidayDefaultSerialid"));
bb.writeLog("AutoScheduNextMonthJob.fixedSerialid:{},defaultSerialid:{},weekendDefaultSerialid{},holidayDefaultSerialid:{} " + fixedSerialid+defaultSerialid+weekendDefaultSerialid+holidayDefaultSerialid);
String fixedUserId = "";
//查询指定和考勤组成员
String query = "select distinct typevalue from kq_groupmember where groupid = ? ";
rs.executeQuery(query,fixedSerialid);
if (rs.next()) {
fixedUserId = rs.getString("typevalue");
}
bb.writeLog("AutoScheduNextMonthJob.fixedUserId: " + fixedUserId);
//查询下个月的全部日期
List<String> nextMonthDates = getNextMonthDates();
//排默认班次
for (String userId : userList) {
for (String nextMonthDate : nextMonthDates) {
WorkTimeEntity workTimeEntity = new KQWorkTime().getWorkTime(userId, nextMonthDate);
boolean holiday = KQHolidaySetBiz.isHoliday(fixedUserId, nextMonthDate, true);
if (holiday) {
//节假日休息班
b = rs.executeUpdate(sql, nextMonthDate, holidayDefaultSerialid, userId, workTimeEntity.getGroupId(), "0");
} else {
// //周末休息班
// if(DateUtil.getWeek(nextMonthDate) == 6 || DateUtil.getWeek(nextMonthDate) == 7){
// b = rs.executeUpdate(sql, nextMonthDate, weekendDefaultSerialid, userId, workTimeEntity.getGroupId(), "0");
// }else{
b = rs.executeUpdate(sql, nextMonthDate, defaultSerialid, userId, workTimeEntity.getGroupId(), "0");
//}
}
}
}
bb.writeLog("AutoScheduNextMonthJob.b: " + b);
}catch (Exception e) {
bb.writeLog("AutoScheduNextMonthJob Exception: " + e);
}
}
/*
*/
public static List<String> getNextMonthDates() {
// 获取当前时间的Calendar实例
List<String> list = new ArrayList<>();
Calendar cal = Calendar.getInstance();
// 将Calendar实例中的月份加1得到下个月的Calendar实例
cal.add(Calendar.MONTH, 1);
// 获取下个月的天数
int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
// 循环获取下个月中的每一天的日期
for (int i = 1; i <= daysInMonth; i++) {
// 将Calendar实例中的日期设置为循环变量i的值
cal.set(Calendar.DATE, i);
// 获取日期并格式化
Date date = cal.getTime();
String dateString = new SimpleDateFormat("yyyy-MM-dd").format(date);
list.add(dateString);
}
return list;
}
}

@ -0,0 +1,92 @@
package weaver.interfaces.hostar.job;
import com.engine.kq.biz.KQGroupComInfo;
import com.engine.kq.biz.KQOvertimeRulesBiz;
import com.engine.kq.biz.KQWorkTime;
import com.engine.kq.entity.WorkTimeEntity;
import org.apache.tools.ant.util.DateUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class AutoSchedulJob extends BaseCronJob {
private String fromDate;
private String toDate;
public String getFromDate() {
return fromDate;
}
public String getToDate() {
return toDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
BaseBean bb= new BaseBean();
@Override
public void execute() {
bb.writeLog("AutoSchedulJob Start");
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
bb.writeLog("fromDate: " + fromDate);
bb.writeLog("toDate: " + toDate);
//当前日期
toDate = DateUtils.format(new Date(), "yyyy-MM-dd");
RecordSet rs = new RecordSet();
boolean b = false;
//查询所有考勤人员(去除人员)
List<String> userList = new ArrayList<>();
rs.executeQuery("select id from hrmresource where 1=1");
while (rs.next()){
userList.add(Util.null2String(rs.getString("id")));
}
bb.writeLog("AutoSchedulJob.userList: " + userList);
String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)";
String sql3 = "select currentnodetype from workflow_requestbase where requestid in (select requestid from kq_flow_split_leave where " +
" resourceid = ? and (fromdatedb +' '+ fromtimedb) <=? and (todatedb+' '+totimedb) >=?) and currentnodetype = '3' ";
//休息日默认排休息班
for (String userId : userList) {
WorkTimeEntity workTimeEntity = new KQWorkTime().getWorkTime(userId, toDate);
/*获取考勤组的ID因为考勤组有有效期所以需要传入日期*/
//String groupId = new KQGroupMemberComInfo().getKQGroupId(userId, toDate);
int changeType = KQOvertimeRulesBiz.getChangeType(userId, toDate);
//无需考勤人员
String excludecount = Util.null2String(new KQGroupComInfo().getExcludecount(workTimeEntity.getGroupId()));//是否参与考勤报表统计
if(workTimeEntity.getIsExclude()&&!excludecount.equals("1")){
continue;
}
if(changeType!=2){
//休息班
b = rs.executeUpdate(sql, toDate, "-1", userId, workTimeEntity.getGroupId(), "0");
}else{
//查询该员工当天是否有已办结的请假流程(有:自动对班;否:不处理)
//6.2 查询这些requestid是否在当天前包含当天已批准
rs.executeQuery(sql3,userId,toDate,toDate);
if(rs.next()){
b = rs.executeUpdate(sql, toDate, "9", userId, workTimeEntity.getGroupId(), "0");
}
}
}
bb.writeLog("AutoSchedulJob.b: " + b);
}catch (Exception e) {
bb.writeLog("AutoSchedulJob Exception: " + e);
}
}
}

@ -0,0 +1,98 @@
package weaver.interfaces.hostar.job;
import cn.hutool.core.date.DateUtil;
import com.engine.hostar.thread.HandleCBDataThread;
import com.engine.hostar.util.HostarUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.ThreadPoolUtil;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* @version 1.0
* @Title ecology-9
* @Company
* @CreateDate 2024/3/12
* @Description
* @Author AdminZm
*/
public class UpdateCbxxjlDataJob extends BaseCronJob {
BaseBean baseBean = new BaseBean();
private String ryParam;
private String startDate;
private String endDate;
@Override
public void execute() {
baseBean.writeLog("UpdateCbxxjlDataJob start, param is:" + ryParam + "、" + startDate + "、" + endDate);
try {
String today = DateUtil.format(new Date(), "yyyy-MM-dd");
if (StringUtils.isEmpty(endDate)) {
endDate = today;
}
if (StringUtils.isEmpty(startDate)) {
startDate = today;
}
String date1 = String.valueOf(startDate);
String date2 = String.valueOf(endDate);
List<String> allDates = getAllDates(date1, date2);
baseBean.writeLog("UpdateCbxxjlDataJob allDatas:" + allDates);
RecordSet rs = new RecordSet();
List<String> userIds = new ArrayList<>();
if (StringUtils.isEmpty(ryParam) || StringUtils.equals(ryParam, "null")) {
baseBean.writeLog("1111.");
rs.executeQuery("select id from hrmresource");
while (rs.next()) {
userIds.add(rs.getString("id"));
}
} else {
baseBean.writeLog("2222.");
rs.executeQuery("select id from hrmresource where workcode = ?", ryParam);
while (rs.next()) {
userIds.add(rs.getString("id"));
}
}
baseBean.writeLog("userIds:" + userIds);
if ((CollectionUtils.isEmpty(userIds) && userIds.isEmpty()) || (CollectionUtils.isEmpty(allDates) && allDates.isEmpty())) {
baseBean.writeLog("no user or date.");
return;
}
ExecutorService executorService = ThreadPoolUtil.getThreadPool(null, null);
for (String userId : userIds) {
for (String kqDate : allDates) {
executorService.execute(new HandleCBDataThread(userId, kqDate));
}
}
if (executorService.isTerminated()) {
executorService.shutdown();
}
} catch (Exception e) {
baseBean.writeLog("UpdateCbxxjlDataJob error:" + e.getMessage());
}
}
public List<String> getAllDates(String startDate, String endDate) {
List<String> result = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate start = LocalDate.parse(startDate, formatter);
LocalDate end = LocalDate.parse(endDate, formatter);
while (!start.isAfter(end)) {
result.add(start.format(formatter));
start = start.plusDays(1);
}
return result;
}
}
Loading…
Cancel
Save