优化单据中计量单位的查询方法
This commit is contained in:
@@ -122,27 +122,6 @@ public class DepotItemController {
|
||||
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")
|
||||
public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
|
||||
@RequestParam("mpList") String mpList,
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.jsh.erp.datasource.mappers;
|
||||
import com.jsh.erp.datasource.entities.AccountHead;
|
||||
import com.jsh.erp.datasource.entities.Material;
|
||||
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
|
||||
import com.jsh.erp.datasource.entities.Unit;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -35,7 +36,7 @@ public interface MaterialMapperEx {
|
||||
@Param("categoryIds") String categoryIds,
|
||||
@Param("mpList") String mpList);
|
||||
|
||||
String findUnitName(@Param("mId") Long mId);
|
||||
List<Unit> findUnitList(@Param("mId") Long mId);
|
||||
|
||||
List<MaterialVo4Unit> findById(@Param("id") Long id);
|
||||
|
||||
|
||||
@@ -329,28 +329,22 @@ public class DepotItemService {
|
||||
depotItem.setMaterialUnit(rowObj.getString("Unit"));
|
||||
if (StringUtil.isExist(rowObj.get("OperNumber"))) {
|
||||
depotItem.setOperNumber(rowObj.getBigDecimal("OperNumber"));
|
||||
try {
|
||||
String Unit = rowObj.get("Unit").toString();
|
||||
String unit = rowObj.get("Unit").toString();
|
||||
BigDecimal oNumber = rowObj.getBigDecimal("OperNumber");
|
||||
//以下进行单位换算
|
||||
String unitName = materialService.findUnitName(materialExtend.getMaterialId()); //查询计量单位名称
|
||||
if (!StringUtil.isEmpty(unitName)) {
|
||||
String unitList = unitName.substring(0, unitName.indexOf("("));
|
||||
String ratioList = unitName.substring(unitName.indexOf("("));
|
||||
String basicUnit = unitList.substring(0, unitList.indexOf(",")); //基本单位
|
||||
String otherUnit = unitList.substring(unitList.indexOf(",") + 1); //副单位
|
||||
Integer ratio = Integer.parseInt(ratioList.substring(ratioList.indexOf(":") + 1).replace(")", "")); //比例
|
||||
if (Unit.equals(basicUnit)) { //如果等于基础单位
|
||||
Unit unitInfo = materialService.findUnit(materialExtend.getMaterialId()); //查询计量单位信息
|
||||
if (StringUtil.isNotEmpty(unitInfo.getName())) {
|
||||
String basicUnit = unitInfo.getBasicUnit(); //基本单位
|
||||
String otherUnit = unitInfo.getOtherUnit(); //副单位
|
||||
Integer ratio = unitInfo.getRatio(); //比例
|
||||
if (unit.equals(basicUnit)) { //如果等于基础单位
|
||||
depotItem.setBasicNumber(oNumber); //数量一致
|
||||
} else if (Unit.equals(otherUnit)) { //如果等于副单位
|
||||
} else if (unit.equals(otherUnit)) { //如果等于副单位
|
||||
depotItem.setBasicNumber(oNumber.multiply(new BigDecimal(ratio)) ); //数量乘以比例
|
||||
}
|
||||
} else {
|
||||
depotItem.setBasicNumber(oNumber); //其他情况
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
|
||||
}
|
||||
}
|
||||
if (StringUtil.isExist(rowObj.get("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)
|
||||
public void deleteDepotItemHeadId(Long headerId)throws Exception {
|
||||
|
||||
@@ -310,14 +310,17 @@ public class MaterialService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String findUnitName(Long mId)throws Exception{
|
||||
String result =null;
|
||||
public Unit findUnit(Long mId)throws Exception{
|
||||
Unit unit = new Unit();
|
||||
try{
|
||||
result= materialMapperEx.findUnitName(mId);
|
||||
List<Unit> list = materialMapperEx.findUnitList(mId);
|
||||
if(list!=null && list.size()>0) {
|
||||
unit = list.get(0);
|
||||
}
|
||||
}catch(Exception e){
|
||||
JshException.readFail(logger, e);
|
||||
}
|
||||
return result;
|
||||
return unit;
|
||||
}
|
||||
|
||||
public List<MaterialVo4Unit> findById(Long id)throws Exception{
|
||||
|
||||
@@ -74,8 +74,8 @@
|
||||
and ifnull(m.delete_flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="findUnitName" resultType="java.lang.String">
|
||||
select u.name from jsh_unit u
|
||||
<select id="findUnitList" resultType="com.jsh.erp.datasource.entities.Unit">
|
||||
select u.* from jsh_unit u
|
||||
left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
|
||||
where m.id = ${mId}
|
||||
and ifnull(u.delete_flag,'0') !='1'
|
||||
|
||||
Reference in New Issue
Block a user