|
@@ -41,6 +41,56 @@ public class DcProductServiceImpl implements IDcProductService {
|
|
|
private DcPsParamMapper dcPsParamMapper;
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除产品及其关联信息
|
|
|
+ * @param dcpId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public int delete(Long dcpId) {
|
|
|
+ try {
|
|
|
+ // 1. 查询产品关联的系统信息(用于删除工程系统关联)
|
|
|
+ List<Map> systemInfos = dcSystemProductMapper.selectWorkSystemByProductId(dcpId);
|
|
|
+
|
|
|
+ // 2. 删除工程系统关联
|
|
|
+ for (Map<String, Object> systemInfo : systemInfos) {
|
|
|
+ int wrId = Integer.parseInt(systemInfo.get("wr_id").toString());
|
|
|
+ int sysNo = Integer.parseInt(systemInfo.get("sys_no").toString());
|
|
|
+ dcWorkSystemMapper.deleteByWrIdAndSysId(wrId, sysNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 删除系统产品关联
|
|
|
+ for (Map<String, Object> systemInfo : systemInfos) {
|
|
|
+ int sysNo = Integer.parseInt(systemInfo.get("sys_no").toString());
|
|
|
+ dcSystemProductMapper.deleteBySysNoAndDcpId(sysNo, dcpId.intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 删除产品规格参数
|
|
|
+ // 4.1 先查询该产品的所有规格
|
|
|
+ DcSpec dcSpecQuery = new DcSpec();
|
|
|
+ dcSpecQuery.setPs_p_id(dcpId.intValue()); // 如果 DcSpec 中的 ps_p_id 是 Integer 类型,需要转换
|
|
|
+ List<DcSpec> specs = dcSpecMapper.selectDcSpecList(dcSpecQuery);
|
|
|
+
|
|
|
+ // 4.2 删除规格参数(如果没有其他产品使用这些参数)
|
|
|
+ for (DcSpec spec : specs) {
|
|
|
+ String psNo = spec.getPs_no();
|
|
|
+ // 检查是否有其他产品使用这个规格参数
|
|
|
+ if (!dcSpecMapper.existsOtherProductSpec(dcpId.intValue(), psNo)) {
|
|
|
+ dcPsParamMapper.deleteDcPsParamByPspMode(psNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4.3 删除产品规格关联
|
|
|
+ dcSpecMapper.deleteByProductId(dcpId.intValue());
|
|
|
+
|
|
|
+ // 5. 删除产品基本信息
|
|
|
+ dcProductMapper.deleteDcProductById(dcpId);
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|