刘浩负责项目源码,部分有git管理,和svn代码备份。

main
howec 1 year ago
parent ed4baca120
commit 3b27c315c3

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,754 @@
package com.engine.kq.cmd.report;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.*;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.util.ExcelUtil;
import com.engine.kq.util.KQDurationCalculatorUtil;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.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.time.LocalDate;
import java.time.format.DateTimeFormatter;
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 {
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);
}
if(showColumns.contains("nightdaysd")) {
//刘浩 导出新增列[大夜班天数]-begin
title = new HashMap<>();
title.put("title","大夜班天数");
title.put("width",30*256);
title.put("rowSpan", 3);
titleList.add(title);
}
if(showColumns.contains("nightdaysx")) {
//刘浩 导出新增列[小夜班天数]-begin
title = new HashMap<>();
title.put("title", "小夜班天数");
title.put("width", 30 * 256);
title.put("rowSpan", 3);
titleList.add(title);
}
//刘浩 导出新增列[夜班天数]-end
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 = " a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," +
" b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,b.attendanceMins,b.beLate," +
" b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins,b.graveLeaveEarly," +
" b.graveLeaveEarlyMins,b.absenteeism,b.signdays,b.signmins, "+
" b.absenteeismMins ,(b.forgotCheck+"+forgotBeginWorkCheck_field+") forgotCheck ";
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'";
String sqlWhere = rightSql;
if(subCompanyId.length()>0){
sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and a.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and a.id in("+resourceId+") ";
}
if(viewScope.equals("4")){//我的下属
if(allLevel.equals("1")){//所有下属
sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'";
}else{
sqlWhere+=" and a.managerid="+user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
String orderBy = " order by a.dsporder asc, a.lastname asc , b.kqDate asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc ";
sql = "select "+backFields + sqlFrom + sqlWhere+orderBy;
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Map<String,String> serialdata = new HashMap<>();
boolean isneedcal = KQSettingsBiz.getKqformatAccurate();
params.put("isneedcal",isneedcal?"1":"0");
Map<String,Object> flowData = kqReportBiz.getDailyFlowData(params,user);
/*考勤二开--转事假start*/
String calLeaveId = bb.getPropValue("project_sskj", "calLeaveId");
/*考勤二开--转事假end*/
rs.execute(sql);
while (rs.next()) {
data = new ArrayList<>();
String id = rs.getString("id");
String kqdate = rs.getString("kqdate");
String tmpkey = id+"|"+kqdate+"|";
// Map<String,Object> signDetailInfo = this.getSignDetailInfo(id,kqdate);
//刘浩--begin--
String serialidx = "";
String signintime1x = "";
String signouttime1x= "";
//刘浩--end--
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()));
if(null != serialdata && serialdata.containsKey(serialid)){
fieldValue = serialdata.get(serialid);
}else{
String tmpserialname = Util.formatMultiLang(shiftManagementToolKit.getShiftOnOffWorkSections(serialid, user.getLanguage()));
fieldValue = tmpserialname;
serialdata.put(serialid,tmpserialname);
}
//liuhao
serialidx = fieldValue;
}
} else if(fieldName.equals("signin1")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signintime1"));
data.add(fieldValue);
//liuhao
signintime1x = fieldValue;
fieldValue = Util.null2String(flowData.get(tmpkey+"signinstatus1"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signin2")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signintime2"));
data.add(fieldValue);
fieldValue = Util.null2String(flowData.get(tmpkey+"signinstatus2"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signin3")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signintime3"));
data.add(fieldValue);
fieldValue = Util.null2String(flowData.get(tmpkey+"signinstatus3"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signout1")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signouttime1"));
data.add(fieldValue);
//liuhao
signouttime1x = fieldValue;
fieldValue = Util.null2String(flowData.get(tmpkey+"signoutstatus1"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signout2")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signouttime2"));
data.add(fieldValue);
fieldValue = Util.null2String(flowData.get(tmpkey+"signoutstatus2"));
data.add(fieldValue);
continue;
} else if(fieldName.equals("signout3")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signouttime3"));
data.add(fieldValue);
fieldValue = Util.null2String(flowData.get(tmpkey+"signoutstatus3"));
data.add(fieldValue);
continue;
}else if ("appForOvertime".equals(fieldName)) {
bb.writeLog("appForOvertime");
LocalDate date = LocalDate.parse(kqdate, formatter);
LocalDate kqdateL = date.plusDays(1);
String kqdateN = kqdateL.format(formatter);
int intValue = Util.getIntValue(Util.null2String(flowData.get(id + "|" + kqdateN + "|" + "appForOvertime")));
bb.writeLog("intValue: " + intValue);
if (intValue == 1) {
data.add("正常");
} 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 = (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)));
}
/*考勤二开--转事假start*/
if ( flowType.equals( ("leaveType_" + calLeaveId) ) ) {
bb.writeLog("flowLeaveData: " + flowLeaveData);
double temp = Util.getDoubleValue(Util.null2String(flowData.get("DailyToComLeaveData|" + resourceId + "|" + kqdate)));
bb.writeLog("temp: " + temp);
if (temp >= 0.00) {
flowLeaveData = flowLeaveData + temp;
}
bb.writeLog("flowLeaveData: " + flowLeaveData);
}
/*考勤二开--转事假end*/
fieldValue = flowLeaveData;
data.add(fieldValue);
}
}else if(fieldName.equals("overtime")){
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave"))));
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal"))));
continue;
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
}else if(fieldName.equals("kqdate")){
fieldValue=kqdate+" "+com.engine.portal.util.DateUtil.getDayWeekOfDate1(DateUtil.parseToDate(kqdate));
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid));
}
if(!fieldName.equals("leave")) {
fieldValue = Util.formatMultiLang(fieldValue, "" + user.getLanguage());
data.add(fieldValue);
}
}
//刘浩 大夜班天数 -- begin
writeLog("howec-serialidx:::::::::"+serialidx);
writeLog("howec-signintime1x:::::::::"+signintime1x);
writeLog("howec-signouttime1x:::::::::"+signouttime1x);
if(showColumns.contains("nightdaysd")) {
if(serialidx.contains("值夜班")) {
if((!"未打卡".equals(signintime1x)) && (!"未打卡".equals(signouttime1x))) {
data.add("1");
}else {
data.add("0");
}
}else {
data.add("0");
}
}
// 刘浩 小夜班天数 --
if(showColumns.contains("nightdaysx")) {
if(serialidx.contains("两班夜班")) {
if((!"未打卡".equals(signintime1x)) && (!"未打卡".equals(signouttime1x))) {
data.add("1");
}else {
data.add("0");
}
}else {
data.add("0");
}
}
//刘浩 大小夜班天数 -- end
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) {
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";
rs.execute(sql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
String kqdate = Util.null2String(rs.getString("kqdate"));
String serialid = Util.null2String(rs.getString("serialid"));
int serialnumber = rs.getInt("serialnumber")+1;
String workbegindate = Util.null2String(rs.getString("workbegindate")).trim();
String workbegintime = Util.null2String(rs.getString("workbegintime")).trim();
String workenddate = Util.null2String(rs.getString("workenddate")).trim();
String workendtime = Util.null2String(rs.getString("workendtime")).trim();
int workMins = rs.getInt("workMins");
String signintime = Util.null2String(rs.getString("signintime")).trim();
String signouttime = Util.null2String(rs.getString("signouttime")).trim();
int attendanceMins = rs.getInt("attendanceMins");
String beLateMins = Util.null2String(rs.getString("beLateMins")).trim();
String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim();
String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim();
String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim();
String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim();
String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim();
String signinid = Util.null2String(rs.getString("signinid")).trim();
String signoutid = Util.null2String(rs.getString("signoutid")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
if(serialid.length()>0){
if (workbegintime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workbegindate);
signStatusInfo.put("worktime",workbegintime);
signStatusInfo.put("beLateMins",beLateMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("graveBeLateMins",graveBeLateMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime);
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
}
if (workendtime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workenddate);
signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime));
signStatusInfo.put("leaveEarlyMins",leaveEarlyMins);
signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins);
signStatusInfo.put("forgotCheckMins",forgotCheckMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime);
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
}
}else{
if(workMins>0){
//弹性工时打卡时间取自签到签退数据
}
signStatusInfo = new HashMap();
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
if(signinid.length() > 0){
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime);
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
if(signoutid.length() > 0){
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime);
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
}
}else{
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
}
}
}
}catch (Exception e){
writeLog(e);
}
return data;
}
private String getFieldValueByUnitType(String fieldValue,String unittype){
if (Util.null2String(unittype).length() > 0) {
if (fieldValue.length() == 0) {
fieldValue = "0";
} else {
if (unittype.equals("2")) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
}
}
return fieldValue;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,702 @@
package com.engine.kq.cmd.report;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.*;
import com.engine.kq.util.ExcelUtil;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.UtilKQ;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.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 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;
}
if("nightdaysd".equals(kqReportFieldComInfo.getFieldname()) || "nightdaysx".equals(kqReportFieldComInfo.getFieldname())) {
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;
// }
Map<String,String> map99 = new HashMap<>();
if(showColumns.contains("kqCalendar")) {
childColumns = new ArrayList<>();
for (String date = fromDate; !isEnd; ) {
if (date.equals(toDate)) isEnd = true;
title = new HashMap<>();
map99.put(date,"22222");
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);
}
if(showColumns.contains("nightdaysd")) {
//刘浩 新增一列[大夜班天数]
title = new HashMap();
title.put("title","大夜班天数");
title.put("width", 30 * 256);
title.put("rowSpan",3);
titleList.add(title);
}
if(showColumns.contains("nightdaysx")) {
//刘浩 新增一列[小夜班天数]
title = new HashMap();
title.put("title","小夜班天数");
title.put("width", 30 * 256);
title.put("rowSpan",3);
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 = " a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," +
" sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," +
" sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " +
" sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," +
" sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " +
" sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " +
" sum(b.signdays) as signdays,sum(b.signmins) as signmins, "+
" sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+"+forgotBeginWorkCheck_field+" as forgotCheck "+(definedFieldSum.length()>0?","+definedFieldSum+"":"");
if(rs.getDBType().equals("oracle")){
backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields;
}
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'";
String sqlWhere = rightSql;
String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle ";
if (subCompanyId.length() > 0) {
sqlWhere += " and a.subcompanyid1 in(" + subCompanyId + ") ";
}
if (departmentId.length() > 0) {
sqlWhere += " and a.departmentid in(" + departmentId + ") ";
}
if (resourceId.length() > 0) {
sqlWhere += " and a.id in(" + resourceId + ") ";
}
if (viewScope.equals("4")) {//我的下属
if (allLevel.equals("1")) {//所有下属
sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'";
} else {
sqlWhere += " and a.managerid=" + user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
String orderBy = " order by a.dsporder asc, a.lastname asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc ";
sql = "select " + backFields + sqlFrom + sqlWhere + groupBy + orderBy;
//System.out.println("start" + DateUtil.getFullDate());
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*/
String calLeaveId = bb.getPropValue("project_sskj", "calLeaveId");
/*考勤二开--转事假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("nightdaysx") || fieldName.equals("nightdaysd") ) {
continue;
}
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)));
}
/*考勤二开--转事假start*/
if ( flowType.equals( ("leaveType_" + calLeaveId) ) ) {
bb.writeLog("ExportExcelCmd flowLeaveData start ");
bb.writeLog("flowLeaveData: " + flowLeaveData);
double temp = Util.getDoubleValue(Util.null2String(flowData.get("ToComLeaveData|" + resourceId)));
bb.writeLog("temp: " + temp);
if (temp >= 0.00) {
flowLeaveData = flowLeaveData + temp;
}
bb.writeLog("flowLeaveData: " + flowLeaveData);
}
/*考勤二开--转事假end*/
data.add(flowLeaveData);
}
continue;
}else if(fieldName.equals("overtime")){
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave"))));
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal"))));
continue;
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
} else if(Util.null2String(kqReportFieldComInfo.getCascadekey(fieldid)).length()>0){
fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage());
data.add(fieldValue);
List<String> lsCascadekey = Util.splitString2List(kqReportFieldComInfo.getCascadekey(fieldid),",");
for(int i=0;i<lsCascadekey.size();i++){
if(Util.null2String(rs.getString(lsCascadekey.get(i))).length()>0){
fieldid = KQReportFieldComInfo.field2Id.get(lsCascadekey.get(i));
fieldValue = getFieldValueByUnitType(rs.getString(lsCascadekey.get(i)),kqReportFieldComInfo.getUnittype(fieldid));
}else{
fieldValue = "0";
}
data.add(fieldValue);
}
continue;
}else {
fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage());
fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid));
}
fieldValue = Util.formatMultiLang(fieldValue,""+user.getLanguage());
data.add(fieldValue);
}
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);
}
}
//刘浩 新增夜班天数
String resourceid = id;
if(map99!=null && map99.keySet().size()>0) {
String s1 = "";
for(String s99 :map99.keySet()) {
s1 = s1+"'"+s99+"',";
}
s1 = s1.substring(0,s1.length()-1);
//刘浩--大夜班天数统计
String sql88 = "select b.resourceid,b.signintime,b.signouttime,b.serialid from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%值夜班%'";
String sql99 = "select count(b.resourceid) as sums from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%值夜班%'";
writeLog("howec:::::sql2:"+sql88);
RecordSet rs99 = new RecordSet();
rs99.execute(sql99);
String counts99 = "0";
if (rs99.next()){
counts99 = String.valueOf(rs99.getInt("sums"));
}
if(showColumns.contains("nightdaysd")) {
data.add(counts99);
}
//刘浩--小夜班天数统计
sql88 = "select b.resourceid,b.signintime,b.signouttime,b.serialid from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%两班夜班%'";
sql99 = "select count(b.resourceid) as sums from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%两班夜班%'";
writeLog("howec:::::sql2-1:"+sql88);
rs99 = new RecordSet();
rs99.execute(sql99);
counts99 = "0";
if (rs99.next()){
counts99 = String.valueOf(rs99.getInt("sums"));
}
if(showColumns.contains("nightdaysx")) {
data.add(counts99);
}
}else {
if(showColumns.contains("nightdaysd")) {
data.add("0");
}
if(showColumns.contains("nightdaysx")) {
data.add("0");
}
}
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,685 @@
package com.engine.kq.cmd.report;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.*;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.PageUidFactory;
import weaver.conn.RecordSet;
import weaver.general.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.time.LocalDate;
import java.time.format.DateTimeFormatter;
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{
writeLog("howeccccccccccccggggggg1"+ new Date());
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();
writeLog("howeccccccccccccggggggg2"+ new Date());
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");
}
}
writeLog("howeccccccccccccggggggg3"+ new Date());
//人员状态
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;
writeLog("howeccccccccccccggggggg4"+ new Date());
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();
writeLog("howeccccccccccccggggggg5"+ new Date());
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()));
}
writeLog("howeccccccccccccggggggg6"+ new Date());
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;
// }
// }
writeLog("howeccccccccccccggggggg7"+ new Date());
String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck ";
if(rs.getDBType().equalsIgnoreCase("oracle")&&!Util.null2String(rs.getOrgindbtype()).equals("dm")&&!Util.null2String(rs.getOrgindbtype()).equals("st")&&!Util.null2String(rs.getOrgindbtype()).equals("jc")) {
forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) ";
}else if((rs.getDBType()).equalsIgnoreCase("mysql")){
forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) ";
}else {
forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) ";
}
String backFields = " a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," +
" b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,b.attendanceMins," +
" b.beLate,b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins," +
" b.signdays,b.signmins, "+
" b.graveLeaveEarly,b.graveLeaveEarlyMins,b.absenteeism ,b.absenteeismMins ,(b.forgotCheck+"+forgotBeginWorkCheck_field+") forgotCheck ";
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'";
String sqlWhere = rightSql;
if(subCompanyId.length()>0){
sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") ";
}
writeLog("howeccccccccccccggggggg8"+ new Date());
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;
writeLog("howeccccccccccccggggggg9"+ new Date());
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;
}
Map<String,Object> flowData = kqReportBiz.getDailyFlowData(params,user);
Map<String,String> serialdata = new HashMap<>();
/*考勤二开--转事假start*/
String calLeaveId = bb.getPropValue("project_sskj", "calLeaveId");
/*考勤二开--转事假end*/
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
rs.execute(sql);
writeLog("howec::::::::::::::::sql:"+sql);
while (rs.next()) {
String id = rs.getString("id");
String kqdate = rs.getString("kqdate");
WorkTimeEntity workTime = kqWorkTime.getWorkTime(id, kqdate);
data = new HashMap<>();
kqReportFieldComInfo.setTofirstRow();
while (kqReportFieldComInfo.next()) {
if (!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1")) continue;
if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily"))
continue;
String fieldName = kqReportFieldComInfo.getFieldname();
String fieldValue = "";
if (fieldName.equals("subcompany")) {
String fieldValueID = rs.getString("subcompanyid");
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") :
subCompanyComInfo.getSubCompanyname(fieldValueID);
//fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID);
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getSubCompanyID(id);
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") :
subCompanyComInfo.getSubCompanyname(fieldValueID);
// fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (fieldName.equals("department")) {
String fieldValueID = rs.getString("departmentid");
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") :
departmentComInfo.getDepartmentname(fieldValueID);
//fieldValue = departmentComInfo.getDepartmentname(fieldValueID);
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getDepartmentID(id);
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") :
departmentComInfo.getDepartmentname(fieldValueID);
// fieldValue = departmentComInfo.getDepartmentname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (fieldName.equals("jobtitle")) {
String fieldValueID = rs.getString("jobtitle");
fieldValue = jobTitlesComInfo.getJobTitlesname(rs.getString("jobtitle"));
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getJobTitle(id);
fieldValue = jobTitlesComInfo.getJobTitlesname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (kqReportFieldComInfo.getParentid().equals("overtime") || kqReportFieldComInfo.getParentid().equals("overtime_nonleave")
|| kqReportFieldComInfo.getParentid().equals("overtime_4leave") || fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) {
if (fieldName.equals("overtimeTotal")) {
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave +
workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave));
} else {
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|" + kqdate + "|" + fieldName)));
}
data.put(fieldName, fieldValue);
} else if (fieldName.equals("serialid")) {
fieldValue = Util.null2String(rs.getString(fieldName));
if (fieldValue.length()>0) {//弹性工作制没有班次
// data.put("serialid", shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage()));
if(null != serialdata && serialdata.containsKey(fieldValue)){
data.put("serialid", serialdata.get(fieldValue));
}else{
String tmpserialname = shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage());
serialdata.put(fieldValue,tmpserialname);
data.put("serialid", tmpserialname);
}
}
} else if ("appForOvertime".equals(fieldName)) {
bb.writeLog("appForOvertime");
LocalDate date = LocalDate.parse(kqdate, formatter);
LocalDate kqdateL = date.plusDays(1);
String kqdateN = kqdateL.format(formatter);
int intValue = Util.getIntValue(Util.null2String(flowData.get(id + "|" + kqdateN + "|" + "appForOvertime")));
bb.writeLog("intValue: " + intValue);
if (intValue == 1) {
data.put(fieldName, "正常");
} else {
data.put(fieldName, "异常");
}
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
if (kqReportFieldComInfo.getUnittype().equals("2") && fieldValue.length() > 0) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
data.put(fieldName, fieldValue);
}
}
data.putAll(this.getSignDetailInfo(id, kqdate));
//请假
List<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)));
}
/*考勤二开--转事假start*/
if ( flowType.equals( ("leaveType_" + calLeaveId) ) ) {
bb.writeLog("flowLeaveData: " + flowLeaveData);
double temp = Util.getDoubleValue(Util.null2String(flowData.get("DailyToComLeaveData|" + resourceId + "|" + kqdate)));
bb.writeLog("temp: " + temp);
if (temp >= 0.00) {
flowLeaveData = flowLeaveData + temp;
}
bb.writeLog("flowLeaveData: " + flowLeaveData);
}
/*考勤二开--转事假end*/
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){
writeLog(e);
}
return retmap;
}
private String getUnitType(String unitType, User user){
String unitTypeName = "";
if(Util.null2String(unitType).length()>0){
if(unitType.equals("1")){
unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage());
}else if(unitType.equals("2")){
unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage());
}else if(unitType.equals("3")){
unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage());
}
}
return unitTypeName;
}
private Map<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{
bb.writeLog("-----getSignDetailInfo start-----");
sql = " select kqdate,resourceid,serialid,serialnumber,workbegindate,workbegintime, " +
" workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" +
" attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," +
" leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid \n" +
" from kq_format_detail b \n" +
" where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' \n" +
" order by serialnumber \n";
rs.execute(sql);
bb.writeLog("sql: " + sql);
while (rs.next()) {
String resourceid = Util.null2String(rs.getString("resourceid"));
String kqdate = Util.null2String(rs.getString("kqdate"));
String serialid = Util.null2String(rs.getString("serialid"));
int serialnumber = rs.getInt("serialnumber")+1;
String workbegindate = Util.null2String(rs.getString("workbegindate")).trim();
String workbegintime = Util.null2String(rs.getString("workbegintime")).trim();
String workenddate = Util.null2String(rs.getString("workenddate")).trim();
String workendtime = Util.null2String(rs.getString("workendtime")).trim();
int workMins = rs.getInt("workMins");
String signintime = Util.null2String(rs.getString("signintime")).trim();
String signouttime = Util.null2String(rs.getString("signouttime")).trim();
int attendanceMins = rs.getInt("attendanceMins");
String beLateMins = Util.null2String(rs.getString("beLateMins")).trim();
String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim();
String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim();
String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim();
String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim();
String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim();
String signinid = Util.null2String(rs.getString("signinid")).trim();
String signoutid = Util.null2String(rs.getString("signoutid")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
if(serialid.length()>0){
if (workbegintime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workbegindate);
signStatusInfo.put("worktime",workbegintime);
signStatusInfo.put("beLateMins",beLateMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("graveBeLateMins",graveBeLateMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
/*考勤二开--当前时间在当天班次下班点之前不显示旷工start*/
String nowDay = DateUtil.format(new Date(), "yyyy-MM-dd");
String nowTime = DateUtil.format(new Date(), "HH:mm");
bb.writeLog("nowDay: " + nowDay);
bb.writeLog("nowTime: " + nowTime);
bb.writeLog("workenddate: " + workenddate);
bb.writeLog("workendtime: " + kqTimesArrayComInfo.turn48to24Time(workendtime));
if (workenddate.equals(nowDay) && nowTime.compareTo(kqTimesArrayComInfo.turn48to24Time(workendtime)) < 0) {
signStatusInfo.put("isneedcal","1");
}
bb.writeLog("signStatusInfo: " + signStatusInfo);
/*考勤二开--当前时间在当天班次下班点之前不显示旷工end*/
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime);
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
}
if (workendtime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("workdate",workenddate);
signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime));
signStatusInfo.put("leaveEarlyMins",leaveEarlyMins);
signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins);
signStatusInfo.put("forgotCheckMins",forgotCheckMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
/*考勤二开--当前时间在当天班次下班点之前不显示旷工start*/
String nowDay = DateUtil.format(new Date(), "yyyy-MM-dd");
String nowTime = DateUtil.format(new Date(), "HH:mm");
bb.writeLog("nowDay: " + nowDay);
bb.writeLog("nowTime: " + nowTime);
bb.writeLog("workenddate: " + workenddate);
bb.writeLog("workendtime: " + kqTimesArrayComInfo.turn48to24Time(workendtime));
if (workenddate.equals(nowDay) && nowTime.compareTo(kqTimesArrayComInfo.turn48to24Time(workendtime)) < 0) {
signStatusInfo.put("isneedcal","1");
}
bb.writeLog("signStatusInfo: " + signStatusInfo);
/*考勤二开--当前时间在当天班次下班点之前不显示旷工end*/
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime);
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
}
}else{
if(workMins>0){
//弹性工时打卡时间取自签到签退数据
}
signStatusInfo = new HashMap();
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
if(signinid.length() > 0){
data.put("signintime"+serialnumber, signintime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signintime);
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
if(signoutid.length() > 0){
data.put("signouttime"+serialnumber, signouttime.length()==0?SystemEnv.getHtmlLabelName(25994, user.getLanguage()):signouttime);
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
}
}else{
data.put("signinstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"on"));
}
}
}
}catch (Exception e){
writeLog(e);
}
return data;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,719 @@
package com.engine.kq.cmd.report;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.*;
import com.engine.kq.util.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.text.ParseException;
import java.text.SimpleDateFormat;
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{
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));
}
//Liuhao 新增列[大夜班天数] --begin
// column = new HashMap();
// column.put("title","大夜班天数");
// column.put("unit","天");
// column.put("dataIndex","nightdaysd");
// column.put("type","businessLeave");
// column.put("key","nightdaysd");
// column.put("isSystem","1");
// column.put("rowSpan","3");
// column.put("width",65);
// column.put("showDetial","1");
// columns.add(column);
//Liuhao 新增列[夜班天数] --end
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 = " a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," +
" sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," +
" sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " +
" sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," +
" sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " +
" sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " +
" sum(b.signdays) as signdays,sum(b.signmins) as signmins, "+
" sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+"+forgotBeginWorkCheck_field+" as forgotCheck "+(definedFieldSum.length()>0?","+definedFieldSum+"":"");
if(rs.getDBType().equals("oracle")){
backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ "+backFields;
}
String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"'";
String sqlWhere = rightSql;
String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle ";
if(subCompanyId.length()>0){
sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and a.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and a.id in("+resourceId+") ";
}
if(viewScope.equals("4")){//我的下属
if(allLevel.equals("1")){//所有下属
sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'";
}else{
sqlWhere+=" and a.managerid="+user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
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;
}
writeLog("howeccccccccccccggggggg10"+ System.currentTimeMillis());
// #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);
Map<String,Object> flowData = kqReportBiz.getFlowData(params,user);
/*考勤二开--转事假start*/
String calLeaveId = bb.getPropValue("project_sskj", "calLeaveId");
/*考勤二开--转事假end*/
rs.execute(sql);
writeLog("howeccccccccccccggggggg11"+ System.currentTimeMillis());
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")){
writeLog("howeccccccccccccggggggg12"+ System.currentTimeMillis());
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 {
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);
}
writeLog("howeccccccccccccggggggg13"+ System.currentTimeMillis());
//请假
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);
}
writeLog("howeccccccccccccggggggg14"+ System.currentTimeMillis());
//考虑下冻结的数据
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);
}
//liuhao 夜班天数
//刘浩 拿到日期 计算天数----begin
List<String>listdate = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy-MM-dd");
for(String key99 : data.keySet()) {
try {
Date date = sdf.parse(key99);
listdate.add(key99);
} catch (ParseException e) {}
}
String resourceid = (String)data.get("resourceId");
if(listdate!=null && listdate.size()>0) {
String s1 = "";
for(String strdate : listdate) {
s1 = s1+"'"+strdate+"',";
}
s1 = s1.substring(0,s1.length()-1);
//刘浩 大夜班天数
String sql88 = "select b.resourceid,b.signintime,b.signouttime,b.serialid from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%值夜班%'";
String sql99 = "select count(b.resourceid) as sums from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%值夜班%'";
writeLog("howec:::::sql1:"+sql88);
RecordSet rs99 = new RecordSet();
rs99.execute(sql99);
String counts99 = "0";
if (rs99.next()){
counts99 = String.valueOf(rs99.getInt("sums"));
}
data.put("nightdaysd",counts99);
//刘浩 小夜班天数
sql88 = "select b.resourceid,b.signintime,b.signouttime,b.serialid from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%两班夜班%'";
sql99 = "select count(b.resourceid) as sums from kq_format_detail b inner join kq_ShiftManagement c on c.id = b.serialid where b.resourceid = "+resourceid+" and b.signintime is not null and b.signouttime is not null " +
" and b.signintime !='' and b.signouttime !='' " +
" and b.kqdate in("+s1+") and c.serial like '%两班夜班%'";
writeLog("howec:::::sql1-1:"+sql88);
rs99 = new RecordSet();
rs99.execute(sql99);
counts99 = "0";
if (rs99.next()){
counts99 = String.valueOf(rs99.getInt("sums"));
}
data.put("nightdaysx",counts99);
}else {
data.put("nightdaysd","0");
data.put("nightdaysx","0");
}
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);
}
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,18 @@
package weaver.haikang.cronjob;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.interfaces.schedule.BaseCronJob;
public class FlowLaowuZzCron extends BaseCronJob {
private final Logger log = LoggerFactory.getLogger(FlowLaowuZzCron.class);
@Override
public void execute() {
log.error("劳务转自招申请开始定时任务开启-------");
new Thread( ()->{
FlowLaowuZzService flowLaowuZzService = new FlowLaowuZzService();
flowLaowuZzService.execute();
}).start();
log.error("劳务转自招申请开始定时任务结束-------");
}
}

