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 a4cb3338..459804c4 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 @@ -332,6 +332,7 @@ public class DepotItemController { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap<>(); try { + Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag(); List categoryIdList = new ArrayList<>(); if(categoryId != null){ categoryIdList = materialService.getListByParentId(categoryId); @@ -371,7 +372,11 @@ public class DepotItemController { item.put("thisSum", thisSum); //将小单位的库存换算为大单位的库存 item.put("bigUnitStock", materialService.getBigUnitStock(thisSum, diEx.getUnitId())); - item.put("unitPrice", diEx.getPurchaseDecimal()); + if(moveAvgPriceFlag) { + item.put("unitPrice", diEx.getCurrentUnitPrice()); + } else { + item.put("unitPrice", diEx.getPurchaseDecimal()); + } item.put("thisAllPrice", thisSum.multiply(diEx.getPurchaseDecimal())); dataArray.add(item); } @@ -408,6 +413,7 @@ public class DepotItemController { BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap<>(); try { + Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag(); List categoryIdList = new ArrayList<>(); if(categoryId != null){ categoryIdList = materialService.getListByParentId(categoryId); @@ -423,7 +429,12 @@ public class DepotItemController { Long mId = diEx.getMId(); BigDecimal thisSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,endTime); thisAllStock = thisAllStock.add(thisSum); - BigDecimal unitPrice = diEx.getPurchaseDecimal(); + BigDecimal unitPrice = null; + if(moveAvgPriceFlag) { + unitPrice = diEx.getCurrentUnitPrice(); + } else { + 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 69291fb9..9a93e632 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 @@ -9,6 +9,7 @@ import com.jsh.erp.service.depot.DepotService; import com.jsh.erp.service.depotItem.DepotItemService; import com.jsh.erp.service.material.MaterialService; import com.jsh.erp.service.role.RoleService; +import com.jsh.erp.service.systemConfig.SystemConfigService; import com.jsh.erp.service.unit.UnitService; import com.jsh.erp.service.user.UserService; import com.jsh.erp.utils.BaseResponseInfo; @@ -48,6 +49,9 @@ public class MaterialController { @Resource private DepotItemService depotItemService; + @Resource + private SystemConfigService systemConfigService; + @Resource private UnitService unitService; @@ -579,7 +583,7 @@ public class MaterialController { * @param depotIds * @param categoryId * @param materialParam - * @param mpList + * @param zeroStock * @param column * @param order * @param request @@ -616,13 +620,18 @@ public class MaterialController { depotList.add(object.getLong("id")); } } + Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag(); List dataList = materialService.getListWithStock(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam), - zeroStock, StringUtil.safeSqlParse(column), StringUtil.safeSqlParse(order), (currentPage-1)*pageSize, pageSize); + moveAvgPriceFlag, zeroStock, StringUtil.safeSqlParse(column), StringUtil.safeSqlParse(order), (currentPage-1)*pageSize, pageSize); int total = materialService.getListWithStockCount(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam), zeroStock); MaterialVo4Unit materialVo4Unit= materialService.getTotalStockAndPrice(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam)); map.put("total", total); map.put("currentStock", materialVo4Unit.getCurrentStock()!=null?materialVo4Unit.getCurrentStock():BigDecimal.ZERO); - map.put("currentStockPrice", materialVo4Unit.getCurrentStockPrice()!=null?materialVo4Unit.getCurrentStockPrice():BigDecimal.ZERO); + if(moveAvgPriceFlag) { + map.put("currentStockPrice", materialVo4Unit.getCurrentStockMovePrice()!=null?materialVo4Unit.getCurrentStockMovePrice():BigDecimal.ZERO); + } else { + map.put("currentStockPrice", materialVo4Unit.getCurrentStockPrice()!=null?materialVo4Unit.getCurrentStockPrice():BigDecimal.ZERO); + } map.put("currentWeight", materialVo4Unit.getCurrentWeight()!=null?materialVo4Unit.getCurrentWeight():BigDecimal.ZERO); map.put("rows", dataList); res.code = 200; @@ -656,6 +665,27 @@ public class MaterialController { } } + /** + * 批量设置商品当前的成本价 + * @param jsonObject + * @param request + * @return + * @throws Exception + */ + @PostMapping(value = "/batchSetMaterialCurrentUnitPrice") + @ApiOperation(value = "批量设置商品当前的成本价") + public String batchSetMaterialCurrentUnitPrice(@RequestBody JSONObject jsonObject, + HttpServletRequest request)throws Exception { + String ids = jsonObject.getString("ids"); + Map objectMap = new HashMap<>(); + int res = materialService.batchSetMaterialCurrentUnitPrice(ids); + if(res > 0) { + return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code); + } else { + return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code); + } + } + /** * 批量更新商品信息 * @param jsonObject diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/DepotItemVo4WithInfoEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/DepotItemVo4WithInfoEx.java index 3a14d875..5fa9c925 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/DepotItemVo4WithInfoEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/DepotItemVo4WithInfoEx.java @@ -46,6 +46,8 @@ public class DepotItemVo4WithInfoEx extends DepotItem{ private BigDecimal purchaseDecimal; + private BigDecimal currentUnitPrice; + private String barCode; private BigDecimal weight; @@ -222,6 +224,14 @@ public class DepotItemVo4WithInfoEx extends DepotItem{ this.purchaseDecimal = purchaseDecimal; } + public BigDecimal getCurrentUnitPrice() { + return currentUnitPrice; + } + + public void setCurrentUnitPrice(BigDecimal currentUnitPrice) { + this.currentUnitPrice = currentUnitPrice; + } + public String getBarCode() { return barCode; } diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java index 9a70863f..31a7b1ec 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java @@ -32,10 +32,14 @@ public class MaterialVo4Unit extends Material{ private BigDecimal initialStock; + private BigDecimal currentUnitPrice; + private BigDecimal currentStock; private BigDecimal currentStockPrice; + private BigDecimal currentStockMovePrice; + private BigDecimal currentWeight; private String sku; @@ -163,6 +167,14 @@ public class MaterialVo4Unit extends Material{ this.initialStock = initialStock; } + public BigDecimal getCurrentUnitPrice() { + return currentUnitPrice; + } + + public void setCurrentUnitPrice(BigDecimal currentUnitPrice) { + this.currentUnitPrice = currentUnitPrice; + } + public BigDecimal getCurrentStock() { return currentStock; } @@ -179,6 +191,14 @@ public class MaterialVo4Unit extends Material{ this.currentStockPrice = currentStockPrice; } + public BigDecimal getCurrentStockMovePrice() { + return currentStockMovePrice; + } + + public void setCurrentStockMovePrice(BigDecimal currentStockMovePrice) { + this.currentStockMovePrice = currentStockMovePrice; + } + public BigDecimal getCurrentWeight() { return currentWeight; } 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 6703f89c..b01165fc 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 @@ -554,9 +554,11 @@ public class DepotHeadService { } } } - //更新当前库存 for (DepotItem depotItem : list) { + //更新当前库存 depotItemService.updateCurrentStock(depotItem); + //更新当前成本价 + depotItemService.updateCurrentUnitPrice(depotItem); } } else { throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_UN_AUDIT_DELETE_FAILED_CODE, 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 994b4f70..3fb4dda2 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 @@ -1277,8 +1277,9 @@ public class MaterialService { return materialMapperEx.getInitialStockWithMaterial(depotList); } - public List getListWithStock(List depotList, List idList, String position, String materialParam, Integer zeroStock, - String column, String order, Integer offset, Integer rows) throws Exception { + public List getListWithStock(List depotList, List idList, String position, String materialParam, + Boolean moveAvgPriceFlag, Integer zeroStock, String column, String order, + Integer offset, Integer rows) throws Exception { Map initialStockMap = new HashMap<>(); List initialStockList = getInitialStockWithMaterial(depotList); for (MaterialInitialStockWithMaterial mism: initialStockList) { @@ -1286,6 +1287,9 @@ public class MaterialService { } List dataList = materialMapperEx.getListWithStock(depotList, idList, position, materialParam, zeroStock, column, order, offset, rows); for(MaterialVo4Unit item: dataList) { + if(moveAvgPriceFlag) { + item.setPurchaseDecimal(item.getCurrentUnitPrice()); + } item.setUnitName(null!=item.getUnitId()?item.getUnitName() + "[多单位]":item.getUnitName()); item.setInitialStock(null!=initialStockMap.get(item.getId())?initialStockMap.get(item.getId()):BigDecimal.ZERO); item.setBigUnitStock(getBigUnitStock(item.getCurrentStock(), item.getUnitId())); @@ -1362,6 +1366,19 @@ public class MaterialService { return res; } + @Transactional(value = "transactionManager", rollbackFor = Exception.class) + public int batchSetMaterialCurrentUnitPrice(String ids) throws Exception { + int res = 0; + List idList = StringUtil.strToLongList(ids); + for(Long mId: idList) { + DepotItem depotItem = new DepotItem(); + depotItem.setMaterialId(mId); + depotItemService.updateCurrentUnitPrice(depotItem); + res = 1; + } + return res; + } + public int batchUpdate(JSONObject jsonObject) { String ids = jsonObject.getString("ids"); String materialStr = jsonObject.getString("material"); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java index 18672e2d..65243b95 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java @@ -507,6 +507,23 @@ public class SystemConfigService { return inOutManageFlag; } + /** + * 获取移动平均价开关 + * @return + * @throws Exception + */ + public boolean getMoveAvgPriceFlag() throws Exception { + boolean moveAvgPriceFlag = false; + List list = getSystemConfig(); + if(list.size()>0) { + String flag = list.get(0).getMoveAvgPriceFlag(); + if(("1").equals(flag)) { + moveAvgPriceFlag = true; + } + } + return moveAvgPriceFlag; + } + /** * Excel导出统一方法 * @param title diff --git a/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml index fc5f4f04..a5caf880 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml @@ -56,6 +56,7 @@ + @@ -345,9 +346,11 @@ select m.*, me.commodity_unit unitName, mc.name categoryName, me.bar_code mBarCode, ifnull(me.purchase_decimal,0) purchaseDecimal, + ifnull(mcs.current_unit_price,0) currentUnitPrice, ifnull(sum(mcs.current_number),0) currentStock, sum(ifnull(me.purchase_decimal, 0) * ifnull(mcs.current_number, 0)) currentStockPrice, + sum(ifnull(mcs.current_unit_price, 0) * ifnull(mcs.current_number, 0)) currentStockMovePrice, sum(ifnull(m.weight, 0) * ifnull(mcs.current_number, 0)) currentWeight FROM jsh_material m left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1' @@ -691,6 +695,7 @@ select ifnull(sum(mcs.current_number),0) currentStock, sum(ifnull(me.purchase_decimal,0)*ifnull(mcs.current_number,0)) currentStockPrice, + sum(ifnull(mcs.current_unit_price,0)*ifnull(mcs.current_number,0)) currentStockMovePrice, sum(ifnull(m.weight,0)*ifnull(mcs.current_number,0)) currentWeight from jsh_material m left JOIN jsh_material_extend me on m.id = me.material_id and ifnull(me.delete_Flag,'0') !='1'