Parcourir la source

1.个人额度同步后台任务

lisheng il y a 4 jours
Parent
commit
b878b214a6

+ 102 - 204
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/operate/PersonReimSyncTaskOp.java → code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/operate/Helper/PersonReimQuotaHelper.java

@@ -1,28 +1,16 @@
-package nckd.jimin.jyyy.fi.plugin.operate;
+package nckd.jimin.jyyy.fi.plugin.operate.Helper;
 
-import com.google.common.collect.Lists;
 import kd.bos.context.RequestContext;
 import kd.bos.dataentity.OperateOption;
 import kd.bos.dataentity.entity.DynamicObject;
-import kd.bos.dataentity.entity.DynamicObjectCollection;
-import kd.bos.dataentity.utils.StringUtils;
-import kd.bos.db.tx.TX;
-import kd.bos.db.tx.TXHandle;
-import kd.bos.entity.EntityMetadataCache;
-import kd.bos.entity.operate.result.OperateErrorInfo;
 import kd.bos.entity.operate.result.OperationResult;
-import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
-import kd.bos.entity.plugin.PreparePropertysEventArgs;
-import kd.bos.entity.plugin.args.AfterOperationArgs;
-import kd.bos.entity.validate.ErrorLevel;
 import kd.bos.exception.KDBizException;
-import kd.bos.logging.Log;
-import kd.bos.logging.LogFactory;
 import kd.bos.org.utils.DynamicObjectUtils;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
 import kd.bos.servicehelper.BusinessDataServiceHelper;
 import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
 import kd.bos.servicehelper.operation.OperationServiceHelper;
 import kd.bos.servicehelper.operation.SaveServiceHelper;
 import kd.fi.gl.util.BigDecimalUtil;
@@ -35,88 +23,62 @@ import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
-public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
-    private static final Log logger = LogFactory.getLog(PersonReimSyncTaskOp.class);
-    @Override
-    public void onPreparePropertys(PreparePropertysEventArgs e) {
-        super.onPreparePropertys(e);
-    }
+public class PersonReimQuotaHelper {
+    /**
+     * 通过 费用项目与职级岗位关系配置 获取额度信息
+     * 按照币别分组,允许设置不同币别的方案
+     * @return
+     */
+    public Map<Long, Map<Long, BigDecimal>> getExpenseJobAmount(Object positionId , Object jobLeverId){
 
-    @Override
-    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
-        super.afterExecuteOperationTransaction(e);
-        DynamicObject[] dataEntities = e.getDataEntities();
-        String operationKey = e.getOperationKey();
+        StringJoiner joiner = new StringJoiner(",");
+        joiner.add(LimitRelasetConstant.KEY_NCKD_CURRENCY);
+        joiner.add(LimitRelasetConstant.KEY_NCKD_EXPENSEITEM);
+        joiner.add(LimitRelasetConstant.KEY_NCKD_AMOUNT);
 
-        List<Object> billIdList = Arrays.stream(dataEntities).map(r -> r.get(PersonReimSyncTaskConstant.ID)).collect(Collectors.toList());
-        // 同步个人额度
-        if(PersonReimSyncTaskConstant.OPERATE.SYNCPERSONREIM.equals(operationKey)){
-            List<List<Object>> patchList = Lists.partition(billIdList, 50);
-            for(List<Object> patchBillList : patchList){
-                DynamicObject[] billDatas = BusinessDataServiceHelper.load(patchBillList.toArray(), EntityMetadataCache.getDataEntityType(PersonReimSyncTaskConstant.ENTITYID));
-                Arrays.stream(billDatas).forEach(r -> doSyncPersonReim(r));
-            }
+        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)));
     }
-    protected void doSyncPersonReim(DynamicObject billInfo){
-        // 校验数据是否合格
-        DynamicObject user = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_USER);
-        DynamicObject org = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG);
-        DynamicObject preOrg = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG_PRE);
-        DynamicObject position = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR);
-        DynamicObject prePosition = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE);
-        DynamicObject jobLever = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR);
-        DynamicObject preJobLever = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE);
 
-        int year = billInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_YEAR);
-        // 增加事务控制,如果发生异常,回滚生成的额度信息,保持数据一致
-        try(TXHandle h = TX.requiresNew(getClass().getName()+"doSyncPersonReim")){
-            try {
-                // 校验数据
-                checkData(billInfo);
-                // 获取总额度  费用项目、职级、岗位
-                Map<Long, Map<Long, BigDecimal>> currencyReimJobAmount = getExpenseJobAmount(position.getPkValue(), jobLever.getPkValue());
-                // 判断组织是否存在便变更,组织变更则作废原组织
-                if(!org.getPkValue().equals(preOrg.getPkValue())){
-                    doInvalidPersonReim(user.getLong(PersonReimSyncTaskConstant.ID),preOrg.getLong(PersonReimSyncTaskConstant.ID),null,null,year);
-                }
-
-                // 变更前岗位、职位为空,直接新增
-                if(prePosition == null || preJobLever == null){
-                    createPersonReimDirect(billInfo,currencyReimJobAmount);
-                }else{
-                    Map<Long, Map<Long, BigDecimal>> sourceCurrencyReimJobAmount = getExpenseJobAmount(prePosition.getPkValue(), preJobLever.getPkValue());
-                    Set<Long> invalidCurrencySet = sourceCurrencyReimJobAmount.keySet().stream()
-                            .filter(r -> !currencyReimJobAmount.keySet().contains(r)).collect(Collectors.toSet());
-                    // 作废已删除的币别数据
-                    logger.info(String.format("需要作废的币别ID为:" + StringUtils.join(",",invalidCurrencySet)));
-                    invalidCurrencySet.forEach(r -> doInvalidPersonReim(user.getLong(PersonReimSyncTaskConstant.ID),org.getLong(PersonReimSyncTaskConstant.ID),null,r,year));
-                    for(Map.Entry<Long, Map<Long, BigDecimal>> currencyRow : currencyReimJobAmount.entrySet()){
-                        Long currencyId = currencyRow.getKey();
-                        Map<Long, BigDecimal> expenseJobAmount = currencyRow.getValue();
-                        if(sourceCurrencyReimJobAmount.containsKey(currencyId)){
-                            Set<Long> invalidExpenseSet = sourceCurrencyReimJobAmount.get(currencyId).keySet().stream()
-                                    .filter(r -> !expenseJobAmount.keySet().contains(r)).collect(Collectors.toSet());
-                            logger.info(String.format("需要作废的费用类型ID为:" + StringUtils.join(",",invalidExpenseSet)));
-                            invalidExpenseSet.forEach(r -> doInvalidPersonReim(user.getLong(PersonReimSyncTaskConstant.ID),org.getLong(PersonReimSyncTaskConstant.ID),r,currencyId,year));
-                        }
-                        for(Map.Entry<Long, BigDecimal> dataRow : expenseJobAmount.entrySet()){
-                            Long expenseItemId = dataRow.getKey();
-                            BigDecimal amount = dataRow.getValue();
-                            createPersonReimByExpense(billInfo,currencyId,expenseItemId,amount);
-                        }
-                    }
-                }
-                addRecord(billInfo,"创建成功。",Boolean.TRUE);
-            }catch (Exception e){
-                logger.error(String.format("单据%s同步额度失败",billInfo.getString(PersonReimSyncTaskConstant.KEY_NUMBER)),e);
-                String errorMsg = StringUtils.isEmpty(e.getMessage())?"同步额度时发生未知异常,请用traceid在monitor通过任务编码查看日志详情。":e.getMessage();
-                addRecord(billInfo,errorMsg,Boolean.FALSE);
-                h.markRollback();
+    /**
+     * 作废条件范围内的个人额度信息
+     * @param userId
+     * @param companyId
+     * @param expenseItemId
+     * @param currencyId
+     */
+    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);
         }
-        SaveServiceHelper.save(new DynamicObject[]{billInfo});
     }
 
     /**
@@ -124,7 +86,7 @@ public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
      * @param billInfo
      * @param currencyReimJobAmount
      */
-    protected void createPersonReimDirect(DynamicObject billInfo,Map<Long, Map<Long, BigDecimal>> 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();
@@ -136,13 +98,18 @@ public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
         }
     }
 
-    protected void createPersonReimByExpense(DynamicObject billInfo,Long currencyId,Long expenseItemId,BigDecimal amount){
-        // 创建个人额度表
-        DynamicObject personReim = createPersonReim(
+    public void createPersonReimByExpense(DynamicObject billInfo,Long currencyId,Long expenseItemId,BigDecimal amount){
+
+        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);
+                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){
@@ -154,68 +121,20 @@ public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
         }
     }
 
