From 852186325514f82adf26f05cce66e2d3e452ceae Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 23 Jan 2024 01:12:42 +0800 Subject: [PATCH 1/8] 1.add count info by multi search, need to improve by one search --- .../luoo/user/controller/MyController.java | 20 ++++++++++++++ .../com/luoo/user/dao/UserCollectDao.java | 9 +++++++ .../com/luoo/user/dto/UserCollectCount.java | 11 ++++++++ .../luoo/user/dto/response/UserRespDTO.java | 12 +++++++++ .../luoo/user/service/UserCollectService.java | 27 +++++++++++++++++-- 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/UserCollectCount.java diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index 791f05c..e08f66c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Paths; import java.util.Date; +import java.util.EnumMap; import org.apache.commons.io.IOUtils; import org.springframework.beans.BeanUtils; @@ -26,6 +27,7 @@ import controller.BaseController; import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.pojo.UserInfo; import com.luoo.user.service.S3Service; +import com.luoo.user.service.UserCollectService; import com.luoo.user.service.UserInfoService; import annotation.GlobalInterceptor; @@ -33,6 +35,7 @@ import annotation.VerifyParam; import api.Result; import api.StatusCode; import dto.UserLoginDto; +import enums.CollectTypeEnum; import enums.DateTimePatternEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -52,6 +55,9 @@ public class MyController extends BaseController{ @Autowired private UserInfoService userInfoService; + @Autowired + private UserCollectService userCollectService; + public static String UPLOAD_DIRECTORY = "user/avatar/"; @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @@ -65,6 +71,20 @@ public class MyController extends BaseController{ UserRespDTO userRespDTO = new UserRespDTO(); UserInfo user = userInfoService.findById(userLoginDto.getUserId()); BeanUtils.copyProperties(user, userRespDTO); + //EnumMap map=userCollectService.getUserCollectTypeMap(user.getId()); + Long fansCount=userCollectService.getFansCount(user.getId()); + Long followCount=userCollectService.getCount(user.getId(),CollectTypeEnum.FOLLOW.getType()); + Long thumbUpCount=userCollectService.getCount(user.getId(),CollectTypeEnum.THUMB_UP.getType()); + Long songCount=userCollectService.getCount(user.getId(),CollectTypeEnum.SONG.getType()); + Long journalCount=userCollectService.getCount(user.getId(),CollectTypeEnum.JOURNAL.getType()); + + userRespDTO.setFollowCount(followCount); + userRespDTO.setFansCount(fansCount); + userRespDTO.setThumbUpCount(thumbUpCount); + userRespDTO.setCommentReplyCount(0L); + userRespDTO.setSongCount(songCount); + userRespDTO.setJournalCount(journalCount); + return Result.success(userRespDTO); } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java index 45a7036..bce5f94 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java @@ -1,11 +1,20 @@ package com.luoo.user.dao; +import java.util.List; + +import org.springframework.data.jpa.repository.Query; import org.springframework.data.mongodb.repository.MongoRepository; +import com.luoo.user.dto.UserCollectCount; import com.luoo.user.pojo.UserCollect; public interface UserCollectDao extends MongoRepository { public UserCollect findByUserIdAndObjectIdAndCollectType(String userId, String objectId, Integer collectType); public long deleteByUserIdAndObjectIdAndCollectType(String userId, String objectId, Integer collectType); + //@Query(value = "select NumberInt(collectType),count(*) from common.userCollect where userId=?1 group by collectType", nativeQuery = true) + //public List countByUserIdAndGroupByCollectType(String userId); + + public long countByObjectIdAndCollectType(String objectId, Integer collectType); + public long countByUserIdAndCollectType(String userId, Integer collectType); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/UserCollectCount.java b/luoo_user/src/main/java/com/luoo/user/dto/UserCollectCount.java new file mode 100644 index 0000000..ddadf05 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserCollectCount.java @@ -0,0 +1,11 @@ +package com.luoo.user.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class UserCollectCount { + private int collectType; + private long count; +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index 32b12d5..0a4b350 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -17,4 +17,16 @@ public class UserRespDTO { private String signature; @ApiModelProperty(value = "用户标识,如“贡献者”,“音乐人”") private String badge; + @ApiModelProperty(value = "关注数") + private Long followCount; + @ApiModelProperty(value = "粉丝数") + private Long fansCount; + @ApiModelProperty(value = "获赞数") + private Long thumbUpCount; + @ApiModelProperty(value = "喜欢歌曲数") + private Long songCount; + @ApiModelProperty(value = "收藏期刊数") + private Long journalCount; + @ApiModelProperty(value = "获得评论数") + private Long commentReplyCount; } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java b/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java index 9a24388..15b1c34 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java @@ -1,6 +1,8 @@ package com.luoo.user.service; import java.util.Date; +import java.util.EnumMap; +import java.util.List; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; @@ -8,6 +10,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.luoo.user.dao.UserCollectDao; +import com.luoo.user.dto.UserCollectCount; import com.luoo.user.pojo.UserCollect; import api.StatusCode; @@ -24,7 +27,7 @@ public class UserCollectService { throw new BizException(StatusCode.VALIDATE_FAILED); } String collectId=userId+"_"+objectId+"_"+collectType; - Optional dbCollect = userCollectDao.findById(collectId);//.findByUserIdAndObjectIdAndCollectType(userId, objectId, collectType); + Optional dbCollect = userCollectDao.findById(collectId); if (dbCollect.isPresent()) { return; } @@ -41,6 +44,26 @@ public class UserCollectService { Integer collectType) { String collectId=userId+"_"+objectId+"_"+collectType; userCollectDao.deleteById(collectId); - //userCollectDao.deleteByUserIdAndObjectIdAndCollectType(userId, objectId, collectType); + } + + public EnumMap getUserCollectTypeMap(String userId) { + EnumMap userCollectTypeMap=new EnumMap<>(CollectTypeEnum.class); + /* + * List + * userCollectCounts=userCollectDao.countByUserIdAndGroupByCollectType(userId); + * + * userCollectCounts.forEach(u->{ CollectTypeEnum collectTypeEnum = + * CollectTypeEnum.getByType(u.getCollectType()); + * userCollectTypeMap.put(collectTypeEnum, u.getCount()); }); + */ + return userCollectTypeMap; + } + + public Long getFansCount(String userId) { + return userCollectDao.countByObjectIdAndCollectType(userId,CollectTypeEnum.FOLLOW.getType()); + } + + public Long getCount(String userId, Integer type) { + return userCollectDao.countByUserIdAndCollectType(userId,type); } } From 58d9c669391365becce86ed225c85c8af7134f85 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Tue, 23 Jan 2024 12:56:37 +0800 Subject: [PATCH 2/8] user Message with rabbitMQ --- .../src/main/java/dto/UserMessageDto.java | 51 ++++++++++++++++++ .../controller/UserMessageController.java | 45 ++++++++++++++++ .../com/luoo/user/dao/UserMessageDao.java | 11 ++++ .../user/listener/UserMessageListener.java | 29 ++++++++++ .../java/com/luoo/user/pojo/UserMessage.java | 53 +++++++++++++++++++ .../luoo/user/service/UserMessageService.java | 42 +++++++++++++++ 6 files changed, 231 insertions(+) create mode 100644 luoo_common/src/main/java/dto/UserMessageDto.java create mode 100644 luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java create mode 100644 luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java create mode 100644 luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java create mode 100644 luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java diff --git a/luoo_common/src/main/java/dto/UserMessageDto.java b/luoo_common/src/main/java/dto/UserMessageDto.java new file mode 100644 index 0000000..43d383d --- /dev/null +++ b/luoo_common/src/main/java/dto/UserMessageDto.java @@ -0,0 +1,51 @@ +package dto; + + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class UserMessageDto implements Serializable { + + private static final long serialVersionUID = 1L; + + + /** + * 消息ID + */ + private String messageId; + + /** + * 消息ID + */ + private String userId; + + + /** + * 消息标题 + */ + private String title; + + /** + * 消息内容 + */ + private String content; + + + /** + * 是否已读 0为未读 1为已读 + */ + private Integer havaRead; + + + /** + * 发送时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date sendTime; +} diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java new file mode 100644 index 0000000..73d067f --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java @@ -0,0 +1,45 @@ +package com.luoo.user.controller; + + +import api.Result; +import com.luoo.user.pojo.UserMessage; +import com.luoo.user.service.UserMessageService; +import dto.UserMessageDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/userMessage") +public class UserMessageController { + + @Autowired + private UserMessageService userMessageService; + + + /** + * 测试时用的,忽略这个方法 + * * @param userMessageDto + * @return + */ + + @PostMapping("/sendUserMessage") + public Result sendUserMessage(@RequestBody UserMessageDto userMessageDto) { + + userMessageService.sendUserMessage(userMessageDto); + return Result.success(); + } + + + /**测试时用的,获取当前登录用户ID请走TOKEN + * 根据登录的用户ID获取消息 + * @return + */ + @GetMapping("/list/{userId}") + public Result list(@PathVariable String userId){ + List list = userMessageService.findByUserId(userId); + return Result.success(list); + } + +} diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java new file mode 100644 index 0000000..144ef15 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java @@ -0,0 +1,11 @@ +package com.luoo.user.dao; + +import com.luoo.user.pojo.UserMessage; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.List; + +public interface UserMessageDao extends MongoRepository { + + List findAllByUserId(String userId); +} diff --git a/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java b/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java new file mode 100644 index 0000000..79a706a --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/listener/UserMessageListener.java @@ -0,0 +1,29 @@ +package com.luoo.user.listener; + + +import com.luoo.user.dao.UserMessageDao; +import com.luoo.user.pojo.UserMessage; +import dto.UserMessageDto; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@RabbitListener(queues = "userMessage") +public class UserMessageListener { + + @Autowired + private UserMessageDao userMessageDao; + + @RabbitHandler + public void executeSendUserMessage(UserMessageDto userMessageDto) { + + UserMessage userMessage = new UserMessage(); + BeanUtils.copyProperties(userMessageDto,userMessage); + + userMessageDao.save(userMessage); + } + +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java new file mode 100644 index 0000000..b209cbb --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java @@ -0,0 +1,53 @@ +package com.luoo.user.pojo; + + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class UserMessage implements Serializable { + + private static final long serialVersionUID = 1L; + + + /** + * 消息ID + */ + @Id + private String messageId; + + /** + * 消息ID + */ + private String userId; + + + /** + * 消息标题 + */ + private String title; + + /** + * 消息内容 + */ + private String content; + + + /** + * 是否已读 0为未读 1为已读 + */ + private Integer havaRead; + + + /** + * 发送时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date sendTime; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java new file mode 100644 index 0000000..eb12109 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java @@ -0,0 +1,42 @@ +package com.luoo.user.service; + +import com.luoo.user.dao.UserMessageDao; +import com.luoo.user.pojo.UserMessage; +import dto.UserMessageDto; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import util.IdWorker; + +import java.util.Date; +import java.util.List; + +@Service +public class UserMessageService { + + @Autowired + private RabbitTemplate rabbitTemplate; + + @Autowired + private UserMessageDao userMessageDao; + @Autowired + private IdWorker idWorker; + public void sendUserMessage(UserMessageDto userMessageDto) { + + userMessageDto.setMessageId(idWorker.nextId()+""); + userMessageDto.setHavaRead(0); + userMessageDto.setSendTime(new Date()); + rabbitTemplate.convertAndSend("userMessage",userMessageDto); + } + + + public List list() { + + return userMessageDao.findAll(); + } + + public List findByUserId(String userId) { + + return userMessageDao.findAllByUserId(userId); + } +} From 7801182926864ea147f56511b76807a94ada6fe9 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Tue, 23 Jan 2024 15:12:55 +0800 Subject: [PATCH 3/8] =?UTF-8?q?userMessage=E6=B7=BB=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=B7=B2?= =?UTF-8?q?=E8=AF=BB=E7=8A=B6=E6=80=81=EF=BC=8C=E6=89=B9=E9=87=8F=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=85=A8=E9=83=A8=E5=B7=B2=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/dto/UserMessageDto.java | 2 +- .../controller/UserMessageController.java | 24 +++++++-- .../com/luoo/user/dao/UserMessageDao.java | 8 +++ .../java/com/luoo/user/pojo/UserMessage.java | 2 +- .../luoo/user/service/UserMessageService.java | 53 ++++++++++++++++++- 5 files changed, 82 insertions(+), 7 deletions(-) diff --git a/luoo_common/src/main/java/dto/UserMessageDto.java b/luoo_common/src/main/java/dto/UserMessageDto.java index 43d383d..d0c9b9f 100644 --- a/luoo_common/src/main/java/dto/UserMessageDto.java +++ b/luoo_common/src/main/java/dto/UserMessageDto.java @@ -39,7 +39,7 @@ public class UserMessageDto implements Serializable { /** * 是否已读 0为未读 1为已读 */ - private Integer havaRead; + private Integer haveRead; /** diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java index 73d067f..6cf7a4c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java @@ -1,11 +1,13 @@ package com.luoo.user.controller; +import api.PageResult; import api.Result; import com.luoo.user.pojo.UserMessage; import com.luoo.user.service.UserMessageService; import dto.UserMessageDto; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -36,10 +38,24 @@ public class UserMessageController { * 根据登录的用户ID获取消息 * @return */ - @GetMapping("/list/{userId}") - public Result list(@PathVariable String userId){ - List list = userMessageService.findByUserId(userId); - return Result.success(list); + @GetMapping("/list/{userId}/{page}/{size}") + public Result list(@PathVariable String userId,@PathVariable int page,@PathVariable int size){ +// List list = userMessageService.findByUserId(userId); + + Page pageList = userMessageService.findSearch(userId,page,size); + return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); + } + + @PutMapping("/haveRead/{messageId}") + public Result haveRead(@PathVariable String messageId) { + userMessageService.haveRead(messageId); + return Result.success(); + } + + @PutMapping("/batchHaveRead") + public Result haveRead(@RequestBody List userMessageList) { + userMessageService.batchHaveRead(userMessageList); + return Result.success(); } } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java index 144ef15..bdc5112 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java @@ -1,6 +1,10 @@ package com.luoo.user.dao; import com.luoo.user.pojo.UserMessage; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.mongodb.repository.MongoRepository; import java.util.List; @@ -8,4 +12,8 @@ import java.util.List; public interface UserMessageDao extends MongoRepository { List findAllByUserId(String userId); + + Page findByUserId(String userId, Pageable pageable); + + } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java index b209cbb..12102e8 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java @@ -41,7 +41,7 @@ public class UserMessage implements Serializable { /** * 是否已读 0为未读 1为已读 */ - private Integer havaRead; + private Integer haveRead; /** diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java index eb12109..533c1d9 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java @@ -2,9 +2,17 @@ package com.luoo.user.service; import com.luoo.user.dao.UserMessageDao; import com.luoo.user.pojo.UserMessage; +import com.mongodb.bulk.BulkWriteResult; import dto.UserMessageDto; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.mongodb.core.BulkOperations; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Service; import util.IdWorker; @@ -21,10 +29,14 @@ public class UserMessageService { private UserMessageDao userMessageDao; @Autowired private IdWorker idWorker; + + @Autowired + private MongoTemplate mongoTemplate; + public void sendUserMessage(UserMessageDto userMessageDto) { userMessageDto.setMessageId(idWorker.nextId()+""); - userMessageDto.setHavaRead(0); + userMessageDto.setHaveRead(0); userMessageDto.setSendTime(new Date()); rabbitTemplate.convertAndSend("userMessage",userMessageDto); } @@ -39,4 +51,43 @@ public class UserMessageService { return userMessageDao.findAllByUserId(userId); } + + public Page findSearch(String userId,int page,int size) { + + + PageRequest pageRequest = PageRequest.of(page-1,size); + return userMessageDao.findByUserId(userId,pageRequest); + } + + + public void haveRead(String messageId) { + + Query query = new Query(); + query.addCriteria(Criteria.where("_id").is(messageId)); + Update update = new Update(); + update.set("haveRead",1); //已读为1 + mongoTemplate.updateFirst(query,update,UserMessage.class); + + } + + + + public void batchHaveRead(List userMessageList) { + + BulkOperations bulkOps = mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, UserMessage.class); + + for (UserMessage userMessage: userMessageList) { + Query query = new Query(); + query.addCriteria(Criteria.where("_id").is(userMessage.getMessageId())); + Update update = new Update(); + update.set("haveRead",1); //已读为1 + // 添加更新操作 + bulkOps.updateOne(query,update); + + } + + //执行批量更新操作 + + BulkWriteResult result = bulkOps.execute(); + } } From 45e78101a279701c4cbbe2917a1a9750e91bd41e Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 24 Jan 2024 00:58:26 +0800 Subject: [PATCH 4/8] 1.change count from Integer to int --- .../java/com/luoo/user/controller/MyController.java | 12 ++++++------ .../main/java/com/luoo/user/dao/UserCollectDao.java | 4 ++-- .../java/com/luoo/user/dto/response/UserRespDTO.java | 12 ++++++------ .../src/main/java/com/luoo/user/pojo/UserInfo.java | 6 +++--- .../com/luoo/user/service/UserCollectService.java | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index e08f66c..d8a60d4 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -72,16 +72,16 @@ public class MyController extends BaseController{ UserInfo user = userInfoService.findById(userLoginDto.getUserId()); BeanUtils.copyProperties(user, userRespDTO); //EnumMap map=userCollectService.getUserCollectTypeMap(user.getId()); - Long fansCount=userCollectService.getFansCount(user.getId()); - Long followCount=userCollectService.getCount(user.getId(),CollectTypeEnum.FOLLOW.getType()); - Long thumbUpCount=userCollectService.getCount(user.getId(),CollectTypeEnum.THUMB_UP.getType()); - Long songCount=userCollectService.getCount(user.getId(),CollectTypeEnum.SONG.getType()); - Long journalCount=userCollectService.getCount(user.getId(),CollectTypeEnum.JOURNAL.getType()); + int fansCount=userCollectService.getFansCount(user.getId()); + int followCount=userCollectService.getCount(user.getId(),CollectTypeEnum.FOLLOW.getType()); + int thumbUpCount=userCollectService.getCount(user.getId(),CollectTypeEnum.THUMB_UP.getType()); + int songCount=userCollectService.getCount(user.getId(),CollectTypeEnum.SONG.getType()); + int journalCount=userCollectService.getCount(user.getId(),CollectTypeEnum.JOURNAL.getType()); userRespDTO.setFollowCount(followCount); userRespDTO.setFansCount(fansCount); userRespDTO.setThumbUpCount(thumbUpCount); - userRespDTO.setCommentReplyCount(0L); + userRespDTO.setCommentReplyCount(0); userRespDTO.setSongCount(songCount); userRespDTO.setJournalCount(journalCount); diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java index bce5f94..74ba5e1 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserCollectDao.java @@ -15,6 +15,6 @@ public interface UserCollectDao extends MongoRepository { //@Query(value = "select NumberInt(collectType),count(*) from common.userCollect where userId=?1 group by collectType", nativeQuery = true) //public List countByUserIdAndGroupByCollectType(String userId); - public long countByObjectIdAndCollectType(String objectId, Integer collectType); - public long countByUserIdAndCollectType(String userId, Integer collectType); + public int countByObjectIdAndCollectType(String objectId, Integer collectType); + public int countByUserIdAndCollectType(String userId, Integer collectType); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index 0a4b350..b99b71f 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -18,15 +18,15 @@ public class UserRespDTO { @ApiModelProperty(value = "用户标识,如“贡献者”,“音乐人”") private String badge; @ApiModelProperty(value = "关注数") - private Long followCount; + private int followCount; @ApiModelProperty(value = "粉丝数") - private Long fansCount; + private int fansCount; @ApiModelProperty(value = "获赞数") - private Long thumbUpCount; + private int thumbUpCount; @ApiModelProperty(value = "喜欢歌曲数") - private Long songCount; + private int songCount; @ApiModelProperty(value = "收藏期刊数") - private Long journalCount; + private int journalCount; @ApiModelProperty(value = "获得评论数") - private Long commentReplyCount; + private int commentReplyCount; } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java index be561c7..680046d 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java @@ -67,11 +67,11 @@ public class UserInfo implements Serializable { /** * 粉丝数 */ - private Integer fansCount; + private int fansCount; /** * 关注数 */ - private Integer followCount; + private int followCount; /** * 创建时间 */ @@ -111,5 +111,5 @@ public class UserInfo implements Serializable { /** * 0:禁用 1:正常 */ - private Integer status; + private int status; } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java b/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java index 15b1c34..8b355a3 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java @@ -59,11 +59,11 @@ public class UserCollectService { return userCollectTypeMap; } - public Long getFansCount(String userId) { + public int getFansCount(String userId) { return userCollectDao.countByObjectIdAndCollectType(userId,CollectTypeEnum.FOLLOW.getType()); } - public Long getCount(String userId, Integer type) { + public int getCount(String userId, Integer type) { return userCollectDao.countByUserIdAndCollectType(userId,type); } } From 602856682de2ae7beaba68168f76c0de3f0ef2fd Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 24 Jan 2024 07:14:10 +0800 Subject: [PATCH 5/8] add s3 upload function for luoo_music --- luoo_music/pom.xml | 6 + .../com/luoo/music/config/AwsS3Config.java | 44 ++++++++ .../luoo/music/controller/S3Controller.java | 75 +++++++++++++ .../com/luoo/music/service/S3Service.java | 103 ++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java create mode 100644 luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java create mode 100644 luoo_music/src/main/java/com/luoo/music/service/S3Service.java diff --git a/luoo_music/pom.xml b/luoo_music/pom.xml index 0b9600d..0cce7b0 100644 --- a/luoo_music/pom.xml +++ b/luoo_music/pom.xml @@ -57,6 +57,12 @@ tika-core 1.27 + + + + software.amazon.awssdk + s3 + app diff --git a/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java b/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java new file mode 100644 index 0000000..ba8e41a --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java @@ -0,0 +1,44 @@ +package com.luoo.music.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.S3Configuration; +import software.amazon.awssdk.services.s3.presigner.S3Presigner; + +import java.net.URI; + +@Configuration +public class AwsS3Config { + + private static final Region region = Region.of("cn-east-1"); + + @Bean + public S3Client s3Client(){ + AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); + S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); + S3Client s3 = S3Client.builder() + .endpointOverride(URI.create("https://s3.bitiful.net/")) + .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) + .region(region) + .serviceConfiguration(s3Config) + .build(); + + return s3; + } + + @Bean + public S3Presigner s3Presigner(){ + S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); + S3Presigner presigner = S3Presigner.builder() + .endpointOverride(URI.create("https://s3.bitiful.net/")) + .region(region) + .build(); + + return presigner; + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java b/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java new file mode 100644 index 0000000..d9a3aa2 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java @@ -0,0 +1,75 @@ +package com.luoo.music.controller; + + +import api.Result; +import com.luoo.music.service.S3Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +@RestController +@CrossOrigin +public class S3Controller { + + @Autowired + private S3Service s3Service; + + + @GetMapping("/awstest") + public Result test() throws UnsupportedEncodingException { + +// s3Service.listObjects() + List list = s3Service.list(); + return Result.success(); + } + + + /** + * 文件存储目录规划 + * + * music 存放期刊和期刊歌曲 二级目录为期刊期刊号 三级目录存放期刊歌曲和封面图片和歌曲图片 + * + * song 存放通用歌曲 + * + * image存放图片 + * + * img + * + * user/avatar/111.jpg + * + * + * + * + */ + @PostMapping("/awsUpload") + public Result upload(MultipartFile file) { + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); +// String fileName = UUID.randomUUID().toString().trim().replaceAll("-", ""); + + + String filePath = sdf.format(new Date()) + "/" + file.getOriginalFilename(); + try{ + int code = s3Service.singleUpload("indie", filePath, file); + + } catch (Exception ex){ + } + + + return Result.success(); + } + + @PostMapping("/awsCopy") + public Result copy() { + s3Service.copy(); + return Result.success(); + } +} diff --git a/luoo_music/src/main/java/com/luoo/music/service/S3Service.java b/luoo_music/src/main/java/com/luoo/music/service/S3Service.java new file mode 100644 index 0000000..a7a83a6 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/service/S3Service.java @@ -0,0 +1,103 @@ +package com.luoo.music.service; + +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.http.SdkHttpResponse; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.*; +import software.amazon.awssdk.services.s3.presigner.S3Presigner; + +import javax.annotation.Resource; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.List; + + +@Service +public class S3Service { + @Resource + private S3Client s3Client; + + @Resource + private S3Presigner s3Presigner; + +// +// public ListObjectsResponse listObjects(){ +// ListObjectsResponse indie = s3Client.listObjects( ListObjectsV2Request.builder().bucket("indie")); +// return indie; +// } + + + public List list() throws UnsupportedEncodingException { +// if(StringUtil.isEmpty(bucket)) return ResultUtil.resultFail("参数错误"); + + ListObjectsV2Request.Builder builder = ListObjectsV2Request.builder(); + // 设置bucket + builder.bucket("indie"); + + + ListObjectsV2Request listObjReq = builder.build(); + ListObjectsV2Response listObjRes = s3Client.listObjectsV2(listObjReq); + + + + List s3ObjectList = listObjRes.contents(); + + + return s3ObjectList; + } + + + + /** + * 异步完整上传不分片 + * @param bucket bucket + * @param key 对象路径 + * @param file 文件对象 + */ +// @Async("awsThreadPoolExecutor") + public int singleUpload(String bucket, String key, MultipartFile file) throws IOException { + Long startTime = System.currentTimeMillis() / 1000; + PutObjectRequest putObjectRequest = PutObjectRequest.builder() + .bucket(bucket) + .key(key) + .build(); + RequestBody requestBody = RequestBody.fromInputStream(file.getInputStream(), file.getSize()); + PutObjectResponse putObjectResponse = s3Client.putObject(putObjectRequest, requestBody); + SdkHttpResponse sdkHttpResponse = putObjectResponse.sdkHttpResponse(); + if(!sdkHttpResponse.isSuccessful()){ + return -1; + } + long endTime = System.currentTimeMillis() / 1000; +// log.info("上传文件(" + key + ")总计耗费时间为:" + (endTime - startTime) + " 秒"); + + return 1; + } + + + + public int copy() { + + String bucket = "indie"; //存储桶名 + String sourceKey = "20240121/1.mp3"; //copy的源文件路径 + String destinationKey = "20240121/2.mp3"; // copy的目的地路径 + CopyObjectResponse copyObjectResponse = s3Client.copyObject(CopyObjectRequest.builder().sourceBucket(bucket).sourceKey(sourceKey).destinationBucket(bucket).destinationKey(destinationKey).build()); + SdkHttpResponse sdkHttpResponse = copyObjectResponse.sdkHttpResponse(); + if(!sdkHttpResponse.isSuccessful()){ + return -1; + } + return 1; + } + + public void uploadAvatar(String bucket, String key, byte[] buffer) { + PutObjectRequest putObjectRequest = PutObjectRequest.builder() + .bucket(bucket) + .key(key) + .build(); + RequestBody requestBody = RequestBody.fromInputStream(new ByteArrayInputStream(buffer), buffer.length); + s3Client.putObject(putObjectRequest, requestBody); + } + +} From a971d104fc1432c804df342508da09c3c3f0216c Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 24 Jan 2024 11:12:26 +0800 Subject: [PATCH 6/8] 1.user info response add birthday --- .../src/main/java/com/luoo/user/controller/MyController.java | 4 +++- .../src/main/java/com/luoo/user/dto/response/UserRespDTO.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index d8a60d4..8b761a9 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -84,7 +84,9 @@ public class MyController extends BaseController{ userRespDTO.setCommentReplyCount(0); userRespDTO.setSongCount(songCount); userRespDTO.setJournalCount(journalCount); - + if(null!=user.getBirthday()) { + userRespDTO.setBirthDay(DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); + } return Result.success(userRespDTO); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java index b99b71f..2f92b11 100644 --- a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -29,4 +29,6 @@ public class UserRespDTO { private int journalCount; @ApiModelProperty(value = "获得评论数") private int commentReplyCount; + @ApiModelProperty(value = "生日,格式为: yyyy.MM.dd") + private String birthDay; } From e7875cbda60037be2330ade2efd684a14c144331 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 24 Jan 2024 11:25:08 +0800 Subject: [PATCH 7/8] 1.add image path to frontend --- .../src/main/java/com/luoo/user/controller/MyController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index 8b761a9..0eae87f 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -132,7 +132,7 @@ public class MyController extends BaseController{ @ApiOperation(value = "3.上传个人头像", notes = "图片压缩为70X70 JPEG,存入S3,桶为indie,目录为 user/avatar/") @PostMapping("/uploadAvatar") @GlobalInterceptor(checkLogin = true) - public Result uploadAvatar(@RequestHeader(value = "token", required = false) String token, + public Result uploadAvatar(@RequestHeader(value = "token", required = false) String token, @VerifyParam(required = true) MultipartFile file) throws IOException { UserLoginDto userLoginDto = getUserLoginDto(token); @@ -145,6 +145,6 @@ public class MyController extends BaseController{ user.setAvatar(filePath); userInfoService.update(user); - return Result.success(); + return Result.success(filePath); } } From 5c57bdfaef3039f25e0166fd75d69954317226e6 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 24 Jan 2024 14:33:18 +0800 Subject: [PATCH 8/8] UserCollectInfo with MongoDB --- .../controller/UserCollectInfoController.java | 37 ++++++++++ .../com/luoo/user/dao/UserCollectInfoDao.java | 9 +++ .../luoo/user/dto/UserCollectJournalDto.java | 59 ++++++++++++++++ .../com/luoo/user/dto/UserCollectSongDto.java | 67 +++++++++++++++++++ .../com/luoo/user/pojo/UserCollectInfo.java | 40 +++++++++++ .../user/service/UserCollectInfoService.java | 61 +++++++++++++++++ 6 files changed, 273 insertions(+) create mode 100644 luoo_user/src/main/java/com/luoo/user/controller/UserCollectInfoController.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dao/UserCollectInfoDao.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/UserCollectJournalDto.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/UserCollectSongDto.java create mode 100644 luoo_user/src/main/java/com/luoo/user/pojo/UserCollectInfo.java create mode 100644 luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectInfoController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectInfoController.java new file mode 100644 index 0000000..65f1207 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectInfoController.java @@ -0,0 +1,37 @@ +package com.luoo.user.controller; + + +import api.Result; +import com.luoo.user.pojo.UserCollectInfo; +import com.luoo.user.service.UserCollectInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/UserCollectInfo") +public class UserCollectInfoController { + + + @Autowired + private UserCollectInfoService userCollectInfoService; + + + @PostMapping("/save") + public Result save(){ + userCollectInfoService.save(); + return Result.success(); + } + + @GetMapping("/show") + public Result show(){ + UserCollectInfo userCollectInfo =userCollectInfoService.findByUserId(); + return Result.success(userCollectInfo); + } + + @PutMapping("/unCollect") + public Result unCollect() { + userCollectInfoService.unCollect(); + return Result.success(); + } + +} diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserCollectInfoDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserCollectInfoDao.java new file mode 100644 index 0000000..21d7e48 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserCollectInfoDao.java @@ -0,0 +1,9 @@ +package com.luoo.user.dao; + +import com.luoo.user.pojo.UserCollectInfo; +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface UserCollectInfoDao extends MongoRepository { + + UserCollectInfo findUserCollectInfoByUserId(String userId); +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/UserCollectJournalDto.java b/luoo_user/src/main/java/com/luoo/user/dto/UserCollectJournalDto.java new file mode 100644 index 0000000..932c189 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserCollectJournalDto.java @@ -0,0 +1,59 @@ +package com.luoo.user.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + + +@Data +public class UserCollectJournalDto implements Serializable { + private String id; + + /** + * 期刊编号 + */ + private String number; + /** + * 期刊标题 + */ + private String name; + /** + * 期刊简介 + */ + private String summary; + /** + * 用户ID + */ + private String userId; + /** + * 启停状态 停用:0,启用:1 + */ + private String state; + /** + * 发布状态 未发布:0,已发布:1 + */ + private String status; + /** + * 是否定时 否:0 是:1 + */ + private String scheduled; + /** + * 封面路径 + */ + private String coverPhoto; + /** + * 发布日期 + */ + private LocalDateTime pubTime; + /** + * 创建日期 + */ + private LocalDateTime createTime; + /** + * 更新日期 + */ + private LocalDateTime updateTime; + + +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/UserCollectSongDto.java b/luoo_user/src/main/java/com/luoo/user/dto/UserCollectSongDto.java new file mode 100644 index 0000000..5eec7b0 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserCollectSongDto.java @@ -0,0 +1,67 @@ +package com.luoo.user.dto; + +import lombok.Data; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; + +import java.io.Serializable; +import java.time.LocalDateTime; + + +@Data +public class UserCollectSongDto implements Serializable { + + private String id; + + /** + * 歌曲名称 + */ + private String name; + /** + * 歌手或乐队 + */ + private String artist; + /** + * 专辑 + */ + private String album; + /** + * 封面图片路径 + */ + private String picture; + /** + * 歌曲状态 0:停用,1:启用 + */ + private String state; + /** + * 文件大小 + */ + private Long size; + /** + * 歌曲时长 + */ + private Long duration; + /** + * 歌曲文件路径 + */ + private String url; + /** + * 歌词 + */ + private String lyric; + /** + * 上传人员ID + */ + private String userId; + /** + * 创建日期 + */ + private LocalDateTime createTime; + /** + * 更新日期 + */ + private LocalDateTime updateTime; + + + +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserCollectInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserCollectInfo.java new file mode 100644 index 0000000..2313084 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserCollectInfo.java @@ -0,0 +1,40 @@ +package com.luoo.user.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + + +@Data +public class UserCollectInfo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 收藏ID + */ + @Id + private String collectId; + + /** + * 用户ID + */ + private String userId; + + /** + * 收藏的单曲 + */ + private List songList; + + + + /** + * 收藏的期刊 + */ + private List journalList; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java new file mode 100644 index 0000000..16cde92 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/UserCollectInfoService.java @@ -0,0 +1,61 @@ +package com.luoo.user.service; + + +import com.luoo.user.dao.UserCollectInfoDao; +import com.luoo.user.dto.UserCollectSongDto; +import com.luoo.user.pojo.UserCollectInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.stereotype.Service; +import util.IdWorker; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class UserCollectInfoService { + + @Autowired + private UserCollectInfoDao userCollectInfoDao; + + @Autowired + private IdWorker idWorker; + + + public void save() { + + UserCollectInfo userCollectInfo = new UserCollectInfo(); + UserCollectSongDto userCollectSongDto = new UserCollectSongDto(); + userCollectSongDto.setName("smell like teensprit"); + userCollectSongDto.setArtist("Nirvana"); + + UserCollectSongDto userCollectSongDto1 = new UserCollectSongDto(); + userCollectSongDto1.setName("the unforgiven"); + userCollectSongDto1.setArtist("Metallica"); + + List list = new ArrayList(); + list.add(userCollectSongDto); + list.add(userCollectSongDto1); + userCollectInfo.setSongList(list); + userCollectInfo.setCollectId(idWorker.nextId()+""); + userCollectInfo.setUserId("111222"); + userCollectInfoDao.save(userCollectInfo); + } + + + public UserCollectInfo findByUserId(){ + + return userCollectInfoDao.findUserCollectInfoByUserId("111222"); + } + + public void unCollect(){ + UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId("111222"); + UserCollectSongDto userCollectSongDto = new UserCollectSongDto(); + userCollectSongDto.setName("smell like teensprit"); + userCollectSongDto.setArtist("Nirvana"); + userCollectInfo.getSongList().remove(userCollectSongDto); + userCollectInfoDao.save(userCollectInfo); + } +}