From 3727271fd0623f4e38348deff7863d7ab249c5ae Mon Sep 17 00:00:00 2001 From: jishenghua <752718920@qq.com> Date: Wed, 22 May 2024 00:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=8D=95=E6=8D=AE=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=9B=B4=E6=96=B0=E6=88=90=E6=9C=AC?= =?UTF-8?q?=E4=BB=B7=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mappers/MaterialCurrentStockMapperEx.java | 5 +++ .../service/depotItem/DepotItemService.java | 44 ++++++++++++++++--- .../MaterialCurrentStockMapperEx.xml | 6 +++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialCurrentStockMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialCurrentStockMapperEx.java index 1132d66b..f0cba59f 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialCurrentStockMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialCurrentStockMapperEx.java @@ -4,6 +4,7 @@ import com.jsh.erp.datasource.entities.MaterialCurrentStock; import com.jsh.erp.datasource.entities.MaterialCurrentStockExample; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.List; public interface MaterialCurrentStockMapperEx { @@ -12,4 +13,8 @@ public interface MaterialCurrentStockMapperEx { List getCurrentStockMapByIdList( @Param("materialIdList") List materialIdList); + + void updateUnitPriceByMId( + @Param("currentUnitPrice") BigDecimal currentUnitPrice, + @Param("materialId") Long materialId); } \ No newline at end of file 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 5617412a..dfc9278b 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 @@ -31,10 +31,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Service public class DepotItemService { @@ -72,6 +69,8 @@ public class DepotItemService { @Resource private MaterialCurrentStockMapper materialCurrentStockMapper; @Resource + private MaterialCurrentStockMapperEx materialCurrentStockMapperEx; + @Resource private LogService logService; public DepotItem getDepotItem(long id)throws Exception { @@ -178,7 +177,7 @@ public class DepotItemService { } public List findDetailByDepotIdsAndMaterialIdList(String depotIds, Boolean forceFlag, Boolean inOutManageFlag, String sku, String batchNumber, - String number, String beginTime, String endTime, Long mId, int offset, int rows)throws Exception { + String number, String beginTime, String endTime, Long mId, Integer offset, Integer rows)throws Exception { Long depotId = null; if(StringUtil.isNotEmpty(depotIds)) { depotId = Long.parseLong(depotIds); @@ -666,6 +665,8 @@ public class DepotItemService { this.insertDepotItemWithObj(depotItem); //更新当前库存 updateCurrentStock(depotItem); + //更新当前成本价 + updateCurrentUnitPrice(depotItem); //更新商品的价格 updateMaterialExtendPrice(materialExtend.getId(), depotHead.getSubType(), depotHead.getBillType(), rowObj); } @@ -1047,6 +1048,39 @@ public class DepotItemService { } } + /** + * 根据单据明细来批量更新当前成本价 + * @param depotItem + */ + @Transactional(value = "transactionManager", rollbackFor = Exception.class) + public void updateCurrentUnitPrice(DepotItem depotItem) throws Exception { + Boolean forceFlag = systemConfigService.getForceApprovalFlag(); + Boolean inOutManageFlag = systemConfigService.getInOutManageFlag(); + List itemList = findDetailByDepotIdsAndMaterialIdList(null, forceFlag, inOutManageFlag, depotItem.getSku(), + depotItem.getBatchNumber(), null, null, null, depotItem.getMaterialId(), null, null); + Collections.reverse(itemList); //倒序之后变成按时间从前往后排序 + BigDecimal currentNumber = BigDecimal.ZERO; + BigDecimal currentUnitPrice = BigDecimal.ZERO; + BigDecimal currentAllPrice = BigDecimal.ZERO; + for(DepotItemVo4DetailByTypeAndMId item: itemList) { + //入库 + if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(item.getType())) { + currentAllPrice = currentAllPrice.add(item.getAllPrice()); + currentNumber = currentNumber.add(item.getBnum()); + currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP); + } + //出库 + if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(item.getType())) { + currentNumber = currentNumber.add(item.getBnum()); + BigDecimal outNum = item.getBnum()!=null?item.getBnum():BigDecimal.ZERO; + //出库的数量*当前的成本单价 + currentAllPrice = currentAllPrice.add(outNum.multiply(currentUnitPrice)); + } + } + //更新实时库存中的当前单价 + materialCurrentStockMapperEx.updateUnitPriceByMId(currentUnitPrice, depotItem.getMaterialId()); + } + /** * 根据商品和仓库来更新当前库存 * @param mId diff --git a/jshERP-boot/src/main/resources/mapper_xml/MaterialCurrentStockMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/MaterialCurrentStockMapperEx.xml index bea9448c..d068cb71 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/MaterialCurrentStockMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/MaterialCurrentStockMapperEx.xml @@ -21,4 +21,10 @@ group by material_id + + update jsh_material_current_stock set current_unit_price = #{currentUnitPrice} + where material_id = #{materialId} + and ifnull(delete_flag,'0') !='1' + + \ No newline at end of file