Pārlūkot izejas kodu

运营绩效功能,大改

zhaoxian 2 gadi atpakaļ
vecāks
revīzija
d31b319e8c

+ 319 - 205
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouOperationReportServiceImpl.java

@@ -424,7 +424,13 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
             //总消耗
             Double totalCharge = datum.getDouble("totalCharge");
             datum.put("totalCharge", totalCharge);
-            datum.put("FWCharge", totalCharge);
+            //服务消耗
+            BigDecimal fwCharge = datum.getBigDecimal("FWCharge");
+            BigDecimal validFWCharge = datum.getBigDecimal("validFWCharge");
+            if (!Check.isNull(validFWCharge)) {
+                fwCharge = validFWCharge;
+            }
+
             //服务消耗提成
             BigDecimal FWChargeCommission = datum.getBigDecimal("FWCharge").multiply(new BigDecimal("0.003")).setScale(3, BigDecimal.ROUND_HALF_UP);
             datum.put("FWChargeCommission", FWChargeCommission);
@@ -596,16 +602,14 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
         JSONObject dates = new JSONObject();
 
         List<JSONObject> dataList = new ArrayList<>();
-        List<JSONObject> changeRoleDataList = new ArrayList<>();
-        List<JSONObject> offJobDataList = new ArrayList<>();
         if (!Check.isNull(changeRoleUserIds)) {
-            changeRoleDataList = getChangeRoleData(changeRoleUserIds, time, quarterMap);
+            dataList.addAll(getChangeRoleData(changeRoleUserIds, time, quarterMap));
         }
         if (!Check.isNull(offJobUserIds)) {
-            offJobDataList = getOffJobUserData(offJobUserIds, time, quarterMap);
+            dataList.addAll(getOffJobUserData(offJobUserIds, time, quarterMap));
         }
         if (!Check.isNull(onJobUserIds)) {
-            dataList = getOnJobUserData(onJobUserIds, quarterMap, changeRoleDataList, offJobDataList);
+            dataList.addAll(getOnJobUserData(onJobUserIds, time, quarterMap));
         }
         return Result.ok(dataList);
     }
