完善库存统计接口,增加移动平均价的逻辑

This commit is contained in:
jishenghua
2024-05-24 01:22:32 +08:00
parent 0292446e15
commit 28548c7957
9 changed files with 124 additions and 9 deletions

View File

@@ -332,6 +332,7 @@ public class DepotItemController {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<>();
try {
Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
List<Long> 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<String, Object> map = new HashMap<>();
try {
Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
List<Long> 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;
}

View File

@@ -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<MaterialVo4Unit> 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<String, Object> 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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -1277,8 +1277,9 @@ public class MaterialService {
return materialMapperEx.getInitialStockWithMaterial(depotList);
}
public List<MaterialVo4Unit> getListWithStock(List<Long> depotList, List<Long> idList, String position, String materialParam, Integer zeroStock,
String column, String order, Integer offset, Integer rows) throws Exception {
public List<MaterialVo4Unit> getListWithStock(List<Long> depotList, List<Long> idList, String position, String materialParam,
Boolean moveAvgPriceFlag, Integer zeroStock, String column, String order,
Integer offset, Integer rows) throws Exception {
Map<Long, BigDecimal> initialStockMap = new HashMap<>();
List<MaterialInitialStockWithMaterial> initialStockList = getInitialStockWithMaterial(depotList);
for (MaterialInitialStockWithMaterial mism: initialStockList) {
@@ -1286,6 +1287,9 @@ public class MaterialService {
}
List<MaterialVo4Unit> 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<Long> 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");

View File

@@ -507,6 +507,23 @@ public class SystemConfigService {
return inOutManageFlag;
}
/**
* 获取移动平均价开关
* @return
* @throws Exception
*/
public boolean getMoveAvgPriceFlag() throws Exception {
boolean moveAvgPriceFlag = false;
List<SystemConfig> list = getSystemConfig();
if(list.size()>0) {
String flag = list.get(0).getMoveAvgPriceFlag();
if(("1").equals(flag)) {
moveAvgPriceFlag = true;
}
}
return moveAvgPriceFlag;
}
/**
* Excel导出统一方法
* @param title