优化单据中计量单位的查询方法

This commit is contained in:
季圣华
2020-12-21 22:57:46 +08:00
parent 8554fda91b
commit 8cc8dea077
5 changed files with 25 additions and 68 deletions

View File

@@ -122,27 +122,6 @@ public class DepotItemController {
return res; return res;
} }
/**
* 查询计量单位信息
*
* @return
*/
public String findUnitName(Long mId)throws Exception {
String unitName = "";
try {
unitName = materialService.findUnitName(mId);
if (unitName != null) {
unitName = unitName.substring(1, unitName.length() - 1);
if (unitName.equals("null")) {
unitName = "";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return unitName;
}
@GetMapping(value = "/getDetailList") @GetMapping(value = "/getDetailList")
public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId, public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
@RequestParam("mpList") String mpList, @RequestParam("mpList") String mpList,

View File

@@ -3,6 +3,7 @@ package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.AccountHead; import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.Material; import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.MaterialVo4Unit; import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import com.jsh.erp.datasource.entities.Unit;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Date; import java.util.Date;
@@ -35,7 +36,7 @@ public interface MaterialMapperEx {
@Param("categoryIds") String categoryIds, @Param("categoryIds") String categoryIds,
@Param("mpList") String mpList); @Param("mpList") String mpList);
String findUnitName(@Param("mId") Long mId); List<Unit> findUnitList(@Param("mId") Long mId);
List<MaterialVo4Unit> findById(@Param("id") Long id); List<MaterialVo4Unit> findById(@Param("id") Long id);

View File

@@ -329,28 +329,22 @@ public class DepotItemService {
depotItem.setMaterialUnit(rowObj.getString("Unit")); depotItem.setMaterialUnit(rowObj.getString("Unit"));
if (StringUtil.isExist(rowObj.get("OperNumber"))) { if (StringUtil.isExist(rowObj.get("OperNumber"))) {
depotItem.setOperNumber(rowObj.getBigDecimal("OperNumber")); depotItem.setOperNumber(rowObj.getBigDecimal("OperNumber"));
try { String unit = rowObj.get("Unit").toString();
String Unit = rowObj.get("Unit").toString();
BigDecimal oNumber = rowObj.getBigDecimal("OperNumber"); BigDecimal oNumber = rowObj.getBigDecimal("OperNumber");
//以下进行单位换算 //以下进行单位换算
String unitName = materialService.findUnitName(materialExtend.getMaterialId()); //查询计量单位名称 Unit unitInfo = materialService.findUnit(materialExtend.getMaterialId()); //查询计量单位信息
if (!StringUtil.isEmpty(unitName)) { if (StringUtil.isNotEmpty(unitInfo.getName())) {
String unitList = unitName.substring(0, unitName.indexOf("(")); String basicUnit = unitInfo.getBasicUnit(); //基本单位
String ratioList = unitName.substring(unitName.indexOf("(")); String otherUnit = unitInfo.getOtherUnit(); //副单位
String basicUnit = unitList.substring(0, unitList.indexOf(",")); //基本单位 Integer ratio = unitInfo.getRatio(); //比例
String otherUnit = unitList.substring(unitList.indexOf(",") + 1); //单位 if (unit.equals(basicUnit)) { //如果等于基础单位
Integer ratio = Integer.parseInt(ratioList.substring(ratioList.indexOf(":") + 1).replace(")", "")); //比例
if (Unit.equals(basicUnit)) { //如果等于基础单位
depotItem.setBasicNumber(oNumber); //数量一致 depotItem.setBasicNumber(oNumber); //数量一致
} else if (Unit.equals(otherUnit)) { //如果等于副单位 } else if (unit.equals(otherUnit)) { //如果等于副单位
depotItem.setBasicNumber(oNumber.multiply(new BigDecimal(ratio)) ); //数量乘以比例 depotItem.setBasicNumber(oNumber.multiply(new BigDecimal(ratio)) ); //数量乘以比例
} }
} else { } else {
depotItem.setBasicNumber(oNumber); //其他情况 depotItem.setBasicNumber(oNumber); //其他情况
} }
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
}
} }
if (StringUtil.isExist(rowObj.get("UnitPrice"))) { if (StringUtil.isExist(rowObj.get("UnitPrice"))) {
depotItem.setUnitPrice(rowObj.getBigDecimal("UnitPrice")); depotItem.setUnitPrice(rowObj.getBigDecimal("UnitPrice"));
@@ -413,26 +407,6 @@ public class DepotItemService {
} }
} }
} }
/**
* 查询计量单位信息
*
* @return
*/
public String findUnitName(Long mId) throws Exception{
String unitName = "";
try {
unitName = materialService.findUnitName(mId);
if (unitName != null) {
unitName = unitName.substring(1, unitName.length() - 1);
if (unitName.equals("null")) {
unitName = "";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return unitName;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void deleteDepotItemHeadId(Long headerId)throws Exception { public void deleteDepotItemHeadId(Long headerId)throws Exception {

View File

@@ -310,14 +310,17 @@ public class MaterialService {
return result; return result;
} }
public String findUnitName(Long mId)throws Exception{ public Unit findUnit(Long mId)throws Exception{
String result =null; Unit unit = new Unit();
try{ try{
result= materialMapperEx.findUnitName(mId); List<Unit> list = materialMapperEx.findUnitList(mId);
if(list!=null && list.size()>0) {
unit = list.get(0);
}
}catch(Exception e){ }catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
return result; return unit;
} }
public List<MaterialVo4Unit> findById(Long id)throws Exception{ public List<MaterialVo4Unit> findById(Long id)throws Exception{

View File

@@ -74,8 +74,8 @@
and ifnull(m.delete_flag,'0') !='1' and ifnull(m.delete_flag,'0') !='1'
</select> </select>
<select id="findUnitName" resultType="java.lang.String"> <select id="findUnitList" resultType="com.jsh.erp.datasource.entities.Unit">
select u.name from jsh_unit u select u.* from jsh_unit u
left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1' left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
where m.id = ${mId} where m.id = ${mId}
and ifnull(u.delete_flag,'0') !='1' and ifnull(u.delete_flag,'0') !='1'