Commit 05fd6bb1 by yinyong

数据中心--库存

parent 5134c487
......@@ -92,6 +92,24 @@ public class DcMidStockDate {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_mid_stock_date.init_stock
*
* @mbg.generated
*/
private Integer initStock;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_mid_stock_date.has_init
*
* @mbg.generated
*/
private Boolean hasInit;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column dc_mid_stock_date.has_transfer
*
* @mbg.generated
......@@ -128,6 +146,8 @@ public class DcMidStockDate {
sb.append(", quantityStock=").append(quantityStock);
sb.append(", stockTime=").append(stockTime);
sb.append(", unitPrice=").append(unitPrice);
sb.append(", initStock=").append(initStock);
sb.append(", hasInit=").append(hasInit);
sb.append(", hasTransfer=").append(hasTransfer);
sb.append(", reportDate=").append(reportDate);
sb.append("]");
......@@ -161,6 +181,8 @@ public class DcMidStockDate {
&& (this.getQuantityStock() == null ? other.getQuantityStock() == null : this.getQuantityStock().equals(other.getQuantityStock()))
&& (this.getStockTime() == null ? other.getStockTime() == null : this.getStockTime().equals(other.getStockTime()))
&& (this.getUnitPrice() == null ? other.getUnitPrice() == null : this.getUnitPrice().equals(other.getUnitPrice()))
&& (this.getInitStock() == null ? other.getInitStock() == null : this.getInitStock().equals(other.getInitStock()))
&& (this.getHasInit() == null ? other.getHasInit() == null : this.getHasInit().equals(other.getHasInit()))
&& (this.getHasTransfer() == null ? other.getHasTransfer() == null : this.getHasTransfer().equals(other.getHasTransfer()))
&& (this.getReportDate() == null ? other.getReportDate() == null : this.getReportDate().equals(other.getReportDate()));
}
......@@ -184,6 +206,8 @@ public class DcMidStockDate {
result = prime * result + ((getQuantityStock() == null) ? 0 : getQuantityStock().hashCode());
result = prime * result + ((getStockTime() == null) ? 0 : getStockTime().hashCode());
result = prime * result + ((getUnitPrice() == null) ? 0 : getUnitPrice().hashCode());
result = prime * result + ((getInitStock() == null) ? 0 : getInitStock().hashCode());
result = prime * result + ((getHasInit() == null) ? 0 : getHasInit().hashCode());
result = prime * result + ((getHasTransfer() == null) ? 0 : getHasTransfer().hashCode());
result = prime * result + ((getReportDate() == null) ? 0 : getReportDate().hashCode());
return result;
......
......@@ -942,6 +942,126 @@ public class DcMidStockDateExample {
return (Criteria) this;
}
public Criteria andInitStockIsNull() {
addCriterion("init_stock is null");
return (Criteria) this;
}
public Criteria andInitStockIsNotNull() {
addCriterion("init_stock is not null");
return (Criteria) this;
}
public Criteria andInitStockEqualTo(Integer value) {
addCriterion("init_stock =", value, "initStock");
return (Criteria) this;
}
public Criteria andInitStockNotEqualTo(Integer value) {
addCriterion("init_stock <>", value, "initStock");
return (Criteria) this;
}
public Criteria andInitStockGreaterThan(Integer value) {
addCriterion("init_stock >", value, "initStock");
return (Criteria) this;
}
public Criteria andInitStockGreaterThanOrEqualTo(Integer value) {
addCriterion("init_stock >=", value, "initStock");
return (Criteria) this;
}
public Criteria andInitStockLessThan(Integer value) {
addCriterion("init_stock <", value, "initStock");
return (Criteria) this;
}
public Criteria andInitStockLessThanOrEqualTo(Integer value) {
addCriterion("init_stock <=", value, "initStock");
return (Criteria) this;
}
public Criteria andInitStockIn(List<Integer> values) {
addCriterion("init_stock in", values, "initStock");
return (Criteria) this;
}
public Criteria andInitStockNotIn(List<Integer> values) {
addCriterion("init_stock not in", values, "initStock");
return (Criteria) this;
}
public Criteria andInitStockBetween(Integer value1, Integer value2) {
addCriterion("init_stock between", value1, value2, "initStock");
return (Criteria) this;
}
public Criteria andInitStockNotBetween(Integer value1, Integer value2) {
addCriterion("init_stock not between", value1, value2, "initStock");
return (Criteria) this;
}
public Criteria andHasInitIsNull() {
addCriterion("has_init is null");
return (Criteria) this;
}
public Criteria andHasInitIsNotNull() {
addCriterion("has_init is not null");
return (Criteria) this;
}
public Criteria andHasInitEqualTo(Boolean value) {
addCriterion("has_init =", value, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitNotEqualTo(Boolean value) {
addCriterion("has_init <>", value, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitGreaterThan(Boolean value) {
addCriterion("has_init >", value, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitGreaterThanOrEqualTo(Boolean value) {
addCriterion("has_init >=", value, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitLessThan(Boolean value) {
addCriterion("has_init <", value, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitLessThanOrEqualTo(Boolean value) {
addCriterion("has_init <=", value, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitIn(List<Boolean> values) {
addCriterion("has_init in", values, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitNotIn(List<Boolean> values) {
addCriterion("has_init not in", values, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitBetween(Boolean value1, Boolean value2) {
addCriterion("has_init between", value1, value2, "hasInit");
return (Criteria) this;
}
public Criteria andHasInitNotBetween(Boolean value1, Boolean value2) {
addCriterion("has_init not between", value1, value2, "hasInit");
return (Criteria) this;
}
public Criteria andHasTransferIsNull() {
addCriterion("has_transfer is null");
return (Criteria) this;
......
......@@ -121,4 +121,6 @@ public interface DcMidStockDateMapper {
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int upsertSelective(DcMidStockDate record);
int selectCount(@Param("bailunSku")String bailunSku, @Param("warehouseCode")String warehouseCode);
}
\ No newline at end of file
......@@ -15,6 +15,8 @@
<result column="quantity_stock" jdbcType="INTEGER" property="quantityStock" />
<result column="stock_time" jdbcType="DATE" property="stockTime" />
<result column="unit_price" jdbcType="DECIMAL" property="unitPrice" />
<result column="init_stock" jdbcType="INTEGER" property="initStock" />
<result column="has_init" jdbcType="BIT" property="hasInit" />
<result column="has_transfer" jdbcType="INTEGER" property="hasTransfer" />
<result column="report_date" jdbcType="DATE" property="reportDate" />
</resultMap>
......@@ -90,7 +92,7 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, gmt_create, gmt_modified, bailun_sku, warehouse_code, warehouse_name, quantity_stock,
stock_time, unit_price, has_transfer, report_date
stock_time, unit_price, init_stock, has_init, has_transfer, report_date
</sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcMidStockDateExample" resultMap="BaseResultMap">
<!--
......@@ -154,11 +156,13 @@
insert into dc_mid_stock_date (id, gmt_create, gmt_modified,
bailun_sku, warehouse_code, warehouse_name,
quantity_stock, stock_time, unit_price,
has_transfer, report_date)
init_stock, has_init, has_transfer,
report_date)
values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, #{warehouseName,jdbcType=VARCHAR},
#{quantityStock,jdbcType=INTEGER}, #{stockTime,jdbcType=DATE}, #{unitPrice,jdbcType=DECIMAL},
#{hasTransfer,jdbcType=INTEGER}, #{reportDate,jdbcType=DATE})
#{initStock,jdbcType=INTEGER}, #{hasInit,jdbcType=BIT}, #{hasTransfer,jdbcType=INTEGER},
#{reportDate,jdbcType=DATE})
</insert>
<insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcMidStockDate">
<!--
......@@ -194,6 +198,12 @@
<if test="unitPrice != null">
unit_price,
</if>
<if test="initStock != null">
init_stock,
</if>
<if test="hasInit != null">
has_init,
</if>
<if test="hasTransfer != null">
has_transfer,
</if>
......@@ -229,6 +239,12 @@
<if test="unitPrice != null">
#{unitPrice,jdbcType=DECIMAL},
</if>
<if test="initStock != null">
#{initStock,jdbcType=INTEGER},
</if>
<if test="hasInit != null">
#{hasInit,jdbcType=BIT},
</if>
<if test="hasTransfer != null">
#{hasTransfer,jdbcType=INTEGER},
</if>
......@@ -281,6 +297,12 @@
<if test="record.unitPrice != null">
unit_price = #{record.unitPrice,jdbcType=DECIMAL},
</if>
<if test="record.initStock != null">
init_stock = #{record.initStock,jdbcType=INTEGER},
</if>
<if test="record.hasInit != null">
has_init = #{record.hasInit,jdbcType=BIT},
</if>
<if test="record.hasTransfer != null">
has_transfer = #{record.hasTransfer,jdbcType=INTEGER},
</if>
......@@ -307,6 +329,8 @@
quantity_stock = #{record.quantityStock,jdbcType=INTEGER},
stock_time = #{record.stockTime,jdbcType=DATE},
unit_price = #{record.unitPrice,jdbcType=DECIMAL},
init_stock = #{record.initStock,jdbcType=INTEGER},
has_init = #{record.hasInit,jdbcType=BIT},
has_transfer = #{record.hasTransfer,jdbcType=INTEGER},
report_date = #{record.reportDate,jdbcType=DATE}
<if test="_parameter != null">
......@@ -344,6 +368,12 @@
<if test="unitPrice != null">
unit_price = #{unitPrice,jdbcType=DECIMAL},
</if>
<if test="initStock != null">
init_stock = #{initStock,jdbcType=INTEGER},
</if>
<if test="hasInit != null">
has_init = #{hasInit,jdbcType=BIT},
</if>
<if test="hasTransfer != null">
has_transfer = #{hasTransfer,jdbcType=INTEGER},
</if>
......@@ -367,6 +397,8 @@
quantity_stock = #{quantityStock,jdbcType=INTEGER},
stock_time = #{stockTime,jdbcType=DATE},
unit_price = #{unitPrice,jdbcType=DECIMAL},
init_stock = #{initStock,jdbcType=INTEGER},
has_init = #{hasInit,jdbcType=BIT},
has_transfer = #{hasTransfer,jdbcType=INTEGER},
report_date = #{reportDate,jdbcType=DATE}
where id = #{id,jdbcType=INTEGER}
......@@ -406,6 +438,12 @@
<if test="unitPrice != null">
unit_price,
</if>
<if test="initStock != null">
init_stock,
</if>
<if test="hasInit != null">
has_init,
</if>
<if test="hasTransfer != null">
has_transfer,
</if>
......@@ -442,6 +480,12 @@
<if test="unitPrice != null">
#{unitPrice,jdbcType=DECIMAL},
</if>
<if test="initStock != null">
#{initStock,jdbcType=INTEGER},
</if>
<if test="hasInit != null">
#{hasInit,jdbcType=BIT},
</if>
<if test="hasTransfer != null">
#{hasTransfer,jdbcType=INTEGER},
</if>
......@@ -478,6 +522,12 @@
<if test="unitPrice != null">
unit_price = #{unitPrice,jdbcType=DECIMAL},
</if>
<if test="initStock != null">
init_stock = #{initStock,jdbcType=INTEGER},
</if>
<if test="hasInit != null">
has_init = #{hasInit,jdbcType=BIT},
</if>
<if test="hasTransfer != null">
has_transfer = #{hasTransfer,jdbcType=INTEGER},
</if>
......@@ -494,12 +544,13 @@
-->
insert into dc_mid_stock_date
(id, gmt_create, gmt_modified, bailun_sku, warehouse_code, warehouse_name, quantity_stock,
stock_time, unit_price, has_transfer, report_date)
stock_time, unit_price, init_stock, has_init, has_transfer, report_date)
values
(#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
#{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, #{warehouseName,jdbcType=VARCHAR},
#{quantityStock,jdbcType=INTEGER}, #{stockTime,jdbcType=DATE}, #{unitPrice,jdbcType=DECIMAL},
#{hasTransfer,jdbcType=INTEGER}, #{reportDate,jdbcType=DATE})
#{initStock,jdbcType=INTEGER}, #{hasInit,jdbcType=BIT}, #{hasTransfer,jdbcType=INTEGER},
#{reportDate,jdbcType=DATE})
on duplicate key update
id = #{id,jdbcType=INTEGER},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
......@@ -510,6 +561,8 @@
quantity_stock = #{quantityStock,jdbcType=INTEGER},
stock_time = #{stockTime,jdbcType=DATE},
unit_price = #{unitPrice,jdbcType=DECIMAL},
init_stock = #{initStock,jdbcType=INTEGER},
has_init = #{hasInit,jdbcType=BIT},
has_transfer = #{hasTransfer,jdbcType=INTEGER},
report_date = #{reportDate,jdbcType=DATE}
</insert>
......@@ -530,4 +583,8 @@
</if>
limit 1
</select>
<select id="selectCount" resultType="java.lang.Integer">
select sum(init_stock) from dc_mid_stock_date where bailun_sku = #{bailun_sku} and warehouse_code = #{warehouseCode} and has_init = 1
</select>
</mapper>
\ No newline at end of file
......@@ -57,6 +57,25 @@ public class CalculateStockRecordJob extends PointJob {
List<DcBaseStockRecord> baseStockRecordList = midDcBaseStockRecordMapper.selectByStockTime(dcBaseStockRecord.getBailunSku(), dcBaseStockRecord.getWarehouseCode());
Integer quantityStock = 0;
boolean firstMatch = true;
DcMidStockDateMapper dcMidStockDateMapper = SessionUtil.getSession().getMapper(DcMidStockDateMapper.class);
Integer stockNum = dcMidStockDateMapper.selectCount(dcBaseStockRecord.getBailunSku(), dcBaseStockRecord.getWarehouseCode());
if(stockOut >= stockNum) {
DcMidStockDate dcMidStockDate = new DcMidStockDate();
dcMidStockDate.setQuantityStock(0);
dcMidStockDate.setBailunSku(dcBaseStockRecord.getBailunSku());
dcMidStockDate.setWarehouseCode(dcBaseStockRecord.getWarehouseCode());
dcMidStockDateMapper.updateByExampleSelective(dcMidStockDate, DcMidStockDateExample.newAndCreateCriteria().
andBailunSkuEqualTo(dcBaseStockRecord.getBailunSku()).andWarehouseCodeEqualTo(dcBaseStockRecord.getWarehouseCode()).andHasTransferEqualTo(1).example());
stockOut = stockOut - stockNum;
}else {
DcMidStockDate dcMidStockDate = new DcMidStockDate();
dcMidStockDate.setQuantityStock(stockNum - stockOut);
dcMidStockDate.setBailunSku(dcBaseStockRecord.getBailunSku());
dcMidStockDate.setWarehouseCode(dcBaseStockRecord.getWarehouseCode());
dcMidStockDateMapper.updateByExampleSelective(dcMidStockDate, DcMidStockDateExample.newAndCreateCriteria().
andBailunSkuEqualTo(dcBaseStockRecord.getBailunSku()).andWarehouseCodeEqualTo(dcBaseStockRecord.getWarehouseCode()).andHasTransferEqualTo(1).example());
stockOut = 0;
}
for(DcBaseStockRecord midDcBaseStockRecord : baseStockRecordList) {
quantityStock = quantityStock + midDcBaseStockRecord.getQuantityStock();
if(quantityStock > stockOut) {
......@@ -78,10 +97,41 @@ public class CalculateStockRecordJob extends PointJob {
// dcMidStockDate.setHasTransfer(midDcBaseStockRecord.getHasTransfer());
dcMidStockDate.setReportDate(localDateTime.toLocalDate());
try {
DcMidStockDateMapper dcMidStockDateMapper = SessionUtil.getSession().getMapper(DcMidStockDateMapper.class);
int result = dcMidStockDateMapper.updateByExampleSelective(dcMidStockDate, DcMidStockDateExample.newAndCreateCriteria().andBailunSkuEqualTo(dcMidStockDate.getBailunSku()).andWarehouseCodeEqualTo(dcMidStockDate.getWarehouseCode()).andStockTimeEqualTo(dcMidStockDate.getStockTime()).andReportDateEqualTo(dcMidStockDate.getReportDate()).example());
DcMidStockDateMapper dcMidStockDateMapper0 = SessionUtil.getSession().getMapper(DcMidStockDateMapper.class);
int result = dcMidStockDateMapper0.updateByExampleSelective(dcMidStockDate, DcMidStockDateExample.newAndCreateCriteria().andBailunSkuEqualTo(dcMidStockDate.getBailunSku()).andWarehouseCodeEqualTo(dcMidStockDate.getWarehouseCode()).andStockTimeEqualTo(dcMidStockDate.getStockTime()).example());
if(result == 0) {
dcMidStockDateMapper0.upsertSelective(dcMidStockDate);
}
firstMatch = false;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("MYbatis操作DB失败", e);
} finally {
SessionUtil.closeSession();
}
}else {
DcMidStockDate dcMidStockDate = new DcMidStockDate();
DcBaseSkuMapper dcBaseSkuMapper = SessionUtil.getSession().getMapper(DcBaseSkuMapper.class);
DcBaseSku dcBaseSku = dcBaseSkuMapper.selectOneByExample(DcBaseSkuExample.newAndCreateCriteria().andBailunSkuEqualTo(midDcBaseStockRecord.getBailunSku()).andCompanyIdEqualTo(1).example());
if(dcBaseSku != null) {
dcMidStockDate.setUnitPrice(dcBaseSku.getUnitPrice());
}
dcMidStockDate.setBailunSku(midDcBaseStockRecord.getBailunSku());
dcMidStockDate.setWarehouseCode(midDcBaseStockRecord.getWarehouseCode());
dcMidStockDate.setWarehouseName(midDcBaseStockRecord.getWarehouseName());
dcMidStockDate.setStockTime(midDcBaseStockRecord.getStockTime().toLocalDate());
if(firstMatch) {
dcMidStockDate.setQuantityStock(quantityStock - stockOut);
}else{
dcMidStockDate.setQuantityStock(midDcBaseStockRecord.getQuantityStock());
}
// dcMidStockDate.setHasTransfer(midDcBaseStockRecord.getHasTransfer());
dcMidStockDate.setReportDate(localDateTime.toLocalDate());
try {
DcMidStockDateMapper dcMidStockDateMapper0 = SessionUtil.getSession().getMapper(DcMidStockDateMapper.class);
int result = dcMidStockDateMapper0.updateByExampleSelective(dcMidStockDate, DcMidStockDateExample.newAndCreateCriteria().andBailunSkuEqualTo(dcMidStockDate.getBailunSku()).andWarehouseCodeEqualTo(dcMidStockDate.getWarehouseCode()).andStockTimeEqualTo(dcMidStockDate.getStockTime()).andReportDateEqualTo(dcMidStockDate.getReportDate()).example());
if(result == 0) {
dcMidStockDateMapper.upsertSelective(dcMidStockDate);
dcMidStockDateMapper0.upsertSelective(dcMidStockDate);
}
firstMatch = false;
} catch (Exception e) {
......
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