初始话
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.jiayunet</groupId>
|
||||
<artifactId>back_end</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>manager</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jiayunet</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.jiayunet.constant;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Oss桶
|
||||
*/
|
||||
@Getter
|
||||
public enum OssBucketEnum {
|
||||
|
||||
|
||||
HuiDongNi("oss-cn-guangzhou.aliyuncs.com", "jiayupet", 1,"https://jiayupet.oss-cn-guangzhou.aliyuncs.com");
|
||||
/**
|
||||
* 服务端口
|
||||
*/
|
||||
private final String endpoint;
|
||||
/**
|
||||
* 桶名
|
||||
*/
|
||||
private final String bucketName;
|
||||
/**
|
||||
* 权限 0 私有 1公共读 2 公共读写
|
||||
*/
|
||||
private final int power;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final String domain;
|
||||
|
||||
OssBucketEnum(String endpoint, String bucketName, int power, String domain) {
|
||||
this.endpoint = endpoint;
|
||||
this.bucketName = bucketName;
|
||||
this.power = power;
|
||||
this.domain = domain;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.jiayunet.constant;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* oss 文件路径
|
||||
*/
|
||||
@Getter
|
||||
public enum OssPathEnum {
|
||||
UserImage("image/user", "用户图片"),
|
||||
ResumeImage("image/resume", "简历图片"),
|
||||
SystemImage("image/system", "系统图片"),
|
||||
ResumeFile("file/resume", "简历文件"),
|
||||
|
||||
;
|
||||
/**
|
||||
* 文件存放目录
|
||||
*/
|
||||
private final String catalogue;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private final String comment;
|
||||
|
||||
OssPathEnum(String catalogue, String comment) {
|
||||
this.catalogue = catalogue;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件路径
|
||||
*
|
||||
* @param fileName 文件全名
|
||||
* @return oss 文件存放路径
|
||||
*/
|
||||
public String getPath(String fileName) {
|
||||
Assert.hasText(fileName, "获取oss文件路径文件名不能为空");
|
||||
String name = UUID.randomUUID().toString().replace("-", "").substring(0, 9);
|
||||
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
||||
return catalogue + "/" + name + fileType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.jiayunet.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.jiayunet.sms.VerifyCodeAttribute;
|
||||
|
||||
/**
|
||||
* @author zk
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SmsVerifyCodeEnum implements VerifyCodeAttribute {
|
||||
/**
|
||||
* 通用验证码
|
||||
*/
|
||||
UNIVERSAL("加鱼宠物", "SMS_480245067", "universal:code:sms:", 5, false);
|
||||
|
||||
|
||||
/**
|
||||
* 模板签名
|
||||
*/
|
||||
private final String signName;
|
||||
/**
|
||||
* 模板code
|
||||
*/
|
||||
private final String templateCode;
|
||||
/**
|
||||
* redis 名
|
||||
*/
|
||||
private final String redisKeyPre;
|
||||
/**
|
||||
* 有效时间 单位分钟
|
||||
*/
|
||||
private final Integer effectiveTime;
|
||||
/**
|
||||
* 覆盖已存在的redis值
|
||||
*/
|
||||
private final Boolean cover;
|
||||
|
||||
|
||||
public String getRedisKey(String phone) {
|
||||
Assert.hasText(phone, "手机号码不能为空");
|
||||
return this.redisKeyPre + phone;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.jiayunet.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/public/actuator")
|
||||
public class HealthCheckController {
|
||||
|
||||
/**
|
||||
* 健康检查
|
||||
*/
|
||||
@RequestMapping("/health")
|
||||
public String healthCheck() {
|
||||
return "Service is running";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.jiayunet.controller;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.jiayunet.constant.OssPathEnum;
|
||||
import org.jiayunet.pojo.vo.OssUrlVo;
|
||||
import org.jiayunet.server.OssServer;
|
||||
|
||||
/**
|
||||
* oss控制类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oss")
|
||||
@AllArgsConstructor
|
||||
@Validated
|
||||
public class OssController {
|
||||
private OssServer ossServer;
|
||||
|
||||
@GetMapping("/requestUploadUrl")
|
||||
public OssUrlVo requestUploadUrl(@RequestParam String fileName, @RequestParam OssPathEnum pathEnum){
|
||||
return ossServer.requestUploadUrl(fileName,pathEnum);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.jiayunet.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.jiayunet.pojo.po.OssFile;
|
||||
|
||||
/**
|
||||
* @author zk
|
||||
*/
|
||||
@Mapper
|
||||
public interface OssFileMapper extends CommonMapper<OssFile>{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.jiayunet.mapper;
|
||||
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.jiayunet.pojo.po.User;
|
||||
|
||||
/**
|
||||
* userMapper控制类
|
||||
*
|
||||
* @author zk
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends CommonMapper<User> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.jiayunet.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* Oss文件存储
|
||||
* @author zk
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("bg_oss_file")
|
||||
public class OssFile {
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 桶名
|
||||
*/
|
||||
private String bucketName;
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
*文件路径
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String fileName;
|
||||
/**
|
||||
* 上传用户
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 状态 0 正常 1删除
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Instant createTime;
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
private Instant deleteTime;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package org.jiayunet.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* 用户基本信息类
|
||||
*
|
||||
* @author zk
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "bg_user")
|
||||
public class User {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobileNumber;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* 登陆密码
|
||||
*/
|
||||
private String loginPassword;
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nick;
|
||||
/**
|
||||
* 真实名字
|
||||
*/
|
||||
private String realName;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String picture;
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
private Instant birthday;
|
||||
/**
|
||||
* 性别 1男 2女
|
||||
*/
|
||||
private Integer sex;
|
||||
/**
|
||||
* 微信头像
|
||||
*/
|
||||
private String wechatAvatar;
|
||||
/**
|
||||
* 学员的微信昵称
|
||||
*/
|
||||
private String wechatNick;
|
||||
/**
|
||||
* 微信openid
|
||||
*/
|
||||
private String wechatOpenid;
|
||||
/**
|
||||
* 微信UnionId
|
||||
*/
|
||||
private String wechatUnionId;
|
||||
/**
|
||||
* 状态 0 正常 1 禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 添加时间
|
||||
*/
|
||||
private Instant createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Instant updateTime;
|
||||
|
||||
/**
|
||||
* 删除标识 0正常 非0 删除
|
||||
*/
|
||||
@TableLogic(value = "0", delval = "new()")
|
||||
private Long isDelete;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.jiayunet.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* oss 文件路径
|
||||
* @author zk
|
||||
*/
|
||||
@Data
|
||||
public class OssUrlVo {
|
||||
/**
|
||||
* 上传地址
|
||||
*/
|
||||
private String uploadUrl;
|
||||
/**
|
||||
* 下载地址
|
||||
*/
|
||||
private String downloadUrl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.jiayunet.server;
|
||||
|
||||
import com.aliyun.oss.HttpMethod;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.jiayunet.constant.OssBucketEnum;
|
||||
import org.jiayunet.constant.OssPathEnum;
|
||||
import org.jiayunet.exception.BusinessException;
|
||||
import org.jiayunet.exception.BusinessExpCodeEnum;
|
||||
import org.jiayunet.mapper.OssFileMapper;
|
||||
import org.jiayunet.oss.AliOssAbility;
|
||||
import org.jiayunet.pojo.po.OssFile;
|
||||
import org.jiayunet.pojo.vo.OssUrlVo;
|
||||
import org.jiayunet.tool.UserSecurityTool;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* Oss 服务类
|
||||
*
|
||||
* @author zk
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class OssServer {
|
||||
|
||||
|
||||
private AliOssAbility aliOssAbility;
|
||||
private OssFileMapper ossFileMapper;
|
||||
|
||||
/**
|
||||
* 申请上传文件签名授权地址
|
||||
*
|
||||
* @return 地址
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public OssUrlVo requestUploadUrl(String fileName, OssPathEnum pathEnum) {
|
||||
Assert.notNull(pathEnum, " 上传路径不能为空");
|
||||
Assert.hasText(fileName, "文件不能为空");
|
||||
Assert.isTrue(fileName.lastIndexOf(".") >= 0, "文件名必须包含类型");
|
||||
|
||||
OssBucketEnum jiaYuPet = OssBucketEnum.HuiDongNi;
|
||||
Long userId = UserSecurityTool.getUserId();
|
||||
String type = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
String path = pathEnum.getPath(fileName);
|
||||
|
||||
|
||||
OssUrlVo ossUrlVo = new OssUrlVo();
|
||||
|
||||
try {
|
||||
//保存上传信息
|
||||
ossFileMapper.insert(new OssFile(null, jiaYuPet.getBucketName(), type, path, fileName, userId, 0, Instant.now(), null));
|
||||
|
||||
//获取上传Url
|
||||
String uploadUrl = aliOssAbility.signatureUrl(jiaYuPet.getEndpoint(), jiaYuPet.getBucketName(), path, 60, HttpMethod.PUT);
|
||||
|
||||
//组装下载地址
|
||||
String downloadUrl = jiaYuPet.getDomain() + "/" + path;
|
||||
|
||||
ossUrlVo.setUploadUrl(uploadUrl);
|
||||
ossUrlVo.setDownloadUrl(downloadUrl);
|
||||
|
||||
return ossUrlVo;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(BusinessExpCodeEnum.UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public OssUrlVo simpleUpload(String fileName, OssPathEnum pathEnum, InputStream inputStream) {
|
||||
Assert.notNull(pathEnum, " 上传路径不能为空");
|
||||
Assert.hasText(fileName, "文件不能为空");
|
||||
Assert.isTrue(fileName.lastIndexOf(".") >= 0, "文件名必须包含类型");
|
||||
|
||||
OssBucketEnum jiaYuPet = OssBucketEnum.HuiDongNi;
|
||||
Long userId = UserSecurityTool.getUserId();
|
||||
String type = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
String path = pathEnum.getPath(fileName);
|
||||
|
||||
|
||||
OssUrlVo ossUrlVo = new OssUrlVo();
|
||||
|
||||
try {
|
||||
//保存上传信息
|
||||
ossFileMapper.insert(new OssFile(null, jiaYuPet.getBucketName(), type, path, fileName, userId, 0, Instant.now(), null));
|
||||
|
||||
aliOssAbility.simpleUpload(jiaYuPet.getEndpoint(), jiaYuPet.getBucketName(), path, inputStream);
|
||||
inputStream.close();
|
||||
|
||||
|
||||
//组装下载地址
|
||||
String downloadUrl = jiaYuPet.getDomain() + "/" + path;
|
||||
|
||||
ossUrlVo.setUploadUrl(downloadUrl);
|
||||
ossUrlVo.setDownloadUrl(downloadUrl);
|
||||
return ossUrlVo;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(BusinessExpCodeEnum.UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user