Commit 963fff92 by 叶立庆

Merge branch 'v5.8.7.6' into 'master'

上线合并

See merge request !28
2 parents 9a764d7e 8d371abf
package cn.com.glsx.dj.staff.constant; package cn.com.glsx.dj.staff.constant;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/** /**
* @Title MeiTuanOrderConstants * @Title MeiTuanOrderConstants
* @author pangst * @author pangst
...@@ -24,4 +28,18 @@ public class MeiTuanOrderConstants { ...@@ -24,4 +28,18 @@ public class MeiTuanOrderConstants {
public static final String DEPT_SALE_TWO = "销售二部"; public static final String DEPT_SALE_TWO = "销售二部";
public static final String DEPT_RETAIL = "零售运营"; 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 { ...@@ -172,6 +172,14 @@ public class MeiTuanOrderJob implements SimpleJob {
return; 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(); Integer roomNightCount = staff.getRoomNightCount();
// 赋值推送内容 // 赋值推送内容
...@@ -267,6 +275,14 @@ public class MeiTuanOrderJob implements SimpleJob { ...@@ -267,6 +275,14 @@ public class MeiTuanOrderJob implements SimpleJob {
return; 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(); Long staffId = staff.getStaffId();
// 获取 lastHour 所在月份的超标次数(商务宴请且超标) // 获取 lastHour 所在月份的超标次数(商务宴请且超标)
......
...@@ -279,10 +279,15 @@ public class StaffMeituanOrderService { ...@@ -279,10 +279,15 @@ public class StaffMeituanOrderService {
List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd); List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd);
List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd); List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd);
// 排除指定部门(零售运营部、场景运营部、数字化运营部)的数据
List<String> excludeDeptNames = getExcludeReportDeptNames();
lastMonthAll = excludeDeptOrders(lastMonthAll, excludeDeptNames);
prevMonthAll = excludeDeptOrders(prevMonthAll, excludeDeptNames);
if (CollectionUtils.isEmpty(lastMonthAll)) { if (CollectionUtils.isEmpty(lastMonthAll)) {
return new ArrayList<>(); 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) Map<Long, List<StaffMeituanOrder>> lastMonthStaffMap = lastMonthAll.stream().filter(o -> o.getStaffId() != null)
...@@ -335,10 +340,15 @@ public class StaffMeituanOrderService { ...@@ -335,10 +340,15 @@ public class StaffMeituanOrderService {
List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd); List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd);
List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd); List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd);
// 排除指定部门(零售运营部、场景运营部、数字化运营部)的数据
List<String> excludeDeptNames = getExcludeReportDeptNames();
lastMonthAll = excludeDeptOrders(lastMonthAll, excludeDeptNames);
prevMonthAll = excludeDeptOrders(prevMonthAll, excludeDeptNames);
if (CollectionUtils.isEmpty(lastMonthAll)) { if (CollectionUtils.isEmpty(lastMonthAll)) {
return new ArrayList<>(); return new ArrayList<>();
} }
log.info("Dept lastMonthAll size:{}", lastMonthAll.size()); log.info("Dept排除部门:{},lastMonthAll size:{}", excludeDeptNames, lastMonthAll.size());
// 按部门分组 // 按部门分组
Map<Long, List<StaffMeituanOrder>> lastMonthDeptMap = lastMonthAll.stream() Map<Long, List<StaffMeituanOrder>> lastMonthDeptMap = lastMonthAll.stream()
...@@ -391,9 +401,15 @@ public class StaffMeituanOrderService { ...@@ -391,9 +401,15 @@ public class StaffMeituanOrderService {
List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd); List<StaffMeituanOrder> lastMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(lastMonthStart, lastMonthEnd);
List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd); List<StaffMeituanOrder> prevMonthAll = staffMeituanOrderMapper.selectByCreateTimeRange(prevMonthStart, prevMonthEnd);
// 排除指定部门(零售运营部、场景运营部、数字化运营部)的数据
List<String> excludeDeptNames = getExcludeReportDeptNames();
lastMonthAll = excludeDeptOrders(lastMonthAll, excludeDeptNames);
prevMonthAll = excludeDeptOrders(prevMonthAll, excludeDeptNames);
if (CollectionUtils.isEmpty(lastMonthAll)) { if (CollectionUtils.isEmpty(lastMonthAll)) {
return null; return null;
} }
log.info("公司月度报告排除部门:{},lastMonthAll size:{}", excludeDeptNames, lastMonthAll.size());
int monthValue = lastMonth.getMonthValue(); int monthValue = lastMonth.getMonthValue();
int monthStartDay = 1; int monthStartDay = 1;
...@@ -590,9 +606,11 @@ public class StaffMeituanOrderService { ...@@ -590,9 +606,11 @@ public class StaffMeituanOrderService {
.value(entry.getValue().intValue()) .value(entry.getValue().intValue())
.build())); .build()));
// 差旅住宿连续超天数人员(公司维度,全量) // 差旅住宿连续超天数人员(公司维度,全量,排除指定部门)
List<StaffMeituanOrder> companyTravelExceed = staffMeituanOrderMapper.selectCompanyTravelExceedByCheckinTime( List<StaffMeituanOrder> companyTravelExceed = staffMeituanOrderMapper.selectCompanyTravelExceedByCheckinTime(
travelExceedDayNum, lastMonthStart, lastMonthEnd); travelExceedDayNum, lastMonthStart, lastMonthEnd);
// 排除指定部门的数据
companyTravelExceed = excludeDeptOrders(companyTravelExceed, excludeDeptNames);
if (CollectionUtils.isNotEmpty(companyTravelExceed)) { if (CollectionUtils.isNotEmpty(companyTravelExceed)) {
companyTravelExceed.forEach(o -> focusIssues.add(DeptIssueItemDTO.builder() companyTravelExceed.forEach(o -> focusIssues.add(DeptIssueItemDTO.builder()
.sceneType(MeituanSceneTypeEnum.BUSINESS_TRAVEL.getCode()) .sceneType(MeituanSceneTypeEnum.BUSINESS_TRAVEL.getCode())
...@@ -1085,6 +1103,89 @@ public class StaffMeituanOrderService { ...@@ -1085,6 +1103,89 @@ public class StaffMeituanOrderService {
return order; 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, private static BigDecimal sumAmount(List<StaffMeituanOrder> list,
Function<StaffMeituanOrder, BigDecimal> getter) { Function<StaffMeituanOrder, BigDecimal> getter) {
if (list == null || list.isEmpty()) { if (list == null || list.isEmpty()) {
......
...@@ -99,13 +99,13 @@ ...@@ -99,13 +99,13 @@
<!-- 公司维度在指定月份内,按入住时间统计差旅超长入住记录 --> <!-- 公司维度在指定月份内,按入住时间统计差旅超长入住记录 -->
<select id="selectCompanyTravelExceedByCheckinTime" resultMap="BaseResultMap"> <select id="selectCompanyTravelExceedByCheckinTime" resultMap="BaseResultMap">
SELECT 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 FROM dj_car_life_staff_meituan_order
WHERE scene_type = 3 WHERE scene_type = 3
AND room_night_count &gt;= #{minRoomNightCount} AND room_night_count &gt;= #{minRoomNightCount}
AND deleted_flag = 'N' AND deleted_flag = 'N'
AND (checkin_time BETWEEN #{startTime} AND #{endTime} or checkout_time BETWEEN #{startTime} AND #{endTime}) 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 order by room_night_count desc
</select> </select>
......
  • @wangxw1
    commented
    Master

    你好 ,我是负责本次代码审查的资深开发工程师。以下是针对本次 代码提交的评审意见:

    一、关键问题与优化建议

    1. 业务逻辑在内存中频繁

    过滤(性能瓶颈)

    • 问题描述:目前代码通过调用 excludeDeptOrders 在 内存中对 List<StaffMeituanOrder> 进行流式处理过滤。随着订单数据量的增长,select ByCreateTimeRange 将获取全量数据后再丢弃其中一部分,这会浪费内存和 CPU 资源。

    • 影响分析:在高并发或历史数据量激增时,可能导致内存溢出(OOM)或接口 响应变慢。
    • 优化建议:应尽量利用 SQL 的 WHERE 条件过滤(即 在数据库端排除),仅将必要的数据加载到内存中。建议在 selectByCreateTimeRange 的 SQL 中增加 AND direct_org_name NOT IN (...) 等过滤条件。

    2. `excludeDeptOrders

    ` 中存在冗余递归调用

    • 问题描述:在 excludeDeptOrders 中调用了 isExcludeReport Dept,而该方法内部又调用了 getExcludeReportDeptNames()。在循环处理订单列表时,每处理一条 订单都会重新读取配置和解析字符串。
    • 影响分析:造成了大量无谓的字符串拆 分与集合创建,降低了执行效率。
    • 优化建议:建议将 getExcludeReportDept Names() 的结果作为参数传入 isExcludeReportDept 中,或者在 excludeDeptOrders 方法入口处先 获取一次名单,避免在过滤循环中重复获取配置。

    3. 潜在的 SQL 聚合

    错误(GROUP BY 规范)

    • 问题描述:在 selectCompanyTravelExceedByCheck inTime 的 XML 中,你添加了 direct_org_name 和 org_name_path 到 GROUP BY 中。
    • 影响分析:如果数据库开启了 ONLY_FULL_GROUP _BY 模式(MySQL 默认推荐开启),且 SELECT 列表中的字段未完全出现在 GROUP BY 中 时,会导致 SQL 执行报错。
    • 优化建议:检查该表是否存在唯一主键或其他非 聚合列被 SELECT 但未加入 GROUP BY。确保 SQL 语句符合严谨的规范,避免在不同环境 间迁移时出现兼容性问题。

    二、评分明细

    1. 功能实现的 正确性与健壮性(35/40):逻辑实现符合需求,通过 orgNamePath 兜底匹配增加了鲁棒性,但未能从数据库层直接排除数据,属于典型的内存补偿逻辑。
    2. 安全性与潜在风险(28/30):代码未涉及 SQL 注入或敏感信息泄漏。唯一 风险点在于 env.getProperty 若未配置时,兜底逻辑虽然存在,但需确保常量定义的 部门名称与库中实际存储完全一致。
    3. 最佳实践与可维护性(18/20) :代码封装良好,符合 SOLID 原则,使用了 Collections.unmodifiableList 保证常量安全,可 维护性较好。
    4. 性能与资源利用(3/5):存在内存中 过滤大集合的情况,且在循环中执行重复的字符串处理逻辑,性能有进一步优化的空间。 5. 提交信息质量(5/5):提交信息清晰,包含业务背景及具体变更点,符合规范 。

    总分:89分

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