Эх сурвалжийг харах

1.调整人员备份表代码逻辑
2.调整职级、岗位变动额度同步逻辑

lisheng 3 өдөр өмнө
parent
commit
e6a98dccd7

+ 76 - 150
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/operate/Helper/PersonReimQuotaHelper.java

@@ -1,10 +1,12 @@
 package nckd.jimin.jyyy.fi.plugin.operate.Helper;
 
+import json.JSON;
 import kd.bos.context.RequestContext;
 import kd.bos.dataentity.OperateOption;
 import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.entity.operate.result.OperationResult;
 import kd.bos.exception.KDBizException;
+import kd.bos.logging.BizLog;
 import kd.bos.org.utils.DynamicObjectUtils;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
@@ -14,177 +16,61 @@ import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
 import kd.bos.servicehelper.operation.OperationServiceHelper;
 import kd.bos.servicehelper.operation.SaveServiceHelper;
 import kd.fi.gl.util.BigDecimalUtil;
+import nckd.jimin.jyyy.fi.common.ReimAmountSourceTypeEnum;
 import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
-import nckd.jimin.jyyy.fi.common.constant.LimitRelasetConstant;
-import nckd.jimin.jyyy.fi.common.constant.PersonReimSyncTaskConstant;
 import nckd.jimin.jyyy.fi.common.util.CommonUtils;
 
 import java.math.BigDecimal;
 import java.util.*;
-import java.util.stream.Collectors;
 
 public class PersonReimQuotaHelper {
-    /**
-     * 通过 费用项目与职级岗位关系配置 获取额度信息
-     * 按照币别分组,允许设置不同币别的方案
-     * @return
-     */
-    public Map<Long, Map<Long, BigDecimal>> getExpenseJobAmount(Object positionId , Object jobLeverId){
-
-        StringJoiner joiner = new StringJoiner(",");
-        joiner.add(LimitRelasetConstant.KEY_NCKD_CURRENCY);
-        joiner.add(LimitRelasetConstant.KEY_NCKD_EXPENSEITEM);
-        joiner.add(LimitRelasetConstant.KEY_NCKD_AMOUNT);
-
-        DynamicObject[] limitRelasetArray = BusinessDataServiceHelper.load(LimitRelasetConstant.ENTITYID, joiner.toString(), new QFilter[]{
-                new QFilter(LimitRelasetConstant.KEY_NCKD_POSITIONHR, QCP.equals, positionId),
-                new QFilter(LimitRelasetConstant.KEY_NCKD_JOBLEVELHR, QCP.equals, jobLeverId),
-                new QFilter(LimitRelasetConstant.KEY_ENABLE, QCP.equals, "1"),
-                new QFilter(LimitRelasetConstant.KEY_STATUS, QCP.equals, "C")
-        });
-        if(limitRelasetArray == null || limitRelasetArray.length == 0){
-            return new HashMap<>();
-        }
-        return Arrays.stream(limitRelasetArray)
-                .filter(r -> r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_EXPENSEITEM) != null)
-                .collect(Collectors.groupingBy(r -> r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_CURRENCY).getLong(PersonReimSyncTaskConstant.ID),
-                        Collectors.toMap(r -> r.getDynamicObject(LimitRelasetConstant.KEY_NCKD_EXPENSEITEM).getLong(PersonReimSyncTaskConstant.ID),
-                                r -> r.getBigDecimal(LimitRelasetConstant.KEY_NCKD_AMOUNT), (a, b) -> a)));
-    }
 
     /**
-     * 作废条件范围内的个人额度信息
-     * @param userId
-     * @param companyId
-     * @param expenseItemId
-     * @param currencyId
+     * 作废个人额度表
+     * @param filterList
      */
-    public void doInvalidPersonReim(Long userId , Long companyId , Long expenseItemId ,Long currencyId , int year){
-        // 作废币别下
-        List<QFilter> filterList = new ArrayList<>();
-        if(userId != null && userId == 0L){
-            filterList.add(new QFilter("employee.id", QCP.equals, userId));
-            if(companyId != null && companyId != 0L){
-                filterList.add(new QFilter("company.id", QCP.equals, companyId));
-            }
-            if(expenseItemId != null && expenseItemId != 0L){
-                filterList.add(new QFilter("expenseitem.id", QCP.equals, expenseItemId));
-            }
-            filterList.add(new QFilter("currency.id", QCP.equals, currencyId));
-            filterList.add(new QFilter("auditstatus", QCP.equals, "1"));
-            filterList.add(new QFilter("dateyear", QCP.equals, String.valueOf(year)));
-            DynamicObject[] invalidPersonReimArray = BusinessDataServiceHelper.load(BillTypeConstants.ER_REIMBURSEAMOUNT, "auditstatus", filterList.toArray(new QFilter[0]));
-            for(DynamicObject invalidPersonReim : invalidPersonReimArray){
-                invalidPersonReim.set("auditstatus","2");
-            }
-            SaveServiceHelper.save(invalidPersonReimArray);
-        }
-    }
+    public void doInvalidPersonReim(QFilter[] filterList){
+        BizLog.log(String.format("作废条件范围内的个人额度表,过滤条件为:" + JSON.toJSONString(filterList)));
 
-    /**
-     * 直接创建个人额度信息
-     * @param billInfo
-     * @param currencyReimJobAmount
-     */
-    public void createPersonReimDirect(DynamicObject billInfo,Map<Long, Map<Long, BigDecimal>> currencyReimJobAmount){
-        for(Map.Entry<Long, Map<Long, BigDecimal>> currencyRow : currencyReimJobAmount.entrySet()){
-            Long currencyId = currencyRow.getKey();
-            Map<Long, BigDecimal> expenseJobAmount = currencyRow.getValue();
-            for(Map.Entry<Long, BigDecimal> dataRow : expenseJobAmount.entrySet()){
-                Long expenseItemId = dataRow.getKey();
-                BigDecimal amount = dataRow.getValue();
-                createPersonReimByExpense(billInfo,currencyId,expenseItemId,amount);
-            }
-        }
-    }
-
-    public void createPersonReimByExpense(DynamicObject billInfo,Long currencyId,Long expenseItemId,BigDecimal amount){
+        DynamicObject[] invalidPersonReimArray = BusinessDataServiceHelper.load(BillTypeConstants.ER_REIMBURSEAMOUNT, "auditstatus", filterList);
 
-        PersonReimQuotaVO personReimQuotaVO = new PersonReimQuotaVO(
-                billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_USER).getLong(PersonReimSyncTaskConstant.ID),
-                billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG).getLong(PersonReimSyncTaskConstant.ID),
-                expenseItemId,
-                currencyId,amount,
-                billInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_YEAR),
-                billInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_MONTH),
-                billInfo.getString(PersonReimSyncTaskConstant.ID));
-        // 创建个人额度表
-        DynamicObject personReim = createPersonReim(personReimQuotaVO,true);
-        // 调用审核
-        OperationResult saveOp = OperationServiceHelper.executeOperate("save", BillTypeConstants.ER_REIMBURSEAMOUNT, new DynamicObject[]{personReim}, OperateOption.create());
-        if(!saveOp.isSuccess() || saveOp.getSuccessPkIds().size() == 0){
-            throw new KDBizException(CommonUtils.getOperationResultErrorInfos(saveOp));
-        }
-        OperationResult approveOp = OperationServiceHelper.executeOperate("approve", BillTypeConstants.ER_REIMBURSEAMOUNT, new Object[]{saveOp.getSuccessPkIds().get(0)}, OperateOption.create());
-        if(!approveOp.isSuccess() || approveOp.getSuccessPkIds().size() == 0){
-            throw new KDBizException(CommonUtils.getOperationResultErrorInfos(approveOp));
+        for(DynamicObject invalidPersonReim : invalidPersonReimArray){
+            invalidPersonReim.set("auditstatus","2");
         }
+        SaveServiceHelper.save(invalidPersonReimArray);
     }
-
     /**
      * 获取个人额度同步表 创建某个费用类型的个人额度
      * @param quotaVO
      * @return
      */