@@ -638,46 +642,183 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
             count++;
         }
         for (JSONObject user : users) {
-            if (!Check.isNull(user.getString("roleName")) && user.getString("roleName").contains("经理")) {
-                data.addAll(baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, endDate));
+            String userId = user.getString("userId");
+            String roleCode = user.getString("roleCode");
+            //有效月份 =3,本季度全算給自己
+            if (user.getInteger("monthCount") == 3) {
+                Set<JSONObject> operatorsCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(userId), startDate, endDate);
+                JSONObject obj = operatorsCharge.iterator().next();
+                if ("operator".equals(roleCode)) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, startDate, endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month1 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate1"));
+                            String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month1)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate1"), dates.getInteger("endDate1"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month2)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            }
+                        }
+                    }
+                    obj.put("assistantCharge", assistantCharge);
+                    /*
+                岗位变为经理,则分别计算转换前后的助理服务数据,转换前的算给自己(有效助理数据)
+                * */
+                } else if (roleCode.contains("Manager")) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, startDate, endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month1 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate1"));
+                            String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month1)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                //有效助理数据
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month2)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            }
+                        }
+                    }
+                    obj.put("assistantCharge", assistantCharge);
+                }
+                data.add(obj);
+
+                //有效月份=2,本季度第二,三个月算有效数据 计算绩效
+            } else if (user.getInteger("monthCount") == 2) {
+                //总数据
+                Set<JSONObject> operatorsCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(userId), startDate, endDate);
+                JSONObject obj = operatorsCharge.iterator().next();
+                //有效数据
+                Set<JSONObject> validQuarterlyCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(userId), dates.getInteger("startDate2"), endDate);
+                JSONObject valid = validQuarterlyCharge.iterator().next();
+                obj.put("validFWCharge", valid.getBigDecimal("FWCharge"));
+                obj.put("validKFCharge", valid.getBigDecimal("KFCharge"));
+                /*
+                岗位变为专员,计算专员后是否带助理,计算助理数据
+                * */
+                if ("operator".equals(roleCode)) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, dates.getInteger("startDate2"), endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month2)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            }
+                        }
+                    }
+                    obj.put("assistantCharge", assistantCharge);
+                    /*
+                岗位变为经理,则分别计算转换前后的助理服务数据,转换前的算给自己(有效助理数据)
+                * */
+                } else if (roleCode.contains("Manager")) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, startDate, endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    BigDecimal validAssistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month1 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate1"));
+                            String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month1)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                //有效助理数据
+                                validAssistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month2)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            }
+                        }
+                    }
+                    obj.put("assistantCharge", assistantCharge);
+                    obj.put("validAssistantCharge", validAssistantCharge);
+                }
+                data.add(obj);
             } else {
-                //有效月份 =3,本季度全算給自己
-                if (user.getInteger("monthCount") == 3) {
-                    data.addAll(baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, endDate));
-                    //有效月份=2,本季度第二,三个月算給自己,前一个月算给leader
-                } else if (user.getInteger("monthCount") == 2) {
-                    data.addAll(baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), dates.getInteger("startDate2"), endDate));
-                    SysOperateRel rel = operateRelMapper.getOne(user.getString("userId"));
-                    if (!Check.isNull(rel)) {
-                        String operateId = rel.getOperateId();
-                        String roleCode = roleService.getRoleCodeByUserId(operateId);
-                        if ("operator".equals(roleCode)) {
-                            Set<JSONObject> quarterlyCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, dates.getInteger("endDate1"));
-                            for (JSONObject object : quarterlyCharge) {
-                                JSONObject operatorCharge = new JSONObject();
-                                BeanUtils.copyProperties(object, operatorCharge);
-                                operatorCharge.put("userId", operateId);
-                                data.add(operatorCharge);
+                //总数据
+                Set<JSONObject> operatorsCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(userId), startDate, endDate);
+                JSONObject obj = operatorsCharge.iterator().next();
+                //有效数据
+                Set<JSONObject> validQuarterlyCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(userId), dates.getInteger("startDate3"), endDate);
+                JSONObject valid = validQuarterlyCharge.iterator().next();
+                obj.put("validFWCharge", valid.getBigDecimal("FWCharge"));
+                obj.put("validKFCharge", valid.getBigDecimal("KFCharge"));
+                 /*
+                岗位变为专员,计算专员后是否带助理,计算助理数据
+                * */
+                if ("operator".equals(roleCode)) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, dates.getInteger("startDate3"), endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
                             }
                         }
                     }
-                } else {
-                    data.addAll(baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), dates.getInteger("startDate3"), endDate));
-                    SysOperateRel rel = operateRelMapper.getOne(user.getString("userId"));
-                    if (!Check.isNull(rel)) {
-                        String operateId = rel.getOperateId();
-                        String roleCode = roleService.getRoleCodeByUserId(operateId);
-                        if ("operator".equals(roleCode)) {
-                            Set<JSONObject> quarterlyCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, dates.getInteger("endDate2"));
-                            for (JSONObject object : quarterlyCharge) {
-                                JSONObject operatorCharge = new JSONObject();
-                                BeanUtils.copyProperties(object, operatorCharge);
-                                operatorCharge.put("userId", operateId);
-                                data.add(operatorCharge);
+                    obj.put("assistantCharge", assistantCharge);
+                    /*
+                岗位变为经理,则分别计算转换前后的助理服务数据,转换前的算给自己(有效助理数据)
+                * */
+                } else if (roleCode.contains("Manager")) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, startDate, endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    BigDecimal validAssistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month1 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate1"));
+                            String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month1)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                //有效助理数据
+                                validAssistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month2)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                validAssistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
                             }
                         }
                     }
+                    obj.put("assistantCharge", assistantCharge);
+                    obj.put("validAssistantCharge", validAssistantCharge);
                 }
