|
@@ -1,9 +1,10 @@
|
|
package nckd.jimin.jyyy.fi.plugin.operate.Helper;
|
|
package nckd.jimin.jyyy.fi.plugin.operate.Helper;
|
|
|
|
|
|
-import json.JSON;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import kd.bos.context.RequestContext;
|
|
import kd.bos.context.RequestContext;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.entity.EntityMetadataCache;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.exception.KDBizException;
|
|
import kd.bos.exception.KDBizException;
|
|
import kd.bos.logging.BizLog;
|
|
import kd.bos.logging.BizLog;
|
|
@@ -18,10 +19,13 @@ import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
import kd.fi.gl.util.BigDecimalUtil;
|
|
import kd.fi.gl.util.BigDecimalUtil;
|
|
import nckd.jimin.jyyy.fi.common.ReimAmountSourceTypeEnum;
|
|
import nckd.jimin.jyyy.fi.common.ReimAmountSourceTypeEnum;
|
|
import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
|
|
import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
|
|
|
|
+import nckd.jimin.jyyy.fi.common.constant.JobPositionBakBillConstant;
|
|
|
|
+import nckd.jimin.jyyy.fi.common.constant.LimitRelasetConstant;
|
|
import nckd.jimin.jyyy.fi.common.util.CommonUtils;
|
|
import nckd.jimin.jyyy.fi.common.util.CommonUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class PersonReimQuotaHelper {
|
|
public class PersonReimQuotaHelper {
|
|
|
|
|
|
@@ -33,7 +37,8 @@ public class PersonReimQuotaHelper {
|
|
BizLog.log(String.format("作废条件范围内的个人额度表,过滤条件为:" + JSON.toJSONString(filterList)));
|
|
BizLog.log(String.format("作废条件范围内的个人额度表,过滤条件为:" + JSON.toJSONString(filterList)));
|
|
|
|
|
|
DynamicObject[] invalidPersonReimArray = BusinessDataServiceHelper.load(BillTypeConstants.ER_REIMBURSEAMOUNT, "auditstatus", filterList);
|
|
DynamicObject[] invalidPersonReimArray = BusinessDataServiceHelper.load(BillTypeConstants.ER_REIMBURSEAMOUNT, "auditstatus", filterList);
|
|
-
|
|
|
|
|
|
+ String idList = Arrays.stream(invalidPersonReimArray).map(personReim -> personReim.getString("id")).collect(Collectors.joining(";"));
|
|
|
|
+ BizLog.log("作废的个人额度表数据为:" + idList);
|
|
for(DynamicObject invalidPersonReim : invalidPersonReimArray){
|
|
for(DynamicObject invalidPersonReim : invalidPersonReimArray){
|
|
invalidPersonReim.set("auditstatus","2");
|
|
invalidPersonReim.set("auditstatus","2");
|
|
}
|
|
}
|
|
@@ -48,6 +53,10 @@ public class PersonReimQuotaHelper {
|
|
Calendar calendar = Calendar.getInstance();
|
|
Calendar calendar = Calendar.getInstance();
|
|
String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
int month = calendar.get(Calendar.MONTH) + 1;
|
|
int month = calendar.get(Calendar.MONTH) + 1;
|
|
|
|
+ // 费用标准同步的下个月生效
|
|
|
|
+ if(ReimAmountSourceTypeEnum.STANDARDCHANGE.equals(quotaVO.getSourcetype())){
|
|
|
|
+ month = month+1;
|
|
|
|
+ }
|
|
|
|
|
|
// 通过[公司、费用类型、人员、币别、年度]判断是否已经创建个人额度表
|
|
// 通过[公司、费用类型、人员、币别、年度]判断是否已经创建个人额度表
|
|
DynamicObject queryPersonAmount = QueryServiceHelper.queryOne(BillTypeConstants.ER_REIMBURSEAMOUNT, "id,nckd_sourcetype", new QFilter[]{
|
|
DynamicObject queryPersonAmount = QueryServiceHelper.queryOne(BillTypeConstants.ER_REIMBURSEAMOUNT, "id,nckd_sourcetype", new QFilter[]{
|
|
@@ -67,7 +76,10 @@ public class PersonReimQuotaHelper {
|
|
BizLog.log(String.format("个人额度表【%s】已存在,且为手工新增,不予处理!", queryPersonAmount.getString("id")));
|
|
BizLog.log(String.format("个人额度表【%s】已存在,且为手工新增,不予处理!", queryPersonAmount.getString("id")));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- copyModifyPersonReim(personAmountBill,queryPersonAmount.getLong("id"),quotaVO.getAmount(),month);
|
|
|
|
|
|
+ boolean isNeedUpdate = copyModifyPersonReim(personAmountBill, queryPersonAmount.getLong("id"), quotaVO.getAmount(), month);
|
|
|
|
+ if(!isNeedUpdate){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
}else{
|
|
}else{
|
|
createNewPersonReimAmount(personAmountBill,quotaVO);
|
|
createNewPersonReimAmount(personAmountBill,quotaVO);
|
|
@@ -82,6 +94,7 @@ public class PersonReimQuotaHelper {
|
|
personAmountBill.set("auditstatus", "0");
|
|
personAmountBill.set("auditstatus", "0");
|
|
personAmountBill.set("nckd_sourcetype",quotaVO.getSourcetype().getValue());
|
|
personAmountBill.set("nckd_sourcetype",quotaVO.getSourcetype().getValue());
|
|
personAmountBill.set("nckd_sourcebillid",quotaVO.getSourcebillid());
|
|
personAmountBill.set("nckd_sourcebillid",quotaVO.getSourcebillid());
|
|
|
|
+ personAmountBill.set("nckd_limitrelaset",quotaVO.getLimitRelasetId());
|
|
|
|
|
|
OperationResult saveOp = OperationServiceHelper.executeOperate("save", BillTypeConstants.ER_REIMBURSEAMOUNT, new DynamicObject[]{personAmountBill}, OperateOption.create());
|
|
OperationResult saveOp = OperationServiceHelper.executeOperate("save", BillTypeConstants.ER_REIMBURSEAMOUNT, new DynamicObject[]{personAmountBill}, OperateOption.create());
|
|
if(!saveOp.isSuccess() || saveOp.getSuccessPkIds().size() == 0){
|
|
if(!saveOp.isSuccess() || saveOp.getSuccessPkIds().size() == 0){
|
|
@@ -94,14 +107,29 @@ public class PersonReimQuotaHelper {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- protected void copyModifyPersonReim(DynamicObject personAmountBill, Long copyPersonAmountBillId,BigDecimal amount, int startMonth) {
|
|
|
|
|
|
+ protected boolean copyModifyPersonReim(DynamicObject personAmountBill, Long copyPersonAmountBillId,BigDecimal amount, int startMonth) {
|
|
DynamicObject oriPersonAmount = BusinessDataServiceHelper.loadSingle(copyPersonAmountBillId, BillTypeConstants.ER_REIMBURSEAMOUNT);
|
|
DynamicObject oriPersonAmount = BusinessDataServiceHelper.loadSingle(copyPersonAmountBillId, BillTypeConstants.ER_REIMBURSEAMOUNT);
|
|
- Set<String> ignoreSet = new HashSet<>(Arrays.asList("id"));
|
|
|
|
- DynamicObjectUtils.copy(oriPersonAmount,personAmountBill);
|
|
|
|
|
|
+
|
|
|
|
+ // 如果月份之后的额度与需要更新的额度相同,则不保存
|
|
|
|
+ Boolean isNeedUpdate = false;
|
|
|
|
+ for(int i = startMonth; i <= 12; i++) {
|
|
|
|
+ if( amount != null && amount.compareTo(oriPersonAmount.getBigDecimal("month" + i)) != 0){
|
|
|
|
+ isNeedUpdate = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!isNeedUpdate){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Set<String> ignoreSet = new HashSet<>(Arrays.asList("id","creator","createtime","modifier","modifytime","auditor","auditdate","nckd_sourcetype","nckd_sourcebillid","nckd_limitrelaset"));
|
|
|
|
+ DynamicObjectUtils.copy(oriPersonAmount,personAmountBill,ignoreSet);
|
|
// 标准字段
|
|
// 标准字段
|
|
personAmountBill.set("wbsrcbilltype","er_reimctl_modify");
|
|
personAmountBill.set("wbsrcbilltype","er_reimctl_modify");
|
|
personAmountBill.set("wbsrcbillid",oriPersonAmount.getPkValue());
|
|
personAmountBill.set("wbsrcbillid",oriPersonAmount.getPkValue());
|
|
setPersonAmountData(personAmountBill,amount,startMonth);
|
|
setPersonAmountData(personAmountBill,amount,startMonth);
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
protected void createNewPersonReimAmount(DynamicObject personAmountBill , PersonReimQuotaVO quotaVO){
|
|
protected void createNewPersonReimAmount(DynamicObject personAmountBill , PersonReimQuotaVO quotaVO){
|
|
@@ -189,4 +217,85 @@ public class PersonReimQuotaHelper {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void createQuotaJobleverChange(DynamicObject jobBakInfo, Map<Long, Map<Long, List<DynamicObject>>> limitRelasetExpenseItemMap, ReimAmountSourceTypeEnum sourcetype){
|
|
|
|
+ DynamicObject joblever_new = jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_NEW);
|
|
|
|
+ for(Map.Entry<Long, Map<Long, List<DynamicObject>>> currencyRow : limitRelasetExpenseItemMap.entrySet()){
|
|
|
|
+ // 币别ID
|
|
|
|
+ Long currencyId = currencyRow.getKey();
|
|
|
|
+ // 费用项目分组
|
|
|
|
+ Map<Long, List<DynamicObject>> expenseItemGroupMap = currencyRow.getValue();
|
|
|
|
+
|
|
|
|
+ for(Map.Entry<Long, List<DynamicObject>> expenseItemRow : expenseItemGroupMap.entrySet()){
|
|
|
|
+ Long expenseItemId = expenseItemRow.getKey();
|
|
|
|
+ List<DynamicObject> limitRelasetList = expenseItemRow.getValue();
|
|
|
|
+
|
|
|
|
+ Optional<DynamicObject> findJobleverOp = limitRelasetList.stream().filter(r -> joblever_new.getPkValue()
|
|
|
|
+ .equals(r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CLASSFIELD_JOBPOS).getPkValue())).findFirst();
|
|
|
|
+ if(findJobleverOp.isPresent()){
|
|
|
|
+ BigDecimal quotaAmont = findJobleverOp.get().getBigDecimal(LimitRelasetConstant.KEY_NCKD_AMOUNT);
|
|
|
|
+ PersonReimQuotaVO personReimQuotaVO = new PersonReimQuotaVO(
|
|
|
|
+ jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID),
|
|
|
|
+ jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getLong(JobPositionBakBillConstant.ID),
|
|
|
|
+ expenseItemId,
|
|
|
|
+ currencyId,
|
|
|
|
+ quotaAmont,
|
|
|
|
+ Optional.ofNullable(sourcetype).orElse(ReimAmountSourceTypeEnum.JOBLEVELCHANGE),
|
|
|
|
+ "",
|
|
|
|
+ findJobleverOp.get().getString(LimitRelasetConstant.ID));
|
|
|
|
+ createPersonReimAmount(personReimQuotaVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void createQuotaPositionChange(DynamicObject jobBakInfo,Map<Long, Map<Long, List<DynamicObject>>> limitRelasetExpenseItemMap,ReimAmountSourceTypeEnum sourcetype){
|
|
|
|
+ DynamicObject joblever_new = jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_NEW);
|
|
|
|
+ DynamicObject position_new = jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_POSITION_NEW);
|
|
|
|
+ for(Map.Entry<Long, Map<Long, List<DynamicObject>>> currencyRow : limitRelasetExpenseItemMap.entrySet()){
|
|
|
|
+ // 币别ID
|
|
|
|
+ Long currencyId = currencyRow.getKey();
|
|
|
|
+ // 费用项目分组
|
|
|
|
+ Map<Long, List<DynamicObject>> expenseItemGroupMap = currencyRow.getValue();
|
|
|
|
+
|
|
|
|
+ for(Map.Entry<Long, List<DynamicObject>> expenseItemRow : expenseItemGroupMap.entrySet()){
|
|
|
|
+ Long expenseItemId = expenseItemRow.getKey();
|
|
|
|
+ List<DynamicObject> limitRelasetList = expenseItemRow.getValue();
|
|
|
|
+
|
|
|
|
+ Optional<DynamicObject> findJobleverOp = limitRelasetList.stream().filter(r -> joblever_new.getPkValue()
|
|
|
|
+ .equals(r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CLASSFIELD_JOBPOS).getPkValue())).findFirst();
|
|
|
|
+ Optional<DynamicObject> findPositionOp = limitRelasetList.stream().filter(r -> position_new.getPkValue()
|
|
|
|
+ .equals(r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CLASSFIELD_JOBPOS).getPkValue())).findFirst();
|
|
|
|
+
|
|
|
|
+ // 人员岗位发生变化时,如果存在职级的费用标准,则不需要调整额度
|
|
|
|
+ if(!findJobleverOp.isPresent() && findPositionOp.isPresent()){
|
|
|
|
+ BigDecimal quotaAmont = findPositionOp.get().getBigDecimal(LimitRelasetConstant.KEY_NCKD_AMOUNT);
|
|
|
|
+ PersonReimQuotaVO personReimQuotaVO = new PersonReimQuotaVO(
|
|
|
|
+ jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID),
|
|
|
|
+ jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getLong(JobPositionBakBillConstant.ID),
|
|
|
|
+ expenseItemId,
|
|
|
|
+ currencyId,
|
|
|
|
+ quotaAmont,
|
|
|
|
+ Optional.ofNullable(sourcetype).orElse(ReimAmountSourceTypeEnum.POSITIONCHANGE),
|
|
|
|
+ "",
|
|
|
|
+ findPositionOp.get().getString(LimitRelasetConstant.ID));
|
|
|
|
+ createPersonReimAmount(personReimQuotaVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<Long, Map<Long, List<DynamicObject>>> getLimitRelasetMap() {
|
|
|
|
+ Set<Long> bakBillIdSet = QueryServiceHelper.query(LimitRelasetConstant.ENTITYID, LimitRelasetConstant.ID, new QFilter[]{
|
|
|
|
+ new QFilter(LimitRelasetConstant.KEY_STATUS, QFilter.equals, "C")
|
|
|
|
+ }).stream().map(r -> r.getLong(JobPositionBakBillConstant.ID)).collect(Collectors.toSet());
|
|
|
|
+
|
|
|
|
+ DynamicObject[] limitRelasetCol = BusinessDataServiceHelper.load(bakBillIdSet.toArray(), EntityMetadataCache.getDataEntityType(LimitRelasetConstant.ENTITYID));
|
|
|
|
+ return Arrays.stream(limitRelasetCol)
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ r -> r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CURRENCY).getLong(LimitRelasetConstant.ID),
|
|
|
|
+ Collectors.groupingBy(r -> r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_EXPENSEITEM).getLong(LimitRelasetConstant.ID)
|
|
|
|
+ )));
|
|
|
|
+ }
|
|
}
|
|
}
|