Commit ecc4de75 by 蔡茜

Merge remote-tracking branch 'origin/v5.5.1' into v5.5.1

2 parents dd3fb8ec 82ea0f67
......@@ -24,10 +24,10 @@ public class BeanConfig {
@Primary
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(200);
taskExecutor.setMaxPoolSize(400);
taskExecutor.setQueueCapacity(10002);
taskExecutor.setKeepAliveSeconds(300);
taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
taskExecutor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 2);
taskExecutor.setQueueCapacity(1000);
taskExecutor.setKeepAliveSeconds(600);
return taskExecutor;
}
......
package cn.com.glsx.dj.peanalysis.job;
import cn.com.glsx.dj.peanalysis.service.BusinessIntelligenceService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource;
@Slf4j
@ElasticJobConf(name = "HandlerExceptionDataJob", cron = "0 0 0 1 1 ? 2100", description = "处理4s店业务历史数据", overwrite = false)
public class HandlerExceptionDataJob implements SimpleJob {
@Resource
private BusinessIntelligenceService businessIntelligenceService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------处理4s店业务历史数据开始-----------------");
try {
businessIntelligenceService.retryDBFailedRecords();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------处理4s店业务历史数据结束-----------------");
}
}
package cn.com.glsx.dj.peanalysis.job;
import cn.com.glsx.dj.peanalysis.service.BusinessIntelligenceService;
import cn.hutool.core.util.StrUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource;
@Slf4j
@ElasticJobConf(name = "HandlerHistoryDataJob", cron = "0 0 0 1 1 ? 2100", description = "处理4s店业务异常数据", overwrite = false)
public class HandlerHistoryDataJob implements SimpleJob {
@Resource
private BusinessIntelligenceService businessIntelligenceService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------处理4s店业务异常数据开始-----------------");
try {
String parameters = shardingContext.getJobParameter();
if (StrUtil.isBlank(parameters)) {
businessIntelligenceService.retryDBFailedRecords();
} else {
// 按逗号分隔层 merchantId,statDate
String[] split = parameters.split(",");
Integer merchantId = Integer.valueOf(split[0].trim());
String statDate = split[1].trim();
businessIntelligenceService.retryRecordsForWrite(merchantId, statDate);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------处理4s店业务异常数据结束-----------------");
}
}
package cn.com.glsx.dj.peanalysis.job;
import cn.com.glsx.dj.peanalysis.service.BusinessIntelligenceService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource;
import java.util.Date;
@Slf4j
@ElasticJobConf(name = "HandlerSelfDailyDataJob", cron = "0 30 1 * * ?", description = "处理4s店业务自定义返回数据,默认前一天", overwrite = false)
public class HandlerSelfDailyDataJob implements SimpleJob {
@Resource
private BusinessIntelligenceService businessIntelligenceService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------处理4s店业务自定义返回数据,默认前一天-开始-----------------");
try {
String parameters = shardingContext.getJobParameter();
if (StrUtil.isBlank(parameters)) {
businessIntelligenceService.selfDailyDataHandle(null, null);
} else {
String[] split = parameters.split(",");
String startDateStr = split[0].trim();
String endDateStr = split[1].trim();
// hutool 判断两个时间是否合法 startDate要小于等于endDate 并且endDate小于等于昨天
Date startDate = DateUtil.parse(startDateStr, "yyyy-MM-dd");
Date endDate = DateUtil.parse(endDateStr, "yyyy-MM-dd");
// startDate <= endDate
if (DateUtil.compare(startDate, endDate) > 0) {
log.error("参数错误,startDate要小于等于endDate");
return;
}
// endDate <= yesterday
Date yesterday = DateUtil.parse(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"));
if (DateUtil.compare(endDate, yesterday) > 0) {
log.error("参数错误,endDate要小于等于昨天");
return;
}
businessIntelligenceService.selfDailyDataHandle(startDateStr, endDateStr);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------处理4s店业务自定义返回数据,默认前一天-结束-----------------");
}
}
......@@ -18,13 +18,13 @@ public class UpdateMerchantJob implements SimpleJob {
@Override
public void execute(ShardingContext shardingContext) {
log.info("----------------更新不同业务第一笔订单时间-----------------");
log.info("----------------更新不同业务第一笔订单时间开始-----------------");
try {
updateMerchantService.updateFirstOrderTime(shardingContext.getJobParameter());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("----------------更新不同业务第一笔订单时间-----------------");
log.info("----------------更新不同业务第一笔订单时间结束-----------------");
}
}
......@@ -49,6 +49,18 @@ public interface BusinessIntelligenceMapper {
List<BusinessOrderStatusEntity> getBusinessOrders(@Param("merchantIds") List<Integer> merchantIds, @Param("statDates") List<Date> statDates);
/**
* 批量获取指定商户列表在指定日期范围内的业务订单状态
*
* @param merchantIds 商户ID列表
* @param startDate 开始统计日期
* @param endDate 结束统计日期
* @return 业务订单状态实体列表
*/
List<BusinessOrderStatusEntity> getBusinessOrdersDateRange(@Param("merchantIds") List<Integer> merchantIds,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
/**
* 单条插入BI记录
*
* @param record BI记录
......
......@@ -9,6 +9,7 @@ import cn.com.glsx.dj.peanalysis.service.UpdateMerchantService;
import cn.com.glsx.dj.peanalysis.service.UsedCarDataStatsService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
......@@ -149,13 +150,31 @@ public class UsedCarDataStatsRemoteImpl implements UsedCarDataStatsRemote {
}
/**
* 处理历史数据
* 处理业务数据
*/
@Override
public RpcResponse<Boolean> generateBusinessIntelligenceData() {
try {
businessIntelligenceService.totalDataHandle();
// businessIntelligenceService.dailyDataHandle();
// 全量数据处理
// businessIntelligenceService.totalDataHandle();
// 按天数据处理
// String parameters = "2023-04-28,2024-04-28";
String parameters = "";
if (StrUtil.isBlank(parameters)) {
businessIntelligenceService.selfDailyDataHandle(null, null);
} else {
String[] split = parameters.split(",");
businessIntelligenceService.selfDailyDataHandle(split[0], split[1]);
}
// 重试库中异常记录
// businessIntelligenceService.retryDBFailedRecords();
// 指定商户指定日期重试
// String parameters = "44217659,2024-04-28";
// if (StrUtil.isNotBlank(parameters)) {
// // 按逗号分隔层 merchantId,statDate
// String[] split = parameters.split(",");
// businessIntelligenceService.retryRecordsForWrite(Integer.valueOf(split[0]), split[1]);
// }
return RpcResponse.success(true);
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
......
......@@ -22,10 +22,13 @@
FROM dj_car_life_goods_order go
LEFT JOIN dj_car_life_pay_order po
ON go.order_code = po.order_code AND po.success_date IS NOT NULL AND po.deleted_flag = 'N'
LEFT JOIN dj_car_life_service_merchant sm ON go.merchant_id = sm.merchant_id AND sm.deleted_flag = 'N'
WHERE
go.scene_type = 0
AND go.business_type = 1
AND go.deleted_flag = 'N'
AND sm.merchant_id IS NOT NULL
AND po.success_date IS NOT NULL
<if test = "merchantIds != null and merchantIds.size() > 0">
AND go.merchant_id IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
......@@ -43,10 +46,13 @@
FROM dj_car_life_goods_order go
LEFT JOIN dj_car_life_pay_order po
ON go.order_code = po.order_code AND po.success_date IS NOT NULL AND po.deleted_flag = 'N'
LEFT JOIN dj_car_life_service_merchant sm ON go.merchant_id = sm.merchant_id AND sm.deleted_flag = 'N'
WHERE
go.scene_type = 0
AND go.business_type = 2
AND go.deleted_flag = 'N'
AND sm.merchant_id IS NOT NULL
AND po.success_date IS NOT NULL
<if test = "merchantIds != null and merchantIds.size() > 0">
AND go.merchant_id IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
......@@ -64,9 +70,12 @@
FROM dj_car_life_goods_order go
LEFT JOIN dj_car_life_pay_order po
ON go.order_code = po.order_code AND po.success_date IS NOT NULL AND po.deleted_flag = 'N'
LEFT JOIN dj_car_life_service_merchant sm ON go.merchant_id = sm.merchant_id AND sm.deleted_flag = 'N'
WHERE
go.scene_type = 1
AND go.deleted_flag = 'N'
AND sm.merchant_id IS NOT NULL
AND po.success_date IS NOT NULL
<if test = "merchantIds != null and merchantIds.size() > 0">
AND go.merchant_id IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
......@@ -83,6 +92,7 @@
v.source_store AS merchant_id,
MIN(v.purchase_time) AS first_order_date
FROM vcp_car_manage_info v
LEFT JOIN dj_car_life_service_merchant sm ON v.source_store = sm.merchant_id AND sm.deleted_flag = 'N'
WHERE
v.deleted_flag = 'N'
<if test = "merchantIds != null and merchantIds.size() > 0">
......@@ -92,6 +102,7 @@
</foreach>
</if>
and v.purchase_time is not null
AND sm.merchant_id IS NOT NULL
GROUP BY v.source_store
) AS combined
GROUP BY merchant_id
......@@ -305,6 +316,124 @@
) AS result
</select>
<select id="getBusinessOrdersDateRange" resultType="cn.com.glsx.dj.peanalysis.dto.job.BusinessOrderStatusEntity">
SELECT
merchant_id as merchantId,
stat_date as statDate,
benefits_order AS hasBenefits,
ext_warranty_order AS hasExtWarranty,
light_mod_order AS hasLightMod,
used_car_order AS hasUsedCar
FROM (
SELECT
merchant_id,
stat_date,
MAX(CASE WHEN business_type = 'BENEFITS' THEN has_order END) AS benefits_order,
MAX(CASE WHEN business_type = 'EXT_WARRANTY' THEN has_order END) AS ext_warranty_order,
MAX(CASE WHEN business_type = 'LIGHT_MOD' THEN has_order END) AS light_mod_order,
MAX(CASE WHEN business_type = 'USED_CAR' THEN has_order END) AS used_car_order
FROM (
<!-- 权益业务 -->
SELECT
go.merchant_id,
DATE(po.success_date) AS stat_date,
'BENEFITS' AS business_type,
1 AS has_order
FROM dj_car_life_goods_order go
JOIN dj_car_life_pay_order po
ON go.order_code = po.order_code
WHERE
go.scene_type = 0
AND go.business_type = 1
AND go.deleted_flag = 'N'
AND po.deleted_flag = 'N'
AND go.merchant_id IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
#{id}
</foreach>
<!-- 修改:使用时间范围查询代替IN子句 -->
<![CDATA[
AND DATE(po.success_date) >= #{startDate}
AND DATE(po.success_date) <= #{endDate}
]]>
UNION ALL
<!-- 延保业务 -->
SELECT
go.merchant_id,
DATE(po.success_date) AS stat_date,
'EXT_WARRANTY' AS business_type,
1 AS has_order
FROM dj_car_life_goods_order go
JOIN dj_car_life_pay_order po
ON go.order_code = po.order_code
WHERE
go.scene_type = 0
AND go.business_type = 2
AND go.deleted_flag = 'N'
AND po.deleted_flag = 'N'
AND go.merchant_id IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
#{id}
</foreach>
<!-- 修改:使用时间范围查询代替IN子句 -->
<![CDATA[
AND DATE(po.success_date) >= #{startDate}
AND DATE(po.success_date) <= #{endDate}
]]>
UNION ALL
<!-- 轻改业务 -->
SELECT
go.merchant_id,
DATE(po.success_date) AS stat_date,
'LIGHT_MOD' AS business_type,
1 AS has_order
FROM dj_car_life_goods_order go
JOIN dj_car_life_pay_order po
ON go.order_code = po.order_code
WHERE
go.scene_type = 1
AND go.deleted_flag = 'N'
AND po.deleted_flag = 'N'
AND go.merchant_id IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
#{id}
</foreach>
<!-- 修改:使用时间范围查询代替IN子句 -->
<![CDATA[
AND DATE(po.success_date) >= #{startDate}
AND DATE(po.success_date) <= #{endDate}
]]>
UNION ALL
<!-- 二手车业务 -->
SELECT
v.source_store AS merchant_id,
DATE(v.purchase_time) AS stat_date,
'USED_CAR' AS business_type,
1 AS has_order
FROM vcp_car_manage_info v
WHERE
v.deleted_flag = 'N'
AND v.source_store IN
<foreach item="id" collection="merchantIds" open="(" separator="," close=")">
#{id}
</foreach>
<!-- 修改:使用时间范围查询代替IN子句 -->
<![CDATA[
AND DATE(v.purchase_time) >= #{startDate}
AND DATE(v.purchase_time) <= #{endDate}
]]>
) AS combined
GROUP BY merchant_id, stat_date
) AS result
</select>
<insert id="insertBiRecord" parameterType="cn.com.glsx.dj.peanalysis.dto.job.BiRecord">
INSERT INTO dj_car_life_service_merchant_bi (
merchant_id,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!