合并商品的库存到商品列表接口一起查询

This commit is contained in:
季圣华
2019-06-16 21:38:22 +08:00
parent 27c58a8d3c
commit d9627ac020
8 changed files with 36 additions and 206 deletions

View File

@@ -152,77 +152,6 @@ public class DepotItemController {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
/**
* 只根据商品id查询库存数量
* @param pageSize
* @param currentPage
* @param mId
* @param request
* @return
*/
@GetMapping(value = "/findStockNumByMaterialId")
public String findStockNumByMaterialId(
@RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize,
@RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage,
@RequestParam("materialId") String mId,
@RequestParam("monthTime") String monthTime,
HttpServletRequest request) throws Exception{
Map<String, String> parameterMap = ParamUtils.requestToMap(request);
parameterMap.put("mId", mId);
parameterMap.put("monthTime", monthTime);
PageQueryInfo queryInfo = new PageQueryInfo();
Map<String, Object> objectMap = new HashMap<String, Object>();
if (pageSize != null && pageSize <= 0) {
pageSize = 10;
}
String offset = ParamUtils.getPageOffset(currentPage, pageSize);
if (StringUtil.isNotEmpty(offset)) {
parameterMap.put(Constants.OFFSET, offset);
}
List<DepotItemVo4Material> list = depotItemService.findStockNumByMaterialIdList(parameterMap);
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != list) {
for (DepotItemVo4Material di : list) {
JSONObject item = new JSONObject();
int InSum = sumNumberByMaterialId("入库", di.getMaterialid());
int OutSum = sumNumberByMaterialId("出库", di.getMaterialid());
item.put("MaterialId", di.getMaterialid() == null ? "" : di.getMaterialid());
item.put("MaterialName", di.getMname());
item.put("MaterialModel", di.getMmodel());
item.put("thisSum", InSum - OutSum);
dataArray.add(item);
}
}
objectMap.put("page", dataArray);
if (list == null) {
queryInfo.setRows(new ArrayList<Object>());
queryInfo.setTotal(BusinessConstants.DEFAULT_LIST_NULL_NUMBER);
return returnJson(objectMap, "查找不到数据", ErpInfo.OK.code);
}
queryInfo.setRows(list);
queryInfo.setTotal(depotItemService.findStockNumByMaterialIdCounts(parameterMap));
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
/**
* 仅根据商品Id进行数量合计
*
* @param type
* @param mId
* @return
*/
public int sumNumberByMaterialId(String type, Long mId)throws Exception {
int allNumber = 0;
try {
allNumber = depotItemService.findByTypeAndMaterialId(type, mId);
} catch (Exception e) {
e.printStackTrace();
}
return allNumber;
}
/**
* 保存明细
* @param inserted

View File

@@ -10,6 +10,8 @@ public class MaterialVo4Unit extends Material{
private String materialOther;
private Long stock;
public String getUnitName() {
return unitName;
}
@@ -33,4 +35,12 @@ public class MaterialVo4Unit extends Material{
public void setMaterialOther(String materialOther) {
this.materialOther = materialOther;
}
public Long getStock() {
return stock;
}
public void setStock(Long stock) {
this.stock = stock;
}
}

View File

@@ -45,10 +45,10 @@ public interface DepotItemMapperEx {
@Param("mId") Long mId,
@Param("monthTime") String monthTime);
int findByTypeAndMaterialIdIn(
Long findByTypeAndMaterialIdIn(
@Param("mId") Long mId);
int findByTypeAndMaterialIdOut(
Long findByTypeAndMaterialIdOut(
@Param("mId") Long mId);
int findByTypeAndDepotIdAndMaterialIdIn(

View File

@@ -290,8 +290,8 @@ public class DepotItemService {
return depotItemMapper.updateByPrimaryKeySelective(depotItem);
}
public int findByTypeAndMaterialId(String type, Long mId) throws Exception{
int result =0;
public Long findByTypeAndMaterialId(String type, Long mId) throws Exception{
Long result = 0l;
try{
if(type.equals(TYPE)) {
result= depotItemMapperEx.findByTypeAndMaterialIdIn(mId);

View File

@@ -9,6 +9,7 @@ import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
import com.jsh.erp.datasource.mappers.MaterialMapper;
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.BaseResponseInfo;
@@ -38,6 +39,8 @@ public class MaterialService {
private UserService userService;
@Resource
private DepotItemMapperEx depotItemMapperEx;
@Resource
private DepotItemService depotItemService;
public Material getMaterial(long id)throws Exception {
Material result=null;
@@ -105,6 +108,9 @@ public class MaterialService {
}
}
m.setMaterialOther(materialOther);
Long InSum = depotItemService.findByTypeAndMaterialId("入库", m.getId());
Long OutSum = depotItemService.findByTypeAndMaterialId("出库", m.getId());
m.setStock(InSum - OutSum);
resList.add(m);
}
}

View File

@@ -87,7 +87,7 @@
<select id="findDetailByTypeAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap">
select dh.Number,concat(dh.SubType,dh.Type) as newType,
case when type='入库' then di.BasicNumber 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 else 0 end as b_num,
date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime
from jsh_depothead dh
INNER JOIN jsh_depotitem di on dh.id=di.HeaderId and ifnull(di.delete_Flag,'0') !='1'
@@ -131,7 +131,7 @@
and ifnull(delete_Flag,'0') !='1'
</select>
<select id="findByTypeAndMaterialIdIn" resultType="java.lang.Integer">
<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='入库'
@@ -139,7 +139,7 @@
and ifnull(dh.delete_Flag,'0') !='1'
</select>
<select id="findByTypeAndMaterialIdOut" resultType="java.lang.Integer">
<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='出库'