@ -0,0 +1,119 @@
package weaver.haikang.cronjob;
import com.weaver.file.Prop;
import weaver.conn.RecordSet;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class FlowLaowuZzService {
private final Logger log = LoggerFactory.getLogger(FlowLaowuZzService.class);
private static final String zzzrzlx = Prop.getPropValue("FlowLaowuZz","zzzrzlx");
private static final String zzzsxrq = Prop.getPropValue("FlowLaowuZz","zzzsxrq");
private static final String zzzygxz = Prop.getPropValue("FlowLaowuZz","zzzygxz");
private static final String flowid = Prop.getPropValue("FlowLaowuZz","flowid");
private static final String flowtablename = Prop.getPropValue("FlowLaowuZz","flowtablename");
public synchronized void execute() {
String nowny = getNowNy();
RecordSet recordSeta = new RecordSet();
RecordSet recordSetb = new RecordSet();
RecordSet recordSetc = new RecordSet();
RecordSet recordSetd = new RecordSet();
RecordSet recordSetd1 = new RecordSet();
RecordSet recordSetb_0 = new RecordSet();
RecordSet recordSetb_1 = new RecordSet();
RecordSet recordSetb_3 = new RecordSet();
String sql1log = "select a.*, b.* from ( select workflowid, workflowtype, iscomplete, requestid, nodeid from workflow_currentoperator where iscomplete = 1 and WORKFLOWID = "+flowid+" group by requestid ) a inner join "+flowtablename+" b on a.requestid = b.requestId";
String sql = "select b.xm1,b.zzzsxrq from (select workflowid,workflowtype ,iscomplete ,requestid ,nodeid from workflow_currentoperator where iscomplete = 1 and WORKFLOWID = "+flowid+" group by requestid) a inner join "+flowtablename+" b on a.requestid = b.requestId";
log.error("sql::::::::::::1:"+sql1log);
recordSeta.executeQuery(sql);
while (recordSeta.next()) {
String uid = recordSeta.getString("xm1");
String date3 = recordSeta.getString("zzzsxrq");
if(uid.length()>0 && date3.length()>0) {
if(judgeRq(nowny,date3)) {
String sql3_0 = "select count(id) as nums from cus_fielddata where scopeid = 3 and scope = 'HrmCustomFieldByInfoType' and id = "+uid;
log.error("howec:::::::::::::::::1:"+sql3_0);
recordSetb_0.executeQuery(sql3_0);
recordSetb_0.next();
int nums = recordSetb_0.getInt("nums");
if(nums == 0) {
//新增
String insertsql = "insert into cus_fielddata("+zzzrzlx+","+zzzsxrq+",scopeid,scope,id) values (?,?,?,?,?)";
recordSetb_1.executeUpdate(insertsql,1,date3,3,"HrmCustomFieldByInfoType",uid);
log.error("howec:::::::::::::::::2:"+insertsql);
}else {
//更新
//更新个人信息
String sql3 = "select "+zzzrzlx+","+zzzsxrq+" from cus_fielddata where scopeid = 3 and scope = 'HrmCustomFieldByInfoType' and id = "+uid;
log.error("sql3 =::::::::::::3:"+sql3);
recordSetb.executeQuery(sql3);
while (recordSetb.next()) {
String zzzrzlx1 = recordSetb.getString(zzzrzlx);//入职类型
String zzzsxrq1 = recordSetb.getString(zzzsxrq);//转入职生效日期
if(!("1".equals(zzzrzlx1))) {
String sql4 = "update cus_fielddata set "+zzzrzlx+" = '1' , "+zzzsxrq+" = '"+date3+"' where scopeid = 3 and scope = 'HrmCustomFieldByInfoType' and id = "+uid;
recordSetc.executeUpdate(sql4);
log.error("sql4 =::::::::::::4:"+sql4);
}
}
}
String sql4_0 = "select count(id) as nums from cus_fielddata where scopeid = -1 and scope = 'HrmCustomFieldByInfoType' and id = "+uid;
log.error("howec:::::::::::::::::3:"+sql4_0);
recordSetb_3.executeQuery(sql4_0);
recordSetb_3.next();
int nums1 = recordSetb_3.getInt("nums");
if(nums1 == 0) {
String insertsql = "insert into cus_fielddata("+zzzygxz+",scopeid,scope,id) values (?,?,?,?)";
recordSetb_1.executeUpdate(insertsql,1,-1,"HrmCustomFieldByInfoType",uid);
log.error("howec:::::::::::::::::5:"+insertsql);
}else {
String sql3 = "select "+zzzrzlx+","+zzzsxrq+" from cus_fielddata where scopeid = 3 and scope = 'HrmCustomFieldByInfoType' and id = "+uid;
log.error("sql3x =::::::::::::3:"+sql3);
recordSetd1.executeQuery(sql3);
while (recordSetd1.next()) {
String zzzrzlx1 = recordSetd1.getString(zzzrzlx);//入职类型
if(("1".equals(zzzrzlx1))) {
String sql5 = "update cus_fielddata set "+zzzygxz+" = '1' where scopeid = -1 and scope = 'HrmCustomFieldByInfoType' and id = "+uid;
recordSetd.executeUpdate(sql5);
log.error("sql5x =::::::::::::5:"+sql5);
}
}
}
//更新入职日期
String rzrqsql = "update hrmresource set companystartdate = '"+date3+"' where id = "+uid;
recordSetd.executeUpdate(rzrqsql);
log.error("sql5-1 =::::::::::::5-1:"+rzrqsql);
}
}
}
}
private boolean judgeRq(String now,String jl) {
LocalDate d1 = LocalDate.parse(now);
LocalDate d2 = LocalDate.parse(jl);
if (d1.isBefore(d2)) {
return false;
} else if (d1.isAfter(d2)) {
return true;
} else {
return true;
}
}
private String getNowNy() {
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String previousMonthString = currentDate.format(formatter);
return previousMonthString;
}
}

