Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

小么熊🐻 vor 4 Jahren
Ursprung
Commit
91cc201b45

+ 4 - 2
zzjs-admin/src/main/java/com/miaxis/app/controller/collection/AppletCollectionInfoController.java

@@ -68,10 +68,12 @@ public class AppletCollectionInfoController extends BaseController {
     @DeleteMapping(value = "/cancelCollection/{ids}")
     @ApiOperation("取消收藏")
     public Response cancelCollection(
-            @ApiParam(name = "ids", value = "收藏ids参数", required = true)
+            @ApiParam(name = "ids", value = "商家id", required = true)
             @PathVariable Long[] ids
     ){
-        return toResponse(collectionInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+        //当前用户
+        UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
+        return collectionInfoService.removeCollectionByIds(userInfo.getId(),ids);
     }
 
 

+ 8 - 35
zzjs-admin/src/main/java/com/miaxis/app/controller/customer/AppletCustomerInfoController.java

@@ -3,7 +3,9 @@ package com.miaxis.app.controller.customer;
 import com.miaxis.collection.service.ICollectionInfoService;
 import com.miaxis.common.constant.Constants;
 import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.entity.UserInfo;
 import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.common.utils.SecurityUtils;
 import com.miaxis.customer.domain.CustomerInfo;
 import com.miaxis.customer.service.ICustomerInfoService;
 import com.miaxis.customer.vo.ExhibitionCustomerInfoVo;
@@ -29,51 +31,22 @@ public class AppletCustomerInfoController extends BaseController {
 
 
     /**
-     * 查询客户信息列表
-     */
-    @GetMapping("/list")
-    @ApiOperation("查询客户信息列表")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "int", paramType = "query", required = false),
-            @ApiImplicitParam(name = "pageSize", value = "每页数据量", dataType = "int", paramType = "query", required = false),
-    })
-    public ResponsePageInfo<CustomerInfo> list(@ModelAttribute CustomerInfo customerInfo) {
-        startPage();
-        List<CustomerInfo> list = customerInfoService.selectCustomerInfoList(customerInfo);
-        return toResponsePageInfo(list);
-    }
-
-
-    /**
-     * 查询所属品类商家
+     * 查询商家列表
      */
     @GetMapping(value = "/getCustomerListByProductId/{id}")
-    @ApiOperation("查询所属品类商家")
+    @ApiOperation("查询商家列表")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "int", paramType = "query", required = false),
             @ApiImplicitParam(name = "pageSize", value = "每页数据量", dataType = "int", paramType = "query", required = false),
     })
     public ResponsePageInfo<ExhibitionCustomerInfoVo> getCustomerListByProductId(
-            @ApiParam(name = "id", value = "品类id", required = true)
+            @ApiParam(name = "id", value = "品类id (0:精选列表)", required = true)
             @PathVariable("id") Long id
     ) {
         startPage();
-        List<ExhibitionCustomerInfoVo> list = customerInfoService.getCustomerListByProductId(id);
-        return toResponsePageInfo(list);
-    }
-
-    /**
-     * 查询精选商家列表 根据收藏数排行
-     */
-    @GetMapping(value = "/getCustomerListByCollectionCount")
-    @ApiOperation("查询精选商家列表")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "int", paramType = "query", required = false),
-            @ApiImplicitParam(name = "pageSize", value = "每页数据量", dataType = "int", paramType = "query", required = false),
-    })
-    public ResponsePageInfo<ExhibitionCustomerInfoVo> getCustomerListByCollectionCount() {
-        startPage();
-        List<ExhibitionCustomerInfoVo> list = customerInfoService.getCustomerListByCollectionCount();
+        //获取当前用户
+        UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
+        List<ExhibitionCustomerInfoVo> list = customerInfoService.getCustomerListByProductId(id,userInfo.getId());
         return toResponsePageInfo(list);
     }
 

+ 7 - 0
zzjs-service/src/main/java/com/miaxis/collection/service/ICollectionInfoService.java

@@ -32,4 +32,11 @@ public interface ICollectionInfoService extends IService<CollectionInfo> {
      */
     Response collectionBusiness(UserInfo userInfo, Long id);
 
+    /**
+     * 取消收藏
+     * @param userId
+     * @param ids
+     * @return
+     */
+    Response removeCollectionByIds(Long userId,Long[] ids);
 }

+ 40 - 7
zzjs-service/src/main/java/com/miaxis/collection/service/impl/CollectionInfoServiceImpl.java

@@ -7,12 +7,14 @@ import com.miaxis.collection.service.ICollectionInfoService;
 import com.miaxis.collection.vo.CollectionCustomerVo;
 import com.miaxis.common.core.domain.Response;
 import com.miaxis.common.core.domain.entity.UserInfo;
+import com.miaxis.common.exception.CustomException;
 import com.miaxis.customer.mapper.CustomerInfoMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -48,15 +50,46 @@ public class CollectionInfoServiceImpl extends ServiceImpl<CollectionInfoMapper,
      * @return
      */
     @Override
-    @SneakyThrows
     @Transactional(rollbackFor = Exception.class)
     public Response collectionBusiness(UserInfo userInfo, Long id) {
-        //保存收藏表
-        CollectionInfo collectionInfo = new CollectionInfo();
-        collectionInfo.setUserId(userInfo.getId());
-        collectionInfo.setCustomerId(id);
-        collectionInfoMapper.insert(collectionInfo);
-        return Response.success();
+        try{
+            List<CollectionInfo> infoList = collectionInfoMapper.selectByMap(new HashMap<String, Object>() {{
+                put("user_id", userInfo.getId());
+                put("customer_id", id);
+            }});
+            if (infoList.isEmpty()){
+                //保存收藏表
+                CollectionInfo collectionInfo = new CollectionInfo();
+                collectionInfo.setUserId(userInfo.getId());
+                collectionInfo.setCustomerId(id);
+                collectionInfoMapper.insert(collectionInfo);
+            }
+            return Response.success();
+        }catch (Exception e){
+            throw new CustomException("系统异常");
+        }
+    }
+
+    /**
+     * 取消收藏
+     * @param userId 当前用户id
+     * @param ids 商家id
+     * @return
+     */
+    @Override
+    public Response removeCollectionByIds(Long userId, Long[] ids) {
+        try{
+            for (Long id : ids) {
+                collectionInfoMapper.deleteByMap(new HashMap<String, Object>(){{
+                    put("user_id",userId);
+                    put("customer_id",id);
+                }});
+            }
+            return Response.success();
+        }catch (Exception e){
+            throw new CustomException("系统异常");
+        }
+
     }
 
 

+ 3 - 7
zzjs-service/src/main/java/com/miaxis/customer/mapper/CustomerInfoMapper.java

@@ -33,17 +33,13 @@ public interface CustomerInfoMapper extends BaseMapper<CustomerInfo> {
     CustomerInfoVo getCustomerById(@Param("id") Long id);
 
     /**
-     * 查询所属品类商家
+     * 查询商家列表
      * @param productId
+     * @param userId
      * @return
      */
-    List<ExhibitionCustomerInfoVo> getCustomerListByProductId(@Param("productId") Long productId);
+    List<ExhibitionCustomerInfoVo> getCustomerListByProductId(@Param("productId") Long productId,@Param("userId")Long userId);
 
-    /**
-     * 查询精选商家列表 根据收藏数排行
-     * @return
-     */
-    List<ExhibitionCustomerInfoVo> getCustomerListByCollectionCount();
 
     /**
      * 查询用户收藏列表

+ 3 - 8
zzjs-service/src/main/java/com/miaxis/customer/service/ICustomerInfoService.java

@@ -48,17 +48,12 @@ public interface ICustomerInfoService extends IService<CustomerInfo>{
 
     /**
      * applet
-     * 查询所属品类商家
+     * 查询商家列表
      * @param productId
+     * @param userId
      * @return
      */
-    List<ExhibitionCustomerInfoVo> getCustomerListByProductId(Long productId);
+    List<ExhibitionCustomerInfoVo> getCustomerListByProductId(Long productId,Long userId);
 
 
-    /**
-     * 查询精选商家列表 根据收藏数排行
-     * @return
-     */
-    List<ExhibitionCustomerInfoVo> getCustomerListByCollectionCount();
-
 }

+ 4 - 14
zzjs-service/src/main/java/com/miaxis/customer/service/impl/CustomerInfoServiceImpl.java

@@ -83,26 +83,16 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
 
     /**
      * applet
-     * 查询所属品类商家
+     * 查询商家列表
      * @param productId
+     * @param userId
      * @return
      */
     @Override
-    public List<ExhibitionCustomerInfoVo> getCustomerListByProductId(Long productId) {
-        return customerInfoMapper.getCustomerListByProductId(productId);
+    public List<ExhibitionCustomerInfoVo> getCustomerListByProductId(Long productId,Long userId) {
+        return customerInfoMapper.getCustomerListByProductId(productId,userId);
     }
 
 
 
-    /**
-     * applet
-     * 查询精选商家列表 根据收藏数排行
-     * @return
-     */
-    @Override
-    public List<ExhibitionCustomerInfoVo> getCustomerListByCollectionCount() {
-        return customerInfoMapper.getCustomerListByCollectionCount();
-    }
-
-
 }

+ 3 - 0
zzjs-service/src/main/java/com/miaxis/customer/vo/ExhibitionCustomerInfoVo.java

@@ -49,5 +49,8 @@ public class ExhibitionCustomerInfoVo extends BaseBusinessEntity{
     @ApiModelProperty(value = "收藏数量")
     private Integer collectionCount;
 
+    @ApiModelProperty(value = "是否收藏 0:未收藏 1:已收藏")
+    private String collectionStatus;
+
 
 }

+ 20 - 28
zzjs-service/src/main/resources/mapper/customer/CustomerInfoMapper.xml

@@ -115,34 +115,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ci.applet_introduce,
         ci.create_time,
         ci.update_time,
+        (select COUNT(1) from collection_info coi where coi.customer_id = ci.id) as collectionCount,
+        (SELECT COUNT(1) from collection_info coi where coi.user_id = #{userId} and customer_id = ci.id) as collectionStatus,
         ci.status
         from customer_info ci
         LEFT JOIN file_info f1 on f1.file_id = ci.corporate_logo
         LEFT JOIN file_info f2 on f2.file_id = ci.applet_logo
         LEFT JOIN file_info f3 on f3.file_id = ci.applet_qr_code
-        WHERE ci.industry_type = #{productId}
-
-    </select>
-
+        <where>
+            1=1
+            <choose>
+                <when test="productId == 0">
+                    ORDER BY collectionCount DESC
+                </when>
+                <otherwise>
+                    and ci.industry_type = #{productId}
+                </otherwise>
+            </choose>
+        </where>
 
-    <select id="getCustomerListByCollectionCount" resultType="com.miaxis.customer.vo.ExhibitionCustomerInfoVo">
-        SELECT
-        ci.id,
-        (select COUNT(1) from collection_info coi where coi.customer_id = ci.id) as collectionCount,
-        ci.corporate_name,
-        f1.file_url as corporateLogoFileUrl,
-        ci.applet_address,
-        f2.file_url as appletLogoFileUrl,
-        f3.file_url as appletQrCodeFileUrl,
-        ci.applet_introduce,
-        ci.create_time,
-        ci.update_time,
-        ci.status
-        FROM `customer_info` ci
-        LEFT JOIN file_info f1 on f1.file_id = ci.corporate_logo
-        LEFT JOIN file_info f2 on f2.file_id = ci.applet_logo
-        LEFT JOIN file_info f3 on f3.file_id = ci.applet_qr_code
-        ORDER BY collectionCount DESC
     </select>
 
 
@@ -158,12 +149,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ci.applet_introduce,
         coi.create_time,
         ci.status
-        FROM `customer_info` ci
-        LEFT JOIN file_info f1 on f1.file_id = ci.corporate_logo
-        LEFT JOIN file_info f2 on f2.file_id = ci.applet_logo
-        LEFT JOIN file_info f3 on f3.file_id = ci.applet_qr_code
-        LEFT JOIN collection_info coi ON coi.customer_id = ci.id
-        WHERE ci.id IN ( select coi.customer_id from collection_info coi where coi.user_id = #{id})
+        FROM `user_info` ui
+	    LEFT JOIN collection_info coi ON coi.user_id = ui.id
+	    LEFT JOIN customer_info ci ON coi.customer_id = ci.id
+	    LEFT JOIN file_info f1 ON f1.file_id = ci.corporate_logo
+	    LEFT JOIN file_info f2 ON f2.file_id = ci.applet_logo
+	    LEFT JOIN file_info f3 ON f3.file_id = ci.applet_qr_code
+        WHERE ui.id = #{id}
 
     </select>