Mr.qian преди 2 седмици
родител
ревизия
e35d6f8a72

+ 14 - 0
mall-service/src/main/java/com/txz/mall/controller/OrderController.java

@@ -9,6 +9,8 @@ import com.txz.mall.core.ResultCode;
 import com.txz.mall.enums.PinkOrderStatusEnum;
 import com.txz.mall.model.StoreOrder;
 import com.txz.mall.service.StoreOrderService;
+import com.txz.mall.service.StorePinkService;
+import com.txz.mall.web.vo.ProductCarouselVO;
 import dto.CreateOrderRequest;
 import dto.StoreOrderDTO;
 import dto.StoreOrderDeliveryDTO;
@@ -43,6 +45,9 @@ public class OrderController {
     @Resource
     private OrderServiceBusiness orderServiceBusiness;
     
+    @Resource
+    private StorePinkService storePinkService;
+    
     @PostMapping("/add")
     @ApiOperation(value = "创建订单")
     public Result add(@Validated @RequestBody CreateOrderRequest orderRequest) {
@@ -230,4 +235,13 @@ public class OrderController {
         storeOrderService.importDelivery(file, response);
         return Result.success();
     }
+    
+    /**
+     * 商品轮播
+     */
+    @GetMapping("carousel/{productId:^\\d+$}")
+    public Result<List<ProductCarouselVO>> carousel(@PathVariable("productId") Long productId) {
+        return Result.success(storePinkService.carousel(productId));
+    }
+    
 }

+ 3 - 1
mall-service/src/main/java/com/txz/mall/controller/appcontroller/AppNoticeController.java

@@ -55,7 +55,9 @@ public class AppNoticeController {
         LambdaQueryWrapper<Notice> eq = Wrappers.<Notice>lambdaQuery()
                 // .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData())
                 .eq(Notice::getUid, AuthService.getTokenUserId(null))
-                .eq(Notice::getUserDel, Boolean.FALSE);
+                .eq(Notice::getUserDel, Boolean.FALSE)
+                .orderByAsc(Notice::getReadFlag)
+                .orderByDesc(Notice::getCreateTime);
         if (ObjectUtil.isNotEmpty(type)) {
             eq.likeRight(Notice::getNoticeType, type.getData());
         }

+ 9 - 0
mall-service/src/main/java/com/txz/mall/dao/StorePinkMapper.java

@@ -1,7 +1,16 @@
 package com.txz.mall.dao;
 
 import com.txz.mall.core.Mapper;
+import com.txz.mall.dao.impl.StorePinkMapperImpl;
 import com.txz.mall.model.StorePink;
+import dto.ProductCarouselDTO;
+import org.apache.ibatis.annotations.SelectProvider;
+
+import java.util.List;
 
 public interface StorePinkMapper extends Mapper<StorePink> {
+    
+    @SelectProvider(type = StorePinkMapperImpl.class, method = "pinkByProductId")
+    List<ProductCarouselDTO> pinkByProductId(Long productId);
+    
 }

+ 20 - 0
mall-service/src/main/java/com/txz/mall/dao/impl/StorePinkMapperImpl.java

@@ -0,0 +1,20 @@
+package com.txz.mall.dao.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/27
+ */
+
+public class StorePinkMapperImpl {
+    
+    public String pinkByProductId(Long productId) {
+        if (ObjectUtil.isNotEmpty(productId)) {
+            return "SELECT uid, k_id FROM m_store_pink WHERE pid = #{productId} GROUP BY uid ORDER BY create_time DESC LIMIT 10";
+        } else {
+            return "SELECT uid, k_id FROM m_store_pink GROUP BY uid ORDER BY create_time DESC LIMIT 10";
+        }
+        
+    }
+}

+ 5 - 2
mall-service/src/main/java/com/txz/mall/dubbo/client/CifUserDubboServiceClient.java

@@ -3,11 +3,10 @@ package com.txz.mall.dubbo.client;
 import com.txz.cif.dto.UserDTO;
 import com.txz.cif.service.UserDubboService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.dubbo.config.annotation.Reference;
 import org.springframework.stereotype.Component;
 
-import java.io.Serializable;
+import java.util.List;
 
 @Slf4j
 @Component
@@ -26,4 +25,8 @@ public class CifUserDubboServiceClient {
     public UserDTO getUser(Long userId) {
         return userDubboService.getUser(userId);
     }
+    
+    public List<UserDTO> getUsersByIds(List<Long> userIds){
+        return userDubboService.getUsersByIds(userIds);
+    }
 }

+ 3 - 0
mall-service/src/main/java/com/txz/mall/service/StorePinkService.java

@@ -3,6 +3,7 @@ package com.txz.mall.service;
 import com.txz.mall.core.Service;
 import com.txz.mall.model.StoreOrder;
 import com.txz.mall.model.StorePink;
+import com.txz.mall.web.vo.ProductCarouselVO;
 import vo.StorePinkOngoingVO;
 
 import java.util.List;
@@ -39,4 +40,6 @@ public interface StorePinkService extends Service<StorePink> {
      * 已存在拼团列表
      */
     List<StorePinkOngoingVO> ongoingList(StorePink storePink);
+    
+    List<ProductCarouselVO> carousel(Long productId);
 }

+ 148 - 104
mall-service/src/main/java/com/txz/mall/service/impl/StorePinkServiceImpl.java

@@ -1,14 +1,16 @@
 package com.txz.mall.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.github.pagehelper.PageHelper;
+import com.txz.cif.dto.UserDTO;
 import com.txz.cif.param.AccomplishParam;
 import com.txz.mall.core.AbstractService;
 import com.txz.mall.core.ServiceException;
 import com.txz.mall.dao.StorePinkMapper;
-import com.txz.mall.dubbo.client.CifAccountDubboServiceClient;
+import com.txz.mall.dubbo.client.CifUserDubboServiceClient;
 import com.txz.mall.enums.PinkOrderStatusEnum;
 import com.txz.mall.model.StoreOrder;
 import com.txz.mall.model.StorePink;
@@ -16,9 +18,10 @@ import com.txz.mall.model.StorePinkSummary;
 import com.txz.mall.service.StorePinkService;
 import com.txz.mall.service.StorePinkSummaryService;
 import com.txz.mall.util.RandomUtil;
+import com.txz.mall.web.vo.ProductCarouselVO;
+import dto.ProductCarouselDTO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import tk.mybatis.mapper.entity.Condition;
 import tk.mybatis.mapper.entity.Example;
@@ -36,16 +39,14 @@ import java.util.stream.Collectors;
 @Transactional
 @Slf4j
 public class StorePinkServiceImpl extends AbstractService<StorePink> implements StorePinkService {
-
-
-
-
+    
+    
     @Resource
     private StorePinkMapper storePinkMapper;
-
+    
     @Resource
-    private CifAccountDubboServiceClient accountDubboServiceClient;
-
+    private CifUserDubboServiceClient userDubboServiceClient;
+    
     @Override
     public List<StorePink> getListByCidAndKid(Long cid, Long kid) {
         Condition condition = new Condition(StorePink.class);
@@ -56,18 +57,17 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
         condition.setOrderByClause("id DESC");
         return findByCondition(condition);
     }
-
-
-
+    
+    
     @Resource
     private StorePinkSummaryService storePinkSummaryService;
-
+    
     @Override
     @Transactional
     public void pinkSuccess(Long id, StoreOrder storeOrder) {
-
-
-        //现在这个方法每次支付的时候都会执行一次
+        
+        
+        // 现在这个方法每次支付的时候都会执行一次
         Date date = new Date();
         if (ObjectUtil.isNull(id)) {
             return;
@@ -79,86 +79,85 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
         storePink2.setStatus(2);
         storePink2.setStopTime(date);
         storePink2.setOrderStatus(PinkOrderStatusEnum.GROUP_ORDER_PAID.getKey());
-        log.info("storePink2:"+storePink2);
+        log.info("storePink2:" + storePink2);
         update(storePink2);
         memberList.add(teamPink);
-//        memberList.forEach(i -> {
-//            i.setStatus(2);
-//            i.setStopTime(date);
-//            update(i);
-//        });
-
-        //理论上在支付环节调用的时候不会出现拼团人数校验异常,所以这块调用这个方法的目的在于维护成团状态。 如果支付环节抛出了
-        //拼团校验异常则证明在 add时就有问题,没有挡住异常的拼团数据
+        //        memberList.forEach(i -> {
+        //            i.setStatus(2);
+        //            i.setStopTime(date);
+        //            update(i);
+        //        });
+        
+        // 理论上在支付环节调用的时候不会出现拼团人数校验异常,所以这块调用这个方法的目的在于维护成团状态。 如果支付环节抛出了
+        // 拼团校验异常则证明在 add时就有问题,没有挡住异常的拼团数据
         Boolean b = storePinkSummaryService.maintainQuantityStatusOfTheStorePinkSummary(teamPink.getSpsId());
-        if(b){
-        // 算出天选
-        theSelection(teamPink.getSpsId());
-
-        Condition condition = new Condition(StorePink.class);
-        Example.Criteria criteria = condition.createCriteria();
-        criteria.andEqualTo("isDelete", 0);
-        criteria.andEqualTo("orderId", teamPink.getOrderId());
-        criteria.andEqualTo("lId", 0);
-        List<StorePink> pinkList = findByCondition(condition);
-
-        //非天选之子给他退款
-        AccomplishParam param = new AccomplishParam();
-        param.setBizNo(teamPink.getOrderId());
-        param.setBizId(teamPink.getId().toString());
-        param.setUserIds(pinkList.stream().map(StorePink::getUid).collect(Collectors.toList()));
-        param.setAmount(teamPink.getPrice());
-        param.setTransTime(date);
-      //  accountDubboServiceClient.accomplishGroup(param);
+        if (b) {
+            // 算出天选
+            theSelection(teamPink.getSpsId());
+            
+            Condition condition = new Condition(StorePink.class);
+            Example.Criteria criteria = condition.createCriteria();
+            criteria.andEqualTo("isDelete", 0);
+            criteria.andEqualTo("orderId", teamPink.getOrderId());
+            criteria.andEqualTo("lId", 0);
+            List<StorePink> pinkList = findByCondition(condition);
+            
+            // 非天选之子给他退款
+            AccomplishParam param = new AccomplishParam();
+            param.setBizNo(teamPink.getOrderId());
+            param.setBizId(teamPink.getId().toString());
+            param.setUserIds(pinkList.stream().map(StorePink::getUid).collect(Collectors.toList()));
+            param.setAmount(teamPink.getPrice());
+            param.setTransTime(date);
+            //  accountDubboServiceClient.accomplishGroup(param);
         }
     }
-
-//    @Override
-//    public void theSelection(String orderId) {
-//        // 假设只有1个用户是天选
-//        long luckNum = 1;
-//
-//        Condition condition = new Condition(StorePink.class);
-//        Example.Criteria criteria = condition.createCriteria();
-//        criteria.andEqualTo("isDelete", 0);
-//        criteria.andEqualTo("orderId", orderId);
-//        // 排除团长
-////        criteria.andEqualTo("kId", 1);
-//        // 支付成功的
-//
-//        criteria.andEqualTo("status", 1);
-//        List<StorePink> list = findByCondition(condition);
-//        if (CollUtil.isEmpty(list)) {
-//            throw new ServiceException("没有拼团订单");
-//        }
-//        long count = list.stream().filter(i -> i.getLId().equals(1)).count();
-//        if (count >= luckNum) {
-//            throw new ServiceException("已有天选");
-//        }
-//
-//        List<Long> idCollect = list.stream().map(StorePink::getId).collect(Collectors.toList());
-//        List<Long> randomIds = RandomUtil.uniqueRandom(idCollect, (int) luckNum);
-//
-//        randomIds.forEach(i -> {
-//            StorePink luckPink = new StorePink();
-//            luckPink.setId(i);
-//            luckPink.setLId(1);
-//            update(luckPink);
-//        });
-//    }
-
-
+    
+    //    @Override
+    //    public void theSelection(String orderId) {
+    //        // 假设只有1个用户是天选
+    //        long luckNum = 1;
+    //
+    //        Condition condition = new Condition(StorePink.class);
+    //        Example.Criteria criteria = condition.createCriteria();
+    //        criteria.andEqualTo("isDelete", 0);
+    //        criteria.andEqualTo("orderId", orderId);
+    //        // 排除团长
+    
+    /// /        criteria.andEqualTo("kId", 1);
+    //        // 支付成功的
+    //
+    //        criteria.andEqualTo("status", 1);
+    //        List<StorePink> list = findByCondition(condition);
+    //        if (CollUtil.isEmpty(list)) {
+    //            throw new ServiceException("没有拼团订单");
+    //        }
+    //        long count = list.stream().filter(i -> i.getLId().equals(1)).count();
+    //        if (count >= luckNum) {
+    //            throw new ServiceException("已有天选");
+    //        }
+    //
+    //        List<Long> idCollect = list.stream().map(StorePink::getId).collect(Collectors.toList());
+    //        List<Long> randomIds = RandomUtil.uniqueRandom(idCollect, (int) luckNum);
+    //
+    //        randomIds.forEach(i -> {
+    //            StorePink luckPink = new StorePink();
+    //            luckPink.setId(i);
+    //            luckPink.setLId(1);
+    //            update(luckPink);
+    //        });
+    //    }
     @Override
     public void theSelection(Long spsId) {
         // 假设只有1个用户是天选
         long luckNum = 1;
-
+        
         Condition condition = new Condition(StorePink.class);
         Example.Criteria criteria = condition.createCriteria();
         criteria.andEqualTo("isDelete", 0);
         criteria.andEqualTo("spsId", spsId);
         // 排除团长
-//        criteria.andEqualTo("kId", 1);
+        //        criteria.andEqualTo("kId", 1);
         // 支付成功的
         criteria.andEqualTo("status", 2);
         List<StorePink> list = findByCondition(condition);
@@ -169,10 +168,10 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
         if (count >= luckNum) {
             throw new ServiceException("已有天选");
         }
-
+        
         List<Long> idCollect = list.stream().map(StorePink::getId).collect(Collectors.toList());
         List<Long> randomIds = RandomUtil.uniqueRandom(idCollect, (int) luckNum);
-
+        
         randomIds.forEach(i -> {
             StorePink luckPink = new StorePink();
             luckPink.setId(i);
@@ -180,13 +179,12 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
             update(luckPink);
         });
     }
-
-
-
+    
+    
     @Override
     public List<StorePinkOngoingVO> ongoingList(StorePink storePink) {
-
-       // PageHelper.startPage(1, 3);
+        
+        // PageHelper.startPage(1, 3);
         List<StorePinkOngoingVO> list = new ArrayList<>();
         Condition storePinkSummarycondition = new Condition(StorePinkSummary.class);
         Example.Criteria storePinkSummarycriteria = storePinkSummarycondition.createCriteria();
@@ -195,26 +193,26 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
         storePinkSummarycriteria.andEqualTo("isVirtual", 0);
         storePinkSummarycondition.setOrderByClause("people_count DESC");
         List<StorePinkSummary> byCondition = storePinkSummaryService.findByCondition(storePinkSummarycondition);
-
-
-        if(!CollectionUtils.isEmpty(byCondition)){
-
+        
+        
+        if (!CollectionUtils.isEmpty(byCondition)) {
+            
             Map<Long, StorePinkSummary> storePinkSummaryMap = byCondition.stream().collect(Collectors.toMap(StorePinkSummary::getId, a -> a, (b, c) -> c));
-
+            
             List<Long> spsIdList = byCondition.stream().map(StorePinkSummary::getId).collect(Collectors.toList());
-
+            
             Condition condition = new Condition(StorePink.class);
             Example.Criteria criteria = condition.createCriteria();
             criteria.andEqualTo("isDelete", 0);
             criteria.andEqualTo("cid", storePink.getCid());
-          //  criteria.andEqualTo("kid", 0);
+            //  criteria.andEqualTo("kid", 0);
             criteria.andIn("spsId", spsIdList);
             List<StorePink> pinkList = findByCondition(condition);
-
+            
             Map<Long, List<StorePink>> collect = pinkList.stream().collect(Collectors.groupingBy(StorePink::getSpsId));
-            list = pinkList.stream().filter(a->a.getKId().equals(0)).map(a -> {
+            list = pinkList.stream().filter(a -> a.getKId().equals(0)).map(a -> {
                 List<StorePink> storePinks = collect.get(a.getSpsId());
-
+                
                 StorePinkOngoingVO pinkOngoingVO = new StorePinkOngoingVO();
                 pinkOngoingVO.setId(a.getId());
                 pinkOngoingVO.setOrderId(a.getOrderId());
@@ -225,12 +223,58 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
                 pinkOngoingVO.setSuccessAvatar(storePinks.stream().map(StorePink::getAvatar).collect(Collectors.toList()));
                 return pinkOngoingVO;
             }).collect(Collectors.toList());
-
+            
             list = list.stream().sorted(Comparator.comparing(StorePinkOngoingVO::getRemainNum).reversed()).collect(Collectors.toList());
-
+            
         }
-
+        
         return list;
     }
-
+    
+    @Override
+    public List<ProductCarouselVO> carousel(Long productId) {
+        List<ProductCarouselDTO> pinks = storePinkMapper.pinkByProductId(productId);
+        // 兜底
+        if (CollectionUtil.isEmpty(pinks)) {
+            pinks = storePinkMapper.pinkByProductId(productId);
+        }
+        // 还是空那也没办法了
+        if (CollectionUtil.isEmpty(pinks)) {
+            return new ArrayList<>();
+        }
+        List<UserDTO> users = userDubboServiceClient.getUsersByIds(pinks.stream().map(ProductCarouselDTO::getUid).collect(Collectors.toList()));
+        // 无用户信息
+        if (CollectionUtil.isEmpty(users)) {
+            return new ArrayList<>();
+        }
+        Map<Long, UserDTO> userMap = users.stream().collect(Collectors.toMap(UserDTO::getId, user -> user));
+        
+        List<ProductCarouselVO> carousel = new ArrayList<>();
+        pinks.forEach(item -> {
+            UserDTO user = userMap.get(item.getUid());
+            if (user != null) {
+                String name = user.getName();
+                switch (name.length()) {
+                    case 1:
+                        name = name;
+                        break;
+                    case 2:
+                        StrUtil.hide(name, 1, name.length());
+                        break;
+                    default:
+                        StrUtil.hide(name, 1, name.length() - 1);
+                        break;
+                }
+                carousel.add(ProductCarouselVO.builder()
+                        .headPic(user.getHeadPic())
+                        .name(name)
+                        .kId(item.getKId())
+                        .time(cn.hutool.core.util.RandomUtil.randomInt(1, 51))
+                        .build()
+                );
+            }
+        });
+        return carousel;
+    }
+    
 }

+ 34 - 0
mall-service/src/main/java/com/txz/mall/web/vo/ProductCarouselVO.java

@@ -0,0 +1,34 @@
+package com.txz.mall.web.vo;
+
+import lombok.Builder;
+import lombok.Data;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/27
+ */
+@Data
+@Builder
+public class ProductCarouselVO {
+    
+    /**
+     * 头像
+     */
+    private String headPic;
+    
+    /**
+     * 昵称
+     */
+    private String name;
+    
+    /**
+     * 时间
+     */
+    private Integer time;
+    
+    /**
+     * 0为团长
+     */
+    private Integer kId;
+    
+}

+ 23 - 0
mall-service/src/main/java/dto/ProductCarouselDTO.java

@@ -0,0 +1,23 @@
+package dto;
+
+import lombok.Data;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/27
+ */
+
+@Data
+public class ProductCarouselDTO {
+    
+    /**
+     * 用户id
+     */
+    private Long uid;
+    
+    /**
+     * 0为团长
+     */
+    private Integer kId;
+    
+}