-    public DynamicObject createPersonReim(PersonReimQuotaVO  quotaVO , boolean isAddnew){
-
-        int year = quotaVO.getYear();
-        int month = quotaVO.getMonth();
-        BigDecimal amount = quotaVO.getAmount();
-        Long userId = quotaVO.getUserId();
-        Long companyId = quotaVO.getCompanyId();
-        Long expenseItemId = quotaVO.getExpenseItemId();
-        Long currencyId = quotaVO.getCurrencyId();
-
-        Date now = new Date();
-        long currUserId = RequestContext.get().getCurrUserId();
-
-        // 已与实施确认,通过公司、费用类型、人员、币别、年度确认是否已经创建个人额度表;如果没有则新增,存在则修改
-        DynamicObject queryPersonAmount = QueryServiceHelper.queryOne(BillTypeConstants.ER_REIMBURSEAMOUNT, "id", new QFilter[]{
-                new QFilter("company.id", QCP.equals, companyId),
-                new QFilter("employee.id", QCP.equals, userId),
-                new QFilter("expenseitem.id", QCP.equals, expenseItemId),
-                new QFilter("currency.id", QCP.equals, currencyId),
+    public void createPersonReimAmount(PersonReimQuotaVO  quotaVO){
+        Calendar calendar = Calendar.getInstance();
+        String year = String.valueOf(calendar.get(Calendar.YEAR));
+        int month = calendar.get(Calendar.MONTH) + 1;
+
+        // 通过[公司、费用类型、人员、币别、年度]判断是否已经创建个人额度表
+        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(year))
+                new QFilter("dateyear", QCP.equals, year)
         });
+
         DynamicObject personAmountBill = BusinessDataServiceHelper.newDynamicObject(BillTypeConstants.ER_REIMBURSEAMOUNT);
         // 如果存在则从个人额度中复制
         if(queryPersonAmount != null){
-            DynamicObject oriPersonAmount = BusinessDataServiceHelper.loadSingle(queryPersonAmount.get("id"), BillTypeConstants.ER_REIMBURSEAMOUNT);
-            Set<String> ignoreSet = new HashSet<>(Arrays.asList("id"));
-            DynamicObjectUtils.copy(oriPersonAmount,personAmountBill);
-            // 标准字段
-            personAmountBill.set("wbsrcbilltype","er_reimctl_modify");
-            personAmountBill.set("wbsrcbillid",oriPersonAmount.getPkValue());
-            setPersonAmountData(personAmountBill,amount,month);
-        }else{
-            // 无需新增时直接返回
-            if(!isAddnew){
-                return null;
-            }
 
-            DynamicObject userInfo = BusinessDataServiceHelper.loadSingleFromCache(userId, "bos_user");
-            DynamicObject companyInfo = BusinessDataServiceHelper.loadSingleFromCache(companyId, "bos_org");
-            DynamicObject expenseItemInfo = BusinessDataServiceHelper.loadSingleFromCache(expenseItemId, "er_expenseitemedit");
-            DynamicObject currencyInfo = BusinessDataServiceHelper.loadSingleFromCache(currencyId, "bd_currency");
-
-            personAmountBill.set("company", companyInfo);
-            personAmountBill.set("expenseitem", expenseItemInfo);
-            personAmountBill.set("currency", currencyInfo);
-            personAmountBill.set("dateyear", String.valueOf(year));
-            personAmountBill.set("costcompany", companyId);
+            if(ReimAmountSourceTypeEnum.ER_REIMCTL_NEW.getKey().equals(queryPersonAmount.getString("nckd_sourcetype"))){
+                BizLog.log(String.format("个人额度表【%s】已存在,且为手工新增,不予处理!", queryPersonAmount.getString("id")));
+                return;
+            }
+            copyModifyPersonReim(personAmountBill,queryPersonAmount.getLong("id"),quotaVO.getAmount(),month);
 
-            personAmountBill.set("amounttype", "1");
-            personAmountBill.set("employee", userInfo);
-            //personAmountBill.set("dept", reimburseQuota.get("dept.id"));
-            personAmountBill.set("auditstatus", "0");
-            personAmountBill.set("createtime", now);
-            personAmountBill.set("modifytime", now);
-            personAmountBill.set("creator", currUserId);
-            personAmountBill.set("modifier", currUserId);
-            personAmountBill.set("wbsrcbilltype", "er_reimctl_new");
-            setPersonAmountData(personAmountBill,amount,1);
+        }else{
+            createNewPersonReimAmount(personAmountBill,quotaVO);
         }
 
         BigDecimal totalAmount = BigDecimal.ZERO;
@@ -194,12 +80,53 @@ public class PersonReimQuotaHelper {
         }
         personAmountBill.set("totalamount", totalAmount);
         personAmountBill.set("auditstatus", "0");
-
-        // 岗位新增变动:positionchange ;年度复制:yearcopy  ; 新增字段,与标准字段区分,防止与标品逻辑冲突
-        personAmountBill.set("nckd_sourcetype","positionchange");
+        personAmountBill.set("nckd_sourcetype",quotaVO.getSourcetype().getValue());
         personAmountBill.set("nckd_sourcebillid",quotaVO.getSourcebillid());
 
-        return personAmountBill;
+        OperationResult saveOp = OperationServiceHelper.executeOperate("save", BillTypeConstants.ER_REIMBURSEAMOUNT, new DynamicObject[]{personAmountBill}, OperateOption.create());
+        if(!saveOp.isSuccess() || saveOp.getSuccessPkIds().size() == 0){
+            throw new KDBizException(CommonUtils.getOperationResultErrorInfos(saveOp));
+        }
+        OperationResult approveOp = OperationServiceHelper.executeOperate("approve", BillTypeConstants.ER_REIMBURSEAMOUNT, new Object[]{saveOp.getSuccessPkIds().get(0)}, OperateOption.create());
+        if(!approveOp.isSuccess() || approveOp.getSuccessPkIds().size() == 0){
+            throw new KDBizException(CommonUtils.getOperationResultErrorInfos(approveOp));
+        }
+
+    }
+
+    protected void copyModifyPersonReim(DynamicObject personAmountBill, Long copyPersonAmountBillId,BigDecimal amount, int startMonth) {
+        DynamicObject oriPersonAmount = BusinessDataServiceHelper.loadSingle(copyPersonAmountBillId, BillTypeConstants.ER_REIMBURSEAMOUNT);
+        Set<String> ignoreSet = new HashSet<>(Arrays.asList("id"));
+        DynamicObjectUtils.copy(oriPersonAmount,personAmountBill);
+        // 标准字段
+        personAmountBill.set("wbsrcbilltype","er_reimctl_modify");
+        personAmountBill.set("wbsrcbillid",oriPersonAmount.getPkValue());
+        setPersonAmountData(personAmountBill,amount,startMonth);
+    }
+
+    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");
+        DynamicObject currencyInfo = BusinessDataServiceHelper.loadSingleFromCache(quotaVO.getCurrencyId(), "bd_currency");
+
+        personAmountBill.set("company", companyInfo);
+        personAmountBill.set("expenseitem", expenseItemInfo);
+        personAmountBill.set("currency", currencyInfo);
+        personAmountBill.set("dateyear", String.valueOf(year));
+        personAmountBill.set("costcompany", companyInfo);
+        personAmountBill.set("amounttype", "1");
+        personAmountBill.set("employee", userInfo);
+        //personAmountBill.set("dept", reimburseQuota.get("dept.id"));
+        personAmountBill.set("auditstatus", "0");
+        personAmountBill.set("createtime", new Date());
+        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);
     }
 
     public void syncReimLever(Long userId ,Long companyId,Long jobId){
@@ -261,6 +188,5 @@ public class PersonReimQuotaHelper {
             personAmountBill.set("month" + i, amount);
 
         }
-
     }
 }

+ 12 - 28
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/operate/Helper/PersonReimQuotaVO.java

@@ -1,5 +1,7 @@
 package nckd.jimin.jyyy.fi.plugin.operate.Helper;
 
+import nckd.jimin.jyyy.fi.common.ReimAmountSourceTypeEnum;
+
 import java.math.BigDecimal;
 import java.util.Date;
 
@@ -32,41 +34,31 @@ public class PersonReimQuotaVO {
      * 额度金额
      */
     private BigDecimal amount;
-    
-    /**
-     * 年份
-     */
-    private int year;
-    
-    /**
-     * 月份
-     */
-    private int month;
-    
+
+    private ReimAmountSourceTypeEnum sourcetype;
     /**
      * 来源单据ID
      */
     private String sourcebillid;
 
-    public PersonReimQuotaVO(Long userId, Long companyId, Long expenseItemId, Long currencyId, BigDecimal amount) {
+    public PersonReimQuotaVO(Long userId, Long companyId, Long expenseItemId, Long currencyId, BigDecimal amount, ReimAmountSourceTypeEnum sourcetype) {
         this.userId = userId;
         this.companyId = companyId;
         this.expenseItemId = expenseItemId;
         this.currencyId = currencyId;
         this.amount = amount;
+        this.sourcetype = sourcetype;
     }
 
-    public PersonReimQuotaVO(Long userId, Long companyId, Long expenseItemId, Long currencyId, BigDecimal amount, int year, int month, String sourcebillid) {
+    public PersonReimQuotaVO(Long userId, Long companyId, Long expenseItemId, Long currencyId, BigDecimal amount, ReimAmountSourceTypeEnum sourcetype, String sourcebillid) {
         this.userId = userId;
         this.companyId = companyId;
         this.expenseItemId = expenseItemId;
         this.currencyId = currencyId;
         this.amount = amount;
-        this.year = year;
-        this.month = month;
+        this.sourcetype = sourcetype;
         this.sourcebillid = sourcebillid;
     }
-// Getters and Setters
 
     public Long getUserId() {
         return userId;
@@ -108,20 +100,12 @@ public class PersonReimQuotaVO {
         this.amount = amount;
     }
 
-    public int getYear() {
-        return year;
-    }
-
-    public void setYear(int year) {
-        this.year = year;
-    }
-
-    public int getMonth() {
-        return month;
+    public ReimAmountSourceTypeEnum getSourcetype() {
+        return sourcetype;
     }
 
-    public void setMonth(int month) {
-        this.month = month;
+    public void setSourcetype(ReimAmountSourceTypeEnum sourcetype) {
+        this.sourcetype = sourcetype;
     }
 
     public String getSourcebillid() {

+ 7 - 6
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/task/PersonJobPositionBakTask.java

@@ -33,7 +33,7 @@ public class PersonJobPositionBakTask extends AbstractTask implements StopTask {
     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
         logger.info("PersonJobPositionBakTask begin ");
         // 将备份表中最新的岗位、职级信息保存
-        Map<String, DynamicObject> hisBakBillMap = getHisPersonJobPositionBak();
+        Map<Long, DynamicObject> hisBakBillMap = getHisPersonJobPositionBak();
         List<Object> hisBakBillIdList = hisBakBillMap.values().stream().map(r -> r.getPkValue()).collect(Collectors.toList());
 
         logger.info("hisBakBillIdList size " + hisBakBillIdList.size());
@@ -50,7 +50,7 @@ public class PersonJobPositionBakTask extends AbstractTask implements StopTask {
 
     }
 
-    protected List<DynamicObject> createNewJobPosotionBakBill(Map<String, DynamicObject> hisBakBillMap){
+    protected List<DynamicObject> createNewJobPosotionBakBill(Map<Long, DynamicObject> hisBakBillMap){
         List<DynamicObject> bakBillList = new ArrayList<>();
         Date syncDate = new Date();
         // 查询当前生效的人员岗位信息
@@ -84,6 +84,7 @@ public class PersonJobPositionBakTask extends AbstractTask implements StopTask {
         for(DynamicObject position : positionCol){
             long personId = position.getLong("person.id");
             DynamicObject userInfo = CommonUtils.getUserByHrPersonId(personId);
+            Long userId = userInfo.getLong("id");
             if(userInfo != null) {
                 DynamicObject bakBillInfo = BusinessDataServiceHelper.newDynamicObject(JobPositionBakBillConstant.ENTITYID);
                 bakBillInfo.set(JobPositionBakBillConstant.KEY_NCKD_USER, userInfo);
@@ -101,8 +102,8 @@ public class PersonJobPositionBakTask extends AbstractTask implements StopTask {
                     bakBillInfo.set(JobPositionBakBillConstant.KEY_NCKD_POSITION_OLD, bakBillInfo.get(JobPositionBakBillConstant.KEY_NCKD_POSITION_NEW));
                     bakBillInfo.set(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_OLD, bakBillInfo.get(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_NEW));
                 }else{
-                    if(hisBakBillMap.containsKey(personId)){
-                        DynamicObject hisBakInfo = hisBakBillMap.get(personId);
+                    if(hisBakBillMap.containsKey(userId)){
+                        DynamicObject hisBakInfo = hisBakBillMap.get(userId);
                         if(hisBakInfo != null){
                             if(isOnlyUpdateNew){
                                 bakBillInfo.set(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD, hisBakInfo.get(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD));
@@ -121,12 +122,12 @@ public class PersonJobPositionBakTask extends AbstractTask implements StopTask {
         return bakBillList;
     }
 
-    protected Map<String, DynamicObject> getHisPersonJobPositionBak(){
+    protected Map<Long, DynamicObject> getHisPersonJobPositionBak(){
         Set<Long> bakBillIdSet = QueryServiceHelper.query(JobPositionBakBillConstant.ENTITYID, JobPositionBakBillConstant.ID, QFilter.isNotNull(JobPositionBakBillConstant.ID).toArray())
                 .stream()
                 .map(r -> r.getLong(JobPositionBakBillConstant.ID))
                 .collect(Collectors.toSet());
         return Arrays.stream(BusinessDataServiceHelper.load(bakBillIdSet.toArray(new Long[0]), EntityMetadataCache.getDataEntityType(JobPositionBakBillConstant.ENTITYID)))
-                .collect(Collectors.toMap(r -> r.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getString(JobPositionBakBillConstant.ID), r -> r, (a, b) -> a));
+                .collect(Collectors.toMap(r -> r.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID), r -> r, (a, b) -> a));
     }
 }

+ 141 - 239
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/task/PersonReimQuotaSyncTask.java

@@ -1,33 +1,24 @@
 package nckd.jimin.jyyy.fi.task;
 
-import com.google.common.collect.Lists;
 import kd.bos.context.RequestContext;
 import kd.bos.dataentity.entity.DynamicObject;
-import kd.bos.dataentity.entity.DynamicObjectCollection;
-import kd.bos.entity.operate.result.OperationResult;
-import kd.bos.exception.KDBizException;
+import kd.bos.entity.EntityMetadataCache;
 import kd.bos.exception.KDException;
 import kd.bos.logging.Log;
 import kd.bos.logging.LogFactory;
-import kd.bos.login.utils.DateUtils;
-import kd.bos.orm.ORM;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.bos.schedule.api.StopTask;
 import kd.bos.schedule.executor.AbstractTask;
 import kd.bos.servicehelper.BusinessDataServiceHelper;
 import kd.bos.servicehelper.QueryServiceHelper;
-import kd.bos.servicehelper.operation.SaveServiceHelper;
-import kd.bos.util.CollectionUtils;
-import kd.bos.util.StringUtils;
-import nckd.jimin.jyyy.fi.common.SyncStatusEnum;
-import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
-import nckd.jimin.jyyy.fi.common.constant.PersonReimSyncTaskConstant;
-import nckd.jimin.jyyy.fi.common.util.CommonUtils;
+import nckd.jimin.jyyy.fi.common.ReimAmountSourceTypeEnum;
+import nckd.jimin.jyyy.fi.common.constant.JobPositionBakBillConstant;
+import nckd.jimin.jyyy.fi.common.constant.LimitRelasetConstant;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaVO;
 
-import java.time.LocalDate;
-import java.time.YearMonth;
-import java.time.ZoneId;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -36,252 +27,163 @@ import java.util.stream.Collectors;
  */
 public class PersonReimQuotaSyncTask extends AbstractTask implements StopTask {
 
+    private PersonReimQuotaHelper personReimQuotaHelper = new PersonReimQuotaHelper();
+
     private static final Log logger = LogFactory.getLog(PersonReimQuotaSyncTask.class);
 
+
+
     @Override
     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
-        logger.info("map data {}" , map);
-        Date beginDate = getBeginDate(map);
-        Date endDate = getEndDate(map);
-        syncMonthPersonReim(beginDate,endDate);
-    }
+        logger.info("-----------PersonReimQuotaSyncTask begin--------------" , map);
+        // 查询员工额度备份全部数据,
+        DynamicObject[] personPositionJobBakArray = getPersonPositionJobBakCol();
+        // 查询费用标准配置 按照费用项目分组
+        Map<Long, Map<Long, List<DynamicObject>>> limitRelasetExpenseItemMap = getLimitRelasetMap();
 
-    /**
-     * 1.参数中有值取参数
-     * 2.参数没有值则默认取上个月第一天
-     * @param map
-     * @return
-     */
-    protected Date getBeginDate(Map<String, Object> map){
-        if(map.containsKey("beginDate") && StringUtils.isNotEmpty((String)map.get("beginDate"))){
-            String beginDateStr = (String)map.get("beginDate");
-            return DateUtils.parseDate(beginDateStr);
-        }else{
-            LocalDate today = LocalDate.now();
-            // 获取上个月的YearMonth对象
-            YearMonth lastMonth = YearMonth.from(today).minusMonths(1);
-            // 获取上个月的第一天
-            LocalDate firstDayOfLastMonth = lastMonth.atDay(1);
-            // 转换为Date对象(默认时区)
-            return Date.from(firstDayOfLastMonth.atStartOfDay()
-                    .atZone(ZoneId.systemDefault())
-                    .toInstant());
-        }
-    }
-    /**
-     * 1.参数中有值取参数
-     * 2.参数没有值则默认取上个月最后一天
-     * @param map
-     * @return
-     */
-    protected Date getEndDate(Map<String, Object> map){
-        if(map.containsKey("endDate") && StringUtils.isNotEmpty((String)map.get("endDate"))){
-            String endDateStr = (String)map.get("endDate");
-            return DateUtils.parseDate(endDateStr);
-        }else{
-            // 获取当前日期
-            LocalDate today = LocalDate.now();
+        Arrays.stream(personPositionJobBakArray).forEach(jobBakInfo -> createPersonPotitionJobQuota(jobBakInfo,limitRelasetExpenseItemMap));
 
-            // 获取上个月的最后一天
-            LocalDate lastDayOfLastMonth = today.withDayOfMonth(1).minusDays(1);
+        logger.info("-----------PersonReimQuotaSyncTask end--------------" );
 
-            // 转换为Date对象(默认时区)
-            return Date.from(lastDayOfLastMonth.atStartOfDay()
-                    .atZone(ZoneId.systemDefault())
-                    .toInstant());
-        }
     }
 
-
-    /**
-     *  查询指定时间范围存在职位变更的人员信息,创建个人额度
-     * @param beginDate 开始时间
-     * @param endDate 结束时间
-     */
-    protected void syncMonthPersonReim(Date beginDate , Date endDate){
-
-        // 从任职经历中查询岗位发生变化的数据
-        Set<Object> positionPersonSet = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPPOSORGREL, "person.id", new QFilter[]{
-                new QFilter("startdate", QCP.large_equals, beginDate),
-                new QFilter("startdate", QCP.less_equals, endDate),
-                new QFilter("businessstatus", QCP.equals, "1"),
-                new QFilter("iscurrentversion", QCP.equals, "1"),
-                new QFilter("isprimary", QCP.equals, "1")
-        }).stream().map(r -> r.get("person.id")).collect(Collectors.toSet());
-
-        // 从职级职等中共查询职级发生变化的数据
-        Set<Object> jobPersonSet = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPJOBREL, "person.id", new QFilter[]{
-                new QFilter("startdate", QCP.large_equals, beginDate),
-                new QFilter("startdate", QCP.less_equals, endDate),
-                new QFilter("businessstatus", QCP.equals, "1"),
-                new QFilter("iscurrentversion", QCP.equals, "1")
-        }).stream().map(r -> r.get("person.id")).collect(Collectors.toSet());
-
-        // 合并去重,得到日期范围内变动了岗位或者职级的人员信息
-        positionPersonSet.addAll(jobPersonSet);
-        logger.info(String.format("查询到岗位或者职级发生变化人员数量为:{} 将开始按照100分批处理。",positionPersonSet.size()));
-        List<List<Object>> partition = Lists.partition(new ArrayList<>(positionPersonSet), 100);
-
-        boolean hasErrorData = false;
-        for(List<Object> patchList : partition){
-
-            try{
-                List<DynamicObject> taskCol = new ArrayList<>();
-                // 根据人员生成额度信息
-                patchList.stream().forEach(r -> taskCol.add(generalPersonReimTask(r,beginDate,endDate)));
-
-                // 移除人员、年、月已存在的数据;移除岗位没有发生变化的数据
-                removeErrorData(taskCol);
-//                Object[] successBillIds = SaveServiceHelper.save(taskCol.toArray(new DynamicObject[0]));
-//                List<Object> successBillIdList = Arrays.stream(successBillIds).filter(r -> r instanceof DynamicObject).map(r -> ((DynamicObject) r).getPkValue()).collect(Collectors.toList());
-//                OperationResult operationResult = OperationServiceHelper.executeOperate(PersonReimSyncTaskConstant.OPERATE.SYNCPERSONREIM,
-//                        PersonReimSyncTaskConstant.ENTITYID, successBillIdList.toArray(), OperateOption.create());
-//                if(!operationResult.isSuccess()){
-//                    hasErrorData = true;
-//                }
-
-            }catch (Exception e){
-                // 发生异常时通过调任务通知,通过任务日志和monitor日志查看失败原因。
-                logger.error("分批执行创建人员额度同步任务异常",e);
-                hasErrorData = true;
-            }
+    protected void createPersonPotitionJobQuota(DynamicObject jobBakInfo,Map<Long, Map<Long, List<DynamicObject>>> limitRelasetExpenseItemMap){
+
+        String userNumber = jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getString(JobPositionBakBillConstant.KEY_NUMBER);
+        // 判断组织是否发生变更
+            // 1.旧公司为空  新公司不为空
+        if( (jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD) == null && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW) != null)){
+            //创建新公司下的个人额度
+            logger.info(String.format("人员【%s】新增公司,开始创建公司【%s】下的个人额度。",userNumber,jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getString(JobPositionBakBillConstant.KEY_NAME)));
+            createQuotaJobleverChange(jobBakInfo,limitRelasetExpenseItemMap,ReimAmountSourceTypeEnum.COMPANYCHANGE);
+            createQuotaPositionChange(jobBakInfo,limitRelasetExpenseItemMap,ReimAmountSourceTypeEnum.COMPANYCHANGE);
+            return;
         }
-        if(hasErrorData){
-            throw new KDBizException("同步人员额度时发生异常,请查询原因后再执行。");
+             // 2.旧公司不为空  新公司为空
+        if( (jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD) != null && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW) == null)){
+            logger.info(String.format("人员【%s】离职,开始作废公司【%s】下的个人额度。",userNumber,jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getString(JobPositionBakBillConstant.KEY_NAME)));
+            //将旧公司下创建的个人额度关闭
+            personReimQuotaHelper.doInvalidPersonReim(new QFilter[]{
+                    new QFilter("company.id", QCP.equals, jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD).getLong(JobPositionBakBillConstant.ID)),
+                    new QFilter("user.id", QCP.equals, jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID))
+            });
+            return;
+        }
+            // 2.新、旧公司不为空且不相等
+        if( (jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD) != null && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW) != null)
+                && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD).getLong(JobPositionBakBillConstant.ID) != jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getLong(JobPositionBakBillConstant.ID)){
+            logger.info(String.format("人员【%s】组织变更,开始作废公司【%s】下的个人额度,同时创建公司【%s】下的个人额度",userNumber,
+                    jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD).getString(JobPositionBakBillConstant.KEY_NAME),
+                    jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_NEW).getString(JobPositionBakBillConstant.KEY_NAME)));
+            //判断新旧公司是否一致
+            //将旧公司下创建的个人额度关闭
+            personReimQuotaHelper.doInvalidPersonReim(new QFilter[]{
+                    new QFilter("company.id", QCP.equals, jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_ORG_OLD).getLong(JobPositionBakBillConstant.ID)),
+                    new QFilter("user.id", QCP.equals, jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_USER).getLong(JobPositionBakBillConstant.ID))
+            });
+            createQuotaJobleverChange(jobBakInfo,limitRelasetExpenseItemMap,ReimAmountSourceTypeEnum.COMPANYCHANGE);
+            createQuotaPositionChange(jobBakInfo,limitRelasetExpenseItemMap,ReimAmountSourceTypeEnum.COMPANYCHANGE);
+            return;
         }
 
-    }
-
-    /**
-     * 移除不符合条件的数据
-     * @param taskCol
-     */
-    protected void removeErrorData(List<DynamicObject> taskCol){
+        // 判断职级是否发生变更
+        if( jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_OLD) != null && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_NEW) != null
+            && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_OLD).getLong(JobPositionBakBillConstant.ID) != jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_JOBLEVEL_NEW).getLong(JobPositionBakBillConstant.ID)){
+            logger.info(String.format("人员【%s】职级发生变动,开始创建个人额度。",userNumber));
+            createQuotaJobleverChange(jobBakInfo,limitRelasetExpenseItemMap,null);
+        }
 
-        Iterator<DynamicObject> it = taskCol.iterator();
-        while (it.hasNext()){
-            DynamicObject taskInfo = it.next();
-            // 移除空数据
-            if(taskInfo == null){
-                it.remove();
-            }
+        // 判断岗位是否发生变更
+        if( jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_POSITION_OLD) != null && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_POSITION_OLD) != null
+            && jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_POSITION_OLD).getLong(JobPositionBakBillConstant.ID) != jobBakInfo.getDynamicObject(JobPositionBakBillConstant.KEY_NCKD_POSITION_NEW).getLong(JobPositionBakBillConstant.ID)){
+            logger.info(String.format("人员【%s】岗位发生变动,开始创建个人额度。",userNumber));
+            createQuotaPositionChange(jobBakInfo,limitRelasetExpenseItemMap,null);
+        }
+    }
 
-            // 移除岗位、职级没有发生变化的数据(只有公司发生变动不处理)
-            if(taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE) != null
-                    && taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR).getPkValue().equals(taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE).getPkValue())
-                && taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE) != null
-                    && taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR).getPkValue().equals(taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE).getPkValue())){
-                it.remove();
+    protected 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));
+                    personReimQuotaHelper.createPersonReimAmount(personReimQuotaVO);
+                }
             }
+        }
+    }
 
-            // 移除已存在的数据
-            QFilter[] filterList = new QFilter[]{
-                    new QFilter(PersonReimSyncTaskConstant.KEY_NCKD_USER,QCP.equals,taskInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_USER).getPkValue()),
-                    new QFilter(PersonReimSyncTaskConstant.KEY_NCKD_YEAR,QCP.equals,taskInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_YEAR)),
-                    new QFilter(PersonReimSyncTaskConstant.KEY_NCKD_MONTH,QCP.equals,taskInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_MONTH))
-            };
-
-            if(ORM.create().exists(PersonReimSyncTaskConstant.ENTITYID,filterList)){
-                it.remove();
+    protected 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));
+                    personReimQuotaHelper.createPersonReimAmount(personReimQuotaVO);
+                }
             }
         }
     }
 
 
-    /**
-     * 生成人员额度同步任务
-     * @param personId
-     * @param beginDate
-     * @param endDate
-     * @return
-     */
-    protected DynamicObject generalPersonReimTask(Object personId,Date beginDate , Date endDate){
-        Date now = new Date();
-        DynamicObject taskInfo = BusinessDataServiceHelper.newDynamicObject(PersonReimSyncTaskConstant.ENTITYID);
-        // 设置人员
-        DynamicObject hrPerson = QueryServiceHelper.queryOne(BillTypeConstants.HRPI_PERSON, "number", new QFilter("id", QCP.equals, personId).toArray());
-        DynamicObject userInfo = BusinessDataServiceHelper.loadSingleFromCache("bos_user", new QFilter("number", QCP.equals, hrPerson.getString("number")).toArray());
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_USER,userInfo);
-        // 设置人员最新的岗位、公司信息
-        setNewPosition(taskInfo,personId,beginDate,endDate);
-        // 设置人员最新的职级信息
-        setNewJob(taskInfo,personId,beginDate,endDate);
-        // 设置人员上个月之前的最新岗位、公司信息
-        setOldPosition(taskInfo,personId,beginDate,endDate);
-        // 设置人员上个月之前的最新的职级信息
-        setOldJob(taskInfo,personId,beginDate,endDate);
-
-        // 其他字段初始化赋值
-        int year = CommonUtils.getDateFeild(now, Calendar.YEAR);
-        int month = CommonUtils.getDateFeild(now, Calendar.MONTH);
-
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_YEAR,year);
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_MONTH,month+1);
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_ENABLE,"1");
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_STATUS,"C");
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_SYNCSTATUS, SyncStatusEnum.UNSYNC.getValue());
-        // 返回对象
-        return taskInfo;
-    }
 
