部门编码新规则自定义生成
This commit is contained in:
parent
ef675bef1f
commit
7a25169fab
|
|
@ -1,6 +1,7 @@
|
|||
package com.engine.xmgsecond.util;
|
||||
|
||||
import com.engine.xmgsecond.entity.DeptCodeRule;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.StringUtil;
|
||||
import weaver.general.Util;
|
||||
|
|
@ -52,20 +53,25 @@ public class DepartmentCodeUtil {
|
|||
return "";
|
||||
}
|
||||
|
||||
//2.获取该部门所有上级部门 (需求确认中 部门层级最多只有3级),并获取对应的流水号,若不存在为 00
|
||||
//2.获取该部门所有上级部门 (需求确认 部门层级最多只有3级),并获取对应的流水号,若不存在为 00
|
||||
//导入时缓存无法获取部门信息 String lastSupCode = deptInfo.getDepartmentCode(lastSupdepid);
|
||||
DepartmentComInfo deptInfo = new DepartmentComInfo();
|
||||
|
||||
//上级部门id
|
||||
if (StringUtil.isEmpty(lastSupdepid)) {
|
||||
lastSupdepid = deptInfo.getDepartmentsupdepid(deptId);
|
||||
}
|
||||
String lastSupCode = deptInfo.getDepartmentCode(lastSupdepid);
|
||||
Map<String, String> lastData = getDepartmentCode(lastSupdepid);
|
||||
|
||||
|
||||
String lastSupCode = lastData.get("departmentcode");
|
||||
lastSupdepid = lastSupdepid == null || lastSupdepid.isEmpty() ? "0" : lastSupdepid;
|
||||
|
||||
|
||||
//上上级部门id
|
||||
String lastTopSupdepid = deptInfo.getDepartmentsupdepid(lastSupdepid);
|
||||
Map<String, String> lastTopData = getDepartmentCode(lastSupdepid);
|
||||
String lastTopSupdepid = lastTopData.get("supdepid");
|
||||
lastTopSupdepid = lastTopSupdepid == null || lastTopSupdepid.isEmpty() ? "0" : lastTopSupdepid;
|
||||
String lastTopSupCode = deptInfo.getDepartmentCode(lastTopSupdepid);
|
||||
String lastTopSupCode = lastTopData.get("departmentcode");
|
||||
|
||||
// 例如一级部门 lastSupdepid="0",lastTopSupdepid="0"
|
||||
// 例如二级部门 lastSupdepid="2726",lastTopSupdepid="0"
|
||||
|
|
@ -100,6 +106,11 @@ public class DepartmentCodeUtil {
|
|||
if ("00".equals(serialnum)) {
|
||||
departmentSerial.add(serialnum);
|
||||
}
|
||||
//如果本身已经存在编码 需要移除该编号
|
||||
if (StringUtils.isNotEmpty(deptId)) {
|
||||
String code = getSubstringByLevel(deptInfo.getDepartmentCode(deptId),deptLevel);
|
||||
departmentSerial.removeIf(element -> element.equals(code));
|
||||
}
|
||||
|
||||
|
||||
//List<String>中元素 ["01","02","03","06","05","24","08"] 如 01 - 24,若是连续且存在 则当前部门流水号 24+1;2.若不连续则使用跳号中最小的数字作为当前部门流水号
|
||||
|
|
@ -118,7 +129,7 @@ public class DepartmentCodeUtil {
|
|||
String newSerialnum = String.format("%02d", nextNumber);
|
||||
|
||||
//4.更新部门规则表流水号
|
||||
//检查是否存在跳号 如果是跳号则不更新
|
||||
//检查是否存在跳号 如果是跳号则不更新 true为不是跳号
|
||||
boolean isJump = nextNumber > Integer.parseInt(serialnum);
|
||||
|
||||
if (isJump) {
|
||||
|
|
@ -127,7 +138,7 @@ public class DepartmentCodeUtil {
|
|||
fieldMap.put("2", "ejbmls");
|
||||
fieldMap.put("3", "sjbmls");
|
||||
String field = fieldMap.get(deptLevel);
|
||||
rs.executeUpdate("update uf_departmentcode_rules set "+field+" = ?",newSerialnum);
|
||||
rs.executeUpdate("update uf_departmentcode_rules set "+field+" = ? where id = ?",newSerialnum,deptCodeRule.getId());
|
||||
}
|
||||
|
||||
return String.format(departmentCode,newSerialnum);
|
||||
|
|
@ -164,4 +175,17 @@ public class DepartmentCodeUtil {
|
|||
}
|
||||
return "00";
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> getDepartmentCode(String deptId) {
|
||||
RecordSet rs = new RecordSet();
|
||||
Map<String,String> data = new HashMap<>();
|
||||
rs.executeQuery("select departmentcode,supdepid from hrmdepartment where id = ?",deptId);
|
||||
rs.next();
|
||||
data.put("departmentcode",Util.null2String(rs.getString("departmentcode")));
|
||||
data.put("supdepid",Util.null2String(rs.getString("supdepid")));
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -346,6 +346,7 @@ public int getDeptId(String deptNames, int subCompanyId){
|
|||
if (departmentshoworder == null) departmentshoworder = 0.00F;
|
||||
}
|
||||
// 如果编码为空 自动生成编码
|
||||
departmentcode = "";
|
||||
try {
|
||||
departmentcode = CodeRuleManager.getCodeRuleManager().generateRuleCode(RuleCodeType.DEPARTMENT, String.valueOf(subCompanyId), departmentcode,String.valueOf(parentId));
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue