优化库存逻辑
This commit is contained in:
@@ -73,7 +73,13 @@ public class DepotItemController {
|
||||
for (DepotItemVo4DetailByTypeAndMId d: list) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("Number", d.getNumber()); //商品编号
|
||||
item.put("Type", d.getNewtype()); //进出类型
|
||||
String type = d.getType();
|
||||
String subType = d.getSubType();
|
||||
if(("其它").equals(type)) {
|
||||
item.put("Type", subType); //进出类型
|
||||
} else {
|
||||
item.put("Type", subType + type); //进出类型
|
||||
}
|
||||
item.put("BasicNumber", d.getBnum()); //数量
|
||||
item.put("OperTime", d.getOtime().getTime()); //时间
|
||||
dataArray.add(item);
|
||||
|
||||
@@ -7,7 +7,9 @@ public class DepotItemVo4DetailByTypeAndMId {
|
||||
|
||||
private String number;
|
||||
|
||||
private String newtype;
|
||||
private String type;
|
||||
|
||||
private String subType;
|
||||
|
||||
private BigDecimal bnum;
|
||||
|
||||
@@ -21,12 +23,20 @@ public class DepotItemVo4DetailByTypeAndMId {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getNewtype() {
|
||||
return newtype;
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setNewtype(String newtype) {
|
||||
this.newtype = newtype;
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSubType() {
|
||||
return subType;
|
||||
}
|
||||
|
||||
public void setSubType(String subType) {
|
||||
this.subType = subType;
|
||||
}
|
||||
|
||||
public BigDecimal getBnum() {
|
||||
|
||||
@@ -70,6 +70,12 @@ public interface DepotItemMapperEx {
|
||||
@Param("subType") String subType,
|
||||
@Param("MonthTime") String MonthTime);
|
||||
|
||||
BigDecimal getStockCheckSum(
|
||||
@Param("depotId") Long depotId,
|
||||
@Param("mId") Long mId,
|
||||
@Param("beginTime") String beginTime,
|
||||
@Param("endTime") String endTime);
|
||||
|
||||
DepotItemVo4Stock getStockByParam(
|
||||
@Param("depotId") Long depotId,
|
||||
@Param("mId") Long mId,
|
||||
|
||||
@@ -647,10 +647,12 @@ public class DepotItemService {
|
||||
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
|
||||
//初始库存
|
||||
BigDecimal initStock = materialService.getInitStockByMid(depotId, mId);
|
||||
//盘点复盘后数量的变动
|
||||
BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSum(depotId, mId, beginTime, endTime);
|
||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
|
||||
BigDecimal intNum = stockObj.getInNum();
|
||||
BigDecimal outNum = stockObj.getOutNum();
|
||||
return initStock.add(intNum).subtract(outNum);
|
||||
return initStock.add(intNum).subtract(outNum).add(stockCheckSum);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
<resultMap id="DetailByTypeAndMIdResultMap" type="com.jsh.erp.datasource.entities.DepotItemVo4DetailByTypeAndMId">
|
||||
<result column="Number" jdbcType="VARCHAR" property="number" />
|
||||
<result column="newType" jdbcType="VARCHAR" property="newtype" />
|
||||
<result column="b_num" jdbcType="DECIMAL" property="bnum" />
|
||||
<result column="Type" jdbcType="VARCHAR" property="type" />
|
||||
<result column="SubType" jdbcType="VARCHAR" property="subType" />
|
||||
<result column="b_num" jdbcType="BIGINT" property="bnum" />
|
||||
<result column="oTime" jdbcType="TIMESTAMP" property="otime" />
|
||||
</resultMap>
|
||||
|
||||
@@ -96,7 +97,7 @@
|
||||
</select>
|
||||
|
||||
<select id="findDetailByTypeAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap">
|
||||
select dh.Number,concat(dh.SubType,dh.Type) as newType,
|
||||
select dh.Number,dh.Type,dh.SubType,
|
||||
case
|
||||
when type='入库' then ifnull(di.BasicNumber,0)
|
||||
when type='出库' then 0-di.BasicNumber
|
||||
@@ -104,6 +105,7 @@
|
||||
when dh.SubType='组装单' and di.MType='普通子件' then 0-di.BasicNumber
|
||||
when dh.SubType='拆卸单' and di.MType='普通子件' then ifnull(di.BasicNumber,0)
|
||||
when dh.SubType='拆卸单' and di.MType='组合件' then 0-di.BasicNumber
|
||||
when dh.SubType='盘点复盘' then ifnull(di.BasicNumber,0)
|
||||
else 0
|
||||
end
|
||||
as b_num,
|
||||
@@ -112,7 +114,8 @@
|
||||
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
|
||||
where ((dh.type!='其它' and dh.SubType!='调拨')
|
||||
or (dh.type='其它' and dh.SubType='组装单')
|
||||
or (dh.type='其它' and dh.SubType='拆卸单'))
|
||||
or (dh.type='其它' and dh.SubType='拆卸单')
|
||||
or (dh.type='其它' and dh.SubType='盘点复盘' and dh.Status=1))
|
||||
and di.MaterialId =${mId}
|
||||
and ifnull(dh.delete_Flag,'0') !='1'
|
||||
ORDER BY oTime desc
|
||||
@@ -125,8 +128,10 @@
|
||||
select count(1)
|
||||
from jsh_depothead dh
|
||||
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
|
||||
where dh.type!='其它'
|
||||
and dh.SubType!='调拨'
|
||||
where ((dh.type!='其它' and dh.SubType!='调拨')
|
||||
or (dh.type='其它' and dh.SubType='组装单')
|
||||
or (dh.type='其它' and dh.SubType='拆卸单')
|
||||
or (dh.type='其它' and dh.SubType='盘点复盘' and dh.Status=1))
|
||||
and di.MaterialId =${mId}
|
||||
and ifnull(dh.delete_Flag,'0') !='1'
|
||||
</select>
|
||||
@@ -223,6 +228,27 @@
|
||||
and ifnull(dh.delete_Flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="getStockCheckSum" resultType="java.math.BigDecimal">
|
||||
select ifnull(sum(di.BasicNumber),0) stockCheckSum from jsh_depothead dh
|
||||
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId
|
||||
where 1=1
|
||||
<if test="mId != null">
|
||||
and di.MaterialId=#{mId}
|
||||
</if>
|
||||
and dh.SubType='盘点复盘' and dh.`Status`='1'
|
||||
<if test="depotId != null">
|
||||
and di.DepotId=#{depotId}
|
||||
</if>
|
||||
<if test="beginTime != null">
|
||||
and dh.OperTime >= '${beginTime}'
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and dh.OperTime <= '${endTime}'
|
||||
</if>
|
||||
and ifnull(dh.delete_Flag,'0') !='1'
|
||||
and ifnull(di.delete_Flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="getStockByParam" resultMap="StockMap">
|
||||
select ifnull((curep.inTotal+curep.transfInTotal+curep.assemInTotal+curep.disAssemInTotal),0) as in_stock,
|
||||
ifnull((curep.transfOutTotal+curep.outTotal+curep.assemOutTotal+curep.disAssemOutTotal),0) out_stock
|
||||
|
||||
Reference in New Issue
Block a user