-    protected void setNewPosition(DynamicObject taskInfo,Object personId,Date beginDate , Date endDate){
-        // 设置人员最新的岗位、公司信息
-        DynamicObject potisionInfo = QueryServiceHelper.queryOne(BillTypeConstants.HRPI_EMPPOSORGREL, "position.id,company.number", new QFilter[]{
-                new QFilter("businessstatus", QCP.equals, "1"),
-                new QFilter("iscurrentversion", QCP.equals, "1"),
-                new QFilter("person.id", QCP.equals, personId),
-                new QFilter("isprimary", QCP.equals, "1")
-        });
-        if(potisionInfo == null){
-            return ;
-        }
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR,potisionInfo.get("position.id"));
-        DynamicObject orgInfo = BusinessDataServiceHelper
-                .loadSingleFromCache("bos_org", new QFilter("number", QCP.equals, potisionInfo.getString("company.number")).toArray());
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_ORG,orgInfo);
+    protected DynamicObject[] getPersonPositionJobBakCol() {
+        Set<Long> bakBillIdSet = QueryServiceHelper.query(JobPositionBakBillConstant.ENTITYID, JobPositionBakBillConstant.ID, QFilter.isNotNull(JobPositionBakBillConstant.ID).toArray())
+                .stream()
+                .map(r -> r.getLong(JobPositionBakBillConstant.ID))
+                .collect(Collectors.toSet());
+        return BusinessDataServiceHelper.load(bakBillIdSet.toArray(), EntityMetadataCache.getDataEntityType(JobPositionBakBillConstant.ENTITYID));
     }
 