-
-    protected void checkData(DynamicObject billInfo){
-        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_USER) == null){
-            throw new KDBizException("同步人员不能为空。");
-        }
-        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG) == null){
-            throw new KDBizException("组织不能为空。");
-        }
-        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR) == null){
-            throw new KDBizException("岗位人员不能为空。");
-        }
-        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR) == null){
-            throw new KDBizException("职级不能为空。");
-        }
-    }
-
-    /**
-     * 作废条件范围内的个人额度信息
-     * @param userId
-     * @param companyId
-     * @param expenseItemId
-     * @param currencyId
-     */
-    protected 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);
-        }
-    }
-
-
     /**
      * 获取个人额度同步表 创建某个费用类型的个人额度
-     * @param userId
-     * @param companyId
-     * @param expenseItemId
-     * @param currencyId
-     * @param amount
-     * @param billInfo
+     * @param quotaVO
      * @return
      */
-    protected DynamicObject createPersonReim(Long userId , Long companyId , Long expenseItemId ,Long currencyId,
-                                             BigDecimal amount , DynamicObject billInfo){
-
-        int year = billInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_YEAR);
+    public DynamicObject createPersonReim(PersonReimQuotaVO  quotaVO , boolean isAddnew){
 
-        int month = billInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_MONTH);
+        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();
@@ -240,6 +159,11 @@ public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
             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");
@@ -273,11 +197,37 @@ public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
 
         // 岗位新增变动:positionchange ;年度复制:yearcopy  ; 新增字段,与标准字段区分,防止与标品逻辑冲突
         personAmountBill.set("nckd_sourcetype","positionchange");
-        personAmountBill.set("nckd_sourcebillid",billInfo.getPkValue());
+        personAmountBill.set("nckd_sourcebillid",quotaVO.getSourcebillid());
 
         return personAmountBill;
     }
 
+    public void syncReimLever(Long userId ,Long companyId,Long jobId){
+
+        DynamicObject reimLever = getReimLever(jobId, companyId);
+        if(reimLever != null){
+            DynamicObject realReimSettingQuery = QueryServiceHelper.queryOne("er_reimbursesetting_rel", "id", new QFilter[]{
+                    new QFilter("user", QCP.equals, userId),
+                    new QFilter("company", QCP.equals, companyId)
+            });
+            // 存在则修改
+            if(realReimSettingQuery != null){
+                DynamicObject reimSettingInfo = BusinessDataServiceHelper.loadSingle(realReimSettingQuery.get("id"),"er_reimbursesetting_rel");
+                reimSettingInfo.set("reimburselevel",reimLever.get("id"));
+                SaveServiceHelper.save(new DynamicObject[]{ reimSettingInfo });
+            }
+        }
+    }
+
+    private DynamicObject getReimLever(Long jobId , Long companyId) {
+        // 查询差旅级别
+        List<QFilter> leverFilterList = new ArrayList<>();
+        // 基础资料标准过滤条件
+        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]));
+    }
     /**
      * 对个人额度表的额度字段赋值
      * @param personAmountBill 个人额度表
@@ -293,56 +243,4 @@ public class PersonReimSyncTaskOp extends AbstractOperationServicePlugIn {
         }
 
     }
-
-
-    protected void addRecord(DynamicObject billInfo , String successMsg , Boolean isSuccess){
-        DynamicObjectCollection recordEntryCol = billInfo.getDynamicObjectCollection(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.ENTITYID);
-        DynamicObject record = recordEntryCol.addNew();
-        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_SYNC_DATE,new Date());
-        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_TRACEID, RequestContext.get().getTraceId());
-        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_SYNC_ISSUCCESS,isSuccess?1:0);
-        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_SYNC_MSG, StringUtils.substring(successMsg,0,500));
-
-        billInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_SYNCSTATUS,isSuccess?"40":"30");
-
-        if(!isSuccess){
-            OperationResult operationResult = this.getOperationResult();
-            operationResult.setSuccess(false);
-            operationResult.getSuccessPkIds().removeIf(r -> billInfo.getPkValue().equals(r));
-            OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
-            operateErrorInfo.setMessage(successMsg);
-            operateErrorInfo.setLevel(ErrorLevel.Error);
-            operationResult.addErrorInfo(operateErrorInfo);
-        }
-
-
-    }
-
-    /**
-     * 通过 费用项目与职级岗位关系配置 获取额度信息
-     * 按照币别分组,允许设置不同币别的方案
-     * @return
-     */
-    protected 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)));
-    }
 }

+ 170 - 0
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/operate/PersonReimSyncQuotaTaskOp.java

@@ -0,0 +1,170 @@
+package nckd.jimin.jyyy.fi.plugin.operate;
+
+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.dataentity.utils.StringUtils;
+import kd.bos.db.tx.TX;
+import kd.bos.db.tx.TXHandle;
+import kd.bos.entity.EntityMetadataCache;
+import kd.bos.entity.operate.result.OperateErrorInfo;
+import kd.bos.entity.operate.result.OperationResult;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.PreparePropertysEventArgs;
+import kd.bos.entity.plugin.args.AfterOperationArgs;
+import kd.bos.entity.plugin.args.InitOperationArgs;
+import kd.bos.entity.validate.ErrorLevel;
+import kd.bos.exception.KDBizException;
+import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import nckd.jimin.jyyy.fi.common.constant.PersonReimSyncTaskConstant;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
+
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class PersonReimSyncQuotaTaskOp extends AbstractOperationServicePlugIn {
+    private static final Log logger = LogFactory.getLog(PersonReimSyncQuotaTaskOp.class);
+
+    protected PersonReimQuotaHelper personReimQuotaHelper;
+    @Override
+    public void initialize(InitOperationArgs e) {
+        super.initialize(e);
+        personReimQuotaHelper = new PersonReimQuotaHelper();
+    }
+
+    @Override
+    public void onPreparePropertys(PreparePropertysEventArgs e) {
+        super.onPreparePropertys(e);
+    }
+
+    @Override
+    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
+        super.afterExecuteOperationTransaction(e);
+        DynamicObject[] dataEntities = e.getDataEntities();
+        String operationKey = e.getOperationKey();
+
+        List<Object> billIdList = Arrays.stream(dataEntities).map(r -> r.get(PersonReimSyncTaskConstant.ID)).collect(Collectors.toList());
+        // 同步个人额度
+        if(PersonReimSyncTaskConstant.OPERATE.SYNCPERSONREIM.equals(operationKey)){
+            List<List<Object>> patchList = Lists.partition(billIdList, 50);
+            for(List<Object> patchBillList : patchList){
+                DynamicObject[] billDatas = BusinessDataServiceHelper.load(patchBillList.toArray(), EntityMetadataCache.getDataEntityType(PersonReimSyncTaskConstant.ENTITYID));
+                Arrays.stream(billDatas).forEach(r -> doSyncPersonReim(r));
+            }
+        }
+
+    }
+    protected void doSyncPersonReim(DynamicObject billInfo){
+        // 校验数据是否合格
+        DynamicObject user = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_USER);
+        DynamicObject org = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG);
+        DynamicObject preOrg = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG_PRE);
+        DynamicObject position = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR);
+        DynamicObject prePosition = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE);
+        DynamicObject jobLever = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR);
+        DynamicObject preJobLever = billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE);
+
+        int year = billInfo.getInt(PersonReimSyncTaskConstant.KEY_NCKD_YEAR);
+        // 增加事务控制,如果发生异常,回滚生成的额度信息,保持数据一致
+        try(TXHandle h = TX.requiresNew(getClass().getName()+"doSyncPersonReim")){
+            try {
+                // 校验数据
+                checkData(billInfo);
+                // 获取总额度  费用项目、职级、岗位
+                Map<Long, Map<Long, BigDecimal>> currencyReimJobAmount = personReimQuotaHelper.getExpenseJobAmount(position.getPkValue(), jobLever.getPkValue());
+                // 判断组织是否存在便变更,组织变更则作废原组织
+                if(!org.getPkValue().equals(preOrg.getPkValue())){
+                    personReimQuotaHelper.doInvalidPersonReim(user.getLong(PersonReimSyncTaskConstant.ID),preOrg.getLong(PersonReimSyncTaskConstant.ID),null,null,year);
+                }
+
+                // 变更前岗位、职位为空,直接新增
+                if(prePosition == null || preJobLever == null){
+                    personReimQuotaHelper.createPersonReimDirect(billInfo,currencyReimJobAmount);
+                }else{
+                    Map<Long, Map<Long, BigDecimal>> sourceCurrencyReimJobAmount = personReimQuotaHelper.getExpenseJobAmount(prePosition.getPkValue(), preJobLever.getPkValue());
+                    Set<Long> invalidCurrencySet = sourceCurrencyReimJobAmount.keySet().stream()
+                            .filter(r -> !currencyReimJobAmount.keySet().contains(r)).collect(Collectors.toSet());
+                    // 作废已删除的币别数据
+                    logger.info(String.format("需要作废的币别ID为:" + StringUtils.join(",",invalidCurrencySet)));
+                    invalidCurrencySet.forEach(r -> personReimQuotaHelper.doInvalidPersonReim(user.getLong(PersonReimSyncTaskConstant.ID),org.getLong(PersonReimSyncTaskConstant.ID),null,r,year));
+                    for(Map.Entry<Long, Map<Long, BigDecimal>> currencyRow : currencyReimJobAmount.entrySet()){
+                        Long currencyId = currencyRow.getKey();
+                        Map<Long, BigDecimal> expenseJobAmount = currencyRow.getValue();
+                        if(sourceCurrencyReimJobAmount.containsKey(currencyId)){
+                            Set<Long> invalidExpenseSet = sourceCurrencyReimJobAmount.get(currencyId).keySet().stream()
+                                    .filter(r -> !expenseJobAmount.keySet().contains(r)).collect(Collectors.toSet());
+                            logger.info(String.format("需要作废的费用类型ID为:" + StringUtils.join(",",invalidExpenseSet)));
+                            invalidExpenseSet.forEach(r -> personReimQuotaHelper.doInvalidPersonReim(user.getLong(PersonReimSyncTaskConstant.ID),org.getLong(PersonReimSyncTaskConstant.ID),r,currencyId,year));
+                        }
+                        for(Map.Entry<Long, BigDecimal> dataRow : expenseJobAmount.entrySet()){
+                            Long expenseItemId = dataRow.getKey();
+                            BigDecimal amount = dataRow.getValue();
+                            personReimQuotaHelper.createPersonReimByExpense(billInfo,currencyId,expenseItemId,amount);
+                        }
+                    }
+                }
+                addRecord(billInfo,"创建成功。",Boolean.TRUE);
+            }catch (Exception e){
+                logger.error(String.format("单据%s同步额度失败",billInfo.getString(PersonReimSyncTaskConstant.KEY_NUMBER)),e);
+                String errorMsg = StringUtils.isEmpty(e.getMessage())?"同步额度时发生未知异常,请用traceid在monitor通过任务编码查看日志详情。":e.getMessage();
+                addRecord(billInfo,errorMsg,Boolean.FALSE);
+                h.markRollback();
+            }
+        }
+        SaveServiceHelper.save(new DynamicObject[]{billInfo});
+    }
+
+
+
+
+    protected void checkData(DynamicObject billInfo){
+        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_USER) == null){
+            throw new KDBizException("同步人员不能为空。");
+        }
+        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_ORG) == null){
+            throw new KDBizException("组织不能为空。");
+        }
+        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR) == null){
+            throw new KDBizException("岗位人员不能为空。");
+        }
+        if(billInfo.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR) == null){
+            throw new KDBizException("职级不能为空。");
+        }
+    }
+
+
+
+
+
+
+
+    protected void addRecord(DynamicObject billInfo , String successMsg , Boolean isSuccess){
+        DynamicObjectCollection recordEntryCol = billInfo.getDynamicObjectCollection(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.ENTITYID);
+        DynamicObject record = recordEntryCol.addNew();
+        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_SYNC_DATE,new Date());
+        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_TRACEID, RequestContext.get().getTraceId());
+        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_SYNC_ISSUCCESS,isSuccess?1:0);
+        record.set(PersonReimSyncTaskConstant.NCKD_RECORDENTRY.KEY_NCKD_SYNC_MSG, StringUtils.substring(successMsg,0,500));
+
+        billInfo.set(PersonReimSyncTaskConstant.KEY_NCKD_SYNCSTATUS,isSuccess?"40":"30");
+
+        if(!isSuccess){
+            OperationResult operationResult = this.getOperationResult();
+            operationResult.setSuccess(false);
+            operationResult.getSuccessPkIds().removeIf(r -> billInfo.getPkValue().equals(r));
+            OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
+            operateErrorInfo.setMessage(successMsg);
+            operateErrorInfo.setLevel(ErrorLevel.Error);
+            operationResult.addErrorInfo(operateErrorInfo);
+        }
+
+
+    }
+
+
+}

+ 13 - 31
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/task/PersonReimLeverSyncTask.java

@@ -5,27 +5,24 @@ import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
 import kd.bos.exception.KDException;
 import kd.bos.logging.Log;
+import kd.bos.logging.LogFactory;
 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.basedata.BaseDataServiceHelper;
-import kd.bos.servicehelper.operation.SaveServiceHelper;
 import kd.bos.util.StringUtils;
 import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 import java.util.Map;
-import kd.bos.logging.LogFactory;
+import java.util.Optional;
 
 
 /**
@@ -35,6 +32,12 @@ public class PersonReimLeverSyncTask extends AbstractTask implements StopTask {
 
     private static final Log log = LogFactory.getLog(PersonReimLeverSyncTask.class);
 
+    private PersonReimQuotaHelper personReimQuotaHelper = new PersonReimQuotaHelper();
+
+
+    protected PersonReimQuotaHelper getPersonReimQuotaHelper() {
+        return Optional.ofNullable(personReimQuotaHelper).orElse(new PersonReimQuotaHelper());
+    }
     private static final String SYNCDATE = "syncdate";
     @Override
     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
@@ -91,22 +94,9 @@ public class PersonReimLeverSyncTask extends AbstractTask implements StopTask {
             return;
         }
         String companyNumber = potisionInfo.getString("company.number");
-        DynamicObject company = QueryServiceHelper.queryOne("bos_org", "id", new QFilter[]{
-                new QFilter("number", QCP.equals, companyNumber)
-        });
-        DynamicObject reimLever = getReimLever(jobId, company.getLong("id"));
-        if(reimLever != null){
-            DynamicObject realReimSettingQuery = QueryServiceHelper.queryOne("er_reimbursesetting_rel", "id", new QFilter[]{
-                    new QFilter("user.number", QCP.equals, personNumber),
-                    new QFilter("company", QCP.equals, company.getLong("id"))
-            });
-            // 存在则修改
-            if(realReimSettingQuery != null){
-                DynamicObject reimSettingInfo = BusinessDataServiceHelper.loadSingle(realReimSettingQuery.get("id"),"er_reimbursesetting_rel");
-                reimSettingInfo.set("reimburselevel",reimLever.get("id"));
-                SaveServiceHelper.save(new DynamicObject[]{ reimSettingInfo });
-            }
-        }
+        DynamicObject company = QueryServiceHelper.queryOne("bos_org", "id", new QFilter("number", QCP.equals, companyNumber).toArray());
+        DynamicObject userInfo = QueryServiceHelper.queryOne("bos_user", "id", new QFilter("number", QCP.equals, personNumber).toArray());
+        getPersonReimQuotaHelper().syncReimLever(userInfo.getLong("id"),jobId,company.getLong("id"));
 
     }
     private DynamicObject fetchPositionInfo(Long personId) {
@@ -118,14 +108,6 @@ public class PersonReimLeverSyncTask extends AbstractTask implements StopTask {
         });
     }
 
-    private DynamicObject getReimLever(Long jobId , Long companyId) {
-         // 查询差旅级别
-        List<QFilter> leverFilterList = new ArrayList<>();
-        // 基础资料标准过滤条件
-        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]));
-    }
+
 
 }

+ 57 - 40
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/task/PersonReimSyncTask.java → code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/task/PersonReimQuotaSyncTask.java

@@ -4,6 +4,7 @@ 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.exception.KDException;
 import kd.bos.logging.Log;
@@ -31,11 +32,11 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 /**
- * 个人额度更新功能
+ * 员工额度同步任务
  */
-public class PersonReimSyncTask extends AbstractTask implements StopTask {
+public class PersonReimQuotaSyncTask extends AbstractTask implements StopTask {
 
-    private static final Log logger = LogFactory.getLog(PersonReimSyncTask.class);
+    private static final Log logger = LogFactory.getLog(PersonReimQuotaSyncTask.class);
 
     @Override
     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
@@ -103,25 +104,25 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
         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.less_equals, "1"),
-                new QFilter("iscurrentversion", QCP.less_equals, "1"),
-                new QFilter("isprimary", QCP.less_equals, "1")
+                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.less_equals, "1"),
-                new QFilter("iscurrentversion", QCP.less_equals, "1")
+                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);
-        int totalCount = 0 ;
-        int successCount = 0;
+
+        boolean hasErrorData = false;
         for(List<Object> patchList : partition){
 
             try{
@@ -131,39 +132,49 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
 
                 // 移除人员、年、月已存在的数据;移除岗位没有发生变化的数据
                 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());
+//                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());
-//                totalCount+=successBillIds.length;
-//                successCount+=operationResult.getSuccessPkIds().size();
+//                if(!operationResult.isSuccess()){
+//                    hasErrorData = true;
+//                }
 
             }catch (Exception e){
-                // 失败的怎么处理
+                // 发生异常时通过调任务通知,通过任务日志和monitor日志查看失败原因。
                 logger.error("分批执行创建人员额度同步任务异常",e);
+                hasErrorData = true;
             }
         }
