Merge branch 'main' into feature/240101-tag

main
itao 10 months ago
commit 6339c7d067

@ -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 haveRead;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date sendTime;
}

@ -1,30 +1,30 @@
package enums;
public enum CollectTypeEnum {
SONG(0, "歌曲"), JOURNAL(1, "期刊");
SONG(0, "歌曲"), JOURNAL(1, "期刊"), FOLLOW(2, "关注"), BLACK_LIST(3, "黑名单"), THUMB_UP(4, "点赞");
private Integer type;
private String description;
private Integer type;
private String description;
CollectTypeEnum(int type, String description) {
this.type = type;
this.description = description;
}
CollectTypeEnum(int type, String description) {
this.type = type;
this.description = description;
}
public Integer getType() {
return type;
}
public Integer getType() {
return type;
}
public String getDescription() {
return description;
}
public String getDescription() {
return description;
}
public static CollectTypeEnum getByType(Integer type) {
for (CollectTypeEnum at : CollectTypeEnum.values()) {
if (at.type.equals(type)) {
return at;
}
}
return null;
}
public static CollectTypeEnum getByType(Integer type) {
for (CollectTypeEnum at : CollectTypeEnum.values()) {
if (at.type.equals(type)) {
return at;
}
}
return null;
}
}

@ -57,6 +57,12 @@
<artifactId>tika-core</artifactId>
<version>1.27</version>
</dependency>
<!-- amazon s3 -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
</dependencies>
<build>
<finalName>app</finalName>

@ -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;
}
}

@ -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();
}
}

@ -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<S3Object> 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<S3Object> 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);
}
}

@ -46,8 +46,9 @@ import util.StringTools;
@CrossOrigin
@RequestMapping("/user")
@Api(tags = "LoginController")
public class LoginController extends BaseController{
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES=Arrays.asList(new CountryCodeDTO("中国","+86"));
public class LoginController extends BaseController {
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
.asList(new CountryCodeDTO("中国", "+86"));
@Autowired
private UserInfoService userInfoService;
@ -71,30 +72,44 @@ public class LoginController extends BaseController{
*/
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天内最多发送50个请求")
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
@ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86", required = false, defaultValue="+86"),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@ApiImplicitParam(name = "countryCode", value = "国家码,默认为‘+86", required = false, defaultValue = "+86"),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "imageCheckCode", value = "图形验证码", required = false) })
@PostMapping("/sendsms")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50)
public Result<Void> sendSms(
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam(name="countryCode",defaultValue="+86") String countryCode,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile) {
userInfoService.sendSms(deviceId,mobile);
public Result<Void> sendSms(@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam(name = "countryCode", defaultValue = "+86") String countryCode,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
@VerifyParam(required = false) @RequestParam("imageCheckCode") String imageCheckCode) {
if (!StringTools.isEmpty(imageCheckCode)) {
// 得到缓存中的验证码
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
if (StringTools.isEmpty(redisImageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
}
if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
}
redisTemplate.delete(redisImageCheckCodeKey);
}
userInfoService.sendSms(deviceId, mobile);
return Result.success();
}
@ApiOperation(value = "2.登录/注册", notes = "成功后返回token")
@ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true),
@ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true),
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@PostMapping("/appLogin")
@GlobalInterceptor
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
public Result appLogin(HttpServletRequest request,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam("deviceBrand") String deviceBrand) {
@RequestParam("deviceBrand") String deviceBrand) {
// 得到缓存中的验证码
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
try {
@ -116,34 +131,30 @@ public class LoginController extends BaseController{
}
}
/**
* token
*/
@ApiOperation(value = "3.token续期", notes = "有效期7天")
@ApiImplicitParams({
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true),
@ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) })
@PostMapping("/autoLogin")
@GlobalInterceptor
public Result<String> autoLogin(HttpServletRequest request,@RequestHeader(value = "token", required = false) String token,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam("deviceBrand") String deviceBrand) {
return Result.success(userInfoService.autoLogin(token,deviceId,deviceBrand,getIpAddr(request)));
public Result<String> autoLogin(HttpServletRequest request,
@RequestHeader(value = "token", required = false) String token,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam("deviceBrand") String deviceBrand) {
return Result.success(userInfoService.autoLogin(token, deviceId, deviceBrand, getIpAddr(request)));
}
/**
*
*/
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiImplicitParams({
@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true) })
@GetMapping("/imageCheckCode/{deviceId}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId)
throws IOException {
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
@ -155,35 +166,12 @@ public class LoginController extends BaseController{
vCode.write(response.getOutputStream());
}
@ApiOperation(value = "5.图形验证码+短信验证码 登录/注册后返回token")
@PostMapping("/appLoginWithImageCode")
@GlobalInterceptor
public Result appLoginWithImageCheckCode(
HttpServletRequest request,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile,
@VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode,
@VerifyParam(required = true) @RequestParam("deviceId") String deviceId,
@RequestParam("deviceBrand") String deviceBrand,
@VerifyParam(required = true) @RequestParam("imageCheckCode") String imageCheckCode) {
// 得到缓存中的验证码
String redisImageCheckCodeKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
if (StringTools.isEmpty(redisImageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
}
if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
}
redisTemplate.delete(redisImageCheckCodeKey);
return appLogin(request, mobile, mobileCheckCode, deviceId, deviceBrand);
}
/**
*
*/
@ApiOperation(value = "6.获取支持的手机号国家码", notes = "v1仅支持'+86'")
@ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'")
@GetMapping("/supportedCountryCode")
public Result<List<CountryCodeDTO>> getSupportedCountryCode(){
public Result<List<CountryCodeDTO>> getSupportedCountryCode() {
return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES);
}
}

@ -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,22 @@ public class MyController extends BaseController{
UserRespDTO userRespDTO = new UserRespDTO();
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
BeanUtils.copyProperties(user, userRespDTO);
//EnumMap<CollectTypeEnum,Long> map=userCollectService.getUserCollectTypeMap(user.getId());
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(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);
}
@ -110,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<Void> uploadAvatar(@RequestHeader(value = "token", required = false) String token,
public Result<String> uploadAvatar(@RequestHeader(value = "token", required = false) String token,
@VerifyParam(required = true) MultipartFile file) throws IOException {
UserLoginDto userLoginDto = getUserLoginDto(token);
@ -123,6 +145,6 @@ public class MyController extends BaseController{
user.setAvatar(filePath);
userInfoService.update(user);
return Result.success();
return Result.success(filePath);
}
}

@ -3,9 +3,7 @@ package com.luoo.user.controller;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.Result;
import client.vo.SimpleUser;
import com.luoo.user.service.UserCollectService;
import com.luoo.user.service.UserService;
import dto.UserLoginDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -15,8 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import util.JwtUtil;
import java.util.List;
@Api(tags = "UserCollectController")
@RestController
@RequestMapping("/userCollect")
@ -25,12 +21,11 @@ public class UserCollectController {
private JwtUtil jwtUtil;
@Autowired
private UserCollectService userCollectService;
@Autowired
private UserService userService;
@ApiOperation(value = "1.收藏/喜欢")
@ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id此处为歌曲/期刊id", required = true),
@ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型0为歌曲1为期刊", required = true) })
@ApiOperation(value = "1.喜欢歌曲/收藏期刊/关注/黑名单/点赞")
@ApiImplicitParams({
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@PostMapping("/addCollect")
@GlobalInterceptor(checkLogin = true)
public Result<Void> addCollect(@RequestHeader(value = "token", required = false) String token,
@ -41,9 +36,10 @@ public class UserCollectController {
return Result.success();
}
@ApiOperation(value = "2.取消 收藏/喜欢")
@ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id此处为歌曲/期刊id", required = true),
@ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型0为歌曲1为期刊", required = true) })
@ApiOperation(value = "2.取消 喜欢歌曲/收藏期刊/关注/黑名单/点赞")
@ApiImplicitParams({
@ApiImplicitParam(name = "objectId", value = "喜欢歌曲/收藏期刊/关注某用户/某用户列入黑名单/点赞评论的id", required = true),
@ApiImplicitParam(name = "collectType", value = "0:歌曲1:期刊2:关注3:黑名单4:点赞", required = true) })
@DeleteMapping("/cancelCollect")
@GlobalInterceptor(checkLogin = true)
public Result<Void> cancelCollect(@RequestHeader(value = "token", required = false) String token,
@ -54,13 +50,4 @@ public class UserCollectController {
collectType);
return Result.success();
}
/*
* @ApiOperation(value = "根据 IDs 获取用户简要信息")
*
* @GetMapping("/findUserByIds") public Result<List<SimpleUser>>
* findUserByIds(@RequestBody List<String> ids) { List<SimpleUser> userByIds =
* userService.findUserByIds(ids); return Result.success(userByIds); }
*/
}

@ -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();
}
}

@ -0,0 +1,61 @@
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;
@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();
}
/**IDTOKEN
* ID
* @return
*/
@GetMapping("/list/{userId}/{page}/{size}")
public Result list(@PathVariable String userId,@PathVariable int page,@PathVariable int size){
// List list = userMessageService.findByUserId(userId);
Page<UserMessage> pageList = userMessageService.findSearch(userId,page,size);
return Result.success(new PageResult<UserMessage>(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<UserMessage> userMessageList) {
userMessageService.batchHaveRead(userMessageList);
return Result.success();
}
}

@ -1,11 +1,43 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.AppUpdate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.luoo.user.pojo.AppUpdate;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
public interface AppUpdateDao extends JpaRepository<AppUpdate, String>, JpaSpecificationExecutor<AppUpdate> {
//AppUpdate selectLatestUpdate(String appVersion, String deviceId);
default AppUpdate selectLatestUpdate(String appVersion, String deviceId){
Specification<AppUpdate> appUpdateSpecification = createAppUpdateSpecification(appVersion, deviceId);
Sort createTimeDescSort = Sort.by(Sort.Direction.DESC, "createTime");
Page<AppUpdate> appUpdatePage = this.findAll(appUpdateSpecification, PageRequest.of(0, 1, createTimeDescSort));
if(appUpdatePage.getContent().isEmpty()){
return null;
}
return appUpdatePage.getContent().get(0);
}
default Specification<AppUpdate> createAppUpdateSpecification(String appVersion, String deviceId) {
return (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
predicateList.add(criteriaBuilder.greaterThan(root.get("version"), appVersion));
Predicate allPublishPredicate = criteriaBuilder.equal(root.get("status"), 2);
Predicate grayPublishPredicate = criteriaBuilder.equal(root.get("status"), 1);
Expression<Integer> grayDeviceExpress = criteriaBuilder
.function("find_in_set", Integer.class, criteriaBuilder.literal(deviceId), root.get("grayscaleDevice"));
Predicate grayDevicePredicate = criteriaBuilder.gt(grayDeviceExpress, 0);
Predicate grayScalePredicate = criteriaBuilder.and(grayPublishPredicate, grayDevicePredicate);
predicateList.add(criteriaBuilder.or(allPublishPredicate, grayScalePredicate));
Predicate[] predicates = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicates));
};
}
}

@ -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<UserCollect, String> {
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<UserCollectCount> countByUserIdAndGroupByCollectType(String userId);
public int countByObjectIdAndCollectType(String objectId, Integer collectType);
public int countByUserIdAndCollectType(String userId, Integer collectType);
}

@ -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, String> {
UserCollectInfo findUserCollectInfoByUserId(String userId);
}

@ -0,0 +1,19 @@
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;
public interface UserMessageDao extends MongoRepository<UserMessage,String> {
List<UserMessage> findAllByUserId(String userId);
Page<UserMessage> findByUserId(String userId, Pageable pageable);
}

@ -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;
}

@ -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;
/**
* 01
*/
private String state;
/**
* 01
*/
private String status;
/**
* 0 1
*/
private String scheduled;
/**
*
*/
private String coverPhoto;
/**
*
*/
private LocalDateTime pubTime;
/**
*
*/
private LocalDateTime createTime;
/**
*
*/
private LocalDateTime updateTime;
}

@ -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;
}

@ -17,4 +17,18 @@ public class UserRespDTO {
private String signature;
@ApiModelProperty(value = "用户标识,如“贡献者”,“音乐人”")
private String badge;
@ApiModelProperty(value = "关注数")
private int followCount;
@ApiModelProperty(value = "粉丝数")
private int fansCount;
@ApiModelProperty(value = "获赞数")
private int thumbUpCount;
@ApiModelProperty(value = "喜欢歌曲数")
private int songCount;
@ApiModelProperty(value = "收藏期刊数")
private int journalCount;
@ApiModelProperty(value = "获得评论数")
private int commentReplyCount;
@ApiModelProperty(value = "生日,格式为: yyyy.MM.dd")
private String birthDay;
}

@ -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);
}
}

@ -11,9 +11,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
@Entity
@ -58,6 +56,7 @@ public class AppUpdate implements Serializable {
*/
private String grayscaleDevice;
@Transient
private String[] updateDescArray;
public String[] getUpdateDescArray() {

@ -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;
}

@ -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;
}