-    protected void setNewJob(DynamicObject taskInfo,Object personId,Date beginDate , Date endDate){
-        // 设置人员最新的岗位、公司信息
-        DynamicObject jobInfo = QueryServiceHelper.queryOne(BillTypeConstants.HRPI_EMPJOBREL, "joblevel.id", new QFilter[]{
-                new QFilter("businessstatus", QCP.equals, "1"),
-                new QFilter("iscurrentversion", QCP.equals, "1"),
-                new QFilter("person.id", QCP.equals, personId)
-        });
-        if(jobInfo == null){
-            return ;
-        }
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR,jobInfo.get("joblevel.id"));
-    }
-    protected void setOldPosition(DynamicObject taskInfo,Object personId,Date beginDate , Date endDate){
-        // 开始日期之前,最新的岗位
-        DynamicObjectCollection positionCol = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPPOSORGREL, "position.id,company.number", new QFilter[]{
-                new QFilter("enddate", QCP.less_than, beginDate),
-                new QFilter("iscurrentversion", QCP.equals, "1"),
-                new QFilter("person.id", QCP.equals, personId),
-                new QFilter("isprimary", QCP.equals, "1")
-        }, "enddate desc", 1);
-        if(CollectionUtils.isEmpty(positionCol)){
-            return ;
-        }
-        DynamicObject potisionInfo = positionCol.get(0);
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE,potisionInfo.get("position.id"));
-        DynamicObject orgInfo = BusinessDataServiceHelper
-                .loadSingleFromCache("bos_org", new QFilter("number", QCP.equals, potisionInfo.getString("company.number")).toArray());
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_ORG_PRE,orgInfo);
-    }
-
-
-    protected void setOldJob(DynamicObject taskInfo,Object personId,Date beginDate , Date endDate){
-        // 设置人员最新的岗位、公司信息
-        DynamicObjectCollection jobCol = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPJOBREL, "joblevel.id", new QFilter[]{
-                new QFilter("startdate", QCP.equals, beginDate),
-                new QFilter("iscurrentversion", QCP.equals, "1"),
-                new QFilter("person.id", QCP.equals, personId)
-        }, "enddate desc", 1);
-        if(CollectionUtils.isEmpty(jobCol)){
-            return ;
-        }
-        taskInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE,jobCol.get(0).get("joblevel.id"));
+    protected 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)
+                )));
     }
 }