Commit 6ff32b50 by 张富康

feat(perfSalary): 新增4s店商户品牌及交车数统计功能

- 在EffectiveReferralReviewMapper中添加获取4s店商户ID方法
- 新增根据月份统计各品牌交车数的MyBatis SQL查询
- 添加MerchantBrandReportDTO类,封装品牌交车数统计数据
- 在EffectiveReferralReviewService中新增stats方法,实现并发调用车品牌接口
- 对并发任务添加异常处理及重试机制,保障调用稳定性
- 通过查询结果映射品牌与交车数量,准备后续业务逻辑处理
1 parent 43638e27
package cn.com.glsx.dj.staff.dto.perfSalary;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
/**
* 商户品牌统计报表实体类
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class MerchantBrandReportDTO implements Serializable {
private static final long serialVersionUID = 1L;
/** 商户ID */
private Integer merchantId;
/** 年月(格式:YYYY-MM) */
private String reportYearMonth;
/** 轻改享界数量 */
private Integer qgXiangjCount;
/** 轻改尊界数量 */
private Integer qgZunjCount;
/** 轻改尚界数量 */
private Integer qgShangjCount;
/** 轻改智界数量 */
private Integer qgZhijCount;
/** 轻改问界数量 */
private Integer qgWenjCount;
/** 轻改其他品牌数量 */
private Integer qgOtherCount;
/** 单延保享界数量 */
private Integer ybXiangjCount;
/** 单延保尊界数量 */
private Integer ybZunjCount;
/** 单延保尚界数量 */
private Integer ybShangjCount;
/** 单延保智界数量 */
private Integer ybZhijCount;
/** 单延保问界数量 */
private Integer ybWenjCount;
/** 单延保其他品牌数量 */
private Integer ybOtherCount;
/** 广联权益享界数量 */
private Integer qyXiangjCount;
/** 广联权益尊界数量 */
private Integer qyZunjCount;
/** 广联权益尚界数量 */
private Integer qyShangjCount;
/** 广联权益智界数量 */
private Integer qyZhijCount;
/** 广联权益问界数量 */
private Integer qyWenjCount;
/** 广联权益其他品牌数量 */
private Integer qyOtherCount;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package cn.com.glsx.dj.staff.mapper.perfSalary;
import cn.com.glsx.dj.staff.dto.perfSalary.EffectiveReferralReviewCommonDTO;
import cn.com.glsx.dj.staff.dto.perfSalary.EffectiveReferralReviewDTO;
import cn.com.glsx.dj.staff.dto.perfSalary.MerchantBrandReportDTO;
import cn.com.glsx.dj.staff.model.perfSalary.EffectiveReferralReview;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -42,4 +43,8 @@ public interface EffectiveReferralReviewMapper extends OreMapper<EffectiveReferr
List<String> queryOnlineNoHandlerQwSendMobilePhone(@Param("date") String date, @Param("merchantId") Integer merchantId, @Param("sceneType") Byte sceneType);
List<Integer> getAll4sRefMerchantId();
List<MerchantBrandReportDTO> getDeliveryCount(@Param("date") String date);
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package cn.com.glsx.dj.staff.service.perfSalary;
import cn.com.glsx.dj.smartcarlife.constant.CommonConstants;
import cn.com.glsx.dj.staff.dto.perfSalary.EffectiveReferralReviewCommonDTO;
import cn.com.glsx.dj.staff.dto.perfSalary.EffectiveReferralReviewDTO;
import cn.com.glsx.dj.staff.dto.perfSalary.MerchantBrandReportDTO;
import cn.com.glsx.dj.staff.dto.perfSalary.MerchantCarBrandDTO;
import cn.com.glsx.dj.staff.dto.performance.PerformanceTimeCycleDTO;
import cn.com.glsx.dj.staff.enums.PerformanceTimeCycleCodeEnum;
......@@ -17,6 +18,9 @@ import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.scrm.proxy.model.MerchantCarInfoResponse;
import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse;
import cn.com.glsx.scrm.proxy.remote.merchant.MerchantRemote;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
......@@ -32,10 +36,9 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Slf4j
......@@ -174,7 +177,65 @@ public class EffectiveReferralReviewService {
* 有效引荐数(交车数)统计
*/
public void stats() {
// 获取所有4s店商户id
List<Integer> merchantIds = effectiveReferralReviewMapper.getAll4sRefMerchantId();
// 查询这些4s店对应的品牌信息
// 多线程调用getCarBrand接口
ConcurrentHashMap<Integer, List<MerchantCarBrandDTO>> merchantCarBrandMap = new ConcurrentHashMap<>();
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (Integer merchantId : merchantIds) {
CompletableFuture<Void> future = CompletableFuture.supplyAsync(
() -> fetchCarBrand(merchantId), // 封装业务逻辑
taskExecutor).thenAccept(carBrands -> {
if (carBrands != null) {
merchantCarBrandMap.put(merchantId, carBrands);
}}).exceptionally(ex -> {
log.error("获取车辆品牌失败-merchantId={}", merchantId, ex);
// 6. 添加默认空值
merchantCarBrandMap.put(merchantId, new ArrayList<>());
return null;
});
futures.add(future);
}
// 5. 等待所有任务完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
// 获取交车数
// 上个月
DateTime lastMonthDate = DateUtil.offsetMonth(new Date(), -1);
String lastMonth = DateUtil.format(lastMonthDate, DatePattern.NORM_MONTH_PATTERN);
List<MerchantBrandReportDTO> deliveryCount = effectiveReferralReviewMapper.getDeliveryCount(lastMonth);
Map<Integer, MerchantBrandReportDTO> deliveryCountMap = deliveryCount.stream().collect(Collectors.toMap(MerchantBrandReportDTO::getMerchantId, item -> item));
List<EffectiveReferralReview> insertList = new ArrayList<>();
for (Integer merchantId : merchantIds) {
List<MerchantCarBrandDTO> merchantCarBrandDTOS = merchantCarBrandMap.get(merchantId);
MerchantBrandReportDTO merchantBrandReportDTO = deliveryCountMap.get(merchantId);
// 判断品牌和设置品牌对应的交车数
}
}
// 封装业务逻辑 + 重试机制
private List<MerchantCarBrandDTO> fetchCarBrand(Integer merchantId) {
// 3次指数退避重试
int maxRetries = 3;
for (int i = 0; i < maxRetries; i++) {
try {
return getCarBrand(merchantId);
} catch (Exception e) {
if (i == maxRetries - 1) throw e;
try {
Thread.sleep((long) Math.pow(2, i) * 100); // 指数退避
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RuntimeException(ex);
}
}
}
return null;
}
......
......@@ -190,4 +190,56 @@
AND dc.director_phone IS NOT NULL;
</select>
<select id="getAll4sRefMerchantId" resultType="java.lang.Integer">
select distinct main_merchant_id
from dj_car_life_scene_merchant_ref a
where a.main_merchant_type = 2
and a.sub_merchant_type in (6, 8)
and a.deleted_flag = 'N'
and a.scene in (0, 1)
</select>
<select id="getDeliveryCount" resultType="cn.com.glsx.dj.staff.dto.perfSalary.MerchantBrandReportDTO">
SELECT
m.merchant_id AS `merchantId`,
DATE_FORMAT(m.report_date, '%Y-%m') AS `reportYearMonth`,
SUM(IF(m.brand_name = '享界' AND (s.template_type IN (0) OR s.template_type IS NULL), m.delivery_count, null)) AS `qgXiangjCount`,
SUM(IF(m.brand_name = '尊界' AND (s.template_type IN (0) OR s.template_type IS NULL), m.delivery_count, null)) AS `qgZunjCount`,
SUM(IF(m.brand_name = '尚界' AND (s.template_type IN (0) OR s.template_type IS NULL), m.delivery_count, null)) AS `qgShangjCount`,
SUM(IF(m.brand_name = '智界' AND (s.template_type IN (0) OR s.template_type IS NULL), m.delivery_count, null)) AS `qgZhijCount`,
SUM(IF(m.brand_name = '问界' AND (s.template_type IN (0) OR s.template_type IS NULL), m.delivery_count, null)) AS `qgWenjCount`,
SUM(IF(m.brand_name = '其他' AND (s.template_type IN (0) OR s.template_type IS NULL), m.delivery_count, null)) AS `qgOtherCount`,
SUM(IF(m.brand_name = '享界' AND (s.template_type IN (1, 2) OR s.template_type IS NULL), m.delivery_count, null)) AS `ybXiangjCount`,
SUM(IF(m.brand_name = '尊界' AND (s.template_type IN (1, 2) OR s.template_type IS NULL), m.delivery_count, null)) AS `ybZunjCount`,
SUM(IF(m.brand_name = '尚界' AND (s.template_type IN (1, 2) OR s.template_type IS NULL), m.delivery_count, null)) AS `ybShangjCount`,
SUM(IF(m.brand_name = '智界' AND (s.template_type IN (1, 2) OR s.template_type IS NULL), m.delivery_count, null)) AS `ybZhijCount`,
SUM(IF(m.brand_name = '问界' AND (s.template_type IN (1, 2) OR s.template_type IS NULL), m.delivery_count, null)) AS `ybWenjCount`,
SUM(IF(m.brand_name = '其他' AND (s.template_type IN (1, 2) OR s.template_type IS NULL), m.delivery_count, null)) AS `ybOtherCount`,
SUM(IF(m.brand_name = '享界' AND (s.template_type IN (2, 3) OR s.template_type IS NULL), m.delivery_count, null)) AS `qyXiangjCount`,
SUM(IF(m.brand_name = '尊界' AND (s.template_type IN (2, 3) OR s.template_type IS NULL), m.delivery_count, null)) AS `qyZunjCount`,
SUM(IF(m.brand_name = '尚界' AND (s.template_type IN (2, 3) OR s.template_type IS NULL), m.delivery_count, null)) AS `qyShangjCount`,
SUM(IF(m.brand_name = '智界' AND (s.template_type IN (2, 3) OR s.template_type IS NULL), m.delivery_count, null)) AS `qyZhijCount`,
SUM(IF(m.brand_name = '问界' AND (s.template_type IN (2, 3) OR s.template_type IS NULL), m.delivery_count, null)) AS `qyWenjCount`,
SUM(IF(m.brand_name = '其他' AND (s.template_type IN (2, 3) OR s.template_type IS NULL), m.delivery_count, null)) AS `qyOtherCount`
FROM dj_car_life_merchant_daily_report_huawei m
left join (SELECT merchant_id, report_date, scene_type, template_type
FROM dj_car_life_staff_daily_report
WHERE deleted_flag = 'N'
AND DATE_FORMAT(report_date, '%Y-%m') = #{date}
AND template_type IN (0, 1, 2, 3)
GROUP BY merchant_id, report_date, template_type) s
ON m.merchant_id = s.merchant_id
AND m.report_date = s.report_date
AND m.scene_type = s.scene_type
WHERE m.deleted_flag = 'N'
AND m.brand_name IN ('享界', '尊界', '尚界', '智界', '问界', '其他')
AND s.merchant_id IS NOT NULL
AND template_type IN (0, 1, 2, 3)
AND DATE_FORMAT(m.report_date, '%Y-%m') = #{date}
GROUP BY m.merchant_id, DATE_FORMAT(m.report_date, '%Y-%m');
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!