优化商品模块的库存统计

This commit is contained in:
季圣华
2019-10-12 15:03:04 +08:00
parent ee8390559b
commit f90aa299aa
5 changed files with 30 additions and 55 deletions

View File

@@ -10,7 +10,7 @@ public class MaterialVo4Unit extends Material{
private String materialOther; private String materialOther;
private Long stock; private BigDecimal stock;
public String getUnitName() { public String getUnitName() {
return unitName; return unitName;
@@ -36,11 +36,11 @@ public class MaterialVo4Unit extends Material{
this.materialOther = materialOther; this.materialOther = materialOther;
} }
public Long getStock() { public BigDecimal getStock() {
return stock; return stock;
} }
public void setStock(Long stock) { public void setStock(BigDecimal stock) {
this.stock = stock; this.stock = stock;
} }
} }

View File

@@ -36,12 +36,6 @@ public interface DepotItemMapperEx {
Long findDetailByTypeAndMaterialIdCounts( Long findDetailByTypeAndMaterialIdCounts(
@Param("mId") Long mId); @Param("mId") Long mId);
Long findByTypeAndMaterialIdIn(
@Param("mId") Long mId);
Long findByTypeAndMaterialIdOut(
@Param("mId") Long mId);
List<DepotItemVo4WithInfoEx> getDetailList( List<DepotItemVo4WithInfoEx> getDetailList(
@Param("headerId") Long headerId); @Param("headerId") Long headerId);
@@ -77,12 +71,10 @@ public interface DepotItemMapperEx {
@Param("tenantId") Long tenantId); @Param("tenantId") Long tenantId);
/** /**
* create by: cjl * 通过单据主表id查询所有单据子表数据
* description: * @param depotheadId
* 通过单据主表id查询所有单据子表数据 * @param enableSerialNumber
* create time: 2019/1/24 16:56 * @return
* @Param: depotheadId
* @return java.util.List<com.jsh.erp.datasource.entities.DepotItem>
*/ */
List<DepotItem> findDepotItemListBydepotheadId(@Param("depotheadId")Long depotheadId, List<DepotItem> findDepotItemListBydepotheadId(@Param("depotheadId")Long depotheadId,
@Param("enableSerialNumber")String enableSerialNumber); @Param("enableSerialNumber")String enableSerialNumber);
@@ -103,7 +95,6 @@ public interface DepotItemMapperEx {
List<DepotItem> getDepotItemListListByMaterialIds(@Param("materialIds") String[] materialIds); List<DepotItem> getDepotItemListListByMaterialIds(@Param("materialIds") String[] materialIds);
List<DepotItemStockWarningCount> findStockWarningCount(@Param("offset") Integer offset, List<DepotItemStockWarningCount> findStockWarningCount(@Param("offset") Integer offset,
@Param("rows") Integer rows, @Param("pid") Integer pid); @Param("rows") Integer rows, @Param("pid") Integer pid);

View File

@@ -215,20 +215,6 @@ public class DepotItemService {
return result; return result;
} }
public Long findByTypeAndMaterialId(String type, Long mId) throws Exception{
Long result = 0l;
try{
if(type.equals(TYPE)) {
result= depotItemMapperEx.findByTypeAndMaterialIdIn(mId);
} else {
result= depotItemMapperEx.findByTypeAndMaterialIdOut(mId);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<DepotItemVo4WithInfoEx> getDetailList(Long headerId)throws Exception { public List<DepotItemVo4WithInfoEx> getDetailList(Long headerId)throws Exception {
List<DepotItemVo4WithInfoEx> list =null; List<DepotItemVo4WithInfoEx> list =null;
try{ try{

View File

@@ -100,9 +100,8 @@ public class MaterialService {
} }
} }
m.setMaterialOther(materialOther); m.setMaterialOther(materialOther);
Long InSum = depotItemService.findByTypeAndMaterialId("入库", m.getId()); Long tenantId = m.getTenantId();
Long OutSum = depotItemService.findByTypeAndMaterialId("出库", m.getId()); m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null,tenantId));
m.setStock(InSum - OutSum);
resList.add(m); resList.add(m);
} }
} }

View File

@@ -40,6 +40,7 @@
<result column="PresetPriceOne" jdbcType="DECIMAL" property="presetPriceOne" /> <result column="PresetPriceOne" jdbcType="DECIMAL" property="presetPriceOne" />
<result column="PriceStrategy" jdbcType="VARCHAR" property="priceStrategy" /> <result column="PriceStrategy" jdbcType="VARCHAR" property="priceStrategy" />
</resultMap> </resultMap>
<resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount"> <resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount">
<result column="MaterialName" jdbcType="VARCHAR" property="MaterialName" /> <result column="MaterialName" jdbcType="VARCHAR" property="MaterialName" />
<result column="MaterialModel" jdbcType="VARCHAR" property="MaterialModel" /> <result column="MaterialModel" jdbcType="VARCHAR" property="MaterialModel" />
@@ -76,6 +77,7 @@
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>
</select> </select>
<select id="countsByDepotItem" resultType="java.lang.Long"> <select id="countsByDepotItem" resultType="java.lang.Long">
SELECT SELECT
COUNT(id) COUNT(id)
@@ -95,12 +97,22 @@
<select id="findDetailByTypeAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap"> <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,concat(dh.SubType,dh.Type) as newType,
case when type='入库' then ifnull(di.BasicNumber,0) when type='出库' then 0-di.BasicNumber else 0 end as b_num, case
when type='入库' then ifnull(di.BasicNumber,0)
when type='出库' 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='拆卸单' and di.MType='普通子件' then ifnull(di.BasicNumber,0)
when dh.SubType='拆卸单' and di.MType='组合件' then 0-di.BasicNumber
else 0
end
as b_num,
date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime
from jsh_depothead dh from jsh_depothead dh
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1' INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
where dh.type!='其它' where ((dh.type!='其它' and dh.SubType!='调拨')
and dh.SubType!='调拨' or (dh.type='其它' and dh.SubType='组装单')
or (dh.type='其它' and dh.SubType='拆卸单'))
and di.MaterialId =${mId} and di.MaterialId =${mId}
and ifnull(dh.delete_Flag,'0') !='1' and ifnull(dh.delete_Flag,'0') !='1'
ORDER BY oTime desc ORDER BY oTime desc
@@ -108,6 +120,7 @@
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>
</select> </select>
<select id="findDetailByTypeAndMaterialIdCounts" resultType="java.lang.Long"> <select id="findDetailByTypeAndMaterialIdCounts" resultType="java.lang.Long">
select count(1) select count(1)
from jsh_depothead dh from jsh_depothead dh
@@ -118,23 +131,6 @@
and ifnull(dh.delete_Flag,'0') !='1' and ifnull(dh.delete_Flag,'0') !='1'
</select> </select>
<select id="findByTypeAndMaterialIdIn" resultType="java.lang.Long">
select ifnull(sum(BasicNumber),0) as BasicNumber 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 di.MaterialId = ${mId}
and ifnull(dh.delete_Flag,'0') !='1'
</select>
<select id="findByTypeAndMaterialIdOut" resultType="java.lang.Long">
select ifnull(sum(BasicNumber),0) as BasicNumber 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!='调拨'
and di.MaterialId = ${mId}
and ifnull(dh.delete_Flag,'0') !='1'
</select>
<select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap"> <select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
select di.*,m.Name MName,m.Model MModel,m.Unit MaterialUnit,m.Color MColor,m.Standard MStandard,m.Mfrs MMfrs, select di.*,m.Name MName,m.Model MModel,m.Unit MaterialUnit,m.Color MColor,m.Standard MStandard,m.Mfrs MMfrs,
m.OtherField1 MOtherField1,m.OtherField2 MOtherField2,m.OtherField3 MOtherField3, m.OtherField1 MOtherField1,m.OtherField2 MOtherField2,m.OtherField3 MOtherField3,
@@ -254,6 +250,7 @@
and ifnull(dep.delete_Flag,'0') !='1' and ifnull(dep.delete_Flag,'0') !='1'
and ifnull(mat.delete_Flag,'0') !='1' and ifnull(mat.delete_Flag,'0') !='1'
</select> </select>
<delete id="deleteDepotItemByDepotHeadIds"> <delete id="deleteDepotItemByDepotHeadIds">
delete from jsh_depotitem delete from jsh_depotitem
where 1=1 where 1=1
@@ -264,6 +261,7 @@
</foreach> </foreach>
) )
</delete> </delete>
<update id="batchDeleteDepotItemByDepotHeadIds"> <update id="batchDeleteDepotItemByDepotHeadIds">
update jsh_depotitem update jsh_depotitem
set delete_Flag='1' set delete_Flag='1'
@@ -275,6 +273,7 @@
</foreach> </foreach>
) )
</update> </update>
<update id="batchDeleteDepotItemByIds"> <update id="batchDeleteDepotItemByIds">
update jsh_depotitem update jsh_depotitem
set delete_Flag='1' set delete_Flag='1'
@@ -285,6 +284,7 @@
</foreach> </foreach>
) )
</update> </update>
<select id="getDepotItemListListByDepotIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap"> <select id="getDepotItemListListByDepotIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
select select
<include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" /> <include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" />
@@ -297,6 +297,7 @@
) )
and ifnull(delete_Flag,'0') !='1' and ifnull(delete_Flag,'0') !='1'
</select> </select>
<select id="getDepotItemListListByMaterialIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap"> <select id="getDepotItemListListByMaterialIds" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
select select
<include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" /> <include refid="com.jsh.erp.datasource.mappers.DepotItemMapper.Base_Column_List" />
@@ -310,8 +311,6 @@
and ifnull(delete_Flag,'0') !='1' and ifnull(delete_Flag,'0') !='1'
</select> </select>
<select id="findStockWarningCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStockWarningCount"> <select id="findStockWarningCount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStockWarningCount">
SELECT SELECT
m. NAME MaterialName, m. NAME MaterialName,