优化进销存统计接口
This commit is contained in:
@@ -124,7 +124,7 @@ public class DepotItemController {
|
|||||||
@GetMapping(value = "/findStockByDepotAndBarCode")
|
@GetMapping(value = "/findStockByDepotAndBarCode")
|
||||||
@ApiOperation(value = "根据商品条码和仓库id查询库存数量")
|
@ApiOperation(value = "根据商品条码和仓库id查询库存数量")
|
||||||
public BaseResponseInfo findStockByDepotAndBarCode(
|
public BaseResponseInfo findStockByDepotAndBarCode(
|
||||||
@RequestParam("depotId") Long depotId,
|
@RequestParam(value = "depotId",required = false) Long depotId,
|
||||||
@RequestParam("barCode") String barCode,
|
@RequestParam("barCode") String barCode,
|
||||||
HttpServletRequest request) throws Exception{
|
HttpServletRequest request) throws Exception{
|
||||||
BaseResponseInfo res = new BaseResponseInfo();
|
BaseResponseInfo res = new BaseResponseInfo();
|
||||||
@@ -286,7 +286,7 @@ public class DepotItemController {
|
|||||||
@RequestParam("mpList") String mpList,
|
@RequestParam("mpList") String mpList,
|
||||||
HttpServletRequest request)throws Exception {
|
HttpServletRequest request)throws Exception {
|
||||||
BaseResponseInfo res = new BaseResponseInfo();
|
BaseResponseInfo res = new BaseResponseInfo();
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME;
|
String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME;
|
||||||
String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
|
String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
|
||||||
@@ -299,7 +299,7 @@ public class DepotItemController {
|
|||||||
//存放数据json数组
|
//存放数据json数组
|
||||||
JSONArray dataArray = new JSONArray();
|
JSONArray dataArray = new JSONArray();
|
||||||
if (null != dataList) {
|
if (null != dataList) {
|
||||||
List<Long> idList = new ArrayList<Long>();
|
List<Long> idList = new ArrayList<>();
|
||||||
for (DepotItemVo4WithInfoEx m : dataList) {
|
for (DepotItemVo4WithInfoEx m : dataList) {
|
||||||
idList.add(m.getMId());
|
idList.add(m.getMId());
|
||||||
}
|
}
|
||||||
@@ -316,20 +316,10 @@ public class DepotItemController {
|
|||||||
item.put("materialOther", materialOther);
|
item.put("materialOther", materialOther);
|
||||||
item.put("materialColor", diEx.getMColor());
|
item.put("materialColor", diEx.getMColor());
|
||||||
item.put("unitName", diEx.getMaterialUnit());
|
item.put("unitName", diEx.getMaterialUnit());
|
||||||
BigDecimal prevSum = BigDecimal.ZERO;
|
BigDecimal prevSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,timeA);
|
||||||
BigDecimal inSum = BigDecimal.ZERO;
|
BigDecimal inSum = depotItemService.getInNumByParamWithDepotList(depotList,mId,timeA,timeB);
|
||||||
BigDecimal outSum = BigDecimal.ZERO;
|
BigDecimal outSum = depotItemService.getOutNumByParamWithDepotList(depotList,mId,timeA,timeB);
|
||||||
BigDecimal thisSum = BigDecimal.ZERO;
|
BigDecimal thisSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,timeB);
|
||||||
for(Long depotId: depotList) {
|
|
||||||
BigDecimal prevSumStock = depotItemService.getStockByParam(depotId,mId,null,timeA);
|
|
||||||
BigDecimal inSumStock = depotItemService.getInNumByParam(depotId,mId,timeA,timeB);
|
|
||||||
BigDecimal outSumStock = depotItemService.getOutNumByParam(depotId,mId,timeA,timeB);
|
|
||||||
BigDecimal thisSumStock = depotItemService.getStockByParam(depotId,mId,null,timeB);
|
|
||||||
prevSum = prevSum.add(prevSumStock);
|
|
||||||
inSum = inSum.add(inSumStock);
|
|
||||||
outSum = outSum.add(outSumStock);
|
|
||||||
thisSum = thisSum.add(thisSumStock);
|
|
||||||
}
|
|
||||||
item.put("prevSum", prevSum);
|
item.put("prevSum", prevSum);
|
||||||
item.put("inSum", inSum);
|
item.put("inSum", inSum);
|
||||||
item.put("outSum", outSum);
|
item.put("outSum", outSum);
|
||||||
@@ -371,7 +361,7 @@ public class DepotItemController {
|
|||||||
@RequestParam("materialParam") String materialParam,
|
@RequestParam("materialParam") String materialParam,
|
||||||
HttpServletRequest request) throws Exception{
|
HttpServletRequest request) throws Exception{
|
||||||
BaseResponseInfo res = new BaseResponseInfo();
|
BaseResponseInfo res = new BaseResponseInfo();
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
|
String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME;
|
||||||
List<Long> depotList = StringUtil.strToLongList(depotIds);
|
List<Long> depotList = StringUtil.strToLongList(depotIds);
|
||||||
@@ -381,11 +371,7 @@ public class DepotItemController {
|
|||||||
if (null != dataList) {
|
if (null != dataList) {
|
||||||
for (DepotItemVo4WithInfoEx diEx : dataList) {
|
for (DepotItemVo4WithInfoEx diEx : dataList) {
|
||||||
Long mId = diEx.getMId();
|
Long mId = diEx.getMId();
|
||||||
BigDecimal thisSum = BigDecimal.ZERO;
|
BigDecimal thisSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,endTime);
|
||||||
for(Long depotId: depotList) {
|
|
||||||
BigDecimal thisSumStock = depotItemService.getStockByParam(depotId,mId,null,endTime);
|
|
||||||
thisSum = thisSum.add(thisSumStock);
|
|
||||||
}
|
|
||||||
BigDecimal unitPrice = diEx.getPurchaseDecimal();
|
BigDecimal unitPrice = diEx.getPurchaseDecimal();
|
||||||
if(unitPrice == null) {
|
if(unitPrice == null) {
|
||||||
unitPrice = BigDecimal.ZERO;
|
unitPrice = BigDecimal.ZERO;
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ public interface DepotItemMapperEx {
|
|||||||
@Param("beginTime") String beginTime,
|
@Param("beginTime") String beginTime,
|
||||||
@Param("endTime") String endTime);
|
@Param("endTime") String endTime);
|
||||||
|
|
||||||
BigDecimal getStockCheckSum(
|
BigDecimal getStockCheckSumByDepotList(
|
||||||
@Param("depotId") Long depotId,
|
@Param("depotList") List<Long> depotList,
|
||||||
@Param("mId") Long mId,
|
@Param("mId") Long mId,
|
||||||
@Param("beginTime") String beginTime,
|
@Param("beginTime") String beginTime,
|
||||||
@Param("endTime") String endTime);
|
@Param("endTime") String endTime);
|
||||||
@@ -90,8 +90,8 @@ public interface DepotItemMapperEx {
|
|||||||
@Param("beginTime") String beginTime,
|
@Param("beginTime") String beginTime,
|
||||||
@Param("endTime") String endTime);
|
@Param("endTime") String endTime);
|
||||||
|
|
||||||
DepotItemVo4Stock getStockByParam(
|
DepotItemVo4Stock getStockByParamWithDepotList(
|
||||||
@Param("depotId") Long depotId,
|
@Param("depotList") List<Long> depotList,
|
||||||
@Param("mId") Long mId,
|
@Param("mId") Long mId,
|
||||||
@Param("beginTime") String beginTime,
|
@Param("beginTime") String beginTime,
|
||||||
@Param("endTime") String endTime);
|
@Param("endTime") String endTime);
|
||||||
@@ -104,12 +104,6 @@ public interface DepotItemMapperEx {
|
|||||||
*/
|
*/
|
||||||
List<DepotItem> findDepotItemListBydepotheadId(@Param("depotheadId")Long depotheadId,
|
List<DepotItem> findDepotItemListBydepotheadId(@Param("depotheadId")Long depotheadId,
|
||||||
@Param("enableSerialNumber")String enableSerialNumber);
|
@Param("enableSerialNumber")String enableSerialNumber);
|
||||||
/**
|
|
||||||
* 根据单据主表id删除单据子表数据
|
|
||||||
* 物理删除,已弃用
|
|
||||||
* */
|
|
||||||
@Deprecated
|
|
||||||
int deleteDepotItemByDepotHeadIds(@Param("depotheadIds")Long []depotHeadIds);
|
|
||||||
/**
|
/**
|
||||||
* 根据单据主表id删除单据子表数据
|
* 根据单据主表id删除单据子表数据
|
||||||
* */
|
* */
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -581,7 +582,7 @@ public class DepotItemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 库存统计
|
* 库存统计-单仓库
|
||||||
* @param depotId
|
* @param depotId
|
||||||
* @param mId
|
* @param mId
|
||||||
* @param beginTime
|
* @param beginTime
|
||||||
@@ -589,11 +590,27 @@ public class DepotItemService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime){
|
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime){
|
||||||
|
List<Long> depotList = new ArrayList<>();
|
||||||
|
if(depotId != null) {
|
||||||
|
depotList.add(depotId);
|
||||||
|
}
|
||||||
|
return getStockByParamWithDepotList(depotList, mId, beginTime, endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 库存统计-多仓库
|
||||||
|
* @param depotList
|
||||||
|
* @param mId
|
||||||
|
* @param beginTime
|
||||||
|
* @param endTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BigDecimal getStockByParamWithDepotList(List<Long> depotList, Long mId, String beginTime, String endTime){
|
||||||
//初始库存
|
//初始库存
|
||||||
BigDecimal initStock = materialService.getInitStockByMid(depotId, mId);
|
BigDecimal initStock = materialService.getInitStockByMidAndDepotList(depotList, mId);
|
||||||
//盘点复盘后数量的变动
|
//盘点复盘后数量的变动
|
||||||
BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSum(depotId, mId, beginTime, endTime);
|
BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSumByDepotList(depotList, mId, beginTime, endTime);
|
||||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime);
|
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParamWithDepotList(depotList, mId, beginTime, endTime);
|
||||||
BigDecimal stockSum = BigDecimal.ZERO;
|
BigDecimal stockSum = BigDecimal.ZERO;
|
||||||
if(stockObj!=null) {
|
if(stockObj!=null) {
|
||||||
BigDecimal inTotal = stockObj.getInTotal();
|
BigDecimal inTotal = stockObj.getInTotal();
|
||||||
@@ -611,15 +628,15 @@ public class DepotItemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 入库统计
|
* 入库统计-多仓库
|
||||||
* @param depotId
|
* @param depotList
|
||||||
* @param mId
|
* @param mId
|
||||||
* @param beginTime
|
* @param beginTime
|
||||||
* @param endTime
|
* @param endTime
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public BigDecimal getInNumByParam(Long depotId, Long mId, String beginTime, String endTime){
|
public BigDecimal getInNumByParamWithDepotList(List<Long> depotList, Long mId, String beginTime, String endTime){
|
||||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime);
|
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParamWithDepotList(depotList, mId, beginTime, endTime);
|
||||||
BigDecimal stockSum = BigDecimal.ZERO;
|
BigDecimal stockSum = BigDecimal.ZERO;
|
||||||
if(stockObj!=null) {
|
if(stockObj!=null) {
|
||||||
BigDecimal inTotal = stockObj.getInTotal();
|
BigDecimal inTotal = stockObj.getInTotal();
|
||||||
@@ -632,15 +649,15 @@ public class DepotItemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 出库统计
|
* 出库统计-多仓库
|
||||||
* @param depotId
|
* @param depotList
|
||||||
* @param mId
|
* @param mId
|
||||||
* @param beginTime
|
* @param beginTime
|
||||||
* @param endTime
|
* @param endTime
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public BigDecimal getOutNumByParam(Long depotId, Long mId, String beginTime, String endTime){
|
public BigDecimal getOutNumByParamWithDepotList(List<Long> depotList, Long mId, String beginTime, String endTime){
|
||||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime);
|
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParamWithDepotList(depotList, mId, beginTime, endTime);
|
||||||
BigDecimal stockSum = BigDecimal.ZERO;
|
BigDecimal stockSum = BigDecimal.ZERO;
|
||||||
if(stockObj!=null) {
|
if(stockObj!=null) {
|
||||||
BigDecimal outTotal = stockObj.getOutTotal();
|
BigDecimal outTotal = stockObj.getOutTotal();
|
||||||
|
|||||||
@@ -762,15 +762,16 @@ public class MaterialService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据商品获取初始库存,仓库为空的时候查全部库存
|
* 根据商品获取初始库存-多仓库
|
||||||
|
* @param depotList
|
||||||
* @param materialId
|
* @param materialId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public BigDecimal getInitStockByMid(Long depotId, Long materialId) {
|
public BigDecimal getInitStockByMidAndDepotList(List<Long> depotList, Long materialId) {
|
||||||
BigDecimal stock = BigDecimal.ZERO;
|
BigDecimal stock = BigDecimal.ZERO;
|
||||||
MaterialInitialStockExample example = new MaterialInitialStockExample();
|
MaterialInitialStockExample example = new MaterialInitialStockExample();
|
||||||
if(depotId!=null) {
|
if(depotList!=null && depotList.size()>0) {
|
||||||
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
|
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdIn(depotList)
|
||||||
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||||
} else {
|
} else {
|
||||||
example.createCriteria().andMaterialIdEqualTo(materialId)
|
example.createCriteria().andMaterialIdEqualTo(materialId)
|
||||||
|
|||||||
@@ -273,7 +273,7 @@
|
|||||||
and ifnull(dh.delete_flag,'0') !='1'
|
and ifnull(dh.delete_flag,'0') !='1'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getStockCheckSum" resultType="java.math.BigDecimal">
|
<select id="getStockCheckSumByDepotList" resultType="java.math.BigDecimal">
|
||||||
select ifnull(sum(di.basic_number),0) stockCheckSum from jsh_depot_head dh
|
select ifnull(sum(di.basic_number),0) stockCheckSum from jsh_depot_head dh
|
||||||
left JOIN jsh_depot_item di on dh.id=di.header_id
|
left JOIN jsh_depot_item di on dh.id=di.header_id
|
||||||
where 1=1
|
where 1=1
|
||||||
@@ -281,8 +281,11 @@
|
|||||||
and di.material_id=#{mId}
|
and di.material_id=#{mId}
|
||||||
</if>
|
</if>
|
||||||
and dh.sub_type='盘点复盘'
|
and dh.sub_type='盘点复盘'
|
||||||
<if test="depotId != null">
|
<if test="depotList.size()>0">
|
||||||
and di.depot_id=#{depotId}
|
and di.depot_id in
|
||||||
|
<foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
<if test="beginTime != null">
|
<if test="beginTime != null">
|
||||||
and dh.oper_time >= #{beginTime}
|
and dh.oper_time >= #{beginTime}
|
||||||
@@ -319,16 +322,22 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getStockByParam" resultMap="stockMap">
|
<sql id="depotParam">
|
||||||
|
<if test="depotList.size()>0">
|
||||||
|
and di.depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
|
||||||
|
</if>
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="getStockByParamWithDepotList" resultMap="stockMap">
|
||||||
select
|
select
|
||||||
sum(case when dh.type='入库' <if test="depotId != null">and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as inTotal,
|
sum(case when dh.type='入库' <include refid="depotParam" /> then di.basic_number else 0 end) as inTotal,
|
||||||
sum(case when dh.type='出库' and dh.sub_type!='调拨' <if test="depotId != null">and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as outTotal,
|
sum(case when dh.type='出库' and dh.sub_type!='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as outTotal,
|
||||||
sum(case when dh.sub_type='调拨' <if test="depotId != null">and di.another_depot_id=#{depotId}</if> then di.basic_number else 0 end) as transfInTotal,
|
sum(case when dh.sub_type='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as transfInTotal,
|
||||||
sum(case when dh.sub_type='调拨' <if test="depotId != null">and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as transfOutTotal,
|
sum(case when dh.sub_type='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as transfOutTotal,
|
||||||
sum(case when dh.sub_type='组装单' and di.material_type='组合件' <if test="depotId != null">and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as assemInTotal,
|
sum(case when dh.sub_type='组装单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemInTotal,
|
||||||
sum(case when dh.sub_type='组装单' and di.material_type='普通子件' <if test="depotId != null">and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as assemOutTotal,
|
sum(case when dh.sub_type='组装单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as assemOutTotal,
|
||||||
sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' <if test="depotId != null">and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as disAssemInTotal,
|
sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemInTotal,
|
||||||
sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <if test="depotId != null"> and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as disAssemOutTotal
|
sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemOutTotal
|
||||||
from
|
from
|
||||||
jsh_depot_head dh
|
jsh_depot_head dh
|
||||||
left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
|
left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
|
||||||
@@ -362,17 +371,6 @@
|
|||||||
and ifnull(mat.delete_flag,'0') !='1'
|
and ifnull(mat.delete_flag,'0') !='1'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<delete id="deleteDepotItemByDepotHeadIds">
|
|
||||||
delete from jsh_depot_item
|
|
||||||
where 1=1
|
|
||||||
and header_id in
|
|
||||||
(
|
|
||||||
<foreach collection="depotheadIds" item="depotheadId" separator=",">
|
|
||||||
#{depotheadId}
|
|
||||||
</foreach>
|
|
||||||
)
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<update id="batchDeleteDepotItemByDepotHeadIds">
|
<update id="batchDeleteDepotItemByDepotHeadIds">
|
||||||
update jsh_depot_item
|
update jsh_depot_item
|
||||||
set delete_flag='1'
|
set delete_flag='1'
|
||||||
|
|||||||
Reference in New Issue
Block a user