Commit cfff1274 by huluobin

头程费用计算

亚马逊广告
parent 56e48859
...@@ -46,10 +46,10 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob { ...@@ -46,10 +46,10 @@ public class AmazonAdGenerateReportIdJob implements SimpleJob {
dcBaseCompanyAccountList.forEach(dcBaseCompanyAccount -> { dcBaseCompanyAccountList.forEach(dcBaseCompanyAccount -> {
try { try {
//
LocalDateTime reportDate = LocalDateTime.now().minusDays(1).minusHours(12);
// LocalDateTime reportDate = LocalDateTime.now().minusDays(1).minusHours(12); // LocalDateTime reportDate = LocalDateTime.of(2020, 8, 22, 0, 0);
LocalDateTime reportDate =LocalDateTime.of(2020,8,21,0,0);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("reportDate", reportDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); jsonObject.put("reportDate", reportDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
jsonObject.put("metrics", propertiesUtil.getPropertyAsString("METRICS")); jsonObject.put("metrics", propertiesUtil.getPropertyAsString("METRICS"));
......
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.job.CompanyAccountSyncJob;
import com.bailuntec.job.CompanyInfoSyncJob;
import com.bailuntec.job.CompanyStaffSyncJob;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
public class CompanyTest {
@Test
public void test() {
CompanyInfoSyncJob skuSyncJob = new CompanyInfoSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("", 0, 100, 1, 1, LocalDateTime.now().minusMonths(1), LocalDateTime.now().minusDays(29)));
}
@Test
public void test2() {
CompanyStaffSyncJob skuSyncJob = new CompanyStaffSyncJob();
skuSyncJob.executeJob(null, new JobPointLog("", 0, 100, 1, 1, LocalDateTime.now().minusMonths(1), LocalDateTime.now().minusDays(29)));
}
@Test
public void test3() {
CompanyAccountSyncJob skuSyncJob = new CompanyAccountSyncJob();
skuSyncJob.execute(null);
}
}
...@@ -139,5 +139,5 @@ public interface DcBaseCostFirstMapper { ...@@ -139,5 +139,5 @@ public interface DcBaseCostFirstMapper {
* @param pageOffset 分页参数 * @param pageOffset 分页参数
* @return 未计算的基础头程费用 * @return 未计算的基础头程费用
*/ */
List<DcBaseCostFirst> listUnCalc(@Param("pageStart") Integer pageStart, @Param("pageOffset") Integer pageOffset); List<DcBaseCostFirst> dcBaseCostGroupList(@Param("pageStart") Integer pageStart, @Param("pageOffset") Integer pageOffset);
} }
...@@ -834,7 +834,7 @@ ...@@ -834,7 +834,7 @@
# and has_calculation = 0 # and has_calculation = 0
GROUP BY channel_order_id, transfer_order_id, box_id, warehouse_code) tb; GROUP BY channel_order_id, transfer_order_id, box_id, warehouse_code) tb;
</select> </select>
<select id="listUnCalc" resultType="com.bailuntec.domain.entity.DcBaseCostFirst"> <select id="dcBaseCostGroupList" resultType="com.bailuntec.domain.entity.DcBaseCostFirst">
SELECT t2.* SELECT t2.*
from ( from (
SELECT channel_order_id, transfer_order_id, box_id, warehouse_code SELECT channel_order_id, transfer_order_id, box_id, warehouse_code
...@@ -857,7 +857,6 @@ ...@@ -857,7 +857,6 @@
and transfer_order_id = #{transferOrderId} and transfer_order_id = #{transferOrderId}
and box_id = #{boxId} and box_id = #{boxId}
and warehouse_code = #{warehouseCode} and warehouse_code = #{warehouseCode}
# and has_calculation = 0
</update> </update>
......
...@@ -121,4 +121,12 @@ public interface DcMidCostFirstMapper { ...@@ -121,4 +121,12 @@ public interface DcMidCostFirstMapper {
* @project https://github.com/itfsw/mybatis-generator-plugin * @project https://github.com/itfsw/mybatis-generator-plugin
*/ */
int upsertSelective(DcMidCostFirst record); int upsertSelective(DcMidCostFirst record);
}
\ No newline at end of file
/**
* 批量插入更细
*
* @param dcMidCostFirstList
*/
void upsertBatch(@Param("lists") List<DcMidCostFirst> dcMidCostFirstList);
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bailuntec.mapper.DcMidCostFirstMapper"> <mapper namespace="com.bailuntec.mapper.DcMidCostFirstMapper">
<resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcMidCostFirst"> <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcMidCostFirst">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="cost_first" jdbcType="DECIMAL" property="costFirst" /> <result column="cost_first" jdbcType="DECIMAL" property="costFirst"/>
<result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku" /> <result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku"/>
<result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode" /> <result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode"/>
<result column="company_id" jdbcType="INTEGER" property="companyId" /> <result column="company_id" jdbcType="INTEGER" property="companyId"/>
<result column="has_calculation" jdbcType="BIT" property="hasCalculation" /> <result column="has_calculation" jdbcType="BIT" property="hasCalculation"/>
<result column="cost_count" jdbcType="INTEGER" property="costCount" /> <result column="cost_count" jdbcType="INTEGER" property="costCount"/>
<result column="has_config" jdbcType="BIT" property="hasConfig" /> <result column="has_config" jdbcType="BIT" property="hasConfig"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
--> -->
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid"> <if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")"> <trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion"> <foreach collection="criteria.criteria" item="criterion">
<choose> <choose>
<when test="criterion.noValue"> <when test="criterion.noValue">
and ${criterion.condition} and ${criterion.condition}
</when> </when>
<when test="criterion.singleValue"> <when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.betweenValue"> <when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.listValue"> <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="("
#{listItem} separator=",">
</foreach> #{listItem}
</when> </foreach>
</choose> </when>
</choose>
</foreach>
</trim>
</if>
</foreach> </foreach>
</trim> </where>
</if> </sql>
</foreach> <sql id="Update_By_Example_Where_Clause">
</where> <!--
</sql> WARNING - @mbg.generated
<sql id="Update_By_Example_Where_Clause"> This element is automatically generated by MyBatis Generator, do not modify.
<!-- -->
WARNING - @mbg.generated <where>
This element is automatically generated by MyBatis Generator, do not modify. <foreach collection="example.oredCriteria" item="criteria" separator="or">
--> <if test="criteria.valid">
<where> <trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="example.oredCriteria" item="criteria" separator="or"> <foreach collection="criteria.criteria" item="criterion">
<if test="criteria.valid"> <choose>
<trim prefix="(" prefixOverrides="and" suffix=")"> <when test="criterion.noValue">
<foreach collection="criteria.criteria" item="criterion"> and ${criterion.condition}
<choose> </when>
<when test="criterion.noValue"> <when test="criterion.singleValue">
and ${criterion.condition} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.singleValue"> <when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.betweenValue"> <when test="criterion.listValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition}
</when> <foreach close=")" collection="criterion.value" item="listItem" open="("
<when test="criterion.listValue"> separator=",">
and ${criterion.condition} #{listItem}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> </foreach>
#{listItem} </when>
</foreach> </choose>
</when> </foreach>
</choose> </trim>
</if>
</foreach> </foreach>
</trim> </where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, cost_first, bailun_sku, warehouse_code, company_id, has_calculation, cost_count,
has_config
</sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if> </if>
</foreach> <include refid="Base_Column_List"/>
</where> from dc_mid_cost_first
</sql> <if test="_parameter != null">
<sql id="Base_Column_List"> <include refid="Example_Where_Clause"/>
<!-- </if>
WARNING - @mbg.generated <if test="orderByClause != null">
This element is automatically generated by MyBatis Generator, do not modify. order by ${orderByClause}
--> </if>
id, cost_first, bailun_sku, warehouse_code, company_id, has_calculation, cost_count, <if test="rows != null">
has_config <if test="offset != null">
</sql> limit ${offset}, ${rows}
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample" resultMap="BaseResultMap"> </if>
<!-- <if test="offset == null">
WARNING - @mbg.generated limit ${rows}
This element is automatically generated by MyBatis Generator, do not modify. </if>
--> </if>
select </select>
<if test="distinct"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
distinct <!--
</if> WARNING - @mbg.generated
<include refid="Base_Column_List" /> This element is automatically generated by MyBatis Generator, do not modify.
from dc_mid_cost_first -->
<if test="_parameter != null"> select
<include refid="Example_Where_Clause" /> <include refid="Base_Column_List"/>
</if> from dc_mid_cost_first
<if test="orderByClause != null"> where id = #{id,jdbcType=INTEGER}
order by ${orderByClause} </select>
</if> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<if test="rows != null"> <!--
<if test="offset != null"> WARNING - @mbg.generated
limit ${offset}, ${rows} This element is automatically generated by MyBatis Generator, do not modify.
</if> -->
<if test="offset == null"> delete from dc_mid_cost_first
limit ${rows} where id = #{id,jdbcType=INTEGER}
</if> </delete>
</if> <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample">
</select> <!--
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> WARNING - @mbg.generated
<!-- This element is automatically generated by MyBatis Generator, do not modify.
WARNING - @mbg.generated -->
This element is automatically generated by MyBatis Generator, do not modify. delete from dc_mid_cost_first
--> <if test="_parameter != null">
select <include refid="Example_Where_Clause"/>
<include refid="Base_Column_List" /> </if>
from dc_mid_cost_first </delete>
where id = #{id,jdbcType=INTEGER} <insert id="insert" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
</select> <!--
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> WARNING - @mbg.generated
<!-- This element is automatically generated by MyBatis Generator, do not modify.
WARNING - @mbg.generated -->
This element is automatically generated by MyBatis Generator, do not modify. insert into dc_mid_cost_first (id, cost_first, bailun_sku,
--> warehouse_code, company_id, has_calculation,
delete from dc_mid_cost_first cost_count, has_config)
where id = #{id,jdbcType=INTEGER} values (#{id,jdbcType=INTEGER}, #{costFirst,jdbcType=DECIMAL}, #{bailunSku,jdbcType=VARCHAR},
</delete> #{warehouseCode,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER}, #{hasCalculation,jdbcType=BIT},
<delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample"> #{costCount,jdbcType=INTEGER}, #{hasConfig,jdbcType=BIT})
<!-- </insert>
WARNING - @mbg.generated <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
This element is automatically generated by MyBatis Generator, do not modify. <!--
--> WARNING - @mbg.generated
delete from dc_mid_cost_first This element is automatically generated by MyBatis Generator, do not modify.
<if test="_parameter != null"> -->
<include refid="Example_Where_Clause" /> insert into dc_mid_cost_first
</if> <trim prefix="(" suffix=")" suffixOverrides=",">
</delete> <if test="id != null">
<insert id="insert" parameterType="com.bailuntec.domain.entity.DcMidCostFirst"> id,
<!-- </if>
WARNING - @mbg.generated <if test="costFirst != null">
This element is automatically generated by MyBatis Generator, do not modify. cost_first,
--> </if>
insert into dc_mid_cost_first (id, cost_first, bailun_sku, <if test="bailunSku != null">
warehouse_code, company_id, has_calculation, bailun_sku,
cost_count, has_config) </if>
values (#{id,jdbcType=INTEGER}, #{costFirst,jdbcType=DECIMAL}, #{bailunSku,jdbcType=VARCHAR}, <if test="warehouseCode != null">
#{warehouseCode,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER}, #{hasCalculation,jdbcType=BIT}, warehouse_code,
#{costCount,jdbcType=INTEGER}, #{hasConfig,jdbcType=BIT}) </if>
</insert> <if test="companyId != null">
<insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcMidCostFirst"> company_id,
<!-- </if>
WARNING - @mbg.generated <if test="hasCalculation != null">
This element is automatically generated by MyBatis Generator, do not modify. has_calculation,
--> </if>
insert into dc_mid_cost_first <if test="costCount != null">
<trim prefix="(" suffix=")" suffixOverrides=","> cost_count,
<if test="id != null"> </if>
id, <if test="hasConfig != null">
</if> has_config,
<if test="costFirst != null"> </if>
cost_first, </trim>
</if> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="bailunSku != null"> <if test="id != null">
bailun_sku, #{id,jdbcType=INTEGER},
</if> </if>
<if test="warehouseCode != null"> <if test="costFirst != null">
warehouse_code, #{costFirst,jdbcType=DECIMAL},
</if> </if>
<if test="companyId != null"> <if test="bailunSku != null">
company_id, #{bailunSku,jdbcType=VARCHAR},
</if> </if>
<if test="hasCalculation != null"> <if test="warehouseCode != null">
has_calculation, #{warehouseCode,jdbcType=VARCHAR},
</if> </if>
<if test="costCount != null"> <if test="companyId != null">
cost_count, #{companyId,jdbcType=INTEGER},
</if> </if>
<if test="hasConfig != null"> <if test="hasCalculation != null">
has_config, #{hasCalculation,jdbcType=BIT},
</if> </if>
</trim> <if test="costCount != null">
<trim prefix="values (" suffix=")" suffixOverrides=","> #{costCount,jdbcType=INTEGER},
<if test="id != null"> </if>
#{id,jdbcType=INTEGER}, <if test="hasConfig != null">
</if> #{hasConfig,jdbcType=BIT},
<if test="costFirst != null"> </if>
#{costFirst,jdbcType=DECIMAL}, </trim>
</if> </insert>
<if test="bailunSku != null"> <select id="countByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample"
#{bailunSku,jdbcType=VARCHAR}, resultType="java.lang.Long">
</if> <!--
<if test="warehouseCode != null"> WARNING - @mbg.generated
#{warehouseCode,jdbcType=VARCHAR}, This element is automatically generated by MyBatis Generator, do not modify.
</if> -->
<if test="companyId != null"> select count(*) from dc_mid_cost_first
#{companyId,jdbcType=INTEGER}, <if test="_parameter != null">
</if> <include refid="Example_Where_Clause"/>
<if test="hasCalculation != null"> </if>
#{hasCalculation,jdbcType=BIT}, </select>
</if> <update id="updateByExampleSelective" parameterType="map">
<if test="costCount != null"> <!--
#{costCount,jdbcType=INTEGER}, WARNING - @mbg.generated
</if> This element is automatically generated by MyBatis Generator, do not modify.
<if test="hasConfig != null"> -->
#{hasConfig,jdbcType=BIT}, update dc_mid_cost_first
</if> <set>
</trim> <if test="record.id != null">
</insert> id = #{record.id,jdbcType=INTEGER},
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample" resultType="java.lang.Long"> </if>
<!-- <if test="record.costFirst != null">
WARNING - @mbg.generated cost_first = #{record.costFirst,jdbcType=DECIMAL},
This element is automatically generated by MyBatis Generator, do not modify. </if>
--> <if test="record.bailunSku != null">
select count(*) from dc_mid_cost_first bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
<if test="_parameter != null"> </if>
<include refid="Example_Where_Clause" /> <if test="record.warehouseCode != null">
</if> warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
</select> </if>
<update id="updateByExampleSelective" parameterType="map"> <if test="record.companyId != null">
<!-- company_id = #{record.companyId,jdbcType=INTEGER},
WARNING - @mbg.generated </if>
This element is automatically generated by MyBatis Generator, do not modify. <if test="record.hasCalculation != null">
--> has_calculation = #{record.hasCalculation,jdbcType=BIT},
update dc_mid_cost_first </if>
<set> <if test="record.costCount != null">
<if test="record.id != null"> cost_count = #{record.costCount,jdbcType=INTEGER},
id = #{record.id,jdbcType=INTEGER}, </if>
</if> <if test="record.hasConfig != null">
<if test="record.costFirst != null"> has_config = #{record.hasConfig,jdbcType=BIT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update dc_mid_cost_first
set id = #{record.id,jdbcType=INTEGER},
cost_first = #{record.costFirst,jdbcType=DECIMAL}, cost_first = #{record.costFirst,jdbcType=DECIMAL},
</if>
<if test="record.bailunSku != null">
bailun_sku = #{record.bailunSku,jdbcType=VARCHAR}, bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
</if>
<if test="record.warehouseCode != null">
warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR}, warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
</if>
<if test="record.companyId != null">
company_id = #{record.companyId,jdbcType=INTEGER}, company_id = #{record.companyId,jdbcType=INTEGER},
</if>
<if test="record.hasCalculation != null">
has_calculation = #{record.hasCalculation,jdbcType=BIT}, has_calculation = #{record.hasCalculation,jdbcType=BIT},
</if>
<if test="record.costCount != null">
cost_count = #{record.costCount,jdbcType=INTEGER}, cost_count = #{record.costCount,jdbcType=INTEGER},
</if> has_config = #{record.hasConfig,jdbcType=BIT}
<if test="record.hasConfig != null"> <if test="_parameter != null">
has_config = #{record.hasConfig,jdbcType=BIT}, <include refid="Update_By_Example_Where_Clause"/>
</if> </if>
</set> </update>
<if test="_parameter != null"> <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
<include refid="Update_By_Example_Where_Clause" /> <!--
</if> WARNING - @mbg.generated
</update> This element is automatically generated by MyBatis Generator, do not modify.
<update id="updateByExample" parameterType="map"> -->
<!-- update dc_mid_cost_first
WARNING - @mbg.generated <set>
This element is automatically generated by MyBatis Generator, do not modify. <if test="costFirst != null">
--> cost_first = #{costFirst,jdbcType=DECIMAL},
update dc_mid_cost_first </if>
set id = #{record.id,jdbcType=INTEGER}, <if test="bailunSku != null">
cost_first = #{record.costFirst,jdbcType=DECIMAL}, bailun_sku = #{bailunSku,jdbcType=VARCHAR},
bailun_sku = #{record.bailunSku,jdbcType=VARCHAR}, </if>
warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR}, <if test="warehouseCode != null">
company_id = #{record.companyId,jdbcType=INTEGER}, warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
has_calculation = #{record.hasCalculation,jdbcType=BIT}, </if>
cost_count = #{record.costCount,jdbcType=INTEGER}, <if test="companyId != null">
has_config = #{record.hasConfig,jdbcType=BIT} company_id = #{companyId,jdbcType=INTEGER},
<if test="_parameter != null"> </if>
<include refid="Update_By_Example_Where_Clause" /> <if test="hasCalculation != null">
</if> has_calculation = #{hasCalculation,jdbcType=BIT},
</update> </if>
<update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcMidCostFirst"> <if test="costCount != null">
<!-- cost_count = #{costCount,jdbcType=INTEGER},
WARNING - @mbg.generated </if>
This element is automatically generated by MyBatis Generator, do not modify. <if test="hasConfig != null">
--> has_config = #{hasConfig,jdbcType=BIT},
update dc_mid_cost_first </if>
<set> </set>
<if test="costFirst != null"> where id = #{id,jdbcType=INTEGER}
cost_first = #{costFirst,jdbcType=DECIMAL}, </update>
</if> <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
<if test="bailunSku != null"> <!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update dc_mid_cost_first
set cost_first = #{costFirst,jdbcType=DECIMAL},
bailun_sku = #{bailunSku,jdbcType=VARCHAR}, bailun_sku = #{bailunSku,jdbcType=VARCHAR},
</if>
<if test="warehouseCode != null">
warehouse_code = #{warehouseCode,jdbcType=VARCHAR}, warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
</if>
<if test="companyId != null">
company_id = #{companyId,jdbcType=INTEGER}, company_id = #{companyId,jdbcType=INTEGER},
</if>
<if test="hasCalculation != null">
has_calculation = #{hasCalculation,jdbcType=BIT}, has_calculation = #{hasCalculation,jdbcType=BIT},
</if>
<if test="costCount != null">
cost_count = #{costCount,jdbcType=INTEGER}, cost_count = #{costCount,jdbcType=INTEGER},
</if> has_config = #{hasConfig,jdbcType=BIT}
<if test="hasConfig != null"> where id = #{id,jdbcType=INTEGER}
has_config = #{hasConfig,jdbcType=BIT}, </update>
</if> <update id="upsertBatch">
</set>
where id = #{id,jdbcType=INTEGER} insert into dc_mid_cost_first
</update> (
<update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update dc_mid_cost_first
set cost_first = #{costFirst,jdbcType=DECIMAL},
bailun_sku = #{bailunSku,jdbcType=VARCHAR},
warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
company_id = #{companyId,jdbcType=INTEGER},
has_calculation = #{hasCalculation,jdbcType=BIT},
cost_count = #{costCount,jdbcType=INTEGER},
has_config = #{hasConfig,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
<insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
insert into dc_mid_cost_first
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="costFirst != null">
cost_first, cost_first,
</if>
<if test="bailunSku != null">
bailun_sku, bailun_sku,
</if>
<if test="warehouseCode != null">
warehouse_code, warehouse_code,
</if>
<if test="companyId != null">
company_id, company_id,
</if>
<if test="hasCalculation != null">
has_calculation, has_calculation,
</if>
<if test="costCount != null">
cost_count, cost_count,
</if> has_config)
<if test="hasConfig != null"> values
has_config, <foreach collection="lists" item="item" index="index" separator=",">
</if> (
</trim> #{item.costFirst,jdbcType=DECIMAL},
values #{item.bailunSku,jdbcType=VARCHAR},
<trim prefix="(" suffix=")" suffixOverrides=","> #{item.warehouseCode,jdbcType=VARCHAR},
<if test="id != null"> #{item.companyId,jdbcType=INTEGER},
#{id,jdbcType=INTEGER}, #{item.hasCalculation,jdbcType=BIT},
</if> #{item.costCount,jdbcType=INTEGER},
<if test="costFirst != null"> #{item.hasConfig,jdbcType=BIT}
#{costFirst,jdbcType=DECIMAL}, )
</if> </foreach>
<if test="bailunSku != null"> on duplicate key update
#{bailunSku,jdbcType=VARCHAR}, cost_first = values(cost_first),
</if> bailun_sku = values(bailun_sku),
<if test="warehouseCode != null"> warehouse_code = values(warehouse_code),
#{warehouseCode,jdbcType=VARCHAR}, company_id = values(company_id),
</if> has_calculation = values(has_calculation),
<if test="companyId != null"> cost_count = values(cost_count),
#{companyId,jdbcType=INTEGER}, has_config = values(has_config)
</if> </update>
<if test="hasCalculation != null">
#{hasCalculation,jdbcType=BIT}, <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
</if> <!--
<if test="costCount != null"> WARNING - @mbg.generated
#{costCount,jdbcType=INTEGER}, This element is automatically generated by MyBatis Generator, do not modify.
</if> @project https://github.com/itfsw/mybatis-generator-plugin
<if test="hasConfig != null"> -->
#{hasConfig,jdbcType=BIT}, insert into dc_mid_cost_first
</if> <trim prefix="(" suffix=")" suffixOverrides=",">
</trim> <if test="id != null">
on duplicate key update id,
<trim suffixOverrides=","> </if>
<if test="id != null"> <if test="costFirst != null">
cost_first,
</if>
<if test="bailunSku != null">
bailun_sku,
</if>
<if test="warehouseCode != null">
warehouse_code,
</if>
<if test="companyId != null">
company_id,
</if>
<if test="hasCalculation != null">
has_calculation,
</if>
<if test="costCount != null">
cost_count,
</if>
<if test="hasConfig != null">
has_config,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="costFirst != null">
#{costFirst,jdbcType=DECIMAL},
</if>
<if test="bailunSku != null">
#{bailunSku,jdbcType=VARCHAR},
</if>
<if test="warehouseCode != null">
#{warehouseCode,jdbcType=VARCHAR},
</if>
<if test="companyId != null">
#{companyId,jdbcType=INTEGER},
</if>
<if test="hasCalculation != null">
#{hasCalculation,jdbcType=BIT},
</if>
<if test="costCount != null">
#{costCount,jdbcType=INTEGER},
</if>
<if test="hasConfig != null">
#{hasConfig,jdbcType=BIT},
</if>
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
<if test="costFirst != null">
cost_first = #{costFirst,jdbcType=DECIMAL},
</if>
<if test="bailunSku != null">
bailun_sku = #{bailunSku,jdbcType=VARCHAR},
</if>
<if test="warehouseCode != null">
warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
</if>
<if test="companyId != null">
company_id = #{companyId,jdbcType=INTEGER},
</if>
<if test="hasCalculation != null">
has_calculation = #{hasCalculation,jdbcType=BIT},
</if>
<if test="costCount != null">
cost_count = #{costCount,jdbcType=INTEGER},
</if>
<if test="hasConfig != null">
has_config = #{hasConfig,jdbcType=BIT},
</if>
</trim>
</insert>
<insert id="upsert" parameterType="com.bailuntec.domain.entity.DcMidCostFirst">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
insert into dc_mid_cost_first
(id, cost_first, bailun_sku, warehouse_code, company_id, has_calculation, cost_count,
has_config)
values
(#{id,jdbcType=INTEGER}, #{costFirst,jdbcType=DECIMAL}, #{bailunSku,jdbcType=VARCHAR},
#{warehouseCode,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER}, #{hasCalculation,jdbcType=BIT},
#{costCount,jdbcType=INTEGER}, #{hasConfig,jdbcType=BIT})
on duplicate key update
id = #{id,jdbcType=INTEGER}, id = #{id,jdbcType=INTEGER},
</if>
<if test="costFirst != null">
cost_first = #{costFirst,jdbcType=DECIMAL}, cost_first = #{costFirst,jdbcType=DECIMAL},
</if>
<if test="bailunSku != null">
bailun_sku = #{bailunSku,jdbcType=VARCHAR}, bailun_sku = #{bailunSku,jdbcType=VARCHAR},
</if>
<if test="warehouseCode != null">
warehouse_code = #{warehouseCode,jdbcType=VARCHAR}, warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
</if>
<if test="companyId != null">
company_id = #{companyId,jdbcType=INTEGER}, company_id = #{companyId,jdbcType=INTEGER},
</if>
<if test="hasCalculation != null">
has_calculation = #{hasCalculation,jdbcType=BIT}, has_calculation = #{hasCalculation,jdbcType=BIT},
</if>
<if test="costCount != null">
cost_count = #{costCount,jdbcType=INTEGER}, cost_count = #{costCount,jdbcType=INTEGER},
</if> has_config = #{hasConfig,jdbcType=BIT}
<if test="hasConfig != null"> </insert>
has_config = #{hasConfig,jdbcType=BIT}, <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample"
</if> resultMap="BaseResultMap">
</trim> <!--
</insert> WARNING - @mbg.generated
<insert id="upsert" parameterType="com.bailuntec.domain.entity.DcMidCostFirst"> This element is automatically generated by MyBatis Generator, do not modify.
<!-- @project https://github.com/itfsw/mybatis-generator-plugin
WARNING - @mbg.generated -->
This element is automatically generated by MyBatis Generator, do not modify. select
@project https://github.com/itfsw/mybatis-generator-plugin <include refid="Base_Column_List"/>
--> from dc_mid_cost_first
insert into dc_mid_cost_first <if test="_parameter != null">
(id, cost_first, bailun_sku, warehouse_code, company_id, has_calculation, cost_count, <include refid="Example_Where_Clause"/>
has_config) </if>
values <if test="orderByClause != null">
(#{id,jdbcType=INTEGER}, #{costFirst,jdbcType=DECIMAL}, #{bailunSku,jdbcType=VARCHAR}, order by ${orderByClause}
#{warehouseCode,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER}, #{hasCalculation,jdbcType=BIT}, </if>
#{costCount,jdbcType=INTEGER}, #{hasConfig,jdbcType=BIT}) limit 1
on duplicate key update </select>
id = #{id,jdbcType=INTEGER}, </mapper>
cost_first = #{costFirst,jdbcType=DECIMAL},
bailun_sku = #{bailunSku,jdbcType=VARCHAR},
warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
company_id = #{companyId,jdbcType=INTEGER},
has_calculation = #{hasCalculation,jdbcType=BIT},
cost_count = #{costCount,jdbcType=INTEGER},
has_config = #{hasConfig,jdbcType=BIT}
</insert>
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcMidCostFirstExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<include refid="Base_Column_List" />
from dc_mid_cost_first
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
limit 1
</select>
</mapper>
\ No newline at end of file
...@@ -129,6 +129,5 @@ public interface DcMidCostFirstOrderMapper { ...@@ -129,6 +129,5 @@ public interface DcMidCostFirstOrderMapper {
List<MidCostFirst> listSkuWarehouse(@Param("v1") int v1, @Param("v2") int v2); List<MidCostFirst> listSkuWarehouse(@Param("v1") int v1, @Param("v2") int v2);
int updateHasCalculation(MidCostFirst midCostFirst);
} }
...@@ -577,28 +577,26 @@ ...@@ -577,28 +577,26 @@
limit 1 limit 1
</select> </select>
<!---->
<select id="countSkuWarehouse" resultType="int"> <select id="countSkuWarehouse" resultType="int">
select count(*) select count(*)
from (SELECT * FROM dc_mid_cost_first_order where has_calculation = 0 GROUP BY bailun_sku, warehouse_code) tb; from (SELECT *
FROM dc_mid_cost_first_order
GROUP BY bailun_sku, warehouse_code) tb;
</select> </select>
<!---->
<select id="listSkuWarehouse" resultType="com.bailuntec.domain.pojo.MidCostFirst"> <select id="listSkuWarehouse" resultType="com.bailuntec.domain.pojo.MidCostFirst">
SELECT bailun_sku, SELECT bailun_sku,
warehouse_code, warehouse_code,
sum(cost_first) as total_cost_first, sum(cost_first) as total_cost_first,
sum(quantity) as total_count sum(quantity) as total_count
FROM dc_mid_cost_first_order FROM dc_mid_cost_first_order
where has_calculation = 0
GROUP BY bailun_sku, warehouse_code GROUP BY bailun_sku, warehouse_code
order by id asc order by id
limit #{v1}, #{v2} limit #{v1}, #{v2}
</select> </select>
<update id="updateHasCalculation">
update dc_mid_cost_first_order
set has_calculation = 1
where bailun_sku = #{bailunSku}
and warehouse_code = #{warehouseCode}
</update>
</mapper> </mapper>
...@@ -2,16 +2,19 @@ package com.bailuntec.job; ...@@ -2,16 +2,19 @@ package com.bailuntec.job;
import com.bailuntec.domain.entity.DcBaseCostFirst; import com.bailuntec.domain.entity.DcBaseCostFirst;
import com.bailuntec.domain.entity.DcBaseSku; import com.bailuntec.domain.entity.DcBaseSku;
import com.bailuntec.domain.entity.DcMidCostFirst;
import com.bailuntec.domain.entity.DcMidCostFirstOrder; import com.bailuntec.domain.entity.DcMidCostFirstOrder;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseSkuExample; import com.bailuntec.domain.example.DcBaseSkuExample;
import com.bailuntec.domain.example.DcMidCostFirstExample;
import com.bailuntec.domain.pojo.MidCostFirst;
import com.bailuntec.mapper.DcBaseCostFirstMapper; import com.bailuntec.mapper.DcBaseCostFirstMapper;
import com.bailuntec.mapper.DcBaseSkuMapper; import com.bailuntec.mapper.DcBaseSkuMapper;
import com.bailuntec.mapper.DcMidCostFirstMapper;
import com.bailuntec.mapper.DcMidCostFirstOrderMapper; import com.bailuntec.mapper.DcMidCostFirstOrderMapper;
import com.bailuntec.support.PointJob;
import com.bailuntec.utils.ListUtil; import com.bailuntec.utils.ListUtil;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
...@@ -23,85 +26,58 @@ import java.util.Optional; ...@@ -23,85 +26,58 @@ import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
public class CalculateCostFirstJob extends PointJob { public class CalculateCostFirstJob implements SimpleJob {
@Override @Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) { public void execute(ShardingContext shardingContext) {
int countChannelOrder;
try (SqlSession sqlSession = SessionUtil.getFactory().openSession(true)) { try (SqlSession sqlSession = SessionUtil.getFactory().openSession(true)) {
DcBaseCostFirstMapper dcBaseCostFirstMapper = sqlSession.getMapper(DcBaseCostFirstMapper.class); DcBaseCostFirstMapper dcBaseCostFirstMapper = sqlSession.getMapper(DcBaseCostFirstMapper.class);
DcMidCostFirstOrderMapper dcMidCostFirstOrderMapper = sqlSession.getMapper(DcMidCostFirstOrderMapper.class); DcMidCostFirstOrderMapper dcMidCostFirstOrderMapper = sqlSession.getMapper(DcMidCostFirstOrderMapper.class);
DcBaseSkuMapper dcBaseSkuMapper = SessionUtil.getSession().getMapper(DcBaseSkuMapper.class); DcBaseSkuMapper dcBaseSkuMapper = sqlSession.getMapper(DcBaseSkuMapper.class);
DcMidCostFirstMapper dcMidCostFirstMapper = sqlSession.getMapper(DcMidCostFirstMapper.class);
countChannelOrder = dcBaseCostFirstMapper.countChannelOrder(); int currentPage = 1;
int pageSize = 1000;
int countChannelOrder = dcBaseCostFirstMapper.countChannelOrder();
int totalPage = getTotalPage(countChannelOrder, pageSize);
int totalPage = getChannelOrderPage(countChannelOrder, jobPointLog);
do { do {
log.info("当前第:{}页", jobPointLog.getPageIndex()); log.info("当前第:{}页", currentPage);
log.info("总共:{}页", totalPage); log.info("总共:{}页", totalPage);
Integer pageStart = (jobPointLog.getPageIndex() - 1) * jobPointLog.getPageSize(); Integer pageStart = (currentPage - 1) * currentPage;
Integer pageOffset = jobPointLog.getPageSize(); Integer pageOffset = currentPage;
List<DcBaseCostFirst> dcBaseCostFirstList = dcBaseCostFirstMapper.listUnCalc(pageStart, pageOffset); List<DcBaseCostFirst> dcBaseCostFirstList = dcBaseCostFirstMapper.dcBaseCostGroupList(pageStart, pageOffset);
if (ListUtil.isNotEmpty(dcBaseCostFirstList)) { if (ListUtil.isNotEmpty(dcBaseCostFirstList)) {
List<DcBaseSku> dcBaseSkuList = dcBaseSkuMapper.selectByExample(DcBaseSkuExample.newAndCreateCriteria()
.andBailunSkuIn(dcBaseCostFirstList.stream().map(DcBaseCostFirst::getBailunSku).collect(Collectors.toList())).example());
//聚合base头程费sku信息 //聚合base头程费sku信息
List<DcBaseSku> dcBaseSkuList = dcBaseSkuMapper.selectByExample(DcBaseSkuExample
.newAndCreateCriteria()
.andBailunSkuIn(dcBaseCostFirstList
.stream()
.map(DcBaseCostFirst::getBailunSku)
.collect(Collectors.toList()))
.example());
Map<String, DcBaseSku> dcBaseSkuMap = dcBaseSkuList.stream().collect(Collectors.toMap(DcBaseSku::getBailunSku, dcBaseSku -> dcBaseSku)); Map<String, DcBaseSku> dcBaseSkuMap = dcBaseSkuList.stream().collect(Collectors.toMap(DcBaseSku::getBailunSku, dcBaseSku -> dcBaseSku));
dcBaseCostFirstList.forEach(dcBaseCostFirst -> dcBaseCostFirst.setDcBaseSku(Optional.ofNullable(dcBaseSkuMap.get(dcBaseCostFirst.getBailunSku())))); dcBaseCostFirstList.forEach(dcBaseCostFirst -> dcBaseCostFirst.setDcBaseSku(Optional.ofNullable(dcBaseSkuMap.get(dcBaseCostFirst.getBailunSku()))));
//头程费用 按订单维度(boxId,channelOrderId ,transferOrderId,warehouseCode)分组
Map<String, List<DcBaseCostFirst>> dcBaseCostFirstMap = dcBaseCostFirstList.stream().collect( Map<String, List<DcBaseCostFirst>> dcBaseCostFirstMap = dcBaseCostFirstList.stream().collect(
Collectors.groupingBy(val -> val.getChannelOrderId() + val.getTransferOrderId() + val.getBoxId() + val.getWarehouseCode())); Collectors.groupingBy(val -> val.getChannelOrderId() + val.getTransferOrderId() + val.getBoxId() + val.getWarehouseCode()));
//生成订单维度DcMidCostFirstOrder列表
List<DcMidCostFirstOrder> dcMidCostFirstOrderList = dcBaseCostFirstMap.values() List<DcMidCostFirstOrder> dcMidCostFirstOrderList = dcBaseCostFirstMap.values()
.stream() .stream()
.map(dcBaseCostFirstGroup -> { .map(dcBaseCostFirstGroup -> {
//总重量
BigDecimal totalWeight = dcBaseCostFirstGroup.stream().map(dcBaseCostFirst -> dcBaseCostFirst.getDcBaseSku().map(DcBaseSku::getWeight).orElse(BigDecimal.ZERO) //计算sku权重
.multiply(new BigDecimal(dcBaseCostFirst.getQuantity() == null ? 0 : dcBaseCostFirst.getQuantity()))) this.calcBaseFirstCostSkuWeightRatio(dcBaseCostFirstGroup);
.reduce(BigDecimal.ZERO, BigDecimal::add); return dcBaseCostFirstGroup
BigDecimal leftRatio = BigDecimal.ONE;
if (totalWeight.equals(BigDecimal.ZERO)) {
for (int i = 0; i < dcBaseCostFirstGroup.size(); i++) {
DcBaseCostFirst dcBaseCostFirst = dcBaseCostFirstGroup.get(i);
//最后一个元素用减法计算
if (dcBaseCostFirstGroup.size() - 1 == i) {
dcBaseCostFirst.setSkuWeightRatio(leftRatio);
}
//前面用除法计算
else {
BigDecimal skuWeightRatio = BigDecimal.ONE.divide(new BigDecimal(dcBaseCostFirstGroup.size()), 2, BigDecimal.ROUND_HALF_UP);
dcBaseCostFirst.setSkuWeightRatio(skuWeightRatio);
leftRatio = leftRatio.subtract(skuWeightRatio);
}
}
} else {
for (int i = 0; i < dcBaseCostFirstGroup.size(); i++) {
DcBaseCostFirst dcBaseCostFirst = dcBaseCostFirstGroup.get(i);
//最后一个元素用减法计算
if (dcBaseCostFirstGroup.size() - 1 == i) {
dcBaseCostFirst.setSkuWeightRatio(leftRatio);
}
//前面用除法计算
else {
BigDecimal skuWeightRatio = new BigDecimal(dcBaseCostFirst.getQuantity()).multiply(dcBaseCostFirst.getDcBaseSku().map(DcBaseSku::getWeight).orElse(BigDecimal.ZERO))
.divide(totalWeight, 2, BigDecimal.ROUND_HALF_UP);
dcBaseCostFirst.setSkuWeightRatio(skuWeightRatio);
leftRatio = leftRatio.subtract(skuWeightRatio);
}
}
}
List<DcMidCostFirstOrder> dcMidCostFirstOrderGroup = dcBaseCostFirstGroup
.stream() .stream()
.map(dcBaseCostFirst -> { .map(dcBaseCostFirst -> {
...@@ -117,36 +93,118 @@ public class CalculateCostFirstJob extends PointJob { ...@@ -117,36 +93,118 @@ public class CalculateCostFirstJob extends PointJob {
dcMidCostFirstOrder.setWeightRatio(dcBaseCostFirst.getSkuWeightRatio()); dcMidCostFirstOrder.setWeightRatio(dcBaseCostFirst.getSkuWeightRatio());
dcMidCostFirstOrder.setCostFirst(skuCostFirst); dcMidCostFirstOrder.setCostFirst(skuCostFirst);
dcMidCostFirstOrder.setCompanyId(dcBaseCostFirst.getCompanyId()); dcMidCostFirstOrder.setCompanyId(dcBaseCostFirst.getCompanyId());
dcMidCostFirstOrder.setHasCalculation(false); dcMidCostFirstOrder.setHasCalculation(true);
return dcMidCostFirstOrder; return dcMidCostFirstOrder;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return dcMidCostFirstOrderGroup;
}) })
.flatMap(List::stream) .flatMap(List::stream)
.collect(Collectors.toList()); .collect(Collectors.toList());
//批量插入更新订单维度
dcMidCostFirstOrderMapper.upsertBatch(dcMidCostFirstOrderList); dcMidCostFirstOrderMapper.upsertBatch(dcMidCostFirstOrderList);
} }
jobPointLog.setPageIndex(jobPointLog.getPageIndex() + 1); currentPage = currentPage + 1;
} }
while (jobPointLog.getPageIndex() <= totalPage); while (currentPage <= totalPage);
jobPointLog.setPageIndex(0);
int dcMidCostFirstIndex = 1;
int dcMidCostFirstPageSize = 1000;
int countSkuWarehouse = dcMidCostFirstOrderMapper.countSkuWarehouse();
int dcMidCostFirstTotalPage = this.getTotalPage(countSkuWarehouse, dcMidCostFirstPageSize);
do {
List<MidCostFirst> midCostFirstList = dcMidCostFirstOrderMapper.listSkuWarehouse((dcMidCostFirstIndex - 1) * dcMidCostFirstPageSize, dcMidCostFirstPageSize);
List<DcMidCostFirst> dcMidCostFirstList = midCostFirstList.stream().map(midCostFirst -> {
DcMidCostFirst dcMidCostFirst = dcMidCostFirstMapper.selectOneByExample(DcMidCostFirstExample.newAndCreateCriteria()
.andBailunSkuEqualTo(midCostFirst.getBailunSku())
.andWarehouseCodeEqualTo(midCostFirst.getWarehouseCode())
.example());
if (dcMidCostFirst == null) {
dcMidCostFirst = new DcMidCostFirst();
dcMidCostFirst.setBailunSku(midCostFirst.getBailunSku());
dcMidCostFirst.setWarehouseCode(midCostFirst.getWarehouseCode());
dcMidCostFirst.setCompanyId(0);
dcMidCostFirst.setHasConfig(false);
}
dcMidCostFirst.setCostFirst(midCostFirst.getTotalCostFirst().divide(new BigDecimal(midCostFirst.getTotalCount()), 2, BigDecimal.ROUND_HALF_UP));
dcMidCostFirst.setCostCount(midCostFirst.getTotalCount());
dcMidCostFirst.setHasCalculation(true);
return dcMidCostFirst;
}
)
.collect(Collectors.toList());
dcMidCostFirstMapper.upsertBatch(dcMidCostFirstList);
dcMidCostFirstIndex = dcMidCostFirstIndex + 1;
} while (dcMidCostFirstIndex < dcMidCostFirstTotalPage);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("任务失败", e); throw new RuntimeException("任务失败", e);
} }
} }
/**
* <p>
* 按照sku重量计算组别内每个订单维度的头程费用权重
* </p>
*
* @param dcBaseCostFirstGroup 基础头程费用 按订单维度(boxId,channelOrderId ,transferOrderId,warehouseCode)分组后的组别
*/
private void calcBaseFirstCostSkuWeightRatio(List<DcBaseCostFirst> dcBaseCostFirstGroup) {
//总重量
BigDecimal totalWeight = dcBaseCostFirstGroup.stream().map(dcBaseCostFirst -> dcBaseCostFirst.getDcBaseSku().map(DcBaseSku::getWeight).orElse(BigDecimal.ZERO)
.multiply(new BigDecimal(dcBaseCostFirst.getQuantity() == null ? 0 : dcBaseCostFirst.getQuantity())))
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal leftRatio = BigDecimal.ONE;
if (totalWeight.equals(BigDecimal.ZERO)) {
for (int i = 0; i < dcBaseCostFirstGroup.size(); i++) {
DcBaseCostFirst dcBaseCostFirst = dcBaseCostFirstGroup.get(i);
//最后一个元素用减法计算
if (dcBaseCostFirstGroup.size() - 1 == i) {
dcBaseCostFirst.setSkuWeightRatio(leftRatio);
}
//前面用除法计算
else {
BigDecimal skuWeightRatio = BigDecimal.ONE.divide(new BigDecimal(dcBaseCostFirstGroup.size()), 2, BigDecimal.ROUND_HALF_UP);
dcBaseCostFirst.setSkuWeightRatio(skuWeightRatio);
leftRatio = leftRatio.subtract(skuWeightRatio);
}
}
} else {
for (int i = 0; i < dcBaseCostFirstGroup.size(); i++) {
DcBaseCostFirst dcBaseCostFirst = dcBaseCostFirstGroup.get(i);
//最后一个元素用减法计算
if (dcBaseCostFirstGroup.size() - 1 == i) {
dcBaseCostFirst.setSkuWeightRatio(leftRatio);
}
//前面用除法计算
else {
BigDecimal skuWeightRatio = new BigDecimal(dcBaseCostFirst.getQuantity()).multiply(dcBaseCostFirst.getDcBaseSku().map(DcBaseSku::getWeight).orElse(BigDecimal.ZERO))
.divide(totalWeight, 2, BigDecimal.ROUND_HALF_UP);
dcBaseCostFirst.setSkuWeightRatio(skuWeightRatio);
leftRatio = leftRatio.subtract(skuWeightRatio);
}
}
}
}
private int getChannelOrderPage(int countChannelOrder, JobPointLog jobPointLog) { private int getTotalPage(int count, int pageSize) {
if (countChannelOrder % jobPointLog.getPageSize() == 0) { if (count % pageSize == 0) {
return countChannelOrder / jobPointLog.getPageSize(); return count / pageSize;
} }
return countChannelOrder / jobPointLog.getPageSize() + 1; return count / pageSize + 1;
} }
} }
...@@ -2,7 +2,6 @@ import com.bailuntec.domain.constant.Constant; ...@@ -2,7 +2,6 @@ import com.bailuntec.domain.constant.Constant;
import com.bailuntec.domain.entity.DcBaseSku; import com.bailuntec.domain.entity.DcBaseSku;
import com.bailuntec.domain.entity.DcMidCostFirst; import com.bailuntec.domain.entity.DcMidCostFirst;
import com.bailuntec.domain.entity.DcMidCostFirstConfig; import com.bailuntec.domain.entity.DcMidCostFirstConfig;
import com.bailuntec.domain.entity.JobPointLog;
import com.bailuntec.domain.example.DcBaseSkuExample; import com.bailuntec.domain.example.DcBaseSkuExample;
import com.bailuntec.domain.example.DcMidCostFirstExample; import com.bailuntec.domain.example.DcMidCostFirstExample;
import com.bailuntec.domain.pojo.MidCostFirst; import com.bailuntec.domain.pojo.MidCostFirst;
...@@ -37,7 +36,7 @@ public class CostFirstTest { ...@@ -37,7 +36,7 @@ public class CostFirstTest {
@Test @Test
public void test() { public void test() {
CalculateCostFirstJob costFirstJob = new CalculateCostFirstJob(); CalculateCostFirstJob costFirstJob = new CalculateCostFirstJob();
costFirstJob.executeJob(null, new JobPointLog("dc-mid-calculate-cost-first", 1, 100, null, null, null, null)); costFirstJob.execute(null);
} }
@Test @Test
......
...@@ -20,6 +20,6 @@ class CalculateCostFirstJobTest { ...@@ -20,6 +20,6 @@ class CalculateCostFirstJobTest {
JobPointLog jobPointLog = new JobPointLog(); JobPointLog jobPointLog = new JobPointLog();
jobPointLog.setPageSize(1000); jobPointLog.setPageSize(1000);
jobPointLog.setPageIndex(1); jobPointLog.setPageIndex(1);
calculateCostFirstJob.executeJob(null, jobPointLog); calculateCostFirstJob.execute(null);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment