cxd 6 mesiacov pred
rodič
commit
6f35ae62e4

+ 17 - 1
gqy-admin/src/main/java/com/gqy/web/controller/document/ProductController.java

@@ -69,7 +69,11 @@ public class ProductController extends BaseController {
     }
 
 
-
+    /**
+     * 列表
+     * @param maps
+     * @return
+     */
     @GetMapping("/list")
     public TableDataInfo list(@RequestParam Map<String, Object> maps) {
         // 开启分页
@@ -78,4 +82,16 @@ public class ProductController extends BaseController {
         return getDataTable(list);
     }
 
+
+
+    /**
+     * 删除产品
+     * @return
+     */
+    @GetMapping("/delete/{dcpId}")
+    public AjaxResultCQY delete(@PathVariable(value = "dcpId") Long dcpId) {
+        return AjaxResultCQY.success(iDcProductService.delete(dcpId));
+    }
+
+
 }

+ 11 - 0
gqy-system/src/main/java/com/gqy/document/mapper/DcProductMapper.java

@@ -1,6 +1,7 @@
 package com.gqy.document.mapper;
 
 import com.gqy.document.domain.DcProduct;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -10,6 +11,16 @@ import java.util.Map;
  */
 public interface DcProductMapper {
 
+
+
+    /**
+     * 批量删除产品对象 dc_product
+     *
+     * @param dcpIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteDcProductById(@Param("dcp_id")  Long dcp_id);
+
     /**
      * 更新产品对象 dc_product
      *

+ 6 - 0
gqy-system/src/main/java/com/gqy/document/mapper/DcSpecMapper.java

@@ -8,6 +8,12 @@ import java.util.List;
 public interface DcSpecMapper {
 
 
+    /**
+     * 校验产品规格编号是否唯一
+     */
+    boolean existsOtherProductSpec(@Param("productId") Integer productId, @Param("psNo") String psNo);
+
+
     /**
      * 批量新增产品规格
      */

+ 7 - 0
gqy-system/src/main/java/com/gqy/document/service/IDcProductService.java

@@ -11,6 +11,13 @@ import java.util.Map;
 public interface IDcProductService {
 
 
+    /**
+     * 删除产品
+     * @param dcpId
+     * @return
+     */
+    public int delete(Long dcpId);
+
     /**
      * 修改产品
      * @param params

+ 50 - 0
gqy-system/src/main/java/com/gqy/document/service/impl/DcProductServiceImpl.java

@@ -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;
+        }
+    }
 
 
     /**

+ 3 - 1
gqy-system/src/main/java/com/gqy/system/mapper/DcPsParamMapper.java

@@ -1,6 +1,7 @@
 package com.gqy.system.mapper;
 
 import com.gqy.document.domain.DcPsParam;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -50,7 +51,8 @@ public interface DcPsParamMapper {
      * @param psp_mode
      * @return
      */
-    public int deleteDcPsParamByPspMode(String psp_mode);
+    public int deleteDcPsParamByPspMode(@Param("psp_mode") String psp_mode);
+
 
 
 }

+ 1 - 1
gqy-system/src/main/resources/mapper/document/DcProductMapper.xml

@@ -152,7 +152,7 @@
         where dcp_id = #{dcp_id}
     </update>
 
-    <delete id="deleteDcProductById" parameterType="Integer">
+    <delete id="deleteDcProductById" parameterType="Long">
         delete from dc_product where dcp_id = #{dcp_id}
     </delete>
 

+ 13 - 11
gqy-system/src/main/resources/mapper/document/DcPsParamMapper.xml

@@ -16,18 +16,16 @@
 
 
 
-
-
     <select id="selectDcPsParamAndSpec" resultType="map" parameterType="java.util.Map">
         SELECT
         p.psp_name,
         p.psp_value,
         p.psp_type,
-        s.ps_id,
-        s.ps_p_id,
+        MIN(s.ps_id) as ps_id,
+        MIN(s.ps_p_id) as ps_p_id,
         s.ps_no,
-        s.ps_name,
-        s.dcb_id,
+        MIN(s.ps_name) as ps_name,
+        MIN(s.dcb_id) as dcb_id,
         p.psp_category
         FROM dc_ps_param p
         LEFT JOIN dc_p_spec s ON p.psp_mode = s.ps_no
@@ -44,17 +42,21 @@
             <if test="psp_name != null and psp_name != ''">
                 AND p.psp_name like concat('%', #{psp_name}, '%')
             </if>
-
             <if test="ps_p_id != null and ps_p_id != ''">
-                and s.ps_p_id = #{ps_p_id}
+                AND s.ps_p_id = #{ps_p_id}
             </if>
         </where>
+        GROUP BY
+        p.psp_name,
+        p.psp_value,
+        p.psp_type,
+        s.ps_no,
+        p.psp_category
+        ORDER BY MIN(s.ps_id) DESC
     </select>
 
-
-
     <sql id="selectDcPsParamVo">
-        select psp_id, psp_mode, psp_name, psp_value, dcb_id        from dc_ps_param
+        select psp_id, psp_mode, psp_name, psp_value, dcb_id, psp_type      from dc_ps_param
     </sql>
 
     <select id="selectDcPsParamList" parameterType="DcPsParam" resultMap="DcPsParamResult">

+ 9 - 0
gqy-system/src/main/resources/mapper/document/DcSpecMapper.xml

@@ -76,4 +76,13 @@
         delete from dc_p_spec where ps_id = #{ps_id}
     </delete>
 
+
+    <select id="existsOtherProductSpec" resultType="boolean">
+        select count(1) > 0
+        from dc_p_spec
+        where ps_no = #{psNo}
+          and ps_p_id != #{productId}
+    </select>
+
+
 </mapper>