|
|
|
|
package com.engine.attendance.component.persongroup.cmd;
|
|
|
|
|
|
|
|
|
|
import com.engine.attendance.component.persongroup.commonutil.PersongroupCommonUtil;
|
|
|
|
|
import com.engine.common.biz.AbstractCommonCommand;
|
|
|
|
|
import com.engine.common.entity.BizLogContext;
|
|
|
|
|
|
|
|
|
|
import com.engine.common.util.DateUtil;
|
|
|
|
|
import com.engine.common.util.DbTools;
|
|
|
|
|
import com.engine.core.interceptor.CommandContext;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
import weaver.hrm.company.DepartmentComInfo;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当递归查询时获得表格数据
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class GetDatatableRecurrenceCmd extends AbstractCommonCommand<Map<String,Object>> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BizLogContext getLogContext() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public GetDatatableRecurrenceCmd(Map<String, Object> params){
|
|
|
|
|
this.params=params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> execute(CommandContext commandContext) {
|
|
|
|
|
String tableName = Util.null2String(params.get("tableName"));
|
|
|
|
|
String startDate = Util.null2String(params.get("startDate"));
|
|
|
|
|
String endDate = Util.null2String(params.get("endDate"));
|
|
|
|
|
String pblx = Util.null2String(params.get("pblx"));
|
|
|
|
|
String pbdx = Util.null2String(params.get("pbdx"));
|
|
|
|
|
|
|
|
|
|
String sql = "select a.id as `key`,b.lastname,a.* from "+tableName +" a left join hrmresource b on a.pbdxry=b.id where pbtj=0 ";
|
|
|
|
|
|
|
|
|
|
String conditions = "";
|
|
|
|
|
List<Object> Dateparam = Lists.newArrayList();
|
|
|
|
|
if (!"".equals(startDate) && !"".equals(endDate)){
|
|
|
|
|
conditions += " and bcrq >= ? and bcrq<= ?";
|
|
|
|
|
Dateparam.add(startDate);
|
|
|
|
|
Dateparam.add(endDate);
|
|
|
|
|
}
|
|
|
|
|
Map<String,Object> resultMap = Maps.newHashMap();
|
|
|
|
|
List<Map<String, Object>> dataTableList = Lists.newArrayList();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if (!"".equals(pbdx)){
|
|
|
|
|
if ("0".equals(pblx)){
|
|
|
|
|
//人员递归查人员、人员分组、部门、分部
|
|
|
|
|
String querySqlbyPbdx = sql +conditions + " and pbdxry = ?";
|
|
|
|
|
List<Object> param = Lists.newArrayList();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
param.add(pbdx);
|
|
|
|
|
log.info("递归查询人员-人员节点,sql:{},param:{}",querySqlbyPbdx,param);
|
|
|
|
|
List<Map<String,Object>> dataList = DbTools.getSqlToList(querySqlbyPbdx,param.toArray());
|
|
|
|
|
if (dataList.size() == 0){
|
|
|
|
|
//查人员分组
|
|
|
|
|
String currentTime = DateUtil.getCurrentDate();
|
|
|
|
|
String queryryfz = "select a.mainid,a.empid,a.filters,a.bdate,a.edate from uf_ryqz_dt1 a,(select pbdxryfz from uf_pbjg where dxlx=1 group by pbdxryfz) b where a.mainid =b.pbdxryfz and a.bdate <= '"+currentTime+"'";
|
|
|
|
|
List<Map<String,Object>> personGroupData = DbTools.getSqlToList(queryryfz);
|
|
|
|
|
Set<String> personnelGroupIds = PersongroupCommonUtil.getPersonnelGroupingByPerson(personGroupData,pbdx,null,null);
|
|
|
|
|
querySqlbyPbdx = sql +conditions + " and pbdxryfz in (?)";
|
|
|
|
|
log.info("递归查询人员-人员分组节点,sql:{},personnelGroupIds:{}",querySqlbyPbdx,personnelGroupIds);
|
|
|
|
|
if(personnelGroupIds.size() > 0){
|
|
|
|
|
param.clear();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
param.add(String.join(",",personnelGroupIds));
|
|
|
|
|
dataList = DbTools.getSqlToList(querySqlbyPbdx,param.toArray());
|
|
|
|
|
}
|
|
|
|
|
if (dataList.size() == 0){
|
|
|
|
|
//查询人员部门
|
|
|
|
|
String queryDepartmentidAndSubcompanyid = "select id,departmentid,subcompanyid1 from hrmresource where id =?";
|
|
|
|
|
Map<String,Object> dataMap = DbTools.getSqlToMap(queryDepartmentidAndSubcompanyid,pbdx);
|
|
|
|
|
String pdeptids = "";
|
|
|
|
|
pdeptids = new DepartmentComInfo().getAllParentDepartId(Util.null2String(dataMap.get("departmentid")), pdeptids);
|
|
|
|
|
pdeptids = Util.null2String(dataMap.get("departmentid")) + pdeptids;
|
|
|
|
|
log.info("pdeptids : [{}]",pdeptids);
|
|
|
|
|
querySqlbyPbdx = sql + conditions + " and pbdxbm in (?)";
|
|
|
|
|
log.info("递归查询人员-部门节点,sql:{},pdeptids:{}",querySqlbyPbdx,pdeptids);
|
|
|
|
|
param.clear();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
param.add(pdeptids);
|
|
|
|
|
dataList = DbTools.getSqlToList(querySqlbyPbdx,param.toArray());
|
|
|
|
|
if (dataList.size() == 0){
|
|
|
|
|
//查询人员分部
|
|
|
|
|
querySqlbyPbdx = sql + conditions + " and pbdxfb = ?";
|
|
|
|
|
log.info("递归查询人员-分部节点,sql:{},pdeptids:{}",querySqlbyPbdx,dataMap.get("subcompanyid1"));
|
|
|
|
|
param.clear();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
param.add(dataMap.get("subcompanyid1"));
|
|
|
|
|
dataList = DbTools.getSqlToList(querySqlbyPbdx,param.toArray());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dataTableList = dataList;
|
|
|
|
|
}else if ("1".equals(pblx)){
|
|
|
|
|
List<Object> param = Lists.newArrayList();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
//人员分组
|
|
|
|
|
conditions += " and pbdxryfz = ?";
|
|
|
|
|
sql +=conditions;
|
|
|
|
|
param.add(pbdx);
|
|
|
|
|
dataTableList = DbTools.getSqlToList(sql,param.toArray());
|
|
|
|
|
|
|
|
|
|
}else if ("2".equals(pblx)){
|
|
|
|
|
List<Object> param = Lists.newArrayList();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
//部门
|
|
|
|
|
//部门递归查、部门、分部
|
|
|
|
|
String querySqlbyPbdx = sql +conditions + " and pbdxbm = ?";
|
|
|
|
|
param.add(pbdx);
|
|
|
|
|
dataTableList = DbTools.getSqlToList(querySqlbyPbdx,param.toArray());
|
|
|
|
|
if (dataTableList.size() == 0){
|
|
|
|
|
String querySubCompanySql = "select subcompanyid1 from hrmdepartment where id=?";
|
|
|
|
|
Map<String,Object> departMentMap = DbTools.getSqlToMap(querySubCompanySql,pbdx);
|
|
|
|
|
querySqlbyPbdx = sql +conditions + " and pbdxfb = ?";
|
|
|
|
|
log.info("递归查询部门-分部节点,sql:{},pdeptids:{}",querySqlbyPbdx,departMentMap.get("subcompanyid1"));
|
|
|
|
|
param.clear();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
param.add(departMentMap.get("subcompanyid1"));
|
|
|
|
|
dataTableList = DbTools.getSqlToList(querySqlbyPbdx,param.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if ("3".equals(pblx)){
|
|
|
|
|
List<Object> param = Lists.newArrayList();
|
|
|
|
|
param.addAll(Dateparam);
|
|
|
|
|
//分部
|
|
|
|
|
conditions += " and pbdxfb = ?";
|
|
|
|
|
sql +=conditions;
|
|
|
|
|
param.add(pbdx);
|
|
|
|
|
dataTableList = DbTools.getSqlToList(sql,param.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("catch error : {}",e);
|
|
|
|
|
}
|
|
|
|
|
resultMap.put("dataTableList",dataTableList);
|
|
|
|
|
log.info("dataTableList total size : {}",dataTableList.size());
|
|
|
|
|
|
|
|
|
|
return resultMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|