#weaver-zhewen-1# 初始化代码

main
shilei 9 months ago
parent 20262e1a60
commit da53b73432

@ -0,0 +1,261 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.temporal.TemporalAdjusters" %>
<%@ page import="java.time.DayOfWeek" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupBiz" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
RecordSet rs = new RecordSet();
String serialids = request.getParameter("serialids");
String userid = request.getParameter("userid");
String pbyf = request.getParameter("pbyf");
String serdata = request.getParameter("serdata");
List<String> restList = getSchedulingRestData();
String worktime = "0";
String totalworktime = "0";
if(StringUtils.isNotBlank(serialids)){
String sql = "";
String[] serialidArray = serialids.split(",");
for(int i=0;i<serialidArray.length;i++){
String serialid = serialidArray[i];
if(StringUtils.isNotBlank(serialid)){
if(!restList.contains(serialid)){
String sql2 = " select try_convert(int,worktime) as worktime from kq_ShiftManagement where id ="+serialid+"" ;
sql += StringUtils.isBlank(sql) ? sql2 : " union all \n"+sql2 ;
}
}
}
if(StringUtils.isNotBlank(sql)){
sql = " select round(sum(worktime)/60.0,2) as worktime,sum(worktime) as totalworktime from ("+sql+") w ";
rs.executeQuery(sql);
if(rs.next()){
worktime = Util.null2String(rs.getString("worktime"));
totalworktime = Util.null2String(rs.getString("totalworktime"));
}
}
}
int restcount = 0;
int weekrestcount = 0;
Map<String,String> weekMap = queryWeekTypeByMonth(userid,pbyf);
if(StringUtils.isNotBlank(serdata)){
JSONArray jsonArray = JSONArray.parseArray(serdata);
for(int i=0;i<jsonArray.size();i++){
JSONObject dataJSON = jsonArray.getJSONObject(i);
String date = dataJSON.getString("date");
String serialid = dataJSON.getString("serialid");
if(StringUtils.isNotBlank(serialid)){
if(restList.contains(serialid)){
restcount++;
}
}
if(weekMap.containsKey(date)){
String value = weekMap.get(date);
//6 = 周六 7 = 周日 11 = 公众假日、调配休息日
if("6".equals(value) || "7".equals(value) || "11".equals(value)){
if(restList.contains(serialid)){
weekrestcount++;
}
}
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",worktime);
jsonObject.put("total",totalworktime);
jsonObject.put("restcount",restcount+"");
jsonObject.put("weekrestcount",weekrestcount+"");
%>
<%=jsonObject.toJSONString() %>
<%!
public Map<String,String> queryWeekTypeByMonth(String userid,String pbyf){
Map<String,String> weekMap = new HashMap<String,String>();
if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7) {
LocalDate date = LocalDate.parse(pbyf + "-01"); // 获取当前日期
LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天
LocalDate startDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天
String monthStartDate = startDayOfMonth.toString();
String monthEndDate = lastDayOfMonth.toString();
Map<String,String> holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate);
int thisMonth = date.getMonthValue(); // 获取当前是哪月
int daysInMonth = date.lengthOfMonth(); // 获取本月有多少天
for (int i = 1; i <= daysInMonth; i++) {
LocalDate currentDate = LocalDate.of(date.getYear(), thisMonth, i);
System.out.println("currentDate:" + currentDate.toString());
DayOfWeek dayOfWeek = currentDate.getDayOfWeek();
System.out.println(i + "号是周 " + dayOfWeek.getValue());
int weekValue = dayOfWeek.getValue();
String changeType = "" ;
if(holidayMap.containsKey(currentDate.toString())){
changeType = holidayMap.get(currentDate.toString());
}
if("1".equals(changeType) || "3".equals(changeType)){
weekValue = 11;
}
if(StringUtils.isNotBlank(changeType)){
weekMap.put(currentDate.toString(), weekValue+"");
}else{
weekMap.put(currentDate.toString(), weekValue+"");
}
}
}
return weekMap;
}
public Map<String,String> getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){
Map<String,String> holidayMap = new HashMap<String,String>();
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
try {
if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){
String activeGroupId = getUserActiveGroupId(userid);
bb.writeLog("activeGroupId:"+activeGroupId);
if(StringUtils.isNotBlank(activeGroupId)){
String sql =" select holidayDate,changeType from KQ_HolidaySet\n" +
" where groupid = " + activeGroupId+
" and holidayDate >='"+monthStartDate+"'\n" +
" and holidayDate <='"+monthEndDate+"' " ;
rs.execute(sql);
while (rs.next()){
String holidayDate = Util.null2String(rs.getString("holidayDate"));
String changeType = Util.null2String(rs.getString("changeType"));
holidayMap.put(holidayDate,changeType);
}
}
}
}catch (Exception e){
}
return holidayMap;
}
/***
*
* @param userid
* @return
*/
public String getUserActiveGroupId(String userid){
BaseBean bb = new BaseBean();
KQGroupMemberComInfo kqGroupMemberComInfo = null;
KQGroupComInfo kqGroupComInfo = null ;
String activeGroupId = "";
try{
kqGroupMemberComInfo = new KQGroupMemberComInfo();
kqGroupComInfo = new KQGroupComInfo();
Map<String, List<String>> groupMemberMap = getUserGroup();
String activeGroup = "";
if(groupMemberMap.containsKey(userid)){
List<String> groupIds = groupMemberMap.get(userid);
bb.writeLog("groupIds:"+groupIds.size());
for(String i : groupIds){
String isDelete = kqGroupComInfo.getIsdelete(i);
if(!"1".equals(isDelete)) {
String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate()));
if (i.equals(currentGroupId)) {
activeGroupId = i;
}
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog(e);
}
return activeGroupId;
}
/***
*
* @return
*/
public Map<String, List<String>> getUserGroup(){
BaseBean bb = new BaseBean();
Map<String, List<String>> groupMemberMap = new HashMap<>();
RecordSet rs = new RecordSet();
String viewScope = "3";
try {
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String, Object> groupParams = new HashMap<String, Object>();
if("3".equals(viewScope)){
groupParams.put("isNoAccount", "1");
}
rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams));
while (rs.next()) {
String id = rs.getString("resourceid");
String gid = rs.getString("groupid");
if (!groupMemberMap.containsKey(id))
groupMemberMap.put(id, new ArrayList<>());
groupMemberMap.get(id).add(gid);
}
} catch (Exception e) {
}
return groupMemberMap;
}
public List<String> getSchedulingRestData(){
List<String> list = new ArrayList<String>();
RecordSet rs = new RecordSet();
try{
String sql =" select id " +
" from kq_ShiftManagement \n" +
" where is_rest = 1 \n" +
" and (isdelete is null or isdelete = 0) ";
rs.executeQuery(sql);
while (rs.next()){
String id = Util.null2String(rs.getString("id"));
list.add(id);
}
}catch (Exception e){
}
return list;
}
%>

@ -0,0 +1,223 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.engine.kq.biz.KQGroupBiz" %>
<%@ page import="com.engine.kq.biz.KQGroupComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="java.time.DayOfWeek" %>
<%@ page import="java.time.temporal.TemporalAdjusters" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
String pbyf = request.getParameter("pbyf");
String userid = request.getParameter("userid");
String deptid = request.getParameter("deptid");
int daysInMonth = 0;
Map<String,String> weekMap = new HashMap<String,String>();
List<Map<String,String>> weekList = new ArrayList<Map<String,String>>();
if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7) {
LocalDate date = LocalDate.parse(pbyf + "-01"); // 获取当前日期
LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天
LocalDate startDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天
String monthStartDate = startDayOfMonth.toString();
String monthEndDate = lastDayOfMonth.toString();
Map<String,String> holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate);
int thisMonth = date.getMonthValue(); // 获取当前是哪月
daysInMonth = date.lengthOfMonth(); // 获取本月有多少天
for (int i = 1; i <= daysInMonth; i++) {
LocalDate currentDate = LocalDate.of(date.getYear(), thisMonth, i);
System.out.println("currentDate:" + currentDate.toString());
DayOfWeek dayOfWeek = currentDate.getDayOfWeek();
System.out.println(i + "号是周 " + dayOfWeek.getValue());
int weekValue = dayOfWeek.getValue();
String weekDayName = "";
switch (weekValue) {
case 1:
weekDayName = "周一";
break;
case 2:
weekDayName = "周二";
break;
case 3:
weekDayName = "周三";
break;
case 4:
weekDayName = "周四";
break;
case 5:
weekDayName = "周五";
break;
case 6:
weekDayName = "周六";
break;
case 7:
weekDayName = "周日";
break;
}
String changeType = "" ;
if(holidayMap.containsKey(currentDate.toString())){
changeType = holidayMap.get(currentDate.toString());
}
weekMap = new HashMap<String,String>();
weekMap.put("weekname", weekDayName);
weekMap.put("changeType", changeType);
weekMap.put("weekday", i+"");
weekMap.put("weekdate", currentDate.toString());
weekList.add(weekMap);
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",weekList);
jsonObject.put("count",daysInMonth);
%>
<%=jsonObject.toJSONString() %>
<%!
/***
*
* @param userid
* @return
*/
public String getUserActiveGroupId(String userid){
BaseBean bb = new BaseBean();
KQGroupMemberComInfo kqGroupMemberComInfo = null;
KQGroupComInfo kqGroupComInfo = null ;
String activeGroupId = "";
try{
kqGroupMemberComInfo = new KQGroupMemberComInfo();
kqGroupComInfo = new KQGroupComInfo();
Map<String, List<String>> groupMemberMap = getUserGroup();
String activeGroup = "";
if(groupMemberMap.containsKey(userid)){
List<String> groupIds = groupMemberMap.get(userid);
bb.writeLog("groupIds:"+groupIds.size());
for(String i : groupIds){
String isDelete = kqGroupComInfo.getIsdelete(i);
if(!"1".equals(isDelete)) {
String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate()));
if (i.equals(currentGroupId)) {
activeGroupId = i;
}
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog(e);
}
return activeGroupId;
}
/***
*
* @return
*/
public Map<String, List<String>> getUserGroup(){
BaseBean bb = new BaseBean();
Map<String, List<String>> groupMemberMap = new HashMap<>();
RecordSet rs = new RecordSet();
String viewScope = "3";
try {
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String, Object> groupParams = new HashMap<String, Object>();
if("3".equals(viewScope)){
groupParams.put("isNoAccount", "1");
}
rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams));
while (rs.next()) {
String id = rs.getString("resourceid");
String gid = rs.getString("groupid");
if (!groupMemberMap.containsKey(id))
groupMemberMap.put(id, new ArrayList<>());
groupMemberMap.get(id).add(gid);
}
} catch (Exception e) {
}
return groupMemberMap;
}
public Map<String,String> getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){
Map<String,String> holidayMap = new HashMap<String,String>();
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
try {
if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){
String activeGroupId = getUserActiveGroupId(userid);
bb.writeLog("activeGroupId:"+activeGroupId);
if(StringUtils.isNotBlank(activeGroupId)){
String sql =" select holidayDate,changeType from KQ_HolidaySet\n" +
" where groupid = " + activeGroupId+
" and holidayDate >='"+monthStartDate+"'\n" +
" and holidayDate <='"+monthEndDate+"' " ;
rs.execute(sql);
while (rs.next()){
String holidayDate = Util.null2String(rs.getString("holidayDate"));
String changeType = Util.null2String(rs.getString("changeType"));
String changeTypename = "" ;
if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日
changeTypename += "公众假日";
}else if("2".equals(changeType)){
changeTypename += "调配工作日";
}else if("3".equals(changeType)){
changeTypename += "调配休息日";
}
holidayMap.put(holidayDate,changeTypename);
// if(weekMap.containsKey(holidayDate)){
// String holidayDate_new = weekMap.get(holidayDate);
// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日
// holidayDate_new += "[公众假日]";
// }else if("1".equals(changeType)){
// holidayDate_new += "[调配工作日]";
// }else if("2".equals(changeType)){
// holidayDate_new += "[调配休息日]";
// }
// weekMap.put(holidayDate,holidayDate_new);
// }
}
}
}
}catch (Exception e){
}
return holidayMap;
}
%>

