编制模块
parent
498da847b3
commit
d8d69381ea
@ -1,10 +0,0 @@
|
||||
package com.engine.organization.entity.staff.param;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/9/1 2:03 PM
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class TransactionParam {
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
package com.engine.organization.service.impl;
|
||||
|
||||
import com.engine.organization.entity.staff.param.StaffOutParam;
|
||||
import com.engine.organization.entity.staff.po.StaffPO;
|
||||
import com.engine.organization.enums.StaffChangeEnum;
|
||||
import com.engine.organization.mapper.staff.StaffMapper;
|
||||
import com.engine.organization.util.OrganizationAssert;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/9/4 10:44 AM
|
||||
* @Description: 函数式接口 function interface 实现
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class FunctionOutStaffServiceImpl {
|
||||
|
||||
private static final Integer HARDCONTROLLER = 2;
|
||||
|
||||
private static Map<StaffChangeEnum, Function<StaffOutParam, Integer>> affairFunctionS = new HashMap<>();
|
||||
|
||||
private StaffMapper staffMapper() {
|
||||
return MapperProxyFactory.getProxy(StaffMapper.class);
|
||||
}
|
||||
|
||||
FunctionOutStaffServiceImpl(){
|
||||
affairFunctionS.put(StaffChangeEnum.ADD, this::addStaffNums);
|
||||
affairFunctionS.put(StaffChangeEnum.REDUCE, this::reduceStaffNums);
|
||||
affairFunctionS.put(StaffChangeEnum.FROZEN, this::frozenStaffNums);
|
||||
affairFunctionS.put(StaffChangeEnum.ENTRY, this::entryAdd);
|
||||
affairFunctionS.put(StaffChangeEnum.DIMISSION, this::dimissionReduce);
|
||||
affairFunctionS.put(StaffChangeEnum.TRANSFER, this::transfer);
|
||||
}
|
||||
|
||||
|
||||
private Integer addStaffNums(StaffOutParam param) {
|
||||
StaffPO staffPO = select(param);
|
||||
List<Integer> numbers = Arrays.asList(staffPO.getStaffNum(),param.getNum());
|
||||
int sum = numbers.stream()
|
||||
.mapToInt(Integer::intValue)
|
||||
.sum();
|
||||
staffPO.setStaffNum(sum);
|
||||
return staffMapper().updateStaff(staffPO);
|
||||
}
|
||||
|
||||
private Integer reduceStaffNums(StaffOutParam param) {
|
||||
StaffPO staffPO = select(param);
|
||||
List<Integer> numbers = Arrays.asList(staffPO.getStaffNum(),param.getNum());
|
||||
Integer difference = numbers.stream()
|
||||
.reduce((a, b) -> a - b)
|
||||
.orElse(0);
|
||||
Integer sums = staffPO.getPermanentNum() + staffPO.getFreezeNum();
|
||||
if (staffPO.getControlPolicy().equals(HARDCONTROLLER)) {
|
||||
OrganizationAssert.isFalse(difference.compareTo(sums) < 0,"存在编制超编风险,请先修改控制策略");
|
||||
}
|
||||
staffPO.setStaffNum(difference);
|
||||
return staffMapper().updateStaff(staffPO);
|
||||
}
|
||||
|
||||
private Integer frozenStaffNums(StaffOutParam param) {
|
||||
StaffPO staffPO = select(param);
|
||||
List<Integer> numberF = Arrays.asList(staffPO.getFreezeNum(),param.getNum());
|
||||
//1.增加冻结数
|
||||
Integer sum = numberF.stream()
|
||||
.mapToInt(Integer::intValue)
|
||||
.sum();
|
||||
if (staffPO.getControlPolicy().equals(HARDCONTROLLER)) {
|
||||
OrganizationAssert.isFalse(sum.compareTo(staffPO.getStaffNum()) > 0, "冻结数不能大于剩余编制数!");
|
||||
}
|
||||
staffPO.setFreezeNum(sum);
|
||||
return staffMapper().updateStaff(staffPO);
|
||||
}
|
||||
|
||||
|
||||
private Integer entryAdd(StaffOutParam param) {
|
||||
StaffPO staffPO = select(param);
|
||||
Integer sums = staffPO.getPermanentNum() + staffPO.getFreezeNum();
|
||||
//强控策略下不容许超编
|
||||
if (staffPO.getControlPolicy().equals(HARDCONTROLLER)) {
|
||||
OrganizationAssert.isFalse(sums.compareTo(staffPO.getStaffNum()) > 0,"强控策略下不容许超编");
|
||||
}
|
||||
List<Integer> numbers = Arrays.asList(staffPO.getPermanentNum(),param.getNum());
|
||||
//1.增加在编数
|
||||
int sum = numbers.stream()
|
||||
.mapToInt(Integer::intValue)
|
||||
.sum();
|
||||
staffPO.setPermanentNum(sum);
|
||||
// todo 向上部门 分部在编数调整
|
||||
//2.调整方式为流程时释放冻结数
|
||||
if (param.getChangeMode() == 1) {
|
||||
List<Integer> numbersF = Arrays.asList(staffPO.getFreezeNum(),param.getNum());
|
||||
int difference = numbersF.stream()
|
||||
.reduce((a, b) -> a - b)
|
||||
.orElse(0);
|
||||
staffPO.setFreezeNum(difference);
|
||||
}
|
||||
return staffMapper().updateStaff(staffPO);
|
||||
}
|
||||
|
||||
private Integer dimissionReduce(StaffOutParam param) {
|
||||
StaffPO staffPO = select(param);
|
||||
OrganizationAssert.isFalse(param.getNum().compareTo(staffPO.getPermanentNum()) > 0,"调整数量不可大于在编数");
|
||||
List<Integer> numbers = Arrays.asList(staffPO.getPermanentNum(),param.getNum());
|
||||
Integer difference = numbers.stream()
|
||||
.reduce((a, b) -> a - b)
|
||||
.orElse(0);
|
||||
staffPO.setPermanentNum(difference);
|
||||
// todo 向上部门 分部在编数调整
|
||||
//2.调整方式为流程时释放冻结数
|
||||
if (param.getChangeMode() == 1) {
|
||||
List<Integer> numbersF = Arrays.asList(staffPO.getFreezeNum(),param.getNum());
|
||||
int differenceF = numbersF.stream()
|
||||
.reduce((a, b) -> a - b)
|
||||
.orElse(0);
|
||||
staffPO.setFreezeNum(differenceF);
|
||||
}
|
||||
return staffMapper().updateStaff(staffPO);
|
||||
}
|
||||
|
||||
private Integer transfer(StaffOutParam param) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private StaffPO select(StaffOutParam param) {
|
||||
StaffPO staffPO = staffMapper().customSelect(param.getPlanId(), param.getCompany(), param.getDepartment(), param.getJob());
|
||||
OrganizationAssert.notNull(staffPO,"未查询到对应编制方案下的组织编制信息!");
|
||||
return staffPO;
|
||||
}
|
||||
|
||||
|
||||
public Integer actuator(StaffChangeEnum functionEnum,StaffOutParam staffOutParam) {
|
||||
Function<StaffOutParam, Integer> function = affairFunctionS.get(functionEnum);
|
||||
return function.apply(staffOutParam);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue