优化商品条码查询接口,支持选择多商品

This commit is contained in:
季圣华
2021-08-06 01:21:35 +08:00
parent 3269b4874a
commit c6a5689f44
5 changed files with 73 additions and 29 deletions

View File

@@ -7,6 +7,7 @@ import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants; import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*; import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.service.depotItem.DepotItemService; import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.material.MaterialService; import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.service.redis.RedisService; import com.jsh.erp.service.redis.RedisService;
@@ -45,6 +46,9 @@ public class MaterialController {
@Resource @Resource
private UnitService unitService; private UnitService unitService;
@Resource
private DepotService depotService;
@Resource @Resource
private RedisService redisService; private RedisService redisService;
@@ -445,40 +449,63 @@ public class MaterialController {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
String[] mpArr = mpList.split(","); String[] mpArr = mpList.split(",");
MaterialVo4Unit mu = new MaterialVo4Unit();
List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(barCode); List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(barCode);
if(list!=null && list.size()>0) { if(list!=null && list.size()>0) {
mu = list.get(0); for(MaterialVo4Unit mvo: list) {
String expand = ""; //扩展信息 String expand = ""; //扩展信息
for (int i = 0; i < mpArr.length; i++) { for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("制造商")) { if (mpArr[i].equals("制造商")) {
expand = expand + ((mu.getMfrs() == null || mu.getMfrs().equals("")) ? "" : "(" + mu.getMfrs() + ")"); expand = expand + ((mvo.getMfrs() == null || mvo.getMfrs().equals("")) ? "" : "(" + mvo.getMfrs() + ")");
}
if (mpArr[i].equals("自定义1")) {
expand = expand + ((mvo.getOtherField1() == null || mvo.getOtherField1().equals("")) ? "" : "(" + mvo.getOtherField1() + ")");
}
if (mpArr[i].equals("自定义2")) {
expand = expand + ((mvo.getOtherField2() == null || mvo.getOtherField2().equals("")) ? "" : "(" + mvo.getOtherField2() + ")");
}
if (mpArr[i].equals("自定义3")) {
expand = expand + ((mvo.getOtherField3() == null || mvo.getOtherField3().equals("")) ? "" : "(" + mvo.getOtherField3() + ")");
}
} }
if (mpArr[i].equals("自定义1")) { mvo.setMaterialOther(expand);
expand = expand + ((mu.getOtherField1() == null || mu.getOtherField1().equals("")) ? "" : "(" + mu.getOtherField1() + ")"); if("LSCK".equals(prefixNo) || "LSTH".equals(prefixNo)) {
//零售价
mvo.setBillPrice(mvo.getCommodityDecimal());
} else if("CGDD".equals(prefixNo) || "CGRK".equals(prefixNo) || "CGTH".equals(prefixNo)
|| "QTRK".equals(prefixNo) || "DBCK".equals(prefixNo) || "ZZD".equals(prefixNo) || "CXD".equals(prefixNo) ) {
//采购价
mvo.setBillPrice(mvo.getPurchaseDecimal());
} else if("XSDD".equals(prefixNo) || "XSCK".equals(prefixNo) || "XSTH".equals(prefixNo) || "QTCK".equals(prefixNo)) {
//销售价
mvo.setBillPrice(mvo.getWholesaleDecimal());
} }
if (mpArr[i].equals("自定义2")) { //仓库id
expand = expand + ((mu.getOtherField2() == null || mu.getOtherField2().equals("")) ? "" : "(" + mu.getOtherField2() + ")"); JSONArray depotArr = depotService.findDepotByCurrentUser();
for(Object obj: depotArr){
JSONObject depotObj = JSONObject.parseObject(obj.toString());
if(depotObj.get("isDefault")!=null) {
Boolean isDefault = depotObj.getBoolean("isDefault");
if(isDefault) {
Long depotId = depotObj.getLong("id");
mvo.setDepotId(depotId);
//库存
BigDecimal stock = depotItemService.getStockByParam(depotId,mvo.getId(),null,null);
if (mvo.getUnitId()!=null){
Unit unit = unitService.getUnit(mvo.getUnitId());
if(mvo.getCommodityUnit().equals(unit.getOtherUnit())) {
if(unit.getRatio()!=0) {
stock = stock.divide(BigDecimal.valueOf(unit.getRatio()),2,BigDecimal.ROUND_HALF_UP);
}
}
}
mvo.setStock(stock);
}
}
} }
if (mpArr[i].equals("自定义3")) {
expand = expand + ((mu.getOtherField3() == null || mu.getOtherField3().equals("")) ? "" : "(" + mu.getOtherField3() + ")");
}
}
mu.setMaterialOther(expand);
if("LSCK".equals(prefixNo) || "LSTH".equals(prefixNo)) {
//零售价
mu.setBillPrice(mu.getCommodityDecimal());
} else if("CGDD".equals(prefixNo) || "CGRK".equals(prefixNo) || "CGTH".equals(prefixNo)
|| "QTRK".equals(prefixNo) || "DBCK".equals(prefixNo) || "ZZD".equals(prefixNo) || "CXD".equals(prefixNo) ) {
//采购价
mu.setBillPrice(mu.getPurchaseDecimal());
} else if("XSDD".equals(prefixNo) || "XSCK".equals(prefixNo) || "XSTH".equals(prefixNo) || "QTCK".equals(prefixNo)) {
//销售价
mu.setBillPrice(mu.getWholesaleDecimal());
} }
} }
res.code = 200; res.code = 200;
res.data = mu; res.data = list;
} catch(Exception e){ } catch(Exception e){
e.printStackTrace(); e.printStackTrace();
res.code = 500; res.code = 500;

View File

@@ -36,6 +36,8 @@ public class MaterialVo4Unit extends Material{
private String sku; private String sku;
private Long depotId;
public String getUnitName() { public String getUnitName() {
return unitName; return unitName;
} }
@@ -163,4 +165,12 @@ public class MaterialVo4Unit extends Material{
public void setSku(String sku) { public void setSku(String sku) {
this.sku = sku; this.sku = sku;
} }
public Long getDepotId() {
return depotId;
}
public void setDepotId(Long depotId) {
this.depotId = depotId;
}
} }

View File

@@ -84,7 +84,7 @@ public interface MaterialMapperEx {
int setUnitIdToNull(@Param("id") Long id); int setUnitIdToNull(@Param("id") Long id);
List<MaterialVo4Unit> getMaterialByBarCode(@Param("barCode") String barCode); List<MaterialVo4Unit> getMaterialByBarCode(@Param("barCodeArray") String [] barCodeArray);
List<MaterialVo4Unit> getListWithStock( List<MaterialVo4Unit> getListWithStock(
@Param("depotId") Long depotId, @Param("depotId") Long depotId,

View File

@@ -803,7 +803,8 @@ public class MaterialService {
} }
public List<MaterialVo4Unit> getMaterialByBarCode(String barCode) { public List<MaterialVo4Unit> getMaterialByBarCode(String barCode) {
return materialMapperEx.getMaterialByBarCode(barCode); String [] barCodeArray=barCode.split(",");
return materialMapperEx.getMaterialByBarCode(barCodeArray);
} }
public List<MaterialVo4Unit> getListWithStock(Long depotId, List<Long> idList, String materialParam, Integer offset, Integer rows) { public List<MaterialVo4Unit> getListWithStock(Long depotId, List<Long> idList, String materialParam, Integer offset, Integer rows) {

View File

@@ -307,8 +307,14 @@
from jsh_material m from jsh_material m
left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1' left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1' left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
where me.bar_code = #{barCode} where
me.bar_code in (
<foreach collection="barCodeArray" item="barCode" separator=",">
#{barCode}
</foreach>
)
and ifnull(m.delete_flag,'0') !='1' and ifnull(m.delete_flag,'0') !='1'
order by me.id desc
</select> </select>
<update id="setUnitIdToNull"> <update id="setUnitIdToNull">