weaver-hrm-organization/src/com/engine/organization/service/impl/StaffServiceImpl.java

535 lines
25 KiB
Java
Raw Normal View History

2022-05-26 10:11:02 +08:00
package com.engine.organization.service.impl;
2022-08-03 18:35:42 +08:00
import com.alibaba.fastjson.JSONObject;
2022-05-26 10:11:02 +08:00
import com.api.browser.bean.BrowserBean;
import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.core.impl.Service;
import com.engine.organization.component.OrganizationWeaTable;
2022-06-01 14:38:39 +08:00
import com.engine.organization.entity.DeleteParam;
2022-08-03 18:35:42 +08:00
import com.engine.organization.entity.browser.po.CustomBrowserBean;
2022-09-06 10:33:46 +08:00
import com.engine.organization.entity.department.po.DepartmentPO;
2022-11-16 17:39:58 +08:00
import com.engine.organization.entity.job.po.JobPO;
2022-05-26 10:11:02 +08:00
import com.engine.organization.entity.staff.bo.StaffBO;
2023-09-06 17:17:10 +08:00
import com.engine.organization.entity.staff.param.StaffParams;
import com.engine.organization.entity.staff.param.StaffSerachParam;
2022-05-26 10:11:02 +08:00
import com.engine.organization.entity.staff.po.StaffPO;
2022-08-10 15:25:34 +08:00
import com.engine.organization.entity.staff.po.StaffPlanPO;
2022-06-08 09:01:13 +08:00
import com.engine.organization.entity.staff.po.StaffsPO;
2022-05-26 10:11:02 +08:00
import com.engine.organization.entity.staff.vo.StaffTableVO;
2023-09-06 17:17:10 +08:00
import com.engine.organization.exception.OrganizationRunTimeException;
import com.engine.organization.mapper.department.DepartmentMapper;
2022-05-30 18:39:03 +08:00
import com.engine.organization.mapper.job.JobMapper;
2022-05-26 10:11:02 +08:00
import com.engine.organization.mapper.staff.StaffMapper;
import com.engine.organization.mapper.staff.StaffPlanMapper;
2022-06-08 09:01:13 +08:00
import com.engine.organization.mapper.staff.StaffsMapper;
2022-05-26 10:11:02 +08:00
import com.engine.organization.service.StaffService;
2022-06-07 12:02:36 +08:00
import com.engine.organization.util.*;
2022-09-06 10:33:46 +08:00
import com.engine.organization.util.browser.OrganizationBrowserUtil;
2022-05-26 10:11:02 +08:00
import com.engine.organization.util.db.DBType;
import com.engine.organization.util.db.MapperProxyFactory;
import com.engine.organization.util.excel.ExcelUtil;
2023-09-14 16:22:56 +08:00
import org.apache.commons.collections.CollectionUtils;
2022-05-26 10:11:02 +08:00
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2022-05-26 10:11:02 +08:00
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
2022-05-26 10:11:02 +08:00
import weaver.general.StringUtil;
import weaver.general.Util;
2023-09-07 16:50:42 +08:00
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
2022-05-26 10:11:02 +08:00
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
2022-05-26 10:11:02 +08:00
import java.util.*;
/**
2022-06-14 11:07:48 +08:00
* @description:
2022-05-26 10:11:02 +08:00
* @author:dxfeng
* @createTime: 2022/05/25
* @version: 1.0
*/
public class StaffServiceImpl extends Service implements StaffService {
2022-06-07 12:02:36 +08:00
private static final String RIGHT_NAME = "Staff:All";
2023-09-08 10:53:46 +08:00
private static final Integer HARDCONTROLLER = 2;
2022-05-26 10:11:02 +08:00
private StaffMapper getStaffMapper() {
return MapperProxyFactory.getProxy(StaffMapper.class);
}
private StaffPlanMapper getStaffPlanMapper() {
return MapperProxyFactory.getProxy(StaffPlanMapper.class);
}
2022-05-30 18:39:03 +08:00
private JobMapper getJobMapper() {
return MapperProxyFactory.getProxy(JobMapper.class);
}
2022-05-26 10:11:02 +08:00
private DepartmentMapper getDepartmentMapper() {
return MapperProxyFactory.getProxy(DepartmentMapper.class);
}
// 判断编制导入模板是否存在,不存在则创建该文件
static {
try {
2022-10-25 16:24:18 +08:00
String outPutPath = GCONST.getRootPath() + File.separator + "hrm" + File.separator + "import" + File.separator + "template" + File.separator + "staff.xls";
File excelPathFile = new File(outPutPath);
if (!excelPathFile.exists()) {
String columns = "方案编号,方案名称,分部,部门,岗位,编制数";
String[] split = columns.split(",");
List<Object> columnList = new ArrayList<>(Arrays.asList(split));
// 创建导入模板
List<List<Object>> excelSheetData = new ArrayList<>();
excelSheetData.add(columnList);
XSSFWorkbook sheets = ExcelUtil.genWorkbookV2(excelSheetData, "staff");
File excelFile = new File(outPutPath);
if (!excelFile.exists()) {
String substring = outPutPath.substring(0, outPutPath.lastIndexOf(File.separator));
File file = new File(substring);
if (file.mkdirs()) {
boolean newFile = excelPathFile.createNewFile();
if (!newFile) {
throw new IOException(outPutPath + "文件创建失败");
}
}
}
FileOutputStream out = new FileOutputStream(excelPathFile);
sheets.write(out);
out.flush();
}
} catch (IOException e) {
new BaseBean().writeLog(e);
throw new RuntimeException(e);
}
}
2022-05-26 10:11:02 +08:00
@Override
2023-09-06 17:17:10 +08:00
public Map<String, Object> listPage(StaffSerachParam params) {
2022-06-06 19:19:28 +08:00
Map<String, Object> resultMap = new HashMap<>();
2022-06-07 12:02:36 +08:00
boolean hasRight = HasRightUtil.hasRight(user, RIGHT_NAME, true);
resultMap.put("hasRight", hasRight);
if (!hasRight) {
2022-06-06 19:19:28 +08:00
return resultMap;
}
// 刷新引用状态
RefreshIsUsedUtil.RefreshStaff("jcl_org_staff");
2022-05-26 10:11:02 +08:00
OrganizationWeaTable<StaffTableVO> table = new OrganizationWeaTable<>(user, StaffTableVO.class);
2022-06-07 14:57:17 +08:00
String sqlWhere = buildSqlWhere(params);
2022-05-26 10:11:02 +08:00
table.setSqlwhere(sqlWhere);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
2022-06-06 19:19:28 +08:00
resultMap.putAll(result.getResultMap());
return resultMap;
2022-05-26 10:11:02 +08:00
}
@Override
2023-09-06 17:17:10 +08:00
public int saveStaff(StaffParams param) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-05-26 10:11:02 +08:00
StaffPO staffPO = StaffBO.convertParamToPO(param, (long) user.getUID());
2022-08-17 19:29:46 +08:00
OrganizationAssert.isFalse(staffPO.getStaffNum() < 0, "编制数不可小于0请更正");
2023-09-06 17:17:10 +08:00
List<StaffPO> verify = getStaffMapper().customSelect(param.getPlanId(), param.getEcCompany(), param.getEcDepartment(), param.getJobId());
2023-09-07 16:50:42 +08:00
if (!verify.isEmpty()) {
2023-09-06 17:17:10 +08:00
throw new OrganizationRunTimeException("同一编制方案下,同一维度的编制信息不可重复创建!");
}
2022-09-06 14:01:01 +08:00
checkRequired(staffPO);
int ignoreNull = getStaffMapper().insertIgnoreNull(staffPO);
2023-07-24 10:32:10 +08:00
// 初始化编制在编数
initStaffInfo(staffPO);
return ignoreNull;
2022-05-26 10:11:02 +08:00
}
@Override
2023-09-06 17:17:10 +08:00
public int updateStaff(StaffParams param) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2023-09-06 17:17:10 +08:00
List<StaffPO> verify = getStaffMapper().customSelect(param.getPlanId(), param.getEcCompany(), param.getEcDepartment(), param.getJobId());
if (verify.size() > 1) {
throw new OrganizationRunTimeException("同一编制方案下,同一维度的编制信息已存在!");
}
2022-06-08 09:01:13 +08:00
StaffPO staffByID = getStaffMapper().getStaffByID(param.getId());
StaffPO staffPO = StaffBO.convertParamToPO(param, (long) user.getUID());
2022-09-30 11:05:42 +08:00
staffPO.setPermanentNum(staffByID.getPermanentNum());
staffPO.setFreezeNum(staffByID.getFreezeNum());
2022-09-06 14:01:01 +08:00
checkRequired(staffPO);
2022-11-16 17:39:58 +08:00
2022-06-08 09:01:13 +08:00
Integer changeNum = param.getChangeNum();
if (null == changeNum) {
// 插入明细表数据
StaffsPO staffsPO = StaffsPO.builder().staffId(staffPO.getId()).businessType(1).changeNum(staffPO.getStaffNum() - staffByID.getStaffNum()).businessSource(1).build();
MapperProxyFactory.getProxy(StaffsMapper.class).insertIgnoreNull(staffsPO);
} else {
// 插入明细表数据
2022-06-23 14:29:56 +08:00
StaffsPO staffsPO = StaffsPO.builder().staffId(staffPO.getId()).businessType(2).changeNum(changeNum).businessSource(1).description(param.getChangeDescription()).build();
2022-06-08 09:01:13 +08:00
MapperProxyFactory.getProxy(StaffsMapper.class).insertIgnoreNull(staffsPO);
// 更新编制表
staffPO.setStaffNum(staffPO.getStaffNum() + changeNum);
}
2022-06-08 10:38:04 +08:00
OrganizationAssert.isFalse(staffPO.getStaffNum() < 0, "调整后编制数小于0请更正");
2022-06-08 09:01:13 +08:00
StaffBO.buildStaffDesc(staffPO);
2023-09-08 10:53:46 +08:00
if (staffPO.getControlPolicy().equals(HARDCONTROLLER) && staffPO.getStaffNum() < (staffPO.getPermanentNum() + staffPO.getFreezeNum())){
throw new OrganizationRunTimeException("存在编制超编风险,请先修改控制策略");
}
2022-06-08 09:01:13 +08:00
// 更新主表
int updateStaff = getStaffMapper().updateStaff(staffPO);
// 同步组织架构图编制信息
2022-12-16 16:21:54 +08:00
//new StaffTriggerRunnable(staffPO).run();
return updateStaff;
2022-05-26 10:11:02 +08:00
}
@Override
public int deleteByIds(Collection<Long> ids) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-05-26 10:11:02 +08:00
OrganizationAssert.notEmpty(ids, "请选择要删除的数据");
List<StaffPO> staffsByIds = getStaffMapper().getStaffsByIds(ids);
int deleteByIds = getStaffMapper().deleteByIds(ids);
2022-12-16 16:21:54 +08:00
//for (StaffPO staffsById : staffsByIds) {
// new StaffTriggerRunnable(staffsById).run();
//}
return deleteByIds;
2022-05-26 10:11:02 +08:00
}
@Override
public Map<String, Object> getSearchCondition(Map<String, Object> params) {
Map<String, Object> apiDatas = new HashMap<>();
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> conditionItems = new ArrayList<>();
2022-09-06 10:33:46 +08:00
2022-05-26 10:11:02 +08:00
// 分部
2022-09-06 10:33:46 +08:00
SearchConditionItem compIdItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "分部", "164", "ecCompany", "");
2022-05-26 10:11:02 +08:00
// 部门
2022-09-06 10:33:46 +08:00
SearchConditionItem deptIdItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "部门", "4", "ecDepartment", "");
2022-05-26 10:11:02 +08:00
// 岗位
2022-09-06 10:33:46 +08:00
SearchConditionItem jobIdItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "岗位", "666", "jobId", "");
2022-05-26 10:11:02 +08:00
// 编制数
SearchConditionItem staffNumItem = OrganizationFormItemUtil.inputNumberItem(user, 2, 16, 2, "编制数", "staffNum");
// 在编
SearchConditionItem permanentNumItem = OrganizationFormItemUtil.inputNumberItem(user, 2, 16, 2, "在编", "permanentNum");
// 冻结数
SearchConditionItem freezeNumItem = OrganizationFormItemUtil.inputNumberItem(user, 2, 16, 2, "冻结数", "freezeNum");
// 缺编状态
List<SearchConditionOption> selectOptions = new ArrayList<>();
SearchConditionOption lackOption = new SearchConditionOption("1", "缺编");
SearchConditionOption fullOption = new SearchConditionOption("2", "满员");
SearchConditionOption overOption = new SearchConditionOption("3", "超编");
selectOptions.add(lackOption);
selectOptions.add(fullOption);
selectOptions.add(overOption);
SearchConditionItem lackStatusItem = OrganizationFormItemUtil.selectItem(user, selectOptions, 2, 16, 6, false, "缺编状态", "lackStatus");
// 编制描述
SearchConditionItem staffDescItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 2, 50, "编制描述", "staffDesc");
// 说明
SearchConditionItem descriptionItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 2, 50, "说明", "description");
2022-05-26 11:03:04 +08:00
2022-06-23 16:55:26 +08:00
//conditionItems.add(planIdItem);
2022-05-26 11:03:04 +08:00
conditionItems.add(compIdItem);
conditionItems.add(deptIdItem);
conditionItems.add(jobIdItem);
2022-05-26 10:11:02 +08:00
conditionItems.add(staffNumItem);
conditionItems.add(permanentNumItem);
conditionItems.add(freezeNumItem);
conditionItems.add(lackStatusItem);
conditionItems.add(staffDescItem);
conditionItems.add(descriptionItem);
addGroups.add(new SearchConditionGroup("高级搜索条件", true, conditionItems));
apiDatas.put("conditions", addGroups);
return apiDatas;
}
@Override
public Map<String, Object> getForm(Map<String, Object> params) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-05-26 10:11:02 +08:00
Map<String, Object> apiDatas = new HashMap<>();
List<SearchConditionItem> selectItems = new ArrayList<>();
List<SearchConditionGroup> addGroups = new ArrayList<>();
// 方案
2022-06-23 16:55:26 +08:00
SearchConditionItem planIdItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 3, false, "方案", "161", "planId", "staffPlanBrowser");
2022-08-08 08:55:24 +08:00
planIdItem.setRules("required|string");
2023-09-15 10:28:37 +08:00
planIdItem.setIsQuickSearch(false);
planIdItem.setEntSearch(false);
2022-05-26 10:11:02 +08:00
// 分部
2022-09-06 10:33:46 +08:00
SearchConditionItem ecCompanyItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "分部", "164", "ecCompany", "compBrowser");
2022-05-26 10:11:02 +08:00
// 部门
2022-09-06 10:33:46 +08:00
SearchConditionItem ecDepartmentItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "部门", "4", "ecDepartment", "deptBrowser");
2022-05-26 10:11:02 +08:00
// 岗位
2022-08-05 15:21:56 +08:00
SearchConditionItem jobIdItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "岗位", "666", "jobId", "");
2022-08-03 18:35:42 +08:00
BrowserBean browserBean = jobIdItem.getBrowserConditionParam();
String s = JSONObject.toJSONString(browserBean);
CustomBrowserBean customBrowserBean = JSONObject.parseObject(s, CustomBrowserBean.class);
customBrowserBean.setHasLeftTree(true);
customBrowserBean.setLeftToSearchKey("treeKey");
jobIdItem.setBrowserConditionParam(customBrowserBean);
2022-05-26 10:11:02 +08:00
// 编制数
SearchConditionItem staffNumItem = OrganizationFormItemUtil.inputNumberItem(user, 2, 16, 3, "编制数", "staffNum");
2022-06-07 13:44:29 +08:00
staffNumItem.setRules("required");
staffNumItem.setMin("0");
2022-05-26 10:11:02 +08:00
// 控制策略
List<SearchConditionOption> selectOptions = new ArrayList<>();
SearchConditionOption option1 = new SearchConditionOption("1", "弱控");
SearchConditionOption option2 = new SearchConditionOption("2", "强控");
SearchConditionOption option3 = new SearchConditionOption("3", "不控");
selectOptions.add(option1);
selectOptions.add(option2);
selectOptions.add(option3);
2022-09-06 10:34:23 +08:00
SearchConditionItem controlPolicyItem = OrganizationFormItemUtil.selectItem(user, selectOptions, 2, 16, 6, false, "控制策略", "controlPolicy");
2022-05-26 10:11:02 +08:00
controlPolicyItem.setViewAttr(3);
2022-09-06 10:34:23 +08:00
controlPolicyItem.setValue("1");
2022-05-26 10:11:02 +08:00
controlPolicyItem.setRules("required|string");
2022-09-06 10:34:23 +08:00
SearchConditionItem descriptionItem = OrganizationFormItemUtil.textareaItem(user, 2, 16, true, 2, 200, "描述说明", "description");
2022-06-08 09:01:13 +08:00
2023-09-14 16:22:56 +08:00
StaffPlanPO staffPlanPO = new StaffPlanPO();
2022-05-26 10:11:02 +08:00
// 编辑状态下赋值操作
String id = Util.null2String(params.get("id"));
if (!StringUtil.isEmpty(id)) {
StaffPO staffPO = getStaffMapper().getStaffByID(Integer.parseInt(id));
OrganizationAssert.notNull(staffPO, "选择的数据不存在,或数据已删除");
2023-09-14 16:22:56 +08:00
staffPlanPO = getStaffPlanMapper().getStaffPlanByID(staffPO.getPlanId());
2022-05-26 10:11:02 +08:00
BrowserBean planIdItemBean = planIdItem.getBrowserConditionParam();
2022-06-01 14:38:39 +08:00
List<Map<String, Object>> planIdMaps = getStaffPlanMapper().listPlansByIds(DeleteParam.builder().ids(staffPO.getPlanId().toString()).build().getIds());
2022-05-26 11:03:04 +08:00
planIdItemBean.setReplaceDatas(planIdMaps);
2022-05-26 10:11:02 +08:00
planIdItem.setBrowserConditionParam(planIdItemBean);
2022-09-06 10:33:46 +08:00
if (null != staffPO.getEcCompany()) {
OrganizationBrowserUtil.assignBrowser(user, staffPO.getEcCompany().toString(), 164, ecCompanyItem);
2022-08-10 15:25:34 +08:00
}
2022-09-06 10:33:46 +08:00
if (null != staffPO.getEcDepartment()) {
OrganizationBrowserUtil.assignBrowser(user, staffPO.getEcDepartment().toString(), 4, ecDepartmentItem);
2022-08-10 15:25:34 +08:00
}
if (null != staffPO.getJobId()) {
BrowserBean jobIdItemBean = jobIdItem.getBrowserConditionParam();
List<Map<String, Object>> jobIdMaps = getJobMapper().listJobsByIds(DeleteParam.builder().ids(staffPO.getJobId().toString()).build().getIds());
jobIdItemBean.setReplaceDatas(jobIdMaps);
jobIdItem.setBrowserConditionParam(jobIdItemBean);
}
2022-05-26 11:03:04 +08:00
staffNumItem.setValue(staffPO.getStaffNum());
2022-09-09 10:25:57 +08:00
controlPolicyItem.setValue(Util.null2String(staffPO.getControlPolicy()));
2022-06-08 09:01:13 +08:00
descriptionItem.setValue(staffPO.getDescription());
2022-05-26 10:11:02 +08:00
}
2022-05-26 11:03:04 +08:00
selectItems.add(planIdItem);
2023-09-14 16:22:56 +08:00
if (StringUtil.isEmpty(id) || "1".equals(staffPlanPO.getControlDimension())) {
selectItems.add(ecCompanyItem);
}
if (StringUtil.isEmpty(id) || "2".equals(staffPlanPO.getControlDimension())) {
selectItems.add(ecDepartmentItem);
}
if (StringUtil.isEmpty(id) || "3".equals(staffPlanPO.getControlDimension())) {
selectItems.add(jobIdItem);
}
2022-05-26 11:03:04 +08:00
selectItems.add(staffNumItem);
selectItems.add(controlPolicyItem);
2022-06-08 09:01:13 +08:00
selectItems.add(descriptionItem);
2022-06-08 10:38:04 +08:00
String operateType = (String) params.get("operateType");
2022-06-08 09:01:13 +08:00
if ("2".equals(operateType)) {
2022-06-08 10:38:04 +08:00
selectItems.forEach(item -> {
item.setViewAttr(1);
item.setRules(null);
});
2022-06-08 09:01:13 +08:00
SearchConditionItem changeNumItem = OrganizationFormItemUtil.inputNumberItem(user, 2, 16, 3, "调整数量", "changeNum");
2022-09-08 10:41:04 +08:00
changeNumItem.setHelpfulTip("提示:正数为增加,负数为减少编制数");
2022-06-08 09:01:13 +08:00
staffNumItem.setRules("required");
selectItems.add(changeNumItem);
2022-06-23 14:29:56 +08:00
SearchConditionItem changeDescriptionItem = OrganizationFormItemUtil.textareaItem(user, 2, 16, false, 2, 50, "变更说明", "changeDescription");
selectItems.add(changeDescriptionItem);
2022-06-08 09:01:13 +08:00
}
2022-05-26 10:11:02 +08:00
addGroups.add(new SearchConditionGroup("基本信息", true, selectItems));
apiDatas.put("condition", addGroups);
return apiDatas;
}
@Override
public Map<String, Object> getHasRight() {
2022-09-14 17:14:12 +08:00
Map<String, List<MenuBtn>> datas = MenuBtn.getCommonBtnDatas();
datas.get("topMenu").add(MenuBtn.builder().isBatch("1").isTop("1").menuFun("import").menuIcon("icon-coms-leading-in").menuName("批量导入").type("BTN_BatchImport").build());
datas.get("rightMenu").add(MenuBtn.builder().isBatch("1").isTop("0").menuFun("import").menuIcon("icon-coms-leading-in").menuName("批量导入").type("BTN_BatchImport").build());
Map<String, Object> map = new HashMap<>(datas);
2022-06-23 13:43:52 +08:00
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> selectItems = new ArrayList<>();
// 方案
2023-09-06 17:17:10 +08:00
SearchConditionItem planIdItem = OrganizationFormItemUtil.browserItem(user, 4, 3, 2, false, "编制方案", "162", "planId", "staffPlanBrowser");
2022-06-23 13:43:52 +08:00
planIdItem.setRules("required|string");
2022-06-23 15:42:12 +08:00
planIdItem.setHelpfulTip("请选择编制方案后查看数据");
planIdItem.setLabelcol(2);
2022-09-14 17:14:12 +08:00
2022-06-23 13:43:52 +08:00
selectItems.add(planIdItem);
addGroups.add(new SearchConditionGroup("基本信息", true, selectItems));
2022-09-14 17:14:12 +08:00
map.put("condition", addGroups);
return map;
2022-05-26 10:11:02 +08:00
}
/**
* 查询条件
*
2022-06-07 14:57:17 +08:00
* @param param
2022-05-26 10:11:02 +08:00
* @return
*/
2023-09-06 17:17:10 +08:00
private String buildSqlWhere(StaffSerachParam param) {
2022-05-26 10:11:02 +08:00
DBType dbType = DBType.get(new RecordSet().getDBType());
String sqlWhere = " where t.delete_type ='0' ";
2023-09-06 17:17:10 +08:00
String planId = param.getPlanId();
2023-09-07 10:43:56 +08:00
if (!"".equals(planId)) {
2023-09-06 17:17:10 +08:00
sqlWhere += " AND t.plan_id in (" + planId + ")";
2022-06-23 13:43:52 +08:00
} else {
sqlWhere = " where 1 = 2 ";
2022-05-26 10:11:02 +08:00
}
2022-11-28 11:15:54 +08:00
Integer compId = param.getCompId();
2022-05-26 10:11:02 +08:00
if (null != compId) {
sqlWhere += " AND t.comp_id = '" + compId + "'";
}
Integer deptId = param.getDeptId();
2022-05-26 10:11:02 +08:00
if (null != deptId) {
sqlWhere += " AND t.dept_id = '" + deptId + "'";
}
2022-11-28 11:15:54 +08:00
Integer ecCompany = param.getEcCompany();
2022-09-06 10:33:46 +08:00
if (null != ecCompany) {
sqlWhere += " AND t.ec_company = '" + ecCompany + "'";
}
Integer ecDepartment = param.getEcDepartment();
2022-09-06 10:33:46 +08:00
if (null != ecDepartment) {
sqlWhere += " AND t.ec_department = '" + ecDepartment + "'";
}
2023-09-06 09:55:43 +08:00
Integer jobId = param.getJobId();
2022-05-26 10:11:02 +08:00
if (null != jobId) {
sqlWhere += " AND t.job_id = '" + jobId + "'";
}
2022-06-07 14:57:17 +08:00
Integer staffNum = param.getStaffNum();
2022-05-26 10:11:02 +08:00
if (null != staffNum) {
sqlWhere += " AND t.staff_num = '" + staffNum + "'";
}
2022-06-07 14:57:17 +08:00
Integer controlPolicy = param.getControlPolicy();
2022-05-26 10:11:02 +08:00
if (null != controlPolicy) {
sqlWhere += " AND t.control_policy = '" + controlPolicy + "'";
}
2022-06-07 14:57:17 +08:00
Integer permanentNum = param.getPermanentNum();
2022-05-26 10:11:02 +08:00
if (null != permanentNum) {
sqlWhere += " AND t.permanent_num = '" + permanentNum + "'";
}
2022-06-07 14:57:17 +08:00
Integer freezeNum = param.getFreezeNum();
2022-05-26 10:11:02 +08:00
if (null != freezeNum) {
sqlWhere += " AND t.freeze_num = '" + freezeNum + "'";
}
2022-06-07 14:57:17 +08:00
Integer lackStatus = param.getLackStatus();
2022-05-26 10:11:02 +08:00
if (null != lackStatus) {
sqlWhere += " AND t.lack_status = '" + lackStatus + "'";
}
2022-06-07 14:57:17 +08:00
String staffDesc = param.getStaffDesc();
2022-05-26 10:11:02 +08:00
if (StringUtils.isNotBlank(staffDesc)) {
sqlWhere += " AND t.staff_desc " + dbType.like(staffDesc);
}
2022-06-07 14:57:17 +08:00
String description = param.getDescription();
2022-05-26 10:11:02 +08:00
if (StringUtils.isNotBlank(description)) {
sqlWhere += " AND t.description " + dbType.like(description);
}
2022-06-07 14:57:17 +08:00
String staffName = param.getStaffName();
if (StringUtils.isNotBlank(staffName)) {
sqlWhere += " AND t.plan_id in ( select id from jcl_org_staffplan where plan_name " + dbType.like(staffName) + ") ";
}
2022-05-26 10:11:02 +08:00
return sqlWhere;
}
2022-06-06 19:19:28 +08:00
2022-08-10 15:25:34 +08:00
/**
* 校验必填字段
*
* @param staffPO
*/
private void checkRequired(StaffPO staffPO) {
// 根据维度、校验必填字段
StaffPlanPO staffPlanByID = getStaffPlanMapper().getStaffPlanByID(staffPO.getPlanId());
switch (staffPlanByID.getControlDimension()) {
case "1":// 分部
2022-09-06 14:01:01 +08:00
OrganizationAssert.notNull(staffPO.getEcCompany(), "编制维度选择分部时,分部必填!");
2022-11-28 11:15:54 +08:00
staffPO.setCompId(staffPO.getEcCompany());
2022-08-10 15:25:34 +08:00
break;
case "2":// 部门
2022-09-06 14:01:01 +08:00
OrganizationAssert.notNull(staffPO.getEcDepartment(), "编制维度选择部门时,部门必填!");
DepartmentPO jclDepartmentId = getDepartmentMapper().getDeptById(staffPO.getEcDepartment());
2022-11-16 17:39:58 +08:00
if (null != jclDepartmentId) {
staffPO.setDeptId(jclDepartmentId.getId());
staffPO.setCompId(jclDepartmentId.getSubCompanyId1());
staffPO.setEcCompany(jclDepartmentId.getSubCompanyId1());
2022-11-16 17:39:58 +08:00
}
2022-08-10 15:25:34 +08:00
break;
case "3": // 岗位
OrganizationAssert.notNull(staffPO.getJobId(), "编制维度选择岗位时,岗位必填!");
2023-09-06 09:55:43 +08:00
JobPO jobById = getJobMapper().getJobById(Long.valueOf(staffPO.getJobId()));
2022-11-16 17:39:58 +08:00
if (null != jobById) {
2022-12-09 14:29:20 +08:00
staffPO.setDeptId(jobById.getEcDepartment());
2022-11-16 17:39:58 +08:00
staffPO.setEcDepartment(jobById.getEcDepartment());
2022-12-09 14:29:20 +08:00
staffPO.setCompId(jobById.getEcCompany());
2022-11-16 17:39:58 +08:00
staffPO.setEcCompany(jobById.getEcCompany());
}
2022-08-10 15:25:34 +08:00
break;
default:
break;
}
}
2023-07-24 10:32:10 +08:00
/**
* 初始化编制在编数
*
* @param staffPO 编制信息实体列
*/
public static void initStaffInfo(StaffPO staffPO) {
2023-09-07 16:50:42 +08:00
boolean hasDepartment = null != staffPO.getEcDepartment() && 0 != staffPO.getEcDepartment();
boolean hasJob = null != staffPO.getJobId() && 0 != staffPO.getJobId();
2023-07-24 10:32:10 +08:00
RecordSet rs = new RecordSet();
String sql = "select count(1) as num from hrmresource where STATUS < 4";
if (null != staffPO.getEcCompany() && 0 != staffPO.getEcCompany()) {
2023-09-07 16:50:42 +08:00
ArrayList<String> subCompanyList = new ArrayList<>();
subCompanyList.add(staffPO.getEcCompany().toString());
if (!hasJob && !hasDepartment) {
new SubCompanyComInfo().getSubCompanyLists(staffPO.getEcCompany().toString(), subCompanyList);
}
sql += " and subcompanyid1 in (" + StringUtils.join(subCompanyList, ",") + ")";
2023-07-24 10:32:10 +08:00
}
2023-09-07 16:50:42 +08:00
if (hasDepartment) {
ArrayList<String> departmentList = new ArrayList<>();
departmentList.add(staffPO.getEcDepartment().toString());
if (!hasJob) {
new DepartmentComInfo().getAllChildDeptByDepId(departmentList, staffPO.getEcDepartment().toString());
}
sql += " and departmentid in (" + StringUtils.join(departmentList, ",") + ")";
2023-07-24 10:32:10 +08:00
}
2023-09-07 16:50:42 +08:00
if (hasJob) {
2023-09-06 09:55:43 +08:00
JobPO jobById = MapperProxyFactory.getProxy(JobMapper.class).getJobById(Long.valueOf(staffPO.getJobId()));
2023-07-24 10:32:10 +08:00
if (null == jobById) {
return;
}
Integer ecJobTitle = jobById.getEcJobTitle();
sql += " and jobtitle = " + ecJobTitle;
}
if ("false".equals(new BaseBean().getPropValue("hrmOrganization","accountType"))) {
sql += " and accounttype != 1";
}
2023-07-24 10:32:10 +08:00
rs.executeQuery(sql);
if (rs.next()) {
staffPO.setPermanentNum(-1 == rs.getInt("num") ? 0 : rs.getInt("num"));
StaffBO.buildStaffDesc(staffPO);
MapperProxyFactory.getProxy(StaffMapper.class).updateStaff(staffPO);
}
}
2022-05-26 10:11:02 +08:00
}