fix:单位非空兜底PCS
This commit is contained in:
@@ -15,8 +15,10 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
import org.nl.common.exception.BadRequestException;
|
import org.nl.common.exception.BadRequestException;
|
||||||
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||||
|
import org.nl.wms.basedata_manage.service.IMdPbMeasureunitService;
|
||||||
import org.nl.wms.basedata_manage.service.IStructattrService;
|
import org.nl.wms.basedata_manage.service.IStructattrService;
|
||||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||||
|
import org.nl.wms.basedata_manage.service.dao.MdPbMeasureunit;
|
||||||
import org.nl.wms.basedata_manage.service.dao.Structattr;
|
import org.nl.wms.basedata_manage.service.dao.Structattr;
|
||||||
import org.nl.wms.ext_manage.api.MesApi;
|
import org.nl.wms.ext_manage.api.MesApi;
|
||||||
import org.nl.wms.ext_manage.enums.EXTConstant;
|
import org.nl.wms.ext_manage.enums.EXTConstant;
|
||||||
@@ -61,6 +63,10 @@ import static org.nl.common.domain.query.PageQuery.trimStringFields;
|
|||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> implements IPmDemandService {
|
public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> implements IPmDemandService {
|
||||||
|
|
||||||
|
/** 物料未维护计量单位时的默认单位名称(md_pb_measureunit.unit_name='PCS',注意其 unit_code 为 '602') */
|
||||||
|
private static final String DEFAULT_UNIT_NAME = "PCS";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IStInventoryService iStInventoryService;
|
private IStInventoryService iStInventoryService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -70,6 +76,8 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private IMdPbMeasureunitService iMdPbMeasureunitService;
|
||||||
|
@Autowired
|
||||||
private ISysParamService iSysParamService;
|
private ISysParamService iSysParamService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISchBaseRegionService iSchBaseRegionService;
|
private ISchBaseRegionService iSchBaseRegionService;
|
||||||
@@ -459,6 +467,38 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取计量单位标识,物料未维护单位(qty_unit_id 为空)时用默认单位 PCS 兜底。
|
||||||
|
* <p>
|
||||||
|
* st_ivt_iostorinvdtl.qty_unit_id 为非空列,直接塞 null 会报
|
||||||
|
* Column 'qty_unit_id' cannot be null;单位按「编码优先、名称兜底」解析,
|
||||||
|
* 以保证 md_pb_measureunit 里 unit_code='602'、unit_name='PCS' 这种数据也能命中。
|
||||||
|
*/
|
||||||
|
private String resolveQuantityUnitId(String qtyUnitId) {
|
||||||
|
if (StringUtils.isNotBlank(qtyUnitId)) {
|
||||||
|
return qtyUnitId;
|
||||||
|
}
|
||||||
|
MdPbMeasureunit defaultUnit = findPcsMeasureUnit();
|
||||||
|
if (defaultUnit == null || StringUtils.isBlank(defaultUnit.getMeasure_unit_id())) {
|
||||||
|
throw new BadRequestException("下推失败:默认计量单位" + DEFAULT_UNIT_NAME + "在计量单位表中不存在,请先维护");
|
||||||
|
}
|
||||||
|
log.warn("物料未维护计量单位,使用默认单位{}兜底,measure_unit_id={}", DEFAULT_UNIT_NAME, defaultUnit.getMeasure_unit_id());
|
||||||
|
return defaultUnit.getMeasure_unit_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查默认计量单位 PCS:先按单位编码匹配,再按单位名称匹配(忽略大小写)。
|
||||||
|
*/
|
||||||
|
private MdPbMeasureunit findPcsMeasureUnit() {
|
||||||
|
MdPbMeasureunit unit = iMdPbMeasureunitService.getOne(new LambdaQueryWrapper<MdPbMeasureunit>()
|
||||||
|
.eq(MdPbMeasureunit::getUnit_code, DEFAULT_UNIT_NAME).last("limit 1"));
|
||||||
|
if (unit != null) {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
return iMdPbMeasureunitService.getOne(new LambdaQueryWrapper<MdPbMeasureunit>()
|
||||||
|
.apply("UPPER(unit_name) = {0}", DEFAULT_UNIT_NAME).last("limit 1"));
|
||||||
|
}
|
||||||
|
|
||||||
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
|
private JSONObject convertDemandsToBillParam(List<PmDemandDto> demands) {
|
||||||
if (CollectionUtils.isEmpty(demands)) {
|
if (CollectionUtils.isEmpty(demands)) {
|
||||||
throw new BadRequestException("需求单数据为空");
|
throw new BadRequestException("需求单数据为空");
|
||||||
@@ -491,7 +531,8 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
|
|||||||
}
|
}
|
||||||
detailRow.put("material_id", materialbase.getMaterial_id());
|
detailRow.put("material_id", materialbase.getMaterial_id());
|
||||||
detailRow.put("qty_unit_name", demand.getUnit());
|
detailRow.put("qty_unit_name", demand.getUnit());
|
||||||
detailRow.put("qty_unit_id", codeToIdMap.get(demand.getSkuCode()).getQty_unit_id());
|
// st_ivt_iostorinvdtl.qty_unit_id 非空,物料未维护单位时用默认单位 PCS 兜底,否则会报 Column 'qty_unit_id' cannot be null
|
||||||
|
detailRow.put("qty_unit_id", resolveQuantityUnitId(materialbase.getQty_unit_id()));
|
||||||
detailRow.put("qty", demand.getQty());
|
detailRow.put("qty", demand.getQty());
|
||||||
detailRow.put("source_bill_code", demand.getId());
|
detailRow.put("source_bill_code", demand.getId());
|
||||||
//走调拨回传
|
//走调拨回传
|
||||||
|
|||||||
Reference in New Issue
Block a user