Browse Source

已被物料绑定,不能删除

master
han\hanst 2 weeks ago
parent
commit
fe6928c3bf
  1. 6
      src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java
  2. 23
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  3. 14
      src/main/resources/mapper/ecss/CoDelMapper.xml
  4. 3
      src/main/resources/mapper/part/PartInformationMapper.xml

6
src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java

@ -118,6 +118,12 @@ public interface CoDelMapper {
void deleteHsCode(EcssHsCodeData inData);
/**
* 按工厂+BU+品名+品牌查询已绑定该HS品名的物料编码
* 删除品名前必须先拦截避免物料上的品名引用悬空
*/
List<String> listPartNosBoundByHsCode(EcssHsCodeData inData);
List<PropertyItem> searchPropertiesItemList(@Param("site") String site,
@Param("itemNo")String itemNo,
@Param("buNo") String buNo,

23
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java

@ -407,6 +407,29 @@ public class CoDelServiceImpl implements CoDelService {
@Override
@Transactional
public void deleteHsCode(EcssHsCodeData data) {
if (StringUtils.isBlank(data.getHsCodeDesc()) || StringUtils.isBlank(data.getBuNo())) {
throw new RuntimeException("品名或BU不能为空。");
}
if (StringUtils.isBlank(data.getSite())) {
data.setSite(coDelMapper.getSiteByBu(data.getBuNo()));
}
if (StringUtils.isBlank(data.getBrand())) {
data.setBrand("无");
}
// 删除前按工厂+BU+品名+品牌校验物料绑定有引用则禁止删除避免物料 HS 品名悬空
List<String> boundPartNos = coDelMapper.listPartNosBoundByHsCode(data);
if (boundPartNos != null && !boundPartNos.isEmpty()) {
int total = boundPartNos.size();
int displayLimit = 30;
List<String> displayList = total > displayLimit ? boundPartNos.subList(0, displayLimit) : boundPartNos;
String partNoText = String.join("、", displayList);
String suffix = total > displayLimit ? " 等,共" + total + "个" : "";
log.warn("删除HS品名失败,存在物料绑定. site={}, buNo={}, hsCodeDesc={}, brand={}, partCount={}",
data.getSite(), data.getBuNo(), data.getHsCodeDesc(), data.getBrand(), total);
throw new RuntimeException("品名【" + data.getHsCodeDesc() + "】品牌【" + data.getBrand()
+ "】已被物料(" + partNoText + suffix+")绑定,不能删除。");
}
PartSubPropertiesValueData propertiesData = new PartSubPropertiesValueData();
propertiesData.setSite(data.getSite());
propertiesData.setBuNo(data.getBuNo());

14
src/main/resources/mapper/ecss/CoDelMapper.xml

@ -420,6 +420,17 @@
delete from ecss_hsCode where site=#{site} and buNo=#{buNo} and hsCodeDesc=#{hsCodeDesc} and ISNULL(brand,'无') = ISNULL(#{brand},'无')
</select>
<!-- 物料绑定以 Part.hsCodeDesc+brand 为准,需与品名档案唯一键保持一致 -->
<select id="listPartNosBoundByHsCode" resultType="java.lang.String">
select distinct a.part_no
from Part a
where a.site = #{site}
and a.sourceBu = #{buNo}
and a.hsCodeDesc = #{hsCodeDesc}
and ISNULL(a.brand, '无') = ISNULL(#{brand}, '无')
order by a.part_no
</select>
<select id="searchPropertiesItemList" resultType="com.xujie.sys.modules.attrbute.entity.PropertyItem">
select
id,site,bu_no,item_no,item_type,item_desc,default_value,value_type,value_type_db,value_choose_flag,min_value,max_value,
@ -2180,6 +2191,9 @@ create_by,create_date,update_by,update_date
<if test = "query.partDesc != null and query.partDesc != ''">
AND a.part_desc like '%' + #{query.partDesc} + '%'
</if>
<if test = "query.hsCodeDesc != null and query.hsCodeDesc != ''">
AND a.hsCodeDesc like '%' + #{query.hsCodeDesc} + '%'
</if>
<if test = "query.sku != null and query.sku != ''">
AND a.sku like '%' + #{query.sku} + '%'
</if>

3
src/main/resources/mapper/part/PartInformationMapper.xml

@ -127,6 +127,9 @@
<if test = "query.partDesc != null and query.partDesc != ''">
AND a.part_desc like '%' + #{query.partDesc} + '%'
</if>
<if test = "query.hsCodeDesc != null and query.hsCodeDesc != ''">
AND a.hsCodeDesc like '%' + #{query.hsCodeDesc} + '%'
</if>
<if test = "query.sku != null and query.sku != ''">
AND a.sku like '%' + #{query.sku} + '%'
</if>

Loading…
Cancel
Save