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 fd7903de6..4f4a073a6 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 @@ -308,7 +308,7 @@ public class DepotItemController { } /** - * 进销存统计 + * 进销存统计-即将废弃 * @param currentPage * @param pageSize * @param depotIds @@ -340,10 +340,10 @@ public class DepotItemController { String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME; String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; List depotList = parseListByDepotIds(depotIds); - List dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), + List dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam), categoryIdList, timeB,(currentPage-1)*pageSize, pageSize); String[] mpArr = mpList.split(","); - int total = depotItemService.findByAllCount(StringUtil.toNull(materialParam), categoryIdList, timeB); + int total = depotItemService.getInOutStockCount(StringUtil.toNull(materialParam), categoryIdList, timeB); map.put("total", total); //存放数据json数组 JSONArray dataArray = new JSONArray(); @@ -400,7 +400,7 @@ public class DepotItemController { } /** - * 进销存统计总计金额 + * 进销存统计总计金额-即将废弃 * @param depotIds * @param monthTime * @param materialParam @@ -424,7 +424,159 @@ public class DepotItemController { } String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; List depotList = parseListByDepotIds(depotIds); - List dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), + List dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam), + categoryIdList, endTime, null, null); + BigDecimal thisAllStock = BigDecimal.ZERO; + BigDecimal thisAllPrice = BigDecimal.ZERO; + if (null != dataList) { + for (DepotItemVo4WithInfoEx diEx : dataList) { + Long mId = diEx.getMId(); + BigDecimal thisSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,endTime); + thisAllStock = thisAllStock.add(thisSum); + BigDecimal unitPrice = null; + if(moveAvgPriceFlag) { + unitPrice = diEx.getCurrentUnitPrice(); + } else { + unitPrice = diEx.getPurchaseDecimal(); + } + if(unitPrice == null) { + unitPrice = BigDecimal.ZERO; + } + thisAllPrice = thisAllPrice.add(thisSum.multiply(unitPrice)); + } + } + map.put("totalStock", thisAllStock); + map.put("totalCount", thisAllPrice); + res.code = 200; + res.data = map; + } catch (BusinessRunTimeException e) { + res.code = e.getCode(); + res.data = e.getData().get("message"); + } catch(Exception e){ + logger.error(e.getMessage(), e); + res.code = 500; + res.data = "获取数据失败"; + } + return res; + } + + /** + * 进销存统计查询 + * @param currentPage + * @param pageSize + * @param depotIds + * @param beginTime + * @param endTime + * @param materialParam + * @param mpList + * @param request + * @return + * @throws Exception + */ + @GetMapping(value = "/getInOutStock") + @ApiOperation(value = "进销存统计查询") + public BaseResponseInfo getInOutStock(@RequestParam("currentPage") Integer currentPage, + @RequestParam("pageSize") Integer pageSize, + @RequestParam(value = "depotIds",required = false) String depotIds, + @RequestParam(value = "categoryId", required = false) Long categoryId, + @RequestParam("beginTime") String beginTime, + @RequestParam("endTime") String endTime, + @RequestParam("materialParam") String materialParam, + @RequestParam("mpList") String mpList, + HttpServletRequest request)throws Exception { + BaseResponseInfo res = new BaseResponseInfo(); + Map map = new HashMap<>(); + try { + Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag(); + List categoryIdList = new ArrayList<>(); + if(categoryId != null){ + categoryIdList = materialService.getListByParentId(categoryId); + } + List depotList = parseListByDepotIds(depotIds); + List dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam), + categoryIdList, endTime,(currentPage-1)*pageSize, pageSize); + String[] mpArr = mpList.split(","); + int total = depotItemService.getInOutStockCount(StringUtil.toNull(materialParam), categoryIdList, endTime); + map.put("total", total); + //存放数据json数组 + JSONArray dataArray = new JSONArray(); + if (null != dataList) { + for (DepotItemVo4WithInfoEx diEx : dataList) { + JSONObject item = new JSONObject(); + Long mId = diEx.getMId(); + item.put("barCode", diEx.getBarCode()); + item.put("materialName", diEx.getMName()); + item.put("materialModel", diEx.getMModel()); + item.put("materialStandard", diEx.getMStandard()); + //扩展信息 + String materialOther = depotItemService.getOtherInfo(mpArr, diEx); + item.put("materialOther", materialOther); + item.put("materialColor", diEx.getMColor()); + item.put("unitId", diEx.getUnitId()); + item.put("unitName", null!=diEx.getUnitId() ? diEx.getMaterialUnit()+"[多单位]" : diEx.getMaterialUnit()); + BigDecimal prevSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,beginTime); + Map intervalMap = depotItemService.getIntervalMapByParamWithDepotList(depotList,mId,beginTime,endTime); + BigDecimal inSum = intervalMap.get("inSum"); + BigDecimal outSum = intervalMap.get("outSum"); + BigDecimal thisSum = prevSum.add(inSum).subtract(outSum); + item.put("prevSum", prevSum); + item.put("inSum", inSum); + item.put("outSum", outSum); + item.put("thisSum", thisSum); + //将小单位的库存换算为大单位的库存 + item.put("bigUnitStock", materialService.getBigUnitStock(thisSum, diEx.getUnitId())); + if(moveAvgPriceFlag) { + item.put("unitPrice", diEx.getCurrentUnitPrice()); + } else { + item.put("unitPrice", diEx.getPurchaseDecimal()); + } + if(moveAvgPriceFlag) { + item.put("thisAllPrice", thisSum.multiply(diEx.getCurrentUnitPrice())); + } else { + item.put("thisAllPrice", thisSum.multiply(diEx.getPurchaseDecimal())); + } + dataArray.add(item); + } + } + map.put("rows", dataArray); + res.code = 200; + res.data = map; + } catch (BusinessRunTimeException e) { + res.code = e.getCode(); + res.data = e.getData().get("message"); + } catch(Exception e){ + logger.error(e.getMessage(), e); + res.code = 500; + res.data = "获取数据失败"; + } + return res; + } + + /** + * 进销存统计总计金额 + * @param depotIds + * @param endTime + * @param materialParam + * @param request + * @return + */ + @GetMapping(value = "/getInOutStockCountMoney") + @ApiOperation(value = "进销存统计总计金额") + public BaseResponseInfo getInOutStockCountMoney(@RequestParam(value = "depotIds",required = false) String depotIds, + @RequestParam(value = "categoryId", required = false) Long categoryId, + @RequestParam("endTime") String endTime, + @RequestParam("materialParam") String materialParam, + HttpServletRequest request) throws Exception{ + BaseResponseInfo res = new BaseResponseInfo(); + Map map = new HashMap<>(); + try { + Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag(); + List categoryIdList = new ArrayList<>(); + if(categoryId != null){ + categoryIdList = materialService.getListByParentId(categoryId); + } + List depotList = parseListByDepotIds(depotIds); + List dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam), categoryIdList, endTime, null, null); BigDecimal thisAllStock = BigDecimal.ZERO; BigDecimal thisAllPrice = BigDecimal.ZERO; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java index c64b1c73e..009bc4f02 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java @@ -60,14 +60,14 @@ public interface DepotItemMapperEx { List getBillDetailListByIds( @Param("idList") List idList); - List findByAll( + List getInOutStock( @Param("materialParam") String materialParam, @Param("categoryIdList") List categoryIdList, @Param("endTime") String endTime, @Param("offset") Integer offset, @Param("rows") Integer rows); - int findByAllCount( + int getInOutStockCount( @Param("materialParam") String materialParam, @Param("categoryIdList") List categoryIdList, @Param("endTime") String endTime); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java index ee8f3ee17..4223e217d 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java @@ -301,20 +301,20 @@ public class DepotItemService { return list; } - public List findByAll(String materialParam, List categoryIdList, String endTime, Integer offset, Integer rows)throws Exception { + public List getInOutStock(String materialParam, List categoryIdList, String endTime, Integer offset, Integer rows)throws Exception { List list =null; try{ - list = depotItemMapperEx.findByAll(materialParam, categoryIdList, endTime, offset, rows); + list = depotItemMapperEx.getInOutStock(materialParam, categoryIdList, endTime, offset, rows); }catch(Exception e){ JshException.readFail(logger, e); } return list; } - public int findByAllCount(String materialParam, List categoryIdList, String endTime)throws Exception { + public int getInOutStockCount(String materialParam, List categoryIdList, String endTime)throws Exception { int result=0; try{ - result = depotItemMapperEx.findByAllCount(materialParam, categoryIdList, endTime); + result = depotItemMapperEx.getInOutStockCount(materialParam, categoryIdList, endTime); }catch(Exception e){ JshException.readFail(logger, e); } diff --git a/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml index 06f8811ee..67e7ec293 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml @@ -343,7 +343,7 @@ order by di.header_id desc, di.id asc - select m.id MId, me.bar_code, m.name MName, m.mfrs MMfrs, m.model MModel, m.standard MStandard, m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3, concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.unit_id, u.name unit_name, @@ -376,7 +376,7 @@ - select count(1) from (select m.id from jsh_material m left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'