优化商品库存查询逻辑,在没有选择仓库的时候过滤出当前有权限的仓库
This commit is contained in:
parent
a84b9e8c12
commit
81c065ea5c
@ -116,8 +116,8 @@ public interface DepotItemMapperEx {
|
||||
@Param("beginTime") String beginTime,
|
||||
@Param("endTime") String endTime);
|
||||
|
||||
DepotItemVo4Stock getSkuStockByParam(
|
||||
@Param("depotId") Long depotId,
|
||||
DepotItemVo4Stock getSkuStockByParamWithDepotList(
|
||||
@Param("depotList") List<Long> depotList,
|
||||
@Param("meId") Long meId,
|
||||
@Param("beginTime") String beginTime,
|
||||
@Param("endTime") String endTime);
|
||||
|
||||
@ -287,6 +287,21 @@ public class DepotService {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<Long> parseDepotList(Long depotId) throws Exception {
|
||||
List<Long> depotList = new ArrayList<>();
|
||||
if(depotId !=null) {
|
||||
depotList.add(depotId);
|
||||
} else {
|
||||
//未选择仓库时默认为当前用户有权限的仓库
|
||||
JSONArray depotArr = findDepotByCurrentUser();
|
||||
for(Object obj: depotArr) {
|
||||
JSONObject object = JSONObject.parseObject(obj.toString());
|
||||
depotList.add(object.getLong("id"));
|
||||
}
|
||||
}
|
||||
return depotList;
|
||||
}
|
||||
|
||||
public JSONArray findDepotByCurrentUser() throws Exception {
|
||||
JSONArray arr = new JSONArray();
|
||||
String type = "UserDepot";
|
||||
|
||||
@ -11,6 +11,7 @@ import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
|
||||
import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.exception.JshException;
|
||||
import com.jsh.erp.service.depot.DepotService;
|
||||
import com.jsh.erp.service.depotHead.DepotHeadService;
|
||||
import com.jsh.erp.service.materialExtend.MaterialExtendService;
|
||||
import com.jsh.erp.service.log.LogService;
|
||||
@ -62,6 +63,8 @@ public class DepotItemService {
|
||||
@Resource
|
||||
private SystemConfigService systemConfigService;
|
||||
@Resource
|
||||
private DepotService depotService;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private MaterialCurrentStockMapper materialCurrentStockMapper;
|
||||
@ -863,8 +866,9 @@ public class DepotItemService {
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getSkuStockByParam(Long depotId, Long meId, String beginTime, String endTime){
|
||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getSkuStockByParam(depotId, meId, beginTime, endTime);
|
||||
public BigDecimal getSkuStockByParam(Long depotId, Long meId, String beginTime, String endTime) throws Exception {
|
||||
List<Long> depotList = depotService.parseDepotList(depotId);
|
||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getSkuStockByParamWithDepotList(depotList, meId, beginTime, endTime);
|
||||
BigDecimal stockSum = BigDecimal.ZERO;
|
||||
if(stockObj!=null) {
|
||||
BigDecimal inTotal = stockObj.getInTotal();
|
||||
@ -889,11 +893,8 @@ public class DepotItemService {
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime){
|
||||
List<Long> depotList = new ArrayList<>();
|
||||
if(depotId != null) {
|
||||
depotList.add(depotId);
|
||||
}
|
||||
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime) throws Exception {
|
||||
List<Long> depotList = depotService.parseDepotList(depotId);
|
||||
return getStockByParamWithDepotList(depotList, mId, beginTime, endTime);
|
||||
}
|
||||
|
||||
@ -970,7 +971,7 @@ public class DepotItemService {
|
||||
* @param depotItem
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void updateCurrentStock(DepotItem depotItem){
|
||||
public void updateCurrentStock(DepotItem depotItem) throws Exception {
|
||||
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId());
|
||||
if(depotItem.getAnotherDepotId()!=null){
|
||||
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId());
|
||||
@ -982,7 +983,7 @@ public class DepotItemService {
|
||||
* @param mId
|
||||
* @param dId
|
||||
*/
|
||||
public void updateCurrentStockFun(Long mId, Long dId) {
|
||||
public void updateCurrentStockFun(Long mId, Long dId) throws Exception {
|
||||
if(mId!=null && dId!=null) {
|
||||
MaterialCurrentStockExample example = new MaterialCurrentStockExample();
|
||||
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId)
|
||||
|
||||
@ -520,16 +520,16 @@
|
||||
and ifnull(di.delete_flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="getSkuStockByParam" resultMap="stockMap">
|
||||
<select id="getSkuStockByParamWithDepotList" resultMap="stockMap">
|
||||
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='出库' 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.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='调拨' <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='组装单' 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='普通子件' <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='普通子件' <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='组合件' <if test="depotId != null"> and di.depot_id=#{depotId}</if> then di.basic_number else 0 end) as disAssemOutTotal
|
||||
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!='调拨' <include refid="depotParam" /> then di.basic_number else 0 end) as outTotal,
|
||||
sum(case when dh.sub_type='调拨' <include refid="anotherDepotParam" /> 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 transfOutTotal,
|
||||
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='普通子件' <include refid="depotParam" /> 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 disAssemInTotal,
|
||||
sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' <include refid="depotParam" /> then di.basic_number else 0 end) as disAssemOutTotal
|
||||
from
|
||||
jsh_depot_head dh
|
||||
left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1'
|
||||
@ -545,18 +545,6 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<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>
|
||||
|
||||
<sql id="anotherDepotParam">
|
||||
<if test="depotList.size()>0">
|
||||
and di.another_depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="getStockByParamWithDepotList" resultMap="stockMap">
|
||||
select
|
||||
sum(case when dh.type='入库' <include refid="depotParam" /> then di.basic_number else 0 end) as inTotal,
|
||||
@ -581,6 +569,18 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<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>
|
||||
|
||||
<sql id="anotherDepotParam">
|
||||
<if test="depotList.size()>0">
|
||||
and di.another_depot_id in <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">#{item}</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="findDepotItemListBydepotheadId" resultType="com.jsh.erp.datasource.entities.DepotItem">
|
||||
select
|
||||
dep.id,dep.header_id,dep.material_id,dep.material_unit,dep.oper_number,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user