Просмотр исходного кода

定时任务处理,订单统计校正

limin лет назад: 7
Родитель
Сommit
97cdf476d3

+ 5 - 0
src/main/java/com/goafanti/common/dao/TOrderMonthReportMapper.java

@@ -91,4 +91,9 @@ public interface TOrderMonthReportMapper {
 	
 	int updateYearReportData(String d);
 	int insertLastYearOrderData();
+	
+	int insertBySome(TOrderNew on);
+	
+	int updateByMonth(Integer month);
+	int updateByYear();
 }

+ 33 - 4
src/main/java/com/goafanti/common/mapper/TOrderMonthReportMapper.xml

@@ -317,7 +317,7 @@
   </update>
    <!-- 定时插入上月的签单数据 -->
   <insert id="insertLastMonthOrderData" parameterType="java.lang.String">
-  	INSERT INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id) 
+  	REPLACE INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id) 
 	select o.order_type, date_format(DATE_ADD(NOW(),INTERVAL -1 MONTH),'%Y%m'),sum(o.total_amount), sum(o.proof_count), o.salesman_id 
 	from t_order_new o
 	where 1 = 1
@@ -327,9 +327,9 @@
   </insert>
   <!-- 定时插入上一年的数据 -->
   <insert id="insertLastYearOrderData" parameterType="java.lang.String">
-  	INSERT INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id) 
-	select m.`type`, m.`year`, sum(amount), sum(proof_count), salemans_id from t_order_month_report m
-	where m.`year` = year(date_sub(now(),interval 1 year))
+  	REPLACE INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id) 
+	select m.`type`, year(date_sub(now(),interval 1 year)), sum(amount), sum(proof_count), salemans_id from t_order_month_report m
+	where CAST(`month` as CHAR) like concat (year(date_sub(now(),interval 1 year)),'%') 
 	group by m.salemans_id , m.`type`
   </insert>
   <!-- 查看订单统计数据 -->
@@ -459,4 +459,33 @@
 	  	
 	WHERE y.salemans_id = m.salemans_id and y.type = m.type and year = date_format(now(),'%Y')
  </update>
+ 
+ <!-- 新增某人某月某类型的统计数据 -->
+ <insert id="insertBySome" parameterType="com.goafanti.common.model.TOrderNew">
+ 	INSERT INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id) 
+ 	select order_type,  date_format( sign_time , '%Y%m' ), sum(total_amount) as amount, sum(proof_count) as proof_count,   salesman_id  
+	from t_order_new 
+	  	where  
+	  	proof_status = 1 
+	  	and salesman_id = #{salesmanId,jdbcType=VARCHAR} 
+	  	and order_type = #{orderType,jdbcType=INTEGER}
+	  	and date_format( sign_time , '%Y%m' )  = date_format( #{signTime,jdbcType=DATE}, '%Y%m' )
+ </insert>
+ <!-- 更新指定月份的统计数据 -->
+ <insert id="updateByMonth" parameterType="java.lang.Integer">
+ 	REPLACE INTO t_order_month_report(`type`,`month`,amount,proof_count,salemans_id) 
+	select o.order_type, date_format(#{month,jdbcType=INTEGER},'%Y%m'),sum(o.total_amount), sum(o.proof_count), o.salesman_id 
+	from t_order_new o
+	where 1 = 1
+	  and o.proof_status = 1
+	  and date_format( o.sign_time, '%Y%m' ) = #{month,jdbcType=INTEGER}
+	group by o.salesman_id , o.order_type
+ </insert>
+ <!-- 更新本年的年统计数据 -->
+ <insert id="updateByYear">
+ 	REPLACE INTO t_order_year_report(`type`,`year`,amount,proof_count,salemans_id) 
+	select m.`type`, year(now()), sum(amount), sum(proof_count), salemans_id from t_order_month_report m
+	where CAST(`month` as CHAR) like concat (year(now()),'%') 
+	group by m.salemans_id , m.`type`
+ </insert>
 </mapper>

+ 2 - 2
src/main/java/com/goafanti/common/task/MonthReportTask.java

@@ -20,12 +20,12 @@ public class MonthReportTask {
      * 每月1号7点执行任务
      */
     @Scheduled(cron = "0 0 7 1 * ?")
-   //@Scheduled(cron = "0 3 18 * * ?")
+    //@Scheduled(cron = "0 3 16 * * ?")
     public void testTask(){
     	//新增月数据
     	int count = orderReportServiceImpl.insertOrderStatisticsByMonthTask();
     	//更新年数据
-    	int c = orderReportServiceImpl.updateYearReportData();
+    	int c = orderReportServiceImpl.saveYearReportData();
     	
     	LoggerUtils.debug(logger, "统计上月订单【%s】条。", count);
     	LoggerUtils.debug(logger, "更新年订单【%s】条。", c);

+ 29 - 0
src/main/java/com/goafanti/common/task/YearReportTask.java

@@ -0,0 +1,29 @@
+package com.goafanti.common.task;
+
+import javax.annotation.Resource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import com.goafanti.common.utils.LoggerUtils;
+import com.goafanti.order.service.OrderReportService;
+
+@Component
+public class YearReportTask {
+	@Resource
+	private  OrderReportService	orderReportServiceImpl;
+	
+	Logger	logger	= LoggerFactory.getLogger(YearReportTask.class);
+	/**
+     * 每年1月1日0点执行任务
+     */
+	//@Scheduled(cron = "0 10 14 * * ?")
+    @Scheduled(cron = "0 0 0 1 1 ?")
+    public void testTask(){
+    	//新增年数据
+    	int c = orderReportServiceImpl.saveLastYearReportData();
+    	LoggerUtils.debug(logger, "统计去年订单【%s】条。", c);
+    }
+}

+ 7 - 1
src/main/java/com/goafanti/order/service/OrderReportService.java

@@ -49,7 +49,13 @@ public interface OrderReportService {
 	int updateYearReportData();
 	
 	/**
-	 * 每年定时统计订单
+	 * 每年定时统计去年订单
+	 * @return
+	 */
+	int saveLastYearReportData();
+	
+	/**
+	 * 统计今年订单
 	 * @return
 	 */
 	int saveYearReportData();

Разница между файлами не показана из-за своего большого размера
+ 53 - 28
src/main/java/com/goafanti/order/service/impl/FundManagerOrderServiceImpl.java


+ 6 - 1
src/main/java/com/goafanti/order/service/impl/OrderReportServiceImpl.java

@@ -88,13 +88,18 @@ public class OrderReportServiceImpl extends BaseMybatisDao<TOrderMonthReportMapp
 
 	@Override
 	public int updateYearReportData() {
+		
 		return monthReportMapper.updateYearReportData(null);
 	}
 
 	@Override
-	public int saveYearReportData() {
+	public int saveLastYearReportData() {
 		return monthReportMapper.insertLastYearOrderData();
 	}
 	
+	@Override
+	public int saveYearReportData() {
+		return monthReportMapper.updateByYear();
+	}
 	
 }