@ -0,0 +1,240 @@
package weaver.haikang.cronjob;
import cn.hutool.core.date.DateUtil;
import com.weaver.file.Prop;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.util.Date;
/**
*
*/
public class InternalReferralRewardService {
private final Logger log = LoggerFactory.getLogger(InternalReferralRewardService.class);
private static final String ntjljmid = Prop.getPropValue("jiangshixinchou","ntjlhjjmid");
private static final String ntjltzjmid = Prop.getPropValue("jiangshixinchou","ntjltzjmid");
public synchronized void execute(String currentYm,String nowNy) {
log.error("howec::::::合计内推奖励月份:"+currentYm);
RecordSet recordSeta = new RecordSet();
RecordSet recordSetb = new RecordSet();
RecordSet recordSetc = new RecordSet();
RecordSet recordSetd= new RecordSet();
RecordSet recordSete = new RecordSet();
RecordSet recordSetf = new RecordSet();
RecordSet recordSetg = new RecordSet();
RecordSet recordSeth = new RecordSet();
//内推记录有并且已经入职的人员
String sql2 = "select b.id as uid,a.btjrxm,a.sfzhm,a.tjr,a.tjgw,b.companystartdate,c.rz,c.zz,c.rzbn,b.status from uf_ntjl a inner join hrmresource b on a.btjrxm = b.lastname " +
"and a.sfzhm = b.certificatenum inner join uf_gwtjjlgz c on a.tjrylb = c.tjgw where b.status in (0,1,2,3)";
recordSeta.executeQuery(sql2);
log.error("howec::::::sql2:"+sql2);
while (recordSeta.next()) {
/**
*
* 1
* 2
* 3
*/
String btjrxm = recordSeta.getString("btjrxm");//被推荐人姓名
String sfzhm = recordSeta.getString("sfzhm");//被推荐人身份证号
String tjr = recordSeta.getString("tjr");//推荐人
String tjgw = recordSeta.getString("tjgw");//推荐岗位
String companystartdate = recordSeta.getString("companystartdate");//入职日期
Double rz = recordSeta.getDouble("rz");//入职
Double zz = recordSeta.getDouble("zz");//转正
Double rzbn = recordSeta.getDouble("rzbn");//入职半年
String uid = recordSeta.getString("uid");
if(getSums2(recordSete,tjr,currentYm)){//如果存在
log.error("当前推荐人:"+tjr+" 在"+currentYm+" 已经执行过合计,一个月合计一次!");
}else {
Double result = 0d;
//判断 当前岗位当前推荐人,被推荐人,当前奖励类型是否已经发放工资
//以下奖励 都是针对被推荐人
String statusstr = "";
//先发一笔入职,需要统计入职日期如果是被统计月,才进行合计
if(!getJudgeResult(1,tjr,sfzhm,recordSetb)) {//如果不存在,处理
if(judgeCurrentNyCompanyNy(companystartdate,currentYm)) {
result+=rz;
statusstr = statusstr+"1,";
log.error("howec:::::::::::入职奖励新增");
//记录入职奖励
insertRzRecord(recordSetc,tjr,1,rz,tjgw,btjrxm,sfzhm);
}
}
//判断员工状态是否存在转正,存在则给一笔转正钱
if(isExistZz(recordSetg,uid)) {
if(!getJudgeResult(2,tjr,sfzhm,recordSetb)) {//如果不存在,处理
//如果存在转正,需要获取转正日期,如果转正日期是被统计月,则进行转正奖励
String zzrq = getZzrq(recordSeth,uid);
if(judgeCurrentNyCompanyNy(zzrq,currentYm)) {
result+=zz;
statusstr = statusstr+"2,";
log.error("howec:::::::::::转正奖励新增");
//记录转正奖励
insertRzRecord(recordSetc,tjr,2,zz,tjgw,btjrxm,sfzhm);
}
}
}
//判断员工统计月月底和入职时间差 时间差如果大于6个月并且小于等于7个月
if(!getJudgeResult(3,tjr,sfzhm,recordSetb)) {//如果不存在,处理
//判断当前日期是否大于180天
String ny = getMonthEndDay(currentYm);
if(dataCompare(companystartdate,ny) == 6l){//间隔时间刚好是6个月
result+=rzbn;
statusstr = statusstr+"3,";
log.error("howec:::::::::::入职半年新增");
insertRzRecord(recordSetc,tjr,3,rzbn,tjgw,btjrxm,sfzhm);
}
}
if(result > 0d) {
if(statusstr.length()>0) {
log.error("xxxxxxxxxxxxxxxxxxx:"+statusstr);
statusstr = statusstr.substring(0,statusstr.length()-1);
String zzrq = getZzrq(recordSetf,uid);
insertJlRecord(recordSetd,currentYm,tjr,result,uid,companystartdate,zzrq,statusstr);
}
}
}
}
}
private String getMonthEndDay(String ny1) {
String ny = ny1;
YearMonth currentYearMonth = YearMonth.parse(ny); // 获取当前的年月
LocalDate lastDayOfMonth = currentYearMonth.atEndOfMonth(); // 获取当前年月的最后一天
return lastDayOfMonth.toString();
}
private boolean judgeCurrentNyCompanyNy(String comparedate1, String currentYm) {
String comparedate = comparedate1;
comparedate = comparedate.substring(0,7);
if(currentYm.equals(comparedate)) {
return true;
}
return false;
}
//根据userid获取转正日期
private String getZzrq(RecordSet recordSetf,String uid) {
String sql = "select count(id) as sums from hrmstatushistory where resourceid = "+uid+" and type_n = 2";
log.error("howec::::::sql3:"+sql);
recordSetf.executeQuery(sql);
recordSetf.next();
int sums = recordSetf.getInt("sums");
if(sums > 0) {
sql = "select changedate from hrmstatushistory where resourceid = "+uid+" and type_n = 2";
log.error("howec::::::sql4:"+sql);
recordSetf.executeQuery(sql);
recordSetf.next();
return recordSetf.getString("changedate");
}else {
return "";
}
}
//判断员工是否存在转正
private Boolean isExistZz(RecordSet recordSetg, String uid) {
String sql = "select count(id) as sums from hrmstatushistory where resourceid = "+uid+" and type_n = 2";
log.error("howec::::::sql3:"+sql);
recordSetg.executeQuery(sql);
recordSetg.next();
int sums = recordSetg.getInt("sums");
return sums >0;
}
//判断推荐人 被推荐人 的奖励类型
private Boolean getJudgeResult(int type,String tjr,String btjrsfzh,RecordSet recordSetb) {
String sql = "select count(id) as nums from uf_neituijiangli where tjr = '"+tjr+"' and jllx = "+type+" and btjrsfzh = '"+btjrsfzh+"'";
log.error("howec::::::sql5:"+sql);
recordSetb.executeQuery(sql);
recordSetb.next();
int nums = recordSetb.getInt("nums");
return nums> 0;
}
//新增台账合计记录
private void insertJlRecord(RecordSet recordSetd,String ny,String tjr,Double jlje,String btjrxm,String rzrq,String zzrq,String bz) {
String sql = "insert into uf_ntjlb(ny,tjr,jlje,btjrxm,rzrq,zzrq,bz,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values(?,?,?,?,?,?,?,?,?,?,?,?)";
recordSetd.executeUpdate(sql,ny,tjr,jlje,btjrxm,rzrq,zzrq,bz,
ntjltzjmid,"1","0", DateUtil.today(),DateUtil.formatTime(new Date()));
String idSql = "SELECT max(id) as mid from uf_neituijiangli order by id desc";
recordSetd.executeQuery(idSql);
recordSetd.next();
String id = recordSetd.getString("mid");
// 权限重构
permissionReconstruction(Util.getIntValue(id),Integer.parseInt(ntjltzjmid));
}
private Boolean getSums2(RecordSet recordSetce,String tjr,String currentYm) {
String sql = "select count(id) as nums from uf_ntjlb where tjr = '"+tjr+"' and ny = '"+currentYm+"'";
log.error("howec::::::sql6:"+sql);
recordSetce.executeQuery(sql);
recordSetce.next();
int sums = recordSetce.getInt("nums");
return sums>0;
}
private void insertRzRecord(RecordSet recordSetc,String tjr,int jllx,Double jlje,String tjgw,String btjr,String btjrsfzh) {
String sql = "insert into uf_neituijiangli(tjr,jllx,jlje,tjgw,btjr,btjrsfzh,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values(?,?,?,?,?,?,?,?,?,?,?)";
recordSetc.executeUpdate(sql,tjr,jllx,jlje,tjgw,btjr,btjrsfzh,
ntjljmid,"1","0", DateUtil.today(),DateUtil.formatTime(new Date()));
String idSql = "SELECT max(id) as mid from uf_neituijiangli order by id desc";
recordSetc.executeQuery(idSql);
recordSetc.next();
log.error("howeccccccc:"+idSql);
String id = recordSetc.getString("mid");
// 权限重构
permissionReconstruction(Util.getIntValue(id),Integer.parseInt(ntjljmid));
}
//
//
/**
*
* @param billId
*/
private void permissionReconstruction(int billId,int jmid) {
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare(1, Util.getIntValue(jmid),billId);
}
public Date parseDateBystr(String str) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date1 = format.parse(str);
return date1;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 6
*/
public static long dataCompare(String beforedate,String nowdate) {
LocalDate date1 = LocalDate.parse(beforedate);
LocalDate date2 = LocalDate.parse(nowdate);
long monthsBetween = ChronoUnit.MONTHS.between(date1, date2);
return monthsBetween;
}
}

