246 lines
10 KiB
Java
246 lines
10 KiB
Java
package com.engine.hrm.cmd.organization;
|
||
|
||
import com.api.hrm.util.ServiceUtil;
|
||
import com.engine.common.biz.AbstractCommonCommand;
|
||
import com.engine.common.biz.SimpleBizLogger;
|
||
import com.engine.common.constant.BizLogOperateAuditType;
|
||
import com.engine.common.constant.BizLogSmallType4Hrm;
|
||
import com.engine.common.constant.BizLogType;
|
||
import com.engine.common.constant.ParamConstant;
|
||
import com.engine.common.entity.BizLogContext;
|
||
import com.engine.common.service.ThemeService;
|
||
import com.engine.common.service.impl.ThemeServiceImpl;
|
||
import com.engine.core.interceptor.CommandContext;
|
||
import com.engine.hrm.cmd.matrix.biz.MatrixMaintComInfo;
|
||
import com.engine.hrm.entity.RuleCodeType;
|
||
import com.engine.hrm.util.CodeRuleManager;
|
||
import com.engine.hrm.util.HrmOrganizationUtil;
|
||
import com.engine.hrm.util.face.HrmFaceCheckManager;
|
||
import com.lingyue.util.KqUtil;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import weaver.conn.RecordSet;
|
||
import weaver.general.Util;
|
||
import weaver.hrm.HrmUserVarify;
|
||
import weaver.hrm.User;
|
||
import weaver.hrm.common.DbFunctionUtil;
|
||
import weaver.hrm.company.SubCompanyComInfo;
|
||
import weaver.hrm.definedfield.HrmDeptFieldManagerE9;
|
||
import weaver.interfaces.email.CoreMailAPI;
|
||
import weaver.interfaces.hrm.HrmServiceManager;
|
||
import weaver.matrix.MatrixUtil;
|
||
import weaver.rtx.OrganisationCom;
|
||
import weaver.rtx.OrganisationComRunnable;
|
||
import weaver.systeminfo.SystemEnv;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
public class AddSubCompanyCmd extends AbstractCommonCommand<Map<String, Object>> {
|
||
private SimpleBizLogger logger;
|
||
|
||
public AddSubCompanyCmd(Map<String, Object> params, User user) {
|
||
this.user = user;
|
||
this.params = params;
|
||
|
||
String subcompanyname = Util.fromScreen((String) params.get("subcompanyname"), user.getLanguage());
|
||
|
||
this.logger = new SimpleBizLogger();
|
||
BizLogContext bizLogContext = new BizLogContext();
|
||
bizLogContext.setLogType(BizLogType.HRM_ENGINE);//模块类型
|
||
bizLogContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_ORGANIZATION);
|
||
bizLogContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_ORGANIZATION_SUBCOMPANY);//当前小类型
|
||
bizLogContext.setOperateAuditType(BizLogOperateAuditType.WARNING);//警告
|
||
bizLogContext.setParams(params);//当前request请求参数
|
||
logger.setUser(user);//当前操作人
|
||
String mainSql = "select * from HrmSubCompany where 1=2 ";
|
||
logger.setMainSql(mainSql, "id");//主表sql
|
||
logger.setMainPrimarykey("id");//主日志表唯一key
|
||
logger.setMainTargetNameColumn("subcompanyname");//当前targetName对应的列(对应日志中的对象名)
|
||
logger.before(bizLogContext);
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> execute(CommandContext commandContext) {
|
||
Map<String, Object> retmap = new HashMap<String, Object>();
|
||
try {
|
||
String sql = "";
|
||
RecordSet rs = null;
|
||
|
||
if (!HrmUserVarify.checkUserRight("HrmSubCompanyEdit:Edit", user)) {
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
|
||
return retmap;
|
||
}
|
||
|
||
SubCompanyComInfo SubCompanyComInfo = new SubCompanyComInfo();
|
||
//OrganisationCom OrganisationCom = new OrganisationCom();
|
||
HrmServiceManager HrmServiceManager = new HrmServiceManager();
|
||
|
||
int companyid = 1;
|
||
int supsubcomid = Util.getIntValue((String) params.get("supsubcomid"), 0);
|
||
String subcompanycode = Util.fromScreen((String) params.get("subcompanycode"), user.getLanguage());
|
||
String subcompanyname = Util.fromScreen((String) params.get("subcompanyname"), user.getLanguage());
|
||
String subcompanydesc = Util.fromScreen((String) params.get("subcompanydesc"), user.getLanguage());
|
||
String url = Util.null2String((String) params.get("url"));
|
||
float showorder = Util.getFloatValue((String) params.get("showorder"), 0.00f);
|
||
int limitUsers = Util.getIntValue(Util.fromScreen((String) params.get("limitUsers"), user.getLanguage()), 0);
|
||
limitUsers = limitUsers < 0 ? 0 : limitUsers;
|
||
|
||
if (supsubcomid > 0) {
|
||
Map<String, String> supMap = new HashMap<String, String>();
|
||
supMap.put(""+supsubcomid, "1");
|
||
int supsubcomidtemp = Util.getIntValue(SubCompanyComInfo.getSupsubcomid(""+supsubcomid), 0);
|
||
while(supsubcomidtemp>0){
|
||
if(supMap.get(""+supsubcomidtemp)==null){
|
||
supMap.put(""+supsubcomidtemp, "1");
|
||
supsubcomidtemp = Util.getIntValue(SubCompanyComInfo.getSupsubcomid(""+supsubcomidtemp), 0);
|
||
}else{
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(382649,user.getLanguage()));
|
||
return retmap;
|
||
}
|
||
}
|
||
if (HrmOrganizationUtil.ifSubComLevelEquals10(supsubcomid)) {
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(382649, user.getLanguage()));
|
||
return retmap;
|
||
}
|
||
}
|
||
|
||
// 如果编码为空 自动生成编码
|
||
subcompanycode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, subcompanycode);
|
||
|
||
if (!"".equals(subcompanycode)) {
|
||
sql = "select id from HrmSubCompany where subcompanycode = '" + subcompanycode + "'";
|
||
rs = new RecordSet();
|
||
rs.executeSql(sql);
|
||
if (rs.next()) {
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(382651, user.getLanguage()));
|
||
return retmap;
|
||
}
|
||
}
|
||
|
||
char separator = Util.getSeparator();
|
||
String para = subcompanyname + separator + subcompanydesc + separator + companyid + separator + supsubcomid + separator + url + separator + showorder;
|
||
rs = new RecordSet();
|
||
rs.executeProc("HrmSubCompany_Insert", para);
|
||
int flag = rs.getFlag();
|
||
int id = 0;
|
||
if (rs.next()) {
|
||
id = rs.getInt(1);
|
||
}
|
||
|
||
if (flag == 2) {
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(382654, user.getLanguage()));
|
||
return retmap;
|
||
}
|
||
if (flag == 3) {
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(382656, user.getLanguage()));
|
||
return retmap;
|
||
}
|
||
|
||
sql = "update HrmSubCompany set subcompanycode = '" + subcompanycode + "'";
|
||
if (user.getUID() == 1){
|
||
sql += ", limitUsers = " + limitUsers;
|
||
}
|
||
sql += ","+ DbFunctionUtil.getInsertUpdateSetSql(rs.getDBType(),user.getUID()) ;
|
||
sql += " where id = " + id;
|
||
rs.executeSql(sql);
|
||
|
||
HrmDeptFieldManagerE9 hrmDeptFieldManager = new HrmDeptFieldManagerE9(4);
|
||
hrmDeptFieldManager.editCustomData(params,id);
|
||
|
||
|
||
|
||
// 更新机构权限数据:新增加的分部默认继承上级分部的所有机构权限。
|
||
para = String.valueOf(id) + separator + String.valueOf(supsubcomid);
|
||
rs = new RecordSet();
|
||
rs.executeProc("HrmRoleSRT_AddByNewSc", para);
|
||
|
||
//新增分部,統一调用门户接口创建门户菜单
|
||
ThemeService themService = new ThemeServiceImpl();
|
||
themService.createSubCompanyMenu(id,supsubcomid);
|
||
// // 更新左侧菜单,新增的分部继承上级分部的左侧菜单
|
||
// String strWhere = " where resourcetype=2 and resourceid=" + supsubcomid;
|
||
// if (supsubcomid == 0)
|
||
// strWhere = " where resourcetype=1 and resourceid=1 ";
|
||
// String strSql = "insert into leftmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + id + ",2,locked,lockedbyid,usecustomname,customname,customname_e from leftmenuconfig " + strWhere;
|
||
// rs = new RecordSet();
|
||
// rs.executeSql(strSql);
|
||
//
|
||
// // 更新顶部菜单,新增的分部继承上级分部的顶部菜单
|
||
// strWhere = " where resourcetype=2 and resourceid=" + supsubcomid;
|
||
// if (supsubcomid == 0)
|
||
// strWhere = " where resourcetype=1 and resourceid=1 ";
|
||
// strSql = "insert into mainmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + id + ",2,locked,lockedbyid,usecustomname,customname,customname_e from mainmenuconfig " + strWhere;
|
||
// rs = new RecordSet();
|
||
// rs.executeSql(strSql);
|
||
|
||
SubCompanyComInfo.removeCompanyCache();
|
||
|
||
rs = new RecordSet();
|
||
rs.executeSql("update orgchartstate set needupdate=1");
|
||
weaver.hrm.company.OrgOperationUtil OrgOperationUtil = new weaver.hrm.company.OrgOperationUtil();
|
||
OrgOperationUtil.updateSubcompanyLevel("" + id, "0");
|
||
//OrganisationCom.addSubCompany(id);//执行速度过慢,改成另起现成执行
|
||
new Thread(new OrganisationComRunnable("subcompany", "add", String.valueOf(id))).start();
|
||
|
||
// 同步到CoreMail邮件系统开始
|
||
if (supsubcomid > 0) {
|
||
CoreMailAPI.synOrg("com_" + id, subcompanyname, "parent_org_unit_id=com_" + supsubcomid + "&org_unit_name=" + subcompanyname, "0");
|
||
// testapi.synOrg("com_"+id, subcompanyname, "com_"+supsubcomid, "0");
|
||
} else {
|
||
CoreMailAPI.synOrg("com_" + id, subcompanyname, "org_unit_name=" + subcompanyname, "0");
|
||
// testapi.synOrg("com_"+id, subcompanyname, "", "0");
|
||
}
|
||
// 同步到CoreMail邮件系统结束
|
||
|
||
// OA与第三方接口单条数据同步方法开始
|
||
HrmServiceManager.SynInstantSubCompany("" + id, "1");
|
||
// OA与第三方接口单条数据同步方法结束
|
||
|
||
HrmFaceCheckManager.sync(id+"",HrmFaceCheckManager.getOptInsert(),"HRM_AddSubCompanyCmd",HrmFaceCheckManager.getOaSubcompany());
|
||
|
||
// 同步分部数据到矩阵
|
||
MatrixUtil.updateSubcompayData("" + id);
|
||
//同步矩阵维护范围
|
||
MatrixMaintComInfo maintComInfo = new MatrixMaintComInfo();
|
||
maintComInfo.removeCache();
|
||
// 初始化应用分权
|
||
new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData();
|
||
|
||
// 同步分部数据到中控考勤机
|
||
KqUtil.synAddOrUpdateSubComInfo(""+id);
|
||
|
||
String mainSql = "select a.* from HrmSubCompany a left join hrmsubcompanydefined b on a.id=b.subcomid where a.id in(" + id + ") ";
|
||
String tableColumns = new ServiceUtil().getTableColumns("select * from hrmsubcompanydefined", "b", "id");
|
||
if (!tableColumns.equals("")) {
|
||
mainSql = "select a.*," + tableColumns + " from HrmSubCompany a left join hrmsubcompanydefined b on a.id=b.subcomid where a.id in(" + id + ") ";
|
||
}
|
||
logger.setMainSql(mainSql, "id");//主表sql
|
||
retmap.put("id", id);
|
||
retmap.put("status", "1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage()));
|
||
} catch (Exception e) {
|
||
retmap.put("status", "-1");
|
||
retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
|
||
writeLog(e);
|
||
}
|
||
return retmap;
|
||
}
|
||
|
||
@Override
|
||
public BizLogContext getLogContext() {
|
||
return null;
|
||
}
|
||
|
||
@Override
|
||
public List<BizLogContext> getLogContexts() {
|
||
return logger.getBizLogContexts();
|
||
}
|
||
}
|