Bladeren bron

机构个人中心数据

chao 3 jaren geleden
bovenliggende
commit
775f1912b2

+ 12 - 0
src/main/java/com/caimei365/user/mapper/ClubMapper.java

@@ -209,4 +209,16 @@ public interface ClubMapper {
      * 售后无忧,购物须知
      */
     AfterSaleVo getAfterSale();
+    /**
+     * 未读消息数量
+     */
+    Integer getUnReadMessageCount(Integer userId);
+    /**
+     * 优惠券可用数量
+     */
+    Integer getUserCouponCount(Integer userId);
+
+    List<AdvertiseVo> getUserAdvertiseList(AdvertiseVo advertiseVo);
+
+    List<InformationVo> getInformationList(InformationVo informationVo);
 }

+ 58 - 0
src/main/java/com/caimei365/user/model/vo/AdvertiseVo.java

@@ -0,0 +1,58 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 今日推荐商品
+ *
+ * @author : Aslee
+ * @date : 2020/9/1
+ */
+
+@Data
+public class AdvertiseVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 主键 advertiseID
+     */
+    private Integer advertiseId;
+    /**
+     * 首页栏位ID:6机构个人中心推荐栏位
+     */
+    private Integer typeId;
+    /**
+     * 广告位种类ID:1001推荐商品,1002推荐公司
+     */
+    private Integer advertiseTypeId;
+    /**
+     * 关联广告位ID
+     */
+    private Integer associationId;
+    /**
+     * 广告位图片URL
+     */
+    private String image;
+    /**
+     * 广告位链接
+     */
+    private String link;
+    /**
+     * 排序值
+     */
+    private Integer sortIndex;
+    /**
+     * 可用标志:1可用,0不可用
+     */
+    private String validFlag;
+    /**
+     * 广告标题
+     */
+    private String title;
+    /**
+     * 备注
+     */
+    private String comment;
+
+}

+ 64 - 0
src/main/java/com/caimei365/user/model/vo/InformationVo.java

@@ -0,0 +1,64 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 最新动态信息
+ *
+ * @author : Aslee
+ * @date : 2020/9/1
+ */
+@Data
+public class InformationVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 主键 informationID
+     */
+    private Integer informationId;
+    /**
+     * 信息类型
+     */
+    private Integer infoTypeId;
+    /**
+     * 标签
+     */
+    private String tag;
+    /**
+     * 信息标题
+     */
+    private String title;
+    /**
+     * 信息链接
+     */
+    private String link;
+    /**
+     * html内容
+     */
+    private String content;
+    /**
+     * 文本内容
+     */
+    private String contentTxt;
+    /**
+     * 可用标志
+     */
+    private String validFlag;
+    /**
+     * 添加时间
+     */
+    private String addTime;
+    /**
+     * 作者
+     */
+    private String author;
+    /**
+     * 图片路径
+     */
+    private String imgUrl;
+    /**
+     * 未知
+     */
+    private Long areaValue;
+}

+ 75 - 5
src/main/java/com/caimei365/user/service/impl/ClubServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClientBuilder;
+import com.caimei365.user.components.RedisService;
 import com.caimei365.user.mapper.BaseMapper;
 import com.caimei365.user.mapper.ClubMapper;
 import com.caimei365.user.mapper.RegisterMapper;
