新增员工增加自动生成员工工号逻辑
This commit is contained in:
parent
ff6d5da87a
commit
0e52073668
|
|
@ -4,6 +4,8 @@ import com.alibaba.nacos.common.utils.CollectionUtils;
|
|||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.common.cache.tablecache.impl.ComInfoCache;
|
||||
import com.weaver.common.distribution.genid.IdGenerator;
|
||||
import com.weaver.common.form.auth.FormAuthenticationService;
|
||||
import com.weaver.common.form.dto.auth.FormAuthenticationDto;
|
||||
import com.weaver.common.form.enums.auth.FormAuthenticationEnum;
|
||||
|
|
@ -12,6 +14,9 @@ import com.weaver.common.form.fieldmanage.service.FormFieldManageService;
|
|||
import com.weaver.common.form.metadata.ModuleSource;
|
||||
import com.weaver.common.form.param.FieldManageParam;
|
||||
import com.weaver.common.form.param.auth.FormAuthenticationParam;
|
||||
import com.weaver.common.hrm.cache.HrmDepartmentComInfo;
|
||||
import com.weaver.common.hrm.cache.HrmPositionComInfo;
|
||||
import com.weaver.common.hrm.util.HrmDepartmentUtil;
|
||||
import com.weaver.common.i18n.label.SystemEnv;
|
||||
import com.weaver.common.mybatis.util.DatabaseUtil;
|
||||
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
|
||||
|
|
@ -29,6 +34,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.security.SecureRandom;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
|
@ -46,6 +52,8 @@ public class SyncOrganizationPersonInfo implements EsbServerlessRpcRemoteInterfa
|
|||
|
||||
@Autowired
|
||||
private DatabaseUtils databaseUtils;
|
||||
@Autowired
|
||||
private ComInfoCache comInfoCache;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SyncOrganizationPersonInfo.class);
|
||||
|
||||
|
|
@ -62,6 +70,7 @@ public class SyncOrganizationPersonInfo implements EsbServerlessRpcRemoteInterfa
|
|||
int code3;
|
||||
int code4 = 200;
|
||||
int code5 = 200;
|
||||
String yggh = "";
|
||||
String ygxxid = null!=params.get("ygxxid")?String.valueOf(params.get("ygxxid").toString()):"";
|
||||
String glzzyg = null!=params.get("glzzyg")?String.valueOf(params.get("glzzyg").toString()):"";
|
||||
//String tenant_key = null!=params.get("tenant_key")?String.valueOf(params.get("tenant_key").toString()):"";
|
||||
|
|
@ -178,6 +187,24 @@ public class SyncOrganizationPersonInfo implements EsbServerlessRpcRemoteInterfa
|
|||
log.error("SyncOrganizationPersonInfo.employee_info:{}", employee_info);
|
||||
//插入数据到employee表
|
||||
log.error("SyncOrganizationPersonInfo.employee_new:{}", employee_new);
|
||||
/**
|
||||
* 这里判断是否有系统人员工号自动生成规则
|
||||
*
|
||||
*/
|
||||
String tenant_key = getIgnoreCase(employee_info, "tenant_key");
|
||||
String ryid = getIgnoreCase(employee_info, "id");
|
||||
String rule_id = getRuleId(tenant_key);
|
||||
log.error("SyncOrganizationPersonInfo.tenant_key:{},ryid:{},rule_id:{}", tenant_key,ryid,rule_id);
|
||||
if(StringUtils.isBlank(rule_id)){
|
||||
//规则为空,则人员信息表工号
|
||||
yggh = getIgnoreCase(employee_info, "job_num");
|
||||
}else{
|
||||
//按照系统规则生成工号
|
||||
yggh = buildCode(tenant_key, ryid);
|
||||
//替换原本工号
|
||||
employee_new.put("job_num",yggh);
|
||||
}
|
||||
log.error("SyncOrganizationPersonInfo.yggh:{}", yggh);
|
||||
code = insert("eteams.employee",employee_new);
|
||||
//2查询基础信息自定义表
|
||||
String tableName = "ft_"+personCustomfieldFormid;
|
||||
|
|
@ -398,6 +425,7 @@ public class SyncOrganizationPersonInfo implements EsbServerlessRpcRemoteInterfa
|
|||
//if(code==200&&code2==200&&code3==200&&code4==200&&code5==200){
|
||||
result.put("code",200);
|
||||
result.put("msg","同步组织数据成功!");
|
||||
result.put("yggh",yggh);
|
||||
if(StringUtils.isNotBlank(glzzyg)){
|
||||
result.put("glzzyg",glzzyg);
|
||||
}else {
|
||||
|
|
@ -1398,4 +1426,161 @@ public class SyncOrganizationPersonInfo implements EsbServerlessRpcRemoteInterfa
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询规则id
|
||||
*/
|
||||
private String getRuleId(String teantKey){
|
||||
String rule_id="";
|
||||
String str = "select id from eteams.hrm_code_rule where serial_type='EMPLOYEE' and delete_type=0 and teant_key = '" + teantKey + "'";
|
||||
log.error("getRuleId.str:{}", str);
|
||||
Map<String, Object> st = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", str);
|
||||
List<Map<String, Object>> rule_ids = databaseUtils.getDataSourceList(st);
|
||||
log.error("getRuleId.rule_ids:{}", rule_ids);
|
||||
if(CollectionUtils.isNotEmpty(rule_ids)){
|
||||
rule_id = String.valueOf(rule_ids.get(0).get("current_number"));
|
||||
}
|
||||
return rule_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成编号
|
||||
*/
|
||||
private String buildCode(String teantKey,String ryid){
|
||||
//查询人员创建时间
|
||||
String create_time = "";
|
||||
String sql = "select create_time from eteams.employee where id ="+ryid;
|
||||
log.error("buildCode.sql:{}", sql);
|
||||
Map<String, Object> rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(rs);
|
||||
log.error("buildCode.recordList:{}", recordList);
|
||||
if(CollectionUtils.isNotEmpty(recordList)){
|
||||
create_time = String.valueOf(recordList.get(0).get("create_time"));
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDate localDate = LocalDate.parse(create_time, formatter);
|
||||
/**
|
||||
* 查询人员分部
|
||||
*/
|
||||
List<Long> empIds = new ArrayList<>();
|
||||
empIds.add(Long.valueOf(ryid));
|
||||
Map<Long, Long> subcompanyByEmpIds = HrmDepartmentUtil.findSubcompanyByEmpIds(empIds);
|
||||
log.error("buildCode.subcompanyByEmpIds:{}", subcompanyByEmpIds);
|
||||
Long subCompanyid = subcompanyByEmpIds.get(Long.valueOf(ryid));
|
||||
log.error("buildCode.subCompanyid:{}", subCompanyid);
|
||||
/**
|
||||
* 查询人员部门和岗位
|
||||
*/
|
||||
String deptid = "";
|
||||
String positionid = "";
|
||||
String sql3 = "select department,position from eteams.employee where delete_type=0 and tenant_key='" + teantKey + "' and id ="+ryid;
|
||||
log.error("buildCode.sql3:{}", sql3);
|
||||
Map<String, Object> rs3 = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql3);
|
||||
List<Map<String, Object>> recordList3 = databaseUtils.getDataSourceList(rs3);
|
||||
log.error("buildCode.recordList:{}", recordList3);
|
||||
if(CollectionUtils.isNotEmpty(recordList3)){
|
||||
deptid = String.valueOf(recordList3.get(0).get("department"));
|
||||
positionid = String.valueOf(recordList3.get(0).get("position"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 这里先查询出员工编号规则id
|
||||
*/
|
||||
String ruleId = getRuleId(teantKey);
|
||||
|
||||
//查询系统表编号规则详情
|
||||
String sql2 = "select rule_type,rule_value from eteams.hrm_code_rule_detail where rule_id = '" + ruleId + "' and teant_key = '" + teantKey + "' order by showorder asc ";
|
||||
log.error("buildCode.sql2:{}", sql2);
|
||||
Map<String, Object> rs2 = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql2);
|
||||
List<Map<String, Object>> codeRuleDetails = databaseUtils.getDataSourceList(rs2);
|
||||
log.error("buildCode.codeRuleDetails:{}", codeRuleDetails);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if(CollectionUtils.isNotEmpty(codeRuleDetails)){
|
||||
for (Map<String, Object> codeRuleDetail : codeRuleDetails) {
|
||||
String rule_type = String.valueOf(codeRuleDetail.get("rule_type"));
|
||||
String rule_value = String.valueOf(codeRuleDetail.get("rule_value"));
|
||||
if("STRING".equalsIgnoreCase(rule_type)){
|
||||
sb.append(rule_value);
|
||||
}
|
||||
if("YEAR".equalsIgnoreCase(rule_type)){
|
||||
sb.append(localDate.getYear());
|
||||
}
|
||||
if("MONTH".equalsIgnoreCase(rule_type)){
|
||||
sb.append(String.format("%02d",localDate.getMonthValue()));
|
||||
}
|
||||
if("DAY".equalsIgnoreCase(rule_type)){
|
||||
sb.append(String.format("%02d",localDate.getDayOfMonth()));
|
||||
}
|
||||
if("SUBCOMPANY".equalsIgnoreCase(rule_type)){
|
||||
HrmDepartmentComInfo subCompanyCache = comInfoCache.getCacheById(HrmDepartmentComInfo.class, subCompanyid);
|
||||
sb.append(subCompanyCache!=null?subCompanyCache.getCode():"");
|
||||
}
|
||||
if("DEPARTMENT".equalsIgnoreCase(rule_type)){
|
||||
HrmDepartmentComInfo departmentCache = comInfoCache.getCacheById(HrmDepartmentComInfo.class, deptid);
|
||||
sb.append(departmentCache!=null?departmentCache.getCode():"");
|
||||
}
|
||||
if("JOBTITLES".equalsIgnoreCase(rule_type)){
|
||||
HrmPositionComInfo jobtitleCache = comInfoCache.getCacheById(HrmPositionComInfo.class, positionid);
|
||||
sb.append(jobtitleCache!=null?jobtitleCache.getCode():"");
|
||||
}
|
||||
if("NUMBER".equalsIgnoreCase(rule_type)){
|
||||
int number = getNumber(teantKey);
|
||||
sb.append(String.format("%0"+rule_value+"d",number));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询起始编号
|
||||
*/
|
||||
private int getNumber(String teantKey) {
|
||||
//返回值
|
||||
int number = 1;
|
||||
//查询起始编号表
|
||||
int current_number = -1;
|
||||
int versions_num = -1;
|
||||
String ruleId = getRuleId(teantKey);
|
||||
String sql = "select current_number,versions_num from eteams.hrm_code_rule_record where code_rule_id ='" + ruleId + "' and delete_type=0 and tenant_key='" + teantKey + "'";
|
||||
log.error("getNumber.sql:{}", sql);
|
||||
Map<String, Object> rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
||||
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(rs);
|
||||
log.error("getNumber.recordList:{}", recordList);
|
||||
if (CollectionUtils.isNotEmpty(recordList)) {
|
||||
current_number = Integer.parseInt(recordList.get(0).get("current_number").toString());
|
||||
versions_num = Integer.parseInt(recordList.get(0).get("versions_num").toString());
|
||||
current_number = current_number + 1;
|
||||
versions_num = versions_num + 1;
|
||||
//流水号+1更新到原表中
|
||||
String str = "update eteams.hrm_code_rule_record set current_number='" + current_number + "',versions_num='" + versions_num + "' where code_rule_id ='" + ruleId + "' and delete_type=0 and tenant_key='" + teantKey + "'";
|
||||
log.error("getNumber3333.str:{}", str);
|
||||
Map<String, Object> rs2 = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", str);
|
||||
List<Map<String, Object>> recordList2 = databaseUtils.getDataSourceList(rs2);
|
||||
log.error("getNumber3333.recordList:{}", recordList2);
|
||||
number = current_number;
|
||||
} else {
|
||||
//为空,新增一条数据插入hrm_code_rule_record表
|
||||
long id = IdGenerator.generate();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// 获取当前日期时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 定义日期时间格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 格式化为字符串
|
||||
String formattedDateTime = now.format(formatter);
|
||||
map.put("id", id);
|
||||
map.put("create_time", formattedDateTime);
|
||||
map.put("tenant_key", teantKey);
|
||||
map.put("code_rule_id", ruleId);
|
||||
map.put("uniqueconstitute", "NULL-NULL-NULL-NULL-NULL-NULL");
|
||||
map.put("current_number", 1);
|
||||
map.put("versions_num", 1);
|
||||
insert("eteams.hrm_code_rule_record",map);
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ package com.weaver.seconddev.jcl.organization.esb;
|
|||
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.common.cache.tablecache.impl.ComInfoCache;
|
||||
import com.weaver.common.distribution.genid.IdGenerator;
|
||||
import com.weaver.common.hrm.cache.HrmDepartmentComInfo;
|
||||
import com.weaver.common.hrm.cache.HrmPositionComInfo;
|
||||
import com.weaver.common.mybatis.util.DatabaseUtil;
|
||||
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
|
||||
import com.weaver.seconddev.jcl.organization.util.DatabaseUtils;
|
||||
|
|
@ -14,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.security.SecureRandom;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
|
@ -36,6 +41,8 @@ public class SyncRzglPersonInfo implements EsbServerlessRpcRemoteInterface {
|
|||
|
||||
private static String nowData;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
|
||||
int code =200;
|
||||
|
|
@ -86,6 +93,7 @@ public class SyncRzglPersonInfo implements EsbServerlessRpcRemoteInterface {
|
|||
log.error("SyncRzglPersonInfo88888.map:{}", map);
|
||||
code = insert("uf_jcl_employee_information",map);
|
||||
log.error("SyncRzglPersonInfo.code:{}", code);
|
||||
|
||||
/**
|
||||
* 员工信息明细表数据同步处理
|
||||
*/
|
||||
|
|
@ -148,7 +156,6 @@ public class SyncRzglPersonInfo implements EsbServerlessRpcRemoteInterface {
|
|||
return WeaResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 写入表单引擎数据大表
|
||||
* @return
|
||||
|
|
|
|||
Loading…
Reference in New Issue