Browse Source

朗通后台产品线管理——添加、修改(增加产品重名判断)

wangyu 6 years ago
parent
commit
277aa3c2b7

+ 8 - 0
diagbotman-service/src/main/java/com/diagbot/facade/LantoneProductFacade.java

@@ -62,6 +62,10 @@ public class LantoneProductFacade extends LantoneProductServiceImpl {
      * @return Boolean true
      */
     public Boolean addProducts(AddProductsVO addProductsVO) {
+        if(addProductsVO.getName().equals(this.selectProductByName(addProductsVO.getName()).getName())){
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "产品名称重复");
+        }
         LantoneProduct lantoneProduct = new LantoneProduct();
         BeanUtil.copyProperties(addProductsVO, lantoneProduct);
         lantoneProduct.setGmtCreate(DateUtil.now());
@@ -81,6 +85,10 @@ public class LantoneProductFacade extends LantoneProductServiceImpl {
      * @return Boolean true
      */
     public Boolean updateProduct(UpdateProductVO updateProductVO) {
+        if(updateProductVO.getName().equals(this.selectProductByName(updateProductVO.getName()).getName())){
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "产品名称重复");
+        }
         LantoneProduct lantoneProduct = this.getById(updateProductVO.getId());
         BeanUtil.copyProperties(updateProductVO, lantoneProduct);
         lantoneProduct.setModifier(UserUtils.getCurrentPrincipleID());

+ 7 - 0
diagbotman-service/src/main/java/com/diagbot/mapper/LantoneProductMapper.java

@@ -50,4 +50,11 @@ public interface LantoneProductMapper extends BaseMapper<LantoneProduct> {
      */
     List<LantoneProductWrapper> opendedProductByUserId(Long userId);
 
+    /**
+     * 根据产品名称查询产品
+     * @param productName
+     * @return
+     */
+    LantoneProduct selectProductByName(@Param("name") String productName);
+
 }

+ 7 - 0
diagbotman-service/src/main/java/com/diagbot/service/LantoneProductService.java

@@ -47,4 +47,11 @@ public interface LantoneProductService extends IService<LantoneProduct> {
      * @Date: 10:10 2018/9/20
      */
     List<LantoneProductWrapper> opendedProductByUserId(Long userId);
+
+    /**
+     * 根据产品名称查询产品
+     * @param productName
+     * @return
+     */
+    LantoneProduct selectProductByName(String productName);
 }

+ 5 - 0
diagbotman-service/src/main/java/com/diagbot/service/impl/LantoneProductServiceImpl.java

@@ -58,4 +58,9 @@ public class LantoneProductServiceImpl extends ServiceImpl<LantoneProductMapper,
     public List<LantoneProductWrapper> opendedProductByUserId(Long userId) {
         return baseMapper.opendedProductByUserId(userId);
     }
+
+    @Override
+    public LantoneProduct selectProductByName(String productName) {
+        return baseMapper.selectProductByName(productName);
+    }
 }

+ 5 - 1
diagbotman-service/src/main/resources/mapper/LantoneProductMapper.xml

@@ -43,7 +43,6 @@
         <result column="service_ids" property="serviceIds"/>
     </resultMap>
 
-    <!--根据用户id查询用户是否有开通产品-->
     <select id="productLines" resultType="com.diagbot.dto.ProductLineDTO">
         SELECT * FROM `diag_lantone_product` WHERE is_deleted = 'N'
     </select>
@@ -100,4 +99,9 @@
               and a.is_deleted='N' and b.is_deleted='N' and c.is_deleted='N' and d.is_deleted='N'
               and b.user_id=#{userId}  and c.user_id=#{userId}  and d.user_id=#{userId}
     </select>
+    
+    <select id="selectProductByName" resultMap="BaseResultMap">
+        SELECT * FROM `diag_lantone_product` WHERE `name`=#{name}
+    </select>
+
 </mapper>