+                data.add(obj);
             }
         }
         if (!Check.isNull(data)) {
@@ -690,150 +831,66 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
     /**
      * 查询在职人员数据
      */
-    private List<JSONObject> getOnJobUserData(List<JSONObject> users, Map<String, String> dateMap, List<JSONObject> changeRoleDataList, List<JSONObject> offJobDataList) throws ParseException {
+    private List<JSONObject> getOnJobUserData(List<JSONObject> users, Integer time, Map<String, String> dateMap) throws ParseException {
         List<JSONObject> data = new ArrayList<>();
         Integer startDate = DateUtils.getDateInteger(dateMap.get("startDate"));
         Integer endDate = DateUtils.getDateInteger(dateMap.get("endDate"));
 
         List<String> userIds = new ArrayList<>();
+        JSONObject userMap = new JSONObject();
         for (JSONObject user : users) {
             userIds.add(user.getString("userId"));
+            userMap.put(user.getString("userId"), user);
         }
-
-        //记录助理和对应的专员,单独计算
-        List<String> delUserIds = new ArrayList<>();
-        //只记录专员和助理关系
-        Set<SysOperateRel> addRelList = new HashSet<>();
-        for (JSONObject user : users) {
-            if ("operationAssistant".equals(user.getString("roleCode"))) {
-                //记录专员和助理关系
-                SysOperateRel rel = operateRelMapper.getOne(user.getString("userId"));
-                if (!Check.isNull(rel)) {
-                    String operateId = rel.getOperateId();
-                    for (JSONObject us : users) {
-                        //筛选出专员和助理关系
-                        if (operateId.equals(us.getString("userId")) && "operator".equals(us.getString("roleCode"))) {
-                            addRelList.add(rel);
-                            delUserIds.add(us.getString("userId"));
-                            delUserIds.add(user.getString("userId"));
-                            break;
-                        }
-                    }
-                }
-            }
+        List<Integer> monthInt = getMonthInt(time);
+        JSONObject dates = new JSONObject();
+        int count = 1;
+        for (Integer month : monthInt) {
+            Map<String, String> monthMap = DateUtils.getFirstDayAndLastDayOfTheSpecifiedMonth(DateUtils.getYear(), month);
+            dates.put("startDate" + count, DateUtils.getDateInteger(monthMap.get("start")));
+            dates.put("endDate" + count, DateUtils.getDateInteger(monthMap.get("end")));
+            count++;
         }
 
-        //单独计算专员和助理数据
-        if (!Check.isNull(addRelList)) {
-            List<String> ids = new ArrayList<>();
-            //助理-专员map
-            Map<String, String> map = new HashMap<>();
-            for (SysOperateRel rel : addRelList) {
-                ids.add(rel.getOperateId());
-                ids.add(rel.getAssistantId());
-                map.put(rel.getAssistantId(), rel.getOperateId());
-            }
-            //记录人员和数据
-            JSONObject da = new JSONObject();
-            Set<JSONObject> list = baseMapper.getKsQuarterlyOnJobOperatorsCharge(ids, startDate, endDate);
-            for (JSONObject object : list) {
-                da.put(object.getString("userId"), object);
-            }
-            //整合助理和专员数据
-            List<JSONObject> relDataList = new ArrayList<>();
-            for (Map.Entry<String, String> entry : map.entrySet()) {
-                //助理数据
-                JSONObject assistantData = da.getJSONObject(entry.getKey());
-                //专员数据
-                JSONObject operatorData = da.getJSONObject(entry.getValue());
-                //添加助理数据
-                relDataList.add(assistantData);
-                /*判断是否添加过专员数据,若已存在(一个专员带多个助理),则将助理数据叠加到已有的专员上
-                若不存在(一个专员带多个助理),则将助理数据直接叠加到专员上
-                */
-                //专员Id
-                String operatorUserId = operatorData.getString("userId");
-                if (relDataList.toString().contains(operatorUserId)) {
-                    for (JSONObject o : relDataList) {
-                        String userId = o.getString("userId");
-                        //筛选出已有的专员
-                        if (!Check.isNull(userId) && userId.equals(operatorUserId)) {
-                            o.put("totalCharge", assistantData.getBigDecimal("totalCharge").add(o.getBigDecimal("totalCharge")));
-                            o.put("FWCharge", assistantData.getBigDecimal("FWCharge").add(o.getBigDecimal("FWCharge")));
-                            o.put("JLCharge", assistantData.getBigDecimal("JLCharge").add(o.getBigDecimal("JLCharge")));
-                            o.put("KFCharge", assistantData.getBigDecimal("KFCharge").add(o.getBigDecimal("KFCharge")));
+        Set<JSONObject> list = baseMapper.getKsQuarterlyOnJobOperatorsCharge(userIds, startDate, endDate);
+        for (JSONObject dat : list) {
+            String userId = dat.getString("userId");
+            JSONObject user = userMap.getJSONObject(userId);
+            if (!Check.isNull(user)) {
+                String roleCode = user.getString("roleCode");
+                if (!"operationAssistant".equals(roleCode)) {
+                    List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, startDate, endDate);
+                    BigDecimal assistantCharge = new BigDecimal("0.0");
+                    if (!Check.isNull(relList)) {
+                        for (SysOperateRel rel : relList) {
+                            String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                            String month1 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate1"));
+                            String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                            String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                            if (month.equals(month1)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate1"), dates.getInteger("endDate1"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month2)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), dates.getInteger("endDate2"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            } else if (month.equals(month3)) {
+                                Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), dates.getInteger("endDate3"));
+                                assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                            }
                         }
                     }
+                    dat.put("assistantCharge", assistantCharge);
+                    data.add(dat);
                 } else {
-                    operatorData.put("totalCharge", assistantData.getBigDecimal("totalCharge").add(operatorData.getBigDecimal("totalCharge")));
-                    operatorData.put("FWCharge", assistantData.getBigDecimal("FWCharge").add(operatorData.getBigDecimal("FWCharge")));
-                    operatorData.put("JLCharge", assistantData.getBigDecimal("JLCharge").add(operatorData.getBigDecimal("JLCharge")));
-                    operatorData.put("KFCharge", assistantData.getBigDecimal("KFCharge").add(operatorData.getBigDecimal("KFCharge")));
-                    relDataList.add(operatorData);
-                }
-            }
-            data.addAll(relDataList);
-        }
-        //去除助理和对应的专员清单
-        userIds.removeAll(delUserIds);
-        if (!Check.isNull(userIds)) {
-            Set<JSONObject> list = baseMapper.getKsQuarterlyOnJobOperatorsCharge(userIds, startDate, endDate);
-            data.addAll(list);
-        }
-        //整合岗位变更人员的数据
-        if (!Check.isNull(changeRoleDataList)) {
-            List<JSONObject> delDataList = new ArrayList<>();
-            JSONObject changeData = new JSONObject();
-            for (JSONObject object : changeRoleDataList) {
-                changeData.put(object.getString("userId"), object);
-            }
-            if (!Check.isNull(data)) {
-                for (JSONObject datum : data) {
-                    String userId = datum.getString("userId");
-                    JSONObject changeObj = changeData.getJSONObject(userId);
-                    //筛选出岗位变更人员中,正常在职人员,即助理对应的专员,需叠加数据
-                    if (!Check.isNull(changeObj)) {
-                        //记录这些已有的专员信息,为避免数据重复,添加后将删除
-                        delDataList.add(changeObj);
-                        datum.put("totalCharge", changeObj.getBigDecimal("totalCharge").add(datum.getBigDecimal("totalCharge")));
-                        datum.put("FWCharge", changeObj.getBigDecimal("FWCharge").add(datum.getBigDecimal("FWCharge")));
-                        datum.put("JLCharge", changeObj.getBigDecimal("JLCharge").add(datum.getBigDecimal("JLCharge")));
-                        datum.put("KFCharge", changeObj.getBigDecimal("KFCharge").add(datum.getBigDecimal("KFCharge")));
-                    }
-                }
-                changeRoleDataList.removeAll(delDataList);
-            }
-        }
-        //整合离职人员的数据
-        if (!Check.isNull(offJobDataList)) {
-            List<JSONObject> delDataList = new ArrayList<>();
-            JSONObject changeData = new JSONObject();
-            for (JSONObject object : offJobDataList) {
-                changeData.put(object.getString("userId"), object);
-            }
-            if (!Check.isNull(data)) {
-                for (JSONObject datum : data) {
-                    String userId = datum.getString("userId");
-                    JSONObject changeObj = changeData.getJSONObject(userId);
-                    //筛选出岗位变更人员中,正常在职人员,即助理对应的专员,需叠加数据
-                    if (!Check.isNull(changeObj)) {
-                        //记录这些已有的专员信息,为避免数据重复,添加后将删除
-                        delDataList.add(changeObj);
-                        datum.put("totalCharge", changeObj.getBigDecimal("totalCharge").add(datum.getBigDecimal("totalCharge")));
-                        datum.put("FWCharge", changeObj.getBigDecimal("FWCharge").add(datum.getBigDecimal("FWCharge")));
-                        datum.put("JLCharge", changeObj.getBigDecimal("JLCharge").add(datum.getBigDecimal("JLCharge")));
-                        datum.put("KFCharge", changeObj.getBigDecimal("KFCharge").add(datum.getBigDecimal("KFCharge")));
-                    }
+                    dat.put("assistantCharge", "0.0");
+                    data.add(dat);
                 }
-                offJobDataList.removeAll(delDataList);
             }
         }
 
         if (!Check.isNull(data)) {
             consolidateData(users, data);
             consolidateData(data, dateMap, null, null);
-            data.addAll(changeRoleDataList);
-            data.addAll(offJobDataList);
         }
         return data;
     }
@@ -845,10 +902,6 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
     private List<JSONObject> getOffJobUserData(List<JSONObject> users, Integer time, Map<String, String> dateMap) throws ParseException {
         List<JSONObject> data = new ArrayList<>();
         Integer startDate = DateUtils.getDateInteger(dateMap.get("startDate"));
-        Integer endDate = DateUtils.getDateInteger(dateMap.get("endDate"));
-
-        //记录助理,单独计算
-        List<JSONObject> assistantUsers = new ArrayList<>();
         for (JSONObject user : users) {
             //统计绩效有效月份
             String quitTime = user.getString("quitTime");
@@ -857,37 +910,63 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
                 Integer endMonth = Integer.valueOf(DateUtils.getMonth("yyyy-MM-dd HH:mm:ss", quitTime));
                 user.put("monthCount", endMonth - startMonth + 1);
             }
-            if ("operationAssistant".equals(user.getString("roleCode"))) {
-                assistantUsers.add(user);
-            }
         }
-
-        //单独计算助理数据
-        if (!Check.isNull(assistantUsers)) {
-            for (JSONObject user : assistantUsers) {
-                Set<JSONObject> charge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, DateUtils.getDateInteger(DateUtils.formatDate(user.getString("quitTime"), "yyyy-MM-dd")));
-                data.addAll(charge);
-                SysOperateRel rel = operateRelMapper.getOne(user.getString("userId"));
-                if (!Check.isNull(rel)) {
-                    String operateId = rel.getOperateId();
-                    String roleCode = roleService.getRoleCodeByUserId(operateId);
-                    if ("operator".equals(roleCode)) {
-                        for (JSONObject object : charge) {
-                            JSONObject operators = new JSONObject();
-                            BeanUtils.copyProperties(object, operators);
-                            operators.put("userId", operateId);
-                            data.add(operators);
+        List<Integer> monthInt = getMonthInt(time);
+        JSONObject dates = new JSONObject();
+        int count = 1;
+        for (Integer month : monthInt) {
+            Map<String, String> monthMap = DateUtils.getFirstDayAndLastDayOfTheSpecifiedMonth(DateUtils.getYear(), month);
+            dates.put("startDate" + count, DateUtils.getDateInteger(monthMap.get("start")));
+            dates.put("endDate" + count, DateUtils.getDateInteger(monthMap.get("end")));
+            count++;
+        }
+        for (JSONObject user : users) {
+            String userId = user.getString("userId");
+            Integer quitTime = DateUtils.getDateInteger(DateUtils.formatDate(user.getString("quitTime"), "yyyy-MM-dd"));
+            Set<JSONObject> operatorsCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, quitTime);
+            JSONObject dat = operatorsCharge.iterator().next();
+            String roleCode = user.getString("roleCode");
+            if (!"operationAssistant".equals(roleCode)) {
+                List<SysOperateRel> relList = operateRelMapper.getMoreByOperatorId(userId, startDate, quitTime);
+                BigDecimal assistantCharge = new BigDecimal("0.0");
+                if (!Check.isNull(relList)) {
+                    for (SysOperateRel rel : relList) {
+                        String month = DateUtils.getMonth("yyyy-MM", rel.getStatMonth());
+                        String month1 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate1"));
+                        String month2 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate2"));
+                        String month3 = DateUtils.getMonth("yyyyMMdd", dates.getString("startDate3"));
+                        String quitTimeStr = DateUtils.getMonth("yyyyMMdd", String.valueOf(quitTime));
+                        if (month.equals(month1)) {
+                            Integer endDate = dates.getInteger("endDate1");
+                            if (quitTimeStr.equals(month1)) {
+                                endDate = quitTime;
+                            }
+                            Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate1"), endDate);
+                            assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                        } else if (month.equals(month2)) {
+                            Integer endDate = dates.getInteger("endDate2");
+                            if (quitTimeStr.equals(month2)) {
+                                endDate = quitTime;
+                            }
+                            Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate2"), endDate);
+                            assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
+                        } else if (month.equals(month3)) {
+                            Integer endDate = dates.getInteger("endDate3");
+                            if (quitTimeStr.equals(month3)) {
+                                endDate = quitTime;
+                            }
+                            Set<JSONObject> AssistantData = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(rel.getAssistantId()), dates.getInteger("startDate3"), endDate);
+                            assistantCharge.add(AssistantData.iterator().next().getBigDecimal("FWCharge"));
                         }
                     }
                 }
+                dat.put("assistantCharge", assistantCharge);
+                data.add(dat);
+            } else {
+                dat.put("assistantCharge", "0.0");
+                data.add(dat);
             }
-            users.removeAll(assistantUsers);
         }
-
-        for (JSONObject user : users) {
-            data.addAll(baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(user.getString("userId")), startDate, DateUtils.getDateInteger(DateUtils.formatDate(user.getString("quitTime"), "yyyy-MM-dd"))));
-        }
-
         if (!Check.isNull(data)) {
             consolidateData(users, data);
             consolidateData(data, dateMap, null, "off");
@@ -900,28 +979,26 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
         for (JSONObject datum : data) {
             String userId = datum.getString("userId");
             SysUser userEntity = sysUserService.getById(userId);
+
+            //助理消耗
+            BigDecimal assistantCharge = datum.getBigDecimal("assistantCharge");
             //服务消耗
             BigDecimal fwCharge = datum.getBigDecimal("FWCharge");
+            BigDecimal validFWCharge = datum.getBigDecimal("validFWCharge");
+            if (!Check.isNull(validFWCharge)) {
+                fwCharge = validFWCharge;
+            }
             //框返消耗
             BigDecimal kfCharge = datum.getBigDecimal("KFCharge");
+            BigDecimal validKFCharge = datum.getBigDecimal("validKFCharge");
+            if (!Check.isNull(validKFCharge)) {
+                kfCharge = validKFCharge;
+            }
             //框返消耗提成
             BigDecimal KFChargeCommission = null;
             //经理管理消耗提成
             BigDecimal manageChargeCommission = null;
-            //服务消耗提成
-            BigDecimal FWChargeCommission = fwCharge.multiply(new BigDecimal("0.003")).setScale(3, BigDecimal.ROUND_HALF_UP);
-            datum.put("FWChargeCommission", FWChargeCommission);
-            if (kfCharge.doubleValue() >= 300000) {
-                //季度框返是否满足30w
-                datum.put("KFChargeIsOk", "是");
-                //框返消耗提成
-                KFChargeCommission = kfCharge.multiply(new BigDecimal("0.003")).setScale(3, BigDecimal.ROUND_HALF_UP);
-                datum.put("KFChargeCommission", KFChargeCommission);
-            } else {
-                KFChargeCommission = new BigDecimal("0.0");
-                datum.put("KFChargeIsOk", "否");
-                datum.put("KFChargeCommission", "-");
-            }
+
             Integer monthCount = datum.getInteger("monthCount");
             Long value = 2400000l;
             if (!Check.isNull(monthCount)) {
@@ -974,6 +1051,15 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
                 datum.put("FWChargeIsOk", "是");
                 //是否符合发放
                 datum.put("paySalary", "是");
+
+                //有效助理消耗
+                BigDecimal validAssistantCharge = datum.getBigDecimal("validAssistantCharge");
+                if (Check.isNull(validAssistantCharge)) {
+                    validAssistantCharge = new BigDecimal("0.0");
+                }
+                //服务消耗提成
+                BigDecimal FWChargeCommission = fwCharge.add(validAssistantCharge).multiply(new BigDecimal("0.003")).setScale(3, BigDecimal.ROUND_HALF_UP);
+                datum.put("FWChargeCommission", FWChargeCommission);
                 //发放金额
                 putMoney = manageChargeCommission.subtract(compMoney);
             } else {
@@ -981,6 +1067,20 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
                 datum.put("manageChargeCommission", "-");
                 datum.put("operateCompensation", "50%");
                 datum.put("manageCompensation", "-");
+                //服务消耗提成
+                BigDecimal FWChargeCommission = fwCharge.add(assistantCharge).multiply(new BigDecimal("0.003")).setScale(3, BigDecimal.ROUND_HALF_UP);
+                datum.put("FWChargeCommission", FWChargeCommission);
+                if (kfCharge.doubleValue() >= 300000) {
+                    //季度框返是否满足30w
+                    datum.put("KFChargeIsOk", "是");
+                    //框返消耗提成
+                    KFChargeCommission = kfCharge.multiply(new BigDecimal("0.003")).setScale(3, BigDecimal.ROUND_HALF_UP);
+                    datum.put("KFChargeCommission", KFChargeCommission);
+                } else {
+                    KFChargeCommission = new BigDecimal("0.0");
+                    datum.put("KFChargeIsOk", "否");
+                    datum.put("KFChargeCommission", "-");
+                }
                 putMoney = FWChargeCommission.add(KFChargeCommission).subtract(compMoney);
             }
             datum.put("putMoney", putMoney);
@@ -1054,4 +1154,18 @@ public class KuaishouOperationReportServiceImpl extends ServiceImpl<KuaishouOper
         return list;
     }
 
+
+    private JSONObject getOperatorData(String operateId, String userId, Integer startDate, Integer endDate) {
+        JSONObject operatorCharge = new JSONObject();
+        String roleCode = roleService.getRoleCodeByUserId(operateId);
+        if ("operator".equals(roleCode)) {
+            Set<JSONObject> quarterlyCharge = baseMapper.getKsQuarterlyOnJobOperatorsCharge(Arrays.asList(userId), startDate, endDate);
+            if (!Check.isNull(quarterlyCharge)) {
+                JSONObject object = quarterlyCharge.iterator().next();
+                BeanUtils.copyProperties(object, operatorCharge);
+                operatorCharge.put("userId", operateId);
+            }
+        }
+        return operatorCharge;
+    }
 }

+ 4 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysOperateRelMapper.java

@@ -21,4 +21,8 @@ public interface SysOperateRelMapper extends BaseMapper<SysOperateRel> {
     SysOperateRel getOne(@Param("assistantId") String assistantId);
 
     List<JSONObject> queryPageList(SysOperateRel sysOperateRel);
+
+    List<SysOperateRel> getMore(@Param("userId") String userId, @Param("startDate") Integer startDate, @Param("endDate") Integer endDate);
+
+    List<SysOperateRel> getMoreByOperatorId(@Param("userId") String userId, @Param("startDate") Integer startDate, @Param("endDate") Integer endDate);
 }

+ 19 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysOperateRelMapper.xml

@@ -23,8 +23,25 @@
         select assistant_id, operate_id, stat_month
         from sys_operate_rel
         where assistant_id = #{assistantId}
-        order by create_time desc
-        limit 1
+        order by create_time desc limit 1
+    </select>
+
+    <select id="getMore" resultType="org.jeecg.modules.system.entity.SysOperateRel">
+        select assistant_id, operate_id, stat_month
+        from sys_operate_rel
+        where assistant_id = #{userId}
+          AND stat_month >= DATE_FORMAT(#{startDate}, '%Y-%m')
+          AND stat_month &lt;= DATE_FORMAT(#{endDate}, '%Y-%m')
+        order by stat_month
+    </select>
+
+    <select id="getMoreByOperatorId" resultType="org.jeecg.modules.system.entity.SysOperateRel">
+        select assistant_id, operate_id, stat_month
+        from sys_operate_rel
+        where operate_id = #{userId}
+          AND stat_month >= DATE_FORMAT(#{startDate}, '%Y-%m')
+          AND stat_month &lt;= DATE_FORMAT(#{endDate}, '%Y-%m')
+        order by stat_month
     </select>
 
     <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">