优化商品库存查询逻辑,在没有选择仓库的时候过滤出当前有权限的仓库

This commit is contained in:
季圣华
2023-03-07 22:06:10 +08:00
parent a84b9e8c12
commit 81c065ea5c
4 changed files with 48 additions and 32 deletions

View File

@@ -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);

View File

@@ -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";

View File

@@ -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)