修改根据材料和仓库获取库存

This commit is contained in:
qiankunpingtai
2019-06-11 10:50:51 +08:00
parent 0b07e2d61f
commit 99d856111e
5 changed files with 260 additions and 314 deletions

View File

@@ -4,7 +4,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.entities.DepotItemVo4DetailByTypeAndMId;
import com.jsh.erp.datasource.entities.DepotItemVo4WithInfoEx;
import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.depotItem.DepotItemService;
@@ -12,8 +13,10 @@ import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -73,6 +76,8 @@ public class DepotItemController {
item.put("Type", d.getNewtype()); //进出类型
item.put("BasicNumber", d.getBnum()); //数量
item.put("OperTime", d.getOtime()); //时间
item.put("depotName", d.getDepotName()); //仓库名称
item.put("depotInName", d.getDepotInName()); //调入仓库名称
dataArray.add(item);
}
}
@@ -113,55 +118,21 @@ public class DepotItemController {
/**
* 只根据商品id查询库存数量
* @param pageSize
* @param currentPage
* @param mId
* @param request
* @return
*/
@GetMapping(value = "/findStockNumByMaterialId")
@RequestMapping(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);
}
}
JSONObject item = new JSONObject();
item.put("thisSum", depotItemService.getCurrentRepByMaterialIdAndDepotId(Long.valueOf(mId),null));
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);
}

View File

@@ -11,6 +11,10 @@ public class DepotItemVo4DetailByTypeAndMId {
private Integer bnum;
private Date otime;
//仓库名称
private String depotName;
//调入仓库名称
private String depotInName;
public String getNumber() {
return number;
@@ -43,4 +47,20 @@ public class DepotItemVo4DetailByTypeAndMId {
public void setOtime(Date otime) {
this.otime = otime;
}
public String getDepotName() {
return depotName;
}
public void setDepotName(String depotName) {
this.depotName = depotName;
}
public String getDepotInName() {
return depotInName;
}
public void setDepotInName(String depotInName) {
this.depotInName = depotInName;
}
}

View File

@@ -7,6 +7,8 @@
<result column="newType" jdbcType="VARCHAR" property="newtype" />
<result column="b_num" jdbcType="BIGINT" property="bnum" />
<result column="oTime" jdbcType="TIMESTAMP" property="otime" />
<result column="depotName" jdbcType="VARCHAR" property="depotName" />
<result column="depotInName" jdbcType="VARCHAR" property="depotInName" />
</resultMap>
<resultMap extends="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap" id="ResultAndMaterialMap" type="com.jsh.erp.datasource.entities.DepotItemVo4Material">
@@ -91,12 +93,22 @@
<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,
date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime
case when dh.type='入库' then ifnull(di.BasicNumber,0)
when dh.type='出库' and dh.SubType!='调拨' then 0 - ifnull(di.BasicNumber,0)
when dh.SubType='组装单' and di.MType='组合件' then ifnull(di.BasicNumber,0)
when dh.SubType='组装单' and di.MType='普通子件' then 0-ifnull(di.BasicNumber,0)
when dh.SubType='拆卸单' and di.MType='普通子件' then ifnull(di.BasicNumber,0)
when dh.SubType='拆卸单' and di.MType='组合件' then 0-ifnull(di.BasicNumber,0)
when dh.SubType='调拨' then 0-ifnull(di.BasicNumber,0)
else 0 end as b_num,
date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime,
depot.name as depotName,depotIn.name as depotInName
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!='调拨'
left join jsh_depot depot on depot.id=di.depotId and ifnull(depot.delete_Flag,'0') !='1'
left join jsh_depot depotIn on depotIn.id=di.AnotherDepotId and ifnull(depotIn.delete_Flag,'0') !='1'
where 1=1
and dh.SubType not in('采购订单','销售订单')
and di.MaterialId =#{mId}
and ifnull(dh.delete_Flag,'0') !='1'
ORDER BY oTime desc
@@ -108,8 +120,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!='调拨'
left join jsh_depot depot on depot.id=di.depotId and ifnull(depot.delete_Flag,'0') !='1'
left join jsh_depot depotIn on depotIn.id=di.AnotherDepotId and ifnull(depotIn.delete_Flag,'0') !='1'
where 1=1
and dh.SubType not in('采购订单','销售订单')
and di.MaterialId =#{mId}
and ifnull(dh.delete_Flag,'0') !='1'
</select>
@@ -589,24 +603,24 @@
AND intype.BasicInNumber > 0
</select>
<select id="getCurrentRepByMaterialIdAndDepotId" resultType="java.math.BigDecimal">
select ((curep.inTotal+curep.transfInTotal+curep.assemInTotal+curep.disAssemInTotal)
-(curep.transfOutTotal+curep.outTotal+curep.assemOutTotal+curep.disAssemOutTotal)) as currentRepo
from
(select sum(if(dh.type='入库' and di.DepotId=#{depotId},di.BasicNumber,0)) as inTotal,
sum(if(dh.SubType='调拨' and di.AnotherDepotId=#{depotId},di.BasicNumber,0)) as transfInTotal,
sum(if(dh.SubType='调拨' and di.DepotId=#{depotId},di.BasicNumber,0)) as transfOutTotal,
sum(if(dh.type='出库' and dh.SubType!='调拨' and di.DepotId=#{depotId},di.BasicNumber,0)) as outTotal,
sum(if(dh.SubType='组装单' and di.MType='组合件' and di.DepotId=#{depotId},di.BasicNumber,0)) as assemInTotal,
sum(if(dh.SubType='组装单' and di.MType='普通子件' and di.DepotId=#{depotId},di.BasicNumber,0)) as assemOutTotal,
sum(if(dh.SubType='拆卸单' and di.MType='普通子件' and di.DepotId=#{depotId},di.BasicNumber,0)) as disAssemInTotal,
sum(if(dh.SubType='拆卸单' and di.MType='组合件' and di.DepotId=#{depotId},di.BasicNumber,0)) as disAssemOutTotal
from
jsh_depothead dh,jsh_depotitem di
where 1=1
and dh.id=di.HeaderId
and di.MaterialId=#{materialId}
and ifnull(dh.delete_Flag,'0') !='1'
and ifnull(di.delete_Flag,'0') !='1') curep
select ((curep.inTotal+curep.transfInTotal+curep.assemInTotal+curep.disAssemInTotal)
-(curep.transfOutTotal+curep.outTotal+curep.assemOutTotal+curep.disAssemOutTotal)) as currentRepo
from
(select sum(if(dh.type='入库' <if test="depotId != null">and di.DepotId=#{depotId}</if>, di.BasicNumber,0)) as inTotal,
sum(if(dh.SubType='调拨' <if test="depotId != null">and di.AnotherDepotId=#{depotId}</if>,di.BasicNumber,0)) as transfInTotal,
sum(if(dh.SubType='调拨' <if test="depotId != null">and di.DepotId=#{depotId}</if>,di.BasicNumber,0)) as transfOutTotal,
sum(if(dh.type='出库' and dh.SubType!='调拨' <if test="depotId != null">and di.DepotId=#{depotId}</if>,di.BasicNumber,0)) as outTotal,
sum(if(dh.SubType='组装单' and di.MType='组合件' <if test="depotId != null">and di.DepotId=#{depotId}</if>,di.BasicNumber,0)) as assemInTotal,
sum(if(dh.SubType='组装单' and di.MType='普通子件' <if test="depotId != null">and di.DepotId=#{depotId}</if>,di.BasicNumber,0)) as assemOutTotal,
sum(if(dh.SubType='拆卸单' and di.MType='普通子件' <if test="depotId != null">and di.DepotId=#{depotId}</if>,di.BasicNumber,0)) as disAssemInTotal,
sum(if(dh.SubType='拆卸单' and di.MType='组合件' <if test="depotId != null"> and di.DepotId=#{depotId}</if>,di.BasicNumber,0)) as disAssemOutTotal
from
jsh_depothead dh,jsh_depotitem di
where 1=1
and dh.id=di.HeaderId
and di.MaterialId=#{materialId}
and ifnull(dh.delete_Flag,'0') !='1'
and ifnull(di.delete_Flag,'0') !='1') as curep
</select>
</mapper>