-        if(totalCount != successCount){
-            throw new KDBizException(String.format("总共执行%s条数据,存在%s条失败,请在人员同步任务中查看失败信息。",totalCount,totalCount-successCount));
+        if(hasErrorData){
+            throw new KDBizException("同步人员额度时发生异常,请查询原因后再执行。");
         }
 
     }
 
+    /**
+     * 移除不符合条件的数据
+     * @param taskCol
+     */
     protected void removeErrorData(List<DynamicObject> taskCol){
-        // 移除空数据
-        taskCol.removeIf(r -> Objects.isNull(r));
-
-        // 移除岗位、职级没有发生变化的数据(只有公司发生变动不处理)
-//        taskCol.removeIf(r -> r.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE) != null && r.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR).getPkValue()
-//                .equals(r.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_POSITIONHR_PRE).getPkValue())
-//                && r.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE) != null && r.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR).getPkValue()
-//                .equals(r.getDynamicObject(PersonReimSyncTaskConstant.KEY_NCKD_JOBLEVELHR_PRE).getPkValue()));
 
-        // 移除已存在的数据
         Iterator<DynamicObject> it = taskCol.iterator();
         while (it.hasNext()){
             DynamicObject taskInfo = it.next();
+            // 移除空数据
+            if(taskInfo == null){
+                it.remove();
+            }
+
+            // 移除岗位、职级没有发生变化的数据(只有公司发生变动不处理)
+            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();
+            }
+
+            // 移除已存在的数据
             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)),
@@ -177,7 +188,13 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
     }
 
 
-
+    /**
+     * 生成人员额度同步任务
+     * @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);
@@ -210,10 +227,10 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
     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.less_equals, "1"),
-                new QFilter("iscurrentversion", QCP.less_equals, "1"),
+                new QFilter("businessstatus", QCP.equals, "1"),
+                new QFilter("iscurrentversion", QCP.equals, "1"),
                 new QFilter("person.id", QCP.equals, personId),
-                new QFilter("isprimary", QCP.less_equals, "1")
+                new QFilter("isprimary", QCP.equals, "1")
         });
         if(potisionInfo == null){
             return ;
@@ -227,9 +244,9 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
     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.less_equals, "1"),
-                new QFilter("iscurrentversion", QCP.less_equals, "1"),
-                new QFilter("person.id", QCP.less_equals, personId)
+                new QFilter("businessstatus", QCP.equals, "1"),
+                new QFilter("iscurrentversion", QCP.equals, "1"),
+                new QFilter("person.id", QCP.equals, personId)
         });
         if(jobInfo == null){
             return ;
@@ -240,9 +257,9 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
         // 开始日期之前,最新的岗位
         DynamicObjectCollection positionCol = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPPOSORGREL, "position.id,company.number", new QFilter[]{
                 new QFilter("enddate", QCP.less_than, beginDate),
-                new QFilter("iscurrentversion", QCP.less_equals, "1"),
+                new QFilter("iscurrentversion", QCP.equals, "1"),
                 new QFilter("person.id", QCP.equals, personId),
-                new QFilter("isprimary", QCP.less_equals, "1")
+                new QFilter("isprimary", QCP.equals, "1")
         }, "enddate desc", 1);
         if(CollectionUtils.isEmpty(positionCol)){
             return ;
@@ -258,9 +275,9 @@ public class PersonReimSyncTask extends AbstractTask implements StopTask {
     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.less_than, beginDate),
-                new QFilter("iscurrentversion", QCP.less_equals, "1"),
-                new QFilter("person.id", QCP.less_equals, personId)
+                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 ;