Commit 90af5d15 by 杨卫

Merge remote-tracking branch 'origin/v5.8.1_yw' into v5.8.1

2 parents 31f445a9 85a3fd1d
Showing 26 changed files with 1351 additions and 4 deletions
......@@ -66,5 +66,8 @@ public class AssignStaffMerchantDTO implements Serializable {
@ApiModelProperty(notes = "园区店商户号")
private Integer yqMerchantId;
@ApiModelProperty(notes = "驻店类型(1:门店常驻, 2:临时调动支援)")
private Byte stationType;
}
}
package cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* @ClassName AssignStaffMerchantV2DTO
* @Description 员工基础账号分配门店V2 DTO
*/
@Data
@ToString
public class AssignStaffMerchantV2DTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "员工基础信息id")
private Integer staffId;
@ApiModelProperty(notes = "员工手机号")
private String staffPhone;
@ApiModelProperty(notes = "员工姓名")
private String staffName;
@ApiModelProperty(notes = "操作人")
private String operatorBy;
@ApiModelProperty(notes = "创建来源(1:账户中心,2:SCRM,3:生意助手,4:门店助手,5:服务商saas,6:D+,7:生意助手员工版小程序,8:北森同步)")
private Byte createdSource;
@ApiModelProperty(notes = "园区店列表")
private List<ShopItem> shopItemList;
@ApiModelProperty(notes = "是否编辑标识(true:编辑, false:新增)")
private Boolean editFlag;
/**
* 园区店项(园区店+4s店列表)
*/
@Data
@ToString
public static class ShopItem implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "园区店商户号")
private Integer yqMerchantId;
@ApiModelProperty(notes = "园区店名称")
private String yqMerchantName;
@ApiModelProperty(notes = "4s店列表")
private List<FourSShopItem> fourSShopList;
}
/**
* 4s店项(4s店+驻店类型+场景列表)
*/
@Data
@ToString
public static class FourSShopItem implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "4s店商户号")
private Integer merchantId;
@ApiModelProperty(notes = "4s店名称")
private String merchantName;
@ApiModelProperty(notes = "驻店类型(1:门店常驻, 2:临时调动支援)")
private Byte stationType;
@ApiModelProperty(notes = "业务场景列表")
private List<SceneItem> sceneList;
}
/**
* 场景项(场景标识+原来的场景)
*/
@Data
@ToString
public static class SceneItem implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "场景标识", required = true)
private String baseSceneCode;
@ApiModelProperty(notes = "原来的场景(scene_type)")
private Byte sceneType;
}
}
......@@ -41,4 +41,7 @@ public class SingleAssignStaffMerchantDTO implements Serializable {
@ApiModelProperty(notes = "创建来源(1:账户中心,2:SCRM,3:生意助手,4:门店助手,5:服务商saas,6:D+,7:生意助手员工版小程序,8:北森同步)")
private Byte createdSource;
@ApiModelProperty(notes = "驻店类型(1:门店常驻, 2:临时调动支援)")
private Byte stationType;
}
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;
}
......@@ -76,4 +76,7 @@ public class StaffAccountRecordDTO extends StaffAccountRecord implements Seriali
@ApiModelProperty(notes = "适配业务字符串,多个以“、”分隔,无适配业务则为null")
private String accountSceneStr;
@ApiModelProperty(notes = "驻店类型描述")
private String stationTypeDesc;
}
package cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import cn.com.glsx.dj.smartcarlife.dto.scene.SceneDTO;
/**
* @ClassName StaffAccountRecordDetailDTO
* @Description 编辑园区店数据回显 DTO(园区店维度聚合:园区店→4s店列表→场景列表)
*/
@Data
@ToString
public class StaffAccountRecordDetailDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "员工手机号")
private String staffPhone;
@ApiModelProperty(notes = "园区店商户号")
private Integer yqMerchantId;
@ApiModelProperty(notes = "园区店名称")
private String yqMerchantName;
@ApiModelProperty(notes = "4s店列表")
private List<FourSShopDetailItem> fourSShopList;
/**
* 4s店详情项(4s店+驻店类型+场景列表)
*/
@Data
@ToString
public static class FourSShopDetailItem implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "账号记录id")
private Integer accountRecordId;
@ApiModelProperty(notes = "4s店商户号")
private Integer merchantId;
@ApiModelProperty(notes = "4s店名称")
private String merchantName;
@ApiModelProperty(notes = "驻店类型(1:门店常驻, 2:临时调动支援)")
private Byte stationType;
@ApiModelProperty(notes = "业务场景列表")
private List<SceneDTO> sceneList;
@ApiModelProperty(notes = "创建时间")
private Date createdDate;
@ApiModelProperty(notes = "创建人")
private String createdBy;
@ApiModelProperty(notes = "删除标识")
private String deletedFlag;
}
}
\ No newline at end of file
package cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* @ClassName YqMerchant4sSceneDTO
* @Description 园区店下4s店及业务场景 DTO(两次聚合)
*/
@Data
@ToString
public class YqMerchant4sSceneDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "园区店商户号")
private Integer yqMerchantId;
@ApiModelProperty(notes = "园区店名称")
private String yqMerchantName;
@ApiModelProperty(notes = "4s店列表")
private List<ShopSceneDTO> shopList;
/**
* 4s店维度聚合
*/
@Data
@ToString
public static class ShopSceneDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "4s店商户号")
private Integer shopMerchantId;
@ApiModelProperty(notes = "4s店名称")
private String shopMerchantName;
@ApiModelProperty(notes = "场景列表")
private List<SceneDetailDTO> sceneList;
}
/**
* 场景详情
*/
@Data
@ToString
public static class SceneDetailDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "场景标识")
private String baseSceneCode;
@ApiModelProperty(notes = "场景值")
private String scene;
@ApiModelProperty(notes = "场景名称")
private String sceneName;
@ApiModelProperty(notes = "原来的场景(scene_type)")
private Byte sceneType;
@ApiModelProperty(notes = "所属园区店商户号")
private Integer yqMerchantId;
@ApiModelProperty(notes = "所属园区店名称")
private String yqMerchantName;
}
}
......@@ -22,6 +22,12 @@ public class SceneQueryFilterDTO implements Serializable {
private Integer yqMerchantId;
/**
* 4s店商户号
*/
@ApiModelProperty(notes = "4s店商户号")
private Integer merchantId;
/**
* 场景名称(模糊查询)
*/
@ApiModelProperty(notes = "场景名称(模糊查询)")
......
package cn.com.glsx.dj.smartcarlife.enums;
/**
* 驻店类型枚举
*/
public enum StationTypeEnum {
PERMANENT((byte) 1, "门店常驻"),
TEMPORARY((byte) 2, "临时调动支援");
private final Byte value;
private final String displayName;
StationTypeEnum(Byte value, String displayName) {
this.value = value;
this.displayName = displayName;
}
public Byte getValue() {
return value;
}
public String getDisplayName() {
return displayName;
}
public static String getDisplayNameByValue(Byte value) {
if (value == null) {
return null;
}
for (StationTypeEnum temp : StationTypeEnum.values()) {
if (temp.getValue().equals(value)) {
return temp.getDisplayName();
}
}
return null;
}
}
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;
}
......@@ -106,6 +106,12 @@ public class StaffAccountRecord implements Serializable {
private Date updatedDate;
/**
* 驻店类型(1:门店常驻, 2:临时调动支援)
*/
@Column(name = "station_type")
private Byte stationType;
/**
* 删除标识(D:已删除;N:未删除;I:禁用)
*/
@Column(name = "deleted_flag")
......
......@@ -205,5 +205,34 @@ public interface StaffBaseInfoRemote {
@ApiParam(name="condition",notes="查询条件",dataType= ApiParam.DataTypeEnum.OBJECT,required=true)
@ApiResponse("员工列表")
RpcResponse<List<StaffBaseInfoDTO>> getStaffListByPhones(StaffBaseInfoDTO condition);
@ApiMethod("员工基础账号分配门店V2")
@ApiParam(name = "dto", notes = "分配门店入参V2", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("分配结果")
RpcResponse<String> assignStaffMerchantV2(AssignStaffMerchantV2DTO dto);
@ApiMethod("禁用或启用员工园区店账号V2")
@ApiParam(name = "condition", notes = "参数id", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("禁用或启用结果V2")
RpcResponse<String> disableStaffAccountV2(StaffAccountRecordDTO condition);
@ApiMethod("查询园区店下4s店及业务场景")
@ApiParam(name = "yqMerchantIdList", notes = "园区店商户号列表", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("园区店4s店场景列表")
RpcResponse<List<YqMerchant4sSceneDTO>> query4sByYqMerchantList(List<Integer> yqMerchantIdList);
@ApiMethod("查询驻店员工门店账号列表")
@ApiParam(name = "condition", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("门店账号列表(园区店维度聚合)")
RpcResponse<List<StaffAccountRecordDetailDTO>> listStaffAccountRecords(StaffAccountRecordDTO condition);
@ApiMethod("编辑园区店数据回显")
@ApiParam(name = "accountRecordId", notes = "账号记录id", dataType = ApiParam.DataTypeEnum.INTEGER, required = true)
@ApiResponse("账号详情")
RpcResponse<StaffAccountRecordDetailDTO> getStaffAccountRecordDetail(Integer accountRecordId);
@ApiMethod("清理无效账户场景数据")
@ApiResponse("清理记录数")
RpcResponse<Integer> cleanInvalidAccountScene();
}
......@@ -38,4 +38,6 @@ public interface SceneMerchantRefNewMapper extends OreMapper<SceneMerchantRefNew
List<MerchantListDTO> querySimpleSceneRefByShopNew(@Param("merchantId") Integer merchantId,@Param("scene") Integer scene,@Param("baseSceneCode") String baseSceneCode);
List<SceneMerchantRefNew> getShopMerchantServiceRef(@Param("shopMerchantId") Integer shopMerchantId, @Param("refMerchantId") Integer refMerchantId,@Param("baseSceneCode") String baseSceneCode);
List<SceneMerchantRefNew> query4sByYqMerchantList(@Param("yqMerchantIdList") List<Integer> yqMerchantIdList);
}
\ No newline at end of file
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> {
}
......@@ -8,6 +8,7 @@ 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
......@@ -27,5 +28,9 @@ public interface StaffAccountRecordMapper extends OreMapper<StaffAccountRecord>
List<String> queryStaffYqMerchantScene(@Param("staffPhone") String staffPhone, @Param("yqMerchantId") Integer yqMerchantId);
List<String> searchStaffYqMerchantScene(@Param("staffPhone") String staffPhone, @Param("yqMerchantId") Integer yqMerchantId, @Param("sceneType") Integer sceneType);
List<String> searchStaffYqMerchantScene(@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 cleanInvalidAccountScene();
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import cn.com.glsx.dj.smartcarlife.dto.scene.SceneDTO;
import cn.com.glsx.dj.smartcarlife.dto.scene.SceneQueryFilterDTO;
import cn.com.glsx.dj.smartcarlife.dto.staff.*;
import cn.com.glsx.dj.smartcarlife.model.StaffConfig;
import cn.com.glsx.dj.smartcarlife.service.SceneMerchantRefService;
import cn.com.glsx.dj.smartcarlife.service.merchantPerformanceConfig.StaffAccountRecordService;
import cn.com.glsx.dj.smartcarlife.service.merchantPerformanceConfig.StaffBaseInfoService;
import cn.com.glsx.dj.smartcarlife.service.merchantPerformanceConfig.StaffConfigService;
......@@ -12,6 +13,9 @@ import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
......@@ -34,6 +38,9 @@ public class StaffBaseInfoRemoteImpl implements StaffBaseInfoRemote {
@Autowired
private StaffAccountRecordService staffAccountRecordService;
@Autowired
private SceneMerchantRefService sceneMerchantRefService;
@Override
public RpcResponse<RpcPagination<StaffBaseInfoDTO>> listWithPage(
@NotNull RpcPagination<StaffBaseInfoDTO> pagination) {
......@@ -444,4 +451,105 @@ public class StaffBaseInfoRemoteImpl implements StaffBaseInfoRemote {
return RpcResponse.error(e);
}
}
@ApiMethod("员工基础账号分配门店V2")
@ApiParam(name = "dto", notes = "分配门店入参V2", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("分配结果")
@Override
public RpcResponse<String> assignStaffMerchantV2(AssignStaffMerchantV2DTO dto) {
try {
staffBaseInfoService.assignStaffMerchantV2(dto);
return RpcResponse.success("分配成功");
} catch (RpcServiceException e) {
log.error("员工基础账号分配门店V2异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("员工基础账号分配门店V2异常: ", e);
return RpcResponse.error(e);
}
}
@ApiMethod("禁用或启用员工园区店账号V2")
@ApiParam(name = "condition", notes = "参数id", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("禁用或启用结果V2")
@Override
public RpcResponse<String> disableStaffAccountV2(StaffAccountRecordDTO condition) {
try {
staffAccountRecordService.disableStaffAccountV2(condition);
return RpcResponse.success("操作成功");
} catch (RpcServiceException e) {
log.error("禁用或启用员工园区店账号V2异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("禁用或启用员工园区店账号V2异常: ", e);
return RpcResponse.error(e);
}
}
@ApiMethod("查询园区店下4s店及业务场景")
@ApiParam(name = "yqMerchantIdList", notes = "园区店商户号列表", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("园区店4s店场景列表")
@Override
public RpcResponse<List<YqMerchant4sSceneDTO>> query4sByYqMerchantList(List<Integer> yqMerchantIdList) {
try {
List<YqMerchant4sSceneDTO> result = sceneMerchantRefService.query4sByYqMerchantList(yqMerchantIdList);
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("查询园区店下4s店及业务场景异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("查询园区店下4s店及业务场景异常: ", e);
return RpcResponse.error(e);
}
}
@ApiMethod("查询驻店员工门店账号列表")
@ApiParam(name = "condition", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("门店账号列表(园区店维度聚合)")
@Override
public RpcResponse<List<StaffAccountRecordDetailDTO>> listStaffAccountRecords(StaffAccountRecordDTO condition) {
try {
List<StaffAccountRecordDetailDTO> result = staffAccountRecordService.listStaffAccountRecordsGrouped(condition);
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("查询驻店员工门店账号列表异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("查询驻店员工门店账号列表异常: ", e);
return RpcResponse.error(e);
}
}
@ApiMethod("编辑园区店数据回显")
@ApiParam(name = "accountRecordId", notes = "账号记录id", dataType = ApiParam.DataTypeEnum.INTEGER, required = true)
@ApiResponse("账号详情")
@Override
public RpcResponse<StaffAccountRecordDetailDTO> getStaffAccountRecordDetail(Integer accountRecordId) {
try {
StaffAccountRecordDetailDTO result = staffAccountRecordService.getStaffAccountRecordDetail(accountRecordId);
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("编辑园区店数据回显异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("编辑园区店数据回显异常: ", e);
return RpcResponse.error(e);
}
}
@ApiMethod("清理无效账户场景数据")
@ApiResponse("清理记录数")
@Override
public RpcResponse<Integer> cleanInvalidAccountScene() {
try {
int count = staffAccountRecordService.cleanInvalidAccountScene();
return RpcResponse.success(count);
} catch (RpcServiceException e) {
log.error("清理无效账户场景数据异常: ", e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("系统异常: ", e);
return RpcResponse.error(e);
}
}
}
......@@ -7,6 +7,7 @@ import cn.com.glsx.dj.smartcarlife.dto.businessassistant.MerchantServiceCenterDT
import cn.com.glsx.dj.smartcarlife.dto.merchant.CarBrandDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantRef.*;
import cn.com.glsx.dj.smartcarlife.dto.scene.SceneDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.YqMerchant4sSceneDTO;
import cn.com.glsx.dj.smartcarlife.dto.staff.StaffDailyReportConfigDTO;
import cn.com.glsx.dj.smartcarlife.enums.*;
import cn.com.glsx.dj.smartcarlife.manager.StaffManager;
......@@ -44,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.remote.CommonProxyRemote;
import cn.com.glsx.scrm.proxy.remote.merchant.MerchantRemote;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
......@@ -2112,4 +2114,73 @@ public class SceneMerchantRefService {
RpcAssert.assertNotNull(baseSceneCode, DefaultErrorEnum.DATA_NULL,"baseSceneCode not be null");
return sceneMerchantRefNewMapper.querySimpleSceneRefByShopNew(merchantId, scene, baseSceneCode);
}
/**
* 查询园区店下4s店及业务场景(二级聚合)
* 第一级: 按园区店(yqMerchantId)聚合
* 第二级: 按园区店下4s店(shopMerchantId)聚合
*
* @param yqMerchantIdList 园区店商户号列表
* @return 园区店4s店场景列表
*/
public List<YqMerchant4sSceneDTO> query4sByYqMerchantList(List<Integer> yqMerchantIdList) {
if (CollectionUtils.isEmpty(yqMerchantIdList)) {
return new ArrayList<>();
}
// 1. 查询原始数据
List<SceneMerchantRefNew> refList = sceneMerchantRefNewMapper.query4sByYqMerchantList(yqMerchantIdList);
if (CollectionUtils.isEmpty(refList)) {
return new ArrayList<>();
}
// 2. 获取场景名称映射 baseSceneCode -> SceneDTO
List<SceneDTO> allScenes = sceneService.getScenesByParams(null);
Map<String, String> sceneNameMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(allScenes)) {
sceneNameMap = allScenes.stream()
.filter(s -> s.getBaseSceneCode() != null)
.collect(Collectors.toMap(SceneDTO::getBaseSceneCode, SceneDTO::getName, (v1, v2) -> v1));
}
// 3. 二级聚合: 先按园区店分组,再按4s店分组
// 第一级: 按园区店(yqMerchantId = subMerchantId)分组
Map<Integer, List<SceneMerchantRefNew>> yqGroup = refList.stream()
.filter(r -> r.getSubMerchantId() != null)
.collect(Collectors.groupingBy(SceneMerchantRefNew::getSubMerchantId, LinkedHashMap::new, Collectors.toList()));
List<YqMerchant4sSceneDTO> result = new ArrayList<>();
for (Map.Entry<Integer, List<SceneMerchantRefNew>> yqEntry : yqGroup.entrySet()) {
YqMerchant4sSceneDTO yqDto = new YqMerchant4sSceneDTO();
yqDto.setYqMerchantId(yqEntry.getKey());
List<SceneMerchantRefNew> yqItems = Optional.ofNullable(yqEntry.getValue()).orElse(Lists.newArrayList());
// 园区店名称取第一条
yqDto.setYqMerchantName(Optional.of(yqItems).filter(r -> !r.isEmpty()).map(r -> r.get(0).getSubMerchantName()).orElse(StrUtil.EMPTY));
// 第二级: 按4s店(shopMerchantId = mainMerchantId)分组
Map<Integer, List<SceneMerchantRefNew>> shopGroup = yqItems.stream()
.filter(r -> r.getMainMerchantId() != null)
.collect(Collectors.groupingBy(SceneMerchantRefNew::getMainMerchantId, LinkedHashMap::new, Collectors.toList()));
List<YqMerchant4sSceneDTO.ShopSceneDTO> shopList = new ArrayList<>();
for (Map.Entry<Integer, List<SceneMerchantRefNew>> shopEntry : shopGroup.entrySet()) {
YqMerchant4sSceneDTO.ShopSceneDTO shopDto = new YqMerchant4sSceneDTO.ShopSceneDTO();
shopDto.setShopMerchantId(shopEntry.getKey());
List<SceneMerchantRefNew> shopItems = Optional.ofNullable(shopEntry.getValue()).orElse(Lists.newArrayList());
// 4s店名称取第一条
shopDto.setShopMerchantName(Optional.of(shopItems).filter(r -> !r.isEmpty()).map(r -> r.get(0).getMainMerchantName()).orElse(StrUtil.EMPTY));
// 场景列表
Map<String, String> finalSceneNameMap = sceneNameMap;
List<YqMerchant4sSceneDTO.SceneDetailDTO> sceneList = shopItems.stream().map(item -> {
YqMerchant4sSceneDTO.SceneDetailDTO sceneDto = new YqMerchant4sSceneDTO.SceneDetailDTO();
sceneDto.setBaseSceneCode(item.getBaseSceneCode());
sceneDto.setScene(item.getScene() != null ? String.valueOf(item.getScene()) : null);
sceneDto.setSceneName(finalSceneNameMap.getOrDefault(item.getBaseSceneCode(), item.getBaseSceneCode()));
sceneDto.setSceneType(item.getScene() != null ? item.getScene().byteValue() : null);
sceneDto.setYqMerchantId(item.getSubMerchantId());
sceneDto.setYqMerchantName(item.getSubMerchantName());
return sceneDto;
}).collect(Collectors.toList());
shopDto.setSceneList(sceneList);
shopList.add(shopDto);
}
yqDto.setShopList(shopList);
result.add(yqDto);
}
return result;
}
}
package cn.com.glsx.dj.smartcarlife.service.merchantPerformanceConfig;
import cn.com.glsx.dj.smartcarlife.constant.CommonConstants;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountAssignRecordDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountRecordDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountRecordDetailDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffAccountStatusNumDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffBaseInfoDTO;
import cn.com.glsx.dj.smartcarlife.dto.scene.SceneDTO;
......@@ -10,8 +12,13 @@ import cn.com.glsx.dj.smartcarlife.dto.staff.StaffAccountStatusDTO;
import cn.com.glsx.dj.smartcarlife.dto.staff.StaffMerchantInfoDTO;
import cn.com.glsx.dj.smartcarlife.enums.AddStaffSourceEnum;
import cn.com.glsx.dj.smartcarlife.enums.StaffStatusEnum;
import cn.com.glsx.dj.smartcarlife.enums.StationTypeEnum;
import cn.com.glsx.dj.smartcarlife.mapper.StaffAccountAssignRecordMapper;
import cn.com.glsx.dj.smartcarlife.mapper.StaffAccountAssignSceneMapper;
import cn.com.glsx.dj.smartcarlife.mapper.StaffAccountRecordMapper;
import cn.com.glsx.dj.smartcarlife.mapper.StaffAccountSceneMapper;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignRecord;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountAssignScene;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountRecord;
import cn.com.glsx.dj.smartcarlife.model.StaffAccountScene;
import cn.com.glsx.dj.smartcarlife.model.StaffInfo;
......@@ -29,11 +36,13 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.*;
......@@ -54,6 +63,9 @@ public class StaffAccountRecordService {
private StaffAccountRecordMapper staffAccountRecordMapper;
@Resource
private StaffAccountAssignRecordMapper staffAccountAssignRecordMapper;
@Resource
private StaffBaseInfoService staffBaseInfoService;
@Autowired
......@@ -68,6 +80,9 @@ public class StaffAccountRecordService {
@Autowired
private StaffAccountSceneMapper staffAccountSceneMapper;
@Resource
private StaffAccountAssignSceneMapper staffAccountAssignSceneMapper;
public int insertStaffAccountRecord(StaffAccountRecord accountRecord) {
RpcAssert.assertNotNull(accountRecord, DefaultErrorEnum.DATA_NULL, "accountRecord not be null");
try {
......@@ -420,7 +435,7 @@ public class StaffAccountRecordService {
}
public List<SceneDTO> searchStaffYqMerchantScene(SceneQueryFilterDTO request) {
List<String> baseSceneCodes = staffAccountRecordMapper.searchStaffYqMerchantScene(request.getStaffPhone(), request.getYqMerchantId(), request.getSceneType());
List<String> baseSceneCodes = staffAccountAssignRecordMapper.searchStaffYqMerchantAssignScene(request.getStaffPhone(), request.getYqMerchantId(), request.getSceneType(), request.getMerchantId());
if (CollectionUtils.isEmpty(baseSceneCodes)) {
return Collections.emptyList();
}
......@@ -433,4 +448,280 @@ public class StaffAccountRecordService {
public void updateByPrimaryKeySelective(StaffAccountRecord staffAccountRecordUpdate) {
staffAccountRecordMapper.updateByPrimaryKeySelective(staffAccountRecordUpdate);
}
/**
* 园区店维度批量禁用/启用V2
* 根据传入的accountId查出StaffAccountRecord,再根据(staffPhone, yqMerchantId)查询所有非删除记录,
* 判断当前状态自动切换,批量更新,账户中心只调用一次同步
*
* @param condition 包含id和updatedBy的DTO
*/
@GlsxDistributeLockable(name = "'StaffAccountRecordService_disableStaffAccountV2_' + #condition.id", time = 3, timeoutException = Exception.class)
@Transactional(rollbackFor = RpcServiceException.class)
public void disableStaffAccountV2(StaffAccountRecordDTO condition) {
// 根据accountId查出StaffAccountAssignRecord
StaffAccountAssignRecord oldAccountRecord = staffAccountAssignRecordMapper.selectByPrimaryKey(condition.getId());
if (oldAccountRecord == null || BaseModel.DeletedFlagEnum.D.name().equals(oldAccountRecord.getDeletedFlag())) {
throw new RpcServiceException("员工账号记录不存在");
}
String staffPhone = oldAccountRecord.getStaffPhone();
Integer yqMerchantId = oldAccountRecord.getYqMerchantId();
// 根据(staffPhone, yqMerchantId)查询所有非删除记录
Example example = new Example(StaffAccountAssignRecord.class);
example.createCriteria()
.andNotEqualTo("deletedFlag", "D")
.andEqualTo("yqMerchantId", yqMerchantId)
.andEqualTo("staffPhone", staffPhone);
List<StaffAccountAssignRecord> records = staffAccountAssignRecordMapper.selectByExample(example);
if (CollectionUtils.isEmpty(records)) {
throw new RpcServiceException("未找到该手机号和园区店下的账号记录");
}
// 判断当前状态(以第一条记录为准),自动切换:禁用->启用,启用->禁用
boolean isCurrentlyDisabled = StaffStatusEnum.INVALID.getName().equals(records.get(0).getDeletedFlag());
String newFlag = isCurrentlyDisabled ? StaffStatusEnum.NOT_DELETED.getName() : StaffStatusEnum.INVALID.getName();
Integer newStatus = isCurrentlyDisabled ? StaffStatusEnum.NOT_DELETED.getValue() : StaffStatusEnum.INVALID.getValue();
String action = isCurrentlyDisabled ? "启用" : "禁用";
// 批量更新
Date now = new Date();
int updatedRows = staffAccountAssignRecordMapper.batchUpdateDeleteFlagByPhoneAndYqMerchant(staffPhone, yqMerchantId, newFlag, condition.getUpdatedBy(), now);
log.info("园区店维度批量{}完成,staffPhone={}, yqMerchantId={}, 更新记录数={}", action, staffPhone, yqMerchantId, updatedRows);
// 同步账户中心(只调用一次)
StaffBatchRequest staffBatchRequest = new StaffBatchRequest();
staffBatchRequest.setStaffPhone(staffPhone);
staffBatchRequest.setMerchantId(String.valueOf(yqMerchantId));
staffBatchRequest.setStatus(newStatus);
log.info("园区店维度批量{}-调用账户中心接口修改账户状态开始,入参:{}", action, staffBatchRequest);
try {
RpcResponse<Boolean> rpcResponse = merchantStaffRemote.updateStaffStatusByPhone(staffBatchRequest);
log.info("园区店维度批量{}-调用账户中心接口修改账户状态结束,返参:{}", action, rpcResponse);
if (!rpcResponse.hasResult()) {
log.info("园区店维度批量{}-修改员工在职状态失败,返回结果:{}", action, rpcResponse);
throw new RpcServiceException("修改员工在职状态失败,失败原因:" + rpcResponse.getMessage());
}
} catch (RpcServiceException e) {
throw e;
} catch (Exception e) {
log.error("园区店维度批量{}-调用账户中心接口异常", action, e);
throw new RpcServiceException("调用账户中心接口异常:" + e.getMessage());
}
}
/**
* 查询驻店员工门店账号列表
*
* @param staffAccountRecordDTO 查询条件
* @return 账号列表
*/
public List<StaffAccountRecordDTO> listStaffAccountRecords(StaffAccountRecordDTO staffAccountRecordDTO) {
try {
List<StaffAccountRecordDTO> records = staffAccountRecordMapper.listStaffAccountRecord(staffAccountRecordDTO);
if (CollectionUtils.isNotEmpty(records)) {
for (StaffAccountRecordDTO record : records) {
// 查询场景名称并拼接accountSceneStr
List<String> baseSceneCodes = staffAccountRecordMapper.queryStaffYqMerchantScene(record.getStaffPhone(), record.getYqMerchantId());
if (CollectionUtils.isNotEmpty(baseSceneCodes)) {
SceneQueryFilterDTO sceneQueryFilterDTO = new SceneQueryFilterDTO();
sceneQueryFilterDTO.setBaseSceneCodeList(baseSceneCodes);
List<SceneDTO> scenes = sceneService.getScenesByParams(sceneQueryFilterDTO);
if (CollectionUtils.isNotEmpty(scenes)) {
String sceneStr = scenes.stream()
.map(SceneDTO::getName)
.filter(Objects::nonNull)
.collect(Collectors.joining("、"));
record.setAccountSceneStr(sceneStr);
}
}
// 填充stationTypeDesc
record.setStationTypeDesc(StationTypeEnum.getDisplayNameByValue(record.getStationType()));
}
}
return records;
} catch (Exception e) {
log.error("查询驻店员工门店账号列表异常", e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());
}
}
/**
* 查询驻店员工门店账号列表(按园区店维度聚合)
* 返回三级结构:园区店列表→4s店列表→场景列表
*
* @param staffAccountRecordDTO 查询条件
* @return 园区店维度聚合的账号列表
*/
public List<StaffAccountRecordDetailDTO> listStaffAccountRecordsGrouped(StaffAccountRecordDTO staffAccountRecordDTO) {
try {
StaffAccountAssignRecordDTO assignQuery = new StaffAccountAssignRecordDTO();
BeanUtils.copyProperties(staffAccountRecordDTO, assignQuery);
List<StaffAccountAssignRecordDTO> assignRecords = staffAccountAssignRecordMapper.listStaffAccountAssignRecord(assignQuery);
if (CollectionUtils.isEmpty(assignRecords)) {
return Collections.emptyList();
}
List<StaffAccountRecordDTO> records = assignRecords.stream().map(assignRecord -> {
StaffAccountRecordDTO record = new StaffAccountRecordDTO();
BeanUtils.copyProperties(assignRecord, record);
return record;
}).collect(Collectors.toList());
// 按yqMerchantId分组
Map<Integer, List<StaffAccountRecordDTO>> yqMerchantMap = records.stream()
.collect(Collectors.groupingBy(StaffAccountRecordDTO::getYqMerchantId, LinkedHashMap::new, Collectors.toList()));
List<StaffAccountRecordDetailDTO> resultList = new ArrayList<>();
for (Map.Entry<Integer, List<StaffAccountRecordDTO>> entry : yqMerchantMap.entrySet()) {
List<StaffAccountRecordDTO> yqRecords = entry.getValue();
StaffAccountRecordDTO firstRecord = yqRecords.get(0);
StaffAccountRecordDetailDTO yqItem = new StaffAccountRecordDetailDTO();
yqItem.setStaffPhone(firstRecord.getStaffPhone());
yqItem.setYqMerchantId(firstRecord.getYqMerchantId());
yqItem.setYqMerchantName(firstRecord.getYqMerchantName());
// 组装4s店列表
List<StaffAccountRecordDetailDTO.FourSShopDetailItem> fourSShopList = new ArrayList<>();
for (StaffAccountRecordDTO record : yqRecords) {
StaffAccountRecordDetailDTO.FourSShopDetailItem shopItem = new StaffAccountRecordDetailDTO.FourSShopDetailItem();
shopItem.setAccountRecordId(record.getId());
shopItem.setMerchantId(record.getMerchantId());
shopItem.setMerchantName(record.getMerchantName());
shopItem.setStationType(record.getStationType());
shopItem.setCreatedDate(record.getCreatedDate());
shopItem.setCreatedBy(record.getCreatedBy());
shopItem.setDeletedFlag(record.getDeletedFlag());
// 查询该4s店关联的场景
StaffAccountAssignScene sceneQuery = new StaffAccountAssignScene();
sceneQuery.setAccountRecordId(record.getId());
sceneQuery.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
List<StaffAccountAssignScene> accountScenes = staffAccountAssignSceneMapper.select(sceneQuery);
List<SceneDTO> sceneList = Collections.emptyList();
if (CollectionUtils.isNotEmpty(accountScenes)) {
List<String> baseSceneCodes = accountScenes.stream()
.map(StaffAccountAssignScene::getBaseSceneCode)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(baseSceneCodes)) {
SceneQueryFilterDTO sceneQueryFilterDTO = new SceneQueryFilterDTO();
sceneQueryFilterDTO.setBaseSceneCodeList(baseSceneCodes);
sceneList = sceneService.getScenesByParams(sceneQueryFilterDTO);
}
}
shopItem.setSceneList(sceneList);
fourSShopList.add(shopItem);
}
yqItem.setFourSShopList(fourSShopList);
resultList.add(yqItem);
}
return resultList;
} catch (Exception e) {
log.error("查询驻店员工门店账号列表异常", e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());
}
}
/**
* 编辑数据回显(园区店维度聚合)
* 返回员工在某园区店下配置的所有4s店列表,4s店内含场景列表
*
* @param accountRecordId 账号记录id(通过该记录定位园区店和员工)
* @return 详情DTO(三级结构:园区店→4s店列表→场景列表)
*/
public StaffAccountRecordDetailDTO getStaffAccountRecordDetail(Integer accountRecordId) {
try {
// 通过accountRecordId定位到该记录,获取yqMerchantId和staffPhone
StaffAccountAssignRecord accountRecord = staffAccountAssignRecordMapper.selectByPrimaryKey(accountRecordId);
if (accountRecord == null) {
throw new RpcServiceException("员工账号记录不存在");
}
String staffPhone = accountRecord.getStaffPhone();
Integer yqMerchantId = accountRecord.getYqMerchantId();
// 查询该员工在该园区店下所有未删除的4s店记录
StaffAccountAssignRecordDTO recordQuery = StaffAccountAssignRecordDTO.builder()
.staffPhone(staffPhone)
.yqMerchantId(yqMerchantId)
.deletedFlagList(Arrays.asList(StaffStatusEnum.NOT_DELETED.getName(), StaffStatusEnum.INVALID.getName()))
.build();
List<StaffAccountAssignRecordDTO> assignRecords = staffAccountAssignRecordMapper.listStaffAccountAssignRecord(recordQuery);
List<StaffAccountRecordDTO> allRecords = assignRecords.stream().map(assignRecord -> {
StaffAccountRecordDTO record = new StaffAccountRecordDTO();
BeanUtils.copyProperties(assignRecord, record);
return record;
}).collect(Collectors.toList());
// 按每个4s店记录组装4s店详情项
List<StaffAccountRecordDetailDTO.FourSShopDetailItem> fourSShopList = new ArrayList<>();
for (StaffAccountRecordDTO record : allRecords) {
StaffAccountRecordDetailDTO.FourSShopDetailItem shopItem = new StaffAccountRecordDetailDTO.FourSShopDetailItem();
shopItem.setAccountRecordId(record.getId());
shopItem.setMerchantId(record.getMerchantId());
shopItem.setMerchantName(record.getMerchantName());
shopItem.setStationType(record.getStationType());
shopItem.setCreatedDate(record.getCreatedDate());
shopItem.setCreatedBy(record.getCreatedBy());
shopItem.setDeletedFlag(record.getDeletedFlag());
// 查询该4s店关联的场景
StaffAccountAssignScene sceneQuery = new StaffAccountAssignScene();
sceneQuery.setAccountRecordId(record.getId());
sceneQuery.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
List<StaffAccountAssignScene> accountScenes = staffAccountAssignSceneMapper.select(sceneQuery);
List<SceneDTO> sceneList = Collections.emptyList();
if (CollectionUtils.isNotEmpty(accountScenes)) {
List<String> baseSceneCodes = accountScenes.stream()
.map(StaffAccountAssignScene::getBaseSceneCode)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(baseSceneCodes)) {
SceneQueryFilterDTO sceneQueryFilterDTO = new SceneQueryFilterDTO();
sceneQueryFilterDTO.setBaseSceneCodeList(baseSceneCodes);
sceneList = sceneService.getScenesByParams(sceneQueryFilterDTO);
}
}
shopItem.setSceneList(sceneList);
fourSShopList.add(shopItem);
}
// 组装园区店维度的返回DTO
StaffAccountRecordDetailDTO detailDTO = new StaffAccountRecordDetailDTO();
detailDTO.setStaffPhone(staffPhone);
detailDTO.setYqMerchantId(yqMerchantId);
detailDTO.setYqMerchantName(accountRecord.getYqMerchantName());
detailDTO.setFourSShopList(fourSShopList);
return detailDTO;
} catch (RpcServiceException e) {
throw e;
} catch (Exception e) {
log.error("查询员工账号记录详情异常, accountRecordId={}", accountRecordId, e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());
}
}
/**
* 清理无效账户场景数据
* 删除4s店不支持的场景记录
*
* @return 清理的记录数
*/
@Transactional(rollbackFor = RpcServiceException.class)
public int cleanInvalidAccountScene() {
try {
int cleanedCount = staffAccountAssignRecordMapper.cleanInvalidAccountAssignScene();
log.info("清理无效账户场景数据完成,清理记录数={}", cleanedCount);
return cleanedCount;
} catch (Exception e) {
log.error("清理无效账户场景数据异常", e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());
}
}
}
......@@ -80,4 +80,16 @@
where main_merchant_id = #{shopMerchantId} and sub_merchant_id = #{refMerchantId} and sub_merchant_type = 7 and base_scene_code = #{baseSceneCode}
and deleted_flag = 'N' and status = 1
</select>
<select id="query4sByYqMerchantList" resultMap="BaseResultMap">
SELECT for4s.main_merchant_id, for4s.main_merchant_name, for4s.base_scene_code, for4s.scene,
for4s.sub_merchant_id, for4s.sub_merchant_name
FROM dj_car_life_scene_merchant_ref_new for4s
WHERE for4s.sub_merchant_id IN
<foreach collection="yqMerchantIdList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
AND for4s.main_merchant_type = 2
AND for4s.deleted_flag = 'N'
AND for4s.status = 1
</select>
</mapper>
\ No newline at end of file
<?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>
......@@ -15,6 +15,7 @@
<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" />
......@@ -36,7 +37,7 @@
<!--
WARNING - @mbg.generated
-->
id, staff_uuid, staff_phone, job_type, staff_scene_label, merchant_id, merchant_name, yq_merchant_id, yq_merchant_name, created_source,
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>
......@@ -104,6 +105,9 @@
<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=",">
......@@ -137,6 +141,9 @@
<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>
......@@ -144,4 +151,31 @@
AND ss.deleted_flag = 'N'
</where>
</select>
<!-- 按手机号+园区店批量更新删除标识状态(禁用/启用V2) -->
<update id="batchUpdateDeleteFlagByPhoneAndYqMerchant">
UPDATE dj_car_life_staff_account_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>
<!-- 清理4s店不支持的场景数据 -->
<update id="cleanInvalidAccountScene">
UPDATE dj_car_life_staff_account_scene ss
INNER JOIN dj_car_life_staff_account_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>
</mapper>
\ No newline at end of file
......@@ -80,6 +80,7 @@
<result column="accountMentorPhone" property="mentorPhone" jdbcType="VARCHAR"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
<result column="station_type" property="stationType" jdbcType="TINYINT"/>
</collection>
</resultMap>
......@@ -482,7 +483,7 @@
/*账号信息*/
sar.id as accountRecordId,sar.deleted_flag as accountRecordDeletedFlag,
sar.merchant_id,sar.merchant_name,sar.yq_merchant_id,sar.yq_merchant_name,sar.staff_scene_label as yqMerchantStaffSceneLabel,
sar.job_type as accountJobType,sbi.mentor_name as accountMentorName,sbi.mentor_phone as accountMentorPhone,sar.created_date,sar.created_by
sar.job_type as accountJobType,sbi.mentor_name as accountMentorName,sbi.mentor_phone as accountMentorPhone,sar.created_date,sar.created_by,sar.station_type
from dj_car_life_staff_base_info sbi
left join dj_car_life_staff_business_info_change_record sbicr on sbi.staff_phone = sbicr.staff_phone and sbicr.deleted_flag = 'N'
left join dj_car_life_staff_account_record sar on sbi.staff_phone = sar.staff_phone and sar.deleted_flag in ('N','I')
......
  • @wangxw1
    commented
    Master

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

    1. 严重违规:MyBatis SQL 语句中使用了子查询(功能正确性与规范)

    • 问题描述:在 StaffAccountAssignRecordMapper.xml 的 cleanInvalidAccountAssignScene 和 StaffAccountRecordMapper.xml 的 cleanInvalidAccountScene 语句中,使用了 NOT EXISTS (SELECT 1 ...) 子查询。这直接违反了“mybatis的sql语句不允许使用子查询”的强制规则。
    • 影响分析:在 UPDATE 语句中使用相关子查询会导致数据库在更新时逐行计算子查询,极易引发严重的性能问题甚至导致死锁,且不符合项目既定的 SQL 规范。
    • 优化建议:使用 LEFT JOIN 关联目标表,并通过判断关联表的主键或非空字段是否为 NULL 来替代 NOT EXISTS 子查询。 代码示例: 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. 性能瓶颈:循环内执行数据库查询与 RPC 调用(性能与最佳实践)

    • 问题描述:在 StaffAccountRecordService 的 listStaffAccountRecords 和 listStaffAccountRecordsGrouped 方法中,存在典型的 N+1 查询问题。代码在 for 循环中调用了 Mapper 查询(如 queryStaffYqMerchantScene、select)以及外部服务调用(sceneService.getScenesByParams)。
    • 影响分析:随着列表数据量(员工数量或门店数量)的增加,数据库连接和网络请求会成倍放大。这不仅会严重拖慢接口响应时间,甚至可能在并发较高时耗尽数据库连接池或引发 RPC 超时。
    • 优化建议:将循环内的查询提取到循环外进行批量查询。先收集所有的 yqMerchantId、staffPhone 或 baseSceneCode,通过 IN (...) 一次性查询出所有相关数据,在内存中组装为 Map,最后在循环中通过 Map.get() 进行数据拼接。

    3. 稳定性风险:在 @Transactional 事务代码块中发起 RPC 远程调用(安全性与稳定性)

    • 问题描述:在 StaffAccountRecordService.disableStaffAccountV2 方法中,方法被 @Transactional 注解修饰,但在方法末尾同步调用了 RPC 接口 merchantStaffRemote.updateStaffStatusByPhone。
    • 影响分析:
      1. 长事务风险:RPC 调用涉及网络 I/O,会拉长本地数据库事务的提交时间,长时间占用数据库连接,降低系统吞吐量。
      2. 分布式数据不一致:如果 RPC 调用成功(远程状态已修改),但本地事务在后续提交阶段由于网络波动或数据库异常导致回滚,将产生严重的分布式数据不一致问题。
    • 优化建议:将 RPC 调用移出本地事务。如果必须保证本地事务提交后再通知远程,可以使用编程式事务,或通过 Spring 的 TransactionSynchronizationManager.registerSynchronization 在 afterCommit 阶段发起 RPC 调用;若对一致性要求极高,应引入本地消息表或可靠消息最终一致性方案。

    二、评分明细

    • 功能实现的正确性与健壮性(30/40分):业务逻辑基本实现,新增的 Dubbo 接口未破坏原有参数结构。但 SQL 实现直接违反了“禁止使用子查询”的硬性红线,扣除 10 分。
    • 安全性与潜在风险(22/30分):在本地数据库事务中直接嵌套 RPC 同步调用,存在较高的长事务风险和分布式数据不一致隐患,扣除 8 分。
    • 最佳实践与可维护性(14/20分):代码分层较清晰,DTO 命名规范。但在 Service 层中出现了“循环内查库/调服务”的反模式,违背了批量处理的最佳实践,扣除 6 分。
    • 性能与资源利用(2/5分):N+1 查询问题对性能影响较大,特别是涉及到场景数据的多次重复加载,会造成不必要的数据库和网络资源浪费,扣除 3 分。
    • 提交信息质量(3/5分):提交历史中存在如“feat:自测提交”、“feat:本地maven问题导致完全无法编译开新分支开发”等无业务价值的 commit message,无法准确追溯代码变更意图,扣除 2 分。

    总分:71分

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