完善库存统计接口,增加移动平均价的逻辑
This commit is contained in:
parent
0292446e15
commit
28548c7957
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
<result column="unit_name" jdbcType="VARCHAR" property="unitName" />
|
||||
<result column="MColor" jdbcType="VARCHAR" property="MColor" />
|
||||
<result column="purchase_decimal" jdbcType="DECIMAL" property="purchaseDecimal" />
|
||||
<result column="currentUnitPrice" jdbcType="DECIMAL" property="currentUnitPrice" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount">
|
||||
@ -345,9 +346,11 @@
|
||||
<select id="findByAll" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
|
||||
select m.id MId, me.bar_code, m.name MName, m.mfrs MMfrs, m.model MModel, m.standard MStandard,
|
||||
m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,
|
||||
concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.unit_id, u.name unit_name, ifnull(me.purchase_decimal,0) purchase_decimal
|
||||
concat_ws('', m.unit, u.basic_unit) MaterialUnit, m.color MColor, m.unit_id, u.name unit_name,
|
||||
ifnull(me.purchase_decimal,0) purchase_decimal, ifnull(mcs.current_unit_price,0) currentUnitPrice
|
||||
from jsh_material m
|
||||
left join jsh_material_extend me on me.material_id=m.id and ifnull(me.delete_Flag,'0') !='1'
|
||||
left join jsh_material_current_stock mcs on m.id = mcs.material_id and ifnull(mcs.delete_flag,'0') !='1'
|
||||
left join jsh_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'
|
||||
left join jsh_depot_head dh on di.header_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
|
||||
left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
|
||||
|
||||
@ -19,9 +19,11 @@
|
||||
<result column="categoryName" jdbcType="VARCHAR" property="categoryName" />
|
||||
<result column="mBarCode" jdbcType="VARCHAR" property="mBarCode" />
|
||||
<result column="purchaseDecimal" jdbcType="VARCHAR" property="purchaseDecimal" />
|
||||
<result column="currentUnitPrice" jdbcType="VARCHAR" property="currentUnitPrice" />
|
||||
<result column="initialStock" jdbcType="DECIMAL" property="initialStock" />
|
||||
<result column="currentStock" jdbcType="DECIMAL" property="currentStock" />
|
||||
<result column="currentStockPrice" jdbcType="DECIMAL" property="currentStockPrice" />
|
||||
<result column="currentStockMovePrice" jdbcType="DECIMAL" property="currentStockMovePrice" />
|
||||
<result column="currentWeight" jdbcType="DECIMAL" property="currentWeight" />
|
||||
</resultMap>
|
||||
|
||||
@ -604,8 +606,10 @@
|
||||
<select id="getListWithStock" resultMap="ResultMapListWithStock">
|
||||
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'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user