Commit 0cad9203 by zhoulm

Merge branch 'v5.7.1' of http://192.168.3.233:8090/dj/rpc-smartcarlife into v5.7.1

2 parents fa8bd607 0435a039
...@@ -39,6 +39,9 @@ public class StaffStudyDetailInfoDTO implements Serializable { ...@@ -39,6 +39,9 @@ public class StaffStudyDetailInfoDTO implements Serializable {
private String merchantIds; private String merchantIds;
@JsonIgnore
private Integer merchantId;
@ApiModelProperty(notes = "业务类型") @ApiModelProperty(notes = "业务类型")
private String businessSceneTypeNames; private String businessSceneTypeNames;
......
...@@ -51,6 +51,27 @@ public interface StaffInfoMapper extends OreMapper<StaffInfo> { ...@@ -51,6 +51,27 @@ public interface StaffInfoMapper extends OreMapper<StaffInfo> {
List<StaffStudyDetailInfoDTO> findByStaffStudy(StaffStudyDetailInfoDTO dto); List<StaffStudyDetailInfoDTO> findByStaffStudy(StaffStudyDetailInfoDTO dto);
/**
* 查询员工的业务场景类型(近30天订单)
* @param staffPhones 员工手机号列表
* @return 员工业务场景类型信息
*/
List<StaffStudyDetailInfoDTO> findStaffBusinessSceneTypes(@Param("staffPhones") List<String> staffPhones);
/**
* 查询员工关联的门店信息
* @param staffPhones 员工手机号列表
* @return 员工门店信息
*/
List<StaffStudyDetailInfoDTO> findStaffMerchantInfo(@Param("staffPhones") List<String> staffPhones);
/**
* 查询门店的区域运营(上级)信息
* @param merchantIds 门店ID列表
* @return 门店上级信息
*/
List<StaffStudyDetailInfoDTO> findMerchantSuperiors(@Param("merchantIds") List<Integer> merchantIds);
StaffInfo getLatestOrderStaff(@Param("staffPhone") String staffPhone, StaffInfo getLatestOrderStaff(@Param("staffPhone") String staffPhone,
@Param("startTime") Date startTime, @Param("startTime") Date startTime,
@Param("endTime") Date endTime, @Param("endTime") Date endTime,
......
...@@ -3143,18 +3143,158 @@ public class ContentManagerTaskService { ...@@ -3143,18 +3143,158 @@ public class ContentManagerTaskService {
return res.get(0); return res.get(0);
} }
public List<StaffStudyDetailInfoDTO> listStaffStudyInfo(StaffStudyDetailInfoDTO dto) { public List<StaffStudyDetailInfoDTO> listStaffStudyInfo(StaffStudyDetailInfoDTO dto) {
// 查询员工关联导师,和服务门店,再查门店下的区域运营 // 优化后的查询:分步查询,避免复杂SQL导致的索引失效问题
// 1. 查询员工基本信息
List<StaffStudyDetailInfoDTO> res = staffInfoMapper.findByStaffStudy(dto); List<StaffStudyDetailInfoDTO> res = staffInfoMapper.findByStaffStudy(dto);
if (CollectionUtils.isEmpty(res)) { if (CollectionUtils.isEmpty(res)) {
log.info("该手机号查询上级、导师等信息失败. dto:{}", dto); log.info("该手机号查询上级、导师等信息失败. dto:{}", dto);
return null; return null;
} }
// 2. 补充员工的业务场景类型(近30天订单)
appendStaffBusinessSceneTypes(res);
// 3. 补充员工关联的门店信息
appendStaffMerchantInfo(res);
// 4. 补充门店的区域运营(上级)信息
appendMerchantSuperiors(res);
// 5. 补充指标信息
appendStaffIndicatorInfo(dto, res); appendStaffIndicatorInfo(dto, res);
// 6. 补充主营品牌信息
appendStaffMainBrand(dto, res); appendStaffMainBrand(dto, res);
return res; return res;
} }
/**
* 补充员工的业务场景类型(近30天订单)
*/
private void appendStaffBusinessSceneTypes(List<StaffStudyDetailInfoDTO> res) {
List<String> staffPhones = res.stream()
.map(StaffStudyDetailInfoDTO::getStaffPhone)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(staffPhones)) {
return;
}
try {
List<StaffStudyDetailInfoDTO> sceneTypes = staffInfoMapper.findStaffBusinessSceneTypes(staffPhones);
if (CollectionUtils.isNotEmpty(sceneTypes)) {
Map<String, String> phoneToSceneMap = sceneTypes.stream()
.filter(s -> StringUtils.isNotBlank(s.getStaffPhone()))
.collect(Collectors.toMap(
StaffStudyDetailInfoDTO::getStaffPhone,
s -> s.getBusinessSceneTypeNames() != null ? s.getBusinessSceneTypeNames() : "",
(existing, replacement) -> existing
));
log.info("查询员工业务场景类型成功. staffPhones: {}, phoneToSceneMap: {}", staffPhones, phoneToSceneMap);
res.forEach(item -> {
if (StringUtils.isNotBlank(item.getStaffPhone()) && phoneToSceneMap.containsKey(item.getStaffPhone())) {
item.setBusinessSceneTypeNames(phoneToSceneMap.get(item.getStaffPhone()));
}
});
}
} catch (Exception e) {
log.error("查询员工业务场景类型失败, staffPhones: {}, error: {}", staffPhones, e.getMessage(), e);
}
}
/**
* 补充员工关联的门店信息
*/
private void appendStaffMerchantInfo(List<StaffStudyDetailInfoDTO> res) {
List<String> staffPhones = res.stream()
.map(StaffStudyDetailInfoDTO::getStaffPhone)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(staffPhones)) {
return;
}
try {
List<StaffStudyDetailInfoDTO> merchantInfos = staffInfoMapper.findStaffMerchantInfo(staffPhones);
if (CollectionUtils.isNotEmpty(merchantInfos)) {
Map<String, StaffStudyDetailInfoDTO> phoneToMerchantMap = merchantInfos.stream()
.filter(s -> StringUtils.isNotBlank(s.getStaffPhone()))
.collect(Collectors.toMap(
StaffStudyDetailInfoDTO::getStaffPhone,
s -> s,
(existing, replacement) -> existing
));
log.info("查询员工门店信息成功. staffPhones: {}, phoneToMerchantMap: {}", staffPhones, phoneToMerchantMap);
res.forEach(item -> {
if (StringUtils.isNotBlank(item.getStaffPhone()) && phoneToMerchantMap.containsKey(item.getStaffPhone())) {
StaffStudyDetailInfoDTO merchantInfo = phoneToMerchantMap.get(item.getStaffPhone());
item.setMerchantIds(merchantInfo.getMerchantIds());
item.setMerchantNames(merchantInfo.getMerchantNames());
}
});
}
} catch (Exception e) {
log.error("查询员工门店信息失败, staffPhones: {}, error: {}", staffPhones, e.getMessage(), e);
}
}
/**
* 补充门店的区域运营(上级)信息
*/
private void appendMerchantSuperiors(List<StaffStudyDetailInfoDTO> res) {
// 收集所有门店ID
List<Integer> merchantIds = res.stream()
.map(StaffStudyDetailInfoDTO::getMerchantIds)
.filter(StringUtils::isNotBlank)
.flatMap(ids -> Arrays.stream(ids.split(",")))
.map(String::trim)
.filter(StringUtils::isNotBlank)
.map(Integer::parseInt)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(merchantIds)) {
return;
}
try {
List<StaffStudyDetailInfoDTO> superiors = staffInfoMapper.findMerchantSuperiors(merchantIds);
if (CollectionUtils.isNotEmpty(superiors)) {
// 构建门店ID到上级的映射
Map<Integer, String> merchantIdToSuperiorMap = superiors.stream()
.filter(s -> s.getMerchantId() != null && StringUtils.isNotBlank(s.getSuperiors()))
.collect(Collectors.toMap(
StaffStudyDetailInfoDTO::getMerchantId,
StaffStudyDetailInfoDTO::getSuperiors,
(existing, replacement) -> existing + "," + replacement
));
log.info("查询门店上级信息成功. merchantIds: {}, merchantIdToSuperiorMap: {}", merchantIds, merchantIdToSuperiorMap);
// 为每个员工设置上级信息
res.forEach(item -> {
if (StringUtils.isNotBlank(item.getMerchantIds())) {
List<String> superiorList = new ArrayList<>();
String[] ids = item.getMerchantIds().split(",");
for (String id : ids) {
try {
Integer merchantId = Integer.parseInt(id.trim());
if (merchantIdToSuperiorMap.containsKey(merchantId)) {
superiorList.add(merchantIdToSuperiorMap.get(merchantId));
}
} catch (NumberFormatException e) {
log.warn("门店ID格式错误: {}", id);
}
}
if (!superiorList.isEmpty()) {
item.setSuperiors(String.join(",", superiorList));
}
}
});
}
} catch (Exception e) {
log.error("查询门店上级信息失败, merchantIds: {}, error: {}", merchantIds, e.getMessage(), e);
}
}
private void appendStaffMainBrand(StaffStudyDetailInfoDTO dto, List<StaffStudyDetailInfoDTO> res) { private void appendStaffMainBrand(StaffStudyDetailInfoDTO dto, List<StaffStudyDetailInfoDTO> res) {
if (!Objects.equals(dto.getQueryMainBrand(), Boolean.TRUE)) { if (!Objects.equals(dto.getQueryMainBrand(), Boolean.TRUE)) {
return; return;
......
...@@ -546,52 +546,15 @@ ...@@ -546,52 +546,15 @@
and scene_type = #{sceneType} and scene_type = #{sceneType}
</select> </select>
<!-- 优化后的基础查询:只查询员工基本信息 -->
<select id="findByStaffStudy" resultType="cn.com.glsx.dj.smartcarlife.dto.study.StaffStudyDetailInfoDTO"> <select id="findByStaffStudy" resultType="cn.com.glsx.dj.smartcarlife.dto.study.StaffStudyDetailInfoDTO">
select select
sbi.staff_phone as staffPhone, sbi.staff_phone as staffPhone,
group_concat(distinct sbi.staff_name) as staffName, sbi.staff_name as staffName,
group_concat(distinct sbi.staff_scene_label) as staffSL, sbi.staff_scene_label as staffSL,
group_concat(distinct sdrc.merchant_id) as merchantIds, sbi.mentor_name as mentors,
group_concat(distinct sdrc.merchant_name) as merchantNames,
group_concat(distinct sbi.mentor_name) as mentors,
group_concat(distinct if(smdc.director_type in (8,9), smdc.director_name, null)) as superiors,
tempTable.staff_scene_label as businessSceneTypeNames,
sbi.entry_time as entryTime sbi.entry_time as entryTime
from dj_car_life_staff_base_info sbi from dj_car_life_staff_base_info sbi
left join
(
select
si.phone_number,
coalesce(
group_concat(
distinct case
when go.scene_type = 1 then '轻改'
when go.scene_type = 0 and go.business_type = 1 then '权益'
when go.scene_type = 0 and go.business_type = 2 then '延保'
end
order by case
when go.scene_type = 1 then '1'
when go.scene_type = 0 and go.business_type = 1 then '权益'
when go.scene_type = 0 and go.business_type = 2 then '延保'
end
separator ', '
),
''
) as staff_scene_label
from dj_car_life_staff_info si
left join dj_car_life_goods_order go on si.staff_uuid = go.seller_user_id and go.install_upgrade_time >= DATE_SUB(CURDATE(), interval 30 day)
where si.phone_number is not null
group by si.phone_number
) as tempTable on sbi.staff_phone = tempTable.phone_number
left join
(
select
sdrc.staff_phone , sdrc.merchant_id , sdrc.merchant_name
from dj_car_life_staff_daily_report_config sdrc
inner join dj_car_life_staff_daily_report_effect_record sdrer on sdrc.id = sdrer.daily_report_config_id and sdrer.deleted_flag = 'N' and ((sdrer.start_effective_time &lt;= NOW() and sdrer.end_effective_time is null) or (sdrer.start_effective_time &lt;= NOW() and sdrer.end_effective_time >= NOW()))
where sdrc.deleted_flag = 'N'
) as sdrc on sdrc.staff_phone = sbi.staff_phone
left join dj_car_life_shop_merchant_director_config smdc on sdrc.merchant_id = smdc.merchant_id and smdc.deleted_flag = "N"
<where> <where>
sbi.deleted_flag = "N" sbi.deleted_flag = "N"
<if test="staffPhone != null and staffPhone != ''"> <if test="staffPhone != null and staffPhone != ''">
...@@ -604,7 +567,72 @@ ...@@ -604,7 +567,72 @@
</foreach> </foreach>
</if> </if>
</where> </where>
group by sbi.staff_phone </select>
<!-- 查询员工的业务场景类型(近30天订单) -->
<select id="findStaffBusinessSceneTypes" resultType="cn.com.glsx.dj.smartcarlife.dto.study.StaffStudyDetailInfoDTO">
select
si.phone_number as staffPhone,
group_concat(
distinct case
when go.scene_type = 1 then '轻改'
when go.scene_type = 0 and go.business_type = 1 then '权益'
when go.scene_type = 0 and go.business_type = 2 then '延保'
end
order by case
when go.scene_type = 1 then '1'
when go.scene_type = 0 and go.business_type = 1 then '2'
when go.scene_type = 0 and go.business_type = 2 then '3'
end
separator ', '
) as businessSceneTypeNames
from dj_car_life_staff_info si
inner join dj_car_life_goods_order go on si.staff_uuid = go.seller_user_id
where si.phone_number is not null
and si.deleted_flag = 'N'
and go.deleted_flag = 'N'
and go.install_upgrade_time >= DATE_SUB(CURDATE(), interval 30 day)
and si.phone_number in
<foreach close=")" collection="staffPhones" item="phone" open="(" separator=",">
#{phone}
</foreach>
group by si.phone_number
</select>
<!-- 查询员工关联的门店信息 -->
<select id="findStaffMerchantInfo" resultType="cn.com.glsx.dj.smartcarlife.dto.study.StaffStudyDetailInfoDTO">
select
sdrc.staff_phone as staffPhone,
group_concat(distinct sdrc.merchant_id) as merchantIds,
group_concat(distinct sdrc.merchant_name) as merchantNames
from dj_car_life_staff_daily_report_config sdrc
inner join dj_car_life_staff_daily_report_effect_record sdrer on sdrc.id = sdrer.daily_report_config_id
where sdrc.deleted_flag = 'N'
and sdrer.deleted_flag = 'N'
and (
(sdrer.start_effective_time &lt;= NOW() and sdrer.end_effective_time is null) or
(sdrer.start_effective_time &lt;= NOW() and sdrer.end_effective_time >= NOW())
)
and sdrc.staff_phone in
<foreach close=")" collection="staffPhones" item="phone" open="(" separator=",">
#{phone}
</foreach>
group by sdrc.staff_phone
</select>
<!-- 查询门店的区域运营(上级)信息 -->
<select id="findMerchantSuperiors" resultType="cn.com.glsx.dj.smartcarlife.dto.study.StaffStudyDetailInfoDTO">
select
smdc.merchant_id as merchantId,
group_concat(distinct smdc.director_name) as superiors
from dj_car_life_shop_merchant_director_config smdc
where smdc.deleted_flag = 'N'
and smdc.director_type in (8, 9)
and smdc.merchant_id in
<foreach close=")" collection="merchantIds" item="merchantId" open="(" separator=",">
#{merchantId}
</foreach>
group by smdc.merchant_id
</select> </select>
<select id="getLatestOrderStaff" resultMap="BaseResultMap"> <select id="getLatestOrderStaff" resultMap="BaseResultMap">
......
  • @wangxw1
    commented
    Master

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

    1. 变量重命名导致编译错误或严重逻辑异常(功能正确性)

    • 问题描述:在第 2939 行附近,将变量声明由 List<OADJOnShelvesDTO> list = new ArrayList<>(); 修改为了 list1。然而,紧随其后的代码依然在使用旧变量名进行操作:list.add(oadjOnShelvesDTO);。
    • 影响分析:如果当前作用域中不存在另一个名为 list 的变量,这将直接导致编译失败;如果上下文中存在同名的全局或外层变量 list,数据将被错误地添加到其他集合中,导致不可预期的业务逻辑异常。
    • 优化建议:保持变量声明与使用的一致性。如果确实需要重命名,请将下方的调用一并修改。 java // 建议的修改方式(同时优化了命名) List<OADJOnShelvesDTO> onShelvesList = new ArrayList<>(); CreateBusinessApproveMerchantDTO merchant = merchants.get(0); OADJOnShelvesDTO oadjOnShelvesDTO = CreateBusinessApproveMerchantDTOConvert.INSTANCE.toOADJOnShelvesDTO(merchant); onShelvesList.add(oadjOnShelvesDTO);

    2. 变量命名缺乏语义,不符合规范(最佳实践)

    • 问题描述:将局部变量命名为 list1。
    • 影响分析:使用带有无意义数字后缀的变量名(如 list1, list2)极大地降低了代码的可读性和可维护性,后续接手维护的开发者无法直观地理解该集合的业务用途。
    • 优化建议:摒弃 list、list1 等无意义命名,改用具有明确业务语义的名称,如 onShelvesDTOList 或 merchantOnShelvesList。

    3. 提交信息与实际代码变更不完全匹配(提交信息质量)

    • 问题描述:Commit 信息为“服务商2分润比例修改”,这准确涵盖了代码中第一处修复(getPartnerMerchantDivideValue 改为 getPartnerMerchant2DivideValue),但并未解释为什么在第二处去将 list 修改为 list1。
    • 影响分析:当代码出现问题(如本次引发的编译/逻辑错误)时,其他开发者无法通过 Commit Message 追溯修改第二处代码的真实意图,增加了排查成本。
    • 优化建议:提交代码前应通过 git diff 仔细 Review 自己的改动,确保不要包含误触或无关的修改。如果包含多项无关重构,建议拆分为不同的 Commit 或在提交信息中详细说明。

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分): 理由:虽然成功修复了 partnerMerchant2DivideValue 字段取值的隐蔽 Bug,但第二处改动引入了极其严重的变量引用错误(list1 声明但使用了 list),这属于低级且致命的错误,大幅扣分。

    • 安全性与潜在风险(30/30分): 理由:本次代码变更仅涉及业务字段调整和局部变量操作,未引入 SQL 注入、越权、敏感信息泄露等安全隐患。

    • 最佳实践与可维护性(15/20分): 理由:变量命名出现了 list1 这种反模式(Anti-pattern)命名,不符合主流工程规范中对代码自解释性的要求,故适当扣分。

    • 性能与资源利用(5/5分): 理由:逻辑属于常规的对象转换和集合操作,不存在明显的性能瓶颈或不必要的资源浪费。

    • 提交信息质量(3/5分): 理由:提交信息指出了主要业务修改点,但混杂了系统自动生成的 Merge 记录,且未能覆盖(或解释)代码中所有变更的意图。

    总分:73分

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