|
@@ -1,11 +1,15 @@
|
|
package com.ruoyi.wx.web.service.impl;
|
|
package com.ruoyi.wx.web.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
-import com.ruoyi.common.constant.Constants;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
+import com.ruoyi.common.core.domain.entity.WxUser;
|
|
|
|
+import com.ruoyi.common.core.domain.model.LoginWxUser;
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.framework.recovery.domain.RecContent;
|
|
import com.ruoyi.framework.recovery.domain.RecContent;
|
|
|
|
+import com.ruoyi.framework.recovery.domain.RecContentUser;
|
|
import com.ruoyi.framework.recovery.domain.RecSaleInfo;
|
|
import com.ruoyi.framework.recovery.domain.RecSaleInfo;
|
|
import com.ruoyi.framework.recovery.domain.RecStores;
|
|
import com.ruoyi.framework.recovery.domain.RecStores;
|
|
import com.ruoyi.framework.recovery.mapper.RecContentMapper;
|
|
import com.ruoyi.framework.recovery.mapper.RecContentMapper;
|
|
@@ -19,8 +23,8 @@ import com.ruoyi.wx.web.service.IWxHomeService;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
@@ -46,9 +50,6 @@ public class WxHomeServiceImpl implements IWxHomeService {
|
|
@Autowired
|
|
@Autowired
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private StringRedisTemplate stringRedisTemplate;
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RecContentMapper recContentMapper;
|
|
private RecContentMapper recContentMapper;
|
|
|
|
|
|
@@ -76,13 +77,6 @@ public class WxHomeServiceImpl implements IWxHomeService {
|
|
executorService.submit(contentTask);
|
|
executorService.submit(contentTask);
|
|
List<RecContent> contents = contentTask.get();
|
|
List<RecContent> contents = contentTask.get();
|
|
String display = wxHomeMapper.selectLotteryDisplay("is_lottery");
|
|
String display = wxHomeMapper.selectLotteryDisplay("is_lottery");
|
|
- for (RecContent content : contents) {
|
|
|
|
- Object value = redisCache.getCacheMapValue(Constants.THUMBS_UP, "like" + content.getId());
|
|
|
|
- if (value != null) {
|
|
|
|
- content.setThumbs(Long.parseLong(value.toString()));
|
|
|
|
- }
|
|
|
|
- redisCache.setCacheMapValue(Constants.THUMBS_UP, "like" + content.getId(), content.getThumbs());
|
|
|
|
- }
|
|
|
|
List<RecSaleInfo> saleInfos = saleInfoTask.get();
|
|
List<RecSaleInfo> saleInfos = saleInfoTask.get();
|
|
saleInfos.sort(Comparator.comparing(RecSaleInfo::getTopIndex, Integer::compareTo));
|
|
saleInfos.sort(Comparator.comparing(RecSaleInfo::getTopIndex, Integer::compareTo));
|
|
contents.sort(Comparator.comparing(RecContent::getCreateDate, (t1, t2) -> t2.compareTo(t1)));
|
|
contents.sort(Comparator.comparing(RecContent::getCreateDate, (t1, t2) -> t2.compareTo(t1)));
|
|
@@ -131,32 +125,24 @@ public class WxHomeServiceImpl implements IWxHomeService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public Long thumbs(Long id) {
|
|
public Long thumbs(Long id) {
|
|
- Object value = redisCache.getCacheMapValue(Constants.THUMBS_UP, "like" + id);
|
|
|
|
- long increment = 0L;
|
|
|
|
- if (value == null) {
|
|
|
|
- increment = stringRedisTemplate.opsForHash().increment(Constants.THUMBS_UP, "like" + id, 1);
|
|
|
|
- } else if (value instanceof Integer) {
|
|
|
|
- increment = stringRedisTemplate.opsForHash().increment(Constants.THUMBS_UP, "like" + id, 1);
|
|
|
|
- } else if (value instanceof Long longValue) {
|
|
|
|
- // 如果值是 Long 类型,将其转换为 Integer 类型并更新
|
|
|
|
- int intValue = longValue.intValue(); // 转换为 Integer
|
|
|
|
- // 更新 Redis 中的值为 Integer 类型
|
|
|
|
- stringRedisTemplate.opsForHash().put(Constants.THUMBS_UP, "like" + id, Integer.toString(intValue));
|
|
|
|
- // 执行自增操作
|
|
|
|
- increment = stringRedisTemplate.opsForHash().increment(Constants.THUMBS_UP, "like" + id, 1);
|
|
|
|
|
|
+ // 点赞记录
|
|
|
|
+ LoginWxUser loginWxUser = SecurityUtils.getLoginWxUser();
|
|
|
|
+ if (loginWxUser == null) {
|
|
|
|
+ throw new SecurityException("请登录");
|
|
}
|
|
}
|
|
- if (increment <= 0) {
|
|
|
|
- return 0L;
|
|
|
|
|
|
+ WxUser wxUser = loginWxUser.getWxUser();
|
|
|
|
+ List<RecContentUser> contentUser = recContentMapper.selectContentUserByOpenId(wxUser.getWxOpenid(), id);
|
|
|
|
+ if (CollectionUtil.isNotEmpty(contentUser)) {
|
|
|
|
+ throw new RuntimeException("该用户已点过赞");
|
|
}
|
|
}
|
|
- Object mapValue = redisCache.getCacheMapValue(Constants.THUMBS_UP, "like" + id);
|
|
|
|
- long result = 0L;
|
|
|
|
- if (mapValue instanceof Integer) {
|
|
|
|
- result = ((Integer) mapValue).longValue();
|
|
|
|
- } else if (mapValue instanceof Long) {
|
|
|
|
- result = (Long) mapValue;
|
|
|
|
- }
|
|
|
|
- return result;
|
|
|
|
|
|
+ int count = recContentService.insertRecContentUser(wxUser.getWxOpenid(), id);
|
|
|
|
+ // 点赞数加一
|
|
|
|
+ RecContent content = recContentService.selectRecContentById(id);
|
|
|
|
+ content.setThumbs(content.getThumbs() + 1);
|
|
|
|
+ recContentService.updateRecContent(content);
|
|
|
|
+ return (long) count;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -164,6 +150,16 @@ public class WxHomeServiceImpl implements IWxHomeService {
|
|
return recContentMapper.insertRecContent(recContent);
|
|
return recContentMapper.insertRecContent(recContent);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<RecContentUser> userThumbs() {
|
|
|
|
+ LoginWxUser loginWxUser = SecurityUtils.getLoginWxUser();
|
|
|
|
+ if (loginWxUser == null) {
|
|
|
|
+ throw new SecurityException("请登录");
|
|
|
|
+ }
|
|
|
|
+ WxUser wxUser = loginWxUser.getWxUser();
|
|
|
|
+ return recContentMapper.selectContentUserByOpenId(wxUser.getWxOpenid(), null);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 将字符串转日期成Long类型的时间戳,格式为:yyyy-MM-dd HH:mm:ss
|
|
* 将字符串转日期成Long类型的时间戳,格式为:yyyy-MM-dd HH:mm:ss
|
|
*/
|
|
*/
|
|
@@ -175,6 +171,7 @@ public class WxHomeServiceImpl implements IWxHomeService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断时间是否在时间段内
|
|
* 判断时间是否在时间段内
|
|
|
|
+ *
|
|
* @param nowTime
|
|
* @param nowTime
|
|
* @param beginTime
|
|
* @param beginTime
|
|
* @param endTime
|
|
* @param endTime
|