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.
tjBANK/com/customization/hrm/dept/ProxyGetOrganizationInfoCmd...

264 lines
13 KiB
Java

2 years ago
package com.customization.hrm.dept;
import com.alibaba.fastjson.JSONObject;
2 years ago
import com.api.hrm.service.HrmUserIconService;
import com.api.hrm.service.impl.HrmUserIconServiceImpl;
import com.engine.common.util.ServiceUtil;
import com.engine.hrm.cmd.emmanager.GetOrganizationInfoCmd;
import org.jsoup.helper.StringUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import org.apache.log4j.Logger;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.appdetach.AppDetachComInfo;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.job.JobTitlesComInfo;
import weaver.hrm.resource.ResourceComInfo;
@CommandDynamicProxy(target = GetOrganizationInfoCmd.class, desc = "")
2 years ago
public class ProxyGetOrganizationInfoCmd extends AbstractCommandProxy<Map<String, Object>> {
private Logger log = Logger.getLogger(this.getClass());
2 years ago
@Override
public Map<String, Object> execute(Command<Map<String, Object>> targetCommand) {
GetOrganizationInfoCmd cmd = (GetOrganizationInfoCmd) targetCommand;
// new BaseBean().writeLog("");
Map<String, Object> result = nextExecute(targetCommand);
Map<String, Object> params = cmd.getParams();
Map<String, Object> resultNew = cmd.getParams();
long startTime = System.currentTimeMillis();
// log.info("进入getOrganizationInfo方法时间===="+startTime);
log.info("params====" + JSONObject.toJSONString(params));
log.info("result====" + JSONObject.toJSONString(result));
2 years ago
String cmdType = Util.null2String(params.get("cmd"));
String fetch_mine = Util.null2String(params.get("fetch_mine"));
new BaseBean().writeLog("fetch_mine", fetch_mine);
if (cmdType.equals("getOrganizationInfo") && "0".equals(fetch_mine)) {
resultNew = this.extracted(params, result);
} else if (cmdType.equals("searchResourceList")) {
// List<Map<String, Object>> userlist = (List<Map<String, Object>>)result.get("userlist");
// if (userlist.size()>0){
// Map<String, Object> user = userlist.get(0);
// String[] strings = {"111111111"};
// user.put("deptlist",strings);
// }
resultNew = result;
} else {
2 years ago
resultNew = result;
}
log.info("resultNew====" + JSONObject.toJSONString(resultNew));
2 years ago
return resultNew;
}
private Map<String, Object> extracted(Map<String, Object> params, Map<String, Object> result) {
try {
BaseBean baseBean = new BaseBean();
Map<String, Object> resultNew = result;
String id = Util.null2String(params.get("id"));//节点id
String userid = Util.null2String(params.get("userid"));//节点id
// int userid = Util.getIntValue(Util.null2String(params.get("userid")));
User user = new User(Integer.parseInt(userid));
String type = "";//节点类型 1 com2 subcom, 3 dept
String tmpStr = id;
if (id.length() > 0) {
2 years ago
if (id.startsWith("-")) {
tmpStr = id.replace("-", "");
type = tmpStr.substring(0, 1);
id = "-" + tmpStr.substring(1, tmpStr.length());
} else {
type = tmpStr.substring(0, 1);
id = tmpStr.substring(1, tmpStr.length());
}
if (type.equals("1")) {
type = "com";
id = "0";
} else {
2 years ago
type = type.equals("2") ? "com" : "dept";
}
}
RecordSet recordSet = new RecordSet();
ArrayList<String> idlist = new ArrayList<>();
Map<String, String> bmIdHrmMap = new HashMap<>();
2 years ago
ArrayList<String> branchDeptidList = new ArrayList<>();
//查询分部下
if ("com".equals(type)) {
recordSet.executeQuery("select BM,KJRY,FB from uf_txlbxsbm where fb = ?", id);
while (recordSet.next()) {
2 years ago
String bm = Util.null2String(recordSet.getString("BM"));
String kjry = Util.null2String(recordSet.getString("KJRY"));
// String fb = Util.null2String(recordSet.getString("FB"));
idlist.add(bm);
bmIdHrmMap.put(bm, kjry);
2 years ago
}
}
//查询部门下
if ("dept".equals(type)) {
recordSet.executeQuery("select BM,KJRY,FB from uf_txlbxsbm where SJBM = ?", id);
while (recordSet.next()) {
2 years ago
String bm = Util.null2String(recordSet.getString("BM"));
String kjry = Util.null2String(recordSet.getString("KJRY"));
// String fb = Util.null2String(recordSet.getString("FB"));
idlist.add(bm);
bmIdHrmMap.put(bm, kjry);
2 years ago
}
recordSet.executeQuery("select ZBM ,kjry from uf_branchdept t1 left join uf_branchdept_dt1 d1 on t1.id = d1.mainid " +
" where t1.DEPT = ?", id);
while (recordSet.next()) {
2 years ago
String bm = Util.null2String(recordSet.getString("ZBM"));
String kjry = Util.null2String(recordSet.getString("KJRY"));
// String fb = Util.null2String(recordSet.getString("FB"));
idlist.add(bm);
bmIdHrmMap.put(bm, kjry);
2 years ago
branchDeptidList.add(bm);
}
}
List<Map<String, Object>> departmentList = (List<Map<String, Object>>) (resultNew.get("department"));
List<Map<String, Object>> departmentListNew = new ArrayList<>();
2 years ago
//过滤建模表里的部门
for (Map<String, Object> department : departmentList) {
String deptid = department.get("id").toString();
2 years ago
deptid = deptid.substring(1, deptid.length());
if (!idlist.contains(deptid)) {
2 years ago
departmentListNew.add(department);
} else {
2 years ago
String kjry = bmIdHrmMap.get(deptid);
List<String> kjrylist = Arrays.asList(kjry.split(","));
if (kjrylist.contains(userid)) {
departmentListNew.add(department);
2 years ago
}
}
}
resultNew.put("department", departmentListNew);
2 years ago
//添加明细里部门的人员
List<Map<String, Object>> userlist = (List<Map<String, Object>>) (resultNew.get("userlist"));
2 years ago
// baseBean.writeLog("人员子部门====",branchDeptidList);
for (String deptid : branchDeptidList) {
List<Map<String, Object>> resourceList = this.getResourceList(deptid, user, params);
2 years ago
// baseBean.writeLog("子部门人员列表====",resourceList);
userlist.addAll(resourceList);
}
// 使用Comparator对List中的Map进行排序
Collections.sort(userlist, Comparator.comparingDouble(m -> (Double) m.get("showorder")));
2 years ago
resultNew.put("userlist", userlist);
2 years ago
return resultNew;
} catch (Exception e) {
2 years ago
new BaseBean().writeLog(e.getMessage());
e.printStackTrace();
return result;
}
}
/***
*
* @param departmentId
* @return
*/
private List<Map<String, Object>> getResourceList(String departmentId, User user, Map<String, Object> params) {
List<Map<String, Object>> resourceList = new ArrayList<>();
Map<String, Object> resourceInfo = null;
2 years ago
RecordSet rs = new RecordSet();
String sql = "";
try {
2 years ago
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
ResourceComInfo resourceComInfo = new ResourceComInfo();
JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo();
boolean enable_main_account = "1".equals(Util.null2String(params.get("enable_main_account")).trim());
departmentComInfo.setTofirstRow();
AppDetachComInfo adci = new AppDetachComInfo(user);
sql = " select hr.id, hr.lastname, hr.sex, hr.managerid, hr.jobtitle, hr.status, hr.dsporder, hr.messagerurl, hr.pinyinlastname, hr.accounttype, hr.belongto "
+ " from hrmresource hr, hrmdepartment t2 "
+ " where hr.departmentid=t2.id and t2.id=?";
String sqlwhere = " and hr.status in (0,1,2,3)";
if (adci.isUseAppDetach()) {
String appdetawhere = adci.getScopeSqlByHrmResourceSearch(user.getUID() + "", true, "resource_hr");
String tempstr = (appdetawhere != null && !"".equals(appdetawhere) ? (" and " + appdetawhere) : "");
sqlwhere += tempstr;
2 years ago
}
if (sqlwhere.length() > 0) sql += sqlwhere;
2 years ago
sql += " order by hr.dsporder ";
rs.executeQuery(sql, departmentId);
2 years ago
while (rs.next()) {
String userid = rs.getString("id");
String lastname = Util.formatMultiLang(rs.getString("lastname"), "" + user.getLanguage());
2 years ago
String accounttype = rs.getString("accounttype");
String belongto = "1".equals(accounttype) ? Util.null2String(rs.getString("belongto")) : "";
String belongto_name = Util.formatMultiLang(resourceComInfo.getLastname(belongto), "" + user.getLanguage());
2 years ago
String pinyinlastname = Util.null2String(rs.getString("pinyinlastname"));
String sex = Util.null2String(rs.getString("sex"), "0");
2 years ago
String managerid = rs.getString("managerid");
String managername = Util.formatMultiLang(managerid.length() > 0 ? resourceComInfo.getResourcename(managerid) : "", "" + user.getLanguage());
2 years ago
String jobtitle = rs.getString("jobtitle");
String jobtitlename = Util.formatMultiLang(jobTitlesComInfo.getJobTitlesname(jobtitle), "" + user.getLanguage());
2 years ago
String status = rs.getString("status");
String showorder = Util.toDecimalDigits(rs.getString("dsporder"), 2);
2 years ago
String messagerurl = rs.getString("messagerurl");
resourceInfo = new HashMap<>();
resourceInfo.put("userid", userid);
resourceInfo.put("name", lastname);
if (enable_main_account) {
resourceInfo.put("main_base_user_id", belongto);
resourceInfo.put("main_base_user_name", belongto_name);
2 years ago
}
resourceInfo.put("manager_id", managerid);
resourceInfo.put("manager_name", managername);
resourceInfo.put("position", jobtitlename);
resourceInfo.put("status", status);
resourceInfo.put("showorder", showorder);
resourceInfo.put("gender", Util.getIntValue(sex));
resourceInfo.put("base_user_id", userid);
resourceInfo.put("base_user_name", lastname);
resourceInfo.put("name_simple_pingyin", pinyinlastname);
resourceInfo.put("name_full_pingyin", pinyinlastname);
resourceInfo.put("guangliyuanxiashu", pinyinlastname);
resourceInfo.put("base_name_simple_pingyin", pinyinlastname);
resourceInfo.put("base_name_full_pingyin", pinyinlastname);
Map<String, Object> avatar = new HashMap<>();//头像信息
params.put("userId", userid);
Map<String, Object> userIconInfo = ((HrmUserIconService) ServiceUtil.getService(HrmUserIconServiceImpl.class, user)).getUserIcon(params, user);
2 years ago
String media_id = userIconInfo.get("messagerurl").toString();
//这种格式得手机端显示不出来,取默认设置图片
if (media_id.startsWith("/weaver/weaver.file.FileDownload")) {
2 years ago
media_id = userIconInfo.get("defaultmessagerurl").toString();
} else if (messagerurl.length() > 0) {
2 years ago
String filePath = GCONST.getRootPath() + media_id;
File file = new File(filePath);
if (!file.exists()) {
2 years ago
media_id = userIconInfo.get("defaultmessagerurl").toString();
}
}
resourceInfo.put("avatar", avatar);
avatar.put("default", "");
2 years ago
avatar.put("show_name", userIconInfo.get("shortname").toString());
avatar.put("show_color", userIconInfo.get("background").toString());
avatar.put("media_id", media_id);
2 years ago
resourceList.add(resourceInfo);
}
} catch (Exception e) {
2 years ago
new BaseBean().writeLog(e);
}
// new BaseBean().writeLog("resourceList",resourceList);
return resourceList;
}
}