给库存相关的接口增加大单位的库存展示字段

This commit is contained in:
季圣华 2022-11-18 23:30:10 +08:00
parent 3df276db21
commit fd842ecc0a
5 changed files with 51 additions and 12 deletions

View File

@ -331,7 +331,8 @@ public class DepotItemController {
String materialOther = getOtherInfo(mpArr, diEx);
item.put("materialOther", materialOther);
item.put("materialColor", diEx.getMColor());
item.put("unitName", diEx.getMaterialUnit());
item.put("unitId", diEx.getUnitId());
item.put("unitName", null!=diEx.getUnitId() ? diEx.getMaterialUnit()+"[多单位]" : diEx.getMaterialUnit());
BigDecimal prevSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,timeA);
Map<String,BigDecimal> intervalMap = depotItemService.getIntervalMapByParamWithDepotList(depotList,mId,timeA,timeB);
BigDecimal inSum = intervalMap.get("inSum");
@ -341,6 +342,8 @@ public class DepotItemController {
item.put("inSum", inSum);
item.put("outSum", outSum);
item.put("thisSum", thisSum);
//将小单位的库存换算为大单位的库存
item.put("bigUnitStock", materialService.getBigUnitStock(thisSum, diEx.getUnitId()));
item.put("unitPrice", diEx.getPurchaseDecimal());
item.put("thisAllPrice", thisSum.multiply(diEx.getPurchaseDecimal()));
dataArray.add(item);

View File

@ -593,11 +593,6 @@ public class MaterialController {
depotList.add(object.getLong("id"));
}
}
Map<Long, BigDecimal> initialStockMap = new HashMap<>();
List<MaterialInitialStockWithMaterial> initialStockList = materialService.getInitialStockWithMaterial(depotList);
for (MaterialInitialStockWithMaterial mism: initialStockList) {
initialStockMap.put(mism.getMaterialId(), mism.getNumber());
}
List<MaterialVo4Unit> dataList = materialService.getListWithStock(depotList, idList, StringUtil.toNull(materialParam), zeroStock,
StringUtil.safeSqlParse(column), StringUtil.safeSqlParse(order), (currentPage-1)*pageSize, pageSize);
int total = materialService.getListWithStockCount(depotList, idList, StringUtil.toNull(materialParam), zeroStock);
@ -605,9 +600,6 @@ public class MaterialController {
map.put("total", total);
map.put("currentStock", materialVo4Unit.getCurrentStock());
map.put("currentStockPrice", materialVo4Unit.getCurrentStockPrice());
for(MaterialVo4Unit item: dataList) {
item.setInitialStock(initialStockMap.get(item.getId()));
}
map.put("rows", dataList);
res.code = 200;
res.data = map;

View File

@ -38,6 +38,11 @@ public class MaterialVo4Unit extends Material{
private Long depotId;
/**
* 换算为大单位的库存
*/
private String bigUnitStock;
public String getUnitName() {
return unitName;
}
@ -173,4 +178,12 @@ public class MaterialVo4Unit extends Material{
public void setDepotId(Long depotId) {
this.depotId = depotId;
}
public String getBigUnitStock() {
return bigUnitStock;
}
public void setBigUnitStock(String bigUnitStock) {
this.bigUnitStock = bigUnitStock;
}
}

View File

@ -133,6 +133,7 @@ public class MaterialService {
for (MaterialVo4Unit m : list) {
m.setMaterialOther(getMaterialOtherByParam(mpArr, m));
m.setStock(currentStockMap.get(m.getId())!=null? currentStockMap.get(m.getId()): BigDecimal.ZERO);
m.setBigUnitStock(getBigUnitStock(m.getStock(), m.getUnitId()));
resList.add(m);
}
}
@ -1103,8 +1104,19 @@ public class MaterialService {
}
public List<MaterialVo4Unit> getListWithStock(List<Long> depotList, List<Long> idList, String materialParam, Integer zeroStock,
String column, String order, Integer offset, Integer rows) {
return materialMapperEx.getListWithStock(depotList, idList, materialParam, zeroStock, column, order, offset, rows);
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) {
initialStockMap.put(mism.getMaterialId(), mism.getNumber());
}
List<MaterialVo4Unit> dataList = materialMapperEx.getListWithStock(depotList, idList, materialParam, zeroStock, column, order, offset, rows);
for(MaterialVo4Unit item: dataList) {
item.setUnitName(null!=item.getUnitId()?item.getUnitName() + "[多单位]":item.getUnitName());
item.setInitialStock(initialStockMap.get(item.getId()));
item.setBigUnitStock(getBigUnitStock(item.getCurrentStock(), item.getUnitId()));
}
return dataList;
}
public int getListWithStockCount(List<Long> depotList, List<Long> idList, String materialParam, Integer zeroStock) {
@ -1115,6 +1127,24 @@ public class MaterialService {
return materialMapperEx.getTotalStockAndPrice(depotList, idList, materialParam);
}
/**
* 将小单位的库存换算为大单位的库存
* @param stock
* @param unitId
* @return
* @throws Exception
*/
public String getBigUnitStock(BigDecimal stock, Long unitId) throws Exception {
String bigUnitStock = "";
if(null!= unitId) {
Unit unit = unitService.getUnit(unitId);
if(unit.getRatio()!=0 && stock!=null) {
bigUnitStock = stock.divide(BigDecimal.valueOf(unit.getRatio()),2,BigDecimal.ROUND_HALF_UP) + unit.getOtherUnit();
}
}
return bigUnitStock;
}
/**
* 构造扩展信息
* @param mpArr

View File

@ -47,6 +47,7 @@
<result column="MOtherField1" jdbcType="VARCHAR" property="MOtherField1" />
<result column="MOtherField2" jdbcType="VARCHAR" property="MOtherField2" />
<result column="MOtherField3" jdbcType="VARCHAR" property="MOtherField3" />
<result column="unit_id" jdbcType="BIGINT" property="unitId" />
<result column="unit_name" jdbcType="VARCHAR" property="unitName" />
<result column="MColor" jdbcType="VARCHAR" property="MColor" />
<result column="purchase_decimal" jdbcType="DECIMAL" property="purchaseDecimal" />
@ -249,7 +250,7 @@
<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, 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
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_depot_item di on di.material_id=m.id and ifnull(di.delete_Flag,'0') !='1'