Commit 2806c3a3 by huluobin

update

parent 1c15608d
......@@ -2,7 +2,7 @@ package com.bailuntec.domain.enumerate;
public enum AccountPlatformType {
Amazon(15,"AMAZON"),
Amazon(15, "AMAZON"),
Wish(8, "WISH"),
Cdiscount(10, "CDISCOUNT"),
Ebay(12, "EBAY"),
......@@ -30,4 +30,10 @@ public enum AccountPlatformType {
public int code() {
return code;
}
public static class Shopify {
public static Integer code() {
return 1;
}
}
}
......@@ -56,6 +56,15 @@ public interface DcAutoUprushConfigMapper {
*/
DcAutoUprushConfig selectOneByExample(DcAutoUprushConfigExample example);
/**
* <p>
* 不知道什么鸡巴
* </p>
*
* @param warehouseCode 仓库编码
* @param hqType 环球仓库类型
* @return 销量突增检测
*/
DcAutoUprushConfig selectOneByWarehouse(@Param("warehouseCode") String warehouseCode, @Param("hqType") String hqType);
/**
......
......@@ -2,8 +2,10 @@ package com.bailuntec.mapper;
import com.bailuntec.domain.entity.DcBaseStock;
import com.bailuntec.domain.example.DcBaseStockExample;
import com.dangdang.ddframe.job.api.ShardingContext;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
public interface DcBaseStockMapper {
......@@ -130,23 +132,78 @@ public interface DcBaseStockMapper {
void insertDailyStock();
List<DcBaseStock> listStockById(@Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listStockById(ShardingContext shardingContext, @Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listStockWarehouseById(@Param("v1") int v1, @Param("v2") int v2, @Param("warehouseCode") String warehouseCode);
List<DcBaseStock> listParameterStockById(@Param("jobParameter")String jobParameter,@Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listParameterStockById(@Param("shardingContext") ShardingContext shardingContext, @Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listAllStock(@Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listAllStock(@Param("shardingContext") ShardingContext shardingContext, @Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listWarehouseStockById(@Param("warehouseCode")String warehouseCode,@Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listWarehouseStockById(@Param("shardingContext") ShardingContext shardingContext, @Param("warehouseCode") String warehouseCode, @Param("v1") int v1, @Param("v2") int v2);
List<DcBaseStock> listInStockNotInAutoTurnover();
long countByParam(@Param("jobParameter") String jobParameter);
// long countByParam(@Param("jobParameter") String jobParameter);
//
// long countAll();
//
// long countByWarehouseCode(@Param("warehouseCode") String warehouseCode);
long countAll();
void updateSkuUnitPrice();
long countByWarehouseCode(@Param("warehouseCode")String warehouseCode);
// /**
// * <p>
// * 自动周转列表普通同步数量
// * </p>
// *
// * @return count
// */
// long countNormal();
void updateSkuUnitPrice();
/**
* <p>
* 自动周转列表普通同步库存列表
* </p>
*
* @param shardingContext shardingContext
* @param pageStart pageStart
* @param pageOffset pageOffset
* @return 库存列表
*/
List<DcBaseStock> listNormal(@Param("shardingContext") ShardingContext shardingContext, @Param("pageStart") int pageStart, @Param("pageOffset") int pageOffset);
long countByParam(@Param("shardingContext") ShardingContext shardingContext);
long countAll(@Param("shardingContext") ShardingContext shardingContext);
long countNormal(@Param("shardingContext") ShardingContext shardingContext);
long countByWarehouseCode(@Param("shardingContext") ShardingContext shardingContext);
/**
* <p>
* 补充晚上定时任务的数据 count
* </p>
*
* @param shardingContext shardingContext
* @param v1 当天凌晨三点
* @param v2 当天往前一周的零点
* @return count
*/
long countIncrement(@Param("shardingContext") ShardingContext shardingContext, @Param("v1") LocalDateTime v1, @Param("v2") LocalDateTime v2);
/**
* <p>
* 补充晚上定时任务的数据
* </p>
*
* @param shardingContext shardingContext
* @param v1 当天凌晨三点
* @param v2 当天往前一周的零点
* @param pageStart pageStart
* @param pageOffset pageOffset
* @return 补充晚上定时任务的数据
*/
List<DcBaseStock> increment(@Param("shardingContext") ShardingContext shardingContext, @Param("v1") LocalDateTime v1, @Param("v2") LocalDateTime v2, @Param("pageStart") int pageStart, @Param("pageOffset") int pageOffset);
}
......@@ -6,39 +6,39 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku" />
<result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode" />
<result column="owner_code" jdbcType="VARCHAR" property="ownerCode" />
<result column="quantity_reservation" jdbcType="INTEGER" property="quantityReservation" />
<result column="quantity_transport" jdbcType="INTEGER" property="quantityTransport" />
<result column="quantity_transfer" jdbcType="INTEGER" property="quantityTransfer" />
<result column="quantity_freeze" jdbcType="INTEGER" property="quantityFreeze" />
<result column="quantity_supplier" jdbcType="INTEGER" property="quantitySupplier" />
<result column="quantity_presell" jdbcType="INTEGER" property="quantityPresell" />
<result column="quantity_defective" jdbcType="INTEGER" property="quantityDefective" />
<result column="quantity_transit" jdbcType="INTEGER" property="quantityTransit" />
<result column="wait_check" jdbcType="INTEGER" property="waitCheck" />
<result column="wait_putaway" jdbcType="INTEGER" property="waitPutaway" />
<result column="usable_stock" jdbcType="INTEGER" property="usableStock" />
<result column="usable_sales" jdbcType="INTEGER" property="usableSales" />
<result column="usable_sales_private" jdbcType="INTEGER" property="usableSalesPrivate" />
<result column="usable_sales_share" jdbcType="INTEGER" property="usableSalesShare" />
<result column="in_warehouse_share" jdbcType="INTEGER" property="inWarehouseShare" />
<result column="in_warehouse_private" jdbcType="INTEGER" property="inWarehousePrivate" />
<result column="in_warehouse" jdbcType="INTEGER" property="inWarehouse" />
<result column="occupy_stock_share" jdbcType="INTEGER" property="occupyStockShare" />
<result column="occupy_stock_private" jdbcType="INTEGER" property="occupyStockPrivate" />
<result column="occupy_stock" jdbcType="INTEGER" property="occupyStock" />
<result column="occupy_activity" jdbcType="INTEGER" property="occupyActivity" />
<result column="occupy_order_private" jdbcType="INTEGER" property="occupyOrderPrivate" />
<result column="occupy_order_share" jdbcType="INTEGER" property="occupyOrderShare" />
<result column="occupy_order" jdbcType="INTEGER" property="occupyOrder" />
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="shipped_stock" jdbcType="INTEGER" property="shippedStock" />
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku"/>
<result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode"/>
<result column="owner_code" jdbcType="VARCHAR" property="ownerCode"/>
<result column="quantity_reservation" jdbcType="INTEGER" property="quantityReservation"/>
<result column="quantity_transport" jdbcType="INTEGER" property="quantityTransport"/>
<result column="quantity_transfer" jdbcType="INTEGER" property="quantityTransfer"/>
<result column="quantity_freeze" jdbcType="INTEGER" property="quantityFreeze"/>
<result column="quantity_supplier" jdbcType="INTEGER" property="quantitySupplier"/>
<result column="quantity_presell" jdbcType="INTEGER" property="quantityPresell"/>
<result column="quantity_defective" jdbcType="INTEGER" property="quantityDefective"/>
<result column="quantity_transit" jdbcType="INTEGER" property="quantityTransit"/>
<result column="wait_check" jdbcType="INTEGER" property="waitCheck"/>
<result column="wait_putaway" jdbcType="INTEGER" property="waitPutaway"/>
<result column="usable_stock" jdbcType="INTEGER" property="usableStock"/>
<result column="usable_sales" jdbcType="INTEGER" property="usableSales"/>
<result column="usable_sales_private" jdbcType="INTEGER" property="usableSalesPrivate"/>
<result column="usable_sales_share" jdbcType="INTEGER" property="usableSalesShare"/>
<result column="in_warehouse_share" jdbcType="INTEGER" property="inWarehouseShare"/>
<result column="in_warehouse_private" jdbcType="INTEGER" property="inWarehousePrivate"/>
<result column="in_warehouse" jdbcType="INTEGER" property="inWarehouse"/>
<result column="occupy_stock_share" jdbcType="INTEGER" property="occupyStockShare"/>
<result column="occupy_stock_private" jdbcType="INTEGER" property="occupyStockPrivate"/>
<result column="occupy_stock" jdbcType="INTEGER" property="occupyStock"/>
<result column="occupy_activity" jdbcType="INTEGER" property="occupyActivity"/>
<result column="occupy_order_private" jdbcType="INTEGER" property="occupyOrderPrivate"/>
<result column="occupy_order_share" jdbcType="INTEGER" property="occupyOrderShare"/>
<result column="occupy_order" jdbcType="INTEGER" property="occupyOrder"/>
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
<result column="shipped_stock" jdbcType="INTEGER" property="shippedStock"/>
</resultMap>
<sql id="Example_Where_Clause">
<!--
......@@ -62,7 +62,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
......@@ -95,7 +96,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
......@@ -118,7 +120,8 @@
occupy_stock_private, occupy_stock, occupy_activity, occupy_order_private, occupy_order_share,
occupy_order, gmt_create, gmt_modified, create_time, update_time, shipped_stock
</sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcBaseStockExample" resultMap="BaseResultMap">
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcBaseStockExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......@@ -127,10 +130,10 @@
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from dc_base_stock
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
......@@ -150,7 +153,7 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from dc_base_stock
where id = #{id,jdbcType=INTEGER}
</select>
......@@ -169,7 +172,7 @@
-->
delete from dc_base_stock
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="com.bailuntec.domain.entity.DcBaseStock">
......@@ -197,7 +200,8 @@
#{usableSales,jdbcType=INTEGER}, #{usableSalesPrivate,jdbcType=INTEGER}, #{usableSalesShare,jdbcType=INTEGER},
#{inWarehouseShare,jdbcType=INTEGER}, #{inWarehousePrivate,jdbcType=INTEGER}, #{inWarehouse,jdbcType=INTEGER},
#{occupyStockShare,jdbcType=INTEGER}, #{occupyStockPrivate,jdbcType=INTEGER}, #{occupyStock,jdbcType=INTEGER},
#{occupyActivity,jdbcType=INTEGER}, #{occupyOrderPrivate,jdbcType=INTEGER}, #{occupyOrderShare,jdbcType=INTEGER},
#{occupyActivity,jdbcType=INTEGER}, #{occupyOrderPrivate,jdbcType=INTEGER},
#{occupyOrderShare,jdbcType=INTEGER},
#{occupyOrder,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{shippedStock,jdbcType=INTEGER}
)
......@@ -411,14 +415,15 @@
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcBaseStockExample" resultType="java.lang.Long">
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcBaseStockExample"
resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from dc_base_stock
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
......@@ -529,7 +534,7 @@
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
......@@ -572,7 +577,7 @@
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
shipped_stock = #{record.shippedStock,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcBaseStock">
......@@ -1057,7 +1062,8 @@
#{usableSales,jdbcType=INTEGER}, #{usableSalesPrivate,jdbcType=INTEGER}, #{usableSalesShare,jdbcType=INTEGER},
#{inWarehouseShare,jdbcType=INTEGER}, #{inWarehousePrivate,jdbcType=INTEGER}, #{inWarehouse,jdbcType=INTEGER},
#{occupyStockShare,jdbcType=INTEGER}, #{occupyStockPrivate,jdbcType=INTEGER}, #{occupyStock,jdbcType=INTEGER},
#{occupyActivity,jdbcType=INTEGER}, #{occupyOrderPrivate,jdbcType=INTEGER}, #{occupyOrderShare,jdbcType=INTEGER},
#{occupyActivity,jdbcType=INTEGER}, #{occupyOrderPrivate,jdbcType=INTEGER},
#{occupyOrderShare,jdbcType=INTEGER},
#{occupyOrder,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{shippedStock,jdbcType=INTEGER}
)
......@@ -1096,17 +1102,18 @@
update_time = #{updateTime,jdbcType=TIMESTAMP},
shipped_stock = #{shippedStock,jdbcType=INTEGER}
</insert>
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcBaseStockExample" resultMap="BaseResultMap">
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcBaseStockExample"
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" />
<include refid="Base_Column_List"/>
from dc_base_stock
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
......@@ -1115,44 +1122,58 @@
</select>
<insert id="supplementOrderSku">
insert into dc_base_stock (bailun_sku,warehouse_code,sku_title_cn, product_inner_code, suppliers_name)
SELECT
tbo.bailun_sku,
tbo.warehouse_code,tbsku.sku_title_cn, tbsku.product_inner_code, tbsku.suppliers_name FROM ( SELECT bailun_sku, warehouse_code FROM dc_base_oms_sku WHERE paid_time >= DATE_SUB(curdate(),INTERVAL 10 DAY) and warehouse_code != '' and bailun_sku != '' GROUP BY bailun_sku, warehouse_code ) tbo
insert into dc_base_stock (bailun_sku, warehouse_code, sku_title_cn, product_inner_code, suppliers_name)
SELECT tbo.bailun_sku,
tbo.warehouse_code,
tbsku.sku_title_cn,
tbsku.product_inner_code,
tbsku.suppliers_name
FROM (SELECT bailun_sku, warehouse_code
FROM dc_base_oms_sku
WHERE paid_time >= DATE_SUB(curdate(), INTERVAL 10 DAY)
and warehouse_code != ''
and bailun_sku != ''
GROUP BY bailun_sku, warehouse_code) tbo
LEFT JOIN dc_base_stock tbs ON tbs.bailun_sku = tbo.bailun_sku
AND tbs.warehouse_code = tbo.warehouse_code
LEFT JOIN dc_base_sku tbsku on tbsku.bailun_sku = tbo.bailun_sku
WHERE
tbs.bailun_sku IS NULL;
WHERE tbs.bailun_sku IS NULL;
</insert>
<insert id="supplementPurchaseSku">
insert into dc_base_stock (bailun_sku,warehouse_code,sku_title_cn, product_inner_code, suppliers_name)
SELECT
tbo.bailun_sku,
tbo.warehouse_code,tbsku.sku_title_cn, tbsku.product_inner_code, tbsku.suppliers_name FROM
(SELECT bailun_sku,warehouse_code FROM dc_base_purchase WHERE create_time >= DATE_SUB(curdate(),INTERVAL 10 DAY) and warehouse_code != '' and bailun_sku != '' GROUP BY bailun_sku, warehouse_code ) tbo
insert into dc_base_stock (bailun_sku, warehouse_code, sku_title_cn, product_inner_code, suppliers_name)
SELECT tbo.bailun_sku,
tbo.warehouse_code,
tbsku.sku_title_cn,
tbsku.product_inner_code,
tbsku.suppliers_name
FROM (SELECT bailun_sku, warehouse_code
FROM dc_base_purchase
WHERE create_time >= DATE_SUB(curdate(), INTERVAL 10 DAY)
and warehouse_code != ''
and bailun_sku != ''
GROUP BY bailun_sku, warehouse_code) tbo
LEFT JOIN dc_base_stock tbs ON tbs.bailun_sku = tbo.bailun_sku
AND tbs.warehouse_code = tbo.warehouse_code
LEFT JOIN dc_base_sku tbsku on tbsku.bailun_sku = tbo.bailun_sku
WHERE
tbs.bailun_sku IS NULL;
WHERE tbs.bailun_sku IS NULL;
</insert>
<insert id="supplementTransitSku">
insert into dc_base_stock (bailun_sku,warehouse_code,sku_title_cn, product_inner_code, suppliers_name)
SELECT
tbo.bailun_sku,
tbo.warehouse_code,tbsku.sku_title_cn, tbsku.product_inner_code, tbsku.suppliers_name FROM (SELECT bailun_sku,warehouse_code FROM dc_mid_transit WHERE warehouse_code != '' and bailun_sku != '' ) tbo
insert into dc_base_stock (bailun_sku, warehouse_code, sku_title_cn, product_inner_code, suppliers_name)
SELECT tbo.bailun_sku,
tbo.warehouse_code,
tbsku.sku_title_cn,
tbsku.product_inner_code,
tbsku.suppliers_name
FROM (SELECT bailun_sku, warehouse_code FROM dc_mid_transit WHERE warehouse_code != '' and bailun_sku != '') tbo
LEFT JOIN dc_base_stock tbs ON tbs.bailun_sku = tbo.bailun_sku
AND tbs.warehouse_code = tbo.warehouse_code
LEFT JOIN dc_base_sku tbsku on tbsku.bailun_sku = tbo.bailun_sku
WHERE
tbs.bailun_sku IS NULL;
WHERE tbs.bailun_sku IS NULL;
</insert>
<insert id="insertDailyStock">
INSERT INTO dc_daily_stock (
`bailun_sku`,
INSERT INTO dc_daily_stock (`bailun_sku`,
`warehouse_code`,
`owner_code`,
`quantity_reservation`,
......@@ -1184,9 +1205,8 @@
`record_time`,
`create_time`,
`update_time`,
unit_price
) SELECT
dc0.bailun_sku,
unit_price)
SELECT dc0.bailun_sku,
dc0.warehouse_code,
dc0.owner_code,
dc0.quantity_reservation,
......@@ -1215,77 +1235,176 @@
dc0.occupy_order,
dc0.gmt_create,
dc0.gmt_modified,
DATE_SUB( CURDATE( ), INTERVAL 1 DAY ),
DATE_SUB(CURDATE(), INTERVAL 1 DAY),
dc0.create_time,
dc0.update_time,
ifnull(dc1.unit_price, 0)
FROM
dc_base_stock dc0
FROM dc_base_stock dc0
left join dc_base_sku dc1 on dc0.bailun_sku = dc1.bailun_sku
where dc0.usable_stock>0 or dc0.occupy_stock>0
where dc0.usable_stock > 0
or dc0.occupy_stock > 0
</insert>
<update id="updateSkuUnitPrice">
update dc_daily_stock t1, dc_base_sku t2 set t1.unit_price = t2.unit_price WHERE t1.record_time = DATE_SUB( CURDATE( ), INTERVAL 1 DAY ) and t1.bailun_sku=t2.bailun_sku
update dc_daily_stock t1, dc_base_sku t2
set t1.unit_price = t2.unit_price
WHERE t1.record_time = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
and t1.bailun_sku = t2.bailun_sku
</update>
<select id="listNoChinaWarehouse" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT * FROM dc_base_stock tb1 inner join dc_base_warehouse tb2 on tb1.warehouse_code = tb2.warehouse_code and tb2.hq_type in ('FBA仓','海外仓','第三方仓库') order by type_id desc limit #{v1}, #{v2}
SELECT *
FROM dc_base_stock tb1
inner join dc_base_warehouse tb2
on tb1.warehouse_code = tb2.warehouse_code and tb2.hq_type in ('FBA仓', '海外仓', '第三方仓库')
order by type_id desc
limit #{v1}, #{v2}
</select>
<select id="listStockById" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT * FROM dc_base_stock order by id asc limit #{v1}, #{v2}
SELECT *
FROM dc_base_stock
order by id asc
limit #{v1}, #{v2}
</select>
<select id="listStockWarehouseById" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT * FROM dc_base_stock where warehouse_code = #{warehouseCode} order by id asc limit #{v1}, #{v2}
SELECT *
FROM dc_base_stock
where warehouse_code = #{warehouseCode}
order by id asc
limit #{v1}, #{v2}
</select>
<select id="listParameterStockById" resultType="com.bailuntec.domain.entity.DcBaseStock">
select * from dc_base_stock tb1
left join (select warehouse_code,hq_type from dc_base_warehouse where hq_type=#{jobParameter}) tb2
on tb1.warehouse_code=tb2.warehouse_code
LEFT JOIN dc_auto_turnover tb3 ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb2.warehouse_code is not null order by tb1.id asc limit #{v1}, #{v2}
select *
from dc_base_stock tb1
left join (select warehouse_code, hq_type from dc_base_warehouse where hq_type = #{jobParameter}) tb2
on tb1.warehouse_code = tb2.warehouse_code
LEFT JOIN dc_auto_turnover tb3
ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb2.warehouse_code is not null
and tb1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
order by tb1.id asc
limit #{v1}, #{v2}
</select>
<select id="listAllStock" resultType="com.bailuntec.domain.entity.DcBaseStock">
select * from dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb3 ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb3.bailun_sku is null order by tb1.id asc limit #{v1}, #{v2}
select *
from dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb3
ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb3.bailun_sku is null
and tb1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
order by tb1.id asc
limit #{v1}, #{v2}
</select>
<select id="listWarehouseStockById" resultType="com.bailuntec.domain.entity.DcBaseStock">
select * from dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb3 ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb1.warehouse_code=#{warehouseCode} and tb3.bailun_sku is null order by tb1.id asc limit #{v1}, #{v2}
select *
from dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb3
ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb1.warehouse_code = #{warehouseCode}
and tb3.bailun_sku is null
and tb1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
order by tb1.id
limit #{v1}, #{v2}
</select>
<select id="listInStockNotInAutoTurnover" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT tb1.* FROM dc_base_stock tb1 LEFT JOIN dc_auto_turnover tb2 ON tb1.bailun_sku = tb2.bailun_sku and tb1.warehouse_code = tb2.warehouse_code left join dc_base_sku tb3 on tb1.bailun_sku = tb3.bailun_sku WHERE tb2.bailun_sku is null and tb1.warehouse_code = 'GZBLWH' and tb3.buyer_name in ('黎艳漫', '李志民') and tb3.push_time > '2019-08-01'
SELECT tb1.*
FROM dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb2
ON tb1.bailun_sku = tb2.bailun_sku and tb1.warehouse_code = tb2.warehouse_code
left join dc_base_sku tb3 on tb1.bailun_sku = tb3.bailun_sku
WHERE tb2.bailun_sku is null
and tb1.warehouse_code = 'GZBLWH'
and tb3.buyer_name in ('黎艳漫', '李志民')
and tb3.push_time > '2019-08-01'
</select>
<select id="countByParam" resultType="long">
select count(*)
select count(tb1.id)
from dc_base_stock tb1
left join (select warehouse_code,hq_type from dc_base_warehouse where hq_type=#{jobParameter}) tb2
on tb1.warehouse_code=tb2.warehouse_code
LEFT JOIN dc_auto_turnover tb3 ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
left join (select warehouse_code, hq_type from dc_base_warehouse where hq_type = #{jobParameter}) tb2
on tb1.warehouse_code = tb2.warehouse_code
LEFT JOIN dc_auto_turnover tb3
ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb2.warehouse_code is not null
and tb1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
</select>
<select id="countAll" resultType="long">
select count(*)
select count(tb1.id)
from dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb3 ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
LEFT JOIN dc_auto_turnover tb3
ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb3.bailun_sku is null
and tb1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
</select>
<select id="countByWarehouseCode" resultType="long">
select count(*)
select count(tb1.id)
from dc_base_stock tb1
LEFT JOIN dc_auto_turnover tb3 ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb1.warehouse_code=#{warehouseCode} and tb3.bailun_sku is null
LEFT JOIN dc_auto_turnover tb3
ON tb1.bailun_sku = tb3.bailun_sku and tb1.warehouse_code = tb3.warehouse_code
where tb1.warehouse_code = #{warehouseCode}
and tb3.bailun_sku is null
and tb1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
</select>
<select id="countNormal" resultType="java.lang.Long">
select count(t1.id)
from dc_base_stock as t1
left join dc_auto_config_sku_warehouse as t2
on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
where (t2.`status` = 0
or t2.`status` is null)
and t1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
</select>
<select id="listNormal" resultType="com.bailuntec.domain.entity.DcBaseStock">
select t1.*
from dc_base_stock as t1
left join dc_auto_config_sku_warehouse as t2
on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
where (t2.`status` = 0
or t2.`status` is null)
and t1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
limit #{pageStart}, #{pageOffset};
</select>
<select id="countIncrement" resultType="java.lang.Long">
SELECT count(t1.id)
FROM dc_base_stock AS t1
WHERE (
bailun_sku_warehouse_code IN (SELECT CONCAT(bailun_sku, warehouse_code)
FROM dc_base_oms_sku
WHERE gmt_create &gt;= #{v1})
OR (bailun_sku_warehouse_code IN (SELECT CONCAT(bailun_sku, warehouse_code)
FROM dc_base_oms_sku
WHERE gmt_create &gt; = #{v2}
AND bailun_sku_quantity_ordered > bailun_sku_quantity_picked))
)
and t1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
</select>
<select id="increment" resultType="com.bailuntec.domain.entity.DcBaseStock">
SELECT t1.*
FROM dc_base_stock AS t1
WHERE (
bailun_sku_warehouse_code IN (SELECT CONCAT(bailun_sku, warehouse_code)
FROM dc_base_oms_sku
WHERE gmt_create &gt;= #{v1})
OR (bailun_sku_warehouse_code IN (SELECT CONCAT(bailun_sku, warehouse_code)
FROM dc_base_oms_sku
WHERE gmt_create &gt;= #{v2}
AND bailun_sku_quantity_ordered > bailun_sku_quantity_picked))
)
and t1.id % #{shardingContext.shardingTotalCount} = #{shardingContext.shardingItem}
limit #{pageStart}, #{pageOffset};
</select>
</mapper>
......@@ -11,7 +11,8 @@ import lombok.extern.slf4j.Slf4j;
import java.time.LocalDateTime;
@Slf4j
public class PointJob implements SimpleJob {
public abstract class PointJob implements SimpleJob {
@Override
public void execute(ShardingContext shardingContext) {
JobPointLog jobPointLog = jobInit(shardingContext);
......@@ -38,6 +39,7 @@ public class PointJob implements SimpleJob {
JobPointLog jobPointLog = null;
try {
JobPointLogMapper mapper = SessionUtil.getSession().getMapper(JobPointLogMapper.class);
jobPointLog = mapper.selectOneByExample(JobPointLogExample.newAndCreateCriteria().andJobNameEqualTo(shardingContext.getJobName()).example());
if (jobPointLog == null) {
jobPointLog = new JobPointLog(shardingContext.getJobName(), 1, 100, 0, 1, LocalDateTime.now().minusDays(1), LocalDateTime.now());
......@@ -51,8 +53,7 @@ public class PointJob implements SimpleJob {
return jobPointLog;
}
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
public abstract void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog);
}
}
package com.bailuntec.mapper;
import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/8/11 5:00 下午
*/
class DcBaseStockMapperTest {
@Test
void countIncrement() {
}
@Test
void increment() {
DcBaseStockMapper dcBaseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
ShardingContexts shardingContexts = new ShardingContexts("1", "jobName", 8, "INCREMENT", new HashMap<>(), 1);
LocalDateTime v1 = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).plusHours(3);
LocalDateTime v2 = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).minusDays(7);
dcBaseStockMapper.increment(new ShardingContext(shardingContexts, 1), v1, v2, 0, 100);
}
}
package com.bailuntec;
import com.alibaba.druid.pool.DruidDataSource;
import com.bailuntec.listener.AutoTurnoverJobListener;
import com.bailuntec.job.AutoTurnoverJob;
import com.bailuntec.listener.AutoTurnoverJobListener;
import com.bailuntec.utils.PropertiesUtil;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
......@@ -24,9 +24,10 @@ public class Application {
private static final String EVENT_RDB_STORAGE_URL = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_URL");
private static final String EVENT_RDB_STORAGE_USERNAME = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_USERNAME");
private static final String EVENT_RDB_STORAGE_PASSWORD = propertiesUtil.getPropertyAsString("EVENT_RDB_STORAGE_PASSWORD");
public static void main(String[] args) {
new JobScheduler(createRegistryCenter(), createJobConfiguration(),createJobEventConfiguration(), new AutoTurnoverJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfigurationParam(),createJobEventConfiguration(), new AutoTurnoverJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfigurationNormal(), createJobEventConfiguration(), new AutoTurnoverJobListener()).init();
new JobScheduler(createRegistryCenter(), createJobConfigurationIncrement(), createJobEventConfiguration(), new AutoTurnoverJobListener()).init();
}
private static CoordinatorRegistryCenter createRegistryCenter() {
......@@ -35,22 +36,30 @@ public class Application {
return regCenter;
}
private static LiteJobConfiguration createJobConfiguration() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME"), propertiesUtil.getPropertyAsString("JOB_CRON"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT")).build();
private static LiteJobConfiguration createJobConfigurationNormal() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(
propertiesUtil.getPropertyAsString("JOB_NAME"),
propertiesUtil.getPropertyAsString("JOB_CRON"),
propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT"))
.jobParameter("NORMAL")
.build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, AutoTurnoverJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
return LiteJobConfiguration.newBuilder(simpleJobConfig).build();
}
private static LiteJobConfiguration createJobConfigurationParam() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(propertiesUtil.getPropertyAsString("JOB_NAME_PARAM"), propertiesUtil.getPropertyAsString("JOB_CRON_PARAM"), propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT_PARAM")).build();
private static LiteJobConfiguration createJobConfigurationIncrement() {
JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder(
propertiesUtil.getPropertyAsString("JOB_NAME_INCREMENT"),
propertiesUtil.getPropertyAsString("JOB_CRON_INCREMENT"),
propertiesUtil.getPropertyAsInt("SHARDING_TOTAL_COUNT_INCREMENT"))
.jobParameter("INCREMENT")
.build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, AutoTurnoverJob.class.getCanonicalName());
LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
return simpleJobRootConfig;
return LiteJobConfiguration.newBuilder(simpleJobConfig).build();
}
private static JobEventConfiguration createJobEventConfiguration() {
JobEventConfiguration jobEventRdbConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
return jobEventRdbConfig;
return new JobEventRdbConfiguration(setUpEventTraceDataSource());
}
private static DataSource setUpEventTraceDataSource() {
......
......@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.constant.Constant;
import com.bailuntec.domain.dto.CatagoryDTO;
import com.bailuntec.domain.dto.SalesVolumeAvgDTO;
import com.bailuntec.domain.dto.SalesVolumeDTO;
import com.bailuntec.domain.entity.*;
......@@ -30,9 +29,12 @@ import java.math.RoundingMode;
import java.net.URLDecoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
public class AutoTurnoverJob extends PointJob {
......@@ -42,29 +44,35 @@ public class AutoTurnoverJob extends PointJob {
@Override
public void executeJob(ShardingContext shardingContext, JobPointLog jobPointLog) {
long count = getTotalCount(shardingContext.getJobParameter());
//分片需要处理的总条数
long count = getTotalCount(shardingContext);
log.info("当前分片需要处理的总条数:{}", count);
//分片需要处理数据总页数
int totalPage = getTotalPage(count, jobPointLog.getPageSize());
/*
* 根据不同分片
* 再分页去处理数据
*/
int shardingSize = totalPage % shardingContext.getShardingTotalCount() == 0 ? totalPage / shardingContext.getShardingTotalCount() : totalPage / shardingContext.getShardingTotalCount() + 1;
if (shardingContext.getShardingItem() + 1 < shardingContext.getShardingTotalCount()) {
totalPage = shardingSize * (shardingContext.getShardingItem() + 1);
}
if (totalPage > 0) {
int page = 0;
if (shardingContext.getShardingItem() > 0) {
page = shardingSize * shardingContext.getShardingItem();
}
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now());
do {
List<DcBaseStock> dcBaseStockList = null;//分页查SKU_仓库
log.info("当前分片分页任务分页查询页码大小:{}", jobPointLog.getPageSize());
log.info("当前分片需要处理的总页数:{}", totalPage);
AtomicInteger countItem = new AtomicInteger(0);
ExecutorService executorService = new ThreadPoolExecutor(20,
100,
2,
TimeUnit.MINUTES,
new LinkedBlockingQueue<>(),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.CallerRunsPolicy());
for (int page = 1; page <= totalPage; page++) {
//分页查SKU_仓库
List<DcBaseStock> dcBaseStockList;
try {
DcBaseStockMapper baseStockMapperFor = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
//这里是根据id排序,方法名没改了
if (StringUtils.isBlank(shardingContext.getJobParameter())) {
dcBaseStockList = baseStockMapperFor.listStockById(page * jobPointLog.getPageSize(), jobPointLog.getPageSize());
dcBaseStockList = baseStockMapperFor.listStockById(shardingContext, (page - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
} else {
switch (shardingContext.getJobParameter()) {
case "国内仓":
......@@ -72,26 +80,42 @@ public class AutoTurnoverJob extends PointJob {
case "海外仓":
case "第三方仓库":
case "耗材仓":
dcBaseStockList = baseStockMapperFor.listParameterStockById(shardingContext.getJobParameter(),page * jobPointLog.getPageSize(), jobPointLog.getPageSize());
dcBaseStockList = baseStockMapperFor.listParameterStockById(shardingContext, (page - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
break;
case "ALL":
dcBaseStockList = baseStockMapperFor.listAllStock(page * jobPointLog.getPageSize(), jobPointLog.getPageSize());
dcBaseStockList = baseStockMapperFor.listAllStock(shardingContext, (page - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
break;
case "NORMAL":
dcBaseStockList = baseStockMapperFor.listNormal(shardingContext, (page - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
break;
case "INCREMENT":
LocalDateTime v1 = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).plusHours(3);
LocalDateTime v2 = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).minusDays(7);
dcBaseStockList = baseStockMapperFor.increment(shardingContext, v1, v2, (page - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
default:
dcBaseStockList = baseStockMapperFor.listWarehouseStockById(shardingContext.getJobParameter(),page * jobPointLog.getPageSize(), jobPointLog.getPageSize());
dcBaseStockList = baseStockMapperFor.listWarehouseStockById(shardingContext, shardingContext.getJobParameter(), (page - 1) * jobPointLog.getPageSize(), jobPointLog.getPageSize());
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Mybatis操作DB分页查询失败", e);
} finally {
SessionUtil.closeSession();
}
if (dcBaseStockList != null && dcBaseStockList.size() > 0) {
for (DcBaseStock dcBaseStock : dcBaseStockList) {
int finalPage1 = page;
dcBaseStockList.stream().parallel().forEach(dcBaseStock -> {
Integer finalPage = finalPage1;
log.info("当前页码:{},当前线程:{},当前sku:{},当前记录数:{}", finalPage,
Thread.currentThread().getName()
, dcBaseStock.getBailunSku() + "_" + dcBaseStock.getWarehouseCode()
, countItem.incrementAndGet());
try {
autoTurnoverFromStock(queryTime, dcBaseStock);
String queryTime = DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now());
this.autoTurnoverFromStock(queryTime, dcBaseStock);
} catch (Exception e) {
//错误记录到日志表, 任务跑完了再跑一次错误SKU
try {
......@@ -104,31 +128,35 @@ public class AutoTurnoverJob extends PointJob {
SessionUtil.closeSession();
}
}
});
}
}
page++;
} while (page <= totalPage);
}
}
private long getTotalCount(String jobParameter) {
private long getTotalCount(ShardingContext shardingContext) {
try {
DcBaseStockMapper baseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
if (StringUtils.isBlank(jobParameter)) {
if (StringUtils.isBlank(shardingContext.getJobParameter())) {
return baseStockMapper.countByExample(DcBaseStockExample.newAndCreateCriteria().example());
} else {
switch (jobParameter) {
switch (shardingContext.getJobParameter()) {
case "国内仓":
case "FBA仓":
case "海外仓":
case "第三方仓库":
case "耗材仓":
return baseStockMapper.countByParam(jobParameter);
return baseStockMapper.countByParam(shardingContext);
case "ALL":
return baseStockMapper.countAll();
return baseStockMapper.countAll(shardingContext);
//普通任务
case "NORMAL":
return baseStockMapper.countNormal(shardingContext);
case "INCREMENT":
LocalDateTime v1 = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).plusHours(3);
LocalDateTime v2 = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).minusDays(7);
return baseStockMapper.countIncrement(shardingContext, v1, v2);
default:
return baseStockMapper.countByWarehouseCode(jobParameter);
return baseStockMapper.countByWarehouseCode(shardingContext);
}
}
} catch (Exception e) {
......@@ -138,43 +166,60 @@ public class AutoTurnoverJob extends PointJob {
}
}
/**
* 基于库存
* 计算自动周转
* <p>
* 核心方法
* 基于库存计算自动周转
* </p>
*
* @param queryTime
* @throws Exception
* @param queryTime 时间
* @param dcBaseStock 库存
* @throws Exception ex
*/
public void autoTurnoverFromStock(String queryTime, DcBaseStock dcBaseStock) throws Exception {
//sku
String bailunSku = dcBaseStock.getBailunSku();
//仓库编码
String warehouseCode = dcBaseStock.getWarehouseCode();
DcAutoSales dcAutoSales = null;
DcBaseWarehouse dcBaseWarehouse = null;
DcAutoWarehouseweekSales dcAutoWarehouseweekSales = null;
//销量
DcAutoSales dcAutoSales;
//仓库
DcBaseWarehouse dcBaseWarehouse;
//自动周转周系数
DcAutoWarehouseweekSales dcAutoWarehouseweekSales;
try {
//库存mapper
DcBaseWarehouseMapper baseWarehouseMapper = SessionUtil.getSession().getMapper(DcBaseWarehouseMapper.class);
//库存对应的仓库
dcBaseWarehouse = baseWarehouseMapper.selectOneByExample(DcBaseWarehouseExample.newAndCreateCriteria().andWarehouseCodeEqualTo(warehouseCode).example());
BigDecimal incrementalRatio = BigDecimal.ONE;
int compareSales = 0;
DcAutoSalesMapper autoSalesMapper = null;
SalesVolumeDTO salesVolumeDTO = null;
//销量
DcAutoSalesMapper autoSalesMapper;
//jb
SalesVolumeDTO salesVolumeDTO;
//销量mapper
autoSalesMapper = SessionUtil.getSession().getMapper(DcAutoSalesMapper.class);
// 获取7、14日均销量
BigDecimal agvSales = autoSalesMapper.getSalesAvg(queryTime, bailunSku, warehouseCode);
//销量突增检测mapper
DcAutoUprushConfigMapper dcAutoUprushConfigMapper = SessionUtil.getSession().getMapper(DcAutoUprushConfigMapper.class);
DcAutoUprushConfig dcAutoUprushConfig = null;
if(dcBaseWarehouse != null) {
//如果仓库不为空
if (dcBaseWarehouse != null) {
//销量突增检测
dcAutoUprushConfig = dcAutoUprushConfigMapper.selectOneByWarehouse(warehouseCode, dcBaseWarehouse.getHqType());
}
if(dcAutoUprushConfig != null && agvSales != null) {
if (dcAutoUprushConfig != null && agvSales != null) {
// 突增销量 = (7+14日均销量)/2 * 突增率
incrementalRatio = incrementalRatio.add(dcAutoUprushConfig.getPercentage());
compareSales = agvSales.multiply(incrementalRatio).setScale(0, RoundingMode.UP).intValue();
}
autoSalesMapper = SessionUtil.getSession().getMapper(DcAutoSalesMapper.class);
if(compareSales == 0) {
if (compareSales == 0) {
salesVolumeDTO = autoSalesMapper.getSalesVolumeDTONoCompare(queryTime, bailunSku, warehouseCode);
}else {
} else {
salesVolumeDTO = autoSalesMapper.getSalesVolumeDTO(queryTime, bailunSku, warehouseCode, compareSales);
}
if (StringUtils.isEmpty(salesVolumeDTO.getHistorySales().trim())) {
......@@ -188,6 +233,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoSales = autoSalesServiceImpl.forecastSalesBySalesVolumeDTO(salesVolumeDTO);
}
DcAutoWarehouseweekSalesMapper dcAutoWarehouseweekSalesMapper = SessionUtil.getSession().getMapper(DcAutoWarehouseweekSalesMapper.class);
dcAutoWarehouseweekSales = dcAutoWarehouseweekSalesMapper.selectOneByWeekDay(warehouseCode);
} catch (Exception e) {
......@@ -199,15 +245,38 @@ public class AutoTurnoverJob extends PointJob {
autoTurnoverUseDcAutoSales(bailunSku, warehouseCode, dcAutoSales, dcBaseStock, dcBaseWarehouse, dcAutoWarehouseweekSales);
}
/*
/**
* <p>
* 将历史销量,dcAutoSales
* 根据历史销量拟合的销量函数曲线,dcAutoSales
* 库存信息传入,dcBaseStock
* 计算自动周转
* </p>
*
* @param bailunSku 百伦sku
* @param warehouseCode 仓库编码
* @param dcAutoSales 销量
* @param dcBaseStock 库存
* @param dcBaseWarehouse 仓库
* @param dcAutoWarehouseweekSales 自动周转系数
*/
private void autoTurnoverUseDcAutoSales(String bailunSku, String warehouseCode, DcAutoSales dcAutoSales, DcBaseStock dcBaseStock, DcBaseWarehouse dcBaseWarehouse, DcAutoWarehouseweekSales dcAutoWarehouseweekSales) throws Exception {
private void autoTurnoverUseDcAutoSales(String bailunSku,
String warehouseCode,
DcAutoSales dcAutoSales,
DcBaseStock dcBaseStock,
DcBaseWarehouse dcBaseWarehouse,
DcAutoWarehouseweekSales dcAutoWarehouseweekSales) throws Exception {
//记录时间
LocalDate recordTime = LocalDate.now();
DcAutoTurnover dcAutoTurnover = new DcAutoTurnover();
DcAutoTurnoverMapper dcAutoTurnoverMapper = SessionUtil.getSession().getMapper(DcAutoTurnoverMapper.class);
DcAutoTurnover dcAutoTurnover = dcAutoTurnoverMapper.selectOneByExample(DcAutoTurnoverExample.newAndCreateCriteria()
.andBailunSkuEqualTo(bailunSku)
.andWarehouseCodeEqualTo(warehouseCode).example());
if (dcAutoTurnover == null) {
dcAutoTurnover = new DcAutoTurnover();
}
dcAutoTurnover.setBailunSku(bailunSku);
dcAutoTurnover.setWarehouseCode(warehouseCode);
/*
......@@ -268,9 +337,9 @@ public class AutoTurnoverJob extends PointJob {
saveDays = BigDecimal.valueOf(4);
}*/
// JIT 周转天数默认为2、4天
if(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2)) {
if (turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2)) {
turnoverDays = 2;
}else {
} else {
turnoverDays = 4;
}
}
......@@ -372,7 +441,7 @@ public class AutoTurnoverJob extends PointJob {
* 可以支持配置
* 2019-04-22更新 不管逾期
*/
BigDecimal totalSafeInventory = calculateSafeInventory( turnoverSku, bailunSku, warehouseCode, bailunFirstLevelCatagoryId, dcAutoSales, JSON.toJSONString(forecastSalesList), dcAutoTurnover, saveDaysMap);
BigDecimal totalSafeInventory = calculateSafeInventory(turnoverSku, bailunSku, warehouseCode, bailunFirstLevelCatagoryId, dcAutoSales, JSON.toJSONString(forecastSalesList), dcAutoTurnover, saveDaysMap);
Integer moq = turnoverSku.getMoq();
/*
......@@ -451,7 +520,7 @@ public class AutoTurnoverJob extends PointJob {
* 自动下单管理的冗余-缺货等异常提醒
*/
if (hasMonitorFluctuation) {
unusualFluctuation(totalSafeInventory, turnoverDays, recordTime, dcAutoConfigSkuWarehouse, turnoverSku, warehouseCode, dcAutoTurnover, avgHistoryThreedaySales, forecastFluctuationList, forecastShortSupplyList, forecastInventoryList,dcBaseStock);
unusualFluctuation(totalSafeInventory, turnoverDays, recordTime, dcAutoConfigSkuWarehouse, turnoverSku, warehouseCode, dcAutoTurnover, avgHistoryThreedaySales, forecastFluctuationList, forecastShortSupplyList, forecastInventoryList, dcBaseStock);
}
//拿一下2倍周转期内的入库总数
......@@ -521,9 +590,9 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setStockUpDays(stockUpDays);
dcAutoTurnover.setStockUpSales(stockUpSales);
dcAutoTurnover.setQuantityBeginAdvise(forecastPurchaseAdvisedList.get(0));
if(turnoverDays == 0) {
if (turnoverDays == 0) {
dcAutoTurnover.setForecastTurnoverdaySales(avgForecastTurnoverDaySales);
}else{
} else {
dcAutoTurnover.setForecastTurnoverdaySales(avgForecastTurnoverDaySales.divide(BigDecimal.valueOf(turnoverDays), 3, RoundingMode.HALF_EVEN));
}
dcAutoTurnover.setSalesExplainDetails(forecastSalesExplainList.toString());
......@@ -548,7 +617,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setPromotions(promotionsBuilder.toString());
if ((warehouseCode.equals(Constant.WAREHOUSE_JIT) && (turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_1) || turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2))) || (warehouseCode.equals(Constant.WAREHOUSE_JIT1) && (turnoverSku.getBuyerName().equals(Constant.BUTER_JIT_5)))) {
dcAutoTurnover.setQuantityInitAdvise(forecastPurchaseAdvisedList.get(0));
}else{
} else {
dcAutoTurnover.setQuantityInitAdvise(forecastPurchaseAdvisedList.get(0).add(stockUpSales));
}
//如果初始建议数 + 备货数 > moq建议数, 那么moq建议数 + 备货数, 否则, 还是取moq建议数
......@@ -580,19 +649,8 @@ public class AutoTurnoverJob extends PointJob {
* 断货=前一天还有库存,但是今天库存为0了则是已经断货
* */
dcAutoTurnover.setIs_out_stock(0);
// if(dcBaseStock.getUsableStock()==0)
// {
// //获取前一天库存
// Integer yesterdayStock = autoTurnoverMapper.yesterdayStock(dcAutoTurnover.getBailunSku(),dcAutoTurnover.getWarehouseCode());
// if(yesterdayStock!=null && yesterdayStock>0)
// {
// dcAutoTurnover.setIs_out_stock(1);
// }
// }
//End Add
dcAutoTurnover.setGmtModified(LocalDateTime.now());
// DcBaseStockMapper dcBaseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
int i = autoTurnoverMapper.updateByExampleSelective(dcAutoTurnover, DcAutoTurnoverExample.newAndCreateCriteria().andBailunSkuEqualTo(dcAutoTurnover.getBailunSku()).andWarehouseCodeEqualTo(dcAutoTurnover.getWarehouseCode()).example());
if (i == 0) {
autoTurnoverMapper.insertSelective(dcAutoTurnover);
......@@ -733,7 +791,7 @@ public class AutoTurnoverJob extends PointJob {
* 实际冗余的,预计冗余(库存> 销量 + 安全库存)
* 波动提醒优先级 --> 实际缺货-实际断货-实际冗余-预计缺货-预计冗余
*/
private void unusualFluctuation(BigDecimal totalSafeInventory, Integer turnoverDays, LocalDate recordTime, DcAutoConfigSkuWarehouse dcAutoConfigSkuWarehouse, DcBaseSku turnoverSku, String warehouseCode, DcAutoTurnover dcAutoTurnover, BigDecimal avgHistoryThreedaySales, List<DcAutoForecastFluctuation> forecastFluctuationList, List<BigDecimal> forecastShortSupplyList, List<BigDecimal> forecastInventoryList,DcBaseStock dcBaseStock) {
private void unusualFluctuation(BigDecimal totalSafeInventory, Integer turnoverDays, LocalDate recordTime, DcAutoConfigSkuWarehouse dcAutoConfigSkuWarehouse, DcBaseSku turnoverSku, String warehouseCode, DcAutoTurnover dcAutoTurnover, BigDecimal avgHistoryThreedaySales, List<DcAutoForecastFluctuation> forecastFluctuationList, List<BigDecimal> forecastShortSupplyList, List<BigDecimal> forecastInventoryList, DcBaseStock dcBaseStock) {
int days = 0;//连续冗余或缺货天数
int index = -1;//冗余或缺货天数索引
......@@ -797,12 +855,10 @@ public class AutoTurnoverJob extends PointJob {
* Add by Allan at 2020-07-23 10:58
* 断货=前一天还有库存,但是今天库存为0了则是已经断货
* */
if(forecastFluctuationList.get(0).getType()!=1 && dcBaseStock.getUsableStock()==0)
{
if (forecastFluctuationList.get(0).getType() != 1 && dcBaseStock.getUsableStock() == 0) {
//获取前一天库存
Integer yesterdayStock = mapper.yesterdayStock(dcAutoTurnover.getBailunSku(),dcAutoTurnover.getWarehouseCode());
if(yesterdayStock!=null && yesterdayStock>0)
{
Integer yesterdayStock = mapper.yesterdayStock(dcAutoTurnover.getBailunSku(), dcAutoTurnover.getWarehouseCode());
if (yesterdayStock != null && yesterdayStock > 0) {
dcAutoForecastFluctuation.setType(5); //实际断货
dcAutoForecastFluctuation.setStartTime(LocalDate.now()); //保存当天日期
dcAutoForecastFluctuation.setEndTime(LocalDate.now()); //保存当天日期
......@@ -1080,7 +1136,7 @@ public class AutoTurnoverJob extends PointJob {
}*/
// JIT 推送时间21天之内的sku 预测销量为最近7天均值
if(turnoverSku.getPushTime() != null && recordTime.minusDays(21L).isBefore(turnoverSku.getPushTime().toLocalDate()) && !(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_1)) && !(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2)) && !(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_4))) {
if (turnoverSku.getPushTime() != null && recordTime.minusDays(21L).isBefore(turnoverSku.getPushTime().toLocalDate()) && !(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_1)) && !(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_2)) && !(turnoverSku.getBuyerName().equals(Constant.BUYER_JIT_4))) {
/*DcBaseOmsSkuMapper dcBaseOmsSkuMapper = SessionUtil.getSession().getMapper(DcBaseOmsSkuMapper.class);
DcBaseOmsSku dcBaseOmsSku = dcBaseOmsSkuMapper.selectOneByCreateTime(bailunSku);*/
......@@ -1092,21 +1148,21 @@ public class AutoTurnoverJob extends PointJob {
historySevenSales += historySalesList.get(23 + i);
}
BigDecimal avgHistorySevendaySales = BigDecimal.valueOf(historySevenSales.longValue()).divide(Constant.BIGDECIMAL_SEVEN, 3, RoundingMode.HALF_EVEN);
for(int j = 0; j < autoForecastDay; j++) {
for (int j = 0; j < autoForecastDay; j++) {
forecastSalesList.set(j, avgHistorySevendaySales);
}
}else{
} else {
BigDecimal forecastSales = BigDecimal.ZERO;
List<Integer> historySalesList = JSON.parseObject(dcAutoSales.getHistorySalesDetails(), new TypeReference<List<Integer>>() {
});
List<Integer> weekRateList = null;
int weekTime = 0;
boolean hasValue = true;
if(dcAutoWarehouseweekSales == null) {
if (dcAutoWarehouseweekSales == null) {
hasValue = false;
}else{
weekRateList = JSON.parseObject("["+dcAutoWarehouseweekSales.getRateDetail()+"]", new TypeReference<List<Integer>>(){
} else {
weekRateList = JSON.parseObject("[" + dcAutoWarehouseweekSales.getRateDetail() + "]", new TypeReference<List<Integer>>() {
});
weekTime = Integer.valueOf(dcAutoWarehouseweekSales.getWeekTime());
}
......@@ -1123,54 +1179,54 @@ public class AutoTurnoverJob extends PointJob {
forecastSalesList.set(j, forecastSales.compareTo(salesUpperLimit) == 1 ? salesUpperLimit : forecastSales);*/
//20191127 预测销量更改为:(过去第四周*0.1 + 过去第三周*0.1 + 过去第二周*0.3 + 过去第一周*0.5)* 周系数
if(0 <= j && j<7 ) {
forecastSales = BigDecimal.valueOf(historySalesList.get(2+j)).multiply(BigDecimal.valueOf(0.1)).
add(BigDecimal.valueOf(historySalesList.get(9+j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(16+j)).multiply(BigDecimal.valueOf(0.3))).
add(BigDecimal.valueOf(historySalesList.get(23+j)).multiply(BigDecimal.valueOf(0.5)));
if(hasValue) {
if (0 <= j && j < 7) {
forecastSales = BigDecimal.valueOf(historySalesList.get(2 + j)).multiply(BigDecimal.valueOf(0.1)).
add(BigDecimal.valueOf(historySalesList.get(9 + j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(16 + j)).multiply(BigDecimal.valueOf(0.3))).
add(BigDecimal.valueOf(historySalesList.get(23 + j)).multiply(BigDecimal.valueOf(0.5)));
if (hasValue) {
forecastSales = forecastSales.multiply(BigDecimal.valueOf(weekRateList.get(weekTime)).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : BigDecimal.valueOf(weekRateList.get(weekTime)));
}
}else if(7 <= j && j < 14) {
forecastSales = (BigDecimal.valueOf(historySalesList.get(2+j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(9+j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(16+j)).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j-7).multiply(BigDecimal.valueOf(0.5)));
if(hasValue) {
if(weekTime > 51) {
} else if (7 <= j && j < 14) {
forecastSales = (BigDecimal.valueOf(historySalesList.get(2 + j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(9 + j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(16 + j)).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j - 7).multiply(BigDecimal.valueOf(0.5)));
if (hasValue) {
if (weekTime > 51) {
weekTime = weekTime - 51;
}
forecastSales = forecastSales.multiply(BigDecimal.valueOf(weekRateList.get(weekTime)).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : BigDecimal.valueOf(weekRateList.get(weekTime)));
}
}else if(14 <= j && j < 21) {
forecastSales = (BigDecimal.valueOf(historySalesList.get(2+j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(9+j)).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j-14).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j-7).multiply(BigDecimal.valueOf(0.5)));
if(hasValue) {
if(weekTime > 50) {
} else if (14 <= j && j < 21) {
forecastSales = (BigDecimal.valueOf(historySalesList.get(2 + j)).multiply(BigDecimal.valueOf(0.1))).
add(BigDecimal.valueOf(historySalesList.get(9 + j)).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j - 14).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j - 7).multiply(BigDecimal.valueOf(0.5)));
if (hasValue) {
if (weekTime > 50) {
weekTime = weekTime - 50;
}
forecastSales = forecastSales.multiply(BigDecimal.valueOf(weekRateList.get(weekTime)).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : BigDecimal.valueOf(weekRateList.get(weekTime)));
}
}else if(21 <= j && j < 27) {
forecastSales = (BigDecimal.valueOf(historySalesList.get(2+j)).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j-21).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j-14).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j-7).multiply(BigDecimal.valueOf(0.5)));
if(hasValue) {
if(weekTime > 49) {
} else if (21 <= j && j < 27) {
forecastSales = (BigDecimal.valueOf(historySalesList.get(2 + j)).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j - 21).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j - 14).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j - 7).multiply(BigDecimal.valueOf(0.5)));
if (hasValue) {
if (weekTime > 49) {
weekTime = weekTime - 49;
}
forecastSales = forecastSales.multiply(BigDecimal.valueOf(weekRateList.get(weekTime)).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : BigDecimal.valueOf(weekRateList.get(weekTime)));
}
}else if(27 <= j && j < autoForecastDay) {
forecastSales = (forecastSalesList.get(j-27).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j-21).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j-14).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j-7).multiply(BigDecimal.valueOf(0.5)));
if(hasValue) {
if(weekTime > 48) {
} else if (27 <= j && j < autoForecastDay) {
forecastSales = (forecastSalesList.get(j - 27).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j - 21).multiply(BigDecimal.valueOf(0.1))).
add(forecastSalesList.get(j - 14).multiply(BigDecimal.valueOf(0.3))).
add(forecastSalesList.get(j - 7).multiply(BigDecimal.valueOf(0.5)));
if (hasValue) {
if (weekTime > 48) {
weekTime = weekTime - 48;
}
forecastSales = forecastSales.multiply(BigDecimal.valueOf(weekRateList.get(weekTime)).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : BigDecimal.valueOf(weekRateList.get(weekTime)));
......@@ -1300,7 +1356,7 @@ public class AutoTurnoverJob extends PointJob {
}
}
private BigDecimal calculateSafeInventory( DcBaseSku turnoverSku, String bailunSku, String warehouseCode, Integer
private BigDecimal calculateSafeInventory(DcBaseSku turnoverSku, String bailunSku, String warehouseCode, Integer
bailunFirstLevelCatagoryId, DcAutoSales dcAutoSales, String forecastSalesListJson, DcAutoTurnover dcAutoTurnover, Map<String, BigDecimal> saveDaysMap) {
/*
* 先判断是否JIT 仓库是广州01 warehouse_code 且是那三个销售员 turnoversku
......@@ -1312,7 +1368,7 @@ public class AutoTurnoverJob extends PointJob {
List<BigDecimal> historyThirtySalesList = JSON.parseObject(dcAutoSales.getHistorySalesDetails(), new TypeReference<List<BigDecimal>>() {
});
BigDecimal weightingAvgSales = caculateWeightingAvgSales(BigDecimal.valueOf(0.3), BigDecimal.valueOf(0.3), BigDecimal.valueOf(0.4), historyThirtySalesList);
if(dcAutoStockUpRange == null && (warehouseCode.equals(Constant.WAREHOUSE_JIT1) && (turnoverSku.getBuyerName().equals(Constant.BUTER_JIT_5)))) {
if (dcAutoStockUpRange == null && (warehouseCode.equals(Constant.WAREHOUSE_JIT1) && (turnoverSku.getBuyerName().equals(Constant.BUTER_JIT_5)))) {
dcAutoStockUpRange = new DcAutoStockUpRange();
dcAutoStockUpRange.setBailunSku(bailunSku);
dcAutoStockUpRange.setGroupId(2);
......@@ -1325,7 +1381,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setDailyWeightedSales(weightingAvgSales);
weightingAvgSales = weightingAvgSales.multiply(saveDays);
return weightingAvgSales;
}else{
} else {
/*
* 手动设置
* 1. 根据仓库 + SKU在表里找dc_auto_config_safe_inventory
......@@ -1581,7 +1637,7 @@ public class AutoTurnoverJob extends PointJob {
totalSales = dcAutoTurnover.getDailyWeightedSales().multiply(BigDecimal.valueOf(turnoverDays));
totalSales = dcAutoTurnover.getDailyWeightedSales().multiply(BigDecimal.valueOf(turnoverDays));
dcAutoTurnover.setTurnoverSales(totalSales);
}else{
} else {
dcAutoTurnover.setTurnoverSales(totalSales);
}
}
......@@ -1690,7 +1746,7 @@ public class AutoTurnoverJob extends PointJob {
dcAutoTurnover.setTurnoverSales(totalSales);
BigDecimal transNumber = BigDecimal.ZERO;
BigDecimal forecastInbound = BigDecimal.ZERO;
if(saveDays != null) {
if (saveDays != null) {
for (int trans = 0; trans < autoForecastDay; trans++) {
forecastInbound = BigDecimal.valueOf(forecastInboundList.get(trans));
transNumber = transNumber.add(forecastInbound);
......@@ -1701,7 +1757,7 @@ public class AutoTurnoverJob extends PointJob {
.add(BigDecimal.valueOf(outStock.longValue())); //今天的实际缺货
firstAdvice = false;
}
}else if(warehouseCode.equals(Constant.WAREHOUSE_JIT1) && (turnoverSku.getBuyerName().equals(Constant.BUTER_JIT_5))) {
} else if (warehouseCode.equals(Constant.WAREHOUSE_JIT1) && (turnoverSku.getBuyerName().equals(Constant.BUTER_JIT_5))) {
DcBaseStockMapper dcBaseStockMapper = SessionUtil.getSession().getMapper(DcBaseStockMapper.class);
DcBaseStock dcBaseStock = dcBaseStockMapper.selectOneByExample(DcBaseStockExample.newAndCreateCriteria().andBailunSkuEqualTo(bailunSku).andWarehouseCodeEqualTo(Constant.WAREHOUSE_JIT).example());
......@@ -1727,18 +1783,18 @@ public class AutoTurnoverJob extends PointJob {
totalSales = dcAutoTurnover.getDailyWeightedSales().multiply(BigDecimal.valueOf(turnoverDays));
dcAutoTurnover.setTurnoverSales(totalSales);
BigDecimal forecastInbound = BigDecimal.ZERO;
if(saveDays != null) {
if (saveDays != null) {
totalSales = dcAutoTurnover.getDailyWeightedSales().multiply(saveDays);
totalAdvised = totalSales.subtract(outStock > 0 ? BigDecimal.ZERO : BigDecimal.valueOf(realInventory.longValue())) //真实库存,如果缺货就不减
.subtract(outStock01 > 0 ? BigDecimal.ZERO : ((dcBaseStock != null && dcBaseStock.getUsableStock() != null) ? BigDecimal.valueOf(dcBaseStock.getUsableStock()) : BigDecimal.ZERO)) //广州014仓库存
.subtract(BigDecimal.valueOf(purchase + transfer)); //广州001仓在途数
firstAdvice = false;
}
}else{
} else {
dcAutoTurnover.setTurnoverSales(totalSales);
}
}
if(firstAdvice){
if (firstAdvice) {
//采购建议 = 安全库存缺少值 + 今日的实际缺货 + 本次采购到货日期前一天的累计销量 - 本次采购到货日期累计到货数量 + 预计销量
totalAdvised = totalSafeInventory.subtract(forecastInventoryList.get(j > 0 ? j - 1 : 0))//安全库存缺少值= 理论安全库存 - 预测库存
.add(BigDecimal.valueOf(outStock.longValue()))//今天的实际缺货
......@@ -2198,7 +2254,7 @@ public class AutoTurnoverJob extends PointJob {
continue;
}
}
if(dcAutoJitTag.getEnable30() == 1) {
if (dcAutoJitTag.getEnable30() == 1) {
switch (dcAutoJitTag.getIsGt30()) {
case 1:
if (avgHistoryThirtydaySales.compareTo(dcAutoJitTag.getQuantitySales30()) == 1) {
......@@ -2234,7 +2290,7 @@ public class AutoTurnoverJob extends PointJob {
continue;
}
}
if(StringUtils.isNotBlank(buyerName) && StringUtils.isNotBlank(dcAutoJitTag.getBuyerName()) && !buyerName.equals(dcAutoJitTag.getBuyerName()))
if (StringUtils.isNotBlank(buyerName) && StringUtils.isNotBlank(dcAutoJitTag.getBuyerName()) && !buyerName.equals(dcAutoJitTag.getBuyerName()))
continue;
saveDays = dcAutoJitTag.getQuantitySafeInventory();
if ("weightingAvgSales".equals(autoForecastDay)) {
......
......@@ -7,7 +7,6 @@ import com.bailuntec.domain.example.DcAutoExceptionExample;
import com.bailuntec.domain.example.DcBaseStockExample;
import com.bailuntec.job.AutoTurnoverJob;
import com.bailuntec.mapper.DcAutoExceptionMapper;
import com.bailuntec.mapper.DcAutoTurnoverMapper;
import com.bailuntec.mapper.DcBaseStockMapper;
import com.bailuntec.utils.SessionUtil;
import com.dangdang.ddframe.job.executor.ShardingContexts;
......@@ -23,22 +22,7 @@ import java.util.List;
public class AutoTurnoverJobListener implements ElasticJobListener {
@Override
public void beforeJobExecuted(ShardingContexts shardingContexts) {
try {
DcAutoTurnoverMapper autoTurnoverMapper = SessionUtil.getSession().getMapper(DcAutoTurnoverMapper.class);
if ( shardingContexts.getJobName().equals("show-auto-turnover")) {
autoTurnoverMapper.truncateAutoInboundTable();
autoTurnoverMapper.truncateAutoInventoryTable();
autoTurnoverMapper.truncateAutoShortSupplyTable();
autoTurnoverMapper.truncateAutoTurnoverTable();
autoTurnoverMapper.truncateAutoSalesTable();
autoTurnoverMapper.truncateAutoExceptionTable();
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Mybatis操作DB失败", e);
} finally {
SessionUtil.closeSession();
}
}
@Override
......
#EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
#EVENT_RDB_STORAGE_URL=jdbc:mysql://gz-cdb-kp7s5i79.sql.tencentcdb.com:61691/bailun_datacenter?serverTimezone=GMT%2B8&characterEncoding=utf-8
EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
EVENT_RDB_STORAGE_URL=jdbc:mysql://gz-cdb-kp7s5i79.sql.tencentcdb.com:61691/bailun_datacenter?serverTimezone=GMT%2B8&characterEncoding=utf-8
#EVENT_RDB_STORAGE_USERNAME=root
#EVENT_RDB_STORAGE_PASSWORD=123456
#ZOOKEEPER_SERVER=127.0.0.1:2181
EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
EVENT_RDB_STORAGE_URL=jdbc:mysql://10.0.8.15:3306/bailun_datacenter?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
#EVENT_RDB_STORAGE_DRIVER=com.mysql.jdbc.Driver
#EVENT_RDB_STORAGE_URL=jdbc:mysql://10.0.8.15:3306/bailun_datacenter?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
EVENT_RDB_STORAGE_USERNAME=root
EVENT_RDB_STORAGE_PASSWORD=#7kfnymAM$Y9-Ntf
ZOOKEEPER_SERVER=172.31.255.120:2181
NAME_SPACE=data-center
JOB_NAME=show-auto-turnover
JOB_CRON=0 30 0 * * ? *
JOB_CRON=0 0 3 * * ?
SHARDING_TOTAL_COUNT=8
JOB_NAME_PARAM=show-auto-turnover-param
JOB_CRON_PARAM=0 30 0 * * ? 2099
JOB_CRON_PARAM=0 0 14 * * ?
SHARDING_TOTAL_COUNT_PARAM=8
JOB_NAME_INCREMENT=show-auto-turnover-param
JOB_CRON_INCREMENT=0 0 14 * * ?
SHARDING_TOTAL_COUNT_INCREMENT=8
#log4j.rootLogger=DEBUG,console,dailyFile,im
#log4j.additivity.org.apache=true
## 控制台(console)
#log4j.appender.console=org.apache.log4j.ConsoleAppender
#log4j.appender.console.Threshold=DEBUG
#log4j.appender.console.ImmediateFlush=true
#log4j.appender.console.Target=System.err
#log4j.appender.console.layout=org.apache.log4j.PatternLayout
#log4j.appender.console.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
## 日志文件(logFile)
#log4j.appender.logFile=org.apache.log4j.FileAppender
#log4j.appender.logFile.Threshold=DEBUG
#log4j.appender.logFile.ImmediateFlush=true
#log4j.appender.logFile.Append=true
#log4j.appender.logFile.File=/logs/log.log4j
#log4j.appender.logFile.layout=org.apache.log4j.PatternLayout
#log4j.appender.logFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
## 回滚文件(rollingFile)
#log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
#log4j.appender.rollingFile.Threshold=DEBUG
#log4j.appender.rollingFile.ImmediateFlush=true
#log4j.appender.rollingFile.Append=true
#log4j.appender.rollingFile.File=/logs/log.log4j
#log4j.appender.rollingFile.MaxFileSize=200KB
#log4j.appender.rollingFile.MaxBackupIndex=50
#log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
#log4j.appender.rollingFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
## 定期回滚日志文件(dailyFile)
#log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.dailyFile.Threshold=DEBUG
#log4j.appender.dailyFile.ImmediateFlush=true
#log4j.appender.dailyFile.Append=true
#log4j.appender.dailyFile.File=/logs/log.log4j
#log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd
#log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout
#log4j.appender.dailyFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
## 应用于socket
#log4j.appender.socket=org.apache.log4j.RollingFileAppender
#log4j.appender.socket.RemoteHost=localhost
#log4j.appender.socket.Port=5001
#log4j.appender.socket.LocationInfo=true
## Set up for Log Factor 5
#log4j.appender.socket.layout=org.apache.log4j.PatternLayout
#log4j.appender.socket.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
## Log Factor 5 Appender
#log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender
#log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000
## 发送日志到指定邮件
#log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#log4j.appender.mail.Threshold=FATAL
#log4j.appender.mail.BufferSize=10
#log4j.appender.mail.From = xxx@mail.com
#log4j.appender.mail.SMTPHost=mail.com
#log4j.appender.mail.Subject=Log4J Message
#log4j.appender.mail.To= xxx@mail.com
#log4j.appender.mail.layout=org.apache.log4j.PatternLayout
#log4j.appender.mail.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
## 应用于数据库
#log4j.appender.database=org.apache.log4j.jdbc.JDBCAppender
#log4j.appender.database.URL=jdbc:mysql://localhost:3306/test
#log4j.appender.database.driver=com.mysql.jdbc.Driver
#log4j.appender.database.user=root
#log4j.appender.database.password=
#log4j.appender.database.sql=INSERT INTO LOG4J (Message) VALUES('=[%-5p] %d(%r) --> [%t] %l: %m %x %n')
#log4j.appender.database.layout=org.apache.log4j.PatternLayout
#log4j.appender.database.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
#
## 自定义Appender
#log4j.appender.im = net.cybercorlin.util.logger.appender.IMAppender
#log4j.appender.im.host = mail.cybercorlin.net
#log4j.appender.im.username = username
#log4j.appender.im.password = password
#log4j.appender.im.recipient = corlin@cybercorlin.net
#log4j.appender.im.layout=org.apache.log4j.PatternLayout
#log4j.appender.im.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
......@@ -98,8 +98,8 @@ public class AutoTurnoverTest {
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
HashMap<Integer, String> map = new HashMap<>();
map.put(1,"");
ShardingContext shardingContext = new ShardingContext(new ShardingContexts("","",4,"", map), 3);
JobPointLog jobPointLog = new JobPointLog("", 1, 2000, 1, 1, LocalDateTime.now().minusSeconds(1), LocalDateTime.now());
ShardingContext shardingContext = new ShardingContext(new ShardingContexts("","",8,"NORMAL", map), 5);
JobPointLog jobPointLog = new JobPointLog("", 1, 400, 1, 1, LocalDateTime.now().minusSeconds(1), LocalDateTime.now());
autoTurnoverJob.executeJob(shardingContext, jobPointLog);
}
......
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