Kaynağa Gözat

后台事务

liuling 2 hafta önce
ebeveyn
işleme
cdba57a559

+ 168 - 49
src/com/kingdee/eas/custom/calcdailypay/task/CalcDailyPayFacadeControllerBean.java

@@ -1,5 +1,7 @@
 package com.kingdee.eas.custom.calcdailypay.task;
 
+import com.alibaba.fastjson.JSONObject;
+import com.kingdee.eas.fi.arap.util.DBUtil;
 import com.kingdee.eas.util.app.DbUtil;
 import com.kingdee.jdbc.rowset.IRowSet;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
@@ -16,10 +18,8 @@ import com.kingdee.bos.*;
 import com.kingdee.eas.common.EASBizException;
 
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 public class CalcDailyPayFacadeControllerBean extends AbstractCalcDailyPayFacadeControllerBean {
     private static Logger logger = Logger.getLogger(CalcDailyPayFacadeControllerBean.class);
@@ -34,53 +34,79 @@ public class CalcDailyPayFacadeControllerBean extends AbstractCalcDailyPayFacade
      */
     @Override
     protected void _calculate(Context ctx, int preCalcDays) throws BOSException, EASBizException {
+        if (preCalcDays<0){
+            preCalcDays=0;
+        }
+        Map<String, Object> stringObjectMap = new HashMap<>();
+        for (int i = 0; i <= preCalcDays; i++) {
+            String dayBefore = getDayBefore(new Date(), i );
+            try {
+                Map<String, Object> stringObjectMap1 = calculateData(dayBefore, ctx);
+                if (stringObjectMap.size()>0){
+                    List<Map> uuidList = ( List<Map>)(stringObjectMap1.get("uid"));
+                    Integer record = ( Integer)(stringObjectMap1.get("record"));
+                    List<Map> newUuidList = ( List<Map>)stringObjectMap.get("uid");
+                    Integer newRecord = ( Integer)(stringObjectMap1.get("record"));
+                    newUuidList.addAll(uuidList);
+                    stringObjectMap1.put("record",record+newRecord);
+                }else {
+                    stringObjectMap.putAll(stringObjectMap1);
+                }
+            } catch (SHRWebException e) {
+                e.printStackTrace();
+                System.out.println("================:"+e.getMessage());
+            }
+        }
+        System.out.println("=======return========="+ JSONObject.toJSONString(stringObjectMap));
         super._calculate(ctx, preCalcDays);
-        //TimepieceDailyDynamicListHandler
-        //com.kingdee.shr.compensation.app.integrate.SubmitSchemeBillFacadeControllerBean
-        //checkIsCal
-        //calculate
-        if (preCalcDays < 0) {
-            preCalcDays = 0;
+
+    }
+    public Map<String, Object>  calculateData(String date,Context context) throws SHRWebException {
+        String whereSql = this.getSelectDataId(context,date);
+        if(whereSql.length()<=0){
+            Map<String, Object> result = new HashMap();
+            result.put("uid",  new ArrayList<Map>());
+            result.put("record", 0);
+            return result;
         }
+        Map<String, List<String>> batchmap = TimepieceBillEntryDataCalService.batchBillEntryDataByScheme(context, whereSql);
+        if (!batchmap.isEmpty()) {
+            try {
+                List<Map> list = new ArrayList();
+                int record = 0;
+                CmpInSql<String> inSql0 = CmpInSqlFactory.getInstance();
+                String filterSql = inSql0.createInSql(context, batchmap.keySet().toArray(), "'", "T_HR_SCalSubmitScheme", "fid");
+                List<String> haslist = TimepieceBillEntryDataCalService.checkIsHasCalFormula(context, filterSql);
+                Iterator var12 = batchmap.entrySet().iterator();
 
-//        String whereSql = this.getSelectDataId(request, ctx);
-//        Map<String, List<String>> batchmap = TimepieceBillEntryDataCalService.batchBillEntryDataByScheme(ctx, whereSql);
-//        if (!batchmap.isEmpty()) {
-//            try {
-//                List<Map> list = new ArrayList();
-//                int record = 0;
-//                CmpInSql<String> inSql0 = CmpInSqlFactory.getInstance();
-//                String filterSql = inSql0.createInSql(ctx, batchmap.keySet().toArray(), "'", "T_HR_SCalSubmitScheme", "fid");
-//                //已计算的id
-//                List<String> haslist = TimepieceBillEntryDataCalService.checkIsHasCalFormula(ctx, filterSql);
-//
-//                for (Map.Entry<String, List<String>> entry : batchmap.entrySet()) {
-//                    Map<String, String> param = new HashMap();
-//                    record += ((List) entry.getValue()).size();
-//                    String calSchemeID = (String) entry.getKey();
-//                    param.put("calSchemeID", calSchemeID);
-//                    param.put("mainTable", "T_HR_TimepieceBillEntry");
-//                    CmpInSql<String> inSql = CmpInSqlFactory.getInstance();
-//                    String conditionSql = inSql.createInSql(ctx, ((List) entry.getValue()).toArray(), "'", "T_HR_TimepieceBillEntry", "fid");
-//                    if (!haslist.contains(calSchemeID)) {
-//                        //更新为已计算
-//                        String updateSQL = "update  T_HR_timepieceBillEntry set  fentrycalstatus = 1 where fid in " + conditionSql;
-//                        DbUtil.execute(ctx, updateSQL);
-//                    }
-//
-//                    param.put("condition", conditionSql.replace("(", "").replace(")", ""));
-//                    //计算
-//                    Map result = SubmitSchemeBillFacadeFactory.getLocalInstance(ctx).calculate(param);
-//                    list.add(result);
-//                }
-//
-//                Map<String, Object> result = new HashMap();
-//                result.put("uid", list);
-//                result.put("record", record);
-//                JSONUtils.SUCCESS(result);
-//            } catch (EASBizException | BOSException e) {
-//            }
-       //}
+                while(var12.hasNext()) {
+                    Map.Entry<String, List<String>> entry = (Map.Entry)var12.next();
+                    Map<String, String> param = new HashMap();
+                    record += ((List)entry.getValue()).size();
+                    String calSchemeID = (String)entry.getKey();
+                    param.put("calSchemeID", calSchemeID);
+                    param.put("mainTable", "T_HR_TimepieceBillEntry");
+                    CmpInSql<String> inSql = CmpInSqlFactory.getInstance();
+                    String conditionSql = inSql.createInSql(context, ((List)entry.getValue()).toArray(), "'", "T_HR_TimepieceBillEntry", "fid");
+                    if (!haslist.contains(calSchemeID)) {
+                        String updateSQL = "update  T_HR_timepieceBillEntry set  fentrycalstatus = 1 where fid in " + conditionSql;
+                        DbUtil.execute(context, updateSQL);
+                    }
+
+                    param.put("condition", conditionSql.replace("(", "").replace(")", ""));
+                    Map result = SubmitSchemeBillFacadeFactory.getLocalInstance(context).calculate(param);
+                    list.add(result);
+                }
+
+                Map<String, Object> result = new HashMap();
+                result.put("uid", list);
+                result.put("record", record);
+                return result;
+            } catch (EASBizException | BOSException var19) {
+                throw new SHRWebException(var19.getMessage(), var19);
+            }
+        }
+        return null;
     }
 
     /**
@@ -93,9 +119,102 @@ public class CalcDailyPayFacadeControllerBean extends AbstractCalcDailyPayFacade
      */
     @Override
     protected void _sendSalary(Context ctx, int preCalcDays) throws BOSException, EASBizException {
+        if (preCalcDays<0){
+            preCalcDays=0;
+        }
+        Map<String, Integer> stringObjectMap = new HashMap<>();
+        for (int i = 0; i <= preCalcDays; i++) {
+            String dayBefore = getDayBefore(new Date(), i );
+            try {
+                Map<String, Integer> stringObjectMap1 = sendSalaryData(ctx,dayBefore);
+                if (stringObjectMap.size()>0){
+                    Integer success = stringObjectMap1.get("success");
+                    Integer fail = stringObjectMap1.get("fail");
+                    stringObjectMap.put("success",success+stringObjectMap.get("success"));
+                    stringObjectMap.put("fail",fail+stringObjectMap.get("fail"));
+                }else {
+                    stringObjectMap.putAll(stringObjectMap1);
+                }
+            } catch (SHRWebException e) {
+                e.printStackTrace();
+                System.out.println("================:"+e.getMessage());
+            }
+        }
+        System.out.println("=======return========="+ JSONObject.toJSONString(stringObjectMap));
         super._sendSalary(ctx, preCalcDays);
-//        sendSalaryAction
+    }
+    public Map<String, Integer> sendSalaryData(Context ctx, String date) throws SHRWebException, BOSException {
+        String whereSql = this.getSelectDataId( ctx,date);
+        String sql = "select count(fid) as count from T_HR_TimepieceBillEntry where  fid in  " + whereSql;
+        String nocalsql = "select count(fid) as count from T_HR_TimepieceBillEntry where   fentrycalstatus = '0' and fid in  " + whereSql;
+        IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
+        int sum = 0;
+        int nocal = 0;
+
+        try {
+            while(iRowSet.next()) {
+                sum = iRowSet.getInt("count");
+            }
+
+            for(iRowSet = DbUtil.executeQuery(ctx, nocalsql); iRowSet.next(); nocal = iRowSet.getInt("count")) {
+            }
+        } catch (SQLException var12) {
+            throw new RuntimeException(var12);
+        }
 
+        TimepieceBillDataService.sendSalaryBillEntryshowByIds(ctx, whereSql);
+        Map<String, Integer> result = new HashMap();
+        result.put("success", sum - nocal);
+        result.put("fail", nocal);
+        return result;
+    }
+
+    /**
+     * 往前推多少天
+     *
+     * @param specifiedDay
+     * @param x
+     * @return
+     */
+    public static String getDayBefore(Date specifiedDay, int x) {
+        Calendar c = Calendar.getInstance();
+        Date date = specifiedDay;
+        c.setTime(date);
+        int day = c.get(Calendar.DATE);
+        c.set(Calendar.DATE, day - x);    //往前推几天
+        //c.set(Calendar.DATE, day + x);  往后推几天
+
+        String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
+        //System.out.println(dayBefore);
+        return dayBefore;
+    }
+
+    /**
+     * @Author: LiuYing
+     * @Description:
+     * @DateTime: 2025/5/20 17:57
+     * @Params:
+     * @Return:
+     */
+
+    protected String getSelectDataId(Context ctx, String date) {
+        String sql = "select FID from T_HR_TimepieceBillEntry where FEffectDate= {ts '"+date+"'}";
+        String whereSql= "";
+        try {
+            IRowSet iRowSet1 = DBUtil.executeQuery(ctx, sql);
+            while (iRowSet1.next()){
+                whereSql+="'"+iRowSet1.getString("FID")+"',";
+            }
+            if (whereSql.length()>0){
+                whereSql=whereSql.substring(0,whereSql.length()-1);
+                whereSql="("+whereSql+")";
+            }
+        } catch (BOSException e) {
+            throw new RuntimeException(e);
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+        return whereSql;
     }
 
     /**