汇总接口开发

danikor
dxfeng 2 years ago
parent 41218ebed0
commit 8a2b024de7

@ -0,0 +1,579 @@
package com.engine.organization.manager;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.common.StringUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.appdetach.AppDetachComInfo;
import weaver.hrm.chart.domain.HrmCompanyVirtual;
import weaver.hrm.chart.domain.MOrgChart;
import weaver.hrm.common.database.dialect.DbDialectFactory;
import weaver.hrm.common.database.dialect.DialectUtil;
import weaver.hrm.common.database.dialect.constract.TableSelfRelationStyle;
import weaver.hrm.common.database.dialect.pojo.TableSelfRelationBean;
import weaver.hrm.company.OrgOperationUtil;
import weaver.systeminfo.SystemEnv;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
* @author:dxfeng
* @createTime: 2023/01/30
* @version: 1.0
*/
public class DanikorOrgChartManager {
private String sql = "";
private String status = "";
private String docStatus = "";
private String customerType = "";
private String customerStatus = "";
private String workType = "";
private String projectStatus = "";
private HttpServletRequest request = null;
private String cmd = "";
private int labelIndex = -1;
private Map params = null;
private String[] cg;
private boolean isPOrg = false;
private boolean isShow = false;
private HrmCompanyVirtual cvBean = null;
private String companyCountSql = "";
private String subCompanyCountSql = "";
private String departmentCountSql = "";
private RecordSet rs = null;
private String defaultHref = "";
private List<MOrgChart> list = null;
private User user;
private String subCompanyTabName = "";
private String departmentTableName = "";
private int shownum = 1;
OrgOperationUtil OrgOperationUtil;
AppDetachComInfo adci = null;
private Boolean useAppDetach;
private List<String> allowsubcompany = null;//能查看的分部
private List<String> allowdepartment = null;//能查看的部门
private List<String> allowsubcompanyview = null;//能查看的分部含必要的上级
private List<String> allowdepartmentview = null;//能查看的部门含必要的上级
boolean isCurrentDate = true;
String syncSearchSql = "";
public DanikorOrgChartManager() {
this.useAppDetach = Boolean.FALSE;
this.rs = new RecordSet();
this.list = new ArrayList<>();
OrgOperationUtil = new OrgOperationUtil();
}
public void init(User user, HttpServletRequest request, Map map, String cg, boolean isPOrg, HrmCompanyVirtual cvBean, Map reqeustMap) {
this.user = user;
this.request = request;
this.params = map;
this.adci = new AppDetachComInfo(user);
this.cmd = StringUtil.vString(this.request.getParameter("cmd"));
String sorgid = StringUtil.vString(this.request.getParameter("sorgid"));
String syncDate = Util.null2String(this.request.getParameter("syncDate"));
if (StringUtils.isNotBlank(syncDate) && !DateUtil.getDate(new Date()).equals(syncDate)) {
isCurrentDate = false;
syncSearchSql = " and sync_date ='" + syncDate + "'";
}
if (reqeustMap != null) {
this.cmd = reqeustMap.containsKey("cmd") ? StringUtil.vString(reqeustMap.get("cmd")) : "";
sorgid = reqeustMap.containsKey("sorgid") ? StringUtil.vString(reqeustMap.get("sorgid")) : "1";
}
this.cg = StringUtil.vString(cg).split(";");
this.isPOrg = isPOrg;
this.defaultHref = weaver.general.GCONST.getContextPath() + "/spa/hrm/index_mobx.html#/main/hrm/orgStaff?_fromURL=HrmResourceSearchResult&from=hrmorg&virtualtype=" + sorgid + "&departmentid={param}";
this.cvBean = cvBean;
checkAppInfo(user);
initParams();
initLabelIndex();
initCountSql();
this.subCompanyTabName = this.isCurrentDate ? "hrmsubcompany" : "hrmsubcompany_back";
String appointCompanySql = this.isPOrg ? "" : ("t.companyid = " + cvBean.getId() + " and ");
String supcompanyConditionSql = " and tlevel <= " + this.shownum;
boolean isMysql = false;
if (DialectUtil.isMySql(rs.getDBType())) {
isMysql = true;
}
String hasnextsql = this.getHasNextBySubCompanySql(isMysql);
this.sql = "select t.id,t.subcompanyname,t.supsubcomid,(" + this.subCompanyCountSql + (getDetachSql("").equals("") ? "" : " and " + getDetachSql("")) + syncSearchSql + ")," +
"(select COUNT(id) from " + subCompanyTabName + " where supsubcomid = t.id " + syncSearchSql + ") as supCount" +
hasnextsql + ",t.tlevel from " + subCompanyTabName + " t where " + appointCompanySql + "(t.canceled IS NULL OR t.canceled !='1') and t.id != t.supsubcomid " + (this.cg.length > 0 ? StringUtil.vString(this.cg[0]) : "") + supcompanyConditionSql + syncSearchSql + " order by t.supsubcomid,t.showorder,t.subcompanyname";
this.rs.executeSql(this.sql);
rs.writeLog("init:" + this.sql);
MOrgChart bean = null;
while (this.rs.next()) {
int subHasNext = this.rs.getInt(6);
int deptHasNext = this.rs.getInt(7);
bean = new MOrgChart();
bean.setId(this.rs.getString(1));
bean.setName(this.rs.getString(2));
bean.setSubId(this.rs.getString(3));
bean.setCount(this.rs.getInt(4));
bean.setSubCount(this.rs.getInt(5));
bean.setHasNext((subHasNext == 1) || (deptHasNext == 1));
bean.setNeedPlus((this.rs.getInt(8) == this.shownum) && ((subHasNext == 1) || (deptHasNext == 1)));
this.list.add(bean);
}
}
private String getDetachSql(String type) {
String detachSql = "";
if (useAppDetach) {
try {
detachSql = adci.getScopeSqlByHrmResourceSearch(user.getUID() + "", false, type);
} catch (Exception e) {
e.printStackTrace();
}
}
return detachSql;
}
private void checkAppInfo(User user) {
RecordSet rs = new RecordSet();
rs.executeSql("select appdetachable from SystemSet");
if (rs.next() && rs.getString("appdetachable") != null && "1".equals(rs.getString("appdetachable"))) {
useAppDetach = Boolean.TRUE;
}
}
public String getData(String pid) {
StringBuffer data = new StringBuffer("");
MOrgChart bean = null;
String cTitle = SystemEnv.getHtmlLabelNames(this.labelIndex + ",523", user.getLanguage());
String initSubSql = initSubCompanyCountSql();
String sorgid = StringUtil.vString(this.request.getParameter("sorgid"));
String tmpdefaultHref = weaver.general.GCONST.getContextPath() + "/spa/hrm/index_mobx.html#/main/hrm/orgStaff?_fromURL=HrmResourceSearchResult&from=hrmorg&virtualtype=" + sorgid + "&subcompanyid1={param}";
if (useAppDetach) {
try {
this.allowsubcompany = adci.getAlllowsubcompany();//能查看的分部
this.allowsubcompanyview = adci.getAlllowsubcompanyview();//能查看的分部含必要的上级
} catch (Exception e) {
e.printStackTrace();
}
}
rs.writeLog("getData:list" + list);
for (int i = 0; i < this.list.size(); i++) {
bean = (MOrgChart) this.list.get(i);
boolean flag = true;
if (!adci.isNotCheckUserAppDetach()) {
flag = false;
if (allowsubcompany.contains(bean.getId())) {
flag = true;
}
if (!flag && allowsubcompanyview.contains(bean.getId())) {
flag = true;
}
}
if (!flag) continue;
int showCount = bean.getCount();
String showTitle = "";
if (bean.getSubCount() != 0 && isShow) {
Map map = getAllSubCompanyId(bean.getId(), initSubSql + (getDetachSql("").equals("") ? "" : " and " + getDetachSql("")));
if (map.containsKey("idCount")) {
String idCount = StringUtil.vString(map.get("idCount"));
if (idCount.length() > 0) {
showCount = StringUtil.parseToInt(idCount, 0);
}
}
}
showTitle = bean.getName() + cTitle + showCount;
boolean hasNext = bean.isHasNext();
StringBuffer str = new StringBuffer();
str.append(",")
.append("{\"id\":\"").append(bean.getId())
.append("\", \"pid\":\"").append(bean.getSubId())
.append("\", \"type\":\"subcompany\", \"name\":\"")
.append(StringUtil.vString(StringUtil.toScreen(Util.formatMultiLang(bean.getName(), "" + user.getLanguage())), 12))
.append("\", \"title\":\"").append(bean.getName())
.append("\", \"num\":\"").append(showCount)
.append("\", \"nTitle\":\"").append(showTitle)
.append("\", \"hasChild\":\"").append("" + hasNext)
.append("\", \"needPlus\":\"").append("" + bean.isNeedPlus())
.append("\", \"cOnclick\":\"").append(StringUtil.replace(tmpdefaultHref, "{param}", bean.getId()))
.append("\", \"oDisplay\":\"none\", \"subRCount\":\"0\", \"subTitle\":\"\"}");
data.append(str);
}
data.append(appendDepartment());
return data.toString();
}
private String appendDepartment() {
this.departmentTableName = this.isCurrentDate ? "hrmdepartment" : "hrmdepartment_back";
String appendSql = this.isPOrg ? "" : ("and subcompanyid1 in (select id from hrmsubcompanyVirtual t where t.companyid = " + this.cvBean.getId() + ")");
appendSql += " and tlevel <= " + this.shownum;
String checkSupdepid = " t.id != t.supdepid ";
boolean isMysql = false;
//对于supdepid为空的情况 增加判断
if ("oracle".equalsIgnoreCase(this.rs.getDBType())) {
checkSupdepid = " t.id != nvl(t.supdepid,0) ";
} else if (DialectUtil.isMySql(rs.getDBType())) {
isMysql = true;
checkSupdepid = " t.id !=" + DbDialectFactory.get(rs.getDBType()).isNull("t.supdepid", 0);
} else {
checkSupdepid = " t.id != ISNULL(t.supdepid,0) ";
}
String hasNextSql = this.getHasNextBySubDeptSql(isMysql);
this.sql = "select t.id,t.departmentname,t.subcompanyid1," +
"(" + this.departmentCountSql + (getDetachSql("").equals("") ? "" : " and" + getDetachSql("")) + "),t.supdepid,(select COUNT(id) from " + departmentTableName + " where supdepid = t.id) as supCount," +
"(case when t.supdepid != 0 and (select COUNT(id) from " + departmentTableName + " where id = t.supdepid)=0 then 0 else 1 end) as isExist" +
hasNextSql + ",t.tlevel from " + departmentTableName + " t where " + checkSupdepid + appendSql + " and (t.canceled IS NULL OR t.canceled !='1') and (t.canceled IS NULL OR t.canceled !='1') order by t.subcompanyid1 asc , t.supdepid asc , t.showorder asc, t.departmentname asc";
this.rs.executeSql(this.sql);
rs.writeLog("appendDepartment:this.sql" + this.sql);
List<MOrgChart> dList = new ArrayList<MOrgChart>();
MOrgChart bean = null;
if (useAppDetach) {
try {
this.allowsubcompany = adci.getAlllowsubcompany();//能查看的分部
this.allowdepartment = adci.getAlllowdepartment();//能查看的部门
this.allowsubcompanyview = adci.getAlllowsubcompanyview();//能查看的分部含必要的上级
this.allowdepartmentview = adci.getAlllowdepartmentview();//能查看的部门含必要的上级
} catch (Exception e) {
e.printStackTrace();
}
}
while (this.rs.next()) {
bean = new MOrgChart();
bean.setId(this.rs.getString(1));
String id = bean.getId();
String subcompanyid1 = this.rs.getString(3);
boolean flag = true;
if (!adci.isNotCheckUserAppDetach()) {
flag = false;
if (allowdepartment.contains(id)) {
flag = true;
}
if (!flag && allowdepartmentview.contains(id)) {
flag = true;
}
if (!flag && allowsubcompany.contains(subcompanyid1)) {
flag = true;
}
}
if (!flag) continue;
bean.setName(this.rs.getString(2));
bean.setSubId((this.rs.getString(5).equals("0") || StringUtil.isNull(this.rs.getString(5))) ? this.rs.getString(3) : ("d" + this.rs.getString(5)));
bean.setCount(this.rs.getInt(4));
bean.setSubCount(this.rs.getInt(6));
bean.setHasNext(this.rs.getInt(8) == 1);
bean.setNeedPlus((this.rs.getInt(9) == this.shownum) && this.rs.getInt(8) == 1);
if (this.rs.getInt(7) == 0) {
continue;
}
dList.add(bean);
}
StringBuffer data = new StringBuffer();
String cTitle = SystemEnv.getHtmlLabelNames("21837," + (this.labelIndex == 179 ? 1867 : this.labelIndex), user.getLanguage());
String sTitle = SystemEnv.getHtmlLabelNames("33864,17587," + (this.labelIndex == 179 ? 1867 : this.labelIndex), user.getLanguage());
String initSubSql = initSubDepartmentCountSql();
for (MOrgChart m : dList) {
String showTitle = "";
String allSubId = "";
boolean isShowSubCount = false;
int subRCount = m.getCount();
showTitle = cTitle + m.getCount();
if (m.getSubCount() != 0 && isShow) {
Map map = getAllSubDepartId(m.getId(), initSubSql + (getDetachSql("").equals("") ? "" : " and " + getDetachSql("")));
if (map.containsKey("idCount") && map.containsKey("ids")) {
String idCount = StringUtil.vString(map.get("idCount"));
allSubId = StringUtil.vString(map.get("ids"));
isShowSubCount = allSubId.length() > 0;
if (idCount.length() > 0) {
subRCount = StringUtil.parseToInt(idCount, 0);
}
}
}
String subTitle = sTitle + subRCount;
boolean hasNext = m.isHasNext();
StringBuffer str = new StringBuffer();
str.append(",")
.append("{\"id\":\"d").append(m.getId())
.append("\", \"pid\":\"").append(m.getSubId())
.append("\", \"type\":\"dept\", \"name\":\"")
.append(StringUtil.vString(StringUtil.toScreen(Util.formatMultiLang(m.getName(), "" + user.getLanguage())), 12))
.append("\", \"title\":\"").append(m.getName())
.append("\", \"num\":\"").append(m.getCount())
.append("\", \"nTitle\":\"").append(showTitle)
.append("\", \"oDisplay\":\"").append(isShowSubCount ? "" : "none")
.append("\", \"subRCount\":\"").append(subRCount)
.append("\", \"subTitle\":\"").append(subTitle)
.append("\", \"hasChild\":\"").append("" + hasNext)
.append("\", \"needPlus\":\"").append("" + m.isNeedPlus())
.append("\", \"cOnclick\":\"").append(StringUtil.replace(this.defaultHref, "{param}", m.getId()))
.append("\", \"sOnclick\":\"").append(isShowSubCount ? StringUtil.replace(this.defaultHref, "{param}", m.getId() + "," + allSubId) : "").append("\"}");
// .append("\"}");
data.append(str.toString());
}
return data.toString();
}
/**
*
*
* @param isMysql
* @return
*/
private String getHasNextBySubCompanySql(boolean isMysql) {
this.subCompanyTabName = this.isCurrentDate ? "hrmsubcompany" : "hrmsubcompany_back";
;
this.departmentTableName = this.isCurrentDate ? "HrmDepartment" : "HrmDepartment_back";
String subsql = ",(select distinct 1 as hasnext from " + subCompanyTabName + " s where (s.supsubcomid=t.id and (s.CANCELED IS NULL OR s.CANCELED !='1')) ) as hassubnext";
String deptsql = ",(select distinct 1 as hasnext from " + departmentTableName + " d where (d.subcompanyid1=t.id and (d.CANCELED IS NULL OR d.CANCELED !='1')) ) as hasdeptnext";
if (isMysql) {
//8.0版本的mysql distinct 1 的时候会出现多条数据
subsql = ",(select distinct if(s.supsubcomid is null,null,1) as hasnext from " + subCompanyTabName + " s where (s.supsubcomid=t.id and (s.CANCELED IS NULL OR s.CANCELED !='1')) ) as hassubnext";
deptsql = ",(select distinct if(d.subcompanyid1 is null,null,1) as hasnext from " + departmentTableName + " d where (d.subcompanyid1=t.id and (d.CANCELED IS NULL OR d.CANCELED !='1')) ) as hasdeptnext";
}
return subsql + deptsql;
}
/**
*
*
* @param isMysql
* @return
*/
private String getHasNextBySubDeptSql(boolean isMysql) {
this.departmentTableName = this.isPOrg ? "HrmDepartment" : "HrmDepartmentVirtual";
String sql = ",(select distinct 1 as hasnext from " + departmentTableName + " d where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')) as hasnext";
if (isMysql) {
//8.0版本的mysql distinct 1 的时候会出现多条数据
sql = ",(select distinct if(d.supdepid is null,null,1) as hasnext from " + departmentTableName + " d where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')) as hasnext";
}
return sql;
}
private Map getAllSubCompanyId(String arg0, String arg1) {
return getSubId(arg0, this.subCompanyTabName, "SUPSUBCOMID", arg1);
}
private Map getAllSubDepartId(String arg0, String arg1) {
return getSubId(arg0, this.departmentTableName, "SUPDEPID", arg1);
}
private Map getSubId(String arg0, String arg1, String arg2, String arg4) {
StringBuffer arg5 = new StringBuffer("SELECT a.ID FROM allSub a LEFT JOIN ")
.append(arg1).append(" b ON a.ID = b.ID WHERE (b.CANCELED IS NULL OR b.CANCELED !='1')");
StringBuffer ids = new StringBuffer();
StringBuffer sql = new StringBuffer();
if ("oracle".equals(rs.getDBType())) {
sql.append(" WITH allSub AS ( SELECT ID FROM ");
sql.append(arg1).append(" start with id=").append(arg0).append(" connect by PRIOR id=").append(arg2);
sql.append(")");
} else if (DialectUtil.isMySql(rs.getDBType())) {
TableSelfRelationBean bean = new TableSelfRelationBean(TableSelfRelationStyle.findByTableName(arg1.trim()));
bean.setLastSqlWhere(" and (CANCELED IS NULL OR CANCELED !='1') ");
bean.setOutFiled("id");
arg5 = new StringBuffer(arg5.toString().replace("allSub", "( " + DbDialectFactory.get(rs.getDBType()).getSelfRelactionSql(bean, arg0) + " )"));
} else if ("postgresql".equals(rs.getDBType())) {
sql.append(" WITH RECURSIVE allSub AS ( SELECT ID FROM ");
sql.append(arg1).append(" WHERE ID = ").append(arg0).append(" UNION ALL SELECT a.ID FROM ").append(arg1)
.append(" a, allSub b WHERE a.").append(arg2).append("= b.ID ");
sql.append(")");
} else {
sql.append(" WITH allSub AS ( SELECT ID FROM ");
sql.append(arg1).append(" WHERE ID = ").append(arg0).append(" UNION ALL SELECT a.ID FROM ").append(arg1)
.append(" a, allSub b WHERE a.").append(arg2).append("= b.ID ");
sql.append(")");
}
sql.append("select a.idCount,b.id from (").append(StringUtil.replace(arg4, "{ids}", arg5.toString())).append(") a, (").append(arg5.toString()).append(") b ");
Map<String, String> map = new HashMap<String, String>();
RecordSet rs = new RecordSet();
rs.executeSql(sql.toString());
String idCount = "";
while (rs.next()) {
if (idCount.length() == 0) idCount = StringUtil.vString(rs.getString(1));
ids.append(StringUtil.isNull(ids.toString()) ? "" : ",").append(StringUtil.vString(rs.getString(2)));
}
map.put("idCount", idCount);
map.put("ids", ids.toString());
return map;
}
private void initParams() {
if (this.params == null || this.params.isEmpty()) {
return;
}
if (StringUtil.isNull(this.cmd)) {
this.status = StringUtil.vString(params.get("status"));
this.status = (StringUtil.isNull(status) || status.equals("8")) ? "0,1,2,3" : status;
this.status = this.status.equals("9") ? "" : (" and status in (" + this.status + ") ");
} else if (this.cmd.equals("doc")) {
this.docStatus = StringUtil.vString(params.get("docStatus"));
this.docStatus = StringUtil.isNull(this.docStatus) ? "" : (" and docstatus = " + this.docStatus);
} else if (this.cmd.equals("customer")) {
this.customerType = StringUtil.vString(params.get("customerType"));
this.customerType = StringUtil.isNull(customerType) ? "" : (" and type = " + this.customerType);
this.customerStatus = StringUtil.vString(params.get("customerStatus"));
this.customerStatus = StringUtil.isNull(customerStatus) ? "" : (" and status = " + this.customerStatus);
} else if (this.cmd.equals("project")) {
this.workType = StringUtil.vString(params.get("workType"));
this.workType = StringUtil.isNull(workType) ? "" : (" and worktype = " + this.workType);
this.projectStatus = StringUtil.vString(params.get("projectStatus"));
this.projectStatus = StringUtil.isNull(projectStatus) ? "" : (" and status = " + this.projectStatus);
}
}
private void initLabelIndex() {
if (StringUtil.isNull(this.cmd)) {
this.labelIndex = 179;
} else if (this.cmd.equals("doc")) {
this.labelIndex = 58;
} else if (this.cmd.equals("customer")) {
this.labelIndex = 136;
} else if (this.cmd.equals("project")) {
this.labelIndex = 101;
}
isShow = this.cg.length >= 3 ? "P".equalsIgnoreCase(this.cg[2]) : false;
}
public int getLabelIndex() {
return this.labelIndex;
}
private void initCountSql() {
String asNamefora = useAppDetach ? "hrmresource" : "a";
String asNameforb = useAppDetach ? "hrmresource" : "b";
String asNameforc = useAppDetach ? "hrmresource" : "c";
if (this.isPOrg) {
if (StringUtil.isNull(this.cmd)) {
this.companyCountSql = "select COUNT(id) from HrmResource where 1=1 " + this.status;
this.subCompanyCountSql = "select COUNT(" + asNamefora + ".id) from HrmResource " + asNamefora + " right join HrmDepartment b on " + asNamefora + ".departmentid = b.id where " + asNamefora + ".subcompanyid1=t.id and (b.canceled IS NULL OR b.canceled !='1') " + this.status;
this.departmentCountSql = "select COUNT(id) from HrmResource where departmentid=t.id " + this.status;
} else if (this.cmd.equals("doc")) {
this.companyCountSql = "select COUNT(id) from DocDetail where (maincategory >= 1 or maincategory <= -1) and (subcategory >= 1 or subcategory <= -1) and (seccategory >= 1 or seccategory <= -1) " + this.docStatus;
this.subCompanyCountSql = "select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResource where subcompanyid1 = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus;
this.departmentCountSql = "select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResource where departmentid = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus;
} else if (this.cmd.equals("customer")) {
this.companyCountSql = "select COUNT(id) from CRM_CustomerInfo where (deleted is null or deleted!=1) " + this.customerType + this.customerStatus;
this.subCompanyCountSql = "select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResource where subcompanyid1 = t.id) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus;
this.departmentCountSql = "select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResource where departmentid = t.id) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus;
} else if (this.cmd.equals("project")) {
this.companyCountSql = "select COUNT(id) from Prj_ProjectInfo where 1=1 " + this.workType + this.projectStatus;
this.subCompanyCountSql = "select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResource where subcompanyid1 = t.id) " + this.workType + this.projectStatus;
this.departmentCountSql = "select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResource where departmentid = t.id) " + this.workType + this.projectStatus;
}
} else {
if (StringUtil.isNull(this.cmd)) {
this.companyCountSql = "select COUNT(a.id) from HrmResourceVirtual a right join HrmResource " + asNameforb + " on a.resourceid = " + asNameforb + ".id where a.subcompanyid in ( select id from hrmsubcompanyVirtual where companyid = " + this.cvBean.getId() + " ) " + this.status;
this.subCompanyCountSql = "select COUNT(a.id) from HrmResourceVirtual a right join HrmDepartmentVirtual b on a.departmentid = b.id right join HrmResource " + asNameforc + " on a.resourceid = " + asNameforc + ".id where a.subcompanyid = t.id and (b.canceled IS NULL OR b.canceled !='1') " + this.status;
this.departmentCountSql = "select COUNT(a.id) from HrmResourceVirtual a right join HrmResource " + asNameforc + " on a.resourceid = " + asNameforc + ".id where a.departmentid=t.id " + this.status;
} else if (this.cmd.equals("doc")) {
this.companyCountSql = "select COUNT(id) from DocDetail where ownerid in (select resourceid from HrmResourceVirtual where subcompanyid in (select id from hrmsubcompanyVirtual where companyid = " + this.cvBean.getId() + ")) and (maincategory >= 1 or maincategory <= -1) and (subcategory >= 1 or subcategory <= -1) and (seccategory >= 1 or seccategory <= -1) " + this.docStatus;
this.subCompanyCountSql = "select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResourceVirtual where subcompanyid = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus;
this.departmentCountSql = "select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResourceVirtual where departmentid = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus;
} else if (this.cmd.equals("customer")) {
this.companyCountSql = "select COUNT(id) from CRM_CustomerInfo where (deleted is null or deleted!=1) and manager in (select resourceid from HrmResourceVirtual where subcompanyid in (select id from hrmsubcompanyVirtual where companyid = " + this.cvBean.getId() + ")) " + this.customerType + this.customerStatus;
this.subCompanyCountSql = "select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResourceVirtual where subcompanyid = t.id) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus;
this.departmentCountSql = "select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResourceVirtual where departmentid = t.id) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus;
} else if (this.cmd.equals("project")) {
this.companyCountSql = "select COUNT(id) from Prj_ProjectInfo where manager in (select resourceid from HrmResourceVirtual where subcompanyid in (select id from hrmsubcompanyVirtual where companyid = " + this.cvBean.getId() + ")) " + this.workType + this.projectStatus;
this.subCompanyCountSql = "select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResourceVirtual where subcompanyid = t.id) " + this.workType + this.projectStatus;
this.departmentCountSql = "select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResourceVirtual where departmentid = t.id) " + this.workType + this.projectStatus;
}
}
}
private String initSubDepartmentCountSql() {
String sql = "";
String asNameforb = useAppDetach ? "hrmresource" : "b";
String asNameforc = useAppDetach ? "hrmresource" : "c";
if (this.isPOrg) {
if (StringUtil.isNull(this.cmd)) {
sql = ("select COUNT(id)as idCount from HrmResource where departmentid in ({ids}) " + this.status);
} else if (this.cmd.equals("doc")) {
sql = ("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select id from HrmResource where departmentid in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus);
} else if (this.cmd.equals("customer")) {
sql = ("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select id from HrmResource where departmentid in ({ids})) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus);
} else if (this.cmd.equals("project")) {
sql = ("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select id from HrmResource where departmentid in ({ids})) " + this.workType + this.projectStatus);
}
} else {
if (StringUtil.isNull(this.cmd)) {
sql = ("select COUNT(a.id)as idCount from HrmResourceVirtual a right join HrmResource " + asNameforc + " on a.resourceid = " + asNameforc + ".id where a.departmentid in ({ids}) " + this.status);
} else if (this.cmd.equals("doc")) {
sql = ("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.departmentid in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus);
} else if (this.cmd.equals("customer")) {
sql = ("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.departmentid in ({ids})) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus);
} else if (this.cmd.equals("project")) {
sql = ("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.departmentid in ({ids})) " + this.workType + this.projectStatus);
}
}
return sql;
}
private String initSubCompanyCountSql() {
String sql = "";
String asNameforb = useAppDetach ? "hrmresource" : "b";
String asNameforc = useAppDetach ? "hrmresource" : "c";
if (this.isPOrg) {
if (StringUtil.isNull(this.cmd)) {
sql = ("select COUNT(id) as idCount from HrmResource where subcompanyid1 in ({ids}) " + this.status);
} else if (this.cmd.equals("doc")) {
sql = ("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select id from HrmResource where subcompanyid1 in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus);
} else if (this.cmd.equals("customer")) {
sql = ("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select id from HrmResource where subcompanyid1 in ({ids})) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus);
} else if (this.cmd.equals("project")) {
sql = ("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select id from HrmResource where subcompanyid1 in ({ids})) " + this.workType + this.projectStatus);
}
} else {
if (StringUtil.isNull(this.cmd)) {
sql = ("select COUNT(a.id)as idCount from HrmResourceVirtual a right join HrmResource " + asNameforc + " on a.resourceid = " + asNameforc + ".id where a.subcompanyid in ({ids}) " + this.status);
} else if (this.cmd.equals("doc")) {
sql = ("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.subcompanyid in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) " + this.docStatus);
} else if (this.cmd.equals("customer")) {
sql = ("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.subcompanyid in ({ids})) and (deleted is null or deleted!=1) " + this.customerType + this.customerStatus);
} else if (this.cmd.equals("project")) {
sql = ("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.subcompanyid in ({ids})) " + this.workType + this.projectStatus);
}
}
return sql;
}
public int getCompanyResourceCount() {
this.rs.executeSql(this.companyCountSql + ((getDetachSql("").equals("")) ? " and 1=1" : (" and " + getDetachSql(""))));
return this.rs.next() ? this.rs.getInt(1) : 0;
}
public int getShownum() {
shownum = shownum <= 0 ? 1 : shownum;
return shownum;
}
public void setShownum(int shownum) {
this.shownum = shownum;
}
public boolean isPOrg() {
return isPOrg;
}
public void setPOrg(boolean isPOrg) {
this.isPOrg = isPOrg;
}
}

@ -2,6 +2,7 @@ package com.engine.organization.service;
import com.engine.organization.util.MenuBtn; import com.engine.organization.util.MenuBtn;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -41,4 +42,10 @@ public interface DanikorResourceBackService {
* @return * @return
*/ */
Map<String, Object> getSummaryData(Map<String, Object> params); Map<String, Object> getSummaryData(Map<String, Object> params);
/**
* @param params
* @return
*/
String getOrgChartData(HttpServletRequest request, Map<String, Object> params);
} }

@ -11,6 +11,7 @@ import com.engine.core.impl.Service;
import com.engine.organization.component.OrganizationWeaTable; import com.engine.organization.component.OrganizationWeaTable;
import com.engine.organization.entity.column.TableColumnPO; import com.engine.organization.entity.column.TableColumnPO;
import com.engine.organization.entity.danikor.vo.ResourceBackVO; import com.engine.organization.entity.danikor.vo.ResourceBackVO;
import com.engine.organization.manager.DanikorOrgChartManager;
import com.engine.organization.mapper.danikor.DanikorResourceMapper; import com.engine.organization.mapper.danikor.DanikorResourceMapper;
import com.engine.organization.mapper.resource.HrmResourceMapper; import com.engine.organization.mapper.resource.HrmResourceMapper;
import com.engine.organization.service.DanikorResourceBackService; import com.engine.organization.service.DanikorResourceBackService;
@ -19,8 +20,18 @@ import com.engine.organization.util.OrganizationFormItemUtil;
import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.db.MapperProxyFactory;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil; import weaver.common.DateUtil;
import weaver.common.StringUtil;
import weaver.general.Util; import weaver.general.Util;
import weaver.hrm.appdetach.AppDetachComInfo;
import weaver.hrm.chart.domain.HrmChartSet;
import weaver.hrm.chart.domain.HrmCompanyVirtual;
import weaver.hrm.chart.manager.HrmChartSetManager;
import weaver.hrm.chart.manager.HrmCompanyVirtualManager;
import weaver.hrm.company.CompanyComInfo;
import weaver.hrm.companyvirtual.CompanyVirtualComInfo;
import weaver.systeminfo.SystemEnv;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
@ -150,4 +161,82 @@ public class DanikorResourceBackServiceImpl extends Service implements DanikorRe
returnMap.put("person", getDanikorResourceMapper().summaryResourceData(resourceTable, syncDate)); returnMap.put("person", getDanikorResourceMapper().summaryResourceData(resourceTable, syncDate));
return returnMap; return returnMap;
} }
@Override
public String getOrgChartData(HttpServletRequest request, Map<String, Object> params) {
CompanyVirtualComInfo CompanyVirtualComInfo = new CompanyVirtualComInfo();
CompanyComInfo CompanyComInfo = new CompanyComInfo();
AppDetachComInfo AppDetachComInfo = new AppDetachComInfo();
boolean isOutCustomer = AppDetachComInfo.isOutCustomer("" + user.getUID());//是否为外部用户
String sorgid = Util.null2String((params.get("arg0")));
int shownum = StringUtil.parseToInt(Util.null2String(params.get("arg1")), 1);
String showName = Util.null2String(params.get("arg2"));
int showtype = Util.getIntValue(Util.null2String(params.get("showtype")), 0);
Map beanMap = new HashMap();
HrmChartSetManager HrmChartSetManager = new HrmChartSetManager();
beanMap.put("is_sys", 1);
HrmChartSet bean = HrmChartSetManager.get(beanMap);
if (bean != null) {
showtype = bean.getShowType();
shownum = bean.getShowNum();
}
shownum = shownum <= 0 ? 1 : shownum;
if (0 == showtype) shownum = 10000;
if (CompanyComInfo.next()) {
showName = CompanyComInfo.getCompanyname();
}
if (isOutCustomer) {
sorgid = "-10000";
showName = CompanyVirtualComInfo.getVirtualType(sorgid);
}
boolean isPOrg = Boolean.parseBoolean(Util.null2s(Util.null2String(params.get("arg3")), "true"));
String arg4 = Util.null2s(Util.null2String(params.get("arg4")), "8");
String arg5 = Util.null2String(params.get("arg5"));
String arg6 = Util.null2String(params.get("arg6"));
String arg7 = Util.null2String(params.get("arg7"));
String arg8 = Util.null2String(params.get("arg8"));
String arg9 = Util.null2String(params.get("arg9"));
String arg10 = Util.null2String(params.get("arg10"));
String arg11 = Util.null2s(Util.null2String(params.get("arg11")), ";;P");
HrmCompanyVirtualManager manager = new HrmCompanyVirtualManager();
HrmCompanyVirtual cvBean = null;
if (!isPOrg) {
cvBean = manager.get(sorgid);
showName = cvBean != null ? cvBean.getVirtualtype() : "";
}
//初始化tlevel
new com.api.hrm.util.ServiceUtil().initOrgLevel();
Map<String, String> map = new HashMap<String, String>();
map.put("status", arg4);
map.put("docStatus", arg5);
map.put("customerType", arg6);
map.put("customerStatus", arg7);
map.put("workType", arg8);
map.put("projectStatus", arg9);
Map<String, String> requestMap = new HashMap<String, String>();
requestMap.put("cmd", arg10);
requestMap.put("sorgid", sorgid);
showName = StringUtil.vString(StringUtil.toScreen(Util.formatMultiLang(showName, "" + user.getLanguage())));
DanikorOrgChartManager chartManager = new DanikorOrgChartManager();
chartManager.setShownum(shownum);
chartManager.init(user, request, map, arg11, isPOrg, cvBean, requestMap);
String showCount = String.valueOf(chartManager.getCompanyResourceCount());
String showTitle = showName + SystemEnv.getHtmlLabelNames(chartManager.getLabelIndex() + ",523", user.getLanguage()) + showCount;
String defaultHref = weaver.general.GCONST.getContextPath() + "/spa/hrm/index_mobx.html#/main/hrm/orgStaff?_fromURL=HrmResourceSearchResult&from=hrmorg&virtualtype=" + sorgid;
StringBuffer data = new StringBuffer("[");
data.append("{\"id\":\"0\", \"pid\":\"\", \"type\":\"company\", \"name\":\"").append(StringUtil.vString(showName, 12)).append("\", \"title\":\"").append(showName).append("\", \"num\":\"" + showCount + "\", \"nTitle\":\"" + showTitle + "\", \"oDisplay\":\"none\", \"subRCount\":\"0\", \"subTitle\":\"\", \"cOnclick\":\"" + defaultHref + "\", \"sOnclick\":\"\"}").append(chartManager.getData("0"));
data.append("]");
return data.toString();
}
} }

@ -83,4 +83,17 @@ public class DanikorResourceBackController {
return ReturnResult.exceptionHandle(e); return ReturnResult.exceptionHandle(e);
} }
} }
@GET
@Path("/getOrgChartData")
@Produces(MediaType.APPLICATION_JSON)
public ReturnResult getOrgChartData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> map = ParamUtil.request2Map(request);
return ReturnResult.successed(getDanikorResourceBackWrapper(user).getOrgChartData(request, map));
} catch (Exception e) {
return ReturnResult.exceptionHandle(e);
}
}
} }

@ -7,6 +7,7 @@ import com.engine.organization.util.MenuBtn;
import com.engine.organization.util.OrganizationWrapper; import com.engine.organization.util.OrganizationWrapper;
import weaver.hrm.User; import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -36,4 +37,8 @@ public class DanikorResourceBackWrapper extends OrganizationWrapper {
public Map<String, Object> getSummaryData(Map<String, Object> params) { public Map<String, Object> getSummaryData(Map<String, Object> params) {
return getDanikorResourceBackService(user).getSummaryData(params); return getDanikorResourceBackService(user).getSummaryData(params);
} }
public String getOrgChartData(HttpServletRequest request, Map<String, Object> params) {
return getDanikorResourceBackService(user).getOrgChartData(request, params);
}
} }

Loading…
Cancel
Save