定时任务-计算销售报表-同步调整,

供应商表 同步调整,
新增 客户销售情况表
This commit is contained in:
king
2026-04-22 15:34:45 +08:00
parent 3865223a14
commit e685531b71
9 changed files with 70 additions and 31 deletions

View File

@@ -23,11 +23,11 @@ public class GrBiSaCustomer implements Serializable
@TableField(value = "USEYEAR") @TableField(value = "USEYEAR")
private Long useyear; private Integer useyear;
@TableField(value = "USEMONTH") @TableField(value = "USEMONTH")
private Long usemonth; private Integer usemonth;
@TableField(value = "CUSTOMID") @TableField(value = "CUSTOMID")

View File

@@ -64,8 +64,8 @@ public interface GrBiSaCustomerMapper extends BaseMapper<GrBiSaCustomer>
public int deleteGrBiSaCustomerByIds(Long[] ids); public int deleteGrBiSaCustomerByIds(Long[] ids);
@DS(value = "#dataSourceType") @DS(value = "#dataSourceType")
List<GrBiSaCustomer> getCustomerList(@Param("dataSourceType") String dataSourceType); List<GrBiSaCustomer> getCustomerList(@Param("dataSourceType") String dataSourceType, @Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
@DS(value = "#dataSourceType") @DS(value = "#dataSourceType")
int deleteOldCustomer(@Param("dataSourceType") String dataSourceType); int deleteOldCustomer(@Param("dataSourceType") String dataSourceType, @Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
} }

View File

@@ -22,35 +22,31 @@ import org.apache.ibatis.annotations.Param;
public interface NewGrBiSaAggMapper extends BaseMapper<NewGrBiSaAgg> public interface NewGrBiSaAggMapper extends BaseMapper<NewGrBiSaAgg>
{ {
List<NewGrBiSaAgg> generateSalesReport(@Param("pastYearMonth") Integer pastYearMonth, List<NewGrBiSaAgg> generateSalesReport(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
@Param("currentYearMonth") Integer currentYearMonth);
int deleteSalesReport(@Param("pastYearMonth") Integer pastYearMonth, int deleteSalesReport(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
@Param("currentYearMonth") Integer currentYearMonth);
int deleteSalesReportMonth(@Param("pastYearMonth") Integer pastYearMonth, int deleteSalesReportMonth(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
@Param("currentYearMonth") Integer currentYearMonth);
int deleteSalesReportYear(@Param("pastYear") Integer pastYear, int deleteSalesReportYear(@Param("pastYear") Integer pastYear,@Param("currentYear") Integer currentYear);
@Param("currentYear") Integer currentYear);
int insertSelectMonth(@Param("pastYearMonth") Integer pastYearMonth, int insertSelectMonth(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
@Param("currentYearMonth") Integer currentYearMonth);
int insertSelectYear(@Param("pastYear") Integer pastYear, int insertSelectYear(@Param("pastYear") Integer pastYear,@Param("currentYear") Integer currentYear);
@Param("currentYear") Integer currentYear);
// void updateThisYearData(); // void updateThisYearData();
// //
// void updateLastYearData(); // void updateLastYearData();
//批量明细的 月度数据 //批量明细的 月度数据
void updateLastMonthSamoney(); void updateLastMonthSamoney(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
void updateYoyMonthData();
void updateComplexCalculateMonth1(); void updateYoyMonthData(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
void updateComplexCalculateMonth2();
void updateComplexCalculateMonth1(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
void updateComplexCalculateMonth2(@Param("pastYearMonth") Integer pastYearMonth,@Param("currentYearMonth") Integer currentYearMonth);
// //
// void updateComplexCalculateYear(); // void updateComplexCalculateYear();
// void updateComplexCalculate3(); // void updateComplexCalculate3();

View File

@@ -114,5 +114,6 @@ public class GrBiPubSupplyServiceImpl extends ServiceImpl<GrBiPubSupplyMapper, G
throw new RuntimeException("批量新增异常"); throw new RuntimeException("批量新增异常");
} }
} }
log.info("保存数量:{}", grBiPubSupplyList.size());
} }
} }

View File

@@ -1,12 +1,15 @@
package com.lideeyunji.core.framework.service.impl; package com.lideeyunji.core.framework.service.impl;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lideeyunji.core.framework.entity.GrBiPubStorage; import com.lideeyunji.core.framework.entity.GrBiPubStorage;
import com.lideeyunji.core.framework.entity.NewGrBiSaAgg;
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant; import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -100,13 +103,41 @@ public class GrBiSaCustomerServiceImpl extends ServiceImpl<GrBiSaCustomerMapper,
@DSTransactional @DSTransactional
@DS(value = "#dataSourceType") @DS(value = "#dataSourceType")
public void generateCustomer(String dataSourceType) { public void generateCustomer(String dataSourceType) {
//获取本地mysql数据库中表中UPDATE_TIME最新的数据
LambdaQueryWrapper<GrBiSaCustomer> queryWrapper = new LambdaQueryWrapper<GrBiSaCustomer>().orderByDesc(GrBiSaCustomer::getUseyear, GrBiSaCustomer::getUsemonth).last("LIMIT 1");
GrBiSaCustomer grBiSaAgg = this.baseMapper.selectOne(queryWrapper);
int lastUserYear = 2022;
int lastUserMonth = 1;
if(grBiSaAgg != null){
lastUserYear = grBiSaAgg.getUseyear();
lastUserMonth = grBiSaAgg.getUsemonth();
}
// 获取当前时间的年和月
LocalDateTime now = LocalDateTime.now();
int currentYear = now.getYear();
int currentMonth = now.getMonthValue();
// 获取二个月前的时间和年月
LocalDateTime threeMonthsAgo = now.minusMonths(2);
int pastYear = threeMonthsAgo.getYear();
int pastMonth = threeMonthsAgo.getMonthValue();
log.info("最后更新的年月:{}年{}月", lastUserYear, lastUserMonth);
log.info("当前:{}年{}月", currentYear, currentMonth);
log.info("二个月前:{}年{}月", pastYear, pastMonth);
if (lastUserYear < pastYear || (lastUserYear == pastYear && lastUserMonth < pastMonth)) {
pastYear = lastUserYear;
pastMonth = lastUserMonth;
}
log.info("开始时间:{}年{}月, 结束时间:{}年{}月", pastYear, pastMonth, currentYear, currentMonth);
// 获取数据 // 获取数据
List<GrBiSaCustomer> grBiSaCustomerList = this.baseMapper.getCustomerList(lideeYunJiBaseConstant.DS_ORACLE_GRYYBI); List<GrBiSaCustomer> grBiSaCustomerList = this.baseMapper.getCustomerList(lideeYunJiBaseConstant.DS_ORACLE_GRYYBI,pastYear * 100 + pastMonth, currentYear * 100 + currentMonth);
if (CollUtil.isEmpty(grBiSaCustomerList)) { if (CollUtil.isEmpty(grBiSaCustomerList)) {
return; return;
} }
//保存数据 //保存数据
int reNum = this.baseMapper.deleteOldCustomer(lideeYunJiBaseConstant.DS_ERP_BI_DATA); int reNum = this.baseMapper.deleteOldCustomer(lideeYunJiBaseConstant.DS_ERP_BI_DATA, pastYear * 100 + pastMonth, currentYear * 100 + currentMonth);
log.info("删除数量:{}", reNum); log.info("删除数量:{}", reNum);
for (GrBiSaCustomer grBiPubStorage : grBiSaCustomerList) { for (GrBiSaCustomer grBiPubStorage : grBiSaCustomerList) {
int re = this.baseMapper.insert(grBiPubStorage); int re = this.baseMapper.insert(grBiPubStorage);
@@ -114,5 +145,6 @@ public class GrBiSaCustomerServiceImpl extends ServiceImpl<GrBiSaCustomerMapper,
throw new RuntimeException("批量新增异常"); throw new RuntimeException("批量新增异常");
} }
} }
log.info("保存数量:{}", grBiSaCustomerList.size());
} }
} }

View File

@@ -114,5 +114,6 @@ public class GrBiSaOrderServiceImpl extends ServiceImpl<GrBiSaOrderMapper, GrBiS
throw new RuntimeException("批量新增异常"); throw new RuntimeException("批量新增异常");
} }
} }
log.info("保存数量:{}", grBiSaOrderList.size());
} }
} }

View File

@@ -79,10 +79,10 @@ public class NewGrBiSaAggServiceImpl extends ServiceImpl<NewGrBiSaAggMapper, New
} }
//保存数据 //保存数据
removeAndSaveBatch(pastYear, pastMonth, currentYear, currentMonth, grBiSaSetdtlList); removeAndSaveBatch(pastYear, pastMonth, currentYear, currentMonth, grBiSaSetdtlList);
this.baseMapper.updateYoyMonthData(); this.baseMapper.updateYoyMonthData(pastYear * 100 + pastMonth, currentYear * 100 + currentMonth);
this.baseMapper.updateLastMonthSamoney(); this.baseMapper.updateLastMonthSamoney(pastYear * 100 + pastMonth, currentYear * 100 + currentMonth);
this.baseMapper.updateComplexCalculateMonth1(); this.baseMapper.updateComplexCalculateMonth1(pastYear * 100 + pastMonth, currentYear * 100 + currentMonth);
this.baseMapper.updateComplexCalculateMonth2(); this.baseMapper.updateComplexCalculateMonth2(pastYear * 100 + pastMonth, currentYear * 100 + currentMonth);
// this.baseMapper.updateThisYearData(); // this.baseMapper.updateThisYearData();
// this.baseMapper.updateLastYearData(); // this.baseMapper.updateLastYearData();

View File

@@ -74,6 +74,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="getCustomerList" resultType="com.lideeyunji.core.framework.entity.GrBiSaCustomer"> <select id="getCustomerList" resultType="com.lideeyunji.core.framework.entity.GrBiSaCustomer">
<include refid="selectGrBiSaCustomerVo"/> <include refid="selectGrBiSaCustomerVo"/>
<where>
(USEYEAR * 100 + USEMONTH) BETWEEN #{pastYearMonth} AND #{currentYearMonth}
</where>
</select> </select>
<insert id="insertGrBiSaCustomer" parameterType="com.lideeyunji.core.framework.entity.GrBiSaCustomer"> <insert id="insertGrBiSaCustomer" parameterType="com.lideeyunji.core.framework.entity.GrBiSaCustomer">
@@ -180,5 +183,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete> </delete>
<delete id="deleteOldCustomer"> <delete id="deleteOldCustomer">
delete from gr_bi_sa_customer delete from gr_bi_sa_customer
<where>
(USEYEAR * 100 + USEMONTH) BETWEEN #{pastYearMonth} AND #{currentYearMonth}
</where>
</delete> </delete>
</mapper> </mapper>

View File

@@ -429,7 +429,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SET a.yoy_month_sa_qty = COALESCE ( b.yoy_month_sa_qty, 0 ), SET a.yoy_month_sa_qty = COALESCE ( b.yoy_month_sa_qty, 0 ),
a.yoy_month_sa_money = COALESCE ( b.yoy_month_sa_money, 0 ), a.yoy_month_sa_money = COALESCE ( b.yoy_month_sa_money, 0 ),
a.yoy_month_cost = COALESCE ( b.yoy_month_cost, 0 ), a.yoy_month_cost = COALESCE ( b.yoy_month_cost, 0 ),
a.yoy_month_profit = COALESCE ( b.yoy_month_profit, 0 ); a.yoy_month_profit = COALESCE ( b.yoy_month_profit, 0 )
where (a.use_year * 100 + a.use_month) BETWEEN #{pastYearMonth} AND #{currentYearMonth};
</update> </update>
<update id="updateLastMonthSamoney"> <update id="updateLastMonthSamoney">
@@ -483,7 +484,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
current_month.last_month_sa_qty = last_month_data.current_month_sa_qty, -- 上月销量 current_month.last_month_sa_qty = last_month_data.current_month_sa_qty, -- 上月销量
current_month.last_month_sa_money = last_month_data.current_month_sa_money, -- 上月销售金额 current_month.last_month_sa_money = last_month_data.current_month_sa_money, -- 上月销售金额
current_month.last_month_cost = last_month_data.current_month_cost, -- 上月销售成本 current_month.last_month_cost = last_month_data.current_month_cost, -- 上月销售成本
current_month.last_month_profit = last_month_data.current_month_profit; -- 上月毛利额 current_month.last_month_profit = last_month_data.current_month_profit -- 上月毛利额
where (current_month.use_year * 100 + current_month.use_month) BETWEEN #{pastYearMonth} AND #{currentYearMonth};
</update> </update>
<update id="updateLastYearData"> <update id="updateLastYearData">
UPDATE new_gr_bi_sa_agg_year_count a UPDATE new_gr_bi_sa_agg_year_count a
@@ -535,8 +537,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
UPDATE new_gr_bi_sa_agg UPDATE new_gr_bi_sa_agg
SET SET
this_month_profit_rate = CASE WHEN last_month_sa_money = 0 or last_month_sa_money is null THEN this_month_profit_rate = CASE WHEN last_month_sa_money = 0 or last_month_sa_money is null THEN
IF(this_month_profit > 0, 100, 0) ELSE this_month_profit/ last_month_sa_money * 100 END; IF(this_month_profit > 0, 100, 0) ELSE this_month_profit/ last_month_sa_money * 100 END
where (use_year * 100 + use_month) BETWEEN #{pastYearMonth} AND #{currentYearMonth};
</update> </update>
<update id="updateComplexCalculateMonth2"> <update id="updateComplexCalculateMonth2">
@@ -557,7 +559,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) b ON b.use_year = a.use_year ) b ON b.use_year = a.use_year
AND b.use_month = a.use_month AND b.use_month = a.use_month
SET a.this_month_sa_money_share = COALESCE (ROUND( a.this_month_sa_money/b.this_month_sa_money_sum * 100, 2), 0 ), SET a.this_month_sa_money_share = COALESCE (ROUND( a.this_month_sa_money/b.this_month_sa_money_sum * 100, 2), 0 ),
a.this_month_profit_share = COALESCE (ROUND( a.this_month_profit/b.this_month_profit_sum * 100, 2), 0 ); a.this_month_profit_share = COALESCE (ROUND( a.this_month_profit/b.this_month_profit_sum * 100, 2), 0 )
where (a.use_year * 100 + a.use_month) BETWEEN #{pastYearMonth} AND #{currentYearMonth};
</update> </update>
<update id="updateComplexCalculateYear"> <update id="updateComplexCalculateYear">