Quellcode durchsuchen

Merge branch 'dev-feat' of https://e.coding.net/chuanghaikeji/moxuanyunshangwaimai/backend into dev-feat

夏文涛 vor 1 Jahr
Ursprung
Commit
c608846bb0

+ 27 - 1
src/main/java/com/sqx/modules/chats/controller/ChatsController.java

@@ -37,8 +37,34 @@ public class ChatsController {
     @GetMapping("/list")
     @ApiOperation("商家端会话列表")
     public Result findAll(@ApiParam("店铺id(总后台商户传0)") @DecryptParam Long storeId,
+                          @ApiParam("用户类型(0全部 1用户 2 骑手 3商家)") @DecryptParam(required = false) Long type,
+                          @ApiParam("关键字") @DecryptParam(required = false) String keyWord,
+                          @ApiParam("开始时间") @DecryptParam(required = false) String starTime,
+                          @ApiParam("结束时间") @DecryptParam(required = false) String endTime,
                           @ApiParam("用户昵称") @DecryptParam(required = false) String userName) {
-        return service.findAll(storeId, userName);
+        return service.findAll(storeId, keyWord,type,starTime,endTime);
+    }
+
+    @GetMapping("/listRead")
+    @ApiOperation("商家端已读会话列表")
+    public Result findRead(@ApiParam("店铺id(总后台商户传0)") @DecryptParam Long storeId,
+                           @ApiParam("用户类型") @DecryptParam(required = false) Long type,
+                           @ApiParam("关键字") @DecryptParam(required = false) String keyWord,
+                           @ApiParam("开始时间") @DecryptParam(required = false) String starTime,
+                           @ApiParam("结束时间") @DecryptParam(required = false) String endTime,
+                          @ApiParam("用户昵称") @DecryptParam(required = false) String userName) {
+        return service.findRead(storeId, keyWord,type,starTime,endTime);
+    }
+
+    @GetMapping("/listUnRead")
+    @ApiOperation("商家端未读会话列表")
+    public Result findUnRead(@ApiParam("店铺id(总后台商户传0)") @DecryptParam Long storeId,
+                             @ApiParam("用户类型") @DecryptParam(required = false) Long type,
+                             @ApiParam("关键字") @DecryptParam(required = false) String keyWord,
+                             @ApiParam("开始时间") @DecryptParam(required = false) String starTime,
+                             @ApiParam("结束时间") @DecryptParam(required = false) String endTime,
+                          @ApiParam("用户昵称") @DecryptParam(required = false) String userName) {
+        return service.findUnRead(storeId, keyWord,type,starTime,endTime);
     }
 
     @GetMapping("/userList")

+ 4 - 0
src/main/java/com/sqx/modules/chats/entity/Chats.java

@@ -43,4 +43,8 @@ public class Chats implements Serializable {
     private String content; //聊天内容
     @Transient
     private String contentTime; //消息时间
+    @Transient
+    private String phone; //手机号
+    @Transient
+    private Integer userType; //用户类型 1用户 2骑手
 }

+ 6 - 0
src/main/java/com/sqx/modules/chats/respository/ChatRepository.java

@@ -2,6 +2,8 @@ package com.sqx.modules.chats.respository;
 
 
 import com.sqx.modules.chats.entity.Chats;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
@@ -10,6 +12,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -17,6 +20,8 @@ import java.util.List;
 import java.util.Map;
 
 @Repository
+@Mapper
+@Component
 public interface ChatRepository extends JpaRepository<Chats, Long> {
 
     //条件查询带分页
@@ -74,4 +79,5 @@ public interface ChatRepository extends JpaRepository<Chats, Long> {
     @Transactional
     @Query(value = "update Chats s set s.userCount=0 where s.chatId=:chatId")
     Integer userCount(@Param("chatId") Long chatId);
+
 }

+ 92 - 0
src/main/java/com/sqx/modules/chats/respository/ChatsMapper.java

@@ -0,0 +1,92 @@
+package com.sqx.modules.chats.respository;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sqx.modules.chats.entity.Chats;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Map;
+
+@Mapper
+@Component
+public interface ChatsMapper extends BaseMapper<Chats> {
+
+    @Select({"<script>" +
+            "select c.*,tu.phone ,tu.user_type  from chats c left join  tb_user tu  on c.user_id =tu.user_id where c.user_id is not null " +
+            " <if test='type != null and type != \"\" and type != 3 and type != 0'>"+
+            "and tu.user_type =#{type} " +
+            " </if>"+
+            " <if test='type != null and type == 3'>"+
+            "and c.is_shop =1 " +
+            " </if>"+
+            " <if test='starTime != null and starTime != \"\" '>"+
+            "and c.create_time >#{starTime} " +
+            " </if>"+
+            " <if test='endTime != null and endTime != \"\" '>"+
+            "and #{endTime}> c.create_time " +
+            " </if>"+
+            " <if test='userName != null and userName != \"\" '>"+
+            "and (tu.phone like '%${userName}%' or c.user_name like '%${userName}%') " +
+            " </if>"+
+            "and store_id =#{storeId} " +
+            "order by c.create_time desc" +
+            "</script>"})
+    List<Chats> findAll(Long storeId, String userName, Long type, String starTime, String endTime);
+
+    @Select({"<script>" +
+            "select c.*,tu.phone ,tu.user_type  from chats c left join  tb_user tu  on c.user_id =tu.user_id where c.user_id is not null " +
+            " <if test='type != null and type != \"\" and type != 3 and type != 0'>"+
+            "and tu.user_type =#{type} " +
+            " </if>"+
+            " <if test='type != null and type == 3'>"+
+            "and c.is_shop =1 " +
+            " </if>"+
+            " <if test='starTime != null and starTime != \"\" '>"+
+            "and c.create_time >#{starTime} " +
+            " </if>"+
+            " <if test='endTime != null and endTime != \"\" '>"+
+            "and #{endTime}> c.create_time " +
+            " </if>"+
+            " <if test='userName != null and userName != \"\" '>"+
+            "and (tu.phone like '%${userName}%' or c.user_name like '%${userName}%') " +
+            " </if>"+
+            "and store_id =#{storeId} and c.store_count =0 " +
+            "order by c.create_time desc" +
+            "</script>"})
+    List<Chats> findRead(Long storeId, String userName, Long type, String starTime, String endTime);
+
+    @Select({"<script>" +
+            "select c.*,tu.phone ,tu.user_type  from chats c left join  tb_user tu  on c.user_id =tu.user_id where c.user_id is not null " +
+            " <if test='type != null and type != \"\" and type != 3 and type != 0'>"+
+            "and tu.user_type =#{type} " +
+            " </if>"+
+            " <if test='type != null and type == 3'>"+
+            "and c.is_shop =1 " +
+            " </if>"+
+            " <if test='starTime != null and starTime != \"\" '>"+
+            "and c.create_time >#{starTime} " +
+            " </if>"+
+            " <if test='endTime != null and endTime != \"\" '>"+
+            "and #{endTime}> c.create_time " +
+            " </if>"+
+            " <if test='userName != null and userName != \"\" '>"+
+            "and (tu.phone like '%${userName}%' or c.user_name like '%${userName}%') " +
+            " </if>"+
+            "and store_id =#{storeId}  and (c.store_count !=0 or c.store_count is null)" +
+            "order by c.create_time desc" +
+            "</script>"})
+    List<Chats> findUnRead(Long storeId, String userName, Long type, String starTime, String endTime);
+}

+ 3 - 1
src/main/java/com/sqx/modules/chats/service/ChatsService.java

@@ -19,7 +19,9 @@ public interface ChatsService {
      * @param storeId
      * @return
      */
-    Result findAll(Long storeId, String userName);
+    Result findAll(Long storeId, String userName,Long type,String starTime,String endTime);
+    Result findRead(Long storeId, String userName,Long type,String starTime,String endTime);
+    Result findUnRead(Long storeId, String userName,Long type,String starTime,String endTime);
 
     /**
      * 用户端会话列表

+ 53 - 11
src/main/java/com/sqx/modules/chats/service/ChatsServiceImpl.java

@@ -5,6 +5,7 @@ import com.sqx.modules.chats.entity.Chats;
 import com.sqx.modules.chats.entity.ChatsContent;
 import com.sqx.modules.chats.respository.ChatContentRepository;
 import com.sqx.modules.chats.respository.ChatRepository;
+import com.sqx.modules.chats.respository.ChatsMapper;
 import com.sqx.modules.chats.utils.DateUtil;
 import com.sqx.modules.chats.utils.Result;
 import com.sqx.modules.chats.utils.ResultUtil;
@@ -26,6 +27,8 @@ public class ChatsServiceImpl implements ChatsService {
     @Autowired
     private ChatRepository jpaRepository;
     @Autowired
+    private ChatsMapper chatsMapper;
+    @Autowired
     private ChatContentRepository chatContentRepository;
 
     @Override
@@ -46,20 +49,59 @@ public class ChatsServiceImpl implements ChatsService {
      * @return
      */
     @Override
-    public Result findAll(Long storeId, String userName) {
+    public Result findAll(Long storeId, String userName,Long type,String starTime,String endTime) {
         //构造自定义查询条件
-        Specification<Chats> queryCondition = new Specification<Chats>() {
-            @Override
-            public Predicate toPredicate(Root<Chats> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
-                List<Predicate> predicateList = new ArrayList<>();
-                predicateList.add(criteriaBuilder.equal(root.get("storeId"), storeId));
-                if (StringUtils.isNotEmpty(userName)){
-                    predicateList.add(criteriaBuilder.like(root.get("userName"), "%"+userName+"%"));
+//        Specification<Chats> queryCondition = new Specification<Chats>() {
+//            @Override
+//            public Predicate toPredicate(Root<Chats> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
+//                List<Predicate> predicateList = new ArrayList<>();
+//                predicateList.add(criteriaBuilder.equal(root.get("storeId"), storeId));
+//                if (StringUtils.isNotEmpty(userName)){
+//                    predicateList.add(criteriaBuilder.like(root.get("userName"), "%"+userName+"%"));
+//                }
+//                if (StringUtils.isNotEmpty(userName)){
+//                    predicateList.add(criteriaBuilder.like(root.get("userName"), "%"+userName+"%"));
+//                }
+//                if (StringUtils.isNotEmpty(userName)){
+//                    predicateList.add(criteriaBuilder.like(root.get("userName"), "%"+userName+"%"));
+//                }
+//                if (StringUtils.isNotEmpty(userName)){
+//                    predicateList.add(criteriaBuilder.like(root.get("userName"), "%"+userName+"%"));
+//                }
+//                return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
+//            }
+//        };
+        List<Chats> list = chatsMapper.findAll(storeId,userName,type,starTime,endTime);
+        //最新一条消息展示
+        List<ChatsContent> allContent = chatContentRepository.findAll();
+        for (Chats c : list) {
+            for (ChatsContent cc : allContent) {
+                if (c.getChatId().equals(cc.getChatId())){
+                    c.setContent(cc.getContent());
+                    c.setContentTime(cc.getCreateTime());
                 }
-                return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
             }
-        };
-        List<Chats> list = jpaRepository.findAll(queryCondition, Sort.by(new Sort.Order(Sort.Direction.DESC, "createTime")));
+        }
+        return ResultUtil.success(list);
+    }
+    @Override
+    public Result findRead(Long storeId, String userName,Long type,String starTime,String endTime) {
+        List<Chats> list = chatsMapper.findRead(storeId,userName,type,starTime,endTime);
+        //最新一条消息展示
+        List<ChatsContent> allContent = chatContentRepository.findAll();
+        for (Chats c : list) {
+            for (ChatsContent cc : allContent) {
+                if (c.getChatId().equals(cc.getChatId())){
+                    c.setContent(cc.getContent());
+                    c.setContentTime(cc.getCreateTime());
+                }
+            }
+        }
+        return ResultUtil.success(list);
+    }
+    @Override
+    public Result findUnRead(Long storeId, String userName,Long type,String starTime,String endTime) {
+        List<Chats> list = chatsMapper.findUnRead(storeId,userName,type,starTime,endTime);
         //最新一条消息展示
         List<ChatsContent> allContent = chatContentRepository.findAll();
         for (Chats c : list) {

+ 1 - 1
src/main/java/com/sqx/modules/coupon/dao/TbCouponUserDao.java

@@ -22,7 +22,7 @@ public interface TbCouponUserDao extends BaseMapper<TbCouponUser> {
 
     IPage<TbCouponUser> selectCouponByUserId(Page<TbCouponUser> pages, @Param("userId") Long userId,
                                              @Param("status") Integer status, @Param("phone") String phone,
-                                             @Param("shopName") String shopName,@Param("shopId") Long shopId);
+                                             @Param("shopName") String shopName,@Param("shopId") Long shopId,@Param("shopFlag") Integer shopFlag);
 
     int selectCountCoupon(Long userId);
 

+ 1 - 1
src/main/java/com/sqx/modules/coupon/service/TbCouponUserService.java

@@ -16,6 +16,6 @@ public interface TbCouponUserService extends IService<TbCouponUser> {
 
     Result buyCoupon(Long userId, Long couponId);
 
-    Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone,String shopName,Long shopId);
+    Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone,String shopName,Long shopId,Integer shopFlag);
 
 }

+ 2 - 2
src/main/java/com/sqx/modules/coupon/service/impl/TbTbCouponUserServiceImpl.java

@@ -123,9 +123,9 @@ public class TbTbCouponUserServiceImpl extends ServiceImpl<TbCouponUserDao, TbCo
     }
 
     @Override
-    public Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone,String shopName,Long shopId) {
+    public Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone,String shopName,Long shopId,Integer shopFalg) {
         Page<TbCouponUser> pages = new Page<>(page, limit);
-        PageUtils pageUtils = new PageUtils(tbCouponUserDao.selectCouponByUserId(pages, userId, status, phone,shopName,shopId));
+        PageUtils pageUtils = new PageUtils(tbCouponUserDao.selectCouponByUserId(pages, userId, status, phone,shopName,shopId,shopFalg));
         return Result.success().put("data", pageUtils);
     }
 }

+ 2 - 2
src/main/java/com/sqx/modules/datacentre/controller/DataCentreController.java

@@ -100,9 +100,9 @@ public class DataCentreController {
 
     @ApiOperation("查看用户拥有的优惠券")
     @GetMapping(value = "selectCouponByUserId")
-    public Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone,String shopName,Long shopId) {
+    public Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone,String shopName,Long shopId,Integer shopFlag/*是否平台券 1是 2否 0 全部 */) {
 
-        return tbCouponUserService.selectCouponByUserId(page, limit, userId, status, phone,shopName,shopId);
+        return tbCouponUserService.selectCouponByUserId(page, limit, userId, status, phone,shopName,shopId,shopFlag);
     }
 
     @ApiOperation("查看积分明细")

+ 6 - 0
src/main/resources/mapper/coupon/TbCouponUserMapper.xml

@@ -46,6 +46,12 @@
         <if test="shopId!=null">
             and tcu.shop_id=#{shopId}
         </if>
+        <if test="shopFlag!=null and shopFlag == 1">
+            and g.shop_id is null
+        </if>
+        <if test="shopFlag!=null and shopFlag == 2">
+            and g.shop_id is not null
+        </if>
         order by tcu.create_time desc
     </select>