@ -0,0 +1,35 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
List<String> list = new ArrayList<String>();
RecordSet rs = new RecordSet();
String sql =" select id " +
" from kq_ShiftManagement \n" +
" where is_rest = 1 \n" +
" and (isdelete is null or isdelete = 0) ";
rs.executeQuery(sql);
while (rs.next()){
String id = Util.null2String(rs.getString("id"));
list.add(id);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",list);
%>
<%=jsonObject.toJSONString() %>

@ -0,0 +1,54 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
List<Map<String,Object>> mainList = new ArrayList<Map<String,Object>>();
RecordSet rs = new RecordSet();
String pbry = request.getParameter("pbry");
if(StringUtils.isNotBlank(pbry)) {
String sql = "select id,lastname from hrmresource where id in("+pbry+")";
rs.executeQuery(sql);
while (rs.next()){
String userid = Util.null2String(rs.getString("id"));
String lastname = Util.null2String(rs.getString("lastname"));
Map<String,Object> mainMap = new HashMap<String,Object>();
mainMap.put("id",userid);
mainMap.put("name",lastname);
List<Map<String,String>> specialobjList = new ArrayList<Map<String,String>>();
Map<String,String> specialobjMap = new HashMap<String,String>();
specialobjMap.put("id",userid);
specialobjMap.put("name",lastname);
specialobjList.add(specialobjMap);
Map<String,Object> valueMap = new HashMap<String,Object>();
valueMap.put("value",userid);
valueMap.put("specialobj",specialobjList);
mainMap.put("value",valueMap);
mainList.add(mainMap);
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("main",mainList);
%>
<%=jsonObject.toJSONString() %>

@ -0,0 +1,66 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
List<Map<String,Object>> userList = new ArrayList<Map<String,Object>>();
List<Map<String,Object>> dt1List = new ArrayList<Map<String,Object>>();
Map<String,Object> userMap = null;
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
String cjrbm = request.getParameter("cjrbm");
if(StringUtils.isNotBlank(cjrbm)) {
String sql = "select id,lastname from hrmresource where departmentid = ?";
rs.executeQuery(sql,new Object[]{cjrbm});
while (rs.next()){
String userid = Util.null2String(rs.getString("id"));
String lastname = Util.null2String(rs.getString("lastname"));
userMap = new HashMap<String,Object>();
userMap.put("id",userid);
userMap.put("name",lastname);
List<Map<String,String>> specialobjList = new ArrayList<Map<String,String>>();
Map<String,String> specialobjMap = new HashMap<String,String>();
specialobjMap.put("id",userid);
specialobjMap.put("name",lastname);
specialobjList.add(specialobjMap);
Map<String,Object> valueMap = new HashMap<String,Object>();
valueMap.put("value",userid);
valueMap.put("specialobj",specialobjList);
userMap.put("value",valueMap);
userList.add(userMap);
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",userList);
jsonObject.put("dt1",userList);
%>
<%=jsonObject.toJSONString() %>

@ -0,0 +1,127 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
String cjrbm = request.getParameter("cjrbm");
Map<String,Object> valueMap = new HashMap<>();
List<Map<String,Object>> dt1List = new ArrayList<Map<String,Object>>();
if(StringUtils.isNotBlank(cjrbm)) {
String sql = "select id,lastname from hrmresource where departmentid = "+cjrbm ;
List<Map<String,String>> hrmList = queryListBySql(sql);
valueMap = getMainUserDate(hrmList);
dt1List = getDt1UserDate(hrmList);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",valueMap);
jsonObject.put("dt1",dt1List);
%>
<%=jsonObject.toJSONString() %>
<%!
public List<Map<String,Object>> getDt1UserDate(List<Map<String,String>> hrmList){
List<Map<String,Object>> dt1List = new ArrayList<Map<String,Object>>();
for(int i=0;i<hrmList.size();i++){
Map<String,String> hrmMap = hrmList.get(i);
String userid = Util.null2String(hrmMap.get("id"));
String lastname = Util.null2String(hrmMap.get("lastname"));
Map<String,Object> dt1Map = new HashMap<String,Object>();
dt1Map.put("id",userid);
dt1Map.put("name",lastname);
List<Map<String,String>> specialobjList2 = new ArrayList<Map<String,String>>();
Map<String,String> specialobjMap2 = new HashMap<String,String>();
specialobjMap2.put("id",userid);
specialobjMap2.put("name",lastname);
specialobjList2.add(specialobjMap2);
Map<String,Object> valueMap2 = new HashMap<String,Object>();
valueMap2.put("value",userid);
valueMap2.put("specialobj",specialobjList2);
dt1Map.put("value",valueMap2);
dt1List.add(dt1Map);
}
return dt1List;
}
/***
*
* @param hrmList
* @return
*/
public Map<String,Object> getMainUserDate(List<Map<String,String>> hrmList){
String userids = "";
List<Map<String,String>> specialobjList = new ArrayList<Map<String,String>>();
for(int i=0;i<hrmList.size();i++){
Map<String,String> hrmMap = hrmList.get(i);
String userid = Util.null2String(hrmMap.get("id"));
String lastname = Util.null2String(hrmMap.get("lastname"));
userids += StringUtils.isBlank(userids) ? userid : ","+userid ;
Map<String,String> specialobjMap = new HashMap<String,String>();
specialobjMap.put("id",userid);
specialobjMap.put("name",lastname);
specialobjList.add(specialobjMap);
}
Map<String,Object> valueMap = new HashMap<String,Object>();
valueMap.put("value",userids);
valueMap.put("specialobj",specialobjList);
return valueMap;
}
public List<Map<String,String>> queryListBySql(String sql){
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
try{
if(StringUtils.isNotBlank(sql)){
Map<String,String> map = new HashMap<String,String>();
rs.executeQuery(sql);
String[] column = rs.getColumnName();
while (rs.next()){
map = new HashMap<String,String>();
for(int i=0;i<column.length;i++){
String value = rs.getString(column[i]);
map.put(column[i],value);
}
if(!map.isEmpty() && map.size()>0){
list.add(map);
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog("queryListBySql-e:"+e);
}
return list;
}
%>

@ -0,0 +1,378 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupBiz" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.DayOfWeek" %>
<%@ page import="java.time.temporal.TemporalAdjusters" %>
<%@ page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
String[] workSchedule = {"09:00-11:00","11:00-16:00","16:00-20:00","20:00-21:30"};
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
int userid = user.getUID();
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
String pbdata = request.getParameter("pbdata");
// if(StringUtils.isBlank(pb)){
//
// JSONArray jsonArray = new JSONArray();
// JSONObject userObject = new JSONObject();
// userObject.put("userid","3039");
// userObject.put("serialid","10");
// jsonArray.add(userObject);
//
// userObject = new JSONObject();
// userObject.put("userid","3373");
// userObject.put("serialid","7");
// jsonArray.add(userObject);
//
// userObject = new JSONObject();
// userObject.put("userid","3661");
// userObject.put("serialid","9");
// jsonArray.add(userObject);
// pb = jsonArray.toJSONString();
// }
String yjl = request.getParameter("yjl");
String pbrq = request.getParameter("pbrq");
String dateType = "0";
if(StringUtils.isNotBlank(pbrq)){
dateType = getWeekTypeByDate(pbrq,userid+"");
}
Map<String,Integer> defaultScheduleMap = new HashMap<String,Integer>();
if(StringUtils.isNotBlank(yjl)){
String sql = " select dysjd,pzrs from uf_pbjcsj where yjl = ? and pblx = ?" ;
rs.executeQuery(sql,new Object[]{yjl,dateType});
while (rs.next()){
int dysd = Util.getIntValue(Util.null2String(rs.getString("dysjd")));
int pzrs = Util.getIntValue(Util.null2String(rs.getString("pzrs")));
String sjd = "";
if(dysd < workSchedule.length){
sjd = workSchedule[dysd];
if(StringUtils.isNotBlank(sjd)){
defaultScheduleMap.put(sjd,pzrs);
}
}
}
}
List<Map<String,String>> workScheduleList = new ArrayList<Map<String,String>>();
Map<String,String> workScheduleMap = null;
for(int k=0;k<workSchedule.length;k++){
if(workSchedule[k].indexOf("-")>0){
String[] schedule = workSchedule[k].split("-");
String scheduleStartTime = schedule[0];
String scheduleEndTime = schedule[1];
if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){
workScheduleMap = new HashMap<String,String>();
workScheduleMap.put("start",scheduleStartTime);
workScheduleMap.put("end",scheduleEndTime);
workScheduleList.add(workScheduleMap);
}
}
}
Map<String,Map<String,String>> userScheduleDayMap = new HashMap<String,Map<String,String>>();
Map<String,Integer> necessaryMap = new HashMap<String,Integer>();
Map<String,Integer> userScheduleMap = new HashMap<String,Integer>();
if(StringUtils.isNotBlank(pbdata)) {
JSONArray jsonArray = JSONArray.parseArray(pbdata);
String yxrys = "" ;
for(int i = 0;i<jsonArray.size();i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pbry = jsonObject.getString("userid");
yxrys+= StringUtils.isBlank(yxrys) ? pbry : ","+pbry ;
}
List<String> userList = new ArrayList<String>();
String sql =" select h.id \n" +
" from hrmresource h \n" +
" inner join hrmjobtitles k on k.id = h.jobtitle\n" +
" where h.id in("+yxrys+")\n" +
" and k.jobtitlename in('店长','验光师')\n" +
" and h.status in(0,1,2,3,4)\n" +
" union \n" +
" select h.id \n" +
" from hrmresource h \n" +
" inner join cus_fielddata k on k.id = h.id\n" +
" where k.field39 = 2 \n" +
" and k.scopeid=3 \n" +
" and k.scope='HrmCustomFieldByInfoType' " +
" and h.id in("+yxrys+") and h.status in(0,1,2,3,4) " +
" union " +
" select h.id\n" +
" from hrmresource h \n" +
" inner join cus_fielddata k on k.id = h.id \n" +
" where k.scopeid=-1 " +
" and k.scope='HrmCustomFieldByInfoType'\n" +
" and substring(k.field1,charindex('_',k.field1)+1,len(k.field1)) in(select id from uf_gwjbsjb where jbmc in('配镜三级','配镜四级','配镜五级')) and charindex('_', k.field1) > 0 \n" +
" and h.status in(0,1,2,3,4) "+
" and h.id in("+yxrys+") ";
rs.executeQuery(sql);
while (rs.next()){
String id = Util.null2String(rs.getString("id"));
userList.add(id);
}
for(int i = 0;i<jsonArray.size();i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pbry = jsonObject.getString("userid");
String serialid = jsonObject.getString("serialid");
String startTime = "";
String endTime = "";
sql = " select times,onoffworktype from kq_ShiftOnOffWorkSections where serialid = ? and (isdelete = 0 or isdelete is null) ";
rs.executeQuery(sql,new Object[]{serialid});
while(rs.next()){
String onoffworktype = Util.null2String(rs.getString("onoffworktype"));
if("start".equals(onoffworktype)){
startTime = Util.null2String(rs.getString("times"));
}else if("end".equals(onoffworktype)){
endTime = Util.null2String(rs.getString("times"));
}
}
Map<String,String> userSchedule_Map = new HashMap<String,String>();
if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){
userSchedule_Map.put("startTime",startTime);
userSchedule_Map.put("endTime",endTime);
for(int k=0;k<workScheduleList.size();k++){
Map<String,String> workSchedule_Map = workScheduleList.get(k);
String scheduleStartTime = workSchedule_Map.get("start");
String scheduleEndTime = workSchedule_Map.get("end");
if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){
if(startTime.compareTo(scheduleStartTime) <=0 && endTime.compareTo(scheduleEndTime) >=0){
String defWorkSchedule = scheduleStartTime+"-"+scheduleEndTime ;
if(userScheduleMap.containsKey(defWorkSchedule)){
int count = userScheduleMap.get(defWorkSchedule);
count++;
userScheduleMap.put(defWorkSchedule,count);
}else{
userScheduleMap.put(defWorkSchedule,1);
}
if(userList.contains(pbry)){
necessaryMap.put(defWorkSchedule,1);
}
}
}
}
}
userScheduleDayMap.put(pbry,userSchedule_Map);
}
}
int defaultcount = 0;
int datacount = 0;
Iterator<Map.Entry<String, Integer>> iterator = defaultScheduleMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> entry = iterator.next();
int value =entry.getValue();
String key = entry.getKey();
if(userScheduleMap.containsKey(key)){
int useValue = userScheduleMap.get(key);
if(useValue < value){
datacount++;
}
}else{
datacount++;
}
defaultcount++;
}
JSONObject jsonObject = new JSONObject();
if(defaultcount >0 && datacount == 0){
if(necessaryMap.size() == 4){
jsonObject.put("pbcode","1");
}else{
jsonObject.put("pbcode","2");
}
}else{
jsonObject.put("pbcode","0");
}
jsonObject.put("pbinfo",userScheduleDayMap);
%>
<%=jsonObject.toJSONString() %>
<%!
public String getWeekTypeByDate(String pbrq,String userid){
String dateType = "0";
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate currentDate = LocalDate.parse(pbrq, df);
DayOfWeek dayOfWeek = currentDate.getDayOfWeek();
int weekValue = dayOfWeek.getValue();
LocalDate lastDayOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天
LocalDate startDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天
String monthStartDate = startDayOfMonth.toString();
String monthEndDate = lastDayOfMonth.toString();
Map<String,String> holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate);
String changeType = "" ;
if(holidayMap.containsKey(currentDate.toString())){
changeType = holidayMap.get(currentDate.toString());
}
if("1".equals(changeType) || "3".equals(changeType)){
dateType = "1";
}else if(weekValue == 6 || weekValue == 7){
dateType = "1";
}
return dateType;
}
/***
*
* @param userid
* @param monthStartDate
* @param monthEndDate
* @return
*/
public Map<String,String> getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){
Map<String,String> holidayMap = new HashMap<String,String>();
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
try {
if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){
String activeGroupId = getUserActiveGroupId(userid);
bb.writeLog("activeGroupId:"+activeGroupId);
if(StringUtils.isNotBlank(activeGroupId)){
String sql =" select holidayDate,changeType from KQ_HolidaySet\n" +
" where groupid = " + activeGroupId+
" and holidayDate >='"+monthStartDate+"'\n" +
" and holidayDate <='"+monthEndDate+"' " ;
rs.execute(sql);
while (rs.next()){
String holidayDate = Util.null2String(rs.getString("holidayDate"));
String changeType = Util.null2String(rs.getString("changeType"));
// String changeTypename = "" ;
// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日
// changeTypename += "公众假日";
// }else if("2".equals(changeType)){
// changeTypename += "调配工作日";
// }else if("3".equals(changeType)){
// changeTypename += "调配休息日";
// }
holidayMap.put(holidayDate,changeType);
// if(weekMap.containsKey(holidayDate)){
// String holidayDate_new = weekMap.get(holidayDate);
// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日
// holidayDate_new += "[公众假日]";
// }else if("1".equals(changeType)){
// holidayDate_new += "[调配工作日]";
// }else if("2".equals(changeType)){
// holidayDate_new += "[调配休息日]";
// }
// weekMap.put(holidayDate,holidayDate_new);
// }
}
}
}
}catch (Exception e){
}
return holidayMap;
}
/***
*
* @param userid
* @return
*/
public String getUserActiveGroupId(String userid){
BaseBean bb = new BaseBean();
KQGroupMemberComInfo kqGroupMemberComInfo = null;
KQGroupComInfo kqGroupComInfo = null ;
String activeGroupId = "";
try{
kqGroupMemberComInfo = new KQGroupMemberComInfo();
kqGroupComInfo = new KQGroupComInfo();
Map<String, List<String>> groupMemberMap = getUserGroup();
String activeGroup = "";
if(groupMemberMap.containsKey(userid)){
List<String> groupIds = groupMemberMap.get(userid);
bb.writeLog("groupIds:"+groupIds.size());
for(String i : groupIds){
String isDelete = kqGroupComInfo.getIsdelete(i);
if(!"1".equals(isDelete)) {
String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate()));
if (i.equals(currentGroupId)) {
activeGroupId = i;
}
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog(e);
}
return activeGroupId;
}
/***
*
* @return
*/
public Map<String, List<String>> getUserGroup(){
BaseBean bb = new BaseBean();
Map<String, List<String>> groupMemberMap = new HashMap<>();
RecordSet rs = new RecordSet();
String viewScope = "3";
try {
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String, Object> groupParams = new HashMap<String, Object>();
if("3".equals(viewScope)){
groupParams.put("isNoAccount", "1");
}
rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams));
while (rs.next()) {
String id = rs.getString("resourceid");
String gid = rs.getString("groupid");
if (!groupMemberMap.containsKey(id))
groupMemberMap.put(id, new ArrayList<>());
groupMemberMap.get(id).add(gid);
}
} catch (Exception e) {
}
return groupMemberMap;
}
%>

@ -0,0 +1,383 @@
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.engine.kq.biz.KQGroupMemberComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupComInfo" %>
<%@ page import="com.engine.kq.biz.KQGroupBiz" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.DayOfWeek" %>
<%@ page import="java.time.temporal.TemporalAdjusters" %>
<%@ page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
String[] workSchedule = {"09:00-11:00","11:00-16:00","16:00-20:00","20:00-21:30"};
User user = HrmUserVarify.getUser(request, response);
if(user==null) {
response.sendRedirect("/login/Login.jsp");
return;
}
int userid = user.getUID();
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
String pbdata = request.getParameter("pbdata");
// if(StringUtils.isBlank(pb)){
//
// JSONArray jsonArray = new JSONArray();
// JSONObject userObject = new JSONObject();
// userObject.put("userid","3039");
// userObject.put("serialid","10");
// jsonArray.add(userObject);
//
// userObject = new JSONObject();
// userObject.put("userid","3373");
// userObject.put("serialid","7");
// jsonArray.add(userObject);
//
// userObject = new JSONObject();
// userObject.put("userid","3661");
// userObject.put("serialid","9");
// jsonArray.add(userObject);
// pb = jsonArray.toJSONString();
// }
String yjl = request.getParameter("yjl");
String pbrq = request.getParameter("pbrq");
String dateType = "0";
if(StringUtils.isNotBlank(pbrq)){
dateType = getWeekTypeByDate(pbrq,userid+"");
}
Map<String,Integer> defaultScheduleMap = new HashMap<String,Integer>();
if(StringUtils.isNotBlank(yjl)){
String sql = " select dysjd,pzrs from uf_pbjcsj where yjl = ? and pblx = ?" ;
rs.executeQuery(sql,new Object[]{yjl,dateType});
while (rs.next()){
int dysd = Util.getIntValue(Util.null2String(rs.getString("dysjd")));
int pzrs = Util.getIntValue(Util.null2String(rs.getString("pzrs")));
String sjd = "";
if(dysd < workSchedule.length){
sjd = workSchedule[dysd];
if(StringUtils.isNotBlank(sjd)){
defaultScheduleMap.put(sjd,pzrs);
}
}
}
}
List<Map<String,String>> workScheduleList = new ArrayList<Map<String,String>>();
Map<String,String> workScheduleMap = null;
for(int k=0;k<workSchedule.length;k++){
if(workSchedule[k].indexOf("-")>0){
String[] schedule = workSchedule[k].split("-");
String scheduleStartTime = schedule[0];
String scheduleEndTime = schedule[1];
if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){
workScheduleMap = new HashMap<String,String>();
workScheduleMap.put("start",scheduleStartTime);
workScheduleMap.put("end",scheduleEndTime);
workScheduleList.add(workScheduleMap);
}
}
}
Map<String,Map<String,String>> userScheduleDayMap = new HashMap<String,Map<String,String>>();
Map<String,Integer> userScheduleMap = new HashMap<String,Integer>();
Map<String,Integer> necessaryMap = new HashMap<String,Integer>();
if(StringUtils.isNotBlank(pbdata)) {
JSONArray jsonArray = JSONArray.parseArray(pbdata);
String yxrys = "" ;
for(int i = 0;i<jsonArray.size();i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pbry = jsonObject.getString("userid");
yxrys+= StringUtils.isBlank(yxrys) ? pbry : ","+pbry ;
}
out.println("yxrys:"+yxrys+"</br>");
List<String> userList = new ArrayList<String>();
String sql =" select h.id \n" +
" from hrmresource h \n" +
" inner join hrmjobtitles k on k.id = h.jobtitle\n" +
" where h.id in("+yxrys+")\n" +
" and k.jobtitlename in('店长','验光师')\n" +
" and h.status in(0,1,2,3,4)\n" +
" union \n" +
" select h.id \n" +
" from hrmresource h \n" +
" inner join cus_fielddata k on k.id = h.id\n" +
" where k.field39 = 2 \n" +
" and k.scopeid=3 \n" +
" and k.scope='HrmCustomFieldByInfoType' " +
" and h.id in("+yxrys+") and h.status in(0,1,2,3,4) " +
" union " +
" select h.id\n" +
" from hrmresource h \n" +
" inner join cus_fielddata k on k.id = h.id \n" +
" where k.scopeid=-1 " +
" and k.scope='HrmCustomFieldByInfoType'\n" +
" and substring(k.field1,charindex('_',k.field1)+1,len(k.field1)) in(select id from uf_gwjbsjb where jbmc in('配镜三级','配镜四级','配镜五级')) and charindex('_', k.field1) > 0 \n" +
" and h.status in(0,1,2,3,4) "+
" and h.id in("+yxrys+") ";
out.println("sql:"+sql+"</br>");
rs.executeQuery(sql);
while (rs.next()){
String id = Util.null2String(rs.getString("id"));
out.println("id:"+id+"</br>");
userList.add(id);
}
for(int i = 0;i<jsonArray.size();i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pbry = jsonObject.getString("userid");
String serialid = jsonObject.getString("serialid");
String startTime = "";
String endTime = "";
sql = " select times,onoffworktype from kq_ShiftOnOffWorkSections where serialid = ? and (isdelete = 0 or isdelete is null) ";
rs.executeQuery(sql,new Object[]{serialid});
while(rs.next()){
String onoffworktype = Util.null2String(rs.getString("onoffworktype"));
if("start".equals(onoffworktype)){
startTime = Util.null2String(rs.getString("times"));
}else if("end".equals(onoffworktype)){
endTime = Util.null2String(rs.getString("times"));
}
}
Map<String,String> userSchedule_Map = new HashMap<String,String>();
if(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)){
userSchedule_Map.put("startTime",startTime);
userSchedule_Map.put("endTime",endTime);
for(int k=0;k<workScheduleList.size();k++){
Map<String,String> workSchedule_Map = workScheduleList.get(k);
String scheduleStartTime = workSchedule_Map.get("start");
String scheduleEndTime = workSchedule_Map.get("end");
if(StringUtils.isNotBlank(scheduleStartTime) && StringUtils.isNotBlank(scheduleEndTime)){
if(startTime.compareTo(scheduleStartTime) <=0 && endTime.compareTo(scheduleEndTime) >=0){
String defWorkSchedule = scheduleStartTime+"-"+scheduleEndTime ;
if(userScheduleMap.containsKey(defWorkSchedule)){
int count = userScheduleMap.get(defWorkSchedule);
count++;
userScheduleMap.put(defWorkSchedule,count);
}else{
userScheduleMap.put(defWorkSchedule,1);
}
if(userList.contains(pbry)){
necessaryMap.put(defWorkSchedule,1);
}
}
}
}
}
userScheduleDayMap.put(pbry,userSchedule_Map);
}
}
int defaultcount = 0;
int datacount = 0;
Iterator<Map.Entry<String, Integer>> iterator = defaultScheduleMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> entry = iterator.next();
int value =entry.getValue();
String key = entry.getKey();
if(userScheduleMap.containsKey(key)){
int useValue = userScheduleMap.get(key);
if(useValue < value){
datacount++;
}
}else{
datacount++;
}
defaultcount++;
}
out.println("necessaryMap:"+necessaryMap.size());
JSONObject jsonObject = new JSONObject();
if(defaultcount >0 && datacount == 0){
if(necessaryMap.size() == 4){
jsonObject.put("pbcode","1");
}else{
jsonObject.put("pbcode","2");
}
}else{
jsonObject.put("pbcode","0");
}
jsonObject.put("pbinfo",userScheduleDayMap);
%>
<%=jsonObject.toJSONString() %>
<%!
public String getWeekTypeByDate(String pbrq,String userid){
String dateType = "0";
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate currentDate = LocalDate.parse(pbrq, df);
DayOfWeek dayOfWeek = currentDate.getDayOfWeek();
int weekValue = dayOfWeek.getValue();
LocalDate lastDayOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth()); // 获取本月最后一天
LocalDate startDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth()); // 获取本月最后一天
String monthStartDate = startDayOfMonth.toString();
String monthEndDate = lastDayOfMonth.toString();
Map<String,String> holidayMap = getHolidayByGroupId(userid,monthStartDate,monthEndDate);
String changeType = "" ;
if(holidayMap.containsKey(currentDate.toString())){
changeType = holidayMap.get(currentDate.toString());
}
if("1".equals(changeType) || "3".equals(changeType)){
dateType = "1";
}else if(weekValue == 6 || weekValue == 7){
dateType = "1";
}
return dateType;
}
/***
*
* @param userid
* @param monthStartDate
* @param monthEndDate
* @return
*/
public Map<String,String> getHolidayByGroupId(String userid,String monthStartDate,String monthEndDate){
Map<String,String> holidayMap = new HashMap<String,String>();
BaseBean bb = new BaseBean();
RecordSet rs = new RecordSet();
try {
if(StringUtils.isNotBlank(userid) && StringUtils.isNotBlank(monthStartDate) && StringUtils.isNotBlank(monthEndDate)){
String activeGroupId = getUserActiveGroupId(userid);
bb.writeLog("activeGroupId:"+activeGroupId);
if(StringUtils.isNotBlank(activeGroupId)){
String sql =" select holidayDate,changeType from KQ_HolidaySet\n" +
" where groupid = " + activeGroupId+
" and holidayDate >='"+monthStartDate+"'\n" +
" and holidayDate <='"+monthEndDate+"' " ;
rs.execute(sql);
while (rs.next()){
String holidayDate = Util.null2String(rs.getString("holidayDate"));
String changeType = Util.null2String(rs.getString("changeType"));
// String changeTypename = "" ;
// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日
// changeTypename += "公众假日";
// }else if("2".equals(changeType)){
// changeTypename += "调配工作日";
// }else if("3".equals(changeType)){
// changeTypename += "调配休息日";
// }
holidayMap.put(holidayDate,changeType);
// if(weekMap.containsKey(holidayDate)){
// String holidayDate_new = weekMap.get(holidayDate);
// if("1".equals(changeType)){ //1-公众假日 2-调配工作日 3-调配休息日
// holidayDate_new += "[公众假日]";
// }else if("1".equals(changeType)){
// holidayDate_new += "[调配工作日]";
// }else if("2".equals(changeType)){
// holidayDate_new += "[调配休息日]";
// }
// weekMap.put(holidayDate,holidayDate_new);
// }
}
}
}
}catch (Exception e){
}
return holidayMap;
}
/***
*
* @param userid
* @return
*/
public String getUserActiveGroupId(String userid){
BaseBean bb = new BaseBean();
KQGroupMemberComInfo kqGroupMemberComInfo = null;
KQGroupComInfo kqGroupComInfo = null ;
String activeGroupId = "";
try{
kqGroupMemberComInfo = new KQGroupMemberComInfo();
kqGroupComInfo = new KQGroupComInfo();
Map<String, List<String>> groupMemberMap = getUserGroup();
String activeGroup = "";
if(groupMemberMap.containsKey(userid)){
List<String> groupIds = groupMemberMap.get(userid);
bb.writeLog("groupIds:"+groupIds.size());
for(String i : groupIds){
String isDelete = kqGroupComInfo.getIsdelete(i);
if(!"1".equals(isDelete)) {
String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate()));
if (i.equals(currentGroupId)) {
activeGroupId = i;
}
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog(e);
}
return activeGroupId;
}
/***
*
* @return
*/
public Map<String, List<String>> getUserGroup(){
BaseBean bb = new BaseBean();
Map<String, List<String>> groupMemberMap = new HashMap<>();
RecordSet rs = new RecordSet();
String viewScope = "3";
try {
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String, Object> groupParams = new HashMap<String, Object>();
if("3".equals(viewScope)){
groupParams.put("isNoAccount", "1");
}
rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams));
while (rs.next()) {
String id = rs.getString("resourceid");
String gid = rs.getString("groupid");
if (!groupMemberMap.containsKey(id))
groupMemberMap.put(id, new ArrayList<>());
groupMemberMap.get(id).add(gid);
}
} catch (Exception e) {
}
return groupMemberMap;
}
%>

