From ee8390559bc06397c7209ef411efdc8c5d9d3e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Sat, 12 Oct 2019 01:32:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- erp_web/js/pages/materials/in_out.js | 11 +- .../pages/reports/in_out_stock_report.html | 19 +- .../java/com/jsh/erp/config/TenantConfig.java | 16 +- .../erp/controller/DepotHeadController.java | 17 +- .../erp/controller/DepotItemController.java | 359 +++++------------- .../datasource/mappers/DepotItemMapperEx.java | 89 +---- .../erp/datasource/vo/DepotItemVo4Stock.java | 26 ++ .../service/depotHead/DepotHeadService.java | 9 +- .../service/depotItem/DepotItemService.java | 175 +++------ .../mapper_xml/DepotItemMapperEx.xml | 209 ++-------- 10 files changed, 253 insertions(+), 677 deletions(-) create mode 100644 src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java diff --git a/erp_web/js/pages/materials/in_out.js b/erp_web/js/pages/materials/in_out.js index b7fd744b..62e00570 100644 --- a/erp_web/js/pages/materials/in_out.js +++ b/erp_web/js/pages/materials/in_out.js @@ -603,17 +603,14 @@ type: "get", url: '/depotItem/findStockNumById', data:{ - projectId: depotId, - materialId: mId, - monthTime: monthTime, - currentPage: 1, - pageSize: 10 + depotId: depotId, + mId: mId }, dataType: "json", success: function (res) { if(res && res.code === 200) { - if (res.data && res.data.page && res.data.page[0]) { - var thisStock = res.data.page[0].thisSum; + if (res.data) { + var thisStock = res.data.stock; if (type == "select") { //选择下拉框的时候 if (ratio != undefined && ratio != 1) { loadRatio = ratio; diff --git a/erp_web/pages/reports/in_out_stock_report.html b/erp_web/pages/reports/in_out_stock_report.html index 97b1da3b..92951af8 100644 --- a/erp_web/pages/reports/in_out_stock_report.html +++ b/erp_web/pages/reports/in_out_stock_report.html @@ -71,14 +71,9 @@ //导出EXCEL function exportExcel() { $("#exprotBtn").off("click").on("click", function () { - if (!$("#searchPanel .total-count").text()) { - $.messager.alert('导出提示', '请先选择月份再进行查询!', 'error'); - } - else { - showEachDetails(1, 3000); - //此处直接去做get请求,用下面的查询每月统计的方法,去获取list,参数长度虽长,但还是可以用get - //window.location.href = "/depotItem/exportExcel.action?browserType=" + getOs(); - } + showEachDetails(1, 3000); + //此处直接去做get请求,用下面的查询每月统计的方法,去获取list,参数长度虽长,但还是可以用get + //window.location.href = "/depotItem/exportExcel.action?browserType=" + getOs(); }); } @@ -314,7 +309,7 @@ var mIds = res.data.mIds; if (mIds) { if (pageSize === 3000) { - window.location.href = "/depotItem/exportExcel?browserType=" + getOs() + "¤tPage=" + pageNo + "&pageSize=" + pageSize + "&projectId=" + $.trim($("#searchProjectId").val()) + "&monthTime=" + $("#searchMonth").val() + "&headIds=" + HeadIds + "&materialIds=" + mIds; + window.location.href = "/depotItem/exportExcel?browserType=" + getOs() + "¤tPage=" + pageNo + "&pageSize=" + pageSize + "&depotId=" + $.trim($("#searchProjectId").val()) + "&monthTime=" + $("#searchMonth").val() + "&headIds=" + HeadIds + "&materialIds=" + mIds; } else { $.ajax({ @@ -324,7 +319,7 @@ data: ({ currentPage: pageNo, pageSize: pageSize, - projectId: $.trim($("#searchProjectId").val()), + depotId: $.trim($("#searchProjectId").val()), monthTime: $("#searchMonth").val(), headIds: HeadIds, materialIds: mIds, @@ -348,7 +343,7 @@ url: "/depotItem/totalCountMoney", dataType: "json", data: ({ - projectId: $.trim($("#searchProjectId").val()), + depotId: $.trim($("#searchProjectId").val()), monthTime: $("#searchMonth").val(), headIds: HeadIds, materialIds: mIds @@ -360,7 +355,7 @@ if (count.lastIndexOf('.') > -1) { count = count.substring(0, count.lastIndexOf('.') + 3); } - $("#searchPanel .total-count").text("本月合计金额:" + count + "元");//本月合计金额 + $("#searchTable .total-count").text("本月合计金额:" + count + "元");//本月合计金额 } } }, diff --git a/src/main/java/com/jsh/erp/config/TenantConfig.java b/src/main/java/com/jsh/erp/config/TenantConfig.java index 929d368b..d697a93d 100644 --- a/src/main/java/com/jsh/erp/config/TenantConfig.java +++ b/src/main/java/com/jsh/erp/config/TenantConfig.java @@ -61,9 +61,8 @@ public class TenantConfig { return true; } else { // 这里可以判断是否过滤表 - if ("databasechangelog".equals(tableName) || "databasechangeloglock".equals(tableName) - || "jsh_materialproperty".equals(tableName) || "tbl_sequence".equals(tableName) - || "jsh_userbusiness".equals(tableName) || "jsh_app".equals(tableName) || "jsh_functions".equals(tableName) + if ("jsh_materialproperty".equals(tableName) || "tbl_sequence".equals(tableName) + || "jsh_userbusiness".equals(tableName) || "jsh_functions".equals(tableName) || "jsh_tenant".equals(tableName)) { return true; } else { @@ -83,7 +82,8 @@ public class TenantConfig { public boolean doFilter(MetaObject metaObject) { MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject); // 过滤自定义查询此时无租户信息约束出现 - if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) { + if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())|| + "com.jsh.erp.datasource.mappers.DepotItemMapperEx.getStockByParam".equals(ms.getId())) { return true; } return false; @@ -108,10 +108,10 @@ public class TenantConfig { /** * 性能分析拦截器,不建议生产使用 */ -// @Bean -// public PerformanceInterceptor performanceInterceptor(){ -// return new PerformanceInterceptor(); -// } + @Bean + public PerformanceInterceptor performanceInterceptor(){ + return new PerformanceInterceptor(); + } } diff --git a/src/main/java/com/jsh/erp/controller/DepotHeadController.java b/src/main/java/com/jsh/erp/controller/DepotHeadController.java index e5365893..79042d20 100644 --- a/src/main/java/com/jsh/erp/controller/DepotHeadController.java +++ b/src/main/java/com/jsh/erp/controller/DepotHeadController.java @@ -398,12 +398,13 @@ public class DepotHeadController { @RequestParam("updated") String updated, HttpServletRequest request) throws Exception{ JSONObject result = ExceptionConstants.standardSuccess(); Long billsNumLimit = Long.parseLong(request.getSession().getAttribute("billsNumLimit").toString()); + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); Long count = depotHeadService.countDepotHead(null,null,null,null,null,null,null); if(count>= billsNumLimit) { throw new BusinessParamCheckingException(ExceptionConstants.DEPOT_HEAD_OVER_LIMIT_FAILED_CODE, ExceptionConstants.DEPOT_HEAD_OVER_LIMIT_FAILED_MSG); } else { - depotHeadService.addDepotHeadAndDetail(beanJson,inserted,deleted,updated); + depotHeadService.addDepotHeadAndDetail(beanJson,inserted,deleted,updated,tenantId); } return result; } @@ -421,12 +422,16 @@ public class DepotHeadController { * @return java.lang.Object */ @RequestMapping(value = "/updateDepotHeadAndDetail") - public Object updateDepotHeadAndDetail(@RequestParam("id") Long id,@RequestParam("info") String beanJson,@RequestParam("inserted") String inserted, - @RequestParam("deleted") String deleted, - @RequestParam("updated") String updated,@RequestParam("preTotalPrice") BigDecimal preTotalPrice) throws Exception{ - + public Object updateDepotHeadAndDetail(@RequestParam("id") Long id, + @RequestParam("info") String beanJson, + @RequestParam("inserted") String inserted, + @RequestParam("deleted") String deleted, + @RequestParam("updated") String updated, + @RequestParam("preTotalPrice") BigDecimal preTotalPrice, + HttpServletRequest request) throws Exception{ + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); JSONObject result = ExceptionConstants.standardSuccess(); - depotHeadService.updateDepotHeadAndDetail(id,beanJson,inserted,deleted,updated,preTotalPrice); + depotHeadService.updateDepotHeadAndDetail(id,beanJson,inserted,deleted,updated,preTotalPrice,tenantId); return result; } /** diff --git a/src/main/java/com/jsh/erp/controller/DepotItemController.java b/src/main/java/com/jsh/erp/controller/DepotItemController.java index 88e9edc8..4a32543d 100644 --- a/src/main/java/com/jsh/erp/controller/DepotItemController.java +++ b/src/main/java/com/jsh/erp/controller/DepotItemController.java @@ -89,93 +89,30 @@ public class DepotItemController { /** * 根据商品id和仓库id查询库存数量 - * @param pageSize - * @param currentPage + * @param depotId * @param mId * @param request * @return + * @throws Exception */ @GetMapping(value = "/findStockNumById") - public String findStockNumById( - @RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize, - @RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage, - @RequestParam("projectId") Integer pid, - @RequestParam("materialId") String mId, - @RequestParam("monthTime") String monthTime, + public BaseResponseInfo findStockNumById( + @RequestParam("depotId") Long depotId, + @RequestParam("mId") Long mId, HttpServletRequest request) throws Exception{ - Map parameterMap = ParamUtils.requestToMap(request); - parameterMap.put("mId", mId); - parameterMap.put("monthTime", monthTime); - PageQueryInfo queryInfo = new PageQueryInfo(); - Map objectMap = new HashMap(); - if (pageSize != null && pageSize <= 0) { - pageSize = 10; - } - String offset = ParamUtils.getPageOffset(currentPage, pageSize); - if (StringUtil.isNotEmpty(offset)) { - parameterMap.put(Constants.OFFSET, offset); - } - List list = depotItemService.findStockNumByMaterialIdList(parameterMap); - //存放数据json数组 - Long materialId = Long.parseLong(mId); - JSONArray dataArray = new JSONArray(); - if (null != list) { - for (DepotItemVo4Material di : list) { - JSONObject item = new JSONObject(); - BigDecimal prevSum = sumNumber("入库", pid, materialId, monthTime, true).subtract(sumNumber("出库", pid, materialId, monthTime, true)); - BigDecimal InSum = sumNumber("入库", pid, materialId, monthTime, false); - BigDecimal OutSum = sumNumber("出库", pid, materialId, monthTime, false); - // +组装(组合件)-组装(普通子件)+拆卸(普通子件)-拆卸(组合件) - BigDecimal prevAssembleSum = assembleNumber("组装单","组合件", pid, materialId, monthTime, true) - .subtract(assembleNumber("组装单","普通子件", pid, materialId, monthTime, true)) - .add(assembleNumber("拆卸单","普通子件", pid, materialId, monthTime, true)) - .subtract(assembleNumber("拆卸单","组合件", pid, materialId, monthTime, true)); - BigDecimal notPrevAssembleSum = assembleNumber("组装单","组合件", pid, materialId, monthTime, false) - .subtract(assembleNumber("组装单","普通子件", pid, materialId, monthTime, false)) - .add(assembleNumber("拆卸单","普通子件", pid, materialId, monthTime, false)) - .subtract(assembleNumber("拆卸单","组合件", pid, materialId, monthTime, false)); - item.put("MaterialId", di.getMaterialid() == null ? "" : di.getMaterialid()); - item.put("MaterialName", di.getMname()); - item.put("MaterialModel", di.getMmodel()); - item.put("thisSum", prevSum.add(InSum).subtract(OutSum).add(prevAssembleSum).add(notPrevAssembleSum)); - dataArray.add(item); - } - } - objectMap.put("page", dataArray); - if (list == null) { - queryInfo.setRows(new ArrayList()); - queryInfo.setTotal(BusinessConstants.DEFAULT_LIST_NULL_NUMBER); - return returnJson(objectMap, "查找不到数据", ErpInfo.OK.code); - } - queryInfo.setRows(list); - queryInfo.setTotal(depotItemService.findStockNumByMaterialIdCounts(parameterMap)); - return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code); - } - - /** - * 保存明细 - * @param inserted - * @param deleted - * @param updated - * @param headerId - * @param request - * @return - */ - @PostMapping(value = "/saveDetials") - public String saveDetials(@RequestParam("inserted") String inserted, - @RequestParam("deleted") String deleted, - @RequestParam("updated") String updated, - @RequestParam("headerId") Long headerId, - HttpServletRequest request) throws Exception{ - Map objectMap = new HashMap(); + BaseResponseInfo res = new BaseResponseInfo(); + Map map = new HashMap(); try { - depotItemService.saveDetials(inserted,deleted,updated,headerId); - return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code); - } catch (DataAccessException e) { + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); + map.put("stock", depotItemService.getStockByParam(depotId,mId,null,null,tenantId)); + res.code = 200; + res.data = map; + } catch (Exception e) { e.printStackTrace(); - logger.error(">>>>>>>>>>>>>>>>>>>保存明细信息异常", e); - return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code); + res.code = 500; + res.data = "获取数据失败"; } + return res; } /** @@ -205,10 +142,11 @@ public class DepotItemController { HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); try { List dataList = new ArrayList(); if(headerId != 0) { - dataList = depotItemService.getDetailList(headerId); + dataList = depotItemService.getDetailList(headerId); } String[] mpArr = mpList.split(","); JSONObject outer = new JSONObject(); @@ -233,9 +171,7 @@ public class DepotItemController { String materialOther = getOtherInfo(mpArr, diEx); MaterialName = MaterialName + materialOther + ((diEx.getUName() == null || diEx.getUName().equals("")) ? "" : "(" + diEx.getUName() + ")") + ratio; item.put("MaterialName", MaterialName == null ? "" : MaterialName); - int inSum = depotItemService.findByTypeAndMaterialIdAndDepotId("入库", diEx.getMaterialid(), diEx.getDepotid()); - int outSum = depotItemService.findByTypeAndMaterialIdAndDepotId("出库", diEx.getMaterialid(), diEx.getDepotid()); - item.put("Stock", inSum-outSum); + item.put("Stock", depotItemService.getStockByParam(diEx.getDepotid(),diEx.getMaterialid(),null,null,tenantId)); item.put("Unit", diEx.getMunit()); item.put("OperNumber", diEx.getOpernumber()); item.put("BasicNumber", diEx.getBasicnumber()); @@ -320,7 +256,7 @@ public class DepotItemController { @PostMapping(value = "/findByAll") public BaseResponseInfo findByAll(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize, - @RequestParam("projectId") Integer projectId, + @RequestParam("depotId") Long depotId, @RequestParam("monthTime") String monthTime, @RequestParam("headIds") String headIds, @RequestParam("materialIds") String materialIds, @@ -328,20 +264,20 @@ public class DepotItemController { HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); try { List dataList = depotItemService.findByAll(headIds, materialIds, (currentPage-1)*pageSize, pageSize); String[] mpArr = mpList.split(","); int total = depotItemService.findByAllCount(headIds, materialIds); map.put("total", total); //存放数据json数组 - Integer pid = projectId; JSONArray dataArray = new JSONArray(); if (null != dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) { JSONObject item = new JSONObject(); - BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true)); - BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false); - BigDecimal OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false); + Long mId = diEx.getMId(); + String timeA = monthTime+"-01 00:00:00"; + String timeB = monthTime+"-31 23:59:59"; item.put("MaterialName", diEx.getMName()); item.put("MaterialModel", diEx.getMModel()); //扩展信息 @@ -350,10 +286,10 @@ public class DepotItemController { item.put("MaterialColor", diEx.getMColor()); item.put("unitName", getUName(diEx.getMaterialUnit(), diEx.getUName())); item.put("UnitPrice", getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy())); - item.put("prevSum", prevSum); - item.put("InSum", InSum); - item.put("OutSum", OutSum); - BigDecimal thisSum = prevSum.add(InSum).subtract(OutSum); + item.put("prevSum", depotItemService.getStockByParam(depotId,mId,null,timeA,tenantId)); + item.put("InSum", depotItemService.getInNumByParam(depotId,mId,timeA,timeB,tenantId)); + item.put("OutSum", depotItemService.getOutNumByParam(depotId,mId,timeA,timeB,tenantId)); + BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,null,tenantId); item.put("thisSum", thisSum); item.put("thisAllPrice", thisSum.multiply(getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy()))); dataArray.add(item); @@ -370,6 +306,60 @@ public class DepotItemController { return res; } + + /** + * 导出excel表格 + * @param currentPage + * @param pageSize + * @param projectId + * @param monthTime + * @param headIds + * @param materialIds + * @param request + * @param response + * @return + */ + @GetMapping(value = "/exportExcel") + public void exportExcel(@RequestParam("currentPage") Integer currentPage, + @RequestParam("pageSize") Integer pageSize, + @RequestParam("depotId") Long depotId, + @RequestParam("monthTime") String monthTime, + @RequestParam("headIds") String headIds, + @RequestParam("materialIds") String materialIds, + HttpServletRequest request, HttpServletResponse response) { + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); + try { + List dataList = depotItemService.findByAll(headIds, materialIds, (currentPage-1)*pageSize, pageSize); + //存放数据json数组 + String[] names = {"名称", "型号", "单位", "单价", "上月结存数量", "入库数量", "出库数量", "本月结存数量", "结存金额"}; + String title = "库存报表"; + List objects = new ArrayList(); + if (null != dataList) { + for (DepotItemVo4WithInfoEx diEx : dataList) { + Long mId = diEx.getMId(); + String timeA = monthTime+"-01 00:00:00"; + String timeB = monthTime+"-31 23:59:59"; + String[] objs = new String[9]; + objs[0] = diEx.getMName().toString(); + objs[1] = diEx.getMModel().toString(); + objs[2] = diEx.getMaterialUnit().toString(); + objs[3] = getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy()).toString(); + objs[4] = depotItemService.getStockByParam(depotId,mId,null,timeA,tenantId).toString(); + objs[5] = depotItemService.getInNumByParam(depotId,mId,timeA,timeB,tenantId).toString(); + objs[6] = depotItemService.getOutNumByParam(depotId,mId,timeA,timeB,tenantId).toString(); + BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,null,tenantId); + objs[7] = thisSum.toString(); + objs[8] = thisSum.multiply(getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy())).toString(); + objects.add(objs); + } + } + File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects); + ExportExecUtil.showExec(file, file.getName() + "-" + monthTime, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * 统计总计金额 * @param pid @@ -380,22 +370,23 @@ public class DepotItemController { * @return */ @PostMapping(value = "/totalCountMoney") - public BaseResponseInfo totalCountMoney(@RequestParam("projectId") Integer pid, + public BaseResponseInfo totalCountMoney(@RequestParam("depotId") Long depotId, @RequestParam("monthTime") String monthTime, @RequestParam("headIds") String headIds, @RequestParam("materialIds") String materialIds, HttpServletRequest request) throws Exception{ BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); + Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString()); try { List dataList = depotItemService.findByAll(headIds, materialIds, null, null); BigDecimal thisAllPrice = BigDecimal.ZERO; if (null != dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) { - BigDecimal prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true).subtract(sumPrice("出库", pid, diEx.getMId(), monthTime, true)); - BigDecimal InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false); - BigDecimal OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false); - thisAllPrice = thisAllPrice .add(prevPrice.add(InPrice).subtract(OutPrice)); + Long mId = diEx.getMId(); + BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,null,tenantId); + BigDecimal unitPrice = getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy()); + thisAllPrice = thisAllPrice.add(thisSum.multiply(unitPrice)); } } map.put("totalCount", thisAllPrice); @@ -440,10 +431,10 @@ public class DepotItemController { if (null != dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) { JSONObject item = new JSONObject(); - BigDecimal InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMId(), monthTime); - BigDecimal OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime); - BigDecimal InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMId(), monthTime); - BigDecimal OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime); + BigDecimal InSum = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), monthTime, "number"); + BigDecimal OutSum = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), monthTime, "number"); + BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), monthTime, "price"); + BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), monthTime, "price"); item.put("MaterialName", diEx.getMName()); item.put("MaterialModel", diEx.getMModel()); //扩展信息 @@ -501,14 +492,14 @@ public class DepotItemController { if (null != dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) { JSONObject item = new JSONObject(); - BigDecimal OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMId(), monthTime); - BigDecimal OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMId(), monthTime); - BigDecimal InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime); - BigDecimal InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime); - BigDecimal OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMId(), monthTime); - BigDecimal OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMId(), monthTime); - BigDecimal InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime); - BigDecimal InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime); + BigDecimal OutSumRetail = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), monthTime,"number"); + BigDecimal OutSum = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), monthTime,"number"); + BigDecimal InSumRetail = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), monthTime,"number"); + BigDecimal InSum = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), monthTime,"number"); + BigDecimal OutSumRetailPrice = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), monthTime,"price"); + BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), monthTime,"price"); + BigDecimal InSumRetailPrice = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), monthTime,"price"); + BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), monthTime,"price"); BigDecimal OutInSumPrice = (OutSumRetailPrice.add(OutSumPrice)).subtract(InSumRetailPrice.add(InSumPrice)); item.put("MaterialName", diEx.getMName()); item.put("MaterialModel", diEx.getMModel()); @@ -537,157 +528,6 @@ public class DepotItemController { return res; } - /** - * 导出excel表格 - * @param currentPage - * @param pageSize - * @param projectId - * @param monthTime - * @param headIds - * @param materialIds - * @param request - * @param response - * @return - */ - @GetMapping(value = "/exportExcel") - public void exportExcel(@RequestParam("currentPage") Integer currentPage, - @RequestParam("pageSize") Integer pageSize, - @RequestParam("projectId") Integer projectId, - @RequestParam("monthTime") String monthTime, - @RequestParam("headIds") String headIds, - @RequestParam("materialIds") String materialIds, - HttpServletRequest request, HttpServletResponse response) { - try { - List dataList = depotItemService.findByAll(headIds, materialIds, (currentPage-1)*pageSize, pageSize); - //存放数据json数组 - Integer pid = projectId; - String[] names = {"名称", "型号", "单位", "单价", "上月结存数量", "入库数量", "出库数量", "本月结存数量", "结存金额"}; - String title = "库存报表"; - List objects = new ArrayList(); - if (null != dataList) { - for (DepotItemVo4WithInfoEx diEx : dataList) { - String[] objs = new String[9]; - BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true)); - BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false); - BigDecimal OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false); - BigDecimal prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true).subtract(sumPrice("出库", pid, diEx.getMId(), monthTime, true)); - BigDecimal InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false); - BigDecimal OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false); - BigDecimal unitPrice = BigDecimal.ZERO; - if ((prevSum.add(InSum).subtract(OutSum)).compareTo(BigDecimal.ZERO) != 0) { - unitPrice = (prevPrice.add(InPrice).subtract(OutPrice)).divide(prevSum.add(InSum).subtract(OutSum),2, BigDecimal.ROUND_HALF_UP); - /** - * 2019-01-15通过除法算出金额后,保留两位小数 - * */ - DecimalFormat df = new DecimalFormat("#.00"); - unitPrice= new BigDecimal(df.format(unitPrice)); - } - BigDecimal thisSum = prevSum.add(InSum).subtract(OutSum); - BigDecimal thisAllPrice = prevPrice.add(InPrice).subtract(OutPrice); - objs[0] = diEx.getMName().toString(); - objs[1] = diEx.getMModel().toString(); - objs[2] = diEx.getMaterialUnit().toString(); - objs[3] = unitPrice.toString(); - objs[4] = prevSum.toString(); - objs[5] = InSum.toString(); - objs[6] = OutSum.toString(); - objs[7] = thisSum.toString(); - objs[8] = thisAllPrice.toString(); - objects.add(objs); - } - } - File file = ExcelUtils.exportObjectsWithoutTitle(title, names, title, objects); - ExportExecUtil.showExec(file, file.getName() + "-" + monthTime, response); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * 数量合计 - * - * @param type - * @param MId - * @param MonthTime - * @param isPrev - * @return - */ - public BigDecimal sumNumber(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev)throws Exception { - BigDecimal sumNumber = BigDecimal.ZERO; - try { - BigDecimal sum = depotItemService.findByType(type, ProjectId, MId, MonthTime, isPrev); - if(sum != null) { - sumNumber = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - return sumNumber; - } - - public BigDecimal assembleNumber(String subType, String mType, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) throws Exception{ - BigDecimal assembleNumber = BigDecimal.ZERO; - try { - BigDecimal sum = depotItemService.findAssembleByType(subType, mType, ProjectId, MId, MonthTime, isPrev); - if(sum != null) { - assembleNumber = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - return assembleNumber; - } - - /** - * 价格合计 - * - * @param type - * @param MId - * @param MonthTime - * @param isPrev - * @return - */ - public BigDecimal sumPrice(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) throws Exception{ - BigDecimal sumPrice = BigDecimal.ZERO; - try { - BigDecimal sum = depotItemService.findPriceByType(type, ProjectId, MId, MonthTime, isPrev); - if(sum != null) { - sumPrice = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - return sumPrice; - } - - public BigDecimal sumNumberBuyOrSale(String type, String subType, Long MId, String MonthTime)throws Exception { - BigDecimal sumNumber = BigDecimal.ZERO; - String sumType = "Number"; - try { - BigDecimal sum = depotItemService.buyOrSale(type, subType, MId, MonthTime, sumType); - if(sum != null) { - sumNumber = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - return sumNumber; - } - - public BigDecimal sumPriceBuyOrSale(String type, String subType, Long MId, String MonthTime)throws Exception { - BigDecimal sumPrice = BigDecimal.ZERO; - String sumType = "Price"; - try { - BigDecimal sum = depotItemService.buyOrSale(type, subType, MId, MonthTime, sumType); - if(sum != null) { - sumPrice = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - return sumPrice; - } - /** * 获取单位 * @param materialUnit @@ -803,7 +643,6 @@ public class DepotItemController { if (null != dataList) { for (DepotItemStockWarningCount diEx : dataList) { String[] objs = new String[9]; - objs[0] = diEx.getMaterialName().toString(); objs[1] = diEx.getMaterialModel().toString(); objs[2] = diEx.getMaterialOther().toString(); diff --git a/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java b/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java index 8ff20f2d..12997d77 100644 --- a/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java +++ b/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java @@ -2,6 +2,7 @@ package com.jsh.erp.datasource.mappers; import com.jsh.erp.datasource.entities.*; import com.jsh.erp.datasource.vo.DepotItemStockWarningCount; +import com.jsh.erp.datasource.vo.DepotItemVo4Stock; import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; @@ -35,30 +36,12 @@ public interface DepotItemMapperEx { Long findDetailByTypeAndMaterialIdCounts( @Param("mId") Long mId); - List findStockNumByMaterialIdList( - @Param("mId") Long mId, - @Param("monthTime") String monthTime, - @Param("offset") Integer offset, - @Param("rows") Integer rows); - - Long findStockNumByMaterialIdCounts( - @Param("mId") Long mId, - @Param("monthTime") String monthTime); - Long findByTypeAndMaterialIdIn( @Param("mId") Long mId); Long findByTypeAndMaterialIdOut( @Param("mId") Long mId); - int findByTypeAndDepotIdAndMaterialIdIn( - @Param("depotId") Long depotId, - @Param("mId") Long mId); - - int findByTypeAndDepotIdAndMaterialIdOut( - @Param("depotId") Long depotId, - @Param("mId") Long mId); - List getDetailList( @Param("headerId") Long headerId); @@ -72,62 +55,6 @@ public interface DepotItemMapperEx { @Param("headIds") String headIds, @Param("materialIds") String materialIds); - BigDecimal findByTypeInIsPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findByTypeInIsNotPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findByTypeOutIsPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findByTypeOutIsNotPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - - - BigDecimal findPriceByTypeInIsPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findPriceByTypeInIsNotPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findPriceByTypeOutIsPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findPriceByTypeOutIsNotPrev( - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findAssembleIsPrev( - @Param("subType") String subType, - @Param("mType") String mType, - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - - BigDecimal findAssembleIsNotPrev( - @Param("subType") String subType, - @Param("mType") String mType, - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId, - @Param("MonthTime") String MonthTime); - BigDecimal buyOrSaleNumber( @Param("type") String type, @Param("subType") String subType, @@ -142,15 +69,13 @@ public interface DepotItemMapperEx { @Param("MonthTime") String MonthTime, @Param("sumType") String sumType); - BigDecimal findGiftByTypeIn( - @Param("subType") String subType, - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId); + DepotItemVo4Stock getStockByParam( + @Param("depotId") Long depotId, + @Param("mId") Long mId, + @Param("beginTime") String beginTime, + @Param("endTime") String endTime, + @Param("tenantId") Long tenantId); - BigDecimal findGiftByTypeOut( - @Param("subType") String subType, - @Param("ProjectId") Integer ProjectId, - @Param("MId") Long MId); /** * create by: cjl * description: diff --git a/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java b/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java new file mode 100644 index 00000000..cea9c520 --- /dev/null +++ b/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java @@ -0,0 +1,26 @@ +package com.jsh.erp.datasource.vo; + + +import java.math.BigDecimal; + +public class DepotItemVo4Stock { + + private BigDecimal inNum; + private BigDecimal outNum; + + public BigDecimal getInNum() { + return inNum; + } + + public void setInNum(BigDecimal inNum) { + this.inNum = inNum; + } + + public BigDecimal getOutNum() { + return outNum; + } + + public void setOutNum(BigDecimal outNum) { + this.outNum = outNum; + } +} diff --git a/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java b/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java index 14336020..0177ffbf 100644 --- a/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java +++ b/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java @@ -469,7 +469,7 @@ public class DepotHeadService { * @return java.lang.String */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public void addDepotHeadAndDetail(String beanJson, String inserted, String deleted, String updated) throws Exception { + public void addDepotHeadAndDetail(String beanJson, String inserted, String deleted, String updated,Long tenantId) throws Exception { logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_DEPOT_HEAD, BusinessConstants.LOG_OPERATION_TYPE_ADD, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); @@ -494,7 +494,7 @@ public class DepotHeadService { } } /**入库和出库处理单据子表信息*/ - depotItemService.saveDetials(inserted,deleted,updated,depotHead.getId()); + depotItemService.saveDetials(inserted,deleted,updated,depotHead.getId(),tenantId); /**如果关联单据号非空则更新订单的状态为2 */ if(depotHead.getLinknumber()!=null) { DepotHead depotHeadOrders = new DepotHead(); @@ -522,7 +522,8 @@ public class DepotHeadService { * @return java.lang.Object */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public void updateDepotHeadAndDetail(Long id, String beanJson, String inserted, String deleted, String updated, BigDecimal preTotalPrice)throws Exception { + public void updateDepotHeadAndDetail(Long id, String beanJson, String inserted, String deleted, String updated, + BigDecimal preTotalPrice, Long tenantId)throws Exception { logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_DEPOT_HEAD, new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(id).toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); @@ -545,7 +546,7 @@ public class DepotHeadService { } } /**入库和出库处理单据子表信息*/ - depotItemService.saveDetials(inserted,deleted,updated,depotHead.getId()); + depotItemService.saveDetials(inserted,deleted,updated,depotHead.getId(),tenantId); } /** diff --git a/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java b/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java index 8368dbfd..c5ae239e 100644 --- a/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java +++ b/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java @@ -10,6 +10,7 @@ import com.jsh.erp.datasource.mappers.DepotItemMapper; import com.jsh.erp.datasource.mappers.DepotItemMapperEx; import com.jsh.erp.datasource.mappers.SerialNumberMapperEx; import com.jsh.erp.datasource.vo.DepotItemStockWarningCount; +import com.jsh.erp.datasource.vo.DepotItemVo4Stock; import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.JshException; import com.jsh.erp.service.log.LogService; @@ -192,38 +193,6 @@ public class DepotItemService { return result; } - public List findStockNumByMaterialIdList(Map map)throws Exception { - String mIdStr = map.get("mId"); - Long mId = null; - if(!StringUtil.isEmpty(mIdStr)) { - mId = Long.parseLong(mIdStr); - } - String monthTime = map.get("monthTime"); - List list =null; - try{ - list = depotItemMapperEx.findStockNumByMaterialIdList(mId, monthTime, QueryUtils.offset(map), QueryUtils.rows(map)); - }catch(Exception e){ - JshException.readFail(logger, e); - } - return list; - } - - public Long findStockNumByMaterialIdCounts(Map map)throws Exception { - String mIdStr = map.get("mId"); - Long mId = null; - if(!StringUtil.isEmpty(mIdStr)) { - mId = Long.parseLong(mIdStr); - } - String monthTime = map.get("monthTime"); - Long result =null; - try{ - result = depotItemMapperEx.findStockNumByMaterialIdCounts(mId, monthTime); - }catch(Exception e){ - JshException.readFail(logger, e); - } - return result; - } - @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int insertDepotItemWithObj(DepotItem depotItem)throws Exception { int result =0; @@ -260,14 +229,6 @@ public class DepotItemService { return result; } - public int findByTypeAndMaterialIdAndDepotId(String type, Long mId, Long depotId) { - if(type.equals(TYPE)) { - return depotItemMapperEx.findByTypeAndDepotIdAndMaterialIdIn(depotId, mId); - } else { - return depotItemMapperEx.findByTypeAndDepotIdAndMaterialIdOut(depotId, mId); - } - } - public List getDetailList(Long headerId)throws Exception { List list =null; try{ @@ -298,69 +259,8 @@ public class DepotItemService { return result; } - public BigDecimal findByType(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev)throws Exception { - BigDecimal result=null; - try{ - if (TYPE.equals(type)) { - if (isPrev) { - result= depotItemMapperEx.findByTypeInIsPrev(ProjectId, MId, MonthTime); - } else { - result= depotItemMapperEx.findByTypeInIsNotPrev(ProjectId, MId, MonthTime); - } - } else { - if (isPrev) { - result= depotItemMapperEx.findByTypeOutIsPrev(ProjectId, MId, MonthTime); - } else { - result= depotItemMapperEx.findByTypeOutIsNotPrev(ProjectId, MId, MonthTime); - } - } - }catch(Exception e){ - JshException.readFail(logger, e); - } - return result; - - } - - public BigDecimal findPriceByType(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev)throws Exception { - BigDecimal result=null; - try{ - if (TYPE.equals(type)) { - if (isPrev) { - result= depotItemMapperEx.findPriceByTypeInIsPrev(ProjectId, MId, MonthTime); - } else { - result= depotItemMapperEx.findPriceByTypeInIsNotPrev(ProjectId, MId, MonthTime); - } - } else { - if (isPrev) { - result= depotItemMapperEx.findPriceByTypeOutIsPrev(ProjectId, MId, MonthTime); - } else { - result= depotItemMapperEx.findPriceByTypeOutIsNotPrev(ProjectId, MId, MonthTime); - } - } - }catch(Exception e){ - JshException.readFail(logger, e); - } - return result; - - } - - public BigDecimal findAssembleByType(String subType, String mType, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev)throws Exception { - BigDecimal result=null; - try{ - if (isPrev) { - result= depotItemMapperEx.findAssembleIsPrev(subType, mType, ProjectId, MId, MonthTime); - } else { - result= depotItemMapperEx.findAssembleIsNotPrev(subType, mType, ProjectId, MId, MonthTime); - } - }catch(Exception e){ - JshException.readFail(logger, e); - } - return result; - - } - public BigDecimal buyOrSale(String type, String subType, Long MId, String MonthTime, String sumType) throws Exception{ - BigDecimal result=null; + BigDecimal result= BigDecimal.ZERO; try{ if (SUM_TYPE.equals(sumType)) { result= depotItemMapperEx.buyOrSaleNumber(type, subType, MId, MonthTime, sumType); @@ -380,7 +280,7 @@ public class DepotItemService { * 这里重点重申一下:BasicNumber=OperNumber*ratio * */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public String saveDetials(String inserted, String deleted, String updated, Long headerId) throws Exception{ + public String saveDetials(String inserted, String deleted, String updated, Long headerId, Long tenantId) throws Exception{ logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_DEPOT_ITEM, BusinessConstants.LOG_OPERATION_TYPE_ADD, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); @@ -525,12 +425,14 @@ public class DepotItemService { if(material==null){ continue; } - if(getCurrentInStock(depotItem.getMaterialid(),depotItem.getDepotid())<(depotItem.getBasicnumber()==null?0:depotItem.getBasicnumber()).intValue()){ + BigDecimal stock = getStockByParam(depotItem.getDepotid(),depotItem.getMaterialid(),null,null,tenantId); + BigDecimal thisBasicNumber = depotItem.getBasicnumber()==null?BigDecimal.ZERO:depotItem.getBasicnumber(); + if(stock.compareTo(thisBasicNumber)<0){ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE, String.format(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_MSG,material==null?"":material.getName())); } - /**出库时处理序列号*/ + /**出库时处理序列号*/ if(!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())) { /** * 判断商品是否开启序列号,开启的收回序列号,未开启的跳过 @@ -648,14 +550,16 @@ public class DepotItemService { } /**出库时处理序列号*/ if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){ - if(getCurrentInStock(depotItem.getMaterialid(),depotItem.getDepotid())<(depotItem.getBasicnumber()==null?0:depotItem.getBasicnumber()).intValue()){ + BigDecimal stock = getStockByParam(depotItem.getDepotid(),depotItem.getMaterialid(),null,null,tenantId); + BigDecimal thisBasicNumber = depotItem.getBasicnumber()==null?BigDecimal.ZERO:depotItem.getBasicnumber(); + if(stock.compareTo(thisBasicNumber)<0){ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE, String.format(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_MSG,material==null?"":material.getName())); } if(!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())) { - /** - * 判断商品是否开启序列号,开启的收回序列号,未开启的跳过 - * */ + /** + * 判断商品是否开启序列号,开启的收回序列号,未开启的跳过 + * */ if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableserialnumber())) { //查询单据子表中开启序列号的数据列表 serialNumberService.checkAndUpdateSerialNumber(depotItem, userInfo); @@ -687,17 +591,7 @@ public class DepotItemService { } return unitName; } - /** - * 查询商品当前库存数量是否充足, - * - * */ - public int getCurrentInStock(Long materialId, Long depotId){ - //入库数量 - int inSum = findByTypeAndMaterialIdAndDepotId(BusinessConstants.DEPOTHEAD_TYPE_STORAGE, materialId, depotId); - //出库数量 - int outSum = findByTypeAndMaterialIdAndDepotId(BusinessConstants.DEPOTHEAD_TYPE_OUT, materialId ,depotId); - return (inSum-outSum); - } + @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int batchDeleteDepotItemByIds(String ids)throws Exception { logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_DEPOT_ITEM, @@ -749,4 +643,45 @@ public class DepotItemService { BigDecimal count = depotItemMapperEx.getFinishNumber(mid, linkNumber); return count; } + + /** + * 库存统计 + * @param depotId + * @param mId + * @param beginTime + * @param endTime + * @return + */ + public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){ + DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId); + BigDecimal intNum = stockObj.getInNum(); + BigDecimal outNum = stockObj.getOutNum(); + return intNum.subtract(outNum); + } + + /** + * 入库统计 + * @param depotId + * @param mId + * @param beginTime + * @param endTime + * @return + */ + public BigDecimal getInNumByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){ + DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId); + return stockObj.getInNum(); + } + + /** + * 出库统计 + * @param depotId + * @param mId + * @param beginTime + * @param endTime + * @return + */ + public BigDecimal getOutNumByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){ + DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId); + return stockObj.getOutNum(); + } } diff --git a/src/main/resources/mapper_xml/DepotItemMapperEx.xml b/src/main/resources/mapper_xml/DepotItemMapperEx.xml index c6568ef4..0e48c137 100644 --- a/src/main/resources/mapper_xml/DepotItemMapperEx.xml +++ b/src/main/resources/mapper_xml/DepotItemMapperEx.xml @@ -53,6 +53,11 @@ + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + select ifnull((curep.inTotal+curep.transfInTotal+curep.assemInTotal+curep.disAssemInTotal),0) as in_stock, + ifnull((curep.transfOutTotal+curep.outTotal+curep.assemOutTotal+curep.disAssemOutTotal),0) out_stock + from + (select sum(if(dh.type='入库' and di.DepotId=#{depotId}, di.BasicNumber,0)) as inTotal, + sum(if(dh.SubType='调拨' and di.AnotherDepotId=#{depotId},di.BasicNumber,0)) as transfInTotal, + sum(if(dh.SubType='调拨' and di.DepotId=#{depotId},di.BasicNumber,0)) as transfOutTotal, + sum(if(dh.type='出库' and dh.SubType!='调拨' and di.DepotId=#{depotId},di.BasicNumber,0)) as outTotal, + sum(if(dh.SubType='组装单' and di.MType='组合件' and di.DepotId=#{depotId},di.BasicNumber,0)) as assemInTotal, + sum(if(dh.SubType='组装单' and di.MType='普通子件' and di.DepotId=#{depotId},di.BasicNumber,0)) as assemOutTotal, + sum(if(dh.SubType='拆卸单' and di.MType='普通子件' and di.DepotId=#{depotId},di.BasicNumber,0)) as disAssemInTotal, + sum(if(dh.SubType='拆卸单' and di.MType='组合件' and di.DepotId=#{depotId},di.BasicNumber,0)) as disAssemOutTotal + from + jsh_depothead dh,jsh_depotitem di + where 1=1 + and dh.id=di.HeaderId + and di.MaterialId=#{mId} + + and dh.OperTime >= '${beginTime}' + + + and dh.OperTime <= '${endTime}' + + and dh.tenant_id=#{tenantId} + and di.tenant_id=#{tenantId} and ifnull(dh.delete_Flag,'0') !='1' - and ifnull(di.delete_Flag,'0') !='1' - - -