@ -0,0 +1,44 @@
package weaver.haikang.cronjob;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
*
*/
public class InternalReferralRewardsCron extends BaseCronJob {
private final Logger log = LoggerFactory.getLogger(InternalReferralRewardsCron.class);
@Override
public void execute() {
log.error("内推奖励台账定时任务开启-------");
new Thread( ()->{
String currentNy = getCurrentNy();
String nowNy = getNowNy();
InternalReferralRewardService internalReferralRewardService = new InternalReferralRewardService();
internalReferralRewardService.execute(currentNy,nowNy);
}).start();
log.error("内推奖励台账定时任务结束-------");
}
//获取当前时间的上一个月
private String getCurrentNy() {
LocalDate currentDate = LocalDate.now();
LocalDate previousMonth = currentDate.minusMonths(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
String previousMonthString = previousMonth.format(formatter);
return previousMonthString;
}
private String getNowNy() {
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
String previousMonthString = currentDate.format(formatter);
return previousMonthString+"-01";
}
}

@ -0,0 +1,21 @@
package weaver.haikang.cronjob;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.interfaces.schedule.BaseCronJob;
/**
* @use
*/
public class LeaveSummaryCron extends BaseCronJob {
private final Logger log = LoggerFactory.getLogger(LeaveSummaryService.class);
@Override
public void execute() {
log.error("定时更新汇总请假开始定时任务开启-------");
new Thread( ()->{
LeaveSummaryService leaveSummaryService = new LeaveSummaryService();
leaveSummaryService.execute();
}).start();
log.error("定时更新汇总请假开始定时任务结束-------");
}
}

@ -0,0 +1,129 @@
package weaver.haikang.cronjob;
import cn.hutool.core.date.DateUtil;
import com.weaver.file.Prop;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class LeaveSummaryService {
private final Logger log = LoggerFactory.getLogger(LeaveSummaryService.class);
//销假申请表单
private static final String xjshtablename = Prop.getPropValue("leave_summary_cron","xjshtablename");
//销假申请表单明细
private static final String xjshtablenamemx = Prop.getPropValue("leave_summary_cron","xjshtablenamemx");
private static final String nianjia = Prop.getPropValue("leave_summary_cron","nianjia");
private static final String tiaoxiu = Prop.getPropValue("leave_summary_cron","tiaoxiu");
private static final String shijia = Prop.getPropValue("leave_summary_cron","shijia");
private static final String bingjia = Prop.getPropValue("leave_summary_cron","bingjia");
private static final String chanjia = Prop.getPropValue("leave_summary_cron","chanjia");
private static final String peichanjia = Prop.getPropValue("leave_summary_cron","peichanjia");
private static final String hunjia = Prop.getPropValue("leave_summary_cron","hunjia");
private static final String sangjia = Prop.getPropValue("leave_summary_cron","sangjia");
private static final String burujia = Prop.getPropValue("leave_summary_cron","burujia");
private static final String qjhztablename = Prop.getPropValue("leave_summary_cron","qjhztablename");
private static final String jmid = Prop.getPropValue("leave_summary_cron","jmid");
public synchronized void execute() {
log.error("定时任务:更新请假汇总begin");
RecordSet recordSeta = new RecordSet();
RecordSet recordSetb = new RecordSet();
RecordSet recordSetc = new RecordSet();
RecordSet recordSetd = new RecordSet();
RecordSet recordSete = new RecordSet();
//年份人员组合
String sql = "SELECT LEFT (a.fromdate, 4 ) AS YEAR, a.RESOURCEID, b.lastname, b.workcode FROM kq_flow_split_leave a inner join hrmresource b on a.resourceid = b.id GROUP BY YEAR, a.RESOURCEID";
log.error("定时任务-sql1:"+sql);
recordSeta.executeQuery(sql);
while (recordSeta.next()) {
//每一条代表一个记录
log.error(">>>>>>>>>>>>>>>>3>>>>>>>>>>>>>>>>>>>>>");
String year = recordSeta.getString("YEAR");
String RESOURCEID = recordSeta.getString("RESOURCEID");
String lastname = recordSeta.getString("lastname");
String workcode = recordSeta.getString("workcode");
Map<String,String> hoursrs = getHours(year,RESOURCEID,recordSete);
String sql3 = "select count(id) as sums from "+qjhztablename+" where xm = "+RESOURCEID+" and nf = '"+year+"'";
log.error(">>>>>>>>>>>>>>>>4>>>>>>>>>>>>>>>>>>>>>sql6:"+sql3);
recordSetb.executeQuery(sql3);
if(recordSetb.next()) {
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>xxxxxx>>>>>>>>>>>>>>>>>>>>>>>>>");
int sums = recordSetb.getInt("sums");
String sql4 = "";
if(sums>0) {//更新
sql4 = "update "+qjhztablename+" set nj = ?,dx = ?,sqj = ?,bj = ?,cj = ?,pcj = ?,hj = ?,sj = ?,brj = ? where xm = "+RESOURCEID + " and nf = '"+year+"'";
log.error("定时任务-sql3:"+sql4);
recordSetc.executeUpdate(sql4,hoursrs.get(nianjia),hoursrs.get(tiaoxiu),hoursrs.get(shijia),hoursrs.get(bingjia),hoursrs.get(chanjia),hoursrs.get(peichanjia),hoursrs.get(hunjia),hoursrs.get(sangjia),hoursrs.get(burujia));
}else {//新增
sql4 = "INSERT INTO "+qjhztablename+"(gh,xm,nf,nj,dx,sqj,bj,cj,pcj,hj,sj,brj,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
log.error("定时任务-sql4:"+sql4);
recordSetc.executeUpdate(sql4,workcode,RESOURCEID,year,hoursrs.get(nianjia),hoursrs.get(tiaoxiu),hoursrs.get(shijia),hoursrs.get(bingjia),hoursrs.get(chanjia),hoursrs.get(peichanjia),
hoursrs.get(hunjia),hoursrs.get(sangjia),hoursrs.get(burujia),
jmid,"1","0", DateUtil.today(),DateUtil.formatTime(new Date())
);
String idSql = "SELECT max(id) as mid from "+qjhztablename+" order by id desc";
log.error("定时任务-sql5:"+idSql);
recordSetd.executeQuery(idSql);
String id = recordSetd.getString("mid");
// 权限重构
permissionReconstruction(Util.getIntValue(id));
}
}
}
}
//根据年份,人员id,请假类型获取时间
private Map<String,String> getHours(String year,String resourceid,RecordSet recordSete) {
log.error(">>>>>>>>>>>>>>>>2>>>>>>>>>>>>>>>>>>>>>");
String key = year+resourceid;
Map<String,String> rs = new HashMap<>();
//初始化
rs.put(nianjia,"0");
rs.put(tiaoxiu,"0");
rs.put(shijia,"0");
rs.put(bingjia,"0");
rs.put(chanjia,"0");
rs.put(peichanjia,"0");
rs.put(hunjia,"0");
rs.put(sangjia,"0");
rs.put(burujia,"0");
String insql = nianjia+","+tiaoxiu+","+","+shijia+","+","+bingjia+","+","+chanjia+","+","+peichanjia+","+","+hunjia+","+","+sangjia+","+burujia;
String sql = "SELECT c11.year, c11.RESOURCEID, c11.newleavetype, hours - IFNULL( hoursf, 0 ) AS hours FROM " +
"( SELECT * FROM ( SELECT LEFT ( fromdate, 4 ) AS YEAR, RESOURCEID, newleavetype, SUM( durationdb ) AS hours, " +
"concat( LEFT ( fromdate, 4 ), \"-\", newleavetype, \"-\", RESOURCEID ) AS cid FROM kq_flow_split_leave GROUP BY YEAR, " +
"RESOURCEID, newleavetype ) a11 LEFT JOIN ( SELECT a.detail_newLeaveType, LEFT ( a.detail_leavefromDate, 4 ) AS YEAR1, " +
"b.RESOURCEID AS RESOURCEID1, SUM( a.detail_duration ) AS hoursf, " +
"concat( LEFT ( a.detail_leavefromDate, 4 ), \"-\", a.detail_newLeaveType, \"-\", b.RESOURCEID ) AS cidf " +
"FROM "+xjshtablenamemx+" a INNER JOIN "+xjshtablename+" b ON a.mainid = b.id WHERE b.spzt = '1' GROUP BY " +
"YEAR1, RESOURCEID1, detail_newLeaveType ) b11 ON a11.cid = b11.cidf WHERE 1 = 1 and a11.year = '"+year+"' and a11.resourceid = '"+resourceid+"' ) c11 ";
log.error("定时任务-sql2:"+sql);
recordSete.executeQuery(sql);
while (recordSete.next()) {
String type = recordSete.getString("newleavetype");
Double hours = recordSete.getDouble("hours");
String hours1 = Double.toString(hours);
rs.put(type,hours1);
}
return rs;
}
/**
*
* @param billId
*/
private void permissionReconstruction(int billId) {
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare(1, Util.getIntValue(jmid),billId);
}
}

@ -0,0 +1,75 @@
package weaver.haikang.cronjob;
import cn.hutool.core.date.DateUtil;
import com.weaver.file.Prop;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import java.util.Date;
/**
*
*/
public class LectureAllowanceService {
private final Logger log = LoggerFactory.getLogger(LectureAllowanceService.class);
private static final String pxjlmxname = Prop.getPropValue("jiangshixinchou","pxjlmxname");
private static final String pxjlname = Prop.getPropValue("jiangshixinchou","pxjlname");
private static final String jmid = Prop.getPropValue("jiangshixinchou","jmid");
private static final String jsdaname = Prop.getPropValue("jiangshixinchou","jsdaname");
private static final String jsjtname = Prop.getPropValue("jiangshixinchou","jsjtname");
public synchronized void execute(String currentYm) {
//培训记录uf_pxjl
//培训记录明细uf_pxjl_dt1
//讲师档案uf_jsda
log.error("howec::::::讲师津贴合计月份:"+currentYm);
RecordSet recordSeta = new RecordSet();
RecordSet recordSetb = new RecordSet();
RecordSet recordSetc = new RecordSet();
RecordSet recordSetd = new RecordSet();
String sql1 = "select d.nums * d.jtbzks as jt,d.pxjsnx,d.pxsj, d.nums, d.jtbzks from " +
"( SELECT SUM(b.ksh) as nums, b.pxjsnx, b.pxsj, b.ksh, b.zxzt, c.jtbzks FROM "+pxjlmxname+" a INNER JOIN "+pxjlname+" b " +
"ON a.mainid = b.id INNER JOIN "+jsdaname+" c ON c.xm = b.pxjsnx where " +
"b.zxzt = 2 AND LEFT(b.pxsj,7)= '"+currentYm+"' group by b.pxjsnx ) d";
log.error("howec::::::讲师津贴合计月份:sql1:"+sql1);
recordSeta.executeQuery(sql1);
while (recordSeta.next()) {
String ny = recordSeta.getString("pxsj"); //年月
String pxjsnx = recordSeta.getString("pxjsnx"); //讲师(内训)
Double nums = recordSeta.getDouble("nums");//总数量
Double jtbzks = recordSeta.getDouble("jtbzks");//标准
Double jt = recordSeta.getDouble("jt");//津贴
String sql2 = "select count(id) as nums from "+jsjtname+" where xm = '"+pxjsnx+"' and ny = '"+currentYm+"'";
log.error("howec::::::讲师津贴合计月份:sql2:"+sql2);
recordSetb.executeQuery(sql2);
recordSetb.next();
if(recordSetb.getInt("nums") == 0) {
String sql = "insert into "+jsjtname+" (ny,xm,kcschj,jtbz,jsjt,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) values (?,?,?,?,?,?,?,?,?,?)";
recordSetc.executeUpdate(sql,currentYm,pxjsnx,nums,jtbzks,jt,
jmid,"1","0", DateUtil.today(),DateUtil.formatTime(new Date()));
String idSql = "SELECT max(id) as mid from "+jsjtname+" order by id desc";
recordSetd.executeQuery(idSql);
String id = recordSetd.getString("mid");
// 权限重构
permissionReconstruction(Util.getIntValue(id));
}
}
}
/**
*
* @param billId
*/
private void permissionReconstruction(int billId) {
ModeRightInfo ModeRightInfo = new ModeRightInfo();
ModeRightInfo.setNewRight(true);
ModeRightInfo.editModeDataShare(1, Util.getIntValue(jmid),billId);
}
}

@ -0,0 +1,35 @@
package weaver.haikang.cronjob;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
*
*/
public class LecturerAllowanceCron extends BaseCronJob {
private final Logger log = LoggerFactory.getLogger(LecturerAllowanceCron.class);
@Override
public void execute() {
log.error("讲师津贴台账定时任务开启-------");
new Thread( ()->{
String currentNy = getCurrentNy();
LectureAllowanceService lectureAllowanceService = new LectureAllowanceService();
lectureAllowanceService.execute(currentNy);
}).start();
log.error("讲师津贴台账定时任务结束-------");
}
//获取当前时间的上一个月
private String getCurrentNy() {
LocalDate currentDate = LocalDate.now();
LocalDate previousMonth = currentDate.minusMonths(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
String previousMonthString = previousMonth.format(formatter);
return previousMonthString;
}
}

@ -0,0 +1,26 @@
package weaver.haikang.cronjob;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.interfaces.schedule.BaseCronJob;
/**
*
*/
public class PersonDeptLevelCron extends BaseCronJob {
private final Logger log = LoggerFactory.getLogger(PersonDeptLevelCron.class);
private String currentYear;
@Override
public void execute() {
log.error("新到一级二级三级四级定时任务开启-------");
new Thread( ()->{
PersonDeptLevelCronService personDeptLevelCronService = new PersonDeptLevelCronService();
personDeptLevelCronService.execute();
}).start();
log.error("新到一级二级三级四级定时任务结束-------");
}
}

@ -0,0 +1,162 @@
package weaver.haikang.cronjob;
import com.weaver.file.Prop;
import weaver.conn.RecordSet;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
public class PersonDeptLevelCronService {
private final Logger log = LoggerFactory.getLogger(PersonDeptLevelCronService.class);
private static final String levle1 = Prop.getPropValue("PersonDeptLevel","levle1");
private static final String levle2 = Prop.getPropValue("PersonDeptLevel","levle2");
private static final String levle3 = Prop.getPropValue("PersonDeptLevel","levle3");
private static final String levle4 = Prop.getPropValue("PersonDeptLevel","levle4");
private static final String levle5 = Prop.getPropValue("PersonDeptLevel","levle5");
private static final String levle6 = Prop.getPropValue("PersonDeptLevel","levle6");
public synchronized void execute() {
log.error("howec:::>begin");
RecordSet recordSeta = new RecordSet();
RecordSet recordSetb = new RecordSet();
RecordSet recordSetc = new RecordSet();
String sql = "select r.id as rid, r.lastname, r.departmentid as rdepartmentid, a1.departmentname as rdepartmentname, a2.departmentname as departmentname2, a2.id as departmentid2, a3.departmentname as departmentname3, a3.id as departmentid3, a4.departmentname as departmentname4, a4.id as departmentid4, a5.departmentname as departmentname5, a5.id as departmentid5, a6.departmentname as departmentname6, a6.id as departmentid6, a7.departmentname as departmentname7, a7.id as departmentid7, a8.departmentname as departmentname8, a8.id as departmentid8, a9.departmentname as departmentname9, a9.id as departmentid9, a10.departmentname as departmentname10, a10.id as departmentid10 from HrmResource r inner join HrmDepartment a1 on r.departmentid = a1.id left join HrmDepartment a2 on a1.supdepid = a2.id left join HrmDepartment a3 on a2.supdepid = a3.id left join HrmDepartment a4 on a3.supdepid = a4.id left join HrmDepartment a5 on a4.supdepid = a5.id left join HrmDepartment a6 on a5.supdepid = a6.id left join HrmDepartment a7 on a6.supdepid = a7.id left join HrmDepartment a8 on a6.supdepid = a8.id left join HrmDepartment a9 on a6.supdepid = a9.id left join HrmDepartment a10 on a6.supdepid = a10.id";
recordSeta.executeQuery(sql);
while (recordSeta.next()) {
int rid = recordSeta.getInt("rid");
int levle = 0;
int departmentname1 = recordSeta.getInt("rdepartmentid");
int departmentname2 = recordSeta.getInt("departmentid2");
int departmentname3 = recordSeta.getInt("departmentid3");
int departmentname4 = recordSeta.getInt("departmentid4");
int departmentname5 = recordSeta.getInt("departmentid5");
int departmentname6 = recordSeta.getInt("departmentid6");
int departmentname7 = recordSeta.getInt("departmentid7");
int departmentname8 = recordSeta.getInt("departmentid8");
int departmentname9 = recordSeta.getInt("departmentid9");
int departmentname10 = recordSeta.getInt("departmentid10");
Map<Integer,Integer> rs = new HashMap<>();
if(departmentname1>0) {
levle = 1;
}
if(departmentname2>0) {
levle = 2;
}
if(departmentname3>0) {
levle = 3;
}
if(departmentname4>0) {
levle = 4;
}
if(departmentname5>0) {
levle = 5;
}
if(departmentname6>0) {
levle = 6;
}
if(departmentname7>0) {
levle = 7;
}
if(departmentname8>0) {
levle = 8;
}
if(departmentname9>0) {
levle = 9;
}
if(departmentname10>0) {
levle = 10;
}
//初始化
rs.put(1,0);
rs.put(2,0);
rs.put(3,0);
rs.put(4,0);
rs.put(5,0);
rs.put(6,0);
if(levle == 1) {//一级部门
rs.put(1,departmentname1);
}
if(levle == 2) {//二级部门
rs.put(1,departmentname2);
rs.put(2,departmentname1);
}
if(levle == 3) {//三级部门
rs.put(1,departmentname3);
rs.put(2,departmentname2);
rs.put(3,departmentname1);
}
if(levle == 4) {//四级部门
rs.put(1,departmentname4);
rs.put(2,departmentname3);
rs.put(3,departmentname2);
rs.put(4,departmentname1);
}
if(levle == 5) {//五级部门
rs.put(1,departmentname5);
rs.put(2,departmentname4);
rs.put(3,departmentname3);
rs.put(4,departmentname2);
rs.put(5,departmentname1);
}
if(levle == 6) {//Ⅵ级部门
rs.put(1,departmentname6);
rs.put(2,departmentname5);
rs.put(3,departmentname4);
rs.put(4,departmentname3);
rs.put(5,departmentname2);
rs.put(6,departmentname1);
}
if(levle == 7) {//四级部门
rs.put(1,departmentname7);
rs.put(2,departmentname6);
rs.put(3,departmentname5);
rs.put(4,departmentname4);
rs.put(5,departmentname3);
rs.put(6,departmentname2);
}
if(levle == 8) {//四级部门
rs.put(1,departmentname8);
rs.put(2,departmentname7);
rs.put(3,departmentname6);
rs.put(4,departmentname5);
rs.put(5,departmentname4);
rs.put(6,departmentname3);
}
if(levle == 9) {//四级部门
rs.put(1,departmentname9);
rs.put(2,departmentname8);
rs.put(3,departmentname7);
rs.put(4,departmentname6);
rs.put(5,departmentname5);
rs.put(6,departmentname4);
}
if(levle == 10) {//四级部门
rs.put(1,departmentname10);
rs.put(2,departmentname9);
rs.put(3,departmentname8);
rs.put(4,departmentname7);
rs.put(5,departmentname6);
rs.put(6,departmentname5);
}
if(levle > 0) {
String sql3 = "select count(id) as nums from cus_fielddata where scopeid = -1 and scope = 'HrmCustomFieldByInfoType' and id = "+rid;
recordSetb.executeQuery(sql3);
recordSetb.next();
int nums = recordSetb.getInt("nums");
if(nums>0) {
String sql2 = "update cus_fielddata set "+levle1+" = '"+rs.get(1)+"',"+levle2+" = '"+rs.get(2)+"',"+levle3+"= '"+rs.get(3)+"',"+levle4+" = '"+rs.get(4)+"',"+levle5+" = '"+rs.get(5)+"',"+levle6+" = '"+rs.get(6)+"' where scopeid = -1 and scope = 'HrmCustomFieldByInfoType' and id = "+rid;
recordSetc.executeUpdate(sql2);
log.error("howec::::::::::::::::2:"+sql2);
}else {
String sql4 = "insert into cus_fielddata("+levle1+","+levle2+","+levle3+","+levle4+","+levle5+","+levle6+",scopeid,scope,id) values(?,?,?,?,?,?,?,?,?)";
recordSetc.executeUpdate(sql4,rs.get(1),rs.get(2),rs.get(3),rs.get(4),rs.get(5),rs.get(6),-1,"HrmCustomFieldByInfoType",rid);
}
}
}
}
}
Loading…
Cancel
Save