diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java index 523ed589..beb3fb5d 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java @@ -8,6 +8,7 @@ import com.jsh.erp.datasource.entities.*; import com.jsh.erp.datasource.vo.DepotItemStockWarningCount; import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList; import com.jsh.erp.exception.BusinessRunTimeException; +import com.jsh.erp.service.depot.DepotService; import com.jsh.erp.service.materialExtend.MaterialExtendService; import com.jsh.erp.service.depotItem.DepotItemService; import com.jsh.erp.service.material.MaterialService; @@ -53,6 +54,9 @@ public class DepotItemController { @Resource private UnitService unitService; + @Resource + private DepotService depotService; + @Resource private RedisService redisService; @@ -277,7 +281,7 @@ public class DepotItemController { * 查找所有的明细 * @param currentPage * @param pageSize - * @param depotId + * @param depotIds * @param monthTime * @param materialParam * @param mpList @@ -289,16 +293,27 @@ public class DepotItemController { @ApiOperation(value = "查找所有的明细") public BaseResponseInfo findByAll(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize, - @RequestParam(value = "depotId", required = false) Long depotId, + @RequestParam(value = "depotIds", required = false) String depotIds, @RequestParam("monthTime") String monthTime, @RequestParam("materialParam") String materialParam, @RequestParam("mpList") String mpList, HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); - String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME; - String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; try { + String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME; + String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; + List depotList = new ArrayList<>(); + if(StringUtil.isNotEmpty(depotIds)) { + depotList = StringUtil.strToLongList(depotIds); + } else { + //未选择仓库时默认为当前用户有权限的仓库 + JSONArray depotArr = depotService.findDepotByCurrentUser(); + for(Object obj: depotArr) { + JSONObject object = JSONObject.parseObject(obj.toString()); + depotList.add(object.getLong("id")); + } + } List dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), timeB,(currentPage-1)*pageSize, pageSize); String[] mpArr = mpList.split(","); @@ -324,11 +339,23 @@ public class DepotItemController { item.put("materialOther", materialOther); item.put("materialColor", diEx.getMColor()); item.put("unitName", diEx.getMaterialUnit()); - - item.put("prevSum", depotItemService.getStockByParam(depotId,mId,null,timeA)); - item.put("inSum", depotItemService.getInNumByParam(depotId,mId,timeA,timeB)); - item.put("outSum", depotItemService.getOutNumByParam(depotId,mId,timeA,timeB)); - BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,timeB); + BigDecimal prevSum = BigDecimal.ZERO; + BigDecimal inSum = BigDecimal.ZERO; + BigDecimal outSum = BigDecimal.ZERO; + BigDecimal thisSum = BigDecimal.ZERO; + 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("inSum", inSum); + item.put("outSum", outSum); item.put("thisSum", thisSum); for(MaterialExtend me:meList) { if(me.getMaterialId().longValue() == diEx.getMId().longValue()) { @@ -354,7 +381,7 @@ public class DepotItemController { /** * 统计总计金额 - * @param depotId + * @param depotIds * @param monthTime * @param materialParam * @param request @@ -362,21 +389,36 @@ public class DepotItemController { */ @GetMapping(value = "/totalCountMoney") @ApiOperation(value = "统计总计金额") - public BaseResponseInfo totalCountMoney(@RequestParam(value = "depotId", required = false) Long depotId, + public BaseResponseInfo totalCountMoney(@RequestParam(value = "depotIds", required = false) String depotIds, @RequestParam("monthTime") String monthTime, @RequestParam("materialParam") String materialParam, HttpServletRequest request) throws Exception{ BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); - String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; try { + String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; + List depotList = new ArrayList<>(); + if(StringUtil.isNotEmpty(depotIds)) { + depotList = StringUtil.strToLongList(depotIds); + } else { + //未选择仓库时默认为当前用户有权限的仓库 + JSONArray depotArr = depotService.findDepotByCurrentUser(); + for(Object obj: depotArr) { + JSONObject object = JSONObject.parseObject(obj.toString()); + depotList.add(object.getLong("id")); + } + } List dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), endTime, null, null); BigDecimal thisAllPrice = BigDecimal.ZERO; if (null != dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) { Long mId = diEx.getMId(); - BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,endTime); + BigDecimal thisSum = BigDecimal.ZERO; + for(Long depotId: depotList) { + BigDecimal thisSumStock = depotItemService.getStockByParam(depotId,mId,null,endTime); + thisSum = thisSum.add(thisSumStock); + } BigDecimal unitPrice = diEx.getPurchaseDecimal(); if(unitPrice == null) { unitPrice = BigDecimal.ZERO;