@ -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 haveRead;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date sendTime;
}

@ -151,7 +151,6 @@ public class AppUpdateService {
*/
public AppUpdate getLatestUpdate(String appVersion, String deviceId) {
//return appUpdateDao.selectLatestUpdate(appVersion, deviceId);
return null;
return appUpdateDao.selectLatestUpdate(appVersion, deviceId);
}
}

@ -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);
}
}

@ -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<UserCollect> dbCollect = userCollectDao.findById(collectId);//.findByUserIdAndObjectIdAndCollectType(userId, objectId, collectType);
Optional<UserCollect> 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<CollectTypeEnum,Long> getUserCollectTypeMap(String userId) {
EnumMap<CollectTypeEnum,Long> userCollectTypeMap=new EnumMap<>(CollectTypeEnum.class);
/*
* List<UserCollectCount>
* userCollectCounts=userCollectDao.countByUserIdAndGroupByCollectType(userId);
*
* userCollectCounts.forEach(u->{ CollectTypeEnum collectTypeEnum =
* CollectTypeEnum.getByType(u.getCollectType());
* userCollectTypeMap.put(collectTypeEnum, u.getCount()); });
*/
return userCollectTypeMap;
}
public int getFansCount(String userId) {
return userCollectDao.countByObjectIdAndCollectType(userId,CollectTypeEnum.FOLLOW.getType());
}
public int getCount(String userId, Integer type) {
return userCollectDao.countByUserIdAndCollectType(userId,type);
}
}

@ -0,0 +1,93 @@
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;
import java.util.Date;
import java.util.List;
@Service
public class UserMessageService {
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private UserMessageDao userMessageDao;
@Autowired
private IdWorker idWorker;
@Autowired
private MongoTemplate mongoTemplate;
public void sendUserMessage(UserMessageDto userMessageDto) {
userMessageDto.setMessageId(idWorker.nextId()+"");
userMessageDto.setHaveRead(0);
userMessageDto.setSendTime(new Date());
rabbitTemplate.convertAndSend("userMessage",userMessageDto);
}
public List list() {
return userMessageDao.findAll();
}
public List findByUserId(String userId) {
return userMessageDao.findAllByUserId(userId);
}
public Page<UserMessage> 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<UserMessage> 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();
}
}

@ -0,0 +1,14 @@
-- 创建表
drop table if exists indie_user.tb_app_update;
create table if not exists indie_user.tb_app_update (
id varchar(100) not null comment 'ID' primary key,
version varchar(10) default '' not null comment '版本号',
update_desc varchar(500) default '' not null comment '更新描述',
update_type tinyint(1) default 0 not null comment '更新类型(0=全更新, 1=局部热更新)',
status tinyint(1) default 1 not null comment '状态(0=未发布, 1=灰度发布, 2=全网发布)',
grayscale_device varchar(4000) default '' not null comment '灰度设备ID集合(英文逗号相隔)',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间'
) comment '应用版本更新记录表';
create index idx_version on indie_user.tb_app_update (version);
create index idx_create_time on indie_user.tb_app_update (create_time);
Loading…
Cancel
Save