Просмотр исходного кода

1.公司额度制度发生变化,手工更新所有人员的费用额度
2.公司差旅标准制度发生变化,手工更新所有人的差旅标准设置级别

lisheng 4 дней назад
Родитель
Сommit
741a60b3e6

+ 110 - 0
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/plugin/form/LimitRelasetList.java

@@ -0,0 +1,110 @@
+package nckd.jimin.jyyy.fi.plugin.form;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.kingdee.util.StringUtils;
+import kd.bos.context.RequestContext;
+import kd.bos.entity.operate.result.OperationResult;
+import kd.bos.form.CloseCallBack;
+import kd.bos.form.events.AfterDoOperationEventArgs;
+import kd.bos.form.events.ClosedCallBackEvent;
+import kd.bos.list.plugin.AbstractListPlugin;
+import kd.bos.schedule.api.JobInfo;
+import kd.bos.schedule.api.JobType;
+import kd.bos.schedule.api.TaskInfo;
+import kd.bos.schedule.form.JobForm;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+
+public class LimitRelasetList extends AbstractListPlugin {
+    private static final String OP_REFRESH_ALLQUOTA = "refresh_allquota";
+
+    private static final String OP_REFRESH_ALLLEVER = "refresh_alllever";
+
+
+    private PersonReimQuotaHelper personReimQuotaHelper;
+
+    @Override
+    public void initialize() {
+        super.initialize();
+        personReimQuotaHelper = new PersonReimQuotaHelper();
+    }
+
+    protected PersonReimQuotaHelper getPersonReimQuotaHelper() {
+        return Optional.ofNullable(personReimQuotaHelper).orElse(new PersonReimQuotaHelper());
+    }
+
+    @Override
+    public void afterDoOperation(AfterDoOperationEventArgs args) {
+        super.afterDoOperation(args);
+        String operateKey = args.getOperateKey();
+        OperationResult operationResult = args.getOperationResult();
+        if(operationResult != null && !operationResult.isSuccess()){
+            return;
+        }
+        if ( OP_REFRESH_ALLQUOTA.equals(operateKey)) {
+            dispatch("更新个人额度","updatequota");
+        }
+
+        if ( OP_REFRESH_ALLLEVER.equals(operateKey)) {
+            dispatch("更新差旅级别","updatelever");
+        }
+    }
+    /**
+     * 回调事件,在任务处理完毕后继续后续处理
+     */
+    @Override
+    public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
+        super.closedCallBack(closedCallBackEvent);
+        if (StringUtils.equals(closedCallBackEvent.getActionId(), "taskcloseback")) {
+            Object returnData = closedCallBackEvent.getReturnData();
+            if (returnData == null) {
+                return;
+            }
+            if (returnData instanceof Map) {
+                Map<String, Object> result = (Map<String, Object>)returnData;
+                if (result.containsKey("taskinfo")) {
+                    String taskInfoStr = (String)result.get("taskinfo");
+                    if (!StringUtils.isEmpty(taskInfoStr)) {
+                        TaskInfo taskInfo = JSON.parseObject(taskInfoStr,TaskInfo.class);
+                        if (taskInfo.isTaskEnd()) {
+                            // 获取任务执行完毕,生成的内容
+                            String data = taskInfo.getData();
+                            if(!StringUtils.isEmpty(data)){
+                                JSONObject dataJson = JSON.parseObject(data);
+                                this.getView().showSuccessNotification(dataJson.getString("message"));
+                            }else{
+                                this.getView().showSuccessNotification("执行成功。");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    /**
+     * 创建任务目标,发布新任务
+     */
+    private void dispatch(String jobName,String updateType) {
+        // 创建任务目标
+        JobInfo jobInfo = new JobInfo();
+        jobInfo.setAppId("em");                // 执行类所在的应用名
+        jobInfo.setJobType(JobType.REALTIME);   // 即时执行
+        jobInfo.setName(jobName);
+        jobInfo.setId(UUID.randomUUID().toString());        // 随机产生一个JobId (任务目标的标识)
+        jobInfo.setTaskClassname("nckd.jimin.jyyy.fi.task.PersonReimBigJobTask");
+        // 自定义参数
+        Map<String,Object> params = new HashMap<>();
+        params.put("updatetype", updateType);
+        jobInfo.setParams(params);
+        jobInfo.setRunByUserId(RequestContext.get().getCurrUserId());
+        // 回调参数,设置一个回调处理标识(actionId)
+        CloseCallBack closeCallBack = new CloseCallBack(this, "taskcloseback");
+        // 发布任务,并显示进度
+        JobForm.dispatch(jobInfo, this.getView(), closeCallBack);
+    }
+}

+ 134 - 0
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/task/PersonReimBigJobTask.java

@@ -0,0 +1,134 @@
+package nckd.jimin.jyyy.fi.task;
+
+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.entity.operate.result.OperationResult;
+import kd.bos.exception.KDBizException;
+import kd.bos.exception.KDException;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.schedule.executor.AbstractTask;
+import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.operation.OperationServiceHelper;
+import nckd.jimin.jyyy.fi.common.constant.BillTypeConstants;
+import nckd.jimin.jyyy.fi.common.util.CommonUtils;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaHelper;
+import nckd.jimin.jyyy.fi.plugin.operate.Helper.PersonReimQuotaVO;
+
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static kd.epm.emr.common.spread.domain.view.js.SpreadProperties.P.r;
+
+public class PersonReimBigJobTask extends AbstractTask {
+
+    private PersonReimQuotaHelper personReimQuotaHelper = new PersonReimQuotaHelper();
+
+
+    protected PersonReimQuotaHelper getPersonReimQuotaHelper() {
+        return Optional.ofNullable(personReimQuotaHelper).orElse(new PersonReimQuotaHelper());
+    }
+    @Override
+    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
+
+        // 同步类型
+        String updateType = (String)map.get("updatetype");
+
+        // 获取全部人员生效中的岗位职级
+        DynamicObjectCollection positionCol = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPPOSORGREL, "person.id,person.number,company.id,company.number,position.id", new QFilter[]{
+                new QFilter("businessstatus", QCP.equals, "1"),
+                new QFilter("iscurrentversion", QCP.equals, "1"),
+                new QFilter("isprimary", QCP.equals, "1"),
+                new QFilter("person.id", QCP.equals, Long.parseLong("2203317114964545536"))
+        });
+
+        Map<Long, DynamicObject> personPositionMap = positionCol.stream()
+                .collect(Collectors.toMap(r -> r.getLong("person.id"), r -> r, (k1, k2) -> k1));
+        Set<Long> personPositionSet = positionCol.stream().map(r -> r.getLong("person.id")).collect(Collectors.toSet());
+
+        // 从职级职等中共查询职级发生变化的数据
+        Map<Long, Long> personJobMap = QueryServiceHelper.query(BillTypeConstants.HRPI_EMPJOBREL, "person.id,joblevel.id", new QFilter[]{
+                new QFilter("businessstatus", QCP.equals, "1"),
+                new QFilter("iscurrentversion", QCP.equals, "1"),
+                new QFilter("person.id", QCP.in, personPositionSet)
+        }).stream().collect(Collectors.toMap(r -> r.getLong("person.id"), r -> r.getLong("joblevel.id"), (k1, k2) -> k1));
+
+        List<List<Long>> partition = Lists.partition(new ArrayList<>(personPositionSet), 4);
+
+        for(int i = 0 ; i < partition.size() ; i++){
+            List<Long> patchDataList = partition.get(i);
+
+            for(Long personId : patchDataList){
+
+                if(!personPositionMap.containsKey(personId) || !personJobMap.containsKey(personId)){
+                    continue;
+                }
+                DynamicObject positionInfo = personPositionMap.get(personId);
+
+
+                DynamicObject company = QueryServiceHelper.queryOne("bos_org", "id", new QFilter("number", QCP.equals, positionInfo.getString("company.number")).toArray());
+                DynamicObject userInfo = QueryServiceHelper.queryOne("bos_user", "id", new QFilter("number", QCP.equals, positionInfo.getString("person.number")).toArray());
+                // 更新额度
+                if("updatequota".equals(updateType)){
+                    refreshPersonQuota(userInfo.getLong("id"),company.getLong("id"),positionInfo.getLong("position.id"),(Long)personJobMap.get(personId));
+                    continue;
+                }
+
+                if("updatelever".equals(updateType)){
+                    getPersonReimQuotaHelper().syncReimLever(userInfo.getLong("id"),company.getLong("id"),(Long)personJobMap.get(personId));
+                    continue;
+                }
+            }
+
+            // 回传进度
+            feedbackProgress(100*(i+1)/partition.size());
+        }
+
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("message", String.format("执行成功,总共执行条数%s",personPositionSet.size()));
+        // 输出定制结果
+        feedbackCustomdata(result);
+    }
+
+    /**
+     * 刷新个人额度表
+     * @param userId
+     * @param positionId
+     * @param jobId
+     */
+    protected void refreshPersonQuota(Long userId ,Long companyId , Long positionId,Long jobId) {
+        Map<Long, Map<Long, BigDecimal>> currencyReimJobAmount = getPersonReimQuotaHelper().getExpenseJobAmount(positionId, jobId);
+        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();
+
+                PersonReimQuotaVO quotaVO = new PersonReimQuotaVO(userId, companyId, expenseItemId, currencyId, amount);
+                quotaVO.setYear(CommonUtils.getDateFeild(new Date(), Calendar.YEAR));
+                // 更新下个月
+                quotaVO.setMonth(CommonUtils.getDateFeild(new Date(), Calendar.MONTH)+2);
+                // 创建个人额度表
+                DynamicObject personReim = getPersonReimQuotaHelper().createPersonReim(quotaVO,false);
+
+                if(personReim != null){
+                    // 调用审核
+                    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));
+                    }
+                }
+
+            }
+        }
+    }
+}