@@ -20,12 +21,14 @@ import com.caimei365.user.model.po.UserBeansHistoryPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.ClubService;
+import com.caimei365.user.utils.ImageUtils;
 import com.caimei365.user.utils.OssUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -44,7 +47,8 @@ import static com.alibaba.fastjson.JSON.parseObject;
 @Slf4j
 @Service
 public class ClubServiceImpl implements ClubService {
-
+    @Value("${caimei.wwwDomain}")
+    private String wwwDomain;
     @Resource
     private ClubMapper clubMapper;
     @Resource
@@ -53,6 +57,8 @@ public class ClubServiceImpl implements ClubService {
     private RegisterMapper registerMapper;
     @Resource
     private SuperVipMapper vipMapper;
+    @Resource
+    private RedisService redisService;
 
     /**
      * 根据用户Id查询机构资料
@@ -480,7 +486,7 @@ public class ClubServiceImpl implements ClubService {
      */
     @Override
     public ResponseJson<Map<String, Object>> getPersonalData(Integer userId) {
-        Map<String, Object> result = new HashMap<>(11);
+        Map<String, Object> result = new HashMap<>(8);
         // 1.用户信息
         UserVo user = baseMapper.getUserByUserId(userId);
         if (user == null) {
@@ -511,9 +517,73 @@ public class ClubServiceImpl implements ClubService {
         } else {
             result.put("degree", "80%");
         }
+        // 5.未读消息数量
+        Integer unReadMessageCount = clubMapper.getUnReadMessageCount(userId);
+        result.put("unReadMessageCount", unReadMessageCount);
+        // 6.优惠券可用数量
+        Integer couponNum = clubMapper.getUserCouponCount(userId);
+        result.put("couponNum", couponNum);
+        // 7.今日推荐
+        int floorId = 6;
+        int index = 1;
+        String homeAdvertiseKey = "home_advertise_" + floorId;
+        if (!redisService.exists(homeAdvertiseKey)) {
+            AdvertiseVo homePageAdvertise = new AdvertiseVo();
+            homePageAdvertise.setAdvertiseTypeId(1001);
+            homePageAdvertise.setTypeId(floorId);
+            homePageAdvertise.setValidFlag("1");
+            List<AdvertiseVo> list = clubMapper.getUserAdvertiseList(homePageAdvertise);
+            for (AdvertiseVo advertise : list) {
+                advertise.setImage(ImageUtils.getImageURL("homePageImages", advertise.getImage(), 0, wwwDomain));
+            }
+            redisService.setList(homeAdvertiseKey, list);
+        }
+        int pageSize = 4;
+        int totalRecord = (int) redisService.listSize(homeAdvertiseKey);
+        int total = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
+        if (index > total) {
+            index = index % total;
+        }
+        int begin = (index - 1) * pageSize;
+        int end = index * pageSize - 1;
+        //避免unchecked cast warning
+        List<AdvertiseVo> list = new ArrayList<>();
+        Object advertiseObj = redisService.getList(homeAdvertiseKey, begin, end);
+        if (advertiseObj instanceof ArrayList<?>) {
+            for (Object o : (List<?>) advertiseObj) {
+                list.add((AdvertiseVo) o);
+            }
+        }
+        result.put("homePageAdvertiseList", list);
+        // 8.最新动态
+        String informationKey = "home_info_" + floorId;
+        redisService.remove(informationKey);
+        if (!redisService.exists(informationKey)) {
+            InformationVo info = new InformationVo();
+            info.setInfoTypeId(1);
+            info.setValidFlag("1");
+            List<InformationVo> infoList = clubMapper.getInformationList(info);
+            infoList.forEach(information -> information.setLink("/info/detail-" + information.getInformationId() + "-1.html"));
+            redisService.setList(informationKey, infoList);
+        }
+        int infoIndex = 1;
+        int infoPageSize = 5;
+        int totalInfoRecord = (int) redisService.listSize(informationKey);
+        int totalInfo = totalInfoRecord % infoPageSize == 0 ? totalInfoRecord / infoPageSize : totalInfoRecord / infoPageSize + 1;
+        if (infoIndex > totalInfo) {
+            infoIndex = infoIndex % totalInfo;
+        }
+        int infoBegin = (infoIndex - 1) * infoPageSize;
+        int infoEnd = infoIndex * infoPageSize - 1;
+        List<InformationVo> infoList = new ArrayList<>();
+        Object infoObj = redisService.getList(informationKey, infoBegin, infoEnd);
+        if (infoObj instanceof ArrayList<?>) {
+            for (Object o : (List<?>) infoObj) {
+                infoList.add((InformationVo) o);
+            }
+        }
+        result.put("homePageInfoList", infoList);
 
-        //todo
-
-        return null;
+        return ResponseJson.success(result);
     }
 }

+ 39 - 0
src/main/resources/mapper/ClubMapper.xml

@@ -225,4 +225,43 @@
         FROM cm_mall_organize
         WHERE id = 0 AND delFlag = '0'
     </select>
+    <select id="getUnReadMessageCount" resultType="java.lang.Integer">
+        SELECT COUNT(*) FROM message WHERE toUserID = #{userId} AND readFlag='0'
+    </select>
+    <select id="getUserCouponCount" resultType="java.lang.Integer">
+        SELECT COUNT(a.id)
+        FROM cm_coupon_club a
+        LEFT JOIN cm_coupon cc ON a.couponId = cc.id
+        WHERE cc.delFlag = 0 AND a.delFlag = 0 AND a.status = 1 AND cc.status != 2
+        AND a.userId = #{userId}  AND NOW() BETWEEN cc.startDate AND cc.endDate
+    </select>
+    <select id="getUserAdvertiseList" resultType="com.caimei365.user.model.vo.AdvertiseVo">
+        SELECT image, link, title
+        FROM c_homepageadvertise
+        <where>
+            <if test="advertiseTypeId != null">
+                AND advertiseTypeID = #{advertiseTypeId}
+            </if>
+            <if test="typeId != null">
+                AND typeID = #{typeId}
+            </if>
+            <if test="validFlag != null">
+                AND validFlag = #{validFlag}
+            </if>
+        </where>
+        ORDER BY sortIndex DESC
+    </select>
+    <select id="getInformationList" resultType="com.caimei365.user.model.vo.InformationVo">
+        SELECT informationID AS informationId, title, link, addTime
+        FROM information
+        <where>
+            <if test="infoTypeId != null">
+                AND infoTypeID = #{infoTypeId}
+            </if>
+            <if test="validFlag != null">
+                AND validFlag = #{validFlag}
+            </if>
+        </where>
+        ORDER BY informationID DESC
+    </select>
 </mapper>