部门编码新规则自定义生成
This commit is contained in:
parent
46f1c9fde1
commit
ef675bef1f
|
|
@ -0,0 +1,226 @@
|
|||
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.entity.BizLogContext;
|
||||
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 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.DepartmentComInfo;
|
||||
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 AddDepartmentCmd extends AbstractCommonCommand<Map<String, Object>>{
|
||||
|
||||
private SimpleBizLogger logger;
|
||||
|
||||
public AddDepartmentCmd(Map<String, Object> params, User user) {
|
||||
this.user = user;
|
||||
this.params = params;
|
||||
|
||||
String departmentname = Util.fromScreen((String)params.get("departmentname"),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_DPEARTMENT);//当前小类型
|
||||
bizLogContext.setOperateAuditType(BizLogOperateAuditType.WARNING);//警告
|
||||
bizLogContext.setParams(params);//当前request请求参数
|
||||
logger.setUser(user);//当前操作人
|
||||
String mainSql = "select * from HrmDepartment where 1=2 ";
|
||||
logger.setMainSql(mainSql,"id");//主表sql
|
||||
logger.setMainPrimarykey("id");//主日志表唯一key
|
||||
logger.setMainTargetNameColumn("departmentname");//当前targetName对应的列(对应日志中的对象名)
|
||||
logger.before(bizLogContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(CommandContext commandContext) {
|
||||
Map<String, Object> retmap = new HashMap<String, Object>();
|
||||
RecordSet rs = new RecordSet();
|
||||
try {
|
||||
|
||||
if (!HrmUserVarify.checkUserRight("HrmDepartmentAdd:Add", user)) {
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
|
||||
return retmap;
|
||||
}
|
||||
|
||||
DepartmentComInfo DepartmentComInfo = new DepartmentComInfo();
|
||||
//OrganisationCom OrganisationCom = new OrganisationCom();
|
||||
HrmServiceManager HrmServiceManager = new HrmServiceManager();
|
||||
|
||||
String departmentmark = Util.fromScreen((String)params.get("departmentmark"),user.getLanguage());
|
||||
String departmentname = Util.fromScreen((String)params.get("departmentname"),user.getLanguage());
|
||||
String subcompanyid1 = Util.fromScreen((String)params.get("subcompanyid1"),user.getLanguage());
|
||||
int supdepid = Util.getIntValue((String)params.get("supdepid"),0);
|
||||
String showorder = Util.fromScreen(Util.null2s((String)params.get("showorder"),"0"),user.getLanguage());
|
||||
|
||||
if(Util.getIntValue(subcompanyid1,0)<=0){
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(382647, user.getLanguage()));
|
||||
return retmap;
|
||||
}
|
||||
|
||||
String allsupdepid = "0";
|
||||
String departmentcode = Util.fromScreen((String)params.get("departmentcode"),user.getLanguage());
|
||||
int coadjutant=Util.getIntValue((String)params.get("coadjutant"),0);
|
||||
|
||||
/*
|
||||
* Added by Charoes Huang
|
||||
* 判断是否10级部门
|
||||
*/
|
||||
int supdepartmentid = supdepid;
|
||||
if(supdepartmentid > 0){
|
||||
Map<String, String> supMap = new HashMap<String, String>();
|
||||
supMap.put(""+supdepid, "1");
|
||||
int supdepidtemp = Util.getIntValue(DepartmentComInfo.getDepartmentsupdepid(""+supdepid), 0);
|
||||
while(supdepidtemp>0){
|
||||
if(supMap.get(""+supdepidtemp)==null){
|
||||
supMap.put(""+supdepidtemp, "1");
|
||||
supdepidtemp = Util.getIntValue(DepartmentComInfo.getDepartmentsupdepid(""+supdepidtemp), 0);
|
||||
}else{
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(382650,user.getLanguage()));
|
||||
return retmap;
|
||||
}
|
||||
}
|
||||
if(HrmOrganizationUtil.ifDeptLevelEquals10(supdepartmentid)){
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(382650, user.getLanguage()));
|
||||
return retmap;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果编码为空 自动生成编码
|
||||
departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, subcompanyid1, departmentcode,String.valueOf(supdepid));
|
||||
|
||||
if(!"".equals(departmentcode)){
|
||||
String sql2="select id from hrmdepartment where departmentcode = '" + departmentcode + "' ";
|
||||
rs.executeSql(sql2);
|
||||
if(rs.next()){
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(382653, user.getLanguage()));
|
||||
return retmap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char separator = Util.getSeparator() ;
|
||||
if(supdepid > 0){//当选择了上级部门的时候,需要更改当前部门的上级分部
|
||||
subcompanyid1 = DepartmentComInfo.getSubcompanyid1(supdepid+"");
|
||||
}
|
||||
|
||||
String para = departmentmark + separator + departmentname + separator +
|
||||
supdepid+separator+allsupdepid+separator+subcompanyid1 + separator+ showorder+separator+coadjutant;
|
||||
rs.executeProc("HrmDepartment_Insert",para);
|
||||
int flag=rs.getFlag();
|
||||
if(flag==2){
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(382655, user.getLanguage()));
|
||||
return retmap;
|
||||
}else if(flag==3){
|
||||
retmap.put("status", "-1");
|
||||
retmap.put("message", SystemEnv.getHtmlLabelName(382657, user.getLanguage()));
|
||||
return retmap;
|
||||
}
|
||||
|
||||
int id=0;
|
||||
if(rs.next()){
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
|
||||
weaver.hrm.company.OrgOperationUtil OrgOperationUtil = new weaver.hrm.company.OrgOperationUtil();
|
||||
OrgOperationUtil.updateDepartmentLevel(""+id,"0");
|
||||
String sql3="update hrmdepartment set departmentcode = '" + departmentcode + "' ";
|
||||
sql3 += ","+ DbFunctionUtil.getInsertUpdateSetSql(rs.getDBType(),user.getUID()) ;
|
||||
sql3+=" where id = "+id;
|
||||
rs.executeSql(sql3);
|
||||
HrmDeptFieldManagerE9 hrmDeptFieldManager = new HrmDeptFieldManagerE9(5);
|
||||
hrmDeptFieldManager.editCustomData(params,id);
|
||||
|
||||
|
||||
DepartmentComInfo.removeCompanyCache();
|
||||
rs.executeSql("update orgchartstate set needupdate=1");
|
||||
|
||||
//add by wjy
|
||||
//同步RTX端部门信息
|
||||
//OrganisationCom.addDepartment(id);//执行速度过慢,改为另起线程执行
|
||||
new Thread(new OrganisationComRunnable("department", "add", String.valueOf(id))).start();
|
||||
|
||||
//同步到CoreMail邮件系统开始
|
||||
if(supdepid == 0) {
|
||||
CoreMailAPI.synOrg(""+id, departmentname, "parent_org_unit_id=com_"+subcompanyid1+"&org_unit_name="+departmentname, "0");
|
||||
//testapi.synOrg(""+id, departmentname, "com_"+subcompanyid1, "0");
|
||||
} else {
|
||||
CoreMailAPI.synOrg(""+id, departmentname, "parent_org_unit_id="+supdepid+"&org_unit_name="+departmentname, "0");
|
||||
//testapi.synOrg(""+id, departmentname, ""+supdepid, "0");
|
||||
}
|
||||
//同步到CoreMail邮件系统结束
|
||||
|
||||
//OA与第三方接口单条数据同步方法开始
|
||||
HrmServiceManager.SynInstantDepartment(""+id,"1");
|
||||
//OA与第三方接口单条数据同步方法结束
|
||||
|
||||
HrmFaceCheckManager.sync(id+"",HrmFaceCheckManager.getOptInsert(),this.getClass().getName(),HrmFaceCheckManager.getOaDepartment());
|
||||
|
||||
|
||||
//同步部门数据到矩阵
|
||||
MatrixUtil.updateDepartmentData(""+id);
|
||||
//同步矩阵维护范围
|
||||
MatrixMaintComInfo maintComInfo = new MatrixMaintComInfo();
|
||||
maintComInfo.removeCache();
|
||||
//初始化应用分权
|
||||
new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData();
|
||||
|
||||
String mainSql = "select a.* from HrmDepartment a left join HrmDepartmentdefined b on a.id=b.deptid where a.id in(" + id + ")";
|
||||
String tableColumns = new ServiceUtil().getTableColumns("select * from HrmDepartmentdefined", "b", "id");
|
||||
if (!tableColumns.equals("")) {
|
||||
mainSql = "select a.*," + tableColumns + " from HrmDepartment a left join HrmDepartmentdefined b on a.id=b.deptid 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,314 @@
|
|||
package com.engine.hrm.util;
|
||||
|
||||
import com.engine.hrm.entity.RuleCodeType;
|
||||
import com.engine.xmgsecond.util.DepartmentCodeUtil;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.company.DepartmentComInfo;
|
||||
import weaver.hrm.company.SubCompanyComInfo;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CodeRuleManager extends BaseBean {
|
||||
|
||||
private static CodeRuleManager codeRuleManager = new CodeRuleManager();
|
||||
|
||||
private SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
|
||||
private DepartmentComInfo departmentComInfo = new DepartmentComInfo();
|
||||
|
||||
public static String NULL = "NULL";
|
||||
public static String SEPARATOR = "-";
|
||||
|
||||
public static CodeRuleManager getCodeRuleManager() {
|
||||
return codeRuleManager;
|
||||
}
|
||||
|
||||
private CodeRuleManager() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param serialtype SUBCOMPANY("SUBCOMPANY"), DEPARTMENT("DEPARTMENT"), JOBTITLES("JOBTITLES"), USER("USER")
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String generateRuleCode(RuleCodeType serialtype, String inputCode) throws Exception {
|
||||
return this.generateRuleCode(serialtype, null, null, null, inputCode);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param serialtype SUBCOMPANY("SUBCOMPANY"), DEPARTMENT("DEPARTMENT"), JOBTITLES("JOBTITLES"), USER("USER")
|
||||
* @param subcompanyCode 分部编号
|
||||
* @return 部门
|
||||
* @throws Exception
|
||||
*/
|
||||
public String generateRuleCode(RuleCodeType serialtype, String subcompanyid, String inputCode,String supDeptid) throws Exception {
|
||||
|
||||
if (StringUtils.isNotEmpty(inputCode)) {
|
||||
checkReservedIfDel(serialtype.getValue(), inputCode);
|
||||
return inputCode;
|
||||
}
|
||||
RecordSet recordSet = new RecordSet();
|
||||
// 查询启用的编码规则
|
||||
String sql = "select * from hrm_coderule where serialtype = ? and serialenable = 1";
|
||||
recordSet.executeQuery(sql, serialtype.getValue());
|
||||
if (recordSet.getCounts() <=0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
//QC3600738 新美光HR项目 部门自定义编码 新建(卡片 导入等)
|
||||
if("DEPARTMENT".equals(serialtype.getValue())) {
|
||||
DepartmentCodeUtil departmentCodeUtil = new DepartmentCodeUtil();
|
||||
return departmentCodeUtil.generateRuleCode(subcompanyid,"",supDeptid);
|
||||
}
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param serialtype SUBCOMPANY("SUBCOMPANY"), DEPARTMENT("DEPARTMENT"), JOBTITLES("JOBTITLES"), USER("USER")
|
||||
* @param subcompanyid 分部id
|
||||
* @param deptid 部门id
|
||||
* @return 返回编码规则生成的编码
|
||||
* @throws Exception
|
||||
*/
|
||||
public String generateRuleCode(RuleCodeType serialtype, String subcompanyid, String deptid, String jobtitlesid, String inputCode) throws Exception {
|
||||
if (StringUtils.isNotEmpty(inputCode)) {
|
||||
checkReservedIfDel(serialtype.getValue(), inputCode);
|
||||
return inputCode;
|
||||
}
|
||||
RecordSet recordSet = new RecordSet();
|
||||
// 查询启用的编码规则
|
||||
String sql = "select * from hrm_coderule where serialtype = ? and serialenable = 1";
|
||||
recordSet.executeQuery(sql, serialtype.getValue());
|
||||
if (recordSet.getCounts() <=0) {
|
||||
return "";
|
||||
}
|
||||
recordSet.next();
|
||||
|
||||
//QC3600738 新美光HR项目 部门自定义编码 重新生成编号
|
||||
if("DEPARTMENT".equals(serialtype.getValue())) {
|
||||
DepartmentCodeUtil departmentCodeUtil = new DepartmentCodeUtil();
|
||||
return departmentCodeUtil.generateRuleCode(subcompanyid,deptid,"");
|
||||
}
|
||||
|
||||
// 先匹配到规则的唯一编码
|
||||
String oneselftype = recordSet.getString("oneselftype");
|
||||
String id = recordSet.getString("id");
|
||||
String[] oneselftypeList = StringUtils.isEmpty(oneselftype) ? new String[]{} : oneselftype.split(",");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
LocalDate now = LocalDate.now();
|
||||
for (String type : oneselftypeList) {
|
||||
switch (RuleCodeType.getByValue(type)) {
|
||||
case DAY:
|
||||
map.put(RuleCodeType.DAY.getValue(), String.format("%02d", now.getDayOfMonth()));
|
||||
case MONTH:
|
||||
map.put(RuleCodeType.MONTH.getValue(), String.format("%02d", now.getMonthValue()));
|
||||
case YEAR:
|
||||
map.put(RuleCodeType.YEAR.getValue(), String.valueOf(now.getYear()));
|
||||
break;
|
||||
case SUBCOMPANY:
|
||||
map.put("subcompanyid", subcompanyid);
|
||||
break;
|
||||
case DEPARTMENT:
|
||||
map.put("deptid", deptid);
|
||||
break;
|
||||
case JOBTITLES:
|
||||
map.put("jobtitlesid", jobtitlesid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
String uniqueconstitute = map.isEmpty() ? CodeRuleManager.buildUniqueconstituteNULL() : CodeRuleManager.buildUniqueconstitute(map.get(RuleCodeType.YEAR.getValue()), map.get(RuleCodeType.MONTH.getValue()),
|
||||
map.get(RuleCodeType.DAY.getValue()), map.get("subcompanyid"), map.get("deptid"), map.get("jobtitlesid"));
|
||||
// int index = 0;
|
||||
while (true) {
|
||||
// index ++;
|
||||
String code = this.buildCode(id, subcompanyid, deptid, jobtitlesid, uniqueconstitute);
|
||||
sql = "select * from hrm_coderulereserved where reservedcode = ? and coderuleid = ?";
|
||||
recordSet.executeQuery(sql, code, id);
|
||||
if (recordSet.getCounts() <= 0 && !checkIsExist(code, serialtype.getValue())) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
// throw new Exception("自动创建编码失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检验预留编号是否存在 存在就删除
|
||||
* @param serialtype
|
||||
* @param inputCode
|
||||
*/
|
||||
public void checkReservedIfDel(String serialtype, String inputCode) {
|
||||
try {
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "select hcr.id from hrm_coderulereserved hcr left join hrm_coderule hc ON hcr.coderuleid = hc.id where hc.serialtype = ? and reservedcode = ?";
|
||||
rs.executeQuery(sql, serialtype, inputCode);
|
||||
List<String> ids = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
ids.add(rs.getString("id"));
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(ids)) {
|
||||
sql = "delete from hrm_coderulereserved where id in("+StringUtils.strip(ids.toString(),"[]")+")";
|
||||
rs.executeUpdate(sql);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
writeLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIsExist(String code, String serialtype) {
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "";
|
||||
// 判断该字段是否已经被试用
|
||||
switch (RuleCodeType.getByValue(serialtype)) {
|
||||
case SUBCOMPANY:
|
||||
sql = "select id from HrmSubCompany where subcompanycode = ?";
|
||||
break;
|
||||
case DEPARTMENT:
|
||||
sql = "select id from HrmDepartment where departmentcode = ?";
|
||||
break;
|
||||
case JOBTITLES:
|
||||
sql = "select id from HrmJobTitles where jobtitlecode = ?";
|
||||
break;
|
||||
case USER:
|
||||
sql = "select id from hrmresource where workcode = ?";
|
||||
break;
|
||||
}
|
||||
rs.executeQuery(sql, code);
|
||||
if (rs.getCounts() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String buildCode(String id, String subcompanyid, String deptid,String jobtitlesid, String uniqueconstitute) throws Exception {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
// 生成编号
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = "select * from hrm_coderuledetail where coderuleid = ? ORDER BY showorder";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
recordSet.executeQuery(sql, id);
|
||||
while (recordSet.next()) {
|
||||
String ruletype = recordSet.getString("ruletype");
|
||||
String rulevalue = Util.null2String(recordSet.getString("rulevalue")).trim();
|
||||
switch (RuleCodeType.getByValue(ruletype)) {
|
||||
case STRING:
|
||||
sb.append(rulevalue);
|
||||
break;
|
||||
case YEAR:
|
||||
sb.append(localDate.getYear());
|
||||
break;
|
||||
case MONTH:
|
||||
sb.append(String.format("%02d", localDate.getMonthValue()));
|
||||
break;
|
||||
case DAY:
|
||||
sb.append(String.format("%02d", localDate.getDayOfMonth()));
|
||||
break;
|
||||
case SUBCOMPANY:
|
||||
sb.append(subCompanyComInfo.getSubCompanyCode(subcompanyid));
|
||||
break;
|
||||
case DEPARTMENT:
|
||||
sb.append(departmentComInfo.getDepartmentCode(deptid));
|
||||
break;
|
||||
case JOBTITLES:
|
||||
sb.append(getJobtitlesCode(jobtitlesid));
|
||||
break;
|
||||
case NUMBER:
|
||||
int number = this.getNumber(id, 0, uniqueconstitute);
|
||||
// if ((number+ "").length() > Integer.parseInt(rulevalue) - 1) {
|
||||
// throw new Exception("流水号超出定义位数!");
|
||||
// }
|
||||
sb.append(String.format("%0"+rulevalue+"d", number));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getJobtitlesCode(String jobtitlesid) {
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "select jobtitlecode from hrmjobtitles where id = ?";
|
||||
rs.executeQuery(sql, jobtitlesid);
|
||||
while (rs.next()) {
|
||||
return rs.getString("jobtitlecode");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流水号
|
||||
* @param id
|
||||
*/
|
||||
private int getNumber(String id, int index, String uniqueconstitute) throws Exception {
|
||||
if (index == 5) {
|
||||
throw new Exception("编号重复!");
|
||||
}
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "select * from hrm_coderulerecord where coderuleid = ? and uniqueconstitute = ?";
|
||||
rs.executeQuery(sql, id, uniqueconstitute);
|
||||
int currentnumber = -1;
|
||||
int version = -1;
|
||||
if (rs.next()) {
|
||||
currentnumber = Integer.parseInt(rs.getString("currentnumber"));
|
||||
version = Integer.parseInt(rs.getString("version"));
|
||||
} else {
|
||||
// 不存在 插入默认起始编号
|
||||
sql = "insert into hrm_coderulerecord (coderuleid, uniqueconstitute, startnumber, currentnumber, version) values (? ,? ,? ,?, ?)";
|
||||
if (rs.executeUpdate(sql, id, uniqueconstitute, 1, 1, 1)) {
|
||||
currentnumber = 1;
|
||||
version = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sql = "update hrm_coderulerecord set version = ?, currentnumber = ? where coderuleid = ? and version = ? and uniqueconstitute = ?";
|
||||
// 通过乐观锁的实现方式处理集群下的并发可能
|
||||
rs.executeUpdate(sql, version + 1, currentnumber + 1, id, version, uniqueconstitute);
|
||||
if (rs.next() && rs.getInt(0) <= 0) {
|
||||
// 说明存在并发 未执行成功 重新获取
|
||||
index ++;
|
||||
return getNumber(id, index, uniqueconstitute);
|
||||
}
|
||||
return currentnumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置编码规则中的流水号
|
||||
* @param id
|
||||
* @param startnumber
|
||||
*/
|
||||
private void resetRuleCode(String id, String startnumber) {
|
||||
RecordSet rs = new RecordSet();
|
||||
String sql = "update hrm_coderule set resetdate = ?, currentnumber = ? where id = ?";
|
||||
rs.executeUpdate(sql, LocalDate.now().toString(), startnumber, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组成起始编号表唯一性的编号
|
||||
* @return
|
||||
*/
|
||||
public static String buildUniqueconstitute(String year, String month, String day, String subcompanyid, String deptid, String jobtitlesid) {
|
||||
return Util.null2String(year, NULL) + SEPARATOR + Util.null2String(month, NULL) + SEPARATOR
|
||||
+ Util.null2String(day, NULL) + SEPARATOR + Util.null2String(subcompanyid, NULL)
|
||||
+ SEPARATOR + Util.null2String(deptid, NULL) + SEPARATOR + Util.null2String(jobtitlesid, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组成起始编号表唯一性的编号
|
||||
* @return
|
||||
*/
|
||||
public static String buildUniqueconstituteNULL() {
|
||||
return NULL + SEPARATOR + NULL + SEPARATOR
|
||||
+ NULL + SEPARATOR + NULL
|
||||
+ SEPARATOR + NULL + SEPARATOR + NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.engine.xmgsecond.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2025/3/25 14:50
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DeptCodeRule {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer subcompany;
|
||||
|
||||
private String code;
|
||||
|
||||
private String firstNum;
|
||||
|
||||
private String secondNum;
|
||||
|
||||
private String threeNum;
|
||||
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
package com.engine.xmgsecond.util;
|
||||
|
||||
import com.engine.xmgsecond.entity.DeptCodeRule;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.StringUtil;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.company.DepartmentComInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2025/3/25 14:48
|
||||
* @Description: 新部门编号
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class DepartmentCodeUtil {
|
||||
|
||||
private static final Map<String, int[]> DEPT_LABEL_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
DEPT_LABEL_MAP.put("1", new int[]{1, 3});
|
||||
DEPT_LABEL_MAP.put("2", new int[]{3, 5});
|
||||
DEPT_LABEL_MAP.put("3", new int[]{5, 7});
|
||||
}
|
||||
|
||||
public String generateRuleCode(String subcompanyId,String deptId, String lastSupdepid) {
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
//1.根据分部获取新部门编码规则表信息
|
||||
DeptCodeRule deptCodeRule = null;
|
||||
rs.executeQuery("select id,fb,bs,yjbmls,ejbmls,sjbmls,bz from uf_departmentcode_rules where fb = ?",subcompanyId);
|
||||
if (rs.next()) {
|
||||
deptCodeRule = DeptCodeRule.builder()
|
||||
.id(Util.getIntValue(rs.getString("id")))
|
||||
.subcompany(Util.getIntValue(rs.getString("fb")))
|
||||
.code(Util.null2String(rs.getString("bs")))
|
||||
.firstNum(Util.null2String(rs.getString("yjbmls")))
|
||||
.secondNum(Util.null2String(rs.getString("ejbmls")))
|
||||
.threeNum(Util.null2String(rs.getString("sjbmls")))
|
||||
.build();
|
||||
}
|
||||
|
||||
if (deptCodeRule == null) {
|
||||
//新部门编码规则表未设置规则情况下 不进行编码直接返回
|
||||
return "";
|
||||
}
|
||||
|
||||
//2.获取该部门所有上级部门 (需求确认中 部门层级最多只有3级),并获取对应的流水号,若不存在为 00
|
||||
DepartmentComInfo deptInfo = new DepartmentComInfo();
|
||||
|
||||
//上级部门id
|
||||
if (StringUtil.isEmpty(lastSupdepid)) {
|
||||
lastSupdepid = deptInfo.getDepartmentsupdepid(deptId);
|
||||
}
|
||||
String lastSupCode = deptInfo.getDepartmentCode(lastSupdepid);
|
||||
lastSupdepid = lastSupdepid == null || lastSupdepid.isEmpty() ? "0" : lastSupdepid;
|
||||
|
||||
//上上级部门id
|
||||
String lastTopSupdepid = deptInfo.getDepartmentsupdepid(lastSupdepid);
|
||||
lastTopSupdepid = lastTopSupdepid == null || lastTopSupdepid.isEmpty() ? "0" : lastTopSupdepid;
|
||||
String lastTopSupCode = deptInfo.getDepartmentCode(lastTopSupdepid);
|
||||
|
||||
// 例如一级部门 lastSupdepid="0",lastTopSupdepid="0"
|
||||
// 例如二级部门 lastSupdepid="2726",lastTopSupdepid="0"
|
||||
// 例如三级部门 lastSupdepid="2730",lastTopSupdepid="2726"
|
||||
|
||||
String deptLevel = "";
|
||||
String serialnum = "";
|
||||
String departmentCode;
|
||||
if ("0".equals(lastSupdepid)) {
|
||||
// 一级部门
|
||||
serialnum = deptCodeRule.getFirstNum();
|
||||
deptLevel = "1";
|
||||
departmentCode = deptCodeRule.getCode() + "%s0000";
|
||||
} else if ("0".equals(lastTopSupdepid)) {
|
||||
// 二级部门
|
||||
serialnum = deptCodeRule.getSecondNum();
|
||||
deptLevel = "2";
|
||||
String firstSerial = getSubstringByLevel(lastSupCode, "1");
|
||||
departmentCode = deptCodeRule.getCode() + firstSerial + "%s00";
|
||||
} else {
|
||||
// 三级部门
|
||||
serialnum = deptCodeRule.getThreeNum();
|
||||
deptLevel = "3";
|
||||
String secondSerial = getSubstringByLevel(lastSupCode, "2");
|
||||
String firstSerial = getSubstringByLevel(lastTopSupCode,"1");
|
||||
departmentCode = deptCodeRule.getCode() + firstSerial + secondSerial + "%s";
|
||||
}
|
||||
|
||||
|
||||
//3.获取当前部门序列号(1.截取该层级所有部门的流水号比较 )
|
||||
List<String> departmentSerial = getDepartmentSerial(subcompanyId, deptCodeRule.getCode(), deptLevel);
|
||||
if ("00".equals(serialnum)) {
|
||||
departmentSerial.add(serialnum);
|
||||
}
|
||||
|
||||
|
||||
//List<String>中元素 ["01","02","03","06","05","24","08"] 如 01 - 24,若是连续且存在 则当前部门流水号 24+1;2.若不连续则使用跳号中最小的数字作为当前部门流水号
|
||||
List<Integer> sortedNumbers = departmentSerial.stream()
|
||||
.map(Integer::parseInt)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查找跳号
|
||||
int nextNumber = IntStream.rangeClosed(1, sortedNumbers.isEmpty() ? 1 : sortedNumbers.get(sortedNumbers.size() - 1) + 1)
|
||||
.filter(num ->!sortedNumbers.contains(num))
|
||||
.findFirst()
|
||||
.orElseGet(() -> sortedNumbers.isEmpty() ? 1 : sortedNumbers.get(sortedNumbers.size() - 1) + 1);
|
||||
|
||||
// 格式化结果
|
||||
String newSerialnum = String.format("%02d", nextNumber);
|
||||
|
||||
//4.更新部门规则表流水号
|
||||
//检查是否存在跳号 如果是跳号则不更新
|
||||
boolean isJump = nextNumber > Integer.parseInt(serialnum);
|
||||
|
||||
if (isJump) {
|
||||
Map<String,String> fieldMap = new HashMap<>();
|
||||
fieldMap.put("1", "yjbmls");
|
||||
fieldMap.put("2", "ejbmls");
|
||||
fieldMap.put("3", "sjbmls");
|
||||
String field = fieldMap.get(deptLevel);
|
||||
rs.executeUpdate("update uf_departmentcode_rules set "+field+" = ?",newSerialnum);
|
||||
}
|
||||
|
||||
return String.format(departmentCode,newSerialnum);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<String> getDepartmentSerial(String subcompanyId,String code,String deptLevel) {
|
||||
RecordSet rs = new RecordSet();
|
||||
List<String> deptSerial = new ArrayList<>();
|
||||
rs.executeQuery("select departmentcode from hrmdepartment where subcompanyid1 = ? and departmentcode like '"+code+"%'",subcompanyId);
|
||||
while (rs.next()) {
|
||||
String departmentcode = Util.null2String(rs.getString("departmentcode"));
|
||||
|
||||
//D010000 deptLevel="1" 截取23位 deptLevel="2" 截取45位 deptLevel="3" 截取67位
|
||||
String serialNumber = getSubstringByLevel(departmentcode, deptLevel);
|
||||
deptSerial.add(serialNumber);
|
||||
}
|
||||
|
||||
//去除List<String>中 为 00 的元素 ["00","01","02","03","06","05","00"]
|
||||
return deptSerial.stream()
|
||||
.filter(element -> !"00".equals(element))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getSubstringByLevel(String str, String deptLevel) {
|
||||
// 根据 deptLevel 获取对应的索引范围
|
||||
int[] indices = DEPT_LABEL_MAP.get(deptLevel);
|
||||
if (indices != null && str.length() >= indices[1]) {
|
||||
// 若存在对应的索引范围且字符串长度足够,则进行截取
|
||||
return str.substring(indices[0], indices[1]);
|
||||
}
|
||||
return "00";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,514 @@
|
|||
package weaver.hrm.excelimport;
|
||||
|
||||
import com.engine.common.service.impl.HrmCommonServiceImpl;
|
||||
import com.engine.hrm.entity.RuleCodeType;
|
||||
import com.engine.hrm.util.CodeRuleManager;
|
||||
import com.engine.hrm.util.HrmTriggerUtil;
|
||||
import com.engine.hrm.util.face.HrmFaceCheckManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.common.AjaxManager;
|
||||
import weaver.hrm.company.DepartmentComInfo;
|
||||
import weaver.hrm.company.SubCompanyComInfo;
|
||||
import weaver.matrix.MatrixUtil;
|
||||
import weaver.rtx.OrganisationCom;
|
||||
import weaver.systeminfo.SysMaintenanceLog;
|
||||
import weaver.systeminfo.SystemEnv;
|
||||
import weaver.hrm.common.DbFunctionUtil;
|
||||
|
||||
/**
|
||||
* 分部部门信息类
|
||||
* @author lvyi
|
||||
*
|
||||
*/
|
||||
public class HrmCompany extends BaseBean {
|
||||
private RecordSet recordSet=new RecordSet();
|
||||
private OrganisationCom rtxService=new OrganisationCom();; //添加到rtx
|
||||
private int id;
|
||||
private String subcompanyname="";
|
||||
private String departmentname="";
|
||||
private String subcompanycode = "";
|
||||
private Float subcompanyshoworder;
|
||||
private String departmentcode = "";
|
||||
private Float departmentshoworder;
|
||||
private int userlanguage = 7;
|
||||
private int pid;
|
||||
private String operateType;
|
||||
private String message = "";
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public void setUserLanguage(String userlanguage){
|
||||
this.userlanguage = Util.getIntValue((String)userlanguage);
|
||||
}
|
||||
/**
|
||||
* 校验数据有效性
|
||||
* @return
|
||||
*/
|
||||
public String valExcelData(){
|
||||
String errorInfo = "";
|
||||
if(Util.null2String(this.subcompanyname).length()==0){
|
||||
errorInfo = SystemEnv.getHtmlLabelName(125704,userlanguage);
|
||||
return errorInfo;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(operateType) && operateType.equals("add")) {
|
||||
if (!verifySubCompanyCode(subcompanycode)) return subcompanycode + "编号重复";
|
||||
if (!verifyDeptCode(departmentcode)) return departmentcode + "编号重复";
|
||||
}
|
||||
return errorInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
*/
|
||||
public String save(){
|
||||
boolean flag = false;
|
||||
try{
|
||||
if(StringUtils.isNotEmpty(operateType)) {
|
||||
if (operateType.equals("add")) {
|
||||
int subcompanyid = 0;
|
||||
int departmentid = 0;
|
||||
if(Util.null2String(this.subcompanyname).length()>0){
|
||||
//取分部
|
||||
subcompanyid = getSubCompanyId(this.subcompanyname);
|
||||
}
|
||||
departmentid = getDeptId(this.departmentname,subcompanyid);
|
||||
if(Util.null2String(this.departmentname).length()>0){
|
||||
if(departmentid!=0)flag=true;
|
||||
}else{
|
||||
if(subcompanyid!=0)flag=true;
|
||||
}
|
||||
} else if (operateType.equals("update")) {
|
||||
int subcompanyid = updateSubCompany();
|
||||
if (subcompanyid == -1) return String.valueOf(flag);
|
||||
int deptid = updateDept(subcompanyid);
|
||||
if (deptid == -1) return String.valueOf(flag);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
writeLog(e);
|
||||
}
|
||||
|
||||
return String.valueOf(flag);
|
||||
}
|
||||
|
||||
private boolean verifySubCompanyCode(String code) {
|
||||
if (StringUtils.isEmpty(code)) return true;
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = "select id from HrmSubCompany where subcompanycode = ?";
|
||||
recordSet.executeQuery(sql, code);
|
||||
if (recordSet.getCounts() > 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean verifySubCompanyCode(String code, String name, int supsubcomid) {
|
||||
if (StringUtils.isEmpty(code)) return true;
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = "select id from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?";
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "select id from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?";
|
||||
}
|
||||
recordSet.executeQuery(sql, name, supsubcomid);
|
||||
if (recordSet.next()) {
|
||||
String id = recordSet.getString("id");
|
||||
sql = "select id from HrmSubCompany where subcompanycode = ? and id != ?";
|
||||
recordSet.executeQuery(sql, code, id);
|
||||
if (recordSet.getCounts() > 0) return false;
|
||||
return true;
|
||||
}
|
||||
return verifySubCompanyCode(code);
|
||||
}
|
||||
|
||||
private boolean verifyDeptCode(String code) {
|
||||
if (StringUtils.isEmpty(code)) return true;
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = "select id from HrmDepartment where departmentcode = ?";
|
||||
recordSet.executeQuery(sql, code);
|
||||
if (recordSet.getCounts() > 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean verifyDeptCode(String code, String name, int subcompanyid, int supdepid) {
|
||||
if (StringUtils.isEmpty(code)) return true;
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = "select id from HrmDepartment where ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? and subcompanyid1 = ? and supdepid = ?";
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "select id from HrmDepartment where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? and subcompanyid1 = ? and supdepid = ?";
|
||||
}
|
||||
recordSet.executeQuery(sql, name, subcompanyid, supdepid);
|
||||
if (recordSet.next()) {
|
||||
String id = recordSet.getString("id");
|
||||
sql = "select id from HrmDepartment where departmentcode = ? and id != ?";
|
||||
recordSet.executeQuery(sql, code, id);
|
||||
if (recordSet.getCounts() > 0) return false;
|
||||
return true;
|
||||
}
|
||||
return verifyDeptCode(code);
|
||||
}
|
||||
|
||||
private int updateDept(int subcompanyid) {
|
||||
String deptNames[] = departmentname.split(">");
|
||||
int currentId = 0;
|
||||
int parentId = 0;
|
||||
String departmentcode = "";
|
||||
Float departmentshoworder = null;
|
||||
for (int i = 0; i < deptNames.length; i++) {
|
||||
if (StringUtils.isEmpty(deptNames[i])) continue;
|
||||
String sql = "select * from HrmDepartment where subcompanyid1="+ subcompanyid + " and ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ deptNames[i].trim() + "' and supdepid=" + parentId +" and (canceled !=1 or canceled is null)";
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "select * from HrmDepartment where subcompanyid1="+ subcompanyid + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ deptNames[i].trim() + "' and supdepid=" + parentId +" and (canceled !=1 or canceled is null)";
|
||||
}
|
||||
currentId = getResultSetId(sql);
|
||||
if (currentId == 0) {
|
||||
// 部门不存在
|
||||
// 不存在
|
||||
this.setMessage("," + deptNames[i] + "部门不存在");
|
||||
return -1;
|
||||
}
|
||||
if (i == deptNames.length - 1) {
|
||||
// 最后一层级 赋值编码和顺序
|
||||
departmentcode = this.departmentcode;
|
||||
departmentshoworder = this.departmentshoworder;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(departmentcode) || departmentshoworder != null) {
|
||||
recordSet.executeQuery(sql);
|
||||
recordSet.next();
|
||||
if (departmentshoworder == null) departmentshoworder = Float.valueOf(Util.null2s(recordSet.getString("showorder"), "0"));
|
||||
if (StringUtils.isEmpty(departmentcode)) departmentcode = Util.null2String(recordSet.getString("departmentcode"), "");
|
||||
if (verifyDeptCode(departmentcode, deptNames[i], subcompanyid, parentId)) {
|
||||
sql = "update hrmdepartment set departmentcode = ? , showorder = ? where ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? and subcompanyid1 = ? and supdepid = ? and (canceled !=1 or canceled is null)";
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "update hrmdepartment set departmentcode = ? , showorder = ? where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+"))) = ? and subcompanyid1 = ? and supdepid = ? and (canceled !=1 or canceled is null)";
|
||||
}
|
||||
recordSet.executeUpdate(sql, departmentcode, departmentshoworder, deptNames[i], subcompanyid, parentId);
|
||||
} else {
|
||||
setMessage("," + departmentcode + "编号重复");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
parentId = currentId;
|
||||
}
|
||||
return currentId;
|
||||
}
|
||||
private int updateSubCompany(){
|
||||
String subcompanynames[] = subcompanyname.split(">");
|
||||
int parentId = 0;
|
||||
int currentId = 0;
|
||||
String subcompanycode = "";
|
||||
Float subcompanyshoworder = null;
|
||||
for (int i = 0; i < subcompanynames.length; i++) {
|
||||
if (StringUtils.isEmpty(subcompanynames[i])) continue;
|
||||
String sql = "select * from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='"
|
||||
+ subcompanynames[i].trim() + "' and supsubcomid=" + parentId;
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "select * from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='"
|
||||
+ subcompanynames[i].trim() + "' and supsubcomid=" + parentId;
|
||||
}
|
||||
currentId = getResultSetId(sql);
|
||||
if (currentId == 0) {
|
||||
// 不存在
|
||||
this.setMessage("," + subcompanynames[i] + "分部不存在");
|
||||
return -1;
|
||||
}
|
||||
if (i == subcompanynames.length - 1) {
|
||||
// 最后一层级 赋值编码和顺序
|
||||
subcompanycode = this.subcompanycode;
|
||||
subcompanyshoworder = this.subcompanyshoworder;
|
||||
}
|
||||
// 如果编码和顺序不存在则不更新
|
||||
if (StringUtils.isNotEmpty(subcompanycode) || subcompanyshoworder != null) {
|
||||
recordSet.executeQuery(sql);
|
||||
recordSet.next();
|
||||
if (subcompanyshoworder == null) subcompanyshoworder = Float.valueOf(Util.null2s(recordSet.getString("showorder"), "0"));
|
||||
if (StringUtils.isEmpty(subcompanycode)) subcompanycode = Util.null2String(recordSet.getString("subcompanycode"), "");
|
||||
if (verifySubCompanyCode(subcompanycode, subcompanynames[i], parentId)) {
|
||||
sql = "update HrmSubCompany set subcompanycode= ? , showorder = ? where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?";
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "update HrmSubCompany set subcompanycode= ? , showorder = ? where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+"))) = ? and supsubcomid = ?";
|
||||
}
|
||||
recordSet.executeUpdate(sql, subcompanycode, subcompanyshoworder, subcompanynames[i], parentId);
|
||||
} else {
|
||||
setMessage("," + subcompanycode + "编号重复");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
parentId = currentId;
|
||||
}
|
||||
return currentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分部名称获取分部Id,不存在就创建
|
||||
* @param subCompanyName 分部名称 eg:泛微广东>泛微深圳
|
||||
* @return
|
||||
*/
|
||||
public int getSubCompanyId(String subcompanyname) {
|
||||
String subcompanynames[] = subcompanyname.split(">");
|
||||
int currentId = 0;
|
||||
int parentId = 0;
|
||||
String sql = "";
|
||||
String sqlInsert = "";
|
||||
String subcompanycode = "";
|
||||
Float subcompanyshoworder = null;
|
||||
for (int i = 0; i < subcompanynames.length; i++) {
|
||||
if(subcompanynames[i] ==null && subcompanynames[i].equals("")){
|
||||
continue;
|
||||
}
|
||||
sql = "select id from HrmSubCompany where ltrim(rtrim(convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='"
|
||||
+ subcompanynames[i].trim() + "' and supsubcomid=" + parentId;
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "select id from HrmSubCompany where ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(subcompanyname)),"+userlanguage+")))='"
|
||||
+ subcompanynames[i].trim() + "' and supsubcomid=" + parentId;
|
||||
}
|
||||
|
||||
currentId = getResultSetId(sql);
|
||||
|
||||
//added by wcd 2015-02-06 [限制分部数]
|
||||
if (currentId == 0) {
|
||||
if (i == subcompanynames.length - 1) {
|
||||
// 最后一层级 赋值编码和顺序
|
||||
subcompanycode = this.subcompanycode;
|
||||
subcompanyshoworder = this.subcompanyshoworder;
|
||||
if (subcompanyshoworder == null) subcompanyshoworder = 0.00F;
|
||||
}
|
||||
if(AjaxManager.getData("", "getLnScCount;mf").equals("true")){
|
||||
// 如果编码为空 自动生成编码
|
||||
try {
|
||||
subcompanycode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.SUBCOMPANY, subcompanycode);
|
||||
} catch (Exception e) {
|
||||
setMessage("," + e.getMessage());
|
||||
writeLog(e);
|
||||
return -1;
|
||||
}
|
||||
sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid,subcompanycode,showorder,"+DbFunctionUtil.getInsertColumnSql()+") values('"
|
||||
+ subcompanynames[i] +"','"+subcompanynames[i]+"',1" + "," + parentId + ",'" + subcompanycode+ "'," + subcompanyshoworder + ","+DbFunctionUtil.getInsertColumnValueSql(new RecordSet().getDBType(), 1)+")"; // 创建
|
||||
boolean isSuccess = execSql(sqlInsert);
|
||||
HrmTriggerUtil.generateSubcompanyPinyin(subcompanynames[i], null);
|
||||
currentId = getResultSetId(sql);
|
||||
HrmTriggerUtil.Tri_I_SubComKPICheckFlow(String.valueOf(currentId));
|
||||
sql = "insert into leftmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from leftmenuconfig where resourcetype=1 and resourceid=1";
|
||||
execSql(sql);
|
||||
sql = "insert into mainmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from mainmenuconfig where resourcetype=1 and resourceid=1";
|
||||
execSql(sql);
|
||||
|
||||
if(isSuccess){
|
||||
//同步分部数据到矩阵
|
||||
MatrixUtil.updateSubcompayData("" + currentId);
|
||||
HrmFaceCheckManager.sync(currentId+"",HrmFaceCheckManager.getOptInsert(),"hrm_import_subcompany",HrmFaceCheckManager.getOaSubcompany());
|
||||
}
|
||||
|
||||
insertSysLog(subcompanynames[i],"12");
|
||||
} else {
|
||||
currentId = -1;
|
||||
}
|
||||
}
|
||||
parentId = currentId;
|
||||
if(currentId != -1)
|
||||
rtxService.addSubCompany(parentId); //同步RTX
|
||||
}
|
||||
return currentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门id,不存在就创建
|
||||
* @param deptNames 部门名称
|
||||
* @param subCompanyId 所属分部id
|
||||
* @return
|
||||
*/
|
||||
public int getDeptId(String deptNames, int subCompanyId){
|
||||
String deptName[] = deptNames.split(">");
|
||||
int currentId = 0;
|
||||
int parentId = 0;
|
||||
|
||||
String sql = "";
|
||||
String sqlInsert = "";
|
||||
String departmentcode = "";
|
||||
Float departmentshoworder = null;
|
||||
for (int i = 0; i < deptName.length; i++) {
|
||||
if(deptName[i] == null || deptName[i].equals("")){
|
||||
continue;
|
||||
}
|
||||
sql = "select id from HrmDepartment where subcompanyid1="+ subCompanyId + " and ltrim(rtrim(convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ deptName[i].trim() + "' and supdepid=" + parentId +" and (canceled !=1 or canceled is null)";
|
||||
if("sqlserver".equalsIgnoreCase(recordSet.getDBType())){
|
||||
sql = "select id from HrmDepartment where subcompanyid1="+ subCompanyId + " and ltrim(rtrim(dbo.convToMultiLang(ltrim(rtrim(departmentname)),"+userlanguage+")))='"+ deptName[i].trim() + "' and supdepid=" + parentId +" and (canceled !=1 or canceled is null)";
|
||||
}
|
||||
currentId = getResultSetId(sql);
|
||||
|
||||
if (currentId == 0) {
|
||||
if (i == deptName.length -1) {
|
||||
departmentcode = this.departmentcode;
|
||||
departmentshoworder = this.departmentshoworder;
|
||||
if (departmentshoworder == null) departmentshoworder = 0.00F;
|
||||
}
|
||||
// 如果编码为空 自动生成编码
|
||||
try {
|
||||
departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, String.valueOf(subCompanyId), departmentcode,String.valueOf(parentId));
|
||||
} catch (Exception e) {
|
||||
setMessage("," + e.getMessage());
|
||||
writeLog(e);
|
||||
return -1;
|
||||
}
|
||||
sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid,departmentcode,showorder,"+DbFunctionUtil.getInsertColumnSql()+") values('"
|
||||
+ deptName[i]+"','"+deptName[i]+"',"+ subCompanyId+ ","+ parentId + ",'"+ departmentcode + "',"+ departmentshoworder + ","+DbFunctionUtil.getInsertColumnValueSql(new RecordSet().getDBType(), 1)+")"; // 创建
|
||||
boolean isSuccess = execSql(sqlInsert);
|
||||
HrmTriggerUtil.generateDepartmentPinyin(deptName[i], null);
|
||||
currentId = getResultSetId(sql);
|
||||
HrmTriggerUtil.Tri_I_DeptKPICheckFlow(String.valueOf(currentId));
|
||||
if(isSuccess){
|
||||
//同步部门数据到矩阵
|
||||
MatrixUtil.updateDepartmentData("" + currentId);
|
||||
HrmFaceCheckManager.sync(currentId+"",HrmFaceCheckManager.getOptInsert(),"hrm_import_deptment",HrmFaceCheckManager.getOaDepartment());
|
||||
}
|
||||
|
||||
insertSysLog(deptName[i],"12");
|
||||
rtxService.addDepartment(currentId); //同步RTX
|
||||
}
|
||||
parentId = currentId;
|
||||
}
|
||||
return currentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得查询结果Id
|
||||
* @param sql 查询语句
|
||||
* @return
|
||||
*/
|
||||
public int getResultSetId(String sql) {
|
||||
int currentId = 0;
|
||||
recordSet.execute(sql);
|
||||
try {
|
||||
while (recordSet.next()) {
|
||||
currentId = recordSet.getInt("id");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return currentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行插入操作
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
|
||||
public boolean execSql(String sql) {
|
||||
if(recordSet.execute(sql)){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCache(){
|
||||
try{
|
||||
|
||||
MatrixUtil.sysSubcompayData();
|
||||
MatrixUtil.sysDepartmentData();
|
||||
|
||||
SubCompanyComInfo SubCompanyComInfo = new SubCompanyComInfo();
|
||||
SubCompanyComInfo.removeCompanyCache();
|
||||
|
||||
DepartmentComInfo DepartmentComInfo = new DepartmentComInfo();
|
||||
DepartmentComInfo.removeCompanyCache();
|
||||
//初始化应用分权
|
||||
new weaver.hrm.appdetach.AppDetachComInfo().initSubDepAppData();
|
||||
}catch (Exception e) {
|
||||
writeLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubcompanyname() {
|
||||
return subcompanyname;
|
||||
}
|
||||
|
||||
public void setSubcompanyname(String subcompanyname) {
|
||||
this.subcompanyname = subcompanyname;
|
||||
}
|
||||
|
||||
public String getDepartmentname() {
|
||||
return departmentname;
|
||||
}
|
||||
|
||||
public void setDepartmentname(String departmentname) {
|
||||
this.departmentname = departmentname;
|
||||
}
|
||||
|
||||
public String getSubcompanycode() {
|
||||
return subcompanycode;
|
||||
}
|
||||
|
||||
public void setSubcompanycode(String subcompanycode) {
|
||||
this.subcompanycode = subcompanycode;
|
||||
}
|
||||
|
||||
public Float getSubcompanyshoworder() {
|
||||
return subcompanyshoworder;
|
||||
}
|
||||
|
||||
public void setSubcompanyshoworder(Float subcompanyshoworder) {
|
||||
this.subcompanyshoworder = subcompanyshoworder;
|
||||
}
|
||||
|
||||
public String getDepartmentcode() {
|
||||
return departmentcode;
|
||||
}
|
||||
|
||||
public void setDepartmentcode(String departmentcode) {
|
||||
this.departmentcode = departmentcode;
|
||||
}
|
||||
|
||||
public Float getDepartmentshoworder() {
|
||||
return departmentshoworder;
|
||||
}
|
||||
|
||||
public void setDepartmentshoworder(Float departmentshoworder) {
|
||||
this.departmentshoworder = departmentshoworder;
|
||||
}
|
||||
|
||||
public String getOperateType() {
|
||||
return operateType;
|
||||
}
|
||||
|
||||
public void setOperateType(String operateType) {
|
||||
this.operateType = operateType;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private void insertSysLog(String name, String operateItem) {
|
||||
SysMaintenanceLog syslog = new SysMaintenanceLog();
|
||||
syslog.resetParameter();
|
||||
syslog.setRelatedId(pid);
|
||||
syslog.setOperateType("-1");
|
||||
syslog.setOperateItem(operateItem);
|
||||
syslog.setOperateUserid(0);
|
||||
syslog.setRelatedName(name);
|
||||
try {
|
||||
syslog.setSysLogInfo();
|
||||
} catch (Exception e) {
|
||||
writeLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue