Commit 164f3072 by 林永健

refactor(merchant-follow): 优化关注列表与策略动态相关逻辑

- 精简 StrategyInfoMapper 接口,合并方法,采用 MerchantBiCommentReq 作为参数
- 调整 StrategyStaffRelMapper,精简无用方法
- 精简 MerchantBiCommentRemoteImpl,去除废弃接口实现
- MerchantBasicInfoService 调整品牌名称获取逻辑,支持多品牌拼接
- MerchantBiCommentService 重构留言添加逻辑,支持批量处理关联人并改用新字段存储内容
- 删除冗余留言查询方法,优化策略动态查询,默认查询近一月数据
- MerchantBiFollowService 优化他人关注列表查询逻辑,改进权限处理和数据填充流程
- MerchantBiFollowService 门店列表关注与留言信息填充统一调用 MerchantBiCommentService 查询最新动态
- MetricsValueUtils 新增业务类型转换方法 convertBizsToScene,适配不同业务场景
- 修正关注取消及已关注判断返回值,统一返回 false 表示无需重复操作
- 代码中大量使用集合判空及流操作优化,提高性能与代码可读性
1 parent 4f9c938e
Showing 21 changed files with 78 additions and 523 deletions
...@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; ...@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -67,14 +68,9 @@ public class MerchantBiCommentReq implements Serializable { ...@@ -67,14 +68,9 @@ public class MerchantBiCommentReq implements Serializable {
private String staffPhone; private String staffPhone;
/** /**
* 处理人编号 * 处理人列表
*/ */
private String handlerStaffUuid; private List<HandlerStaffInfo> handlerStaffList;
/**
* 处理人姓名
*/
private String handlerStaffName;
/** /**
* 批量查询时的门店列表 * 批量查询时的门店列表
...@@ -90,4 +86,8 @@ public class MerchantBiCommentReq implements Serializable { ...@@ -90,4 +86,8 @@ public class MerchantBiCommentReq implements Serializable {
* 每页条数 * 每页条数
*/ */
private Integer pageSize; private Integer pageSize;
private Date startDate;
private Date endDate;
} }
package cn.com.glsx.dj.peanalysis.dto.analysis;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 策略中心记录 DTO (支持 5 种类型)
*
* @author lyj
*/
@Data
@ApiModel("策略中心记录详情")
public class StrategyRecordDTO implements Serializable {
@ApiModelProperty("ID")
private Integer id;
@ApiModelProperty("类型 (1:学习类; 2:优惠案例分享; 3:记录型; 4:任务型; 5:留言类)")
private Integer type;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("内容/说明")
private String content;
@ApiModelProperty("创建人姓名")
private String creatorName;
@ApiModelProperty("创建人UUID")
private String creatorUuid;
@ApiModelProperty("创建时间")
private Date createdDate;
@ApiModelProperty("处理人姓名 (多个以/分隔)")
private String handlerName;
@ApiModelProperty("执行人姓名")
private String executorName;
@ApiModelProperty("执行周期/时间")
private String executionPeriod;
@ApiModelProperty("学习人员")
private String learnerName;
@ApiModelProperty("学习内容/课程")
private String learningContent;
@ApiModelProperty("是否本人创建 (1:是; 0:否)")
private Integer isMine;
private static final long serialVersionUID = 1L;
}
package cn.com.glsx.dj.peanalysis.dto.analysis;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 策略中心记录查询请求 DTO
*
* @author lyj
*/
@Data
@ApiModel("策略中心记录查询请求")
public class StrategyRecordQryDTO implements Serializable {
@ApiModelProperty("门店ID")
private Integer merchantId;
@ApiModelProperty("业务类型")
private Byte businessType;
@ApiModelProperty("开始日期 (yyyy-MM-dd)")
private String startDate;
@ApiModelProperty("结束日期 (yyyy-MM-dd)")
private String endDate;
private static final long serialVersionUID = 1L;
}
...@@ -61,9 +61,6 @@ public class StoreListResponse implements Serializable { ...@@ -61,9 +61,6 @@ public class StoreListResponse implements Serializable {
@ApiModelProperty(notes = "关注数") @ApiModelProperty(notes = "关注数")
private Integer followCount; private Integer followCount;
@ApiModelProperty(notes = "留言条数")
private Integer commentCount;
@ApiModelProperty(notes = "最新留言/策略摘要") @ApiModelProperty(notes = "最新留言/策略摘要")
private String latestComment; private String latestComment;
......
package cn.com.glsx.dj.peanalysis.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Table(name = "dj_smartcarlife.dj_car_life_strategy_info")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyInfo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "strategy_type")
private Integer strategyType;
private String title;
@Column(name = "sub_title")
private String subTitle;
@Column(name = "start_date")
private Date startDate;
@Column(name = "end_date")
private Date endDate;
private String description;
private String content;
@Column(name = "handler_type")
private String handlerType;
@Column(name = "push_type")
private Integer pushType;
@Column(name = "created_by")
private String createdBy;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "updated_by")
private String updatedBy;
@Column(name = "updated_date")
private Date updatedDate;
@Column(name = "deleted_flag")
private String deletedFlag;
@Column(name = "merchant_id")
private Integer merchantId;
@Column(name = "merchant_name")
private String merchantName;
private Integer biz;
@Column(name = "push_flag")
private Integer pushFlag;
@Column(name = "created_uuid")
private String createdUuid;
private static final long serialVersionUID = 1L;
}
package cn.com.glsx.dj.peanalysis.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Table(name = "dj_smartcarlife.dj_car_life_strategy_staff_rel")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyStaffRel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "strategy_id")
private Integer strategyId;
@Column(name = "user_uuid")
private String userUuid;
@Column(name = "user_name")
private String userName;
@Column(name = "user_phone")
private String userPhone;
@Column(name = "created_by")
private String createdBy;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "updated_by")
private String updatedBy;
@Column(name = "updated_date")
private Date updatedDate;
@Column(name = "deleted_flag")
private String deletedFlag;
@Column(name = "user_position")
private Integer userPosition;
@Column(name = "beisen_userid")
private Integer beisenUserId;
private static final long serialVersionUID = 1L;
}
package cn.com.glsx.dj.peanalysis.remote; package cn.com.glsx.dj.peanalysis.remote;
import cn.com.glsx.dj.peanalysis.dto.analysis.MerchantBiCommentReq; import cn.com.glsx.dj.peanalysis.dto.analysis.MerchantBiCommentReq;
import cn.com.glsx.dj.peanalysis.dto.analysis.StrategyRecordDTO;
import cn.com.glsx.dj.peanalysis.dto.analysis.StrategyRecordQryDTO;
import cn.com.glsx.framework.core.annotation.ApiService; import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.Map;
/** /**
* BI-门店留言远程接口 * BI-门店留言远程接口
* @author lyj * @author lyj
...@@ -27,19 +22,4 @@ public interface MerchantBiCommentRemote { ...@@ -27,19 +22,4 @@ public interface MerchantBiCommentRemote {
* 撤回门店留言 (逻辑删除,限本人) * 撤回门店留言 (逻辑删除,限本人)
*/ */
RpcResponse<Boolean> withdrawComment(Integer id, String staffUuid); RpcResponse<Boolean> withdrawComment(Integer id, String staffUuid);
/**
* 分页查询门店跟进记录列表 (含留言+各类策略)
*/
RpcResponse<RpcPagination<StrategyRecordDTO>> findCombinedRecords(RpcPagination<StrategyRecordQryDTO> pagination, String loginUserUuid);
/**
* 获取记录详情 (支持 5 种策略类型)
*/
RpcResponse<StrategyRecordDTO> getStrategyDetail(Integer id, Integer type);
/**
* 批量查询门店动态条数
*/
RpcResponse<Map<Integer, Integer>> findCommentCounts(MerchantBiCommentReq request);
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<smartcarlife.api.version>5.6.4-SNAPSHOT</smartcarlife.api.version> <smartcarlife.api.version>5.6.4-SNAPSHOT</smartcarlife.api.version>
<mindworkplate.api.version>5.6.1-SNAPSHOT</mindworkplate.api.version> <mindworkplate.api.version>5.6.1-SNAPSHOT</mindworkplate.api.version>
<pe-analysis.api.version>5.7.0-SNAPSHOT</pe-analysis.api.version> <pe-analysis.api.version>5.7.0-SNAPSHOT</pe-analysis.api.version>
<strategy.api.version>5.6.0-SNAPSHOT</strategy.api.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -24,6 +25,11 @@ ...@@ -24,6 +25,11 @@
<artifactId>rpc-dj-pe-analysis-api</artifactId> <artifactId>rpc-dj-pe-analysis-api</artifactId>
<version>${pe-analysis.api.version}</version> <version>${pe-analysis.api.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.com.glsx.dj.strategy</groupId>
<artifactId>rpc-dj-strategy-api</artifactId>
<version>${strategy.api.version}</version>
</dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.merchants</groupId> <groupId>cn.com.glsx.merchants</groupId>
<artifactId>platform-merchants-api</artifactId> <artifactId>platform-merchants-api</artifactId>
......
package cn.com.glsx.dj.peanalysis.mapper; package cn.com.glsx.dj.peanalysis.mapper;
import cn.com.glsx.dj.peanalysis.model.StrategyInfo; import cn.com.glsx.dj.peanalysis.dto.analysis.MerchantBiCommentReq;
import cn.com.glsx.dj.strategy.model.StrategyInfo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
...@@ -12,34 +13,9 @@ import java.util.List; ...@@ -12,34 +13,9 @@ import java.util.List;
public interface StrategyInfoMapper extends OreMapper<StrategyInfo> { public interface StrategyInfoMapper extends OreMapper<StrategyInfo> {
/** /**
* 分页查询策略记录 * 查询门店最新动态
*/ */
List<StrategyInfo> findStrategyRecords(@Param("merchantId") Integer merchantId, @Param("biz") Integer biz); List<StrategyInfo> findLatestStrategyRecords(MerchantBiCommentReq req);
/**
* 批量查询最新动态
*/
List<StrategyInfo> findLatestStrategyRecords(@Param("merchantIds") List<Integer> merchantIds, @Param("biz") Integer biz);
/**
* 批量查询指定时间段内每个门店最新动态
*/
List<StrategyInfo> findLatestStrategyRecordsByTime(@Param("merchantIds") List<Integer> merchantIds,
@Param("biz") Integer biz,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
/**
* 批量统计记录数
*/
List<StrategyInfo> findStrategyCounts(@Param("merchantIds") List<Integer> merchantIds, @Param("biz") Integer biz);
/**
* 批量查询记录数 + 最新记录摘要(merchantId 维度)
* <p>
* 约定:返回的 StrategyInfo.id 存储 count,createdBy/createdDate 存储最新记录信息
*/
List<StrategyInfo> findStrategyCountAndLatestSummary(@Param("merchantIds") List<Integer> merchantIds, @Param("biz") Integer biz);
/** /**
* 统计指定时间段内的记录数 * 统计指定时间段内的记录数
......
package cn.com.glsx.dj.peanalysis.mapper; package cn.com.glsx.dj.peanalysis.mapper;
import cn.com.glsx.dj.peanalysis.model.StrategyStaffRel; import cn.com.glsx.dj.strategy.model.StrategyStaffRel;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
@Mapper @Mapper
public interface StrategyStaffRelMapper extends OreMapper<StrategyStaffRel> { public interface StrategyStaffRelMapper extends OreMapper<StrategyStaffRel> {
/**
* 根据策略 ID 查询关联人
*/
List<StrategyStaffRel> findByStrategyId(@Param("strategyId") Integer strategyId);
/**
* 根据策略 ID 列表查询关联人
*/
List<StrategyStaffRel> findByStrategyIds(@Param("strategyIds") List<Integer> strategyIds);
} }
package cn.com.glsx.dj.peanalysis.remote; package cn.com.glsx.dj.peanalysis.remote;
import cn.com.glsx.dj.peanalysis.dto.analysis.MerchantBiCommentReq; import cn.com.glsx.dj.peanalysis.dto.analysis.MerchantBiCommentReq;
import cn.com.glsx.dj.peanalysis.dto.analysis.StrategyRecordDTO;
import cn.com.glsx.dj.peanalysis.dto.analysis.StrategyRecordQryDTO;
import cn.com.glsx.dj.peanalysis.service.MerchantBiCommentService; import cn.com.glsx.dj.peanalysis.service.MerchantBiCommentService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum; import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -12,8 +9,6 @@ import org.apache.dubbo.config.annotation.DubboService; ...@@ -12,8 +9,6 @@ import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
/** /**
* BI-门店留言远程接口实现 (统一使用策略表存储) * BI-门店留言远程接口实现 (统一使用策略表存储)
* *
...@@ -47,34 +42,4 @@ public class MerchantBiCommentRemoteImpl implements MerchantBiCommentRemote { ...@@ -47,34 +42,4 @@ public class MerchantBiCommentRemoteImpl implements MerchantBiCommentRemote {
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage()); return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
} }
} }
@Override
public RpcResponse<RpcPagination<StrategyRecordDTO>> findCombinedRecords(RpcPagination<StrategyRecordQryDTO> pagination, String loginUserUuid) {
try {
return RpcResponse.success(commentService.findCombinedRecords(pagination, loginUserUuid));
} catch (Exception e) {
log.error("查询合并跟进记录异常", e);
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
}
}
@Override
public RpcResponse<StrategyRecordDTO> getStrategyDetail(Integer id, Integer type) {
try {
return RpcResponse.success(commentService.getStrategyDetail(id, type));
} catch (Exception e) {
log.error("查询记录详情异常", e);
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
}
}
@Override
public RpcResponse<Map<Integer, Integer>> findCommentCounts(@RequestBody MerchantBiCommentReq request) {
try {
return RpcResponse.success(commentService.findCommentCounts(request));
} catch (Exception e) {
log.error("查询门店动态条数异常", e);
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
}
}
} }
...@@ -311,13 +311,15 @@ public class BusinessSceneAnalysisService { ...@@ -311,13 +311,15 @@ public class BusinessSceneAnalysisService {
} }
String targetMonth = queryParams.getStartDate(); String targetMonth = queryParams.getStartDate();
byte businessType = req.convertToBusinessType(queryParams.getBizs());
RpcPagination<MerchantOutputTargetConfigDTO> pagination = new RpcPagination<>(); RpcPagination<MerchantOutputTargetConfigDTO> pagination = new RpcPagination<>();
pagination.setPageSize(Integer.MAX_VALUE); pagination.setPageSize(Integer.MAX_VALUE);
pagination.setPageNum(1); pagination.setPageNum(1);
MerchantOutputTargetConfigDTO condition = new MerchantOutputTargetConfigDTO(); MerchantOutputTargetConfigDTO condition = new MerchantOutputTargetConfigDTO();
condition.setMerchantIdList(req.getMerchantIds()); condition.setMerchantIdList(req.getMerchantIds());
condition.setBusinessType(businessType); if (queryParams.getBizs() != null) {
byte businessType = req.convertToBusinessType(queryParams.getBizs());
condition.setBusinessType(businessType);
}
condition.setTargetMonth(targetMonth.substring(0, targetMonth.length() - 3)); condition.setTargetMonth(targetMonth.substring(0, targetMonth.length() - 3));
pagination.setCondition(condition); pagination.setCondition(condition);
RpcResponse<RpcPagination<MerchantOutputTargetConfigDTO>> outputTargetConfigResp = merchantOutputTargetConfigRemote.listWithPage(pagination); RpcResponse<RpcPagination<MerchantOutputTargetConfigDTO>> outputTargetConfigResp = merchantOutputTargetConfigRemote.listWithPage(pagination);
......
...@@ -5,6 +5,7 @@ import cn.com.glsx.dj.peanalysis.dto.res.output.StoreDetailSummaryResponse; ...@@ -5,6 +5,7 @@ import cn.com.glsx.dj.peanalysis.dto.res.output.StoreDetailSummaryResponse;
import cn.com.glsx.dj.peanalysis.mapper.ServiceMerchantMapper; import cn.com.glsx.dj.peanalysis.mapper.ServiceMerchantMapper;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.merchants.dto.merchant.CarbrandResponse;
import cn.com.glsx.merchants.model.request.merchant.MerchantBasicInfoRequest; import cn.com.glsx.merchants.model.request.merchant.MerchantBasicInfoRequest;
import cn.com.glsx.merchants.model.request.merchant.MerchantInfoSwitch; import cn.com.glsx.merchants.model.request.merchant.MerchantInfoSwitch;
import cn.com.glsx.merchants.model.response.merchant.MerchantBasicInfoListResponse; import cn.com.glsx.merchants.model.response.merchant.MerchantBasicInfoListResponse;
...@@ -112,7 +113,11 @@ public class MerchantBasicInfoService { ...@@ -112,7 +113,11 @@ public class MerchantBasicInfoService {
if (merchantInfo == null) { if (merchantInfo == null) {
return; return;
} }
p.setBrandName(merchantInfo.getMerchantBrandMain()); List<CarbrandResponse> brandList = merchantInfo.getCarBrandList();
if (CollectionUtils.isNotEmpty(brandList)) {
String firstBrandNames = brandList.stream().map(CarbrandResponse::getName).distinct().collect(Collectors.joining(","));
p.setBrandName(firstBrandNames);
}
p.setProvinceName(merchantInfo.getProvinceName()); p.setProvinceName(merchantInfo.getProvinceName());
p.setCityName(merchantInfo.getCityName()); p.setCityName(merchantInfo.getCityName());
}); });
......
package cn.com.glsx.dj.peanalysis.utils; package cn.com.glsx.dj.peanalysis.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -13,6 +14,7 @@ import java.math.RoundingMode; ...@@ -13,6 +14,7 @@ import java.math.RoundingMode;
* - 金额/产值类指标保留两位小数 * - 金额/产值类指标保留两位小数
* - 达成率计算(产值/目标*100) * - 达成率计算(产值/目标*100)
*/ */
@Slf4j
public final class MetricsValueUtils { public final class MetricsValueUtils {
private MetricsValueUtils() { private MetricsValueUtils() {
...@@ -69,4 +71,21 @@ public final class MetricsValueUtils { ...@@ -69,4 +71,21 @@ public final class MetricsValueUtils {
} }
return toPercentage(new BigDecimal(val)).toString(); return toPercentage(new BigDecimal(val)).toString();
} }
/**
*
* BI的业务类型传参Bizs: 1.延保 2.轻改 3.权益 4.二手车
* DJ的业务类型传参scene: 0:2.1会员权益; 1:精品升级
*/
public static Integer convertBizsToScene(Integer bizs) {
switch (bizs){
case 1:
case 3:
return 0;
case 2:
return 1;
}
log.error("不支持的bizs参数: {}", bizs);
return -1;
}
} }
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<select id="findMyFollowDetails" resultMap="BaseResultMap"> <select id="findMyFollowDetails" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow_detail FROM dj_merchant_bi_follow_detail
WHERE staff_uuid = #{staffUuid} WHERE staff_uuid = #{staffUuid}
AND deleted_flag = 'N' AND deleted_flag = 'N'
ORDER BY created_date DESC ORDER BY created_date DESC
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<select id="findOthersFollowDetails" resultMap="BaseResultMap"> <select id="findOthersFollowDetails" resultMap="BaseResultMap">
SELECT SELECT
DISTINCT follow_id DISTINCT follow_id
FROM merchant_bi_follow_detail FROM dj_merchant_bi_follow_detail
WHERE staff_uuid != #{staffUuid} WHERE staff_uuid != #{staffUuid}
AND deleted_flag = 'N' AND deleted_flag = 'N'
ORDER BY created_date DESC ORDER BY created_date DESC
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<select id="findFollowersByFollowIds" resultMap="BaseResultMap"> <select id="findFollowersByFollowIds" resultMap="BaseResultMap">
SELECT SELECT
follow_id, staff_name follow_id, staff_name
FROM merchant_bi_follow_detail FROM dj_merchant_bi_follow_detail
WHERE follow_id IN WHERE follow_id IN
<foreach collection="followIds" item="id" open="(" separator="," close=")"> <foreach collection="followIds" item="id" open="(" separator="," close=")">
#{id} #{id}
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<select id="findOneByFollowIdAndStaffUuid" resultMap="BaseResultMap"> <select id="findOneByFollowIdAndStaffUuid" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow_detail FROM dj_merchant_bi_follow_detail
WHERE follow_id = #{followId} WHERE follow_id = #{followId}
AND staff_uuid = #{staffUuid} AND staff_uuid = #{staffUuid}
AND deleted_flag = 'N' AND deleted_flag = 'N'
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<select id="findByFollowIdsAndStaffUuids" resultMap="BaseResultMap"> <select id="findByFollowIdsAndStaffUuids" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow_detail FROM dj_merchant_bi_follow_detail
WHERE follow_id IN WHERE follow_id IN
<foreach collection="followIds" item="id" open="(" separator="," close=")"> <foreach collection="followIds" item="id" open="(" separator="," close=")">
#{id} #{id}
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
<select id="findByFollowId" resultMap="BaseResultMap"> <select id="findByFollowId" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow_detail FROM dj_merchant_bi_follow_detail
WHERE follow_id = #{followId} WHERE follow_id = #{followId}
AND deleted_flag = 'N' AND deleted_flag = 'N'
</select> </select>
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<select id="findFollowByMerchantAndBiz" resultMap="BaseResultMap"> <select id="findFollowByMerchantAndBiz" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow FROM dj_merchant_bi_follow
WHERE merchant_id = #{merchantId} WHERE merchant_id = #{merchantId}
AND business_type = #{businessType} AND business_type = #{businessType}
AND deleted_flag = 'N' AND deleted_flag = 'N'
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
ELSE '未知' ELSE '未知'
END AS businessTypeName, END AS businessTypeName,
1 AS isFollow 1 AS isFollow
FROM merchant_bi_follow f FROM dj_merchant_bi_follow f
INNER JOIN merchant_bi_follow_detail d ON d.follow_id = f.id INNER JOIN dj_merchant_bi_follow_detail d ON d.follow_id = f.id
WHERE d.staff_uuid = #{staffUuid} WHERE d.staff_uuid = #{staffUuid}
AND f.deleted_flag = 'N' AND f.deleted_flag = 'N'
AND d.deleted_flag = 'N' AND d.deleted_flag = 'N'
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
END AS businessTypeName, END AS businessTypeName,
#{defaultIsFollow,jdbcType=INTEGER} AS isFollow, #{defaultIsFollow,jdbcType=INTEGER} AS isFollow,
MAX(d.created_date) AS followDate MAX(d.created_date) AS followDate
FROM merchant_bi_follow f FROM dj_merchant_bi_follow f
INNER JOIN merchant_bi_follow_detail d ON d.follow_id = f.id INNER JOIN dj_merchant_bi_follow_detail d ON d.follow_id = f.id
WHERE f.deleted_flag = 'N' WHERE f.deleted_flag = 'N'
AND d.deleted_flag = 'N' AND d.deleted_flag = 'N'
<if test="staffUuid != null and staffUuid != ''"> <if test="staffUuid != null and staffUuid != ''">
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
<select id="findByMerchantIds" resultMap="BaseResultMap"> <select id="findByMerchantIds" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow FROM dj_merchant_bi_follow
WHERE merchant_id IN WHERE merchant_id IN
<foreach collection="merchantIds" item="id" open="(" separator="," close=")"> <foreach collection="merchantIds" item="id" open="(" separator="," close=")">
#{id} #{id}
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
<select id="findByMerchantIdsAndBiz" resultMap="BaseResultMap"> <select id="findByMerchantIdsAndBiz" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow FROM dj_merchant_bi_follow
WHERE merchant_id IN WHERE merchant_id IN
<foreach collection="merchantIds" item="id" open="(" separator="," close=")"> <foreach collection="merchantIds" item="id" open="(" separator="," close=")">
#{id} #{id}
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
<select id="findFollowsByIds" resultMap="BaseResultMap"> <select id="findFollowsByIds" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow FROM dj_merchant_bi_follow
WHERE id IN WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{id}
...@@ -121,14 +121,14 @@ ...@@ -121,14 +121,14 @@
<select id="findAllActiveFollows" resultMap="BaseResultMap"> <select id="findAllActiveFollows" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow FROM dj_merchant_bi_follow
WHERE deleted_flag = 'N' WHERE deleted_flag = 'N'
</select> </select>
<select id="findByMinFollowCount" resultMap="BaseResultMap"> <select id="findByMinFollowCount" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM merchant_bi_follow FROM dj_merchant_bi_follow
WHERE follow_count >= #{minCount} WHERE follow_count >= #{minCount}
AND deleted_flag = 'N' AND deleted_flag = 'N'
</select> </select>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.peanalysis.mapper.StrategyInfoMapper"> <mapper namespace="cn.com.glsx.dj.peanalysis.mapper.StrategyInfoMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.peanalysis.model.StrategyInfo"> <resultMap id="BaseResultMap" type="cn.com.glsx.dj.strategy.model.StrategyInfo">
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="strategy_type" jdbcType="INTEGER" property="strategyType" /> <result column="strategy_type" jdbcType="INTEGER" property="strategyType" />
<result column="title" jdbcType="VARCHAR" property="title" /> <result column="title" jdbcType="VARCHAR" property="title" />
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<result column="merchant_name" jdbcType="VARCHAR" property="merchantName" /> <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
<result column="biz" jdbcType="INTEGER" property="biz" /> <result column="biz" jdbcType="INTEGER" property="biz" />
<result column="push_flag" jdbcType="INTEGER" property="pushFlag" /> <result column="push_flag" jdbcType="INTEGER" property="pushFlag" />
<result column="created_uuid" jdbcType="VARCHAR" property="createdUuid" /> <result column="created_uuid" jdbcType="VARCHAR" property="createdUUid" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
...@@ -30,18 +30,6 @@ ...@@ -30,18 +30,6 @@
deleted_flag, merchant_id, merchant_name, biz, push_flag, created_uuid deleted_flag, merchant_id, merchant_name, biz, push_flag, created_uuid
</sql> </sql>
<select id="findStrategyRecords" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM dj_smartcarlife.dj_car_life_strategy_info
WHERE merchant_id = #{merchantId}
<if test="biz != null">
AND biz = #{biz}
</if>
AND deleted_flag = 'N'
ORDER BY created_date DESC
</select>
<select id="findLatestStrategyRecords" resultMap="BaseResultMap"> <select id="findLatestStrategyRecords" resultMap="BaseResultMap">
SELECT t1.* FROM dj_smartcarlife.dj_car_life_strategy_info t1 SELECT t1.* FROM dj_smartcarlife.dj_car_life_strategy_info t1
INNER JOIN ( INNER JOIN (
...@@ -51,68 +39,28 @@ ...@@ -51,68 +39,28 @@
<foreach collection="merchantIds" item="id" open="(" separator="," close=")"> <foreach collection="merchantIds" item="id" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
<if test="biz != null"> <if test="businessType != null">
AND biz = #{biz} AND biz = #{businessType}
</if> </if>
AND deleted_flag = 'N' AND deleted_flag = 'N'
GROUP BY merchant_id <if test="startDate != null">
) t2 ON t1.merchant_id = t2.merchant_id AND t1.created_date = t2.max_date AND created_date &gt;= #{startDate}
WHERE t1.deleted_flag = 'N' </if>
</select> <if test="startDate != null">
AND created_date &lt;= #{endDate}
<select id="findLatestStrategyRecordsByTime" resultMap="BaseResultMap">
SELECT t1.* FROM dj_smartcarlife.dj_car_life_strategy_info t1
INNER JOIN (
SELECT merchant_id, MAX(created_date) as max_date
FROM dj_smartcarlife.dj_car_life_strategy_info
WHERE merchant_id IN
<foreach collection="merchantIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
<if test="biz != null">
AND biz = #{biz}
</if> </if>
AND deleted_flag = 'N'
AND created_date BETWEEN #{startDate} AND #{endDate}
GROUP BY merchant_id GROUP BY merchant_id
) t2 ON t1.merchant_id = t2.merchant_id AND t1.created_date = t2.max_date ) t2 ON t1.merchant_id = t2.merchant_id AND t1.created_date = t2.max_date
WHERE t1.deleted_flag = 'N' WHERE t1.deleted_flag = 'N'
<if test="biz != null"> <if test="businessType != null">
AND t1.biz = #{biz} AND t1.biz = #{businessType}
</if> </if>
AND t1.created_date BETWEEN #{startDate} AND #{endDate} <if test="startDate != null">
</select> AND created_date &gt;= #{startDate}
<select id="findStrategyCounts" resultMap="BaseResultMap">
SELECT merchant_id, COUNT(*) as id
FROM dj_smartcarlife.dj_car_life_strategy_info
WHERE merchant_id IN
<foreach collection="merchantIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
<if test="biz != null">
AND biz = #{biz}
</if> </if>
AND deleted_flag = 'N' <if test="startDate != null">
GROUP BY merchant_id AND created_date &lt;= #{endDate}
</select>
<select id="findStrategyCountAndLatestSummary" resultMap="BaseResultMap">
SELECT
merchant_id,
COUNT(*) AS id,
SUBSTRING_INDEX(GROUP_CONCAT(created_by ORDER BY created_date DESC, id DESC), ',', 1) AS created_by,
MAX(created_date) AS created_date
FROM dj_smartcarlife.dj_car_life_strategy_info
WHERE merchant_id IN
<foreach collection="merchantIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
<if test="biz != null">
AND biz = #{biz}
</if> </if>
AND deleted_flag = 'N'
GROUP BY merchant_id
</select> </select>
<select id="countStrategyByTime" resultType="java.lang.Integer"> <select id="countStrategyByTime" resultType="java.lang.Integer">
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.dj.peanalysis.mapper.StrategyStaffRelMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.peanalysis.model.StrategyStaffRel">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="strategy_id" jdbcType="INTEGER" property="strategyId" />
<result column="user_uuid" jdbcType="VARCHAR" property="userUuid" />
<result column="user_name" jdbcType="VARCHAR" property="userName" />
<result column="user_phone" jdbcType="VARCHAR" property="userPhone" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
<result column="deleted_flag" jdbcType="CHAR" property="deletedFlag" />
<result column="user_position" jdbcType="INTEGER" property="userPosition" />
<result column="beisen_userid" jdbcType="INTEGER" property="beisenUserId" />
</resultMap>
<sql id="Base_Column_List">
id, strategy_id, user_uuid, user_name, user_phone, created_by, created_date,
updated_by, updated_date, deleted_flag, user_position, beisen_userid
</sql>
<select id="findByStrategyId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM dj_smartcarlife.dj_car_life_strategy_staff_rel
WHERE strategy_id = #{strategyId}
AND deleted_flag = 'N'
</select>
<select id="findByStrategyIds" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM dj_smartcarlife.dj_car_life_strategy_staff_rel
WHERE strategy_id IN
<foreach collection="strategyIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND deleted_flag = 'N'
</select>
</mapper>
package cn.com.glsx.dj.peanalysis.service;
import cn.com.glsx.dj.peanalysis.dto.analysis.MerchantBiCommentReq;
import cn.com.glsx.dj.peanalysis.dto.analysis.StrategyRecordDTO;
import cn.com.glsx.dj.peanalysis.dto.analysis.StrategyRecordQryDTO;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collections;
import java.util.Map;
public class MerchantBiCommentServiceTest extends BaseServiceTest {
@Autowired
private MerchantBiCommentService commentService;
@Test
public void testComment() {
MerchantBiCommentReq req = MerchantBiCommentReq.builder()
.merchantId(123)
.merchantName("测试门店")
.businessType((byte) 1)
.staffUuid("test-uuid")
.staffName("测试员工")
.content("这是一条测试留言")
.handlerStaffUuid("handler-uuid")
.handlerStaffName("处理人")
.build();
// 新增
Boolean result = commentService.addComment(req);
Assert.assertTrue(result);
// 查询条数
req.setMerchantIds(Collections.singletonList(123));
Map<Integer, Integer> counts = commentService.findCommentCounts(req);
Assert.assertTrue(counts.get(123) > 0);
// 合并记录查询
RpcPagination<StrategyRecordQryDTO> paginationReq = new RpcPagination<>();
paginationReq.setPageNum(1);
paginationReq.setPageSize(10);
StrategyRecordQryDTO qry = new StrategyRecordQryDTO();
qry.setMerchantId(123);
qry.setBusinessType((byte) 1);
paginationReq.setCondition(qry);
RpcPagination<StrategyRecordDTO> combinedRecords = commentService.findCombinedRecords(paginationReq, "test-uuid");
Assert.assertNotNull(combinedRecords.getList());
Assert.assertTrue(combinedRecords.getList().size() > 0);
Integer strategyId = combinedRecords.getList().get(0).getId();
// 详情
StrategyRecordDTO detail = commentService.getStrategyDetail(strategyId, 7);
Assert.assertNotNull(detail);
Assert.assertEquals("这是一条测试留言", detail.getContent());
// 撤回
commentService.withdrawComment(strategyId, "test-uuid");
combinedRecords = commentService.findCombinedRecords(paginationReq, "test-uuid");
Assert.assertTrue(combinedRecords.getList().stream().noneMatch(c -> c.getId().equals(strategyId)));
}
}
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的软件开发工程师。

    你提交的代码进行了较大规模的重构,包括将策略模块抽离为独立依赖、优化了部分查询逻辑以及规范了入参结构。整体方向符合模块化和解耦的趋势,提交信息也非常规范。

    但在审查中发现违反了“MyBatis SQL禁用子查询”的明确规则,同时存在分布式事务处理不当和测试用例缺失的风险。

    以下是本次审查的 Top 3 关键问题及优化建议:

    一、关键问题与优化建议

    1. 违反 SQL 开发规范(禁止子查询)

    • 问题描述:在 StrategyInfoMapper.xml 的 findLatestStrategyRecords 方法中,使用了 INNER JOIN (SELECT ... GROUP BY ...) 的派生表子查询来获取每个门店的最新记录。这直接违反了本次审查规则中“MyBatis SQL 中不允许使用子查询”的要求。
    • 影响分析:子查询(尤其是派生表)在数据量大时可能导致临时表创建,影响数据库性能。此外,若存在多条记录 created_date 完全一致,该 SQL 会导致笛卡尔积,返回多条重复数据。
    • 优化建议:

      • 方案 A(推荐,Java 处理):SQL 仅负责根据时间范围和门店 ID 批量查询出所有符合条件的记录(按 created_date DESC 排序),然后在 Java 层通过 Stream 流进行分组去重(取第一条)。
      • 方案 B(如果数据量极大):如果担心一次查出数据过多,建议分批查询或仅查询 ID 列表,再回表查询详情。
      • 代码示例(方案 A): ```java // 1. Mapper XML 改为普通查询,按时间倒序 // SELECT * FROM ... WHERE ... ORDER BY created_date DESC

      // 2. Java Service 层处理 List allRecords = strategyInfoMapper.findStrategyRecords(req); Map latestMap = allRecords.stream() .collect(Collectors.toMap( StrategyInfo::getMerchantId, Function.identity(), (v1, v2) -> v1 // 因为已排序,保留第一个即为最新 ));

    2. 事务中包含 RPC/网络请求(稳定性风险)

    • 问题描述:在 MerchantBiCommentService.addComment 方法中,@Transactional 注解覆盖了整个方法,而方法内部调用了 wechatPushService.pushMentionMsg(...)。
    • 影响分析:企微推送属于外部网络请求(RPC 或 HTTP)。如果网络抖动或第三方响应缓慢,会导致数据库事务长时间未提交,占用数据库连接池资源,严重时可能引发“雪崩”效应,拖垮整个服务。
    • 优化建议:将消息推送逻辑移出数据库事务,或使用事务同步管理器在事务提交后执行。
    • 代码示例:

      // 引入 spring-tx 包中的 TransactionSynchronizationManager
      @Transactional(rollbackFor = Exception.class)
      public Boolean addComment(MerchantBiCommentReq request) {
          // ... 数据库 insert 操作 ...
      
          // 注册事务提交后的钩子
          TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
              @Override
              public void afterCommit() {
                  try {
                      wechatPushService.pushMentionMsg(...);
                  } catch (Exception e) {
                      log.error("推送消息失败", e);
                  }
              }
          });
          return true;
      }
      

    3. 删除测试用例导致回归测试缺失(工程质量)

    • 问题描述:你删除了 MerchantBiCommentServiceTest.java 文件,且未提交新的测试类。虽然业务逻辑发生了重构(如 StrategyInfo 迁移),但业务的核心功能(新增留言、查询动态)依然存在。
    • 影响分析:直接删除测试文件会导致该核心模块失去自动化回归测试的保护。后续维护人员在修改代码时,极易引入未知的 Bug。
    • 优化建议:请勿直接删除测试文件。应根据新的 Service 逻辑和依赖(cn.com.glsx.dj.strategy),修复并更新单元测试用例,确保核心路径(新增、查询)的测试覆盖率。

    二、评分明细

    评分维度 得分 理由
    功能实现的正确性与健壮性 (40分) 25 严重扣分项:违反了明确的 SQL 禁用子查询规则;Java 层逻辑基本通顺,但 addComment 中对外部 Jar 包对象的 Setter 方法调用需仔细核对(如 setCreatedUUid 大小写问题)。
    安全性与潜在风险 (30分) 20 存在事务中调用 RPC 的稳定性风险(可能导致资源耗尽);未发现明显的 SQL 注入风险(使用了 <foreach> 和 #{})。
    最佳实践与可维护性 (20分) 10 删除了单元测试文件,严重影响可维护性;代码结构优化较好(如将处理人改为 List),命名规范。
    性能与资源利用 (5分) 4 整体性能尚可,但子查询和事务内 RPC 存在性能隐患。
    提交信息质量 (5分) 5 Commit Message 格式清晰,使用了 Conventional Commits 规范,描述准确。

    总分:64分

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