Commit 85a3fd1d by 杨卫

feat:自测提交

1 parent 7aaa86b5
package cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignRecord;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
import java.util.List;
/**
* @ClassName StaffAccountAssignRecordDTO
* @Description 员工账号信息dto(V2)
*/
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
@Data
public class StaffAccountAssignRecordDTO extends StaffAccountAssignRecord implements Serializable {
private static final long serialVersionUID = -1076817041756853438L;
@ApiModelProperty(notes = "导师姓名")
private String mentorName;
@ApiModelProperty(notes = "导师手机号")
private String mentorPhone;
@ApiModelProperty(notes = "一级车型名称")
private String carBrand;
@ApiModelProperty(notes = "删除标识list")
private List<String> deletedFlagList;
/**
* 园区店商户号list
*/
private List<Integer> yqMerchantIdList;
@ApiModelProperty(notes = "适配业务字符串,多个以、分隔,无适配业务则为null")
private String accountSceneStr;
@ApiModelProperty(notes = "驻店类型描述")
private String stationTypeDesc;
}
package cn.com.glsx.dj.smartcarlife.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
@Data
@Table(name = "dj_car_life_staff_account_assign_record")
public class StaffAccountAssignRecord implements Serializable {
private static final long serialVersionUID = 5366576995446233440L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
/**
* 员工uuid
*/
@Column(name = "staff_uuid")
private String staffUuid;
/**
* 驻店员工手机号
*/
@Column(name = "staff_phone")
private String staffPhone;
/**
* 职级类型(0:实习生(理论),1:实习生(实践),2:初级驻店,3:中级驻店,4:高级驻店,5:小店长,6:大店长,7:初级区域督导,8:中级区域督导,9:高级区域督导)
*/
@Column(name = "job_type")
private Byte jobType;
/**
* 员工业务标签
*/
@Column(name = "staff_scene_label")
private String staffSceneLabel;
/**
* 初始归属门店商户号
*/
@Column(name = "merchant_id")
private Integer merchantId;
/**
* 初始归属门店商户名称
*/
@Column(name = "merchant_name")
private String merchantName;
/**
* 归属园区店商户号
*/
@Column(name = "yq_merchant_id")
private Integer yqMerchantId;
/**
* 归属园区店商户名称
*/
@Column(name = "yq_merchant_name")
private String yqMerchantName;
/**
* 创建来源 (1:账户中心,2:SCRM,3:生意助手,4:门店助手,5:D+,6:生意助手员工版小程序)
*/
@Column(name = "created_source")
private Byte createdSource;
/**
* 创建人
*/
@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;
/**
* 驻店类型(1:门店常驻, 2:临时调动支援)
*/
@Column(name = "station_type")
private Byte stationType;
/**
* 删除标识(D:已删除;N:未删除;I:禁用)
*/
@Column(name = "deleted_flag")
private String deletedFlag;
}
package cn.com.glsx.dj.smartcarlife.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@ToString(callSuper = true)
@Data
@Table(name = "dj_car_life_staff_account_assign_scene")
public class StaffAccountAssignScene implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* dj_car_life_staff_account_assign_record表id
*/
@Column(name = "account_record_id")
private Integer accountRecordId;
/**
* 场景标识
*/
@Column(name = "base_scene_code")
private String baseSceneCode;
/**
* 原来的场景
*/
@Column(name = "scene_type")
private Byte sceneType;
/**
* 删除标识(D:已删除;N:未删除)
*/
@Column(name = "deleted_flag")
private String deletedFlag;
/**
* 创建人
*/
@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;
}
package cn.com.glsx.dj.smartcarlife.mapper;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountAssignRecordDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountStatusNumDTO;
import cn.com.glsx.dj.smartcarlife.dto.staff.StaffMerchantInfoDTO;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.Date;
import java.util.List;
@Mapper
public interface StaffAccountAssignRecordMapper extends OreMapper<StaffAccountAssignRecord> {
List<StaffAccountStatusNumDTO> countStaffAccountAssignRecordByPhone(@Param("phoneNumber") String phoneNumber);
void updateAccountAssignDeleteFlag(StaffAccountAssignRecord accountRecord);
int countDeleteAccountAssignNumByPhone(@Param("staffPhone") String staffPhone);
StaffAccountAssignRecord selectLatestStaffAccountAssignInfo(StaffAccountAssignRecord accountRecord);
List<StaffMerchantInfoDTO> listAllYqMerchantInfoByStaffPhone(@Param("staffPhone") String staffPhone);
List<StaffAccountAssignRecordDTO> listStaffAccountAssignRecord(StaffAccountAssignRecordDTO staffAccountAssignRecordDTO);
List<String> queryStaffYqMerchantAssignScene(@Param("staffPhone") String staffPhone, @Param("yqMerchantId") Integer yqMerchantId);
List<String> searchStaffYqMerchantAssignScene(@Param("staffPhone") String staffPhone, @Param("yqMerchantId") Integer yqMerchantId, @Param("sceneType") Integer sceneType, @Param("merchantId") Integer merchantId);
int batchUpdateDeleteFlagByPhoneAndYqMerchant(@Param("staffPhone") String staffPhone, @Param("yqMerchantId") Integer yqMerchantId, @Param("deletedFlag") String deletedFlag, @Param("updatedBy") String updatedBy, @Param("updatedDate") Date updatedDate);
int cleanInvalidAccountAssignScene();
}
package cn.com.glsx.dj.smartcarlife.mapper;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignScene;
import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
@Mapper
public interface StaffAccountAssignSceneMapper extends OreMapper<StaffAccountAssignScene> {
}
...@@ -460,8 +460,11 @@ public class StaffBaseInfoRemoteImpl implements StaffBaseInfoRemote { ...@@ -460,8 +460,11 @@ public class StaffBaseInfoRemoteImpl implements StaffBaseInfoRemote {
try { try {
staffBaseInfoService.assignStaffMerchantV2(dto); staffBaseInfoService.assignStaffMerchantV2(dto);
return RpcResponse.success("分配成功"); return RpcResponse.success("分配成功");
} catch (RpcServiceException e) {
log.error("员工基础账号分配门店V2异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) { } catch (Exception e) {
log.error("员工基础账号分配门店V2异常: {}", e.getMessage(), e); log.error("员工基础账号分配门店V2异常: ", e);
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
......
...@@ -45,6 +45,7 @@ import cn.com.glsx.scrm.proxy.model.ProxyBaseResponse; ...@@ -45,6 +45,7 @@ import cn.com.glsx.scrm.proxy.model.ProxyBaseResponse;
import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse; import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse;
import cn.com.glsx.scrm.proxy.remote.CommonProxyRemote; import cn.com.glsx.scrm.proxy.remote.CommonProxyRemote;
import cn.com.glsx.scrm.proxy.remote.merchant.MerchantRemote; import cn.com.glsx.scrm.proxy.remote.merchant.MerchantRemote;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -2148,9 +2149,9 @@ public class SceneMerchantRefService { ...@@ -2148,9 +2149,9 @@ public class SceneMerchantRefService {
for (Map.Entry<Integer, List<SceneMerchantRefNew>> yqEntry : yqGroup.entrySet()) { for (Map.Entry<Integer, List<SceneMerchantRefNew>> yqEntry : yqGroup.entrySet()) {
YqMerchant4sSceneDTO yqDto = new YqMerchant4sSceneDTO(); YqMerchant4sSceneDTO yqDto = new YqMerchant4sSceneDTO();
yqDto.setYqMerchantId(yqEntry.getKey()); yqDto.setYqMerchantId(yqEntry.getKey());
List<SceneMerchantRefNew> yqItems = yqEntry.getValue(); List<SceneMerchantRefNew> yqItems = Optional.ofNullable(yqEntry.getValue()).orElse(Lists.newArrayList());
// 园区店名称取第一条 // 园区店名称取第一条
yqDto.setYqMerchantName(yqItems.get(0).getSubMerchantName()); yqDto.setYqMerchantName(Optional.of(yqItems).filter(r -> !r.isEmpty()).map(r -> r.get(0).getSubMerchantName()).orElse(StrUtil.EMPTY));
// 第二级: 按4s店(shopMerchantId = mainMerchantId)分组 // 第二级: 按4s店(shopMerchantId = mainMerchantId)分组
Map<Integer, List<SceneMerchantRefNew>> shopGroup = yqItems.stream() Map<Integer, List<SceneMerchantRefNew>> shopGroup = yqItems.stream()
.filter(r -> r.getMainMerchantId() != null) .filter(r -> r.getMainMerchantId() != null)
...@@ -2159,9 +2160,9 @@ public class SceneMerchantRefService { ...@@ -2159,9 +2160,9 @@ public class SceneMerchantRefService {
for (Map.Entry<Integer, List<SceneMerchantRefNew>> shopEntry : shopGroup.entrySet()) { for (Map.Entry<Integer, List<SceneMerchantRefNew>> shopEntry : shopGroup.entrySet()) {
YqMerchant4sSceneDTO.ShopSceneDTO shopDto = new YqMerchant4sSceneDTO.ShopSceneDTO(); YqMerchant4sSceneDTO.ShopSceneDTO shopDto = new YqMerchant4sSceneDTO.ShopSceneDTO();
shopDto.setShopMerchantId(shopEntry.getKey()); shopDto.setShopMerchantId(shopEntry.getKey());
List<SceneMerchantRefNew> shopItems = shopEntry.getValue(); List<SceneMerchantRefNew> shopItems = Optional.ofNullable(shopEntry.getValue()).orElse(Lists.newArrayList());
// 4s店名称取第一条 // 4s店名称取第一条
shopDto.setShopMerchantName(shopItems.get(0).getMainMerchantName()); shopDto.setShopMerchantName(Optional.of(shopItems).filter(r -> !r.isEmpty()).map(r -> r.get(0).getMainMerchantName()).orElse(StrUtil.EMPTY));
// 场景列表 // 场景列表
Map<String, String> finalSceneNameMap = sceneNameMap; Map<String, String> finalSceneNameMap = sceneNameMap;
List<YqMerchant4sSceneDTO.SceneDetailDTO> sceneList = shopItems.stream().map(item -> { List<YqMerchant4sSceneDTO.SceneDetailDTO> sceneList = shopItems.stream().map(item -> {
......
<?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.smartcarlife.mapper.StaffAccountAssignRecordMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignRecord" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="staff_uuid" property="staffUuid" jdbcType="VARCHAR" />
<result column="staff_phone" property="staffPhone" jdbcType="VARCHAR" />
<result column="job_type" property="jobType" jdbcType="TINYINT" />
<result column="staff_scene_label" property="staffSceneLabel" jdbcType="VARCHAR" />
<result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
<result column="merchant_name" property="merchantName" jdbcType="VARCHAR" />
<result column="yq_merchant_id" property="yqMerchantId" jdbcType="INTEGER" />
<result column="yq_merchant_name" property="yqMerchantName" jdbcType="VARCHAR" />
<result column="created_source" property="createdSource" jdbcType="TINYINT" />
<result column="station_type" property="stationType" jdbcType="TINYINT" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
</resultMap>
<resultMap id="AccountRecordStatusMap" type="cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountStatusNumDTO">
<result column="deleted_flag" property="deletedFlag" jdbcType="VARCHAR" />
<result column="num" property="accountStatusNum" jdbcType="INTEGER" />
</resultMap>
<resultMap id="StaffMerchantInfoMap" type="cn.com.glsx.dj.smartcarlife.dto.staff.StaffMerchantInfoDTO">
<result column="staff_phone" property="staffPhone" jdbcType="VARCHAR" />
<result column="yq_merchant_id" property="merchantId" jdbcType="INTEGER" />
<result column="yq_merchant_name" property="merchantName" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="DTOResultMap" type="cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountAssignRecordDTO" extends="BaseResultMap">
</resultMap>
<sql id="Base_Column_List" >
id, staff_uuid, staff_phone, job_type, staff_scene_label, merchant_id, merchant_name, yq_merchant_id, yq_merchant_name, created_source, station_type,
created_by, created_date, updated_by, updated_date, deleted_flag
</sql>
<update id="updateAccountAssignDeleteFlag" parameterType="cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignRecord">
update dj_car_life_staff_account_assign_record sar
set sar.deleted_flag = #{deletedFlag,jdbcType=VARCHAR},
sar.updated_by = #{updatedBy,jdbcType=VARCHAR},
sar.updated_date = #{updatedDate,jdbcType=TIMESTAMP}
where sar.staff_phone = #{staffPhone,jdbcType=VARCHAR}
<if test="yqMerchantId != null">
and sar.yq_merchant_id = #{yqMerchantId,jdbcType=INTEGER}
</if>
and sar.deleted_flag <![CDATA[<>]]> 'D'
</update>
<select id="countStaffAccountAssignRecordByPhone" parameterType="java.lang.String" resultMap="AccountRecordStatusMap">
select sar.deleted_flag, count(1) as num
from dj_car_life_staff_account_assign_record sar
where sar.staff_phone = #{phoneNumber,jdbcType=VARCHAR}
group by sar.deleted_flag
</select>
<select id="countDeleteAccountAssignNumByPhone" parameterType="java.lang.String" resultType="java.lang.Integer">
SELECT COUNT(1) - COUNT(CASE WHEN deleted_flag = 'D' THEN 1 END) AS difference
FROM dj_car_life_staff_account_assign_record
WHERE staff_phone = #{staffPhone,jdbcType=VARCHAR}
</select>
<select id="selectLatestStaffAccountAssignInfo" parameterType="cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignRecord" resultMap="BaseResultMap">
select id, staff_uuid, staff_phone, job_type, staff_scene_label, merchant_id, merchant_name, yq_merchant_id, yq_merchant_name, created_source,
created_by, created_date, updated_by, updated_date, deleted_flag
from dj_car_life_staff_account_assign_record sar
where sar.staff_phone = #{staffPhone,jdbcType=VARCHAR}
<if test="yqMerchantId != null">
and sar.yq_merchant_id <![CDATA[<>]]> #{yqMerchantId,jdbcType=INTEGER}
and sar.deleted_flag <![CDATA[<>]]> 'D'
</if>
order by sar.id desc
limit 1
</select>
<select id="listAllYqMerchantInfoByStaffPhone" parameterType="java.lang.String" resultMap="StaffMerchantInfoMap">
select sar.staff_phone, sar.yq_merchant_id, sar.yq_merchant_name
from dj_car_life_staff_account_assign_record sar
where sar.staff_phone = #{staffPhone,jdbcType=VARCHAR}
and sar.deleted_flag = 'N'
</select>
<select id="listStaffAccountAssignRecord" parameterType="cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountAssignRecordDTO" resultMap="DTOResultMap">
select
<include refid="Base_Column_List"/>
from dj_car_life_staff_account_assign_record
<where>
<if test="deletedFlagList != null and deletedFlagList.size() != 0 ">
and deleted_flag in
<foreach close=")" collection="deletedFlagList" index="index" item="item" open="(" separator=",">
#{item}
</foreach>
</if>
<if test="staffPhone != null and staffPhone != ''">
and staff_phone = #{staffPhone,jdbcType=VARCHAR}
</if>
<if test="yqMerchantId != null">
and yq_merchant_id = #{yqMerchantId,jdbcType=INTEGER}
</if>
<if test="merchantId != null">
and merchant_id = #{merchantId,jdbcType=INTEGER}
</if>
<if test="yqMerchantIdList != null and yqMerchantIdList.size() != 0 ">
and yq_merchant_id in
<foreach close=")" collection="yqMerchantIdList" index="index" item="item" open="(" separator=",">
#{item}
</foreach>
</if>
</where>
</select>
<select id="queryStaffYqMerchantAssignScene" resultType="java.lang.String">
SELECT
distinct ss.base_scene_code
FROM dj_car_life_staff_account_assign_record sr
INNER JOIN dj_car_life_staff_account_assign_scene ss ON sr.id = ss.account_record_id
WHERE sr.staff_phone = #{staffPhone,jdbcType=VARCHAR}
<if test="yqMerchantId != null">
AND sr.yq_merchant_id = #{yqMerchantId,jdbcType=INTEGER}
</if>
AND sr.deleted_flag = 'N'
AND ss.deleted_flag = 'N'
</select>
<select id="searchStaffYqMerchantAssignScene" resultType="java.lang.String">
SELECT
distinct ss.base_scene_code
FROM dj_car_life_staff_account_assign_record sr
INNER JOIN dj_car_life_staff_account_assign_scene ss ON sr.id = ss.account_record_id
<where>
<if test="staffPhone != null and staffPhone != ''">
and sr.staff_phone = #{staffPhone,jdbcType=VARCHAR}
</if>
<if test="yqMerchantId != null">
AND sr.yq_merchant_id = #{yqMerchantId,jdbcType=INTEGER}
</if>
<if test="merchantId != null">
AND sr.merchant_id = #{merchantId,jdbcType=INTEGER}
</if>
<if test="sceneType != null">
AND ss.scene_type = #{sceneType}
</if>
AND sr.deleted_flag = 'N'
AND ss.deleted_flag = 'N'
</where>
</select>
<update id="batchUpdateDeleteFlagByPhoneAndYqMerchant">
UPDATE dj_car_life_staff_account_assign_record
SET deleted_flag = #{deletedFlag,jdbcType=VARCHAR},
updated_by = #{updatedBy,jdbcType=VARCHAR},
updated_date = #{updatedDate,jdbcType=TIMESTAMP}
WHERE staff_phone = #{staffPhone,jdbcType=VARCHAR}
AND yq_merchant_id = #{yqMerchantId,jdbcType=INTEGER}
AND deleted_flag <![CDATA[<>]]> 'D'
</update>
<update id="cleanInvalidAccountAssignScene">
UPDATE dj_car_life_staff_account_assign_scene ss
INNER JOIN dj_car_life_staff_account_assign_record sr ON ss.account_record_id = sr.id
SET ss.deleted_flag = 'D', ss.updated_date = NOW()
WHERE ss.deleted_flag = 'N'
AND NOT EXISTS (
SELECT 1 FROM dj_car_life_scene_merchant_ref_new ref
WHERE ref.main_merchant_id = sr.merchant_id
AND ref.base_scene_code = ss.base_scene_code
AND ref.main_merchant_type = 2
AND ref.deleted_flag = 'N'
AND ref.status = 1
)
</update>
<select id="searchAssignStaffYqMerchantScene" resultType="java.lang.String">
SELECT
distinct ss.base_scene_code
FROM dj_car_life_staff_account_assign_record sr
INNER JOIN dj_car_life_staff_account_assign_scene ss ON sr.id = ss.account_record_id
<where>
<if test="staffPhone != null and staffPhone != ''">
and sr.staff_phone = #{staffPhone,jdbcType=VARCHAR}
</if>
<if test="yqMerchantId != null">
AND sr.yq_merchant_id = #{yqMerchantId,jdbcType=INTEGER}
</if>
<if test="merchantId != null">
AND sr.merchant_id = #{merchantId,jdbcType=INTEGER}
</if>
<if test="sceneType != null">
AND ss.scene_type = #{sceneType}
</if>
AND sr.deleted_flag = 'N'
AND ss.deleted_flag = 'N'
</where>
</select>
</mapper>
<?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.smartcarlife.mapper.StaffAccountAssignSceneMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignScene" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="account_record_id" property="accountRecordId" jdbcType="INTEGER" />
<result column="base_scene_code" property="baseSceneCode" jdbcType="VARCHAR" />
<result column="scene_type" property="sceneType" jdbcType="TINYINT" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, account_record_id, base_scene_code, scene_type, deleted_flag,
created_by, created_date, updated_by, updated_date
</sql>
</mapper>
  • @wangxw1
    commented
    Master

    这是一份针对您提交代码的专业审查报告。本次审查严格依据您提供的目标与评分权重,并特别关注了MyBatis子查询及Dubbo接口兼容性等核心规则。

    一、关键问题与优化建议(Top 3)

    1. 严重违规:MyBatis SQL 语句中使用了子查询(违反重要规则)

    • 问题描述:在 StaffAccountAssignRecordMapper.xml 的 cleanInvalidAccountAssignScene 方法中,使用了 NOT EXISTS (SELECT 1 FROM ...) 的子查询结构。
    • 影响分析:违反了“MyBatis的SQL语句不允许使用子查询”的硬性工程规范。在 MySQL 中,NOT EXISTS 等子查询在某些复杂场景或数据量增大时,容易导致执行计划走偏,引发慢 SQL,影响数据库整体性能与稳定性。
    • 优化建议:使用 LEFT JOIN 结合 IS NULL 来替代子查询进行改写。 xml <update id="cleanInvalidAccountAssignScene"> UPDATE dj_car_life_staff_account_assign_scene ss INNER JOIN dj_car_life_staff_account_assign_record sr ON ss.account_record_id = sr.id LEFT JOIN dj_car_life_scene_merchant_ref_new ref ON ref.main_merchant_id = sr.merchant_id AND ref.base_scene_code = ss.base_scene_code AND ref.main_merchant_type = 2 AND ref.deleted_flag = 'N' AND ref.status = 1 SET ss.deleted_flag = 'D', ss.updated_date = NOW() WHERE ss.deleted_flag = 'N' AND ref.main_merchant_id IS NULL </update>

    2. 接口破坏性变更:Dubbo 请求参数结构变更(违反重要规则)

    • 问题描述:在 AssignStaffMerchantV2DTO.java 中,直接删除了原有的 baseSceneCodeList 字段,并将其修改为 sceneList (List);同时将 stationType 从 ShopItem 移动到了 FourSShopItem 中。
    • 影响分析:违反了“Dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的规则。这属于破坏性变更(Breaking Change),未升级的服务消费者如果继续传递旧的 JSON/对象结构,会导致服务端反序列化丢失数据(如丢失场景列表和驻店类型),直接引发线上业务逻辑错误。
    • 优化建议:对于 Dubbo 接口的入参,只能新增字段,严禁修改或删除原有字段。
      • 方案A:保留原字段并标记 @Deprecated,在业务代码中兼容处理新老字段的数据。
      • 方案B(推荐):新建 AssignStaffMerchantV3DTO,并在 Remote 接口中提供 V3 版本的服务方法,让消费者平滑迁移。

    3. 性能瓶颈:在循环中执行数据库查询(N+1 查询问题)

    • 问题描述:在 StaffAccountRecordService.java 的 listStaffAccountRecordsGrouped 和 getStaffAccountRecordDetail 方法中,在遍历 4S 店列表的 for 循环内部,调用了 staffAccountAssignSceneMapper.select(sceneQuery) 和 sceneService.getScenesByParams。
    • 影响分析:典型的 N+1 查询性能问题。随着员工关联的 4S 店数量增加,单次 RPC 请求会衍生出大量的数据库查询操作,极大地消耗数据库连接池资源,导致接口响应时间呈线性甚至指数级上升。
    • 优化建议:将循环内的查询提取到循环外部,进行批量查询,然后在内存中进行数据组装。 java // 优化思路示例: // 1. 收集所有的 accountRecordId List<Integer> recordIds = allRecords.stream().map(StaffAccountRecordDTO::getId).collect(Collectors.toList()); // 2. 批量查询所有相关的 Scene List<StaffAccountAssignScene> allScenes = staffAccountAssignSceneMapper.selectByRecordIds(recordIds); // 需在Mapper新增批量查询方法 // 3. 按 accountRecordId 在内存中分组 Map<Integer, List<StaffAccountAssignScene>> sceneGroupMap = allScenes.stream().collect(Collectors.groupingBy(StaffAccountAssignScene::getAccountRecordId)); // 4. 在 for 循环中直接从 Map 中获取数据,消除循环内 IO

    二、评分明细

    • 功能实现的正确性与健壮性(30/40分): 扣分原因:Dubbo DTO 参数的直接修改破坏了向下兼容性,可能导致老版本客户端调用时发生功能性故障。代码在空指针防御方面(如 Optional 的使用)做得较好。
    • 安全性与潜在风险(30/30分): 未发现明显的 SQL 注入、越权或敏感信息泄露等安全漏洞。MyBatis 变量均使用了 #{} 安全绑定。
    • 最佳实践与可维护性(10/20分): 扣分原因:严重违反了项目规范中“MyBatis禁止使用子查询”的硬性规定。此外,DTO 类的层级嵌套过深且职责开始变得复杂,不利于后续维护。
    • 性能与资源利用(0/5分): 扣分原因:Service 层中存在严重的 for 循环内查库(N+1)现象,对高并发场景下的系统资源(DB连接、网络IO)造成极大浪费。
    • 提交信息质量(4/5分): 提交信息 feat:账户分配场景精确到4s店维度 清晰表达了业务意图,但附加的 feat:自测提交 属于无效信息,建议保持 Commit 历史的纯净度。

    总分:74分

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