Merge branch 'dev'
commit
7ce2d8884a
|
@ -0,0 +1,86 @@
|
|||
package com.muyu.cloud.market.domin;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.background.domin
|
||||
* @Project:cloud-background
|
||||
* @name:Company
|
||||
* @Date:2024/8/26 18:44
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "company",autoResultMap = true)
|
||||
public class Company {
|
||||
/**
|
||||
* 企业ID
|
||||
*/
|
||||
@TableId(value = "company_id",type = IdType.AUTO)
|
||||
private Integer companyId;
|
||||
/**
|
||||
*企业名称
|
||||
*/
|
||||
private String companyName;
|
||||
/**
|
||||
*企业头像
|
||||
*/
|
||||
private String companyPhoto;
|
||||
/**
|
||||
* 企业法人
|
||||
*/
|
||||
private String companyLeader;
|
||||
/**
|
||||
*注册人姓名
|
||||
*/
|
||||
private String registrantName;
|
||||
/**
|
||||
*注册人联系方式
|
||||
*/
|
||||
private String registrantPhone;
|
||||
/**
|
||||
*注册人职位
|
||||
*/
|
||||
private String registrantPosition;
|
||||
/**
|
||||
*注册日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "注册日期",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date registrantDate;
|
||||
/**
|
||||
*社会统一信用代码
|
||||
*/
|
||||
private String USCI;
|
||||
/**
|
||||
*企业营业执照
|
||||
*/
|
||||
private String businessLicense;
|
||||
/**
|
||||
*企业地址
|
||||
*/
|
||||
private String companyAddress;
|
||||
/**
|
||||
*审核状态
|
||||
*/
|
||||
private Integer reviewStatus;
|
||||
/**
|
||||
* 公司注册账户余额
|
||||
*/
|
||||
private BigDecimal companyMoney;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package com.muyu.cloud.market.domin;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.domin.resp
|
||||
* @Project:cloud-market
|
||||
* @name:User
|
||||
* @Date:2024/8/27 19:22
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "sys_user",autoResultMap = true)
|
||||
public class User {
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Integer deptId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户类型(00系统用户)
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phonenumber;
|
||||
|
||||
/**
|
||||
* 用户性别(0男 1女 2未知)
|
||||
*/
|
||||
private Integer sex;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除)
|
||||
*/
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 最后登录IP
|
||||
*/
|
||||
private String loginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "产品上架日期",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date loginDate;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "产品上架日期",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "产品上架日期",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 用户余额
|
||||
*/
|
||||
private BigDecimal userMoney;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.muyu.cloud.market.domin.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.background.domin.req
|
||||
* @Project:cloud-background
|
||||
* @name:CompanyListReq
|
||||
* @Date:2024/8/26 20:04
|
||||
*/
|
||||
|
||||
@Tag(name = "企业列表请求对象")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CompanyListReq {
|
||||
|
||||
/**
|
||||
*企业名称
|
||||
*/
|
||||
private String companyName;
|
||||
/**
|
||||
*企业头像
|
||||
*/
|
||||
private String companyPhoto;
|
||||
/**
|
||||
* 企业法人
|
||||
*/
|
||||
private String companyLeader;
|
||||
/**
|
||||
*注册人姓名
|
||||
*/
|
||||
private String registrantName;
|
||||
/**
|
||||
*注册人联系方式
|
||||
*/
|
||||
private String registrantPhone;
|
||||
/**
|
||||
*注册人职位
|
||||
*/
|
||||
private String registrantPosition;
|
||||
/**
|
||||
*社会统一信用代码
|
||||
*/
|
||||
private String USCI;
|
||||
/**
|
||||
*企业营业执照
|
||||
*/
|
||||
private String businessLicense;
|
||||
/**
|
||||
*企业地址
|
||||
*/
|
||||
private String companyAddress;
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.cloud.market.domin.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.domin.req
|
||||
* @Project:cloud-market
|
||||
* @name:LinkEmail
|
||||
* @Date:2024/8/27 19:08
|
||||
*/
|
||||
@Tag(name = "邮箱绑定")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LinkEmailReq {
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String code;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.cloud.market.domin.resp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.domin.resp
|
||||
* @Project:cloud-market
|
||||
* @name:LinkEmailResp
|
||||
* @Date:2024/8/28 18:55
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Tag(name = "绑定邮箱对象",description = "负责邮箱绑定的响应结果")
|
||||
public class LinkEmailResp {
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String code;
|
||||
}
|
|
@ -19,14 +19,25 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-market-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 图片上传 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.16.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 邮箱依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.cloud.market.controller;
|
||||
import com.muyu.cloud.market.util.OssUtil;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.controller
|
||||
* @Project:cloud-market
|
||||
* @name:CompanyController
|
||||
* @Date:2024/8/27 14:16
|
||||
*/
|
||||
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/company")
|
||||
@Tag(name = "企业管理控制层",description = "进行企业管理、查看等相关操作")
|
||||
public class CompanyController {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 图片上传
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(path = "/upload")
|
||||
@Operation(summary = "图片上传",description = "图片上传")
|
||||
public Result upload(MultipartFile file){
|
||||
String s=OssUtil.uploadMultipartFile(file);
|
||||
return Result.success(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.cloud.market.controller;
|
||||
|
||||
import com.muyu.cloud.market.domin.req.LinkEmailReq;
|
||||
import com.muyu.cloud.market.service.UserService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.controller
|
||||
* @Project:cloud-market
|
||||
* @name:UserController
|
||||
* @Date:2024/8/27 19:17
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
@Tag(name = "登录人信息",description = "进行登录人信息查看等相关操作")
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
||||
/**
|
||||
* 发送邮箱验证
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/sendcode/{email}")
|
||||
@Operation(summary = "发送邮箱验证",description = "绑定邮箱时,通过验证码来进行验证")
|
||||
public Result sendcode(@PathVariable String email){
|
||||
return Result.success(userService.sendcode(email));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱绑定
|
||||
* @param linkEmailReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(path = "/linkemail")
|
||||
@Operation(summary = "绑定邮箱",description = "进行邮箱的绑定")
|
||||
public Result linkemail(@RequestBody LinkEmailReq linkEmailReq, HttpServletRequest request){
|
||||
userService.linkemail(linkEmailReq,request);
|
||||
return Result.success(null, "操作成功");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.cloud.market.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.cloud.market.domin.Company;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.mapper
|
||||
* @Project:cloud-market
|
||||
* @name:CompanyMapper
|
||||
* @Date:2024/8/27 14:17
|
||||
*/
|
||||
@Mapper
|
||||
public interface CompanyMapper extends BaseMapper<Company> {
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.cloud.market.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.cloud.market.domin.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.mapper
|
||||
* @Project:cloud-market
|
||||
* @name:UserMapper
|
||||
* @Date:2024/8/27 19:30
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.cloud.market.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.cloud.market.domin.Company;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.service
|
||||
* @Project:cloud-market
|
||||
* @name:CompanyService
|
||||
* @Date:2024/8/27 14:17
|
||||
*/
|
||||
public interface CompanyService extends IService<Company> {
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.cloud.market.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.cloud.market.domin.User;
|
||||
import com.muyu.cloud.market.domin.req.LinkEmailReq;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.service
|
||||
* @Project:cloud-market
|
||||
* @name:UserService
|
||||
* @Date:2024/8/27 19:17
|
||||
*/
|
||||
public interface UserService extends IService<User> {
|
||||
|
||||
/**
|
||||
* 邮箱绑定
|
||||
* @param linkEmailReq
|
||||
* @return
|
||||
*/
|
||||
void linkemail(LinkEmailReq linkEmailReq,HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 发送邮箱验证
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
String sendcode(String email);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.cloud.market.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cloud.market.domin.Company;
|
||||
import com.muyu.cloud.market.mapper.CompanyMapper;
|
||||
import com.muyu.cloud.market.service.CompanyService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.service.impl
|
||||
* @Project:cloud-market
|
||||
* @name:CompanyServiceImpl
|
||||
* @Date:2024/8/27 14:17
|
||||
*/
|
||||
@Service
|
||||
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {
|
||||
}
|
|
@ -55,12 +55,6 @@ public class ProductApiServiceImpl extends ServiceImpl<ProductApiMapper, Product
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品销量和分页限制,查询结果
|
||||
* @param productSales
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package com.muyu.cloud.market.service.impl;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cloud.market.domin.User;
|
||||
import com.muyu.cloud.market.domin.req.LinkEmailReq;
|
||||
import com.muyu.cloud.market.mapper.UserMapper;
|
||||
import com.muyu.common.security.service.TokenService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.market.service.impl
|
||||
* @Project:cloud-market
|
||||
* @name:UserService
|
||||
* @Date:2024/8/27 19:32
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements com.muyu.cloud.market.service.UserService {
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
private JavaMailSender javaMailSender;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱绑定
|
||||
* @param linkEmailReq
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void linkemail(LinkEmailReq linkEmailReq, HttpServletRequest request) {
|
||||
String token = SecurityUtils.getToken();// 获取当前Token
|
||||
LoginUser loginUser = tokenService.getLoginUser(token); // 获取当前登录用户
|
||||
if (loginUser == null) {
|
||||
throw new RuntimeException("用户未登录或Token无效");
|
||||
}
|
||||
// 从请求对象中获取新的邮箱地址
|
||||
String newEmail = linkEmailReq.getEmail();
|
||||
// 如果新邮箱地址为空或无效,可以抛出异常或返回错误提示(这里简单处理为抛出异常)
|
||||
if (newEmail == null || newEmail.isEmpty()) {
|
||||
throw new RuntimeException("绑定邮箱地址不能为空");
|
||||
}
|
||||
|
||||
//判断验证码是否对得上
|
||||
String code = redisTemplate.opsForValue().get(newEmail);
|
||||
if (!code.equals(linkEmailReq.getCode())){
|
||||
throw new RuntimeException("邮箱绑定失败,验证码错误");
|
||||
}
|
||||
|
||||
User user = new User();
|
||||
user.setEmail(newEmail);
|
||||
int result = userMapper.update(null,
|
||||
new UpdateWrapper<User>().set("email", newEmail).eq("user_id", loginUser.getUserid()));
|
||||
if (result == 0) {
|
||||
throw new RuntimeException("邮箱绑定失败,可能用户不存在或已被其他操作修改");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮箱验证
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String sendcode(String email) {
|
||||
//生成验证码
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
//验证码存入redis中
|
||||
redisTemplate.opsForValue().set(email, code,5, TimeUnit.MINUTES);
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
|
||||
helper.setFrom("2392355487@qq.com");
|
||||
helper.setTo(email);
|
||||
helper.setSubject("验证码请查收");
|
||||
helper.setText(code);
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MessagingException e) {
|
||||
// 记录日志或进行其他恢复操作
|
||||
throw new RuntimeException("邮件发送失败:" + e.getMessage());
|
||||
}
|
||||
return code;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package com.muyu.cloud.market.util;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class OssUtil {
|
||||
|
||||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tDbRqXkC5i3SMrCSDcX";
|
||||
private static String accessKeySecret = "XUzMZoHPLsjNLafHsdQnMElBWZATsu";
|
||||
private static String accessPre = "https://mall-bw.oss-cn-shanghai.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "mall-bw";
|
||||
|
||||
private static OSS ossClient;
|
||||
|
||||
static {
|
||||
ossClient = new OSSClientBuilder().build(
|
||||
endPoint,
|
||||
accessKeyId,
|
||||
accessKeySecret);
|
||||
log.info("oss服务连接成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传本地文件
|
||||
*
|
||||
* @param filePath
|
||||
*/
|
||||
public static String uploadFile(String filePath) {
|
||||
return uploadFileForBucket(bucketName, getOssFilePath(filePath), filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传multipartFile文件
|
||||
*
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(MultipartFile multipartFile) {
|
||||
return uploadMultipartFile(bucketName, getOssFilePath(multipartFile.getOriginalFilename()), multipartFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传 multipartFile 类型文件
|
||||
*
|
||||
* @param bucketName
|
||||
* @param ossPath
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(String bucketName, String ossPath, MultipartFile multipartFile) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = multipartFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre + ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||
*
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileForBucket(String bucketName, String ossPath, String filePath) {
|
||||
// 创建PutObjectRequest对象。
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
|
||||
// 上传
|
||||
ossClient.putObject(putObjectRequest);
|
||||
return accessPre + ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用文件流上传到指定的bucket实例
|
||||
*
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileInputStreamForBucket(String bucketName, String ossPath, String filePath) {
|
||||
|
||||
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre + ossPath;
|
||||
}
|
||||
|
||||
public static void uploadFileInputStreamForBucket(String bucketName, String ossPath, InputStream inputStream) {
|
||||
ossClient.putObject(bucketName, ossPath, inputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param ossFilePath
|
||||
* @param filePath
|
||||
*/
|
||||
public static void downloadFile(String ossFilePath, String filePath) {
|
||||
downloadFileForBucket(bucketName, ossFilePath, filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param bucketName 实例名称
|
||||
* @param ossFilePath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static void downloadFileForBucket(String bucketName, String ossFilePath, String filePath) {
|
||||
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static String getOssDefaultPath() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String url =
|
||||
now.getYear() + "/" +
|
||||
now.getMonth() + "/" +
|
||||
now.getDayOfMonth() + "/" +
|
||||
now.getHour() + "/" +
|
||||
now.getMinute() + "/";
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String getOssFilePath(String filePath) {
|
||||
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
|
||||
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue