You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

364 lines
17 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.engine.common.util;
import com.engine.attendance.component.persongroup.commonutil.PersongroupCommonUtil;
import com.engine.attendance.enums.ApplicableOrganizationEnum;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import weaver.soa.workflow.request.*;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class CommonUtil {
/**
* 组装insert的sql语句
* @param tableName 表名
* @param map 列名及对应值
* @return
*/
public static String makeInsertSql(String tableName, Map<String,Object> map){
String insertSql = "insert into "+tableName;
String key = "(";
String value = "(";
for (Map.Entry<String,Object> e : map.entrySet()){
key = key + e.getKey() +",";
value = value + "'"+e.getValue()+"'" +",";
}
key = key.substring(0,key.length()-1) + ")";
value = value.substring(0,value.length()-1)+")";
insertSql = insertSql + key +" values "+value;
log.info("makeInsertSql :[{}]",insertSql);
return insertSql;
}
/**
* 组装update的sql语句
* @param tableName 表名
* @param map 列名及对应值
* @param condition 条件
* @return
*/
public static String makeUpdateSql(String tableName, Map<String,Object> map,Map<String,Object> condition){
String updateSql = "update "+tableName+" set ";
for (Map.Entry<String,Object> e : map.entrySet()){
if (e.getValue() !=null && !"".equals(e.getValue())){
updateSql = updateSql + e.getKey()+"='"+e.getValue().toString()+"',";
}
}
updateSql = updateSql.substring(0,updateSql.length()-1) + " where 1=1";
for (Map.Entry<String,Object> e : condition.entrySet()){
updateSql = updateSql + " and "+ e.getKey()+"='"+e.getValue()+"'";
}
log.info("makeUpdateSql : [{}]",updateSql);
return updateSql;
}
public static Set<String> getDataIds(String resourceId,String modeId,String startDate,String endDate){
String sql = "select dxlx,dataid,dx from uf_jcl_syzz where modeid=?";
List<Map<String,Object>> organizationList = DbTools.getSqlToList(sql,modeId);
sql = "select id,departmentid,subcompanyid1 from hrmresource where id =?";
Map<String,Object> departMentMap = DbTools.getSqlToMap(sql,resourceId);
Set<String> dataIds = Sets.newHashSet();
Map<String, List<Map<String,Object>>> organizationListGroupBydxlx = organizationList.stream().collect(Collectors.groupingBy(e ->e.get("dxlx").toString()));
//对象类型为人员
List<Map<String,Object>> personOrganizationList = organizationListGroupBydxlx.get("0");
//对象类型为人员组织
List<Map<String,Object>> personGroupOrganizationList = organizationListGroupBydxlx.get("1");
//对象类型为部门
List<Map<String,Object>> departmentOrganizationList = organizationListGroupBydxlx.get("2");
//对象类型为分部
List<Map<String,Object>> subCompanyOrganizationList = organizationListGroupBydxlx.get("3");
if (personOrganizationList != null){
for (Map<String,Object> personOrganization :personOrganizationList){
String dx = Util.null2String(personOrganization.get("dx"));
String ids = dx.split("-")[0];
if (ids.equals(resourceId)){
dataIds.add(Util.null2String(personOrganization.get("dataid")));
}
}
}
if (personGroupOrganizationList != null && dataIds.size() ==0){
Set<String> personGroupIds = personGroupOrganizationList.stream().map(e -> Util.null2String(e.get("dx")).split("-")[0]).collect(Collectors.toSet());
sql = "select mainid,empid,filters,bdate,edate from uf_ryqz_dt1 where mainid in ("+String.join(",",personGroupIds)+")";
log.info("query personGroupData : {}",sql);
List<Map<String,Object>> personGroupData = DbTools.getSqlToList(sql);
Set<String> personnelGroupIds = PersongroupCommonUtil.getPersonnelGroupingByPerson(personGroupData,resourceId,startDate,endDate);
log.info("personnelGroupIds : {}",personnelGroupIds);
for (Map<String,Object> personGroupOrganization :personGroupOrganizationList){
String personnelGroupId = Util.null2String(personGroupOrganization.get("dx")).split("-")[0];
if (personnelGroupIds.contains(personnelGroupId)){
dataIds.add(Util.null2String(personGroupOrganization.get("dataid")));
}
}
}
try {
if (departmentOrganizationList != null && dataIds.size() ==0){
String deptid = Util.null2String(departMentMap.get("departmentid"));
String pdeptids = "";
pdeptids = new DepartmentComInfo().getAllParentDepartId(Util.null2String(departMentMap.get("departmentid")), pdeptids);
pdeptids = deptid + pdeptids;
log.info("pdeptids : [{}]",pdeptids);
for (Map<String,Object> departmentOrganization :departmentOrganizationList){
String dx = Util.null2String(departmentOrganization.get("dx"));
String ids = dx.split("-")[0];
for (String pdeptid : pdeptids.split(",")){
if (pdeptid.equals(ids)){
dataIds.add(Util.null2String(departmentOrganization.get("dataid")));
}
}
}
}
}catch (Exception e){
log.error("catch error :{}",e);
}
if (subCompanyOrganizationList != null && dataIds.size() ==0){
String subCompanyId = Util.null2String(departMentMap.get("subcompanyid1"));
for (Map<String,Object> subCompanyOrganization :subCompanyOrganizationList){
String dx = Util.null2String(subCompanyOrganization.get("dx"));
String ids = dx.split("-")[0];
if (ids.equals(subCompanyId)){
dataIds.add(Util.null2String(subCompanyOrganization.get("dataid")));
}
}
}
log.info("dataIds : {}",dataIds);
return dataIds;
}
public static boolean ifContainStr(String fatherStr,String sonStr,String mark){
for (String pdeptid : fatherStr.split(mark)){
if (pdeptid.equals(sonStr)){
return true;
}
}
return false;
}
/**
* 根据流程requestInfo消息对象获取流程主表字段的信息的map集合
* @param requestInfo
* @return
*/
public static HashMap<String,String> getMainTableInfo(RequestInfo requestInfo){
HashMap<String,String> mainMap = new HashMap<String,String>();
Property[] properties = requestInfo.getMainTableInfo().getProperty();// 获取表单主字段信息
for (int i = 0; i < properties.length; i++) {
String name = properties[i].getName();// 主字段名称
String value = Util.null2String(properties[i].getValue());// 主字段对应的值
mainMap.put(name, value);
}
return mainMap;
}
/**
* 明细
* @param request
* @return
*/
public static List<Map<String, String>> getDetailTableInfo(RequestInfo request, int index) {
// 获取明细的信息
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
DetailTable[] detailtables = request.getDetailTableInfo().getDetailTable();// 获取明细表数据
if (detailtables.length > index) {
DetailTable dt = detailtables[index];// 获取明细表 0代表明细表1
Row[] rows = dt.getRow();// 获取明细表中所有行的信息
for (int i = 0; i < rows.length; i++) {
Row row = rows[i];// 获取具体行信息
Cell[] cells = row.getCell();// 获取具体行所有列的信息
Map<String, String> map = new HashMap<String, String>();
for (int j = 0; j < cells.length; j++) {
Cell cell = cells[j];
String name = cell.getName().toLowerCase();// 获取字段名
String value = cell.getValue();// 获取具体的值
map.put(name, value);
}
list.add(map);
}
}
return list;
}
/**
* 获取适用范围对应的人员id列表适用范围由dataId和modeId获得
* @param dataId
* @param modeId
* @return
*/
public static List<String> getEmpIds(String dataId,String modeId) {
List<String> empIdList = new ArrayList<>();
String sql = "select dxlx,aqjb,dx from uf_jcl_syzz where modeid=? and dataid = ?";
//适用组织所有值集合
List<Map<String,Object>> organzationList = DbTools.getSqlToList(sql,modeId, dataId);
//分组
List<Map<String, String>> empIdInfos = new ArrayList<>();
List<Map<String, String>> empGroupIdInfos = new ArrayList<>();
List<Map<String, String>> depIdInfos = new ArrayList<>();
List<Map<String, String>> subCompanyIdInfos = new ArrayList<>();
for (Map<String,Object> organzation:organzationList){
String id = Util.null2String(organzation.get("dx")).split("-")[0];
String securityLevel = Util.null2String(organzation.get("aqjb"));
String[] securityLevelArr = securityLevel.split("-");
String minSecurityLevel = securityLevel.substring(0, 1).equals("-") ? "" : securityLevelArr[0];
String maxSecurityLevel = "";
if (securityLevelArr.length == 1 && !securityLevelArr[0].equals(minSecurityLevel)) {
maxSecurityLevel = securityLevelArr[0];
} else if (securityLevelArr.length == 2) {
maxSecurityLevel = securityLevelArr[1];
}
if (ApplicableOrganizationEnum.PERSONNEL.getKey().equals(organzation.get("dxlx"))){
Map<String,String> infoItem = new HashMap<>();
infoItem.put("id", id);
infoItem.put("minSecurityLevel", minSecurityLevel);
infoItem.put("maxSecurityLevel", maxSecurityLevel);
empIdInfos.add(infoItem);
}else if (ApplicableOrganizationEnum.PERSONNEL_GROUP.getKey().equals(organzation.get("dxlx"))){
Map<String,String> infoItem = new HashMap<>();
infoItem.put("id", id);
infoItem.put("minSecurityLevel", minSecurityLevel);
infoItem.put("maxSecurityLevel", maxSecurityLevel);
empGroupIdInfos.add(infoItem);
}else if (ApplicableOrganizationEnum.DEPARTMENT.getKey().equals(organzation.get("dxlx"))){
Map<String,String> infoItem = new HashMap<>();
infoItem.put("id", id);
infoItem.put("minSecurityLevel", minSecurityLevel);
infoItem.put("maxSecurityLevel", maxSecurityLevel);
depIdInfos.add(infoItem);
}else if (ApplicableOrganizationEnum.SUBCOMPANY.getKey().equals(organzation.get("dxlx"))){
Map<String,String> infoItem = new HashMap<>();
infoItem.put("id", id);
infoItem.put("minSecurityLevel", minSecurityLevel);
infoItem.put("maxSecurityLevel", maxSecurityLevel);
subCompanyIdInfos.add(infoItem);
}
}
//人员类型
for (Map<String, String> map : empIdInfos) {
String id = map.get("id");
String minSecurityLevel = map.get("minSecurityLevel");
String maxSecurityLevel = map.get("maxSecurityLevel");
//查询目标人员信息
String querySql = "select * from hrmresouorce where id = " + id;
if (!minSecurityLevel.equals("")) {
querySql = querySql + " and seclevel >= " +minSecurityLevel;
}
if (!maxSecurityLevel.equals("")) {
querySql = querySql + " and seclevel <= " +maxSecurityLevel;
}
Map<String,Object> data = DbTools.getSqlToMap(querySql);
if (data.size() > 0) {
empIdList.add(id);
}
}
//人员分组类型
for (Map<String, String> map : empGroupIdInfos) {
String id = map.get("id");
String minSecurityLevel = map.get("minSecurityLevel");
String maxSecurityLevel = map.get("maxSecurityLevel");
//获取分组包含人员id
List<String> empIdsByGroup = getEmpGroupUserIds(id);
//查询目标人员信息
String querySql = "select * from hrmresouorce where id = in ("+String.join(",",empIdsByGroup)+")";
if (!minSecurityLevel.equals("")) {
querySql = querySql + " and seclevel >= " +minSecurityLevel;
}
if (!maxSecurityLevel.equals("")) {
querySql = querySql + " and seclevel <= " +maxSecurityLevel;
}
List<Map<String,Object>> datas = DbTools.getSqlToList(querySql);
if (datas.size() > 0) {
datas.forEach(f -> empIdList.add(f.get("id").toString()));
}
}
//部门类型
for (Map<String, String> map : depIdInfos) {
String id = map.get("id");
String minSecurityLevel = map.get("minSecurityLevel");
String maxSecurityLevel = map.get("maxSecurityLevel");
//查询目标人员信息
String querySql = "select * from hrmresouorce where departmentid = " + id;
if (!minSecurityLevel.equals("")) {
querySql = querySql + " and seclevel >= " +minSecurityLevel;
}
if (!maxSecurityLevel.equals("")) {
querySql = querySql + " and seclevel <= " +maxSecurityLevel;
}
List<Map<String,Object>> datas = DbTools.getSqlToList(querySql);
if (datas.size() > 0) {
datas.forEach(f -> empIdList.add(f.get("id").toString()));
}
}
//分部类型
for (Map<String, String> map : subCompanyIdInfos) {
String id = map.get("id");
String minSecurityLevel = map.get("minSecurityLevel");
String maxSecurityLevel = map.get("maxSecurityLevel");
//查询目标人员信息
String querySql = "select * from hrmresouorce where subcompanyid1 = " + id;
if (!minSecurityLevel.equals("")) {
querySql = querySql + " and seclevel >= " +minSecurityLevel;
}
if (!maxSecurityLevel.equals("")) {
querySql = querySql + " and seclevel <= " +maxSecurityLevel;
}
List<Map<String,Object>> datas = DbTools.getSqlToList(querySql);
if (datas.size() > 0) {
datas.forEach(f -> empIdList.add(f.get("id").toString()));
}
}
return empIdList;
}
/**
* 获得人员分组下面的人员集合
* @param empGroupId
* @return 人员id集合
*/
public static List<String> getEmpGroupUserIds(String empGroupId){
String sql = "select b.mainid,b.empid,b.filters,b.bdate,b.edate,a.list_type from uf_ryqz a left join uf_ryqz_dt1 b on a.id=b.mainid where mainid = " + empGroupId;
List<Map<String,Object>> personGroupDataList = DbTools.getSqlToList(sql);
List<String> empIdList = new ArrayList<>();
for (Map<String,Object> personGroupData :personGroupDataList){
String id = Util.null2String(personGroupData.get("mainid"));
String empid = Util.null2String(personGroupData.get("empid"));
String filters = Util.null2String(personGroupData.get("filters"));
String list_type = Util.null2String(personGroupData.get("list_type"));
if ("0".equals(list_type) && !"".equals(empid)){
//人员清单
empIdList.add(empid);
}else if ("1".equals(list_type) && !"".equals(filters)){
//条件清单
sql = "select id,seclevel from hrmresource where 1=1 ";
if (filters.contains("field")){
sql = "select a.id,a.seclevel from hrmresource a left join cus_fielddata b on a.id=b.id where scope='HrmCustomFieldByInfoType' and scopeid=-1 and "+filters;
}else {
filters = filters.replace("","and");
filters = filters.replace("","or");
sql = sql+ " and "+filters;
}
log.info("getPersonnelGroupingByPerson filter sql : {}",sql);
List<Map<String,Object>> dataList = DbTools.getSqlToList(sql);
for (Map<String,Object> dataMap :dataList){
String hrmId = Util.null2String(dataMap.get("id"));
String seclevel = Util.null2String(dataMap.get("seclevel"));
empIdList.add(hrmId);
}
}
}
return empIdList;
}
}