Commit 39ce8ed0 by 张富康

feat(perfSalary): 优化有效引荐数统计及批量插入逻辑

- 在Mapper中新增insertOrUpdate与insertOrUpdateBatch方法支持批量插入或更新
- 统计有效引荐数时根据输入参数动态获取统计月份,默认统计上月数据
- 支持对三种场景类型和多个品牌分别统计交车数并封装为插入实体
- 实现批量分批插入数据,避免单次插入量过大导致性能问题
- 重构商户车辆品牌获取逻辑,简化品牌判断及筛选代码
- 优化定时任务支持传入统计月份参数,增强灵活性
- 删除无用导入及多线程异步调用改为单线程处理,提升代码稳定性
1 parent 89b72b4f
package cn.com.glsx.dj.staff.job; package cn.com.glsx.dj.staff.job;
import cn.com.glsx.dj.staff.service.perfSalary.EffectiveReferralReviewQwService;
import cn.com.glsx.dj.staff.service.perfSalary.EffectiveReferralReviewService; import cn.com.glsx.dj.staff.service.perfSalary.EffectiveReferralReviewService;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob; import com.dangdang.ddframe.job.api.simple.SimpleJob;
...@@ -10,7 +9,7 @@ import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf; ...@@ -10,7 +9,7 @@ import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import javax.annotation.Resource; import javax.annotation.Resource;
@Slf4j @Slf4j
@ElasticJobConf(name = "EffectiveReferralReviewStatsJob", cron = "0 0 2 1 * ? ", description = "有效引荐数(交车数)统计", overwrite = false) @ElasticJobConf(name = "EffectiveReferralReviewStatsJob", cron = "0 0 2 1 * ? ", description = "有效引荐数(交车数)统计(默认每月1号执行统计上个月数据) - 可选输入参数统计年月(yyyy-MM)", overwrite = false)
public class EffectiveReferralReviewStatsJob implements SimpleJob { public class EffectiveReferralReviewStatsJob implements SimpleJob {
@Resource @Resource
...@@ -20,7 +19,7 @@ public class EffectiveReferralReviewStatsJob implements SimpleJob { ...@@ -20,7 +19,7 @@ public class EffectiveReferralReviewStatsJob implements SimpleJob {
public void execute(ShardingContext shardingContext) { public void execute(ShardingContext shardingContext) {
log.info("----------------有效引荐数(交车数)统计开始-----------------"); log.info("----------------有效引荐数(交车数)统计开始-----------------");
try { try {
effectiveReferralReviewService.stats(); effectiveReferralReviewService.stats(shardingContext.getJobParameter());
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
......
...@@ -47,4 +47,8 @@ public interface EffectiveReferralReviewMapper extends OreMapper<EffectiveReferr ...@@ -47,4 +47,8 @@ public interface EffectiveReferralReviewMapper extends OreMapper<EffectiveReferr
List<Integer> getAll4sRefMerchantId(); List<Integer> getAll4sRefMerchantId();
List<MerchantBrandReportDTO> getDeliveryCount(@Param("date") String date); List<MerchantBrandReportDTO> getDeliveryCount(@Param("date") String date);
void insertOrUpdate(EffectiveReferralReview effectiveReferralReview);
void insertOrUpdateBatch(List<EffectiveReferralReview> list);
} }
\ No newline at end of file \ No newline at end of file
...@@ -237,4 +237,41 @@ ...@@ -237,4 +237,41 @@
GROUP BY m.merchant_id, DATE_FORMAT(m.report_date, '%Y-%m'); GROUP BY m.merchant_id, DATE_FORMAT(m.report_date, '%Y-%m');
</select> </select>
<insert id="insertOrUpdate">
insert into sal_effective_referral_review (merchant_id,
total_delivery_count,
review_month,
status,
scene_type,
brand_id,
brand_name)
values (#{merchantId},
#{totalDeliveryCount},
#{reviewMonth},
#{status},
#{sceneType},
#{brandId},
#{brandName})
ON DUPLICATE KEY UPDATE
total_delivery_count = VALUES(total_delivery_count);
</insert>
<insert id="insertOrUpdateBatch">
insert into sal_effective_referral_review
(merchant_id, total_delivery_count, review_month, status, scene_type, brand_id, brand_name)
values
<foreach collection="list" item="item" separator=",">
(#{item.merchantId},
#{item.totalDeliveryCount},
#{item.reviewMonth},
#{item.status},
#{item.sceneType},
#{item.brandId},
#{item.brandName})
</foreach>
ON DUPLICATE KEY UPDATE
total_delivery_count = VALUES(total_delivery_count);
</insert>
</mapper> </mapper>
\ No newline at end of file \ 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!