优化条码重复的校验规则

This commit is contained in:
季圣华 2022-03-17 00:11:42 +08:00
parent d923c8f11a
commit 06f6c4a4fb
3 changed files with 50 additions and 23 deletions

View File

@ -88,6 +88,10 @@ public interface MaterialMapperEx {
List<MaterialVo4Unit> getMaterialByBarCode(@Param("barCodeArray") String [] barCodeArray);
List<MaterialVo4Unit> getMaterialByBarCodeAndWithOutMId(
@Param("barCodeArray") String [] barCodeArray,
@Param("mId") Long mId);
List<MaterialVo4Unit> getListWithStock(
@Param("depotList") List<Long> depotList,
@Param("idList") List<Long> idList,

View File

@ -506,17 +506,6 @@ public class MaterialService {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_NOT_INTEGER_MSG, manyBarCode));
}
//校验条码是否存在
List<MaterialVo4Unit> basicMaterialList = getMaterialByBarCode(barCode);
if(basicMaterialList!=null && basicMaterialList.size()>0) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EXISTS_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_EXISTS_MSG, barCode));
}
List<MaterialVo4Unit> otherMaterialList = getMaterialByBarCode(manyBarCode);
if(otherMaterialList!=null && otherMaterialList.size()>0) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EXISTS_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_EXISTS_MSG, manyBarCode));
}
JSONObject materialExObj = new JSONObject();
JSONObject basicObj = new JSONObject();
basicObj.put("barCode", barCode);
@ -603,12 +592,7 @@ public class MaterialService {
basicMaterialExtend.setCreateSerial(user.getLoginName());
basicMaterialExtend.setUpdateSerial(user.getLoginName());
Long meId = materialExtendService.selectIdByMaterialIdAndDefaultFlag(mId, "1");
if(meId==0L){
materialExtendMapper.insertSelective(basicMaterialExtend);
} else {
basicMaterialExtend.setId(meId);
materialExtendMapper.updateByPrimaryKeySelective(basicMaterialExtend);
}
changeMaterialExtend(mId, basicMaterialExtend, meId);
}
if(StringUtil.isExist(materialExObj.get("other"))) {
String otherStr = materialExObj.getString("other");
@ -620,12 +604,7 @@ public class MaterialService {
otherMaterialExtend.setCreateSerial(user.getLoginName());
otherMaterialExtend.setUpdateSerial(user.getLoginName());
Long meId = materialExtendService.selectIdByMaterialIdAndDefaultFlag(mId, "0");
if(meId==0L){
materialExtendMapper.insertSelective(otherMaterialExtend);
} else {
otherMaterialExtend.setId(meId);
materialExtendMapper.updateByPrimaryKeySelective(otherMaterialExtend);
}
changeMaterialExtend(mId, otherMaterialExtend, meId);
}
//给商品初始化库存getAllListWithStock
Map<Long, BigDecimal> stockMap = m.getStockMap();
@ -657,6 +636,28 @@ public class MaterialService {
return info;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void changeMaterialExtend(Long mId, MaterialExtend materialExtend, Long meId) {
if(meId==0L){
//校验条码是否存在
List<MaterialVo4Unit> basicMaterialList = getMaterialByBarCode(materialExtend.getBarCode());
if(basicMaterialList!=null && basicMaterialList.size()>0) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EXISTS_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_EXISTS_MSG, materialExtend.getBarCode()));
}
materialExtendMapper.insertSelective(materialExtend);
} else {
//校验条码是否存在
List<MaterialVo4Unit> basicMaterialList = getMaterialByBarCodeAndWithOutMId(materialExtend.getBarCode(), mId);
if(basicMaterialList!=null && basicMaterialList.size()>0) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EXISTS_CODE,
String.format(ExceptionConstants.MATERIAL_BARCODE_EXISTS_MSG, materialExtend.getBarCode()));
}
materialExtend.setId(meId);
materialExtendMapper.updateByPrimaryKeySelective(materialExtend);
}
}
/**
* 根据条件返回产品列表
* @param name
@ -884,6 +885,11 @@ public class MaterialService {
return materialMapperEx.getMaterialByBarCode(barCodeArray);
}
public List<MaterialVo4Unit> getMaterialByBarCodeAndWithOutMId(String barCode, Long mId) {
String [] barCodeArray=barCode.split(",");
return materialMapperEx.getMaterialByBarCodeAndWithOutMId(barCodeArray, mId);
}
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);

View File

@ -319,6 +319,23 @@
order by me.id desc
</select>
<select id="getMaterialByBarCodeAndWithOutMId" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultAndUnitMap">
select m.*,u.name unit_name, me.id meId,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,
me.wholesale_decimal, me.low_decimal, me.sku
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_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
where
me.bar_code in (
<foreach collection="barCodeArray" item="barCode" separator=",">
#{barCode}
</foreach>
)
and me.material_id!=#{mId}
and ifnull(m.delete_flag,'0') !='1'
order by me.id desc
</select>
<update id="setUnitIdToNull">
update jsh_material
set unit_id = null