Commit fc519997 by zhouhaibao

feat(meituan): 月度报告及超标推送排除指定部门

- 新增零售运营部、场景运营部、数字化运营部等排除部门常量
- 月度报告统计(公司/个人)自动排除指定部门数据
- 商务差旅和商务宴请超标提醒对排除部门仅入库不推送
- 支持通过配置项覆盖默认排除部门列表
- 匹配逻辑兼容直接归属部门与完整部门路径两种场景
1 parent 9a764d7e
package cn.com.glsx.dj.staff.constant;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @Title MeiTuanOrderConstants
* @author pangst
......@@ -24,4 +28,18 @@ public class MeiTuanOrderConstants {
public static final String DEPT_SALE_TWO = "销售二部";
public static final String DEPT_RETAIL = "零售运营";
/**
* 月度报告统计需要排除的部门(对应订单的 directOrgName 字段)
*/
public static final String DEPT_RETAIL_OPERATION = "零售运营部";
public static final String DEPT_SCENE_OPERATION = "场景运营部";
public static final String DEPT_DIGITAL_OPERATION = "数字化运营部";
public static final String TOTAL_DEPT_DIGITAL_OPERATION = "智慧门店运营中心";
/**
* 公司月度报告、个人月度报告统计时默认排除的部门
*/
public static final List<String> REPORT_EXCLUDE_DEPT_NAMES = Collections.unmodifiableList(
Arrays.asList(DEPT_RETAIL_OPERATION, DEPT_SCENE_OPERATION, DEPT_DIGITAL_OPERATION,TOTAL_DEPT_DIGITAL_OPERATION));
}
......@@ -172,6 +172,14 @@ public class MeiTuanOrderJob implements SimpleJob {
return;
}
// 零售运营部、场景运营部、数字化运营部不推送超标提醒,仅入库
if (staffMeituanOrderService.isExcludeReportDept(staff.getDirectOrgName(), staff.getOrgNamePath())) {
log.info("商务差旅超标不推送(部门已排除),directOrgName:{},orgNamePath:{},staffName:{},sqtBizOrderId:{}",
staff.getDirectOrgName(), staff.getOrgNamePath(), staff.getStaffName(), staff.getSqtBizOrderId());
staffMeituanOrderService.saveMtOrder(staff);
return;
}
// 连续住宿天数
Integer roomNightCount = staff.getRoomNightCount();
// 赋值推送内容
......@@ -267,6 +275,14 @@ public class MeiTuanOrderJob implements SimpleJob {
return;
}
// 零售运营部、场景运营部、数字化运营部不推送超标提醒,仅入库
if (staffMeituanOrderService.isExcludeReportDept(staff.getDirectOrgName(), staff.getOrgNamePath())) {
log.info("商务宴请超标不推送(部门已排除),directOrgName:{},orgNamePath:{},staffName:{},sqtBizOrderId:{}",
staff.getDirectOrgName(), staff.getOrgNamePath(), staff.getStaffName(), staff.getSqtBizOrderId());
staffMeituanOrderService.saveMtOrder(staff);
return;
}
// 查询这个人当月的超标次数
Long staffId = staff.getStaffId();
// 获取 lastHour 所在月份的超标次数(商务宴请且超标)
......
......@@ -279,10 +279,15 @@ public class StaffMeituanOrderService {
List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd);
List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd);
// 排除指定部门(零售运营部、场景运营部、数字化运营部)的数据
List<String> excludeDeptNames = getExcludeReportDeptNames();
lastMonthAll = excludeDeptOrders(lastMonthAll, excludeDeptNames);
prevMonthAll = excludeDeptOrders(prevMonthAll, excludeDeptNames);
if (CollectionUtils.isEmpty(lastMonthAll)) {
return new ArrayList<>();
}
log.info("lastMonthAll size:{}", lastMonthAll.size());
log.info("排除部门:{},lastMonthAll size:{}", excludeDeptNames, lastMonthAll.size());
// 按员工分组
Map<Long, List<StaffMeituanOrder>> lastMonthStaffMap = lastMonthAll.stream().filter(o -> o.getStaffId() != null)
......@@ -391,9 +396,15 @@ public class StaffMeituanOrderService {
List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd);
List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd);
// 排除指定部门(零售运营部、场景运营部、数字化运营部)的数据
List<String> excludeDeptNames = getExcludeReportDeptNames();
lastMonthAll = excludeDeptOrders(lastMonthAll, excludeDeptNames);
prevMonthAll = excludeDeptOrders(prevMonthAll, excludeDeptNames);
if (CollectionUtils.isEmpty(lastMonthAll)) {
return null;
}
log.info("公司月度报告排除部门:{},lastMonthAll size:{}", excludeDeptNames, lastMonthAll.size());
int monthValue = lastMonth.getMonthValue();
int monthStartDay = 1;
......@@ -590,9 +601,11 @@ public class StaffMeituanOrderService {
.value(entry.getValue().intValue())
.build()));
// 差旅住宿连续超天数人员(公司维度,全量)
// 差旅住宿连续超天数人员(公司维度,全量,排除指定部门)
List<StaffMeituanOrder> companyTravelExceed = staffMeituanOrderMapper.selectCompanyTravelExceedByCheckinTime(
travelExceedDayNum, lastMonthStart, lastMonthEnd);
// 排除指定部门的数据
companyTravelExceed = excludeDeptOrders(companyTravelExceed, excludeDeptNames);
if (CollectionUtils.isNotEmpty(companyTravelExceed)) {
companyTravelExceed.forEach(o -> focusIssues.add(DeptIssueItemDTO.builder()
.sceneType(MeituanSceneTypeEnum.BUSINESS_TRAVEL.getCode())
......@@ -1085,6 +1098,89 @@ public class StaffMeituanOrderService {
return order;
}
/**
* 获取月度报告统计需要排除的部门名称(对应订单的 directOrgName 字段)
* 默认排除:零售运营部、场景运营部、数字化运营部;
* 可通过配置 staff.meituan.report.exclude.dept.names 覆盖(多个部门用英文逗号分隔)
*/
private List<String> getExcludeReportDeptNames() {
String config = env.getProperty("staff.meituan.report.exclude.dept.names", String.class);
if (StringUtils.isEmpty(config) || config.trim().isEmpty()) {
return MeiTuanOrderConstants.REPORT_EXCLUDE_DEPT_NAMES;
}
return Arrays.stream(config.split(","))
.map(String::trim)
.filter(name -> !name.isEmpty())
.collect(Collectors.toList());
}
/**
* 判断订单所属的直接归属部门(directOrgName)是否属于需要排除的部门
* 排除部门默认:零售运营部、场景运营部、数字化运营部
*
* @param directOrgName 订单的直接归属部门名称
* @return true-属于排除部门
*/
public boolean isExcludeReportDept(String directOrgName) {
return isExcludeReportDept(directOrgName, null);
}
/**
* 判断订单所属部门是否属于需要排除的部门
* 先匹配直接归属部门 directOrgName,再兜底匹配完整部门路径 orgNamePath 中的任意一级部门,
* 避免部门层级调整(排除部门处于一级或二级)时漏排除
*
* @param directOrgName 直接归属部门名称
* @param orgNamePath 完整部门路径,格式如 "公司-一级部门-二级部门"
* @return true-属于排除部门
*/
public boolean isExcludeReportDept(String directOrgName, String orgNamePath) {
List<String> excludeDeptNames = getExcludeReportDeptNames();
if (CollectionUtils.isEmpty(excludeDeptNames)) {
return false;
}
if (matchesExcludeDept(directOrgName, excludeDeptNames)) {
return true;
}
if (!StringUtils.isEmpty(orgNamePath)) {
for (String orgName : orgNamePath.split("-")) {
if (matchesExcludeDept(orgName, excludeDeptNames)) {
return true;
}
}
}
return false;
}
/**
* 部门名称是否命中排除名单(去空格后全等匹配)
*/
private boolean matchesExcludeDept(String deptName, List<String> excludeDeptNames) {
if (StringUtils.isEmpty(deptName)) {
return false;
}
String name = deptName.trim();
return excludeDeptNames.stream().anyMatch(name::equals);
}
/**
* 排除指定部门(直接归属部门)的订单数据
* @param orders 订单列表
* @param excludeDeptNames 需要排除的部门名称
* @return 排除后的订单列表
*/
private List<StaffMeituanOrder> excludeDeptOrders(List<StaffMeituanOrder> orders, List<String> excludeDeptNames) {
if (CollectionUtils.isEmpty(orders)) {
return orders == null ? new ArrayList<>() : orders;
}
if (CollectionUtils.isEmpty(excludeDeptNames)) {
return orders;
}
return orders.stream()
.filter(o -> !isExcludeReportDept(o.getDirectOrgName(), o.getOrgNamePath()))
.collect(Collectors.toList());
}
private static BigDecimal sumAmount(List<StaffMeituanOrder> list,
Function<StaffMeituanOrder, BigDecimal> getter) {
if (list == null || list.isEmpty()) {
......
......@@ -99,13 +99,13 @@
<!-- 公司维度在指定月份内,按入住时间统计差旅超长入住记录 -->
<select id="selectCompanyTravelExceedByCheckinTime" resultMap="BaseResultMap">
SELECT
staff_name, checkin_time, checkout_time, room_night_count
staff_name, checkin_time, checkout_time, room_night_count, direct_org_name, org_name_path
FROM dj_car_life_staff_meituan_order
WHERE scene_type = 3
AND room_night_count &gt;= #{minRoomNightCount}
AND deleted_flag = 'N'
AND (checkin_time BETWEEN #{startTime} AND #{endTime} or checkout_time BETWEEN #{startTime} AND #{endTime})
group by staff_name, checkin_time, checkout_time, room_night_count
group by staff_name, checkin_time, checkout_time, room_night_count, direct_org_name, org_name_path
order by room_night_count desc
</select>
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 排除配置缺少有效性校验,错误配置会静默取消全部排除规则

    • 问题描述:getExcludeReportDeptNames() 仅判断原始配置是否为空。配置为 ","、" , , " 时,解析结果为空列表,但不会回退默认名单。报告和推送随后均按“不排除任何部门”执行。
    • 影响分析:配置格式错误即可导致原本应排除的部门进入月报,并重新收到超标提醒;系统没有异常或告警,难以及时发现统计口径变化。
    • 优化建议:区分“未配置”“有效配置”“显式关闭排除”三种状态。非空配置解析后为空时,应拒绝配置或回退默认名单并告警;若需要关闭排除,使用独立开关,不要依赖无效分隔符。
    List<String> names = Arrays.stream(config.split(","))
            .map(String::trim)
            .filter(name -> !name.isEmpty())
            .distinct()
            .collect(Collectors.toList());
    
    if (names.isEmpty()) {
        log.warn("部门排除配置无有效条目,使用默认名单");
        return MeiTuanOrderConstants.REPORT_EXCLUDE_DEPT_NAMES;
    }
    return names;
    

    2. 批量过滤未使用传入的配置快照,重复读取配置且可能产生不一致的统计口径

    • 问题描述:excludeDeptOrders(orders, excludeDeptNames) 虽然接收排除名单,但实际过滤调用的 isExcludeReportDept(...) 会对每笔订单重新执行 getExcludeReportDeptNames()。传入名单仅用于空值判断,没有参与实际匹配。
    • 影响分析:每笔订单重复读取、拆分配置并创建集合,增加批量报告的资源开销。如果配置源支持动态更新,同一次报告的不同订单、上月和前月数据可能采用不同名单,日志中的名单也可能与实际过滤口径不一致。
    • 优化建议:将匹配逻辑改为显式接收名单;一次报告生成过程中复用同一份不可变配置快照。可使用 Set<String> 做精确匹配,推送入口再单独读取配置并调用同一匹配函数。
    private boolean isExcludeDept(
            String directOrgName, String orgNamePath, Set<String> excludedNames) {
        // 直接部门和路径各级部门均只使用 excludedNames 判断
    }
    
    // 批量过滤时,不再调用内部读取配置的公开方法
    return orders.stream()
            .filter(o -> !isExcludeDept(
                    o.getDirectOrgName(), o.getOrgNamePath(), excludedNames))
            .collect(Collectors.toList());
    

    3. 新增 INFO 日志不必要地关联记录员工身份、组织路径及订单标识

    • 问题描述:两个“不推送”分支新增日志同时输出 staffName、完整 orgNamePath 和 sqtBizOrderId。判断是否排除并不需要在日志中记录全部这些字段。
    • 影响分析:员工身份、组织归属与订单标识的关联信息被写入日志,扩大了敏感信息的存储及访问范围。若日志进入集中检索平台,其可见范围和保留期限可能超过业务数据本身。
    • 优化建议:遵循日志最小化原则,优先记录排除原因、命中的部门规则和必要的追踪标识;删除员工姓名及完整组织路径。确需保留关联信息时,应脱敏并落实访问权限与保留期限控制。

    二、评分明细

    评分维度 得分 理由
    功能实现的正确性与健壮性 31/40 公司、个人报告及推送均接入排除逻辑,但无效配置会取消排除,批量处理未真正复用配置快照。本次 SQL 变更未使用子查询,也未发现 Dubbo 提供者 Remote 接口已有请求参数变更。
    安全性与潜在风险 26/30 未发现本次变更新增 SQL 注入或越权路径;新增日志存在员工与订单关联信息过度记录风险。
    最佳实践与可维护性 15/20 默认名单使用不可变集合、匹配逻辑有一定复用;但过滤方法参数与实际行为不一致,配置有效性约束不足。
    性能与资源利用 3/5 批量过滤中逐笔读取、解析相同配置,存在可避免的集合分配与计算开销。
    提交信息质量 5/5 提交说明清晰,覆盖排除范围、配置覆盖能力及部门路径匹配方式,与变更基本一致。

    总分:80分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!