package cn.platform.goods.service.impl;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.itcast.feign.userClients.UserClient;
import cn.platform.goods.mapper.GoodsMapper;
import cn.platform.goods.service.GoodsService;
import cn.platform.model.dto.ResponseResult;
import cn.platform.model.good.dto.GoodsDto;
import cn.platform.model.good.enity.Goods;
import cn.platform.model.good.enity.Goods_image;
import cn.platform.model.good.enity.Goods_status;
import cn.platform.model.good.vo.GoodsVo;
import cn.platform.model.user.Vo.UserBrowseVo;
import cn.platform.model.user.enity.User;
import cn.platform.utils.CacheClient;
import cn.platform.utils.RecommendCF;
import cn.platform.utils.RedisData;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static cn.platform.model.constants.QueueConstants.SEARCH_GOODS_DIRECT;
import static cn.platform.model.constants.RedisConstants.*;
@Service
public class GoodsServiceImpl implements GoodsService {
@Resource
private RabbitTemplate rabbitTemplate;
@Resource
private GoodsMapper addGoodsMapper;
@Resource
private UserClient userClient;
@Resource
private StringRedisTemplate stringRedisTemplate;
//创建线程池
private static final ExecutorService CACHE_REBUILD_EXECUTOR = Executors.newFixedThreadPool(10);
@Override
public ResponseResult addGoods(GoodsDto goodsDto) {
String queueName = "goods.direct";
rabbitTemplate.convertAndSend(queueName,"red", goodsDto);
Goods goods = JSONUtil.toBean(JSONUtil.toJsonStr(goodsDto),Goods.class);
rabbitTemplate.convertAndSend(SEARCH_GOODS_DIRECT, "add", JSONUtil.toJsonStr(goods));
return ResponseResult.ok("发布成功");
}
@Override
public List<String> getGoodsImage(int id) {
return addGoodsMapper.getGoodsImage(id);
}
@Override
public ResponseResult getStatusGoods(String str) {
if(str.equals("最新发布")){
return ResponseResult.ok();
}
else {
List<GoodsVo> goodsVoList = addGoodsMapper.getStatusGoods(str);
for (GoodsVo item : goodsVoList) {
User user = userClient.finById(item.getUser_id());
item.setImage(user.getImage());
item.setName(user.getName());
List<String> goodsImage = addGoodsMapper.getGoodsImage(item.getId());
item.setUrlList(goodsImage);
Goods_status goodsStatus = addGoodsMapper.getGoodsStatus(item.getId());
item.setIs_draft(goodsStatus.getIs_draft());
item.setIs_sell(goodsStatus.getIs_sell());
item.setIs_sold_out(goodsStatus.getIs_sold_out());
}
return ResponseResult.ok(goodsVoList);
}
}
@Override
public ResponseResult resertGoodsStatus(int id,int status) {
if(status==2){
addGoodsMapper.updateDraftGoodsStatus(id);
}
if(status==1){
addGoodsMapper.resertGoodsStatus(id,1);
rabbitTemplate.convertAndSend(SEARCH_GOODS_DIRECT, "del", id);
}
if(status==3){
addGoodsMapper.resertGoodsStatus(id,0);
GoodsVo goodsDetail = addGoodsMapper.getGoodsDetail(id);
Goods goods = JSONUtil.toBean(JSONUtil.toJsonStr(goodsDetail),Goods.class);
rabbitTemplate.convertAndSend(SEARCH_GOODS_DIRECT, "add", JSONUtil.toJsonStr(goods));
}
return ResponseResult.ok();
}
@Override
public ResponseResult getRecommerdGoods(int id) {
List<Integer> allUserId = userClient.getAllUserId();
Map<Integer, Map<String,Double>> map = new HashMap<>();
for(Integer item:allUserId){
String key1 = USER_COLLECT_KEY + item;
String key2 = USER_BROWSE_KEY + item;
if(BooleanUtil.isTrue(stringRedisTemplate.hasKey(key1))){
Map<String,Double> map1 = new HashMap<>();
Set<String> members1 = stringRedisTemplate.opsForSet().members(key1);
Set<String> members2 = stringRedisTemplate.opsForSet().members(key2);
if(members1==null || members1.size()==0){
continue;
}
for(String item1 : members1){
map1.put(item1,0.5);
}
if(members2==null || members2.size()==0){
continue;
}
for(String item2 : members2){
if(!map1.containsKey(item2)){
map1.put(item2,0.25);
}
}
map.put(item,map1);
}else {
if(BooleanUtil.isTrue(stringRedisTemplate.hasKey(key2))){
Set<String> members = stringRedisTemplate.opsForSet().members(key2);
if(members==null || members.size()==0){
continue;
}
Map<String,Double> map1 = new HashMap<>();
for(String item1 : members){
map1.put(item1,0.25);
}
map.put(item,map1);
}else{
map.put(item,new HashMap<>());
}
}
}
System.err.println(map.get(6).entrySet()+":"+map.get(5).entrySet()+":"+map.get(4).entrySet()+":"+map.get(3).entrySet()+":"+map.get(2).entrySet()+":"+map.get(1).entrySet());
RecommendCF recommendCF = new RecommendCF();
List<String> list = recommendCF.itemCF(id,30, map);
System.err.println(list);
List<GoodsVo> list1 = new ArrayList<>();
for(String goodsId : list){
GoodsVo goodsDetail = addGoodsMapper.getGoodsDetail(Integer.parseInt(goodsId));
list1.add(goodsDetail);
}
for(GoodsVo goodsVo : list1){
Goods_status goodsStatus = addGoodsMapper.getGoodsStatus(goodsVo.getId());
List<String> goodsImage = addGoodsMapper.getGoodsImage(goodsVo.getId());
goodsVo.setUrlList(goodsImage);
goodsVo.setIs_draft(goodsStatus.getIs_draft());
goodsVo.setIs_sell(goodsStatus.getIs_sell());
goodsVo.setIs_sold_out(goodsStatus.getIs_sold_out());
}
return ResponseResult.ok(list1);
}
@Override
public ResponseResult getGoodsStatus(int id, int status) {
//status为1查询在卖的 2查询草稿 3查询下架
List<GoodsVo> goodsVos = addGoodsMapper.selectGoodsStatus(id);
List<GoodsVo> goodsVoList = new ArrayList<>();
for(GoodsVo item : goodsVos){
Goods_status goodsStatus = addGoodsMapper.getGoodsStatus(item.getId());
List<String> goodsImage = addGoodsMapper.getGoodsImage(item.getId());
item.setUrlList(goodsImage);
item.setIs_draft(goodsStatus.getIs_draft());
item.setIs_sell(goodsStatus.getIs_sell());
item.setIs_sold_out(goodsStatus.getIs_sold_out());
if(item.getGoods_describe().length()>20) {
item.setGood
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该源码是一个综合性二手交易平台,采用Java微服务架构设计,包含998个文件,涵盖307个XML配置、244个Java源代码、240个Class文件、68个JPG图片、39个Vue组件、31个PNG图片、22个YAML配置文件、17个IDE项目配置文件、7个JavaScript脚本文件、4个元数据文件。技术栈包括Java、Vue、JavaScript和HTML,旨在构建一个功能完备的在线交易环境。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java微服务架构的综合性二手交易平台设计源码 (1003个子文件)
GoodsServiceImpl.class 15KB
PayMouthVoucherServiceImpl.class 13KB
payServiceImpl.class 13KB
BlogServiceImpl.class 10KB
Test1.class 10KB
User.class 9KB
GoodsVo.class 8KB
TransferServiceImpl.class 8KB
OrderVo.class 7KB
RecommendCF.class 7KB
RefundServiceImpl.class 7KB
GoodsSearchServiceImpl.class 7KB
BlogSearchServiceImpl.class 7KB
CacheClient.class 7KB
ChatServiceImpl.class 7KB
GoodsCommentServiceImpl.class 7KB
BlogVo.class 7KB
UserSignServiceImpl.class 7KB
BlogCommentServiceImpl.class 7KB
EstablishOrderServiceImpl.class 6KB
UserCollectServiceImpl.class 6KB
UserAttentionServiceImpl.class 6KB
GetOrderServiceImpl.class 6KB
UserDetailServiceImpl.class 6KB
EsTest.class 6KB
GoodsCommentVo.class 6KB
GoodsDto.class 6KB
BlogCommentVo.class 6KB
PayConstant.class 6KB
ReplyGoodsCommentVo.class 6KB
ReplyCommentVo.class 6KB
SeckillVoucherVo.class 6KB
Goods.class 5KB
Goods_order.class 5KB
UserServiceImpl.class 5KB
PayTestController.class 5KB
JwtUtils.class 5KB
VoucherDto.class 5KB
UserBrowseServiceImpl.class 5KB
ManageBlogServiceImpl.class 5KB
UserVoucherVo.class 5KB
ResponseResult.class 5KB
Blog.class 5KB
User_adress.class 5KB
MouthVoucherVo.class 5KB
UserVoucherServiceImpl.class 4KB
UserSearchServiceImpl.class 4KB
AuthorizationServiceImpl.class 4KB
ChatListVo.class 4KB
UserLabelServiceImpl.class 4KB
GoodsCommentDto.class 4KB
User_chat.class 4KB
BlogDto.class 4KB
UserAdressServiceImpl.class 4KB
UserBrowseVo.class 4KB
ChatSocket.class 4KB
Voucher.class 4KB
OrderDto.class 4KB
GoodsComment.class 3KB
BlogComment.class 3KB
BlogViewServiceImpl.class 3KB
AuthorizeFilter.class 3KB
BlogController.class 3KB
UpdateOrderServiceImpl.class 3KB
GoodsController.class 3KB
Transfer.class 3KB
UserFollowVo.class 3KB
UserDetailController.class 3KB
Ali_authorization.class 3KB
Seckill_voucher.class 3KB
User_voucher.class 3KB
User_authentication.class 3KB
AppHttpCodeEnum.class 3KB
MouthOnce_voucher_order.class 3KB
Seckill_voucher_order.class 3KB
HistorySearchServiceImpl.class 3KB
RedisConstants.class 3KB
NoteUtils.class 3KB
UserCollectController.class 3KB
UserDetailMapper.class 3KB
PasswordDto.class 3KB
Chat_list.class 3KB
GoodsMapper.class 3KB
SeckillVoucherServiceImpl.class 3KB
UserAttentionController.class 3KB
History.class 2KB
BlogTypeDto.class 2KB
SearchDto.class 2KB
MouthVoucherServiceImpl.class 2KB
User_blogCollect.class 2KB
User_folow.class 2KB
User_collect.class 2KB
User_browse.class 2KB
User_fan.class 2KB
ChatMapper.class 2KB
GetOrderController.class 2KB
test.class 2KB
Goods_status.class 2KB
ChatController.class 2KB
Label.class 2KB
共 1003 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
csbysj2020
- 粉丝: 2647
- 资源: 5504
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功