@ -0,0 +1,339 @@
package com.engine.kq.biz;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.entity.WorkTimeEntity;
import com.engine.kq.log.KQLog;
import weaver.common.DateUtil;
import weaver.conn.BatchRecordSet;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
*/
public class KQFormatBiz extends BaseBean {
private String today = DateUtil.getCurrentDate();
protected KQLog kqLog = new KQLog();
/**
*
*
* @param lsFormatParams
*/
public void format(List<List<Object>> lsFormatParams) {
format(lsFormatParams, -1);
}
/**
*
* @param lsFormatParams
* @param formatType -1: ; 11:; 12: ;13:; 14: 15: ;16:
*/
public void format(List<List<Object>> lsFormatParams, int formatType) {
BatchRecordSet bRs = new BatchRecordSet();
String sql = "";
List<Object> params = null;
try {
for(List<Object> list : lsFormatParams) {
list.add(formatType);
}
if (KQSettingsBiz.getKqformatthread()) {
sql = " insert into kq_format_pool (resourceid, kqdate, formattype) values (?,?,?)";
if (KQSettingsBiz.getKqformatAccurate()){
sql = " insert into kq_format_pool (resourceid, kqdate, exectime,formattype) values (?,?,?,?)";
lsFormatParams = processFormatParams(lsFormatParams);
}
bRs.executeBatchSqlNew(sql, lsFormatParams);
} else {
String resourceid = "";
String kqdate = "";
for (int i = 0; lsFormatParams != null && i < lsFormatParams.size(); i++) {
params = lsFormatParams.get(i);
resourceid = Util.null2String(params.get(0));
kqdate = Util.null2String(params.get(1));
new KQFormatData().formatKqDateByLock(resourceid, kqdate,formatType);
}
}
} catch (Exception e) {
writeLog(" KQFormatData.formatKqDate lsFormatParams >>>>>>>>>" + e);
}
}
public void formatDateByKQDate(String kqdate) {
String sql = "";
RecordSet rs = new RecordSet();
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
try {
if (DateUtil.timeInterval(kqdate, today) < 0) {
kqLog.info("今天之后的无需处理的数据kqdate==" + kqdate + "today==" + today);
return;//今天之后的无需处理
}
sql = " SELECT distinct resourceid FROM ( " +
new KQGroupBiz().getGroupMemberSql() + ") t ";
rs.executeQuery(sql);
while (rs.next()) {
String resourceid = rs.getString("resourceid");
if(Util.null2String(kqdate).length()!=10)return;
formatParams = new ArrayList<>();
formatParams.add(resourceid);
formatParams.add(kqdate);
lsFormatParams.add(formatParams);
}
this.format(lsFormatParams);
} catch (Exception e) {
writeLog(e);
kqLog.info(e);
}
}
public void formatDateByGroupId(String groupid, String kqdate) {
String sql = "";
RecordSet rs = new RecordSet();
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
try {
if (DateUtil.timeInterval(kqdate, today) < 0) {
kqLog.info("今天之后的无需处理的数据groupid==" + groupid + "kqdate==" + kqdate + "today==" + today);
return;//今天之后的无需处理
}
KQGroupComInfo kqGroupComInfo = new KQGroupComInfo();
KQGroupBiz kqGroupBiz = new KQGroupBiz();
String kqtype = kqGroupComInfo.getKqtype(groupid);
if (kqtype.equals("2")) {//排班
sql = "select resourceid, kqdate from kq_shiftschedule where groupid=" + groupid + " and kqdate='" + kqdate + "' and (isdelete is null or isdelete <> '1') ";
} else {
sql = "select resourceid,'" + kqdate + "' from (" + kqGroupBiz.getGroupMemberSql(groupid) + ") t ";
}
rs.executeQuery(sql);
while (rs.next()) {
String resourceid = rs.getString("resourceid");
if(Util.null2String(kqdate).length()!=10)return;
formatParams = new ArrayList<>();
formatParams.add(resourceid);
formatParams.add(kqdate);
lsFormatParams.add(formatParams);
}
this.format(lsFormatParams);
} catch (Exception e) {
writeLog(e);
kqLog.info(e);
}
}
public void formatDate(String resourceid, String kqdate) {
List<List<Object>> lsFormatParams = new ArrayList<>();
List<Object> formatParams = null;
try {
if (DateUtil.timeInterval(kqdate, today) < 0) {
kqLog.info("今天之后的无需处理的数据resourceid==" + resourceid + "kqdate==" + kqdate + "today==" + today);
return;//今天之后的无需处理
}
if(Util.null2String(kqdate).length()!=10)return;
formatParams = new ArrayList<>();
formatParams.add(resourceid);
formatParams.add(kqdate);
lsFormatParams.add(formatParams);
this.format(lsFormatParams);
} catch (Exception e) {
writeLog(e);
kqLog.info(e);
}
}
public void delFormatData(String resourceid, String kqdate) {
RecordSet rs = new RecordSet();
String sql = "";
try {
sql = " delete from kq_format_detail where resourceid =? and kqdate = ? ";//删除非工作日数据
rs.executeUpdate(sql, resourceid, kqdate);
sql = " delete from kq_format_total where resourceid =? and kqdate = ? ";//删除非工作日数据
rs.executeUpdate(sql, resourceid, kqdate);
} catch (Exception e) {
writeLog(e);
kqLog.info(e);
}
}
public void clearFormatPool() {
RecordSet rs = new RecordSet();
String sql = "";
try {
//删除三天前的数据格式化数据
if (rs.getDBType().equals("sqlserver")) {
sql = " delete from kq_format_pool where status = 1 and datediff(day,created,getdate()) > 1";
} else if (rs.getDBType().equals("mysql")) {
sql = " delete from kq_format_pool where status = 1 and datediff(now(),created) > 1";
}
else if (rs.getDBType().equals("postgresql")) {
sql = " delete from kq_format_pool where status = 1 and datediff(now(),created) > 1";
}
else if (rs.getOrgindbtype().equals("st")) {
sql = " delete from kq_format_pool where status = 1 and to_number(trunc(sysdate) - trunc(created)) > 1";
} else {
sql = " delete from kq_format_pool where status = 1 and trunc(sysdate) - trunc(created) > 1";
}
rs.executeUpdate(sql);
} catch (Exception e) {
writeLog(e);
}
}
public Map<String,Object> getDefinedField(){
Map<String,Object> retMap = new HashMap<>();
String definedField = "";
String definedFieldSum = "";
String definedParam = "";
String definedParamSum = "";
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()) {
if (!Util.null2String(kqReportFieldComInfo.getIsenable()).equals("1")) continue;
if (Util.null2String(kqReportFieldComInfo.getIsSystem()).equals("1")) continue;
if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue;
if(definedField.length()>0)definedField+=",";
definedField+=kqReportFieldComInfo.getFieldname();
if(definedFieldSum.length()>0)definedFieldSum+=",";
definedFieldSum+="sum("+kqReportFieldComInfo.getFieldname()+") as "+kqReportFieldComInfo.getFieldname();
if(definedParam.length()>0)definedParam+=",";
definedParam+="?";
if(definedParamSum.length()>0)definedParamSum+=",";
definedParamSum+="sum("+kqReportFieldComInfo.getFieldname()+")";
String[] cascadekeys = Util.splitString(Util.null2String(kqReportFieldComInfo.getCascadekey()),",");
for(int i=0;cascadekeys!=null&&i<cascadekeys.length;i++){
String fieldname = Util.null2String(cascadekeys[i]);
if(fieldname.length()==0)continue;
if(definedField.length()>0)definedField+=",";
definedField+=fieldname;
if(definedFieldSum.length()>0)definedFieldSum+=",";
definedFieldSum+="sum("+fieldname+") as "+fieldname;
if(definedParam.length()>0)definedParam+=",";
definedParam+="?";
if(definedParamSum.length()>0)definedParamSum+=",";
definedParamSum+="sum("+fieldname+")";
}
}
retMap.put("definedField",definedField);
retMap.put("definedFieldSum",definedFieldSum);
retMap.put("definedParam",definedParam);
retMap.put("definedParamSum",definedParamSum);
return retMap;
}
public boolean needCal(String workDate, String workTime){
boolean needCalForgotCheckMins = true;
if (KQSettingsBiz.getKqformatAccurate()) {
workTime = new KQTimesArrayComInfo().turn48to24Time(workTime);
if (workDate.length() > 0 && workTime.length() > 0) {
String currentFullTime = DateUtil.getFullDate();
String endTime = workDate + " " + workTime;
if (DateUtil.timeInterval(currentFullTime, endTime) > 0) {
//当前时间之后的状态无效计算
needCalForgotCheckMins = false;
}
kqLog.writeLog("currentFullTime"+currentFullTime+"wroktime:"+endTime+"needCalForgotCheckMins:"+needCalForgotCheckMins);
}
}
return needCalForgotCheckMins;
}
public boolean needCal(String workDate, String workTime,String isneedcal){
boolean needCalForgotCheckMins = true;
boolean isneedformat = "1".equals(isneedcal);
if (isneedformat) {
workTime = new KQTimesArrayComInfo().turn48to24Time(workTime);
if (workDate.length() > 0 && workTime.length() > 0) {
String currentFullTime = DateUtil.getFullDate();
String endTime = workDate + " " + workTime;
if (DateUtil.timeInterval(currentFullTime, endTime) > 0) {
//当前时间之后的状态无效计算
needCalForgotCheckMins = false;
}
}
}
return needCalForgotCheckMins;
}
private List<List<Object>> processFormatParams(List<List<Object>> lsFormatParams) {
List<List<Object>> lsFormatParamsTmp = new ArrayList<>();
try {
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
KQWorkTime kqWorkTime = new KQWorkTime();
List<Object> formatParams = null;
for(int i=0;i<lsFormatParams.size();i++){
formatParams = lsFormatParams.get(i);
String resourceId = Util.null2String(formatParams.get(0));
String kqDate = Util.null2String(formatParams.get(1));
String formattype = "";
if(formatParams.size() > 2) {
formattype = Util.null2String(formatParams.get(2));
}
formatParams = new ArrayList<>();
formatParams.add(resourceId);
formatParams.add(kqDate);
formatParams.add(new java.sql.Timestamp(DateUtil.getCalendar(DateUtil.getFullDate()).getTimeInMillis()));
formatParams.add(formattype);
lsFormatParamsTmp.add(formatParams);
String nextDate = DateUtil.addDate(kqDate, 1);//下一天日期
WorkTimeEntity workTime = kqWorkTime.getWorkTime(resourceId, kqDate);
List<TimeScopeEntity> lsWorkTime = new ArrayList<>();
if (workTime != null) {
lsWorkTime = workTime.getWorkTime();//工作时间
for (int j = 0; lsWorkTime != null && j < lsWorkTime.size(); j++) {
TimeScopeEntity workTimeScope = lsWorkTime.get(j);
String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? nextDate : kqDate;
workBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime())+":00:00";
String workEndDateTime = workTimeScope.getEndTimeAcross() ? nextDate : kqDate;
workEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime())+":00:00";
formatParams = new ArrayList<>();
formatParams.add(resourceId);
formatParams.add(kqDate);
formatParams.add(new java.sql.Timestamp(DateUtil.getCalendar(workBeginDateTime).getTimeInMillis()));
formatParams.add(formattype);
lsFormatParamsTmp.add(formatParams);
formatParams = new ArrayList<>();
formatParams.add(resourceId);
formatParams.add(kqDate);
formatParams.add(new java.sql.Timestamp(DateUtil.getCalendar(workEndDateTime).getTimeInMillis()));
formatParams.add(formattype);
lsFormatParamsTmp.add(formatParams);
}
}else{
formatParams = new ArrayList<>();
formatParams.add(resourceId);
formatParams.add(kqDate);
formatParams.add(formattype);
lsFormatParamsTmp.add(formatParams);
}
}
}catch (Exception e) {
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
return lsFormatParamsTmp;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,814 @@
package com.engine.kq.biz;
import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.chain.cominfo.HalfShiftComIndex;
import com.engine.kq.biz.chain.cominfo.RestShiftComIndex;
import com.engine.kq.biz.chain.cominfo.ShiftComIndex;
import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean;
import com.engine.kq.biz.chain.cominfo.WorkShiftComIndex;
import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean;
import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit;
import com.engine.kq.entity.TimeScopeEntity;
import com.engine.kq.log.KQLog;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.commons.lang.math.NumberUtils;
import weaver.cache.CacheBase;
import weaver.cache.CacheColumn;
import weaver.cache.CacheColumnType;
import weaver.cache.CacheItem;
import weaver.cache.CacheMap;
import weaver.cache.PKColumn;
import weaver.conn.RecordSet;
import weaver.general.Util;
/**
*
*/
public class KQShiftManagementComInfo extends CacheBase implements Serializable {
/*
* : initCache
*/
protected static String TABLE_NAME = "";
/*
* : initCache
* sqlwherewhere
*/
protected static String TABLE_WHERE = null;
/*
* : initCache sqlorder
* byorder by
*
*/
protected static String TABLE_ORDER = null;
@PKColumn(type = CacheColumnType.NUMBER)
protected static String PK_NAME = "id";
@CacheColumn
protected static int shiftbean;
@CacheColumn
protected static int color;
@CacheColumn
protected static int isoffdutyfreecheck;
@CacheColumn
protected static int shiftonoffworkcount;
@CacheColumn
protected static int serial;
@CacheColumn
protected static int isresttimeopen;
@CacheColumn
protected static int worktime;
@CacheColumn
protected static int punchsetting;
@CacheColumn
protected static int cardRemind;
@CacheColumn
protected static int cardRemOfSignIn;
@CacheColumn
protected static int minsBeforeSignIn;
@CacheColumn
protected static int cardRemOfSignOut;
@CacheColumn
protected static int minsAfterSignOut;
@CacheColumn
protected static int remindMode;
@CacheColumn
protected static int remindOnPC;
@CacheColumn
protected static int signoutOnlyoff;
@CacheColumn
protected static int isRest;
@CacheColumn
protected static int overtimeRuleId;
private KQLog kqLog = new KQLog();
private boolean isFormat = false;
@Override
public CacheItem initCache(String key) {
if (key == null || "".equals(key.trim())) {
return null;
}
CacheMap localData = createCacheMap();
String sql = "";
kqLog = new KQLog();
ConcurrentHashMap<String, Object> resourceKQGroups = new ConcurrentHashMap<>();
//考勤组优先级
try {
ConcurrentHashMap<String,Object> shiftInfoBeanMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> idMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> colorsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isoffdutyfreechecksMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> shiftonoffworkcountsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> serialsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isresttimeopensMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> worktimesMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> punchsettingsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemindMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsBeforeSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsAfterSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindModeMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindOnPCMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> signoutOnlyoffMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isResetMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> overtimeruleMap = new ConcurrentHashMap<>();
RecordSet rs = new RecordSet();
String getShiftInfo = "select * from kq_ShiftManagement where 1=1 and id="+key+" order by id ";
rs.execute(getShiftInfo);
while(rs.next()){
String serialid = rs.getString("id");
String isresttimeopen = rs.getString("isresttimeopen");
String color = rs.getString("color");
String shiftonoffworkcount = rs.getString("shiftonoffworkcount");
String worktime = rs.getString("worktime");
String serial = rs.getString("serial");
String punchsetting = "1";
String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck");
String cardRemind = rs.getString("cardRemind");
String cardRemOfSignIn = rs.getString("cardRemOfSignIn");
String minsBeforeSignIn = rs.getString("minsBeforeSignIn");
String cardRemOfSignOut = rs.getString("cardRemOfSignOut");
String minsAfterSignOut = rs.getString("minsAfterSignOut");
String remindMode = rs.getString("remindMode");
String remindOnPC = rs.getString("remindOnPC");
String halfcalrule = rs.getString("halfcalrule");
halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule;
String halfcalpoint = rs.getString("halfcalpoint");
String halfcalpoint2cross = rs.getString("halfcalpoint2cross");
String overtimeRuleId = rs.getString("overtime_rule_id");
String signoutOnlyoff = rs.getString("signoutOnlyoff");
String isRest = rs.getString("is_rest");
getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross,signoutOnlyoff);
idMap.put(serialid, serialid);
colorsMap.put(serialid, color);
isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck);
shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount);
serialsMap.put(serialid, serial);
isresttimeopensMap.put(serialid, isresttimeopen);
worktimesMap.put(serialid, worktime);
punchsettingsMap.put(serialid, punchsetting);
cardRemindMap.put(serialid,cardRemind);
cardRemOfSignInMap.put(serialid,cardRemOfSignIn);
minsBeforeSignInMap.put(serialid,minsBeforeSignIn);
cardRemOfSignOutMap.put(serialid,cardRemOfSignOut);
minsAfterSignOutMap.put(serialid,minsAfterSignOut);
remindModeMap.put(serialid,remindMode);
remindOnPCMap.put(serialid,remindOnPC);
signoutOnlyoffMap.put(serialid,signoutOnlyoff);
isResetMap.put(serialid,isRest);
overtimeruleMap.put(serialid,overtimeRuleId);
}
if(shiftInfoBeanMap.size()>0){
CacheItem cacheItem = createCacheItem();
Iterator<Entry<String, Object>> iterator = shiftInfoBeanMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Object> entry = iterator.next();
String id = entry.getKey();
Object value = entry.getValue();
cacheItem.set(PK_INDEX, id);
cacheItem.set(shiftbean, value);
cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id));
cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id));
cacheItem.set(serial, serialsMap.get(id));
cacheItem.set(isresttimeopen, isresttimeopensMap.get(id));
cacheItem.set(worktime, worktimesMap.get(id));
cacheItem.set(punchsetting, punchsettingsMap.get(id));
cacheItem.set(cardRemind,cardRemindMap.get(id));
cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id));
cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id));
cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id));
cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id));
cacheItem.set(remindMode,remindModeMap.get(id));
cacheItem.set(remindOnPC,remindOnPCMap.get(id));
cacheItem.set(signoutOnlyoff,signoutOnlyoffMap.get(id));
cacheItem.set(isRest,isResetMap.get(id));
cacheItem.set(overtimeRuleId,overtimeruleMap.get(id));
modifyCacheItem(id, cacheItem);
}
return cacheItem;
}
} catch (Exception e) {
kqLog.info(e);
}
return null;
}
@Override
public CacheMap initCache() {
CacheMap localData = createCacheMap();
String sql = "";
kqLog = new KQLog();
ConcurrentHashMap<String, Object> resourceKQGroups = new ConcurrentHashMap<>();
//考勤组优先级
try {
ConcurrentHashMap<String,Object> shiftInfoBeanMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> idMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> colorsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isoffdutyfreechecksMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> shiftonoffworkcountsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> serialsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isresttimeopensMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> worktimesMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> punchsettingsMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemindMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsBeforeSignInMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> cardRemOfSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> minsAfterSignOutMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindModeMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> remindOnPCMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> signoutOnlyoffMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> isResetMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String,Object> overtimeruleMap = new ConcurrentHashMap<>();
RecordSet rs = new RecordSet();
String getShiftInfo = "select * from kq_ShiftManagement where 1=1 order by id ";
rs.execute(getShiftInfo);
while(rs.next()){
String serialid = rs.getString("id");
String isresttimeopen = rs.getString("isresttimeopen");
String color = rs.getString("color");
String shiftonoffworkcount = rs.getString("shiftonoffworkcount");
String worktime = rs.getString("worktime");
String serial = rs.getString("serial");
String punchsetting = "1";
String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck");
String cardRemind = rs.getString("cardRemind");
String cardRemOfSignIn = rs.getString("cardRemOfSignIn");
String minsBeforeSignIn = rs.getString("minsBeforeSignIn");
String cardRemOfSignOut = rs.getString("cardRemOfSignOut");
String minsAfterSignOut = rs.getString("minsAfterSignOut");
String remindMode = rs.getString("remindMode");
String remindOnPC = rs.getString("remindOnPC");
String halfcalrule = rs.getString("halfcalrule");
halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule;
String halfcalpoint = rs.getString("halfcalpoint");
String halfcalpoint2cross = rs.getString("halfcalpoint2cross");
String signoutOnlyoff = rs.getString("signoutOnlyoff");
String overtimeRuleId = rs.getString("overtime_rule_id");
String isRest = rs.getString("is_rest");
getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross,signoutOnlyoff);
idMap.put(serialid, serialid);
colorsMap.put(serialid, color);
isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck);
shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount);
serialsMap.put(serialid, serial);
isresttimeopensMap.put(serialid, isresttimeopen);
worktimesMap.put(serialid, worktime);
punchsettingsMap.put(serialid, punchsetting);
cardRemindMap.put(serialid,cardRemind);
cardRemOfSignInMap.put(serialid,cardRemOfSignIn);
minsBeforeSignInMap.put(serialid,minsBeforeSignIn);
cardRemOfSignOutMap.put(serialid,cardRemOfSignOut);
minsAfterSignOutMap.put(serialid,minsAfterSignOut);
remindModeMap.put(serialid,remindMode);
remindOnPCMap.put(serialid,remindOnPC);
signoutOnlyoffMap.put(serialid,signoutOnlyoff);
isResetMap.put(serialid,isRest);
overtimeruleMap.put(serialid,overtimeRuleId);
}
if(shiftInfoBeanMap.size()>0){
Iterator<Entry<String, Object>> iterator = shiftInfoBeanMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Object> entry = iterator.next();
String id = entry.getKey();
Object value = entry.getValue();
CacheItem cacheItem = createCacheItem();
cacheItem.set(PK_INDEX, id);
cacheItem.set(shiftbean, value);
cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id));
cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id));
cacheItem.set(serial, serialsMap.get(id));
cacheItem.set(isresttimeopen, isresttimeopensMap.get(id));
cacheItem.set(worktime, worktimesMap.get(id));
cacheItem.set(punchsetting, punchsettingsMap.get(id));
cacheItem.set(cardRemind,cardRemindMap.get(id));
cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id));
cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id));
cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id));
cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id));
cacheItem.set(remindMode,remindModeMap.get(id));
cacheItem.set(remindOnPC,remindOnPCMap.get(id));
cacheItem.set(signoutOnlyoff,signoutOnlyoffMap.get(id));
cacheItem.set(isRest,isResetMap.get(id));
cacheItem.set(overtimeRuleId,overtimeruleMap.get(id));
modifyCacheItem(id, cacheItem);
localData.put(id, cacheItem);
}
}
} catch (Exception e) {
StringWriter errorsWriter = new StringWriter();
e.printStackTrace(new PrintWriter(errorsWriter));
kqLog.info(errorsWriter.toString());
}
return localData;
}
public String getId(){
return (String)getRowValue(PK_INDEX);
}
public String getColor() { return (String)getRowValue(color); }
public String getColor(String key)
{
return (String)getValue(color,key);
}
public String getIsoffdutyfreecheck() { return (String)getRowValue(isoffdutyfreecheck); }
public String getIsoffdutyfreecheck(String key)
{
return (String)getValue(isoffdutyfreecheck,key);
}
public String getShiftonoffworkcounts() { return (String)getRowValue(shiftonoffworkcount); }
public String getShiftonoffworkcounts(String key)
{
return (String)getValue(shiftonoffworkcount,key);
}
public String getSerial() { return (String)getRowValue(serial); }
public String getSerial(String key)
{
return (String)getValue(serial,key);
}
public String getIsresttimeopen() { return (String)getRowValue(isresttimeopen); }
public String getIsresttimeopen(String key)
{
return (String)getValue(isresttimeopen,key);
}
public String getWorktime() { return (String)getRowValue(worktime); }
public String getWorktime(String key)
{
return (String)getValue(worktime,key);
}
public String getPunchsetting() {
return (String) getRowValue(punchsetting);
}
public String getPunchsetting(String key) {
return (String) getValue(punchsetting, key);
}
public String getCardRemind() {
return (String) getRowValue(cardRemind);
}
public String getCardRemind(String key) {
return (String) getValue(cardRemind,key);
}
public String getCardRemOfSignIn() {
return (String) getRowValue(cardRemOfSignIn);
}
public String getCardRemOfSignIn(String key) {
return (String) getValue(cardRemOfSignIn, key);
}
public String getMinsBeforeSignIn() {
return (String) getRowValue(minsBeforeSignIn);
}
public String getMinsBeforeSignIn(String key) {
return (String) getValue(minsBeforeSignIn, key);
}
public String getCardRemOfSignOut() {
return (String) getRowValue(cardRemOfSignOut);
}
public String getCardRemOfSignOut(String key) {
return (String) getValue(cardRemOfSignOut, key);
}
public String getMinsAfterSignOut() {
return (String) getRowValue(minsAfterSignOut);
}
public String getMinsAfterSignOut(String key) {
return (String) getValue(minsAfterSignOut, key);
}
public String getRemindMode() {
return (String) getRowValue(remindMode);
}
public String getRemindMode(String key) {
return (String) getValue(remindMode, key);
}
public String getRemindOnPC() {
return (String) getRowValue(remindOnPC);
}
public String getRemindOnPC(String key) {
return (String) getValue(remindOnPC, key);
}
public String getSignoutOnlyoff() {
return (String) getRowValue(signoutOnlyoff);
}
public String getSignoutOnlyoff(String key) {
return (String) getValue(signoutOnlyoff, key);
}
public String getIsRest() {
return (String) getRowValue(isRest);
}
public String getIsRest(String key) {
return (String) getValue(isRest, key);
}
public String getOvertimeRuleId() {
return (String) getRowValue(overtimeRuleId);
}
public String getOvertimeRuleId(String key) {
return (String) getValue(overtimeRuleId, key);
}
private void getShiftInfoBean(String serialid, String isresttimeopen, String worktime,
String punchsettings,
ConcurrentHashMap<String, Object> serialMap,
String halfcalrule,String halfcalpoint,String halfcalpoint2cross, String tmp_signoutOnlyoff) throws Exception {
Map<String,Object> workTimeMap = new HashMap<>();
int workmins = 0;
List<Object> workTimes = Collections.synchronizedList(new ArrayList<>());
List<Object> restTimes = Collections.synchronizedList(new ArrayList<>());
KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo();
KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo();
workTimes = kqShiftOnOffWorkSectionComInfo.getWorkSectionTimes(serialid);
if(workTimes != null && !workTimes.isEmpty()){
if("1".equalsIgnoreCase(isresttimeopen)) {
//如果开启了才去判断
restTimes = kqShiftRestTimeSectionComInfo.getRestSectionTimes(serialid);
}
if(NumberUtils.isNumber(worktime)){
if(worktime.indexOf('.') == -1){
workmins = Util.getIntValue(worktime,0);
}else {
worktime = worktime.substring(0,worktime.indexOf('.'));
workmins = Util.getIntValue(worktime,0);
}
}else{
workmins = 0;
kqLog.info("班次有问题serialid:"+serialid+"工作时长为:"+worktime);
}
workTimeMap.put("workTime", workTimes);
workTimeMap.put("restTime", restTimes);
workTimeMap.put("serialid", serialid);
//工作时长分钟数
workTimeMap.put("workmins", workmins+"");
workTimeMap.put("punchsettings", punchsettings);
workTimeMap.put("isresttimeopen", isresttimeopen);
workTimeMap.put("halfcalrule", halfcalrule);
workTimeMap.put("halfcalpoint", halfcalpoint);
workTimeMap.put("halfcalpoint2cross", halfcalpoint2cross);
workTimeMap.put("signoutOnlyoff", tmp_signoutOnlyoff.equals("1") ? "1" : "0");
ShiftInfoCominfoBean shiftInfoCominfoBean = setShiftInfoBean(workTimeMap);
serialMap.put(serialid, shiftInfoCominfoBean);
}
}
private ShiftInfoCominfoBean setShiftInfoBean(Map<String,Object> workTimeMap) throws Exception {
ShiftComIndex workComIndex = new WorkShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005306,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
ShiftComIndex restComIndex = new RestShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005307,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
ShiftComIndex halfComIndex = new HalfShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005308,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap);
//创建执行链
//前一天的都执行完了,去获取当天工作时段,再执行半天的规则
workComIndex.setDuration(restComIndex);
//执行完了半天的规则,再最后判断休息的时段
restComIndex.setDuration(halfComIndex);
ShiftInfoCominfoBean shiftInfoCominfoBean = new ShiftInfoCominfoBean();
workComIndex.handleDuration(shiftInfoCominfoBean);
return shiftInfoCominfoBean;
}
/**
*
* @param workdate
* @param serialidInfo
* @param containYesterday
* @return
*/
public Map<String,Object> getWorkButton(String workdate,Map<String,Object> serialidInfo, boolean containYesterday){
Map<String,Object> shiftMap = new HashMap<>();
//考勤按钮还是走缓存
KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis();
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
if(serialidInfo != null && !serialidInfo.isEmpty()){
LocalDate preLocalDate = LocalDate.parse(workdate);
String preSplitDate = "";
preLocalDate = preLocalDate.minusDays(1);
preSplitDate = preLocalDate.format(dateFormatter);
String serialid = Util.null2String(serialidInfo.get(workdate));
String preSerialid = Util.null2String(serialidInfo.get(preSplitDate));
if(containYesterday){
if(Util.getIntValue(preSerialid) > 0){
ShiftInfoCominfoBean pre_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(preSerialid);
List<Object> timelineList = pre_shiftInfoCominfoBean.getTimelineList();
if(timelineList!=null && !timelineList.isEmpty()){
shiftMap.put("pre_timelineList", timelineList);
}
shiftMap.put("pre_isAcross", pre_shiftInfoCominfoBean.getIsAcross());
shiftMap.put("pre_allWorkTime", pre_shiftInfoCominfoBean.getAllWorkTime());
shiftMap.put("pre_allAcrossWorkTime", pre_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftMap.put("pre_signTime", pre_shiftInfoCominfoBean.getSignWorkTime());
shiftMap.put("pre_restTime", pre_shiftInfoCominfoBean.getRestAcrossLongTime());
}
}
if(Util.getIntValue(serialid) > 0){
ShiftInfoCominfoBean cur_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(serialid);
Map<String,Object> shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false);
List<Object> timelineList = cur_shiftInfoCominfoBean.getTimelineList();
if(timelineList!=null && !timelineList.isEmpty()){
shiftMap.put("timelineList", timelineList);
}
shiftMap.put("isAcross", cur_shiftInfoCominfoBean.getIsAcross());
shiftMap.put("allWorkTime", cur_shiftInfoCominfoBean.getAllWorkTime());
shiftMap.put("allAcrossWorkTime", cur_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime());
shiftMap.put("restTime", cur_shiftInfoCominfoBean.getRestAcrossLongTime());
if(shiftRuleMap != null && !shiftRuleMap.isEmpty()){
shiftMap.put("shiftRuleMap", shiftRuleMap);
}
}
}
return shiftMap;
}
/**
*
* @param workdate
* @param serialidInfo
* @param containYesterday
* @return
* shiftInfoBean ,0-24
* shiftLongInfoBean 0-48
*/
public Map<String,Object> getWorkDuration(String workdate,Map<String,Object> serialidInfo,boolean containYesterday){
KQWorkTime kqWorkTime = new KQWorkTime();
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Map<String,Object> dateWorkTimeMap = new HashMap<>();
LocalDate preLocalDate = LocalDate.parse(workdate);
String preSplitDate = "";
preLocalDate = preLocalDate.minusDays(1);
preSplitDate = preLocalDate.format(dateFormatter);
if(serialidInfo != null && !serialidInfo.isEmpty()){
String preSerialid = Util.null2String(serialidInfo.get(preSplitDate));
String serialid = Util.null2String(serialidInfo.get(workdate));
Boolean isNonWork = kqWorkTime.isNonWork(serialidInfo);
ShiftInfoBean shiftInfoBean = new ShiftInfoBean();
shiftInfoBean.setPreSplitDate(preSplitDate);
shiftInfoBean.setSplitDate(workdate);
shiftInfoBean.setD_Mins(0.0);
shiftInfoBean.setPreSerialid(preSerialid);
shiftInfoBean.setSerialid(serialid);
shiftInfoBean.setRestShift(isNonWork?1:0);
if(containYesterday){
if(Util.getIntValue(serialid) > 0 || Util.getIntValue(preSerialid) > 0){
fillShiftInfoBean(shiftInfoBean, preSerialid, serialid);
dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean);
}
}else{
if(Util.getIntValue(serialid) > 0){
fillShiftInfoBean(shiftInfoBean, preSerialid, serialid);
dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean);
}
}
}
return dateWorkTimeMap;
}
/**
* id+
* @param workdate
* @param serialidInfo
* @return
*/
public Map<String,Object> getWorkTimeMap(String workdate,Map<String,Object> serialidInfo){
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Map<String,Object> dateWorkTimeMap = new HashMap<>();
LocalDate preLocalDate = LocalDate.parse(workdate);
String preSplitDate = "";
preLocalDate = preLocalDate.minusDays(1);
preSplitDate = preLocalDate.format(dateFormatter);
if(serialidInfo != null && !serialidInfo.isEmpty()){
String preSerialid = Util.null2String(serialidInfo.get(preSplitDate));
String serialid = Util.null2String(serialidInfo.get(workdate));
getShiftInfoBeanMap(dateWorkTimeMap,preSerialid, serialid);
}
return dateWorkTimeMap;
}
/**
*
* @param dateWorkTimeMap
* @param preSerialid
* @param serialid
*/
private void getShiftInfoBeanMap(Map<String,Object> dateWorkTimeMap,String preSerialid, String serialid) {
ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid);
if(cur_shiftInfoCominfoBean != null){
dateWorkTimeMap.put("restTime",cur_shiftInfoCominfoBean.getRestAcrossLongTime());
dateWorkTimeMap.put("workTime",cur_shiftInfoCominfoBean.getWorkAcrossLongTime());
dateWorkTimeMap.put("workMins",cur_shiftInfoCominfoBean.getWorkmins());
dateWorkTimeMap.put("isAcross",cur_shiftInfoCominfoBean.getIsAcross());
dateWorkTimeMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime());
dateWorkTimeMap.put("halfWorkTime", cur_shiftInfoCominfoBean.getHalfWorkTime());
dateWorkTimeMap.put("halfWorkIndex", cur_shiftInfoCominfoBean.getHalfWorkIndex());
dateWorkTimeMap.put("convertAttendDay", cur_shiftInfoCominfoBean.getConvertAttendDay());
}
}
/**
*
* @param shiftInfoBean
* @param preSerialid
* @param serialid
*/
private void fillShiftInfoBean(ShiftInfoBean shiftInfoBean,String preSerialid,String serialid){
ShiftInfoCominfoBean pre_shiftInfoCominfoBean = getShiftInfoCominfoBean(preSerialid);
ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid);
Map<String,Object> pre_shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(preSerialid,false);
Map<String,Object> shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false);
//把前一个班次的填充好
if(pre_shiftInfoCominfoBean != null){
shiftInfoBean.setPreWorkIndex(pre_shiftInfoCominfoBean.getPreWorkTimeIndex());
shiftInfoBean.setPreWorkAcrossIndex(pre_shiftInfoCominfoBean.getWorkAcrossTimeIndex());
shiftInfoBean.setPreWorkMinsAcrossIndex(pre_shiftInfoCominfoBean.getWorkPunchMins());
shiftInfoBean.setPreRestIndex(pre_shiftInfoCominfoBean.getPreRestTimeIndex());
shiftInfoBean.setPreHalfWorkIndex(pre_shiftInfoCominfoBean.getHalfWorkIndex());
shiftInfoBean.setPreWorkmins(pre_shiftInfoCominfoBean.getWorkmins());
shiftInfoBean.setPreAllWorkTime(pre_shiftInfoCominfoBean.getAllWorkTime());
shiftInfoBean.setPreAllAcrossWorkTime(pre_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftInfoBean.setPreAllRestTime(pre_shiftInfoCominfoBean.getAllRestTime());
shiftInfoBean.setPreAllAcrossRestTime(pre_shiftInfoCominfoBean.getAllAcrossRestTime());
shiftInfoBean.setPreSerialid(preSerialid);
shiftInfoBean.setIsPreAcross(pre_shiftInfoCominfoBean.getIsAcross());
shiftInfoBean.setShiftRuleMap(pre_shiftRuleMap);
shiftInfoBean.setPreConvertAttendDay(pre_shiftInfoCominfoBean.getConvertAttendDay());
}
//把当前班次的填充好
if(cur_shiftInfoCominfoBean != null){
shiftInfoBean.setWorkIndex(cur_shiftInfoCominfoBean.getWorkTimeIndex());
shiftInfoBean.setWorkAcrossIndex(cur_shiftInfoCominfoBean.getWorkAcrossTimeIndex());
shiftInfoBean.setWorkMinsAcrossIndex(cur_shiftInfoCominfoBean.getWorkPunchMins());
shiftInfoBean.setRestIndex(cur_shiftInfoCominfoBean.getRestTimeIndex());
shiftInfoBean.setHalfWorkIndex(cur_shiftInfoCominfoBean.getHalfWorkIndex());
shiftInfoBean.setWorkmins(cur_shiftInfoCominfoBean.getWorkmins());
shiftInfoBean.setAllWorkTime(cur_shiftInfoCominfoBean.getAllWorkTime());
shiftInfoBean.setAllAcrossWorkTime(cur_shiftInfoCominfoBean.getAllAcrossWorkTime());
shiftInfoBean.setAllRestTime(cur_shiftInfoCominfoBean.getAllRestTime());
shiftInfoBean.setAllAcrossRestTime(cur_shiftInfoCominfoBean.getAllAcrossRestTime());
shiftInfoBean.setAllLongWorkTime(cur_shiftInfoCominfoBean.getAllLongWorkTime());
shiftInfoBean.setRestLongTimeIndex(cur_shiftInfoCominfoBean.getRestLongTimeIndex());
shiftInfoBean.setWorkLongTimeIndex(cur_shiftInfoCominfoBean.getWorkLongTimeIndex());
shiftInfoBean.setIsAcross(cur_shiftInfoCominfoBean.getIsAcross());
shiftInfoBean.setSerialid(serialid);
shiftInfoBean.setShiftRuleMap(shiftRuleMap);
if(cur_shiftInfoCominfoBean.getWorkAcrossLongTime() != null){
List<Object> workTime1 = cur_shiftInfoCominfoBean.getWorkAcrossLongTime().stream().collect(Collectors.toList());
List<TimeScopeEntity> lsWorkTime = new KQWorkTime().formatTimeScope(workTime1, false);
shiftInfoBean.setWorkTime(lsWorkTime);
}
if(cur_shiftInfoCominfoBean.getSignWorkTime() != null){
List<Object> signTime1 = cur_shiftInfoCominfoBean.getSignWorkTime().stream().collect(Collectors.toList());
List<TimeScopeEntity> lsSignTime = new KQWorkTime().formatTimeScope(signTime1, true);
shiftInfoBean.setSignTime(lsSignTime);
}
shiftInfoBean.setHalfcalrule(cur_shiftInfoCominfoBean.getHalfcalrule());
shiftInfoBean.setHalfcalpoint(cur_shiftInfoCominfoBean.getHalfcalpoint());
shiftInfoBean.setHalfcalpoint2cross(cur_shiftInfoCominfoBean.getHalfcalpoint2cross());
shiftInfoBean.setWorkAcrossTime(cur_shiftInfoCominfoBean.getWorkAcrossTime());
shiftInfoBean.setEachWorkMins(cur_shiftInfoCominfoBean.getEachWorkMins());
shiftInfoBean.setConvertAttendDay(cur_shiftInfoCominfoBean.getConvertAttendDay());
}
}
public void removeShiftManagementCache(){
KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo();
KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo();
kqShiftRestTimeSectionComInfo.removeShiftRestTimeSectionCache();
kqShiftOnOffWorkSectionComInfo.removeShiftWorkSectionCache();
super.removeCache();
//改用redis和staticobj的方式
KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis();
kqShiftManagementRedis.resetShiftValWithRedis();
}
/**
* shiftInfoCominfoBean
* @param serialid
* @return
*/
public ShiftInfoCominfoBean getShiftInfoCominfoBean(String serialid){
// Object object = getObjValue(shiftbean, serialid);
// if(object != null){
// return (ShiftInfoCominfoBean) object;
// }else{
// return null;
// }
//改用redis和staticobj的方式
KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis();
return kqShiftManagementRedis.getShiftInfoBeanMapBySql(serialid);
}
/**
* shiftInfoCominfoBean
* @param workdate
* @param serialidInfo
* @return
*/
public ShiftInfoCominfoBean getShiftInfoCominfoBean(String workdate,Map<String,Object> serialidInfo){
ShiftInfoCominfoBean shiftInfoCominfoBean = null;
if(serialidInfo != null && !serialidInfo.isEmpty()){
String serialid = Util.null2String(serialidInfo.get(workdate));
if(Util.getIntValue(serialid) > 0){
shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid);
}
}
return shiftInfoCominfoBean;
}
public boolean isFormat() {
return isFormat;
}
public void setFormat(boolean format) {
isFormat = format;
}
}

@ -0,0 +1,690 @@
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.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
public class ExportDailyExcelCmd extends AbstractCommonCommand<Map<String, Object>> {
private HttpServletRequest request;
private HttpServletResponse response;
private List<String> lsFieldDataKey;
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();
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
new KQReportBiz().insertKqReportExportLog(params, user);
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial"));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect =Util.null2String(jsonObj.get("typeselect"));
if(typeselect.length()==0)typeselect = "3";
if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){
if(typeselect.equals("1")){
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
}else{
fromDate = TimeUtil.getDateByOption(typeselect,"0");
toDate = TimeUtil.getDateByOption(typeselect,"1");
}
}
//人员状态
String status = Util.null2String(jsonObj.get("status"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String allLevel = Util.null2String(jsonObj.get("allLevel"));
String isNoAccount = Util.null2String(jsonObj.get("isNoAccount"));
String viewScope = Util.null2String(jsonObj.get("viewScope"));
List<String> showColumns = Util.splitString2List(Util.null2String(jsonObj.get("showColumns")),",");
showColumns.add("lastname");
showColumns.add("kqdate");
showColumns.add("serialid");
showColumns.removeIf(showColumn->showColumn.trim().equals(""));
List<String> tmpShowColumns = new ArrayList<>();
for(String showColumn:showColumns){
tmpShowColumns.add(showColumn);
String cascadekey = "";
if(showColumn.equals("signin1")){
cascadekey = "signout1";
}else if(showColumn.equals("signin2")){
cascadekey = "signout2";
}else if(showColumn.equals("signin3")){
cascadekey = "signout3";
}else if(showColumn.equals("beLate")){
cascadekey = "beLateMins";
}else if(showColumn.equals("leaveEearly")){
cascadekey = "leaveEarlyMins";
}else if(showColumn.equals("graveBeLate")){
cascadekey = "graveBeLateMins";
}else if(showColumn.equals("graveLeaveEarly")){
cascadekey = "graveLeaveEarlyMins";
}else if(showColumn.equals("absenteeism")){
cascadekey = "absenteeismMins";
}else if(showColumn.equals("overtime")){
tmpShowColumns.add("overtime_4leave");
tmpShowColumns.add("overtime_nonleave");
tmpShowColumns.add("workingDayOvertime_nonleave");
tmpShowColumns.add("workingDayOvertime_4leave");
tmpShowColumns.add("restDayOvertime_nonleave");
tmpShowColumns.add("restDayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_nonleave");
}
if(cascadekey.length()>0){
tmpShowColumns.add(cascadekey);
}
}
showColumns = tmpShowColumns;
String today = DateUtil.getCurrentDate();
if(DateUtil.compDate(today, toDate)>0){//结束如期不大于今天
toDate = today;
}
String rightSql = new KQReportBiz().getReportRight("2",""+user.getUID(),"a");
LinkedHashMap<String, Object> workbook = new LinkedHashMap<>();
List<Object> lsSheet = new ArrayList<>();
Map<String, Object> sheet = null;
List<Object> titleList = new ArrayList<>();
Map<String,Object> title = null;
List<List<Object>> dataList = new ArrayList<>();
List<Object> data = null;
List<Map<String,Object>> constraintList = null;
Map<String,Object> constraint = null;
sheet = new HashMap<>();
sheet.put("sheetName", SystemEnv.getHtmlLabelName( 390352, user.getLanguage()));
sheet.put("sheetTitle", SystemEnv.getHtmlLabelName( 390352, user.getLanguage()));
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
Map<String,Object> mapChildColumnInfo = null;
List<Object> childColumns = null;
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()){
if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue;
if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily"))continue;
if (!showColumns.contains(kqReportFieldComInfo.getFieldname())&&!showColumns.contains(kqReportFieldComInfo.getParentid())) continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
title = new HashMap<>();
String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user);
if(unitType.length()>0){
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ "(" + unitType + ")");
}else{
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
}
title.put("width",30*256);
this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user);
childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
title.put("children", childColumns);
title.put("colSpan",childColumns.size());
}else{
title.put("rowSpan", 3);
}
titleList.add(title);
}
sheet.put("titleList", titleList);
// 没有权限的人最大只支持查询本季
Map<String, String> getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "2");
fromDate = getRealDate.get("fromDate");
toDate = getRealDate.get("toDate");
if("-1".equals(fromDate) || "-1".equals(toDate)) {
retmap.put("status", "1");
return retmap;
}
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";
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
Map<String,String> serialdata = new HashMap<>();
boolean isneedcal = KQSettingsBiz.getKqformatAccurate();
params.put("isneedcal",isneedcal?"1":"0");
Map<String,Object> flowData = kqReportBiz.getDailyFlowData(params,user);
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);
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);
}
}
} else if(fieldName.equals("signin1")){
fieldValue = Util.null2String(flowData.get(tmpkey+"signintime1"));
data.add(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);
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(fieldName.equals("leave")){
//请假
List<Map<String, Object>> allLeaveRules = KQLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = allLeaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = allLeaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
allLeaveRules.remove(i);
}
}
}
Map<String, Object> leaveRule = null;
for(int i=0;allLeaveRules!=null&&i<allLeaveRules.size();i++){
leaveRule = (Map<String, Object>)allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_"+leaveRule.get("id"));
fieldValue = Util.null2String(flowData.get(id+"|"+kqdate+"|"+flowType));
String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try {
//以防止出现精度问题
if (fieldValue.length() == 0) {
fieldValue = "0.0";
}
if (leavebackData.length() == 0) {
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(fieldValue);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
} catch (Exception e) {
writeLog("ExportDailyExcelCmd:fieldValue" + fieldValue + ":leavebackData:" + leavebackData + ":" + e);
}
//考虑下冻结的数据
if (b_flowLeaveData.length() > 0) {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
} else {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(fieldValue, 0.0) - Util.getDoubleValue(leavebackData, 0.0)));
}
fieldValue = flowLeaveData;
data.add(fieldValue);
}
}else if(fieldName.equals("overtime")){
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|workingDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|restDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id +"|"+kqdate+ "|holidayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave"))));
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|"+kqdate+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal"))));
continue;
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+kqdate+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
}else if(fieldName.equals("kqdate")){
fieldValue=kqdate+" "+com.engine.portal.util.DateUtil.getDayWeekOfDate1(DateUtil.parseToDate(kqdate));
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid));
}
if(!fieldName.equals("leave")) {
fieldValue = Util.formatMultiLang(fieldValue, "" + user.getLanguage());
data.add(fieldValue);
}
}
dataList.add(data);
}
sheet.put("dataList", dataList);
sheet.put("constraintList",constraintList);
sheet.put("createFile", "1");
lsSheet.add(sheet);
workbook.put("sheet", lsSheet);
String fileName = SystemEnv.getHtmlLabelName(390352, user.getLanguage())+" "+fromDate+" "+toDate;;
workbook.put("fileName", fileName);
ExcelUtil ExcelUtil = new ExcelUtil();
Map<String,Object> exportMap= ExcelUtil.export(workbook,request,response);
retmap.putAll(exportMap);
retmap.put("status", "1");
} catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage()));
writeLog(e);
}
return retmap;
}
private Map<String,Object> getChildColumnsInfo(String parentid, User user){
Map<String,Object> returnMap = new HashMap<>();
List<Object> titleList = new ArrayList<>();
Map<String,Object> title = null;
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
if(parentid.equals("leave")){
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = leaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = leaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
leaveRules.remove(i);
}
}
}
for(int i=0;leaveRules!=null&&i<leaveRules.size();i++){
Map<String, Object> leaveRule = leaveRules.get(i);
String name = Util.formatMultiLang(Util.null2String(leaveRule.get("name")),""+user.getLanguage());
String unitType = Util.null2String(leaveRule.get("unitType"));
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,718 @@
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.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import com.google.common.collect.Lists;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
public class ExportExcelCmd extends AbstractCommonCommand<Map<String, Object>> {
private HttpServletRequest request;
private HttpServletResponse response;
private List<String> lsFieldDataKey;
private boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half"));
public ExportExcelCmd(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, User user) {
this.user = user;
this.params = params;
this.request = request;
this.response = response;
this.lsFieldDataKey = new ArrayList<>();
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> retmap = new HashMap<String, Object>();
RecordSet rs = new RecordSet();
String sql = "";
try {
SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
KQReportBiz kqReportBiz = new KQReportBiz();
new KQReportBiz().insertKqReportExportLog(params, user);
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial"));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect = Util.null2String(jsonObj.get("typeselect"));
if (typeselect.length() == 0) typeselect = "3";
if (!typeselect.equals("") && !typeselect.equals("0") && !typeselect.equals("6")) {
if (typeselect.equals("1")) {
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
} else {
fromDate = TimeUtil.getDateByOption(typeselect, "0");
toDate = TimeUtil.getDateByOption(typeselect, "1");
}
}
//人员状态
String status = Util.null2String(jsonObj.get("status"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String allLevel = Util.null2String(jsonObj.get("allLevel"));
String isNoAccount = Util.null2String(jsonObj.get("isNoAccount"));
String viewScope = Util.null2String(jsonObj.get("viewScope"));
List<String> showColumns = Util.splitString2List(Util.null2String(jsonObj.get("showColumns")), ",");
showColumns.add("lastname");
showColumns.removeIf(showColumn->showColumn.trim().equals(""));
List<String> tmpShowColumns = new ArrayList<>();
for(String showColumn:showColumns){
tmpShowColumns.add(showColumn);
String cascadekey = "";
if(showColumn.equals("beLate")){
cascadekey = "beLateMins";
}else if(showColumn.equals("leaveEearly")){
cascadekey = "leaveEarlyMins";
}else if(showColumn.equals("graveBeLate")){
cascadekey = "graveBeLateMins";
}else if(showColumn.equals("graveLeaveEarly")){
cascadekey = "graveLeaveEarlyMins";
}else if(showColumn.equals("absenteeism")){
cascadekey = "absenteeismMins";
}else if(showColumn.equals("overtime")){
tmpShowColumns.add("overtime_4leave");
tmpShowColumns.add("overtime_nonleave");
tmpShowColumns.add("workingDayOvertime_nonleave");
tmpShowColumns.add("workingDayOvertime_4leave");
tmpShowColumns.add("restDayOvertime_nonleave");
tmpShowColumns.add("restDayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_4leave");
tmpShowColumns.add("holidayOvertime_nonleave");
}
if(cascadekey.length()>0){
tmpShowColumns.add(cascadekey);
}
}
showColumns = tmpShowColumns;
String rightSql = new KQReportBiz().getReportRight("1", "" + user.getUID(), "a");
LinkedHashMap<String, Object> workbook = new LinkedHashMap<>();
List<Object> lsSheet = new ArrayList<>();
Map<String, Object> sheet = null;
List<Object> titleList = new ArrayList<>();
Map<String, Object> title = null;
List<List<Object>> dataList = new ArrayList<>();
List<Object> data = null;
List<Map<String, Object>> constraintList = null;
sheet = new HashMap<>();
sheet.put("sheetName", SystemEnv.getHtmlLabelName(390351, user.getLanguage()));
sheet.put("sheetTitle", SystemEnv.getHtmlLabelName(390351, user.getLanguage()));
boolean isEnd = false;
Calendar cal = DateUtil.getCalendar();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
Map<String, Object> mapChildColumnInfo = null;
List<Object> childColumns = null;
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()) {
if (Util.null2String(kqReportFieldComInfo.getParentid()).length() > 0) continue;
if(kqReportFieldComInfo.getFieldname().equals("kqCalendar"))continue;
if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue;
if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))
continue;
if (!showColumns.contains(kqReportFieldComInfo.getFieldname())&&!showColumns.contains(kqReportFieldComInfo.getParentid())) continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
title = new HashMap<>();
String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user);
if(unitType.length()>0){
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())+ "(" + unitType + ")");
}else{
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
}
title.put("width", 30 * 256);
this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(), user);
childColumns = (List<Object>) mapChildColumnInfo.get("childColumns");
if (childColumns.size() > 0) {//跨列width取子列的width
title.put("children", childColumns);
title.put("colSpan", childColumns.size());
} else {
title.put("rowSpan", 3);
}
titleList.add(title);
titleList.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user));
}
String today = DateUtil.getCurrentDate();
// if (DateUtil.compDate(today, toDate) > 0) {//结束如期不大于今天
// toDate = today;
// }
if(showColumns.contains("kqCalendar")) {
childColumns = new ArrayList<>();
for (String date = fromDate; !isEnd; ) {
if (date.equals(toDate)) isEnd = true;
title = new HashMap<>();
title.put("title", UtilKQ.getWeekDayShort(DateUtil.getWeek(date)-1,user.getLanguage()) +"\r\n"+ DateUtil.geDayOfMonth(date));
title.put("width", 30 * 256);
childColumns.add(title);
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
title = new HashMap();
title.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage()));
if (childColumns.size() > 0) {//跨列width取子列的width
title.put("children", childColumns);
title.put("colSpan", childColumns.size());
}
titleList.add(title);
}
sheet.put("titleList", titleList);
// 没有权限的人最大只支持查询本季
Map<String, String> getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1");
fromDate = getRealDate.get("fromDate");
toDate = getRealDate.get("toDate");
if("-1".equals(fromDate) || "-1".equals(toDate)) {
retmap.put("status", "1");
return retmap;
}
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());
String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源
params.put("show_card_source",show_card_source);
KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz();
int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位
double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系
params.put("uintType",uintType);
params.put("hoursToDay",hoursToDay);
Map<String, Object> flowData = new KQReportBiz().getFlowData(params, user);
//System.out.println("end" + DateUtil.getFullDate());
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
rs.execute(sql);
int calIndex = -1;
while (rs.next()) {
data = new ArrayList<>();
String id = rs.getString("id");
for (int fieldDataKeyIdx =0;fieldDataKeyIdx<lsFieldDataKey.size();fieldDataKeyIdx++) {
String fieldName = lsFieldDataKey.get(fieldDataKeyIdx);
String fieldid = KQReportFieldComInfo.field2Id.get(fieldName);
String fieldValue = "";
if (fieldName.equals("subcompany")) {
String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid"));
if (tmpSubcompanyId.length() == 0) {
tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id));
}
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") :
subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
// fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
} else if (fieldName.equals("department")) {
String tmpDepartmentId = Util.null2String(rs.getString("departmentid"));
if (tmpDepartmentId.length() == 0) {
tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id));
}
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") :
departmentComInfo.getDepartmentname(tmpDepartmentId);
// fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId);
} else if (fieldName.equals("jobtitle")) {
String tmpJobtitleId = Util.null2String(rs.getString("jobtitle"));
if (tmpJobtitleId.length() == 0) {
tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id));
}
fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId);
} else if (fieldName.equals("attendanceSerial")) {
List<String> serialIds = null;
if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) {
serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ",");
for(int i=0;serialIds!=null&&i<serialIds.size();i++){
data.add(kqReportBiz.getSerialCount(id,fromDate,toDate,serialIds.get(i)));
}
}else{
data.add("");
}
continue;
} else if (fieldName.equals("leave")) {//请假
List<Map<String, Object>> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = allLeaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = allLeaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
allLeaveRules.remove(i);
}
}
}
Map<String, Object> leaveRule = null;
for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) {
leaveRule = allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_" + leaveRule.get("id"));
String leaveData = Util.null2String(flowData.get(id + "|" + flowType));
String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + flowLeaveBackType)), "0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try {
//以防止出现精度问题
if (leaveData.length() == 0) {
leaveData = "0.0";
}
if (leavebackData.length() == 0) {
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(leaveData);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
} catch (Exception e) {
writeLog("GetKQReportCmd:leaveData" + leaveData + ":leavebackData:" + leavebackData + ":" + e);
}
if (b_flowLeaveData.length() > 0) {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
} else {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData, 0.0) - Util.getDoubleValue(leavebackData, 0.0)));
}
data.add(flowLeaveData);
}
continue;
}else if(fieldName.equals("overtime")){
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_nonleave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave"))));
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_4leave")));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave"))));
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal"))));
continue;
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
} else if(Util.null2String(kqReportFieldComInfo.getCascadekey(fieldid)).length()>0){
fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage());
data.add(fieldValue);
List<String> lsCascadekey = Util.splitString2List(kqReportFieldComInfo.getCascadekey(fieldid),",");
for(int i=0;i<lsCascadekey.size();i++){
if(Util.null2String(rs.getString(lsCascadekey.get(i))).length()>0){
fieldid = KQReportFieldComInfo.field2Id.get(lsCascadekey.get(i));
fieldValue = getFieldValueByUnitType(rs.getString(lsCascadekey.get(i)),kqReportFieldComInfo.getUnittype(fieldid));
}else{
fieldValue = "0";
}
data.add(fieldValue);
}
continue;
}else {
fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)),""+user.getLanguage());
fieldValue = getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(fieldid));
}
fieldValue = Util.formatMultiLang(fieldValue,""+user.getLanguage());
data.add(fieldValue);
}
List<Object> amData = Lists.newArrayList();
List<Object> pmData = Lists.newArrayList();
if(isKqReportHalfOpen) {
amData.addAll(data);
pmData.addAll(data);
calIndex = data.size();
}
if(showColumns.contains("kqCalendar")) {
// Map<String, Object> detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true);
Map<String, Object> detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true,uintType,show_card_source);
String user_endDate = Util.null2String(resourceComInfo.getEndDate(id));
String user_status = Util.null2String(resourceComInfo.getStatus(id));
String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim();
String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim();
if(companyStartDate.length()!=10){
companyStartDate = "";
}
if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){
begindate=companyStartDate;
}
isEnd = false;
for (String date = fromDate; !isEnd; ) {
if (date.equals(toDate)) isEnd = true;
String dismissDate = resourceComInfo.getEndDate(id);
if(!"".equals(dismissDate) && DateUtil.compDate(dismissDate, date)>0) {
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
} else if (DateUtil.compDate(today, date) > 0) {
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
} else {
if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){
//其他状态
if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
continue;
}
}
if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准
if(isKqReportHalfOpen) {
amData.add("");
pmData.add("");
} else {
data.add("");
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
continue;
}
if (detialDatas.get(id + "|" + date) != null) {
if(isKqReportHalfOpen) {
amData.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("textAM"));
pmData.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("textPM"));
} else {
data.add(((Map<String, Object>) detialDatas.get(id + "|" + date)).get("text"));
}
} else {
if(isKqReportHalfOpen) {
amData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
pmData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
} else {
data.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage()));
}
}
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
}
if(isKqReportHalfOpen) {
dataList.add(amData);
dataList.add(pmData);
} else {
dataList.add(data);
}
}
sheet.put("dataList", dataList);
if(isKqReportHalfOpen) {
sheet.put("calIndex", calIndex);
}
sheet.put("constraintList", constraintList);
sheet.put("createFile", "1");
lsSheet.add(sheet);
workbook.put("sheet", lsSheet);
String fileName = SystemEnv.getHtmlLabelName(390351, user.getLanguage())+" "+fromDate+" "+toDate;
workbook.put("fileName", fileName);
ExcelUtil ExcelUtil = new ExcelUtil();
Map<String, Object> exportMap = ExcelUtil.export(workbook, request, response,true);
retmap.putAll(exportMap);
retmap.put("status", "1");
} catch (Exception e) {
retmap.put("status", "-1");
retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage()));
writeLog(e);
}
return retmap;
}
private Map<String, Object> getChildColumnsInfo(String parentid, User user) {
Map<String, Object> returnMap = new HashMap<>();
List<Object> titleList = new ArrayList<>();
Map<String, Object> title = null;
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
if (parentid.equals("attendanceSerial")) {//考勤班次
KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo();
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
List<String> serialIds = null;
if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) {
serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ",");
}
for (int i = 0; serialIds != null && i < serialIds.size(); i++) {
title = new HashMap<>();
title.put("title", Util.formatMultiLang(kqShiftManagementComInfo.getSerial(serialIds.get(i)),""+user.getLanguage()));
title.put("width", 30 * 256);
titleList.add(title);
}
} else if (parentid.equals("leave")) {
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = leaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = leaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
leaveRules.remove(i);
}
}
}
for (int i = 0; leaveRules != null && i < leaveRules.size(); i++) {
Map<String, Object> leaveRule = leaveRules.get(i);
String name = Util.formatMultiLang(Util.null2String(leaveRule.get("name")),""+user.getLanguage());
String unitType = Util.null2String(leaveRule.get("unitType"));
String unitName = (KQUnitBiz.isLeaveHour(unitType)) ? SystemEnv.getHtmlLabelName(391, user.getLanguage()) : SystemEnv.getHtmlLabelName(1925, user.getLanguage());
title = new HashMap<>();
title.put("title", name + "(" + unitName + ")");
title.put("width", 30 * 256);
titleList.add(title);
}
}else if(parentid.equals("overtime")){
String[] overtimeChild = {"overtime_nonleave","overtime_4leave","overtimeTotal"};
for(int i=0;i<overtimeChild.length;i++){
String id = overtimeChild[i];
title = new HashMap();
String fieldlabel = "";
if("overtime_nonleave".equalsIgnoreCase(id)){
fieldlabel = "125805";
title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
title.put("rowSpan","2");
}else if("overtime_4leave".equalsIgnoreCase(id)){
fieldlabel = "125804";
title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
title.put("rowSpan","2");
}else{
fieldlabel = "523";
title.put("showDetial","1");
String unitType = (KQOvertimeRulesBiz.getMinimumUnit()==3 || KQOvertimeRulesBiz.getMinimumUnit()==5 ||KQOvertimeRulesBiz.getMinimumUnit()==6)?"2":"1";
String unitTypeName = "";
if(Util.null2String(unitType).length()>0){
if(unitType.equals("1")){
unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage());
}else if(unitType.equals("2")){
unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage());
}else if(unitType.equals("3")){
unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage());
}
}
title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())+ "(" + unitTypeName + ")");
}
Map<String,Object> mapChildColumnInfo = getChildColumnsInfo(id, user);
int childWidth = 65;
List<Object> childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
title.put("children", childColumns);
childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")),65);
}
title.put("width", childWidth+"");
titleList.add(title);
}
} else {
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()) {
if (kqReportFieldComInfo.getParentid().equals(parentid)) {
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
title = new HashMap<>();
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")");
title.put("width", 30 * 256);
titleList.add(title);
}
}
}
returnMap.put("childColumns", titleList);
return returnMap;
}
private List<Object> getCascadeKeyColumnsInfo(String cascadeKey, User user){
List<Object> titleList = new ArrayList<>();
Map<String, Object> title = null;
if(Util.null2String(cascadeKey).length()==0){
return titleList;
}
List<String> lsCascadeKey = Util.splitString2List(cascadeKey,",");
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
for(int i=0;i<lsCascadeKey.size();i++){
kqReportFieldComInfo.setTofirstRow();
while (kqReportFieldComInfo.next()) {
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
if (kqReportFieldComInfo.getFieldname().equals(lsCascadeKey.get(i))){
title = new HashMap<>();
title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")");
title.put("width", 30 * 256);
titleList.add(title);
}
}
}
return titleList;
}
private String getFieldValueByUnitType(String fieldValue,String unittype){
if (Util.null2String(unittype).length() > 0) {
if (fieldValue.length() == 0) {
fieldValue = "0";
} else {
if (unittype.equals("2")) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
}
}
return fieldValue;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,696 @@
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.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.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GetKQDailyReportCmd extends AbstractCommonCommand<Map<String, Object>> {
private KQLog kqLog = new KQLog();
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{
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();
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
String rightSql = new KQReportBiz().getReportRight("2",""+user.getUID(),"a");
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect =Util.null2String(jsonObj.get("typeselect"));
if(typeselect.length()==0)typeselect = "3";
if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){
if(typeselect.equals("1")){
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
}else{
fromDate = TimeUtil.getDateByOption(typeselect,"0");
toDate = TimeUtil.getDateByOption(typeselect,"1");
}
}
//人员状态
String status = Util.null2String(jsonObj.get("status"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String allLevel = Util.null2String(jsonObj.get("allLevel"));
String isNoAccount = Util.null2String(jsonObj.get("isNoAccount"));
String viewScope = Util.null2String(jsonObj.get("viewScope"));
if(typeselect.length()==0)typeselect = "3";
int pageIndex = Util.getIntValue(Util.null2String(jsonObj.get("pageIndex")), 1);
int pageSize = KQReportBiz.getPageSize(Util.null2String(jsonObj.get("pageSize")),pageUid,user.getUID());
int count = 0;
int pageCount = 0;
int isHavePre = 0;
int isHaveNext = 0;
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
List<Object> columns = new ArrayList();
Map<String,Object> column = null;
List<Object> datas = new ArrayList();
Map<String,Object> data = null;
Map<String,Object> mapChildColumnInfo = null;
List<Object> childColumns = null;
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()){
if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue;
boolean isDaily = kqReportFieldComInfo.getReportType().equals("daily");
if(!kqReportFieldComInfo.getReportType().equals("all") && !isDaily)continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user);
childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("rowSpan", 1);
column.put("width", mapChildColumnInfo.get("sumChildColumnWidth"));
column.put("children", childColumns);
}else{
column.put("rowSpan", 3);
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
}
if(kqReportFieldComInfo.getReportType1().equals("daily")){
column.put("isdaily", "1");
}
column.put("showDetial",kqReportFieldComInfo.getShowDetial());
columns.add(column);
}
// String today = DateUtil.getCurrentDate();
// if(DateUtil.compDate(today, toDate)>0){//结束如期不大于今天
// toDate = today;
// if(DateUtil.compDate(today, fromDate)>0){
// fromDate = today;
// }
// }
String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck ";
if(rs.getDBType().equalsIgnoreCase("oracle")&&!Util.null2String(rs.getOrgindbtype()).equals("dm")&&!Util.null2String(rs.getOrgindbtype()).equals("st")&&!Util.null2String(rs.getOrgindbtype()).equals("jc")) {
forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) ";
}else if((rs.getDBType()).equalsIgnoreCase("mysql")){
forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) ";
}else {
forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) ";
}
String backFields = " 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+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and a.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and a.id in("+resourceId+") ";
}
if(viewScope.equals("4")){//我的下属
if(allLevel.equals("1")){//所有下属
sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'";
}else{
sqlWhere+=" and a.managerid="+user.getUID();//直接下属
}
}
if (!"1".equals(isNoAccount)) {
sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' ");
}
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+") t";
rs.execute(sql);
if (rs.next()){
count = rs.getInt("c");
}
if (count <= 0) {
pageCount = 0;
}
pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0);
isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0;
isHavePre = (pageIndex - 1 >= 1) ? 1 : 0;
String orderBy = " order by a.dsporder asc, a.lastname asc, b.kqdate asc ";
String descOrderBy = " order by a.dsporder desc, a.lastname desc, b.kqdate desc ";
sql = backFields + sqlFrom + sqlWhere + orderBy;
if (pageIndex > 0 && pageSize > 0) {
if (rs.getDBType().equals("oracle")) {
sql = " select " + sql;
sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= "
+ (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize);
} else if (rs.getDBType().equals("mysql")) {
sql = " select " + sql;
sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize;
}
else if (rs.getDBType().equals("postgresql")) {
sql = " select " + sql;
sql = "select t1.* from (" + sql + ") t1 limit " + pageSize+ " offset " + ((pageIndex - 1) * pageSize);
}
else {
orderBy = " order by dsporder asc, lastname asc, kqdate asc ";
descOrderBy = " order by dsporder desc, lastname desc, kqdate desc ";
if (pageIndex > 1) {
int topSize = pageSize;
if (pageSize * pageIndex > count) {
topSize = count - (pageSize * (pageIndex - 1));
}
sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top "
+ (pageIndex * pageSize) + sql+" ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy;
} else {
sql = " select top " + pageSize + sql;
}
}
} else {
sql = " select " + sql;
}
boolean isneedcal = KQSettingsBiz.getKqformatAccurate();
params.put("isneedcal",isneedcal?"1":"0");
Map<String,Object> flowData = kqReportBiz.getDailyFlowData(params,user);
Map<String,String> serialdata = new HashMap<>();
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0");
rs.execute(sql);
while (rs.next()) {
String id = rs.getString("id");
String kqdate = rs.getString("kqdate");
WorkTimeEntity workTime = kqWorkTime.getWorkTime(id, kqdate);
data = new HashMap<>();
kqReportFieldComInfo.setTofirstRow();
while (kqReportFieldComInfo.next()) {
if (!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1")) continue;
if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily"))
continue;
String fieldName = kqReportFieldComInfo.getFieldname();
String fieldValue = "";
if (fieldName.equals("subcompany")) {
String fieldValueID = rs.getString("subcompanyid");
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") :
subCompanyComInfo.getSubCompanyname(fieldValueID);
//fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID);
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getSubCompanyID(id);
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") :
subCompanyComInfo.getSubCompanyname(fieldValueID);
// fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (fieldName.equals("department")) {
String fieldValueID = rs.getString("departmentid");
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") :
departmentComInfo.getDepartmentname(fieldValueID);
//fieldValue = departmentComInfo.getDepartmentname(fieldValueID);
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getDepartmentID(id);
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") :
departmentComInfo.getDepartmentname(fieldValueID);
// fieldValue = departmentComInfo.getDepartmentname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (fieldName.equals("jobtitle")) {
String fieldValueID = rs.getString("jobtitle");
fieldValue = jobTitlesComInfo.getJobTitlesname(rs.getString("jobtitle"));
if (fieldValue.length() == 0) {
fieldValueID = resourceComInfo.getJobTitle(id);
fieldValue = jobTitlesComInfo.getJobTitlesname(fieldValueID);
}
data.put(fieldName + "Id", fieldValueID);
data.put(fieldName, fieldValue);
} else if (kqReportFieldComInfo.getParentid().equals("overtime") || kqReportFieldComInfo.getParentid().equals("overtime_nonleave")
|| kqReportFieldComInfo.getParentid().equals("overtime_4leave") || fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) {
if (fieldName.equals("overtimeTotal")) {
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave +
workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave));
} else {
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|" + kqdate + "|" + fieldName)));
}
data.put(fieldName, fieldValue);
} else if (fieldName.equals("serialid")) {
fieldValue = Util.null2String(rs.getString(fieldName));
if (fieldValue.length()>0) {//弹性工作制没有班次
// data.put("serialid", shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage()));
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 {
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();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = allLeaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = allLeaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
allLeaveRules.remove(i);
}
}
}
Map<String, Object> leaveRule = null;
for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) {
leaveRule = (Map<String, Object>) allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_" + leaveRule.get("id"));
String leaveData = Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowType));
String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try {
//以防止出现精度问题
if (leaveData.length() == 0) {
leaveData = "0.0";
}
if (leavebackData.length() == 0) {
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(leaveData);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
} catch (Exception e) {
kqLog.info("GetKQReportCmd:leaveData" + leaveData + ":leavebackData:" + leavebackData + ":" + e);
}
//考虑下冻结的数据
if (b_flowLeaveData.length() > 0) {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
} else {
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData, 0.0) - Util.getDoubleValue(leavebackData, 0.0)));
}
data.put(flowType, flowLeaveData);
}
data.put("resourceId", id);
data.put("kqdate", kqdate);
datas.add(data);
}
List<Object> lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate);
retmap.put("holidays", lsHolidays);
retmap.put("columns",columns);
retmap.put("datas",datas);
retmap.put("pagesize", pageSize);
retmap.put("pageindex", pageIndex);
retmap.put("count", count);
retmap.put("pagecount", pageCount);
retmap.put("ishavepre", isHavePre);
retmap.put("ishavenext", isHaveNext);
}catch (Exception e){
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<>();
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
Map column = null;
int sumChildColumnWidth = 0;
if(parentid.equals("leave")){
KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz();
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = leaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = leaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
leaveRules.remove(i);
}
}
}
for(int i=0;leaveRules!=null&&i<leaveRules.size();i++){
Map<String, Object> leaveRule = leaveRules.get(i);
String 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 = "";
KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo();
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
try{
sql = " select kqdate,resourceid,day_type,serialid,serialnumber,workbegindate,workbegintime, " +
" workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" +
" attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," +
" leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid,flowinfo,on_absenteeismmins,off_absenteeismmins \n" +
" from 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"));
String dayType = Util.null2s(rs.getString("day_type"),"");
int workMins = rs.getInt("workMins");
boolean isNonWork = false;
if(dayType.length() > 0){
if("holiday".equals(dayType) || "playday".equals(dayType)){
isNonWork = true;
}
}else{
if(workMins<=0){
isNonWork = true;
}else{
if(serialid.length() > 0){
String isRest = Util.null2s(kqShiftManagementComInfo.getIsRest(serialid),"");
if("1".equals(isRest)){
isNonWork = true;
}
}
}
}
int serialnumber = rs.getInt("serialnumber")+1;
String workbegindate = Util.null2String(rs.getString("workbegindate")).trim();
String workbegintime = Util.null2String(rs.getString("workbegintime")).trim();
String workenddate = Util.null2String(rs.getString("workenddate")).trim();
String workendtime = Util.null2String(rs.getString("workendtime")).trim();
String signintime = Util.null2String(rs.getString("signintime")).trim();
String signouttime = Util.null2String(rs.getString("signouttime")).trim();
int attendanceMins = rs.getInt("attendanceMins");
String beLateMins = Util.null2String(rs.getString("beLateMins")).trim();
String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim();
String leaveEarlyMins= Util.null2String(rs.getString("leaveEarlyMins")).trim();
String graveLeaveEarlyMins= Util.null2String(rs.getString("graveLeaveEarlyMins")).trim();
String absenteeismMins= Util.null2String(rs.getString("absenteeismMins")).trim();
String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim();
String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim();
String signinid = Util.null2String(rs.getString("signinid")).trim();
String signoutid = Util.null2String(rs.getString("signoutid")).trim();
int leaveMins = rs.getInt("leaveMins");
String leaveInfo = Util.null2String(rs.getString("leaveInfo"));
String flowinfo = Util.null2String(rs.getString("flowinfo"));
String on_absenteeismmins = Util.null2String(rs.getString("on_absenteeismmins"));
String off_absenteeismmins = Util.null2String(rs.getString("off_absenteeismmins"));
int evectionMins = rs.getInt("evectionMins");
int outMins = rs.getInt("outMins");
if(!isNonWork){
if (workbegintime.length() > 0) {
signStatusInfo = new HashMap();
signStatusInfo.put("resourceId",resourceid);
signStatusInfo.put("kqdate",kqdate);
signStatusInfo.put("workdate",workbegindate);
signStatusInfo.put("worktime",workbegintime);
signStatusInfo.put("beLateMins",beLateMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("graveBeLateMins",graveBeLateMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
signStatusInfo.put("flowinfo",flowinfo);
signStatusInfo.put("on_absenteeismmins",on_absenteeismmins);
signStatusInfo.put("off_absenteeismmins",off_absenteeismmins);
signStatusInfo.put("workbegintime",workbegintime);
signStatusInfo.put("workendtime",workendtime);
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("resourceId",resourceid);
signStatusInfo.put("kqdate",kqdate);
signStatusInfo.put("workdate",workenddate);
signStatusInfo.put("worktime",kqTimesArrayComInfo.turn48to24Time(workendtime));
signStatusInfo.put("leaveEarlyMins",leaveEarlyMins);
signStatusInfo.put("graveLeaveEarlyMins",graveLeaveEarlyMins);
signStatusInfo.put("forgotCheckMins",forgotCheckMins);
signStatusInfo.put("forgotBeginWorkCheckMins",forgotBeginWorkCheckMins);
signStatusInfo.put("absenteeismMins",absenteeismMins);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
signStatusInfo.put("flowinfo",flowinfo);
signStatusInfo.put("on_absenteeismmins",on_absenteeismmins);
signStatusInfo.put("off_absenteeismmins",off_absenteeismmins);
signStatusInfo.put("workbegintime",workbegintime);
signStatusInfo.put("workendtime",workendtime);
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("resourceId",resourceid);
signStatusInfo.put("kqdate",kqdate);
signStatusInfo.put("leaveMins",leaveMins);
signStatusInfo.put("leaveInfo",leaveInfo);
signStatusInfo.put("evectionMins",evectionMins);
signStatusInfo.put("outMins",outMins);
signStatusInfo.put("flowinfo",flowinfo);
signStatusInfo.put("on_absenteeismmins",on_absenteeismmins);
signStatusInfo.put("off_absenteeismmins",off_absenteeismmins);
signStatusInfo.put("workbegintime",workbegintime);
signStatusInfo.put("workendtime",workendtime);
if(signinid.length() > 0){
data.put("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("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
}
}else 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"));
data.put("signoutstatus"+serialnumber, KQReportBiz.getSignStatus(signStatusInfo,user,"off"));
}
}
}
}catch (Exception e){
writeLog(e);
}
return data;
}
@Override
public BizLogContext getLogContext() {
return null;
}
}

@ -0,0 +1,818 @@
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.weaver.file.Prop;
import com.engine.kq.util.KQDurationCalculatorUtil;
import com.engine.kq.util.PageUidFactory;
import com.google.common.collect.Maps;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;
import java.math.BigDecimal;
import java.util.*;
public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
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();
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
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());
boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half"));
if(isKqReportHalfOpen) {
pageSize = pageSize/2;
}
int count = 0;
int pageCount = 0;
int isHavePre = 0;
int isHaveNext = 0;
String rightSql = kqReportBiz.getReportRight("1",""+user.getUID(),"a");
if(isFromMyAttendance.equals("1")){
rightSql = "";
}
List<Map<String, Object>> leaveRules = kqLeaveRulesBiz.getAllLeaveRules();
List<Object> columns = new ArrayList();
Map<String,Object> column = null;
List<Object> datas = new ArrayList();
Map<String,Object> data = null;
Map<String,Object> mapChildColumnInfo = null;
List<Object> childColumns = null;
KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo();
while (kqReportFieldComInfo.next()){
if(Util.null2String(kqReportFieldComInfo.getParentid()).length()>0)continue;
if(kqReportFieldComInfo.getFieldname().equals("kqCalendar"))continue;
if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname()))continue;
if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0)continue;
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
column.put("type", kqReportFieldComInfo.getFieldname());
column.put("key", kqReportFieldComInfo.getFieldname());
column.put("isSystem", kqReportFieldComInfo.getIsSystem());
mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(),user);
childColumns = (List<Object>)mapChildColumnInfo.get("childColumns");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("rowSpan", 1);
column.put("width", mapChildColumnInfo.get("sumChildColumnWidth"));
column.put("children", childColumns);
}else{
column.put("rowSpan", 3);
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
}
column.put("showDetial",kqReportFieldComInfo.getShowDetial());
columns.add(column);
columns.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user));
}
boolean isEnd = false;
Calendar cal = DateUtil.getCalendar();
String today = DateUtil.getCurrentDate();
// if(DateUtil.compDate(today, toDate)>0){//结束日期不大于今天
// toDate = today;
// if(DateUtil.compDate(today, fromDate)>0){//结束日期不大于今天
// fromDate = today;
// }
// }
childColumns = new ArrayList<>();
for(String date=fromDate; !isEnd;) {
if(date.equals(toDate)) isEnd = true;
column = new HashMap();
column.put("title", DateUtil.geDayOfMonth(date));
column.put("dataIndex", date);
column.put("key", date);
column.put("type", date);
column.put("rowSpan", 1);
column.put("width", 90);
column.put("isCalendar", 1);
childColumns.add(column);
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
}
column = new HashMap();
column.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage()));
column.put("dataIndex", "kqCalendar");
column.put("key", "kqCalendar");
if(childColumns.size()>0) {//跨列width取子列的width
column.put("rowSpan", 1);
column.put("width", childColumns.size()*90);
column.put("children", childColumns);
}
columns.add(column);
// 没有权限的人最大只支持查询本季
Map<String, String> getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1");
fromDate = getRealDate.get("fromDate");
toDate = getRealDate.get("toDate");
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) ";
}
}
if("-1".equals(fromDate) || "-1".equals(toDate)) {
sqlWhere += " and 1=2 ";
}
sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+groupBy+") t";
rs.execute(sql);
if (rs.next()){
count = rs.getInt("c");
}
if (count <= 0) {
pageCount = 0;
}
pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0);
isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0;
isHavePre = (pageIndex - 1 >= 1) ? 1 : 0;
String orderBy = " order by t.dsporder asc, t.lastname asc ";
String descOrderBy = " order by t.dsporder desc, t.lastname desc ";
//默认排序设置 start有性能问题先取消后面再看看有没有好的方式
// String orderBySql = "select * from kq_report_order where userId=? and sort=1 order by orders";
// rs.executeQuery(orderBySql, user.getUID());
// if (rs.getCounts() <= 0) {
// orderBySql = "select * from kq_report_order where userId=0 and sort=1 order by orders";
// rs.executeQuery(orderBySql);
// }
// while (rs.next()) {
// String dataIndex = rs.getString("dataIndex");
// String ascOrDesc = rs.getString("ascOrDesc");
// String ascOrDesc1 = (ascOrDesc.equals("")||ascOrDesc.equals("asc"))?"desc":"asc";
// if (dataIndex.equals("organization")) {
// orderBy += ",showOrderOfDeptTree " + ascOrDesc + ",dept_id " + ascOrDesc;
// descOrderBy += ",showOrderOfDeptTree " + ascOrDesc1 + ",dept_id " + ascOrDesc1;
// }
// if (dataIndex.equalsIgnoreCase("dspOrder") || dataIndex.equalsIgnoreCase("lastName")) {
// orderBy += "," + dataIndex + " " + ascOrDesc + ",id " + ascOrDesc;
// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",id " + ascOrDesc1;
// } else if (dataIndex.equalsIgnoreCase("deptShowOrder") || dataIndex.equalsIgnoreCase("deptName")) {
// orderBy += "," + dataIndex + " " + ascOrDesc + ",dept_id " + ascOrDesc;
// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",dept_id " + ascOrDesc1;
// } else if (dataIndex.equalsIgnoreCase("subcomShowOrder") || dataIndex.equalsIgnoreCase("subcomName")) {
// orderBy += "," + dataIndex + " " + ascOrDesc + ",subcom_id " + ascOrDesc;
// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",subcom_id " + ascOrDesc1;
// }
// }
// orderBy = orderBy.startsWith(",") ? orderBy.substring(1) : orderBy;
// descOrderBy = descOrderBy.startsWith(",") ? descOrderBy.substring(1) : descOrderBy;
// orderBy = orderBy.equals("") ? " t.dspOrder,t.id " : orderBy;
// descOrderBy = descOrderBy.equals("") ? " t.dspOrder,t.id " : descOrderBy;
// orderBy = "order by "+orderBy;
sql = backFields + sqlFrom + sqlWhere + groupBy;
if (pageIndex > 0 && pageSize > 0) {
if (rs.getDBType().equals("oracle")) {
sql = " select * from (select " + sql+") t "+orderBy;
sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= "
+ (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize);
} else if (rs.getDBType().equals("mysql")) {
sql = " select * from (select " + sql+") t "+orderBy;
sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize;
}
else if (rs.getDBType().equals("postgresql")) {
sql = " select * from (select " + sql+") t "+orderBy;
sql = "select t1.* from (" + sql + ") t1 limit " +pageSize + " offset " + ((pageIndex - 1) * pageSize);
}
else {
orderBy = " order by dsporder asc, lastname asc ";
descOrderBy = " order by dsporder desc, lastname desc ";
if (pageIndex > 1) {
int topSize = pageSize;
if (pageSize * pageIndex > count) {
topSize = count - (pageSize * (pageIndex - 1));
}
sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top "
+ (pageIndex * pageSize) + sql + orderBy+ " ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy;
} else {
sql = " select top " + pageSize + sql+orderBy;
}
}
} else {
sql = " select " + sql;
}
// #1475814-概述:满足考勤报分部部门显示及导出时显示全路径
String fullPathMainKey = "show_full_path";
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);
rs.execute(sql);
while (rs.next()) {
data = new HashMap<>();
kqReportFieldComInfo.setTofirstRow();
String id = rs.getString("id");
data.put("resourceId",id);
while (kqReportFieldComInfo.next()){
if(!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1"))continue;
if(!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month"))continue;
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0){
continue;
}
String fieldName = kqReportFieldComInfo.getFieldname();
String fieldValue = "";
if(fieldName.equals("subcompany")){
String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid"));
if(tmpSubcompanyId.length()==0){
tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id));
}
data.put("subcompanyId",tmpSubcompanyId);
fieldValue = "1".equals(isShowFullPath) ?
SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") :
subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
// fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId);
}else if(fieldName.equals("department")){
String tmpDepartmentId = Util.null2String(rs.getString("departmentid"));
if(tmpDepartmentId.length()==0){
tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id));
}
data.put("departmentId",tmpDepartmentId);
fieldValue = "1".equals(isShowFullPath) ?
departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") :
departmentComInfo.getDepartmentname(tmpDepartmentId);
// fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId);
}else if(fieldName.equals("jobtitle")){
String tmpJobtitleId = Util.null2String(rs.getString("jobtitle"));
if(tmpJobtitleId.length()==0){
tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id));
}
data.put("jobtitleId",tmpJobtitleId);
fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId);
}else if(fieldName.equals("attendanceSerial")){
List<String> serialIds = null;
if(attendanceSerial.length()>0){
serialIds = Util.splitString2List(attendanceSerial,",");
}
for(int i=0;serialIds!=null&&i<serialIds.size();i++){
data.put(serialIds.get(i), kqReportBiz.getSerialCount(id,fromDate,toDate,serialIds.get(i)));
}
}else if(kqReportFieldComInfo.getParentid().equals("overtime")||kqReportFieldComInfo.getParentid().equals("overtime_nonleave")
||kqReportFieldComInfo.getParentid().equals("overtime_4leave")||fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
if(fieldName.equals("overtimeTotal")){
double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leave")));
workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave;
double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leave")));
restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave;
double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leave")));
holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave;
double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleave")));
workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave;
double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleave")));
restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave;
double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleave")));
holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave;
fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+
workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave));
}else if(fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){
String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id+"|"+fieldName)),"0.0");
String backType = fieldName+"_back";
String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+backType)),"0.0");
String businessLeave = "";
try{
//以防止出现精度问题
if(businessLeaveData.length() == 0){
businessLeaveData = "0.0";
}
if(businessLeavebackData.length() == 0){
businessLeavebackData = "0.0";
}
BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData);
BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData);
businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString();
if(Util.getDoubleValue(businessLeave, -1) < 0){
businessLeave = "0.0";
}
}catch (Exception e){
}
fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave);
}else{
fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id+"|"+fieldName)));
}
} else {
fieldValue = Util.null2String(rs.getString(fieldName));
if(Util.null2String(kqReportFieldComInfo.getUnittype()).length()>0) {
if(fieldValue.length() == 0){
fieldValue="0";
}else{
if (kqReportFieldComInfo.getUnittype().equals("2")) {
fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0)));
}
}
}
}
data.put(fieldName,fieldValue);
}
//请假
List<Map<String, Object>> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules();
if(("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = allLeaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = allLeaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
allLeaveRules.remove(i);
}
}
}
Map<String, Object> leaveRule = null;
for(int i=0;allLeaveRules!=null&&i<allLeaveRules.size();i++){
leaveRule = (Map<String, Object>)allLeaveRules.get(i);
String flowType = Util.null2String("leaveType_"+leaveRule.get("id"));
String leaveData = Util.null2String(flowData.get(id+"|"+flowType));
String flowLeaveBackType = Util.null2String("leavebackType_"+leaveRule.get("id"));
String leavebackData = Util.null2s(Util.null2String(flowData.get(id+"|"+flowLeaveBackType)),"0.0");
String b_flowLeaveData = "";
String flowLeaveData = "";
try{
//以防止出现精度问题
if(leaveData.length() == 0){
leaveData = "0.0";
}
if(leavebackData.length() == 0){
leavebackData = "0.0";
}
BigDecimal b_leaveData = new BigDecimal(leaveData);
BigDecimal b_leavebackData = new BigDecimal(leavebackData);
b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString();
if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){
b_flowLeaveData = "0.0";
}
}catch (Exception e){
writeLog("GetKQReportCmd:leaveData"+leaveData+":leavebackData:"+leavebackData+":"+e);
}
//考虑下冻结的数据
if(b_flowLeaveData.length() > 0){
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData);
}else{
flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData,0.0)-Util.getDoubleValue(leavebackData,0.0)));
}
data.put(flowType,flowLeaveData);
}
Map<String,Object> amData = Maps.newHashMap();
Map<String,Object> pmData = Maps.newHashMap();
if(isKqReportHalfOpen) {
amData.putAll(data);
pmData.putAll(data);
}
Map<String,Object> detialDatas = kqReportBiz.getDetialDatas(id,fromDate,toDate,user,flowData,false,uintType,show_card_source);
// new KQLog().info("id:"+id+":detialDatas:"+detialDatas);
String user_endDate = Util.null2String(resourceComInfo.getEndDate(id));
String user_status = Util.null2String(resourceComInfo.getStatus(id));
String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim();
String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim();
if(companyStartDate.length()!=10){
companyStartDate = "";
}
if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){
begindate=companyStartDate;
}
isEnd = false;
for(String date=fromDate; !isEnd;) {
if(date.equals(toDate)) isEnd = true;
if(DateUtil.compDate(today, date)>0){
if(isKqReportHalfOpen) {
amData.put(date,"");
pmData.put(date,"");
} else {
data.put(date,"");
}
}else{
if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){
//其他状态
if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后
if(isKqReportHalfOpen) {
amData.put(date,"");
pmData.put(date,"");
} else {
data.put(date,"");
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
continue;
}
}
if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准
if(isKqReportHalfOpen) {
amData.put(date,"");
pmData.put(date,"");
} else {
data.put(date,"");
}
cal.setTime(DateUtil.parseToDate(date));
date = DateUtil.getDate(cal.getTime(), 1);
continue;
}
if(isKqReportHalfOpen) {
Map<String,Object> tmpData = Maps.newHashMap();
Object tmpValue = null;
if(detialDatas.get(id+"|"+date)==null){
tmpValue = SystemEnv.getHtmlLabelName(26593, user.getLanguage());
data.put(date,tmpValue);
amData.put(date,tmpValue);
pmData.put(date,tmpValue);
}else {
tmpData = (Map<String, Object>) detialDatas.get(id+"|"+date);
data.put(date,tmpData);
if(tmpData != null){
tmpData.put("text",Util.null2String(tmpData.get("textAM")));
Map<String,Object> amTmpData = Maps.newHashMap();
amTmpData.put("text",Util.null2String(tmpData.get("textAM")));
Map<String,Object> pmTmpData = Maps.newHashMap();
pmTmpData.put("text",Util.null2String(tmpData.get("textPM")));
amData.put(date,amTmpData);
pmData.put(date,pmTmpData);
}
}
} else {
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);
}
if(isKqReportHalfOpen) {
amData.put("rowSpan", "2");
pmData.put("rowSpan", "0");
datas.add(amData);
datas.add(pmData);
} else {
datas.add(data);
}
}
List<Object> lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate);
retmap.put("holidays", lsHolidays);
retmap.put("columns",columns);
retmap.put("datas",datas);
if(isKqReportHalfOpen) {
retmap.put("pagesize", pageSize*2);
retmap.put("count", count*2);
} else {
retmap.put("pagesize", pageSize);
retmap.put("count", count);
}
retmap.put("pageindex", pageIndex);
retmap.put("pagecount", pageCount);
retmap.put("ishavepre", isHavePre);
retmap.put("ishavenext", isHaveNext);
retmap.put("isKqReportHalfOpen", isKqReportHalfOpen);
}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;
KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo();
String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0");
if(parentid.equals("attendanceSerial")){//考勤班次
KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo();
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
List<String> serialIds = null;
if(Util.null2String(jsonObj.get("attendanceSerial")).length()>0){
serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")),",");
}
for(int i=0;serialIds!=null&&i<serialIds.size();i++){
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();
if (("1").equals(leavetype_is_on)) {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
for (int i = leaveRules.size() - 1; i >= 0; i--) {
Map<String, Object> leaveRule = leaveRules.get(i);
String leaveId = Util.null2String(leaveRule.get("id"));
boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId);
if (flag) {
leaveRules.remove(i);
}
}
}
for(int i=0;leaveRules!=null&&i<leaveRules.size();i++){
Map<String, Object> leaveRule = leaveRules.get(i);
String 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;
}
/**
* *
*/
public double getOvertimeCount(String userid , String fromDate, String toDate, double leaveTime, String leaveType){
BigDecimal bigDecimal = new BigDecimal(Double.toString(leaveTime));
KQWorkTime kqWorkTime = new KQWorkTime();
String propValue = Util.null2String(Prop.getPropValue("Others","wfTableName"));
if("".equals(propValue)){
return leaveTime;
}
String sql = " select * from " +propValue +" where jbksrq >= ? and jbksrq >= ? and sqr = ?";
RecordSet rs = new RecordSet();
rs.executeQuery(sql,fromDate, toDate, userid);
while (rs.next()) {
String workdate = rs.getString("jbksrq");
boolean workDay = kqWorkTime.isWorkDay(userid, workdate);
boolean isHoliday = KQHolidaySetBiz.isHoliday(userid,workdate);
double dxsc = rs.getDouble("dxsc");
dxsc = (double)Math.round(dxsc*100)/100;
BigDecimal bigDecimalDxsc = new BigDecimal(Double.toString(dxsc));
if(workDay){
if("1".equals(leaveType)){
bigDecimal.subtract(bigDecimalDxsc);
}
}else if(isHoliday ){
if("2".equals(leaveType)){
bigDecimal.subtract(bigDecimalDxsc);
}
}else {
if("3".equals(leaveType)){
bigDecimal.subtract(bigDecimalDxsc);
}
}
}
return bigDecimal.doubleValue();
}
@Override
public BizLogContext getLogContext() {
return null;
}
public static void main(String[] args) {
String s1 = String.format("%.2f", 1.2);
System.out.println(s1);
}
}

@ -0,0 +1,136 @@
package weaver.interfaces.zw.utils;
import weaver.general.BaseBean;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.Util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CommonUtil {
/**
*
* @param sql
* @return
*/
public static List<Map<String,String>> queryListBySql(String sql){
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
try{
if(StringUtils.isNotBlank(sql)){
Map<String,String> map = new HashMap<String,String>();
rs.executeQuery(sql);
String[] column = rs.getColumnName();
while (rs.next()){
map = new HashMap<String,String>();
for(int i=0;i<column.length;i++){
String value = rs.getString(column[i]);
map.put(column[i],value);
}
if(!map.isEmpty() && map.size()>0){
list.add(map);
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog("queryListBySql-e:"+e);
}
return list;
}
/***
*
* @param sql
* @return
*/
public static Map<String,String> queryMapBySql(String sql){
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
Map<String,String> map = new HashMap<String,String>();
try{
if(StringUtils.isNotBlank(sql)){
rs.executeQuery(sql);
String[] column = rs.getColumnName();
if (rs.next()){
for(int i=0;i<column.length;i++){
String value = rs.getString(column[i]);
map.put(column[i],value);
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog("queryMapBySql-e:"+e);
}
return map;
}
/***
*
* @param workflowid
* @return
*/
public static String getFormtableByWorkflowId(String workflowid){
String formtable = "" ;
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
try{
if(StringUtils.isNotBlank(workflowid)){
String sql = "select abs(formid) as formid from workflow_base where id= "+workflowid ;
bb.writeLog("sql:"+sql);
rs.executeQuery(sql);
if(rs.next()){
String formid = Util.null2String(rs.getString("formid"));
bb.writeLog("formid:"+formid);
if(StringUtils.isNotBlank(formid)){
formtable = "formtable_main_"+formid ;
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog("getFormtableByWorkflowId:"+e);
}
return formtable;
}
/**
*
* @param requestid
* @return
*/
public static String getFormtableByRequestId(String requestid){
String formtable = "" ;
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
try{
if(StringUtils.isNotBlank(requestid)){
String sql =" select abs(formid) from workflow_base t \n" +
" inner join workflow_requestbase h on h.workflowid = t.id \n" +
" where requestid= "+requestid ;
bb.writeLog("sql2:"+sql);
rs.executeQuery(sql);
if(rs.next()){
String formid = Util.null2String(rs.getString("formid"));
if(StringUtils.isNotBlank(formid)){
formtable = "formtable_main_"+formid ;
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog("getFormtableByRequestId:"+e);
}
return formtable;
}
}

@ -0,0 +1,278 @@
package weaver.interfaces.zw.workflow.action;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.kq.biz.KQGroupBiz;
import com.engine.kq.biz.KQGroupComInfo;
import com.engine.kq.biz.KQGroupMemberComInfo;
import com.engine.kq.service.KQShiftScheduleService;
import com.engine.kq.service.impl.KQShiftScheduleServiceImpl;
import com.weaver.general.BaseBean;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.interfaces.zw.utils.CommonUtil;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author shil
* @date 2024/8/1
*
*/
public class WorkflowToSchedulingAction implements Action {
@Override
public String execute(RequestInfo requestInfo) {
BaseBean bb = new BaseBean();
String requestid = requestInfo.getRequestid();
String workflowid = requestInfo.getWorkflowid();
String billtable = requestInfo.getRequestManager().getBillTableName();
User user = requestInfo.getRequestManager().getUser();
RecordSet rs = new RecordSet();
bb.writeLog("----WorkflowToSchedulingAction------");
try {
String mainid = "" ;
String cjr = "" ;
String pbyf = "" ;
String cjrbm = "" ;
String sql = " select id,cjr,pbyf,cjrbm from "+billtable+" where requestid="+requestid;
rs.execute(sql);
if(rs.next()){
mainid = Util.null2String(rs.getString("id"));
cjr = Util.null2String(rs.getString("cjr"));
pbyf = Util.null2String(rs.getString("pbyf"));
cjrbm = Util.null2String(rs.getString("cjrbm"));
}
List<Map<String,String>> requestList = queryRequestList(billtable,cjrbm,pbyf,workflowid,requestid);
if(!requestList.isEmpty() && requestList.size() >0){
requestInfo.getRequestManager().setMessageid("1000");
requestInfo.getRequestManager().setMessagecontent("流程提交接口异常");
return Action.FAILURE_AND_CONTINUE;
}else{
List<Map<String,String>> scheduleList = queryScheduleData(billtable,mainid,pbyf);
if(!scheduleList.isEmpty() && scheduleList.size()>0){
requestInfo.getRequestManager().setMessageid("1000");
requestInfo.getRequestManager().setMessagecontent("流程提交接口异常");
return Action.FAILURE_AND_CONTINUE;
}else{
int daysInMonth = 0;
if(StringUtils.isNotBlank(pbyf) && pbyf.length() == 7){
LocalDate date = LocalDate.parse(pbyf + "-01"); // 获取当前日期
daysInMonth = date.lengthOfMonth(); // 获取本月有多少天
}
bb.writeLog("----mainid------"+mainid);
if(StringUtils.isNotBlank(mainid))
{
String groupid = getUserActiveGroupId(user.getUID()+"");
bb.writeLog("groupid:"+groupid);
JSONObject datasJSON = new JSONObject();
JSONArray datasArray = new JSONArray();
sql = " select * from "+billtable+"_dt1 where mainid="+mainid;
List<Map<String,String>> dt1List = CommonUtil.queryListBySql(sql);
for(int i=0;i<dt1List.size();i++)
{
Map<String,String> dt1Map = dt1List.get(i);
String resourceid = Util.null2String(dt1Map.get("yg"));
if(StringUtils.isNotBlank(resourceid)){
JSONArray kqdata = new JSONArray();
for(int k=1;k<=daysInMonth;k++){
String bc = Util.null2String(dt1Map.get("bc"+k));
JSONObject bcJSON = new JSONObject();
bcJSON.put("id","");
bcJSON.put("serialid",bc);
if(k<10){
bcJSON.put("date",pbyf+"-0"+k);
}else{
bcJSON.put("date",pbyf+"-"+k);
}
kqdata.add(bcJSON);
}
JSONObject dataJSON = new JSONObject();
dataJSON.put("resourceid",resourceid);
dataJSON.put("kqdata",kqdata);
datasArray.add(dataJSON);
}
}
datasJSON.put("datas",datasArray);
datasJSON.put("groupId", groupid);
bb.writeLog("data:"+datasJSON.toJSONString());
Map<String, Object> params = new HashMap<String, Object>();
params.put("data",datasJSON.toJSONString());
Map<String, Object> apidatas = getService(user).save(params, user);
bb.writeLog("apidatas:"+ JSONObject.toJSONString(apidatas));
if(apidatas.containsKey("status")){
String status = Util.null2String(apidatas.get("status"));
if(!"1".equals(status)){
String message = Util.null2String(apidatas.get("message"));
requestInfo.getRequestManager().setMessageid("1000");
requestInfo.getRequestManager().setMessagecontent(message);
return Action.FAILURE_AND_CONTINUE;
}
}else{
requestInfo.getRequestManager().setMessageid("1000");
requestInfo.getRequestManager().setMessagecontent("排班保存异常");
return Action.FAILURE_AND_CONTINUE;
}
}else{
requestInfo.getRequestManager().setMessageid("1000");
requestInfo.getRequestManager().setMessagecontent("获取流程数据异常");
return Action.FAILURE_AND_CONTINUE;
}
}
}
}catch (Exception e){
requestInfo.getRequestManager().setMessageid("1000");
requestInfo.getRequestManager().setMessagecontent("流程提交接口异常");
return Action.FAILURE_AND_CONTINUE;
}
return Action.SUCCESS;
}
/**
*
* @param billtable
* @param mainid
* @return
*/
public List<Map<String,String>> queryScheduleData(String billtable,String mainid,String pbyf){
List<Map<String,String>> scheduleList = new ArrayList<Map<String,String>>();
try {
String userids = "" ;
String sql = " select yg from "+billtable+"_dt1 where mainid="+mainid;
List<Map<String,String>> dt1List = CommonUtil.queryListBySql(sql);
for(int i=0;i<dt1List.size();i++)
{
Map<String,String> dt1Map = dt1List.get(i);
String resourceid = Util.null2String(dt1Map.get("yg"));
userids += StringUtils.isBlank(userids) ? resourceid : ","+resourceid ;
}
if(StringUtils.isNotBlank(userids)){
sql = " select kqdate,resourceid,serialid,groupid from kq_shiftschedule where left(kqdate,7) = '"+pbyf+"' and resourceid in("+userids+") and (isdelete is null or isdelete = 0)";
scheduleList = CommonUtil.queryListBySql(sql);
}
}catch (Exception e){
}
return scheduleList;
}
/***
*
* @param billtable
* @param cjrbm
* @param pbyf
* @param workflowid
* @param requestid
* @return
*/
public List<Map<String,String>> queryRequestList(String billtable,String cjrbm,String pbyf,String workflowid,String requestid){
List<Map<String,String>> requestList = new ArrayList<Map<String,String>>();
try{
String sql =" select t.id " +
" from "+billtable+" t " +
" inner join workflow_requestbase r on r.requestid = t.requestid " +
" where t.pbyf ='"+pbyf+"' " +
" and t.cjrbm ='"+cjrbm+"' " +
" and r.currentnodetype in(1,2,3) " +
" and r.workflowid = "+workflowid +
" and t.requestid <> "+requestid;
requestList = CommonUtil.queryListBySql(sql);
}catch (Exception e){
}
return requestList;
}
private KQShiftScheduleService getService(User user) {
return (KQShiftScheduleService) ServiceUtil.getService(KQShiftScheduleServiceImpl.class, user);
}
public String getUserActiveGroupId(String userid){
BaseBean bb = new BaseBean();
KQGroupMemberComInfo kqGroupMemberComInfo = null;
KQGroupComInfo kqGroupComInfo = null ;
String activeGroupId = "";
try{
kqGroupMemberComInfo = new KQGroupMemberComInfo();
kqGroupComInfo = new KQGroupComInfo();
Map<String, List<String>> groupMemberMap = getUserGroup();
String activeGroup = "";
if(groupMemberMap.containsKey(userid)){
List<String> groupIds = groupMemberMap.get(userid);
bb.writeLog("groupIds:"+groupIds.size());
for(String i : groupIds){
String isDelete = kqGroupComInfo.getIsdelete(i);
if(!"1".equals(isDelete)) {
String currentGroupId = Util.null2String(kqGroupMemberComInfo.getKQGroupId(userid, DateUtil.getCurrentDate()));
if (i.equals(currentGroupId)) {
activeGroupId = i;
}
}
}
}
}catch (Exception e){
e.printStackTrace();
bb.writeLog(e);
}
return activeGroupId;
}
/***
*
* @return
*/
public Map<String, List<String>> getUserGroup(){
BaseBean bb = new BaseBean();
Map<String, List<String>> groupMemberMap = new HashMap<>();
RecordSet rs = new RecordSet();
String viewScope = "3";
try {
KQGroupBiz kqGroupBiz = new KQGroupBiz();
Map<String, Object> groupParams = new HashMap<String, Object>();
if("3".equals(viewScope)){
groupParams.put("isNoAccount", "1");
}
rs.executeQuery(kqGroupBiz.getGroupMemberSql(groupParams));
while (rs.next()) {
String id = rs.getString("resourceid");
String gid = rs.getString("groupid");
if (!groupMemberMap.containsKey(id))
groupMemberMap.put(id, new ArrayList<>());
groupMemberMap.get(id).add(gid);
}
} catch (Exception e) {
}
return groupMemberMap;
}
}
Loading…
Cancel
Save