diff --git a/jshERP-boot/docs/jsh_erp.sql b/jshERP-boot/docs/jsh_erp.sql index 0ce09c08..88ead849 100644 --- a/jshERP-boot/docs/jsh_erp.sql +++ b/jshERP-boot/docs/jsh_erp.sql @@ -428,7 +428,7 @@ CREATE TABLE `jsh_material_attribute` ( `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id', `delete_flag` varchar(1) DEFAULT '0' COMMENT '删除标记,0未删除,1删除', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='产品属性'; +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='产品属性表'; -- ---------------------------- -- Records of jsh_material_attribute diff --git a/jshERP-boot/docs/华夏ERP数据库设计汇总.xlsx b/jshERP-boot/docs/华夏ERP数据库设计汇总.xlsx index 71732087..75cfdc90 100644 Binary files a/jshERP-boot/docs/华夏ERP数据库设计汇总.xlsx and b/jshERP-boot/docs/华夏ERP数据库设计汇总.xlsx differ diff --git a/jshERP-boot/docs/数据库更新记录-首次安装请勿使用.txt b/jshERP-boot/docs/数据库更新记录-首次安装请勿使用.txt index 681862c8..c28ec117 100644 --- a/jshERP-boot/docs/数据库更新记录-首次安装请勿使用.txt +++ b/jshERP-boot/docs/数据库更新记录-首次安装请勿使用.txt @@ -1141,7 +1141,7 @@ CREATE TABLE `jsh_material_attribute` ( `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id', `delete_flag` varchar(1) DEFAULT '0' COMMENT '删除标记,0未删除,1删除', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='产品属性'; +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='产品属性表'; INSERT INTO `jsh_material_attribute` VALUES ('1', 'manyColor', '颜色', '红色|橙色|黄色|绿色|蓝色|紫色', '63', '0'); INSERT INTO `jsh_material_attribute` VALUES ('2', 'manySize', '尺寸', 'S|M|L|XL|XXL|XXXL', '63', '0'); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/config/TenantConfig.java b/jshERP-boot/src/main/java/com/jsh/erp/config/TenantConfig.java index 0e51583c..6e55ff47 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/config/TenantConfig.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/config/TenantConfig.java @@ -73,8 +73,7 @@ public class TenantConfig { public boolean doFilter(MetaObject metaObject) { MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject); // 过滤自定义查询此时无租户信息约束出现 - if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())|| - "com.jsh.erp.datasource.mappers.DepotItemMapperEx.getStockByParam".equals(ms.getId())) { + if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) { return true; } return false; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java index 2bb2fd86..be7a4213 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java @@ -270,13 +270,12 @@ public class DepotHeadController { String beanJson = body.getInfo(); String rows = body.getRows(); Long billsNumLimit = Long.parseLong(redisService.getObjectFromSessionByKey(request,"billsNumLimit").toString()); - Long tenantId = redisService.getTenantId(request); Long count = depotHeadService.countDepotHead(null,null,null,null,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,rows,tenantId, request); + depotHeadService.addDepotHeadAndDetail(beanJson,rows, request); } return result; } @@ -290,11 +289,10 @@ public class DepotHeadController { */ @PutMapping(value = "/updateDepotHeadAndDetail") public Object updateDepotHeadAndDetail(@RequestBody DepotHeadVo4Body body, HttpServletRequest request) throws Exception{ - Long tenantId = redisService.getTenantId(request); JSONObject result = ExceptionConstants.standardSuccess(); String beanJson = body.getInfo(); String rows = body.getRows(); - depotHeadService.updateDepotHeadAndDetail(beanJson,rows,tenantId,request); + depotHeadService.updateDepotHeadAndDetail(beanJson,rows,request); return result; } 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 16e7fc69..ddf5e2ec 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 @@ -118,11 +118,10 @@ public class DepotItemController { Map map = new HashMap(); try { BigDecimal stock = BigDecimal.ZERO; - Long tenantId = redisService.getTenantId(request); List list = materialService.getMaterialByBarCode(barCode); if(list!=null && list.size()>0) { MaterialVo4Unit materialVo4Unit = list.get(0); - stock = depotItemService.getStockByParam(depotId,materialVo4Unit.getId(),null,null,tenantId); + stock = depotItemService.getStockByParam(depotId,materialVo4Unit.getId(),null,null); String commodityUnit = materialVo4Unit.getCommodityUnit(); Long unitId = materialVo4Unit.getUnitId(); if(unitId!=null) { @@ -152,7 +151,6 @@ public class DepotItemController { @RequestParam("mpList") String mpList, HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); - Long tenantId = redisService.getTenantId(request); try { List dataList = new ArrayList(); if(headerId != 0) { @@ -173,7 +171,7 @@ public class DepotItemController { item.put("model", diEx.getMModel()); item.put("materialOther", getOtherInfo(mpArr, diEx)); Integer ratio = diEx.getRatio(); - BigDecimal stock = depotItemService.getStockByParam(diEx.getDepotId(),diEx.getMaterialId(),null,null,tenantId); + BigDecimal stock = depotItemService.getStockByParam(diEx.getDepotId(),diEx.getMaterialId(),null,null); if(ratio!=null){ BigDecimal ratioDecimal = new BigDecimal(ratio.toString()); if(ratioDecimal.compareTo(BigDecimal.ZERO)!=0){ @@ -262,7 +260,6 @@ public class DepotItemController { HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); - Long tenantId = redisService.getTenantId(request); String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME; String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; try { @@ -292,10 +289,10 @@ public class DepotItemController { item.put("materialColor", diEx.getMColor()); item.put("unitName", getUName(diEx.getMaterialUnit(), diEx.getUnitName())); - 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,timeB,tenantId); + 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); item.put("thisSum", thisSum); for(MaterialExtend me:meList) { if(me.getMaterialId().longValue() == diEx.getMId().longValue()) { @@ -333,7 +330,6 @@ public class DepotItemController { @RequestParam("monthTime") String monthTime, @RequestParam("materialParam") String materialParam, HttpServletRequest request, HttpServletResponse response) throws Exception { - Long tenantId = redisService.getTenantId(request); String timeA = Tools.firstDayOfMonth(monthTime) + BusinessConstants.DAY_FIRST_TIME; String timeB = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; try { @@ -353,10 +349,10 @@ public class DepotItemController { objs[3] = diEx.getMModel(); objs[4] = diEx.getMaterialUnit(); objs[5] = diEx.getPurchaseDecimal().toString(); - objs[6] = depotItemService.getStockByParam(depotId,mId,null,timeA,tenantId).toString(); - objs[7] = depotItemService.getInNumByParam(depotId,mId,timeA,timeB,tenantId).toString(); - objs[8] = depotItemService.getOutNumByParam(depotId,mId,timeA,timeB,tenantId).toString(); - BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,timeB,tenantId); + objs[6] = depotItemService.getStockByParam(depotId,mId,null,timeA).toString(); + objs[7] = depotItemService.getInNumByParam(depotId,mId,timeA,timeB).toString(); + objs[8] = depotItemService.getOutNumByParam(depotId,mId,timeA,timeB).toString(); + BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,timeB); objs[9] = thisSum.toString(); objs[10] = thisSum.multiply(diEx.getPurchaseDecimal()).toString(); objects.add(objs); @@ -384,7 +380,6 @@ public class DepotItemController { HttpServletRequest request) throws Exception{ BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); - Long tenantId = redisService.getTenantId(request); String endTime = Tools.lastDayOfMonth(monthTime) + BusinessConstants.DAY_LAST_TIME; try { List dataList = depotItemService.findByAll(StringUtil.toNull(materialParam), @@ -393,7 +388,7 @@ public class DepotItemController { if (null != dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) { Long mId = diEx.getMId(); - BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,endTime,tenantId); + BigDecimal thisSum = depotItemService.getStockByParam(depotId,mId,null,endTime); BigDecimal unitPrice = diEx.getPurchaseDecimal(); if(unitPrice == null) { unitPrice = BigDecimal.ZERO; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java index 42cb936e..25a68a20 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java @@ -169,7 +169,6 @@ public class MaterialController { HttpServletRequest request) throws Exception{ JSONObject object = new JSONObject(); try { - Long tenantId = redisService.getTenantId(request); List dataList = materialService.findBySelectWithBarCode(categoryId, q, (currentPage-1)*pageSize, pageSize); String[] mpArr = mpList.split(","); int total = materialService.findBySelectWithBarCodeCount(categoryId, q); @@ -196,7 +195,11 @@ public class MaterialController { item.put("model", material.getModel()); item.put("unit", material.getCommodityUnit() + ratio); item.put("sku", material.getSku()); - BigDecimal stock = depotItemService.getStockByParam(depotId,material.getId(),null,null,tenantId); + BigDecimal skuStock = depotItemService.getSkuStockByParam(depotId,material.getMeId(),null,null); + if(StringUtil.isNotEmpty(material.getSku())){ + item.put("skuStock", skuStock); + } + BigDecimal stock = depotItemService.getStockByParam(depotId,material.getId(),null,null); if (material.getUnitId()!=null){ Unit unit = unitService.getUnit(material.getUnitId()); if(material.getCommodityUnit().equals(unit.getOtherUnit())) { 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 9347f5ab..5c4fdc8d 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 @@ -77,12 +77,17 @@ public interface DepotItemMapperEx { @Param("beginTime") String beginTime, @Param("endTime") String endTime); + DepotItemVo4Stock getSkuStockByParam( + @Param("depotId") Long depotId, + @Param("meId") Long meId, + @Param("beginTime") String beginTime, + @Param("endTime") String endTime); + DepotItemVo4Stock getStockByParam( @Param("depotId") Long depotId, @Param("mId") Long mId, @Param("beginTime") String beginTime, - @Param("endTime") String endTime, - @Param("tenantId") Long tenantId); + @Param("endTime") String endTime); /** * 通过单据主表id查询所有单据子表数据 diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java index cea9c520..59670501 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotItemVo4Stock.java @@ -5,22 +5,76 @@ import java.math.BigDecimal; public class DepotItemVo4Stock { - private BigDecimal inNum; - private BigDecimal outNum; + private BigDecimal inTotal; + private BigDecimal outTotal; + private BigDecimal transfInTotal; + private BigDecimal transfOutTotal; + private BigDecimal assemInTotal; + private BigDecimal assemOutTotal; + private BigDecimal disAssemInTotal; + private BigDecimal disAssemOutTotal; - public BigDecimal getInNum() { - return inNum; + public BigDecimal getInTotal() { + return inTotal; } - public void setInNum(BigDecimal inNum) { - this.inNum = inNum; + public void setInTotal(BigDecimal inTotal) { + this.inTotal = inTotal; } - public BigDecimal getOutNum() { - return outNum; + public BigDecimal getOutTotal() { + return outTotal; } - public void setOutNum(BigDecimal outNum) { - this.outNum = outNum; + public void setOutTotal(BigDecimal outTotal) { + this.outTotal = outTotal; + } + + public BigDecimal getTransfInTotal() { + return transfInTotal; + } + + public void setTransfInTotal(BigDecimal transfInTotal) { + this.transfInTotal = transfInTotal; + } + + public BigDecimal getTransfOutTotal() { + return transfOutTotal; + } + + public void setTransfOutTotal(BigDecimal transfOutTotal) { + this.transfOutTotal = transfOutTotal; + } + + public BigDecimal getAssemInTotal() { + return assemInTotal; + } + + public void setAssemInTotal(BigDecimal assemInTotal) { + this.assemInTotal = assemInTotal; + } + + public BigDecimal getAssemOutTotal() { + return assemOutTotal; + } + + public void setAssemOutTotal(BigDecimal assemOutTotal) { + this.assemOutTotal = assemOutTotal; + } + + public BigDecimal getDisAssemInTotal() { + return disAssemInTotal; + } + + public void setDisAssemInTotal(BigDecimal disAssemInTotal) { + this.disAssemInTotal = disAssemInTotal; + } + + public BigDecimal getDisAssemOutTotal() { + return disAssemOutTotal; + } + + public void setDisAssemOutTotal(BigDecimal disAssemOutTotal) { + this.disAssemOutTotal = disAssemOutTotal; } } diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java index 3904fd89..9053f656 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java @@ -281,8 +281,7 @@ public class DepotHeadService { //更新当前库存 List list = depotItemService.getListByHeaderId(id); for (DepotItem depotItem : list) { - Long tenantId = redisService.getTenantId(request); - depotItemService.updateCurrentStock(depotItem, tenantId); + depotItemService.updateCurrentStock(depotItem); } /**删除单据主表信息*/ batchDeleteDepotHeadByIds(id.toString()); @@ -611,7 +610,7 @@ public class DepotHeadService { * @throws Exception */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public void addDepotHeadAndDetail(String beanJson, String rows, Long tenantId, + public void addDepotHeadAndDetail(String beanJson, String rows, HttpServletRequest request) throws Exception { /**处理单据主表数据*/ DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class); @@ -668,7 +667,7 @@ public class DepotHeadService { if(list!=null) { Long headId = list.get(0).getId(); /**入库和出库处理单据子表信息*/ - depotItemService.saveDetials(rows,headId,tenantId, request); + depotItemService.saveDetials(rows,headId, request); } /**如果关联单据号非空则更新订单的状态为2 (只操作采购订单和销售订单) */ if(depotHead.getLinkNumber()!=null) { @@ -696,7 +695,7 @@ public class DepotHeadService { * @throws Exception */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public void updateDepotHeadAndDetail(String beanJson, String rows, Long tenantId,HttpServletRequest request)throws Exception { + public void updateDepotHeadAndDetail(String beanJson, String rows,HttpServletRequest request)throws Exception { /**更新单据主表信息*/ DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class); //获取之前的金额数据 @@ -742,7 +741,7 @@ public class DepotHeadService { } } /**入库和出库处理单据子表信息*/ - depotItemService.saveDetials(rows,depotHead.getId(),tenantId,request); + depotItemService.saveDetials(rows,depotHead.getId(),request); logService.insertLog("单据", new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(depotHead.getNumber()).toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); 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 ea64e55c..2640d403 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 @@ -298,7 +298,7 @@ public class DepotItemService { } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public void saveDetials(String rows, Long headerId, Long tenantId, HttpServletRequest request) throws Exception{ + public void saveDetials(String rows, Long headerId, HttpServletRequest request) throws Exception{ //查询单据主表信息 DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(headerId); //获得当前操作人 @@ -398,7 +398,7 @@ public class DepotItemService { if(material==null){ continue; } - BigDecimal stock = getStockByParam(depotItem.getDepotId(),depotItem.getMaterialId(),null,null,tenantId); + BigDecimal stock = getStockByParam(depotItem.getDepotId(),depotItem.getMaterialId(),null,null); BigDecimal thisBasicNumber = depotItem.getBasicNumber()==null?BigDecimal.ZERO:depotItem.getBasicNumber(); if(systemConfigService.getMinusStockFlag() == false && stock.compareTo(thisBasicNumber)<0){ throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE, @@ -415,7 +415,7 @@ public class DepotItemService { } this.insertDepotItemWithObj(depotItem); //更新当前库存 - updateCurrentStock(depotItem,tenantId); + updateCurrentStock(depotItem); } } else { throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_CODE, @@ -455,6 +455,32 @@ public class DepotItemService { return result; } + /** + * 库存统计-sku + * @param depotId + * @param meId + * @param beginTime + * @param endTime + * @return + */ + public BigDecimal getSkuStockByParam(Long depotId, Long meId, String beginTime, String endTime){ + DepotItemVo4Stock stockObj = depotItemMapperEx.getSkuStockByParam(depotId, meId, beginTime, endTime); + BigDecimal stockSum = BigDecimal.ZERO; + if(stockObj!=null) { + BigDecimal inTotal = stockObj.getInTotal(); + BigDecimal transfInTotal = stockObj.getTransfInTotal(); + BigDecimal assemInTotal = stockObj.getAssemInTotal(); + BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal(); + BigDecimal outTotal = stockObj.getOutTotal(); + BigDecimal transfOutTotal = stockObj.getTransfOutTotal(); + BigDecimal assemOutTotal = stockObj.getAssemOutTotal(); + BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal(); + stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal) + .subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal); + } + return stockSum; + } + /** * 库存统计 * @param depotId @@ -463,15 +489,26 @@ public class DepotItemService { * @param endTime * @return */ - public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){ + public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime){ //初始库存 BigDecimal initStock = materialService.getInitStockByMid(depotId, mId); //盘点复盘后数量的变动 BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSum(depotId, mId, beginTime, endTime); - DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId); - BigDecimal intNum = stockObj.getInNum(); - BigDecimal outNum = stockObj.getOutNum(); - return initStock.add(intNum).subtract(outNum).add(stockCheckSum); + DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime); + BigDecimal stockSum = BigDecimal.ZERO; + if(stockObj!=null) { + BigDecimal inTotal = stockObj.getInTotal(); + BigDecimal transfInTotal = stockObj.getTransfInTotal(); + BigDecimal assemInTotal = stockObj.getAssemInTotal(); + BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal(); + BigDecimal outTotal = stockObj.getOutTotal(); + BigDecimal transfOutTotal = stockObj.getTransfOutTotal(); + BigDecimal assemOutTotal = stockObj.getAssemOutTotal(); + BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal(); + stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal) + .subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal); + } + return initStock.add(stockCheckSum).add(stockSum); } /** @@ -482,9 +519,17 @@ public class DepotItemService { * @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(); + public BigDecimal getInNumByParam(Long depotId, Long mId, String beginTime, String endTime){ + DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime); + BigDecimal stockSum = BigDecimal.ZERO; + if(stockObj!=null) { + BigDecimal inTotal = stockObj.getInTotal(); + BigDecimal transfInTotal = stockObj.getTransfInTotal(); + BigDecimal assemInTotal = stockObj.getAssemInTotal(); + BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal(); + stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal); + } + return stockSum; } /** @@ -495,21 +540,28 @@ public class DepotItemService { * @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(); + public BigDecimal getOutNumByParam(Long depotId, Long mId, String beginTime, String endTime){ + DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime); + BigDecimal stockSum = BigDecimal.ZERO; + if(stockObj!=null) { + BigDecimal outTotal = stockObj.getOutTotal(); + BigDecimal transfOutTotal = stockObj.getTransfOutTotal(); + BigDecimal assemOutTotal = stockObj.getAssemOutTotal(); + BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal(); + stockSum = outTotal.subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal); + } + return stockSum; } /** * 根据单据明细来批量更新当前库存 * @param depotItem - * @param tenantId */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public void updateCurrentStock(DepotItem depotItem, Long tenantId){ - updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId(),tenantId); + public void updateCurrentStock(DepotItem depotItem){ + updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId()); if(depotItem.getAnotherDepotId()!=null){ - updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId(),tenantId); + updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId()); } } @@ -517,9 +569,8 @@ public class DepotItemService { * 根据商品和仓库来更新当前库存 * @param mId * @param dId - * @param tenantId */ - public void updateCurrentStockFun(Long mId, Long dId, Long tenantId) { + public void updateCurrentStockFun(Long mId, Long dId) { MaterialCurrentStockExample example = new MaterialCurrentStockExample(); example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); @@ -527,7 +578,7 @@ public class DepotItemService { MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock(); materialCurrentStock.setMaterialId(mId); materialCurrentStock.setDepotId(dId); - materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null,tenantId)); + materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null)); if(list!=null && list.size()>0) { Long mcsId = list.get(0).getId(); materialCurrentStock.setId(mcsId); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java index 63f9c79f..91d1f19c 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java @@ -142,8 +142,7 @@ public class MaterialService { } } m.setMaterialOther(materialOther); - Long tenantId = m.getTenantId(); - m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null,tenantId)); + m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null)); resList.add(m); } } @@ -228,8 +227,7 @@ public class MaterialService { insertInitialStockByMaterialAndDepot(depotId, material.getId(), parseBigDecimalEx(number)); } //更新当前库存 - Long tenantId = redisService.getTenantId(request); - depotItemService.updateCurrentStockFun(material.getId(), depotId, tenantId); + depotItemService.updateCurrentStockFun(material.getId(), depotId); } } } @@ -454,8 +452,8 @@ public class MaterialService { String categoryName = ExcelUtils.getContent(src, i, 4); //类别 String safetyStock = ExcelUtils.getContent(src, i, 5); //安全存量 String unit = ExcelUtils.getContent(src, i, 6); //基础单位 - //校验名称、型号、单位是否为空 - if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(model) && StringUtil.isNotEmpty(unit)) { + //校验名称、单位是否为空 + if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(unit)) { MaterialWithInitStock m = new MaterialWithInitStock(); m.setName(name); m.setStandard(standard); @@ -594,8 +592,7 @@ public class MaterialService { depotId = depot.getId(); insertInitialStockByMaterialAndDepot(depotId, mId, stock); //更新当前库存 - Long tenantId = redisService.getTenantId(request); - depotItemService.updateCurrentStockFun(mId, depotId, tenantId); + depotItemService.updateCurrentStockFun(mId, depotId); } } } diff --git a/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml index 0808cd11..ae85769a 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml @@ -68,9 +68,15 @@ - - - + + + + + + + + + - + select + sum(case when dh.type='入库' and di.depot_id=#{depotId} then di.basic_number else 0 end) as inTotal, + sum(case when dh.type='出库' and dh.sub_type!='调拨' and di.depot_id=#{depotId} then di.basic_number else 0 end) as outTotal, + sum(case when dh.sub_type='调拨' and di.another_depot_id=#{depotId} then di.basic_number else 0 end) as transfInTotal, + sum(case when dh.sub_type='调拨' and di.depot_id=#{depotId} then di.basic_number else 0 end) as transfOutTotal, + sum(case when dh.sub_type='组装单' and di.material_type='组合件' and di.depot_id=#{depotId} then di.basic_number else 0 end) as assemInTotal, + sum(case when dh.sub_type='组装单' and di.material_type='普通子件' and di.depot_id=#{depotId} then di.basic_number else 0 end) as assemOutTotal, + sum(case when dh.sub_type='拆卸单' and di.material_type='普通子件' and di.depot_id=#{depotId} then di.basic_number else 0 end) as disAssemInTotal, + sum(case when dh.sub_type='拆卸单' and di.material_type='组合件' and di.depot_id=#{depotId} then di.basic_number else 0 end) as disAssemOutTotal from - (select sum(if(dh.type='入库' and di.depot_id=#{depotId}, di.basic_number,0)) as inTotal, - sum(if(dh.type='出库' and dh.sub_type!='调拨' and di.depot_id=#{depotId},di.basic_number,0)) as outTotal, - sum(if(dh.sub_type='调拨' and di.another_depot_id=#{depotId},di.basic_number,0)) as transfInTotal, - sum(if(dh.sub_type='调拨' and di.depot_id=#{depotId},di.basic_number,0)) as transfOutTotal, - sum(if(dh.sub_type='组装单' and di.material_type='组合件' and di.depot_id=#{depotId},di.basic_number,0)) as assemInTotal, - sum(if(dh.sub_type='组装单' and di.material_type='普通子件' and di.depot_id=#{depotId},di.basic_number,0)) as assemOutTotal, - sum(if(dh.sub_type='拆卸单' and di.material_type='普通子件' and di.depot_id=#{depotId},di.basic_number,0)) as disAssemInTotal, - sum(if(dh.sub_type='拆卸单' and di.material_type='组合件' and di.depot_id=#{depotId},di.basic_number,0)) as disAssemOutTotal - from - jsh_depot_head dh,jsh_depot_item di + jsh_depot_head dh + left join jsh_depot_item di on dh.id=di.header_id and ifnull(di.delete_flag,'0') !='1' where 1=1 - and dh.id=di.header_id + and ifnull(dh.delete_flag,'0') !='1' + and di.material_extend_id=#{meId} + and ifnull(di.sku,'') !='' + + and dh.oper_time >= #{beginTime} + + + and dh.oper_time <= #{endTime} + + + +