优化商品库存报表的查询逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ package com.jsh.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.datasource.entities.MaterialInitialStockWithMaterial;
|
||||
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
|
||||
import com.jsh.erp.datasource.entities.Unit;
|
||||
import com.jsh.erp.service.depot.DepotService;
|
||||
@@ -591,6 +592,11 @@ public class MaterialController {
|
||||
depotList.add(object.getLong("id"));
|
||||
}
|
||||
}
|
||||
Map<Long, BigDecimal> initialStockMap = new HashMap<>();
|
||||
List<MaterialInitialStockWithMaterial> initialStockList = materialService.getInitialStockWithMaterial(depotList);
|
||||
for (MaterialInitialStockWithMaterial mism: initialStockList) {
|
||||
initialStockMap.put(mism.getMaterialId(), mism.getNumber());
|
||||
}
|
||||
List<MaterialVo4Unit> dataList = materialService.getListWithStock(depotList, idList, StringUtil.toNull(materialParam), zeroStock,
|
||||
StringUtil.safeSqlParse(column), StringUtil.safeSqlParse(order), (currentPage-1)*pageSize, pageSize);
|
||||
int total = materialService.getListWithStockCount(depotList, idList, StringUtil.toNull(materialParam), zeroStock);
|
||||
@@ -598,7 +604,9 @@ public class MaterialController {
|
||||
map.put("total", total);
|
||||
map.put("currentStock", materialVo4Unit.getCurrentStock());
|
||||
map.put("currentStockPrice", materialVo4Unit.getCurrentStockPrice());
|
||||
//存放数据json数组
|
||||
for(MaterialVo4Unit item: dataList) {
|
||||
item.setInitialStock(initialStockMap.get(item.getId()));
|
||||
}
|
||||
map.put("rows", dataList);
|
||||
res.code = 200;
|
||||
res.data = map;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class MaterialInitialStockWithMaterial {
|
||||
|
||||
private Long materialId;
|
||||
|
||||
private BigDecimal number;
|
||||
|
||||
public Long getMaterialId() {
|
||||
return materialId;
|
||||
}
|
||||
|
||||
public void setMaterialId(Long materialId) {
|
||||
this.materialId = materialId;
|
||||
}
|
||||
|
||||
public BigDecimal getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(BigDecimal number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.jsh.erp.datasource.mappers;
|
||||
|
||||
import com.jsh.erp.datasource.entities.AccountHead;
|
||||
import com.jsh.erp.datasource.entities.Material;
|
||||
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
|
||||
import com.jsh.erp.datasource.entities.Unit;
|
||||
import com.jsh.erp.datasource.entities.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -110,6 +108,9 @@ public interface MaterialMapperEx {
|
||||
@Param("barCodeArray") String [] barCodeArray,
|
||||
@Param("mId") Long mId);
|
||||
|
||||
List<MaterialInitialStockWithMaterial> getInitialStockWithMaterial(
|
||||
@Param("depotList") List<Long> depotList);
|
||||
|
||||
List<MaterialVo4Unit> getListWithStock(
|
||||
@Param("depotList") List<Long> depotList,
|
||||
@Param("idList") List<Long> idList,
|
||||
|
||||
@@ -1034,6 +1034,10 @@ public class MaterialService {
|
||||
return materialMapperEx.getMaterialByBarCodeAndWithOutMId(barCodeArray, mId);
|
||||
}
|
||||
|
||||
public List<MaterialInitialStockWithMaterial> getInitialStockWithMaterial(List<Long> depotList) {
|
||||
return materialMapperEx.getInitialStockWithMaterial(depotList);
|
||||
}
|
||||
|
||||
public List<MaterialVo4Unit> getListWithStock(List<Long> depotList, List<Long> idList, String materialParam, Integer zeroStock,
|
||||
String column, String order, Integer offset, Integer rows) {
|
||||
return materialMapperEx.getListWithStock(depotList, idList, materialParam, zeroStock, column, order, offset, rows);
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
<result column="sku" jdbcType="VARCHAR" property="sku" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="InitialStockWithMaterialMap" type="com.jsh.erp.datasource.entities.MaterialInitialStockWithMaterial">
|
||||
<result column="materialId" jdbcType="BIGINT" property="materialId" />
|
||||
<result column="number" jdbcType="DECIMAL" property="number" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByConditionMaterial" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
|
||||
select m.*,u.name unitName, mc.name categoryName, me.bar_code,
|
||||
me.purchase_decimal, me.commodity_decimal, me.wholesale_decimal,me.low_decimal,me.sku
|
||||
@@ -531,17 +536,22 @@
|
||||
and id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getListWithStock" resultMap="ResultMapListWithStock">
|
||||
select m.*, me.commodity_unit unitName, mc.name categoryName, me.bar_code,
|
||||
ifnull(me.purchase_decimal,0) purchase_decimal,
|
||||
(select ifnull(sum(mis.number),0) from jsh_material_initial_stock mis where mis.material_id = m.id
|
||||
<select id="getInitialStockWithMaterial" resultMap="InitialStockWithMaterialMap">
|
||||
select material_id, ifnull(sum(mis.number),0)
|
||||
from jsh_material_initial_stock mis
|
||||
where 1=1
|
||||
<if test="depotList.size()>0">
|
||||
and mis.depot_id in
|
||||
<foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
) initialStock,
|
||||
group by mis.material_id
|
||||
</select>
|
||||
|
||||
<select id="getListWithStock" resultMap="ResultMapListWithStock">
|
||||
select m.*, me.commodity_unit unitName, mc.name categoryName, me.bar_code,
|
||||
ifnull(me.purchase_decimal,0) purchase_decimal,
|
||||
ifnull(sum(mcs.current_number),0) currentStock,
|
||||
sum(ifnull(me.purchase_decimal, 0) * ifnull(mcs.current_number, 0)) currentStockPrice
|
||||
FROM jsh_material m
|
||||
|
||||
Reference in New Issue
Block a user