|
@@ -49,15 +49,9 @@ public class PersonReimQuotaHelper {
|
|
|
* @param quotaVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public void createPersonReimAmount(PersonReimQuotaVO quotaVO){
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
|
- int month = calendar.get(Calendar.MONTH) + 1;
|
|
|
- // 费用标准同步的下个月生效
|
|
|
- if(ReimAmountSourceTypeEnum.STANDARDCHANGE.equals(quotaVO.getSourcetype())){
|
|
|
- month = month+1;
|
|
|
- }
|
|
|
+ public DynamicObject createPersonReimAmount(PersonReimQuotaVO quotaVO){
|
|
|
|
|
|
+ initQuotaYearAndMonth(quotaVO);
|
|
|
// 通过[公司、费用类型、人员、币别、年度]判断是否已经创建个人额度表
|
|
|
DynamicObject queryPersonAmount = QueryServiceHelper.queryOne(BillTypeConstants.ER_REIMBURSEAMOUNT, "id,nckd_sourcetype", new QFilter[]{
|
|
|
new QFilter("company.id", QCP.equals, quotaVO.getCompanyId()),
|
|
@@ -65,7 +59,7 @@ public class PersonReimQuotaHelper {
|
|
|
new QFilter("expenseitem.id", QCP.equals, quotaVO.getExpenseItemId()),
|
|
|
new QFilter("currency.id", QCP.equals, quotaVO.getCurrencyId()),
|
|
|
new QFilter("auditstatus", QCP.equals, "1"),
|
|
|
- new QFilter("dateyear", QCP.equals, year)
|
|
|
+ new QFilter("dateyear", QCP.equals, String.valueOf(quotaVO.getYear()))
|
|
|
});
|
|
|
|
|
|
DynamicObject personAmountBill = BusinessDataServiceHelper.newDynamicObject(BillTypeConstants.ER_REIMBURSEAMOUNT);
|
|
@@ -74,11 +68,11 @@ public class PersonReimQuotaHelper {
|
|
|
|
|
|
if(ReimAmountSourceTypeEnum.ER_REIMCTL_NEW.getKey().equals(queryPersonAmount.getString("nckd_sourcetype"))){
|
|
|
BizLog.log(String.format("个人额度表【%s】已存在,且为手工新增,不予处理!", queryPersonAmount.getString("id")));
|
|
|
- return;
|
|
|
+ return null;
|
|
|
}
|
|
|
- boolean isNeedUpdate = copyModifyPersonReim(personAmountBill, queryPersonAmount.getLong("id"), quotaVO.getAmount(), month);
|
|
|
+ boolean isNeedUpdate = copyModifyPersonReim(personAmountBill, queryPersonAmount.getLong("id"), quotaVO.getAmount(), quotaVO.getMonth());
|
|
|
if(!isNeedUpdate){
|
|
|
- return;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}else{
|
|
@@ -104,7 +98,90 @@ public class PersonReimQuotaHelper {
|
|
|
if(!approveOp.isSuccess() || approveOp.getSuccessPkIds().size() == 0){
|
|
|
throw new KDBizException(CommonUtils.getOperationResultErrorInfos(approveOp));
|
|
|
}
|
|
|
+ return personAmountBill;
|
|
|
+ }
|
|
|
|
|
|
+ protected DynamicObject getHrPersonInfo(Object userId){
|
|
|
+ DynamicObject userInfo = BusinessDataServiceHelper.loadSingleFromCache(userId, "bos_user","number");
|
|
|
+ // 查询人员的信息
|
|
|
+ return QueryServiceHelper.queryOne(BillTypeConstants.HRPI_EMPPOSORGREL, "person.id,bsed", new QFilter[]{
|
|
|
+ new QFilter("businessstatus", QCP.equals, "1"),
|
|
|
+ new QFilter("iscurrentversion", QCP.equals, "1"),
|
|
|
+ new QFilter("datastatus", QCP.equals, "1"),
|
|
|
+ new QFilter("isprimary", QCP.equals, "1"),
|
|
|
+ new QFilter("person.number", QCP.equals, userInfo.getString("number"))
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void initQuotaYearAndMonth(PersonReimQuotaVO quotaVO){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ Date quotaDate = new Date();
|
|
|
+ calendar.setTime(quotaDate);
|
|
|
+ // 来源费用标准变更,次月生效
|
|
|
+ if(ReimAmountSourceTypeEnum.STANDARDCHANGE.equals(quotaVO.getSourcetype())){
|
|
|
+ quotaDate = CommonUtils.getFirstDayOfNextMonth(quotaDate);
|
|
|
+ // 来源职级和岗位变动的,当月生效
|
|
|
+ }else if(ReimAmountSourceTypeEnum.JOBLEVELCHANGE.equals(quotaVO.getSourcetype())
|
|
|
+ || ReimAmountSourceTypeEnum.POSITIONCHANGE.equals(quotaVO.getSourcetype())){
|
|
|
+ // 查询当年的额度
|
|
|
+ DynamicObject queryPersonAmount = QueryServiceHelper.queryOne(BillTypeConstants.ER_REIMBURSEAMOUNT, "id,nckd_sourcetype", new QFilter[]{
|
|
|
+ new QFilter("company.id", QCP.equals, quotaVO.getCompanyId()),
|
|
|
+ new QFilter("employee.id", QCP.equals, quotaVO.getUserId()),
|
|
|
+ new QFilter("expenseitem.id", QCP.equals, quotaVO.getExpenseItemId()),
|
|
|
+ new QFilter("currency.id", QCP.equals, quotaVO.getCurrencyId()),
|
|
|
+ new QFilter("auditstatus", QCP.equals, "1"),
|
|
|
+ new QFilter("dateyear", QCP.equals, String.valueOf(calendar.get(Calendar.YEAR)))
|
|
|
+ });
|
|
|
+ if(queryPersonAmount != null){
|
|
|
+ DynamicObject personAmountBill = BusinessDataServiceHelper.loadSingle(queryPersonAmount.get("id"), BillTypeConstants.ER_REIMBURSEAMOUNT);
|
|
|
+ // 获取当前月份的
|
|
|
+ BigDecimal curAmount = personAmountBill.getBigDecimal("month" + (calendar.get(Calendar.MONTH)+1));
|
|
|
+ // 更新的额度如果小于当前额度,则次月生成
|
|
|
+ if(quotaVO.getAmount().compareTo(curAmount) < 0){
|
|
|
+ quotaDate = CommonUtils.getFirstDayOfNextMonth(quotaDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 来源公司的变动,入职生效日期为额度创建时间
|
|
|
+ } else if(ReimAmountSourceTypeEnum.COMPANYCHANGE.equals(quotaVO.getSourcetype())){
|
|
|
+ DynamicObject personPositionInfo = getHrPersonInfo(quotaVO.getUserId());
|
|
|
+ quotaDate = personPositionInfo.getDate("bsed");
|
|
|
+ DynamicObject expenseItem = QueryServiceHelper.queryOne("er_expenseitemedit", "nckd_syncquota_type", new QFilter("id", QCP.equals, quotaVO.getExpenseItemId()).toArray());
|
|
|
+ if("next".equals(expenseItem.getString("nckd_syncquota_type"))){
|
|
|
+ quotaDate = CommonUtils.getFirstDayOfNextMonth(quotaDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ calendar.setTime(quotaDate);
|
|
|
+ quotaVO.setYear(calendar.get(Calendar.YEAR));
|
|
|
+ quotaVO.setMonth(calendar.get(Calendar.MONTH) + 1);
|
|
|
+ }
|
|
|
+ protected int getStartMonth(PersonReimQuotaVO quotaVO , DynamicObject personAmountBill, DynamicObject personPositionInfo) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ // 默认当前月
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1;
|
|
|
+ ReimAmountSourceTypeEnum sourcetype = quotaVO.getSourcetype();
|
|
|
+ // 来源费用标准变更,次月生效
|
|
|
+ if(ReimAmountSourceTypeEnum.STANDARDCHANGE.equals(sourcetype)){
|
|
|
+ month = month+1;
|
|
|
+ // 来源职级和岗位变动的,当月生效
|
|
|
+ }else if(ReimAmountSourceTypeEnum.JOBLEVELCHANGE.equals(sourcetype) || ReimAmountSourceTypeEnum.POSITIONCHANGE.equals(sourcetype)){
|
|
|
+ // 获取当前月份的
|
|
|
+ BigDecimal curAmount = personAmountBill.getBigDecimal("month" + month);
|
|
|
+ // 更新的额度如果小于当前额度,则次月生成
|
|
|
+ if(quotaVO.getAmount().compareTo(curAmount) < 0){
|
|
|
+ month = month+1;
|
|
|
+ }
|
|
|
+ // 来源公司的变动,入职生效日期为额度创建时间
|
|
|
+ } else if(ReimAmountSourceTypeEnum.COMPANYCHANGE.equals(sourcetype)){
|
|
|
+ Date bsedDate = personPositionInfo.getDate("bsed");
|
|
|
+ Calendar bsedCalendar = Calendar.getInstance();
|
|
|
+ bsedCalendar.setTime(bsedDate);
|
|
|
+ month = calendar.get(Calendar.MONTH) + 1;
|
|
|
+ DynamicObject expenseItem = QueryServiceHelper.queryOne("er_expenseitemedit", "nckd_syncquota_type", new QFilter("id", QCP.equals, quotaVO.getExpenseItemId()).toArray());
|
|
|
+ if("next".equals(expenseItem.getString("nckd_syncquota_type"))){
|
|
|
+ month = month+1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return month;
|
|
|
}
|
|
|
|
|
|
protected boolean copyModifyPersonReim(DynamicObject personAmountBill, Long copyPersonAmountBillId,BigDecimal amount, int startMonth) {
|
|
@@ -133,8 +210,7 @@ public class PersonReimQuotaHelper {
|
|
|
}
|
|
|
|
|
|
protected void createNewPersonReimAmount(DynamicObject personAmountBill , PersonReimQuotaVO quotaVO){
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- String year = String.valueOf(calendar.get(Calendar.YEAR));
|
|
|
+
|
|
|
DynamicObject userInfo = BusinessDataServiceHelper.loadSingleFromCache(quotaVO.getUserId(), "bos_user");
|
|
|
DynamicObject companyInfo = BusinessDataServiceHelper.loadSingleFromCache(quotaVO.getCompanyId(), "bos_org");
|
|
|
DynamicObject expenseItemInfo = BusinessDataServiceHelper.loadSingleFromCache(quotaVO.getExpenseItemId(), "er_expenseitemedit");
|
|
@@ -143,7 +219,7 @@ public class PersonReimQuotaHelper {
|
|
|
personAmountBill.set("company", companyInfo);
|
|
|
personAmountBill.set("expenseitem", expenseItemInfo);
|
|
|
personAmountBill.set("currency", currencyInfo);
|
|
|
- personAmountBill.set("dateyear", String.valueOf(year));
|
|
|
+ personAmountBill.set("dateyear", String.valueOf(quotaVO.getYear()));
|
|
|
personAmountBill.set("costcompany", companyInfo);
|
|
|
personAmountBill.set("amounttype", "1");
|
|
|
personAmountBill.set("employee", userInfo);
|
|
@@ -153,8 +229,8 @@ public class PersonReimQuotaHelper {
|
|
|
personAmountBill.set("modifytime", new Date());
|
|
|
personAmountBill.set("creator", RequestContext.get().getCurrUserId());
|
|
|
personAmountBill.set("modifier", RequestContext.get().getCurrUserId());
|
|
|
- personAmountBill.set("wbsrcbilltype", "er_reimctl_new");
|
|
|
- setPersonAmountData(personAmountBill,quotaVO.getAmount(),1);
|
|
|
+ personAmountBill.set("wbsrcbilltype", "er_reimctl_modify");
|
|
|
+ setPersonAmountData(personAmountBill,quotaVO.getAmount(),quotaVO.getMonth());
|
|
|
}
|
|
|
|
|
|
public void syncReimLever(Long userId ,Long companyId,Long jobId){
|
|
@@ -191,7 +267,11 @@ public class PersonReimQuotaHelper {
|
|
|
leverFilterList.add(BaseDataServiceHelper.getBaseDataFilter("er_reimburselevel", companyId));
|
|
|
leverFilterList.add(new QFilter("enable", QCP.equals,"1"));
|
|
|
leverFilterList.add(new QFilter("nckd_joblevelhr.fbasedataid", QCP.equals,jobId));
|
|
|
- return QueryServiceHelper.queryOne("er_reimburselevel", "id", leverFilterList.toArray(new QFilter[0]));
|
|
|
+ DynamicObject queryOne = QueryServiceHelper.queryOne("er_reimburselevel", "id", leverFilterList.toArray(new QFilter[0]));
|
|
|
+ if(queryOne != null){
|
|
|
+ return BusinessDataServiceHelper.loadSingleFromCache(queryOne.getLong("id"), "er_reimburselevel");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public DynamicObject getDefultReimLever() {
|
|
@@ -221,6 +301,10 @@ 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);
|
|
|
+ DynamicObject joblever_old = jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_OLD);
|
|
|
+
|
|
|
+ List<DynamicObject> createQuotaList = new ArrayList<>();
|
|
|
+ // 创建新职级下的个人额度
|
|
|
for(Map.Entry<Long, Map<Long, List<DynamicObject>>> currencyRow : limitRelasetExpenseItemMap.entrySet()){
|
|
|
// 币别ID
|
|
|
Long currencyId = currencyRow.getKey();
|
|
@@ -230,7 +314,6 @@ public class PersonReimQuotaHelper {
|
|
|
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()){
|
|
@@ -244,15 +327,47 @@ public class PersonReimQuotaHelper {
|
|
|
Optional.ofNullable(sourcetype).orElse(ReimAmountSourceTypeEnum.JOBLEVELCHANGE),
|
|
|
"",
|
|
|
findJobleverOp.get().getString(LimitRelasetConstant.ID));
|
|
|
- createPersonReimAmount(personReimQuotaVO);
|
|
|
+ createQuotaList.add(createPersonReimAmount(personReimQuotaVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(joblever_old != null){
|
|
|
+ List<Object> createReimList = createQuotaList.stream().filter(r -> !Objects.isNull(r)).map(r -> r.getPkValue()).collect(Collectors.toList());
|
|
|
+ // 作废旧职级下,非新职级创建的个人额度数据
|
|
|
+ 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_old.getPkValue()
|
|
|
+ .equals(r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CLASSFIELD_JOBPOS).getPkValue())).findFirst();
|
|
|
+ if(findJobleverOp.isPresent()){
|
|
|
+ doInvalidPersonReim(new QFilter[]{
|
|
|
+ new QFilter("company.id", QCP.equals,jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getLong(JobPositionBakBillConstant.ID)),
|
|
|
+ new QFilter("employee.id", QCP.equals, jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID)),
|
|
|
+ new QFilter("expenseitem.id", QCP.equals, expenseItemId),
|
|
|
+ new QFilter("currency.id", QCP.equals, currencyId),
|
|
|
+ new QFilter("auditstatus", QCP.equals, "1"),
|
|
|
+ new QFilter("id", QCP.not_in, createReimList)
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ DynamicObject position_old = jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_POSITION_OLD);
|
|
|
+ List<DynamicObject> createQuotaList = new ArrayList<>();
|
|
|
+ // 创建新岗位下的额度
|
|
|
for(Map.Entry<Long, Map<Long, List<DynamicObject>>> currencyRow : limitRelasetExpenseItemMap.entrySet()){
|
|
|
// 币别ID
|
|
|
Long currencyId = currencyRow.getKey();
|
|
@@ -280,7 +395,38 @@ public class PersonReimQuotaHelper {
|
|
|
Optional.ofNullable(sourcetype).orElse(ReimAmountSourceTypeEnum.POSITIONCHANGE),
|
|
|
"",
|
|
|
findPositionOp.get().getString(LimitRelasetConstant.ID));
|
|
|
- createPersonReimAmount(personReimQuotaVO);
|
|
|
+ createQuotaList.add(createPersonReimAmount(personReimQuotaVO));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(position_old != null){
|
|
|
+ List<Object> createQuotaIdList = createQuotaList.stream().filter(r -> !Objects.isNull(r)).map(r -> r.getPkValue()).collect(Collectors.toList());
|
|
|
+ // 作废旧岗位下的额度
|
|
|
+ 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_old.getPkValue()
|
|
|
+ .equals(r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CLASSFIELD_JOBPOS).getPkValue())).findFirst();
|
|
|
+ // 人员岗位发生变化时,如果存在职级的费用标准,则不需要作废
|
|
|
+ if (!findJobleverOp.isPresent() && findPositionOp.isPresent()) {
|
|
|
+ doInvalidPersonReim(new QFilter[]{
|
|
|
+ new QFilter("company.id", QCP.equals,jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getLong(JobPositionBakBillConstant.ID)),
|
|
|
+ new QFilter("employee.id", QCP.equals, jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID)),
|
|
|
+ new QFilter("expenseitem.id", QCP.equals, expenseItemId),
|
|
|
+ new QFilter("currency.id", QCP.equals, currencyId),
|
|
|
+ new QFilter("auditstatus", QCP.equals, "1"),
|
|
|
+ new QFilter("id",QCP.not_in,createQuotaIdList)
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|