用户模块
This commit is contained in:
@ -79,7 +79,6 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo>
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件类型
|
||||
String fileType = FileUtil.getSuffix(fileName);
|
||||
// 获取文件路径
|
||||
// 获取view值
|
||||
String view = RandomStringUtils.random(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
|
||||
// 获取文件路径
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.greenorange.promotion.service.project;
|
||||
|
||||
import com.greenorange.promotion.model.entity.ProjectDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【project_detail(项目明细表)】的数据库操作Service
|
||||
* @createDate 2025-05-07 03:47:58
|
||||
*/
|
||||
public interface ProjectDetailService extends IService<ProjectDetail> {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.greenorange.promotion.service.project;
|
||||
|
||||
import com.greenorange.promotion.model.entity.ProjectNotification;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【project_notification(项目通知表)】的数据库操作Service
|
||||
* @createDate 2025-05-07 03:31:03
|
||||
*/
|
||||
public interface ProjectNotificationService extends IService<ProjectNotification> {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.greenorange.promotion.service.project.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.greenorange.promotion.model.entity.ProjectDetail;
|
||||
import com.greenorange.promotion.service.project.ProjectDetailService;
|
||||
import com.greenorange.promotion.mapper.ProjectDetailMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【project_detail(项目明细表)】的数据库操作Service实现
|
||||
* @createDate 2025-05-07 03:47:58
|
||||
*/
|
||||
@Service
|
||||
public class ProjectDetailServiceImpl extends ServiceImpl<ProjectDetailMapper, ProjectDetail>
|
||||
implements ProjectDetailService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.greenorange.promotion.service.project.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.greenorange.promotion.model.entity.ProjectNotification;
|
||||
import com.greenorange.promotion.service.project.ProjectNotificationService;
|
||||
import com.greenorange.promotion.mapper.ProjectNotificationMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【project_notification(项目通知表)】的数据库操作Service实现
|
||||
* @createDate 2025-05-07 03:31:03
|
||||
*/
|
||||
@Service
|
||||
public class ProjectNotificationServiceImpl extends ServiceImpl<ProjectNotificationMapper, ProjectNotification>
|
||||
implements ProjectNotificationService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.greenorange.promotion.service.user;
|
||||
|
||||
import com.greenorange.promotion.model.entity.UserMainInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【user_main_info(用户主要信息表)】的数据库操作Service
|
||||
* @createDate 2025-05-07 00:53:58
|
||||
*/
|
||||
public interface UserMainInfoService extends IService<UserMainInfo> {
|
||||
|
||||
}
|
@ -14,9 +14,12 @@ import com.greenorange.promotion.exception.ThrowUtils;
|
||||
import com.greenorange.promotion.mapper.UserInfoMapper;
|
||||
import com.greenorange.promotion.model.dto.user.*;
|
||||
import com.greenorange.promotion.model.entity.UserInfo;
|
||||
import com.greenorange.promotion.model.entity.UserMainInfo;
|
||||
import com.greenorange.promotion.model.enums.UserRoleEnum;
|
||||
import com.greenorange.promotion.service.common.CommonService;
|
||||
import com.greenorange.promotion.service.user.UserInfoService;
|
||||
import com.greenorange.promotion.service.user.UserMainInfoService;
|
||||
import com.greenorange.promotion.service.wechat.WechatGetQrcodeService;
|
||||
import com.greenorange.promotion.utils.JWTUtils;
|
||||
import com.greenorange.promotion.utils.RegexUtils;
|
||||
import com.greenorange.promotion.utils.SendSmsUtil;
|
||||
@ -27,6 +30,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -48,10 +52,18 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
private CommonService commonService;
|
||||
|
||||
|
||||
@Resource
|
||||
private UserMainInfoService userMainInfoService;
|
||||
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
|
||||
@Resource
|
||||
private WechatGetQrcodeService wechatGetQrcodeService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*/
|
||||
@ -120,11 +132,22 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
UserInfo myUserInfo = commonService.copyProperties(userInfoRegisterRequest, UserInfo.class);
|
||||
userInfo.setParentUserId(parentUserInfo.getId());
|
||||
userInfo.setInvitationCode(RandomUtil.randomNumbers(6));
|
||||
userInfo.setUserAccount(RandomUtil.randomNumbers(8));
|
||||
userInfo.setUserAccount(phoneNumber);
|
||||
userInfo.setUserRole(UserConstant.DEFAULT_ROLE);
|
||||
userInfo.setUserAvatar(UserConstant.USER_DEFAULT_AVATAR);
|
||||
userInfo.setSuperUserList(parentUserInfo.getSuperUserList() + "," + parentUserInfo.getId());
|
||||
this.save(myUserInfo);
|
||||
UserMainInfo userMainInfo = new UserMainInfo();
|
||||
userMainInfo.setUserId(myUserInfo.getId());
|
||||
|
||||
// 生成邀请二维码
|
||||
try {
|
||||
String view = wechatGetQrcodeService.getWxQrCode(myUserInfo.getInvitationCode());
|
||||
userMainInfo.setInviteQrCode(view);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
userMainInfoService.save(userMainInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -143,7 +166,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
|
||||
|
||||
Map<String, String> payload = new HashMap<>();
|
||||
payload.put("phoneNumber", phoneNumber);
|
||||
payload.put("userAccount", phoneNumber);
|
||||
payload.put("userPassword", userPassword);
|
||||
return jwtUtils.generateToken(payload);
|
||||
}
|
||||
@ -172,7 +195,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
String userPassword = userInfo.getUserPassword();
|
||||
|
||||
Map<String, String> payload = new HashMap<>();
|
||||
payload.put("phoneNumber", phoneNumber);
|
||||
payload.put("userAccount", phoneNumber);
|
||||
payload.put("userPassword", userPassword);
|
||||
return jwtUtils.generateToken(payload);
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.greenorange.promotion.service.user.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.greenorange.promotion.model.entity.UserMainInfo;
|
||||
import com.greenorange.promotion.service.user.UserMainInfoService;
|
||||
import com.greenorange.promotion.mapper.UserMainInfoMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【user_main_info(用户主要信息表)】的数据库操作Service实现
|
||||
* @createDate 2025-05-07 00:53:58
|
||||
*/
|
||||
@Service
|
||||
public class UserMainInfoServiceImpl extends ServiceImpl<UserMainInfoMapper, UserMainInfo>
|
||||
implements UserMainInfoService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -2,6 +2,8 @@ package com.greenorange.promotion.service.wechat;
|
||||
|
||||
import com.greenorange.promotion.config.WxAccessToken;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface WechatGetQrcodeService {
|
||||
|
||||
/**
|
||||
@ -9,4 +11,15 @@ public interface WechatGetQrcodeService {
|
||||
*/
|
||||
WxAccessToken getAccessToken();
|
||||
|
||||
|
||||
/**
|
||||
* 获取接口调用凭据
|
||||
*/
|
||||
WxAccessToken getApiAccessToken();
|
||||
|
||||
|
||||
/**
|
||||
* 微信小程序获取二维码
|
||||
*/
|
||||
String getWxQrCode(String inviteCode) throws IOException;
|
||||
}
|
||||
|
@ -2,24 +2,49 @@ package com.greenorange.promotion.service.wechat.impl;
|
||||
|
||||
|
||||
|
||||
import ch.qos.logback.core.util.MD5Util;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.greenorange.promotion.common.ErrorCode;
|
||||
import com.greenorange.promotion.common.ResultUtils;
|
||||
import com.greenorange.promotion.config.WxAccessToken;
|
||||
import com.greenorange.promotion.exception.BusinessException;
|
||||
import com.greenorange.promotion.model.entity.FileInfo;
|
||||
import com.greenorange.promotion.service.file.FileInfoService;
|
||||
import com.greenorange.promotion.service.wechat.WechatGetQrcodeService;
|
||||
import com.greenorange.promotion.utils.QRCodeUtil;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class WechatGetQrcodeServiceImpl implements WechatGetQrcodeService {
|
||||
|
||||
|
||||
|
||||
// 上传文件的服务器存储目录
|
||||
private static final String UPLOAD_DIR = "D:/qingcheng/image/";
|
||||
|
||||
|
||||
private final static String ACCESS_TOKEN_KEY = "accessToken";
|
||||
|
||||
// 优化:设置一个合理的缓冲区大小
|
||||
private static final int BUFFER_SIZE = 8192; // 8 KB
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@ -33,6 +58,10 @@ public class WechatGetQrcodeServiceImpl implements WechatGetQrcodeService {
|
||||
private String appSecret;
|
||||
|
||||
|
||||
@Resource
|
||||
private FileInfoService fileInfoService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取接口调用凭据
|
||||
*/
|
||||
@ -51,4 +80,108 @@ public class WechatGetQrcodeServiceImpl implements WechatGetQrcodeService {
|
||||
redisTemplate.opsForValue().set(ACCESS_TOKEN_KEY, access_token, 7200, TimeUnit.SECONDS);
|
||||
return wxAccessToken;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WxAccessToken getApiAccessToken() {
|
||||
String accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
|
||||
if (accessToken == null) {
|
||||
accessToken = this.getAccessToken().getAccess_token();
|
||||
}
|
||||
WxAccessToken wxAccessToken = WxAccessToken.builder()
|
||||
.access_token(accessToken)
|
||||
.expires_in("7200").build();
|
||||
return wxAccessToken;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取微信小程序二维码
|
||||
*/
|
||||
@Override
|
||||
public String getWxQrCode(String inviteCode) throws IOException {
|
||||
String accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY);
|
||||
if (accessToken == null) {
|
||||
accessToken = this.getAccessToken().getAccess_token();
|
||||
}
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("page", "pages/login/login");
|
||||
param.put("scene", "invitationCode=" + inviteCode);
|
||||
param.put("width", 430); // 宽度
|
||||
param.put("check_path", false);
|
||||
param.put("env_version", "develop");
|
||||
String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
|
||||
String jsonParams = JSONUtil.toJsonStr(param);
|
||||
byte[] responseBytes = HttpUtil.createPost(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(jsonParams)
|
||||
.execute()
|
||||
.bodyBytes();
|
||||
|
||||
// 将二维码数据转换为 BufferedImage
|
||||
BufferedImage qrImage = ImageIO.read(new ByteArrayInputStream(responseBytes));
|
||||
// // 获取用户头像
|
||||
// String avatarUrl = "https://img.picui.cn/free/2025/04/09/67f5d7bd6b368.jpg"; // 假设这是用户头像的URL
|
||||
// BufferedImage avatarImage = QRCodeUtil.getScaledAvatar(avatarUrl, 188, 188);
|
||||
// // 获取空白图像
|
||||
// String blankUrl = "https://www.helloimg.com/i/2025/04/07/67f34b0490d07.png";
|
||||
// // 加载一张空白图片来覆盖logo(假设是透明背景的图片)
|
||||
// BufferedImage blankImage = QRCodeUtil.getScaledAvatar(blankUrl, 196, 196); // 空白图片路径
|
||||
// // 将头像转换为圆形
|
||||
// BufferedImage circularAvatar = QRCodeUtil.getCircularImage(avatarImage);
|
||||
// // 将空白头像转换为圆形
|
||||
// BufferedImage circularBlank = QRCodeUtil.getCircularImage(blankImage);
|
||||
// // 合并二维码和空白图片
|
||||
// BufferedImage mergedWithBlank = QRCodeUtil.addImages(qrImage, circularBlank, 116, 116); // 偏移量根据需要调整
|
||||
// // 合并二维码和头像
|
||||
// BufferedImage resultImage = QRCodeUtil.addImages(mergedWithBlank, circularAvatar, 120, 120);
|
||||
// 将合成后的图片转换为 Base64 编码
|
||||
InputStream resultStream = QRCodeUtil.bufferedImageToInputStream(qrImage);
|
||||
byte[] resultBytes = resultStream.readAllBytes();
|
||||
// 创建上传目录,如果不存在
|
||||
String biz = "default";
|
||||
String fileName = "qrcode.png";
|
||||
// 获取文件类型
|
||||
String fileType = FileUtil.getSuffix(fileName);
|
||||
// 获取文件路径
|
||||
String filePath = String.format("%s-%s", biz, fileName);
|
||||
// 获取view值
|
||||
String view = RandomStringUtils.random(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
|
||||
File file = new File(UPLOAD_DIR + filePath);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();// 如果路径不存在则创建
|
||||
}
|
||||
// 将文件上传到目标位置
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE)) {
|
||||
bos.write(resultBytes);
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "文件上传失败,失败原因:" + e.getMessage());
|
||||
}
|
||||
// 生成图片并保存
|
||||
// try (FileOutputStream fos = new FileOutputStream(UPLOAD_DIR)) {
|
||||
// fos.write(resultBytes); // 将二进制数据写入文件
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// 将二维码转换为Base64编码
|
||||
// String base64Image = "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(responseBytes);
|
||||
// 获取文件大小
|
||||
Double fileSize = file.length() / 1024.0;
|
||||
fileSize = Double.valueOf(String.format("%.2f", fileSize));
|
||||
// 获取文件哈希值
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
String hashValue = DigestUtils.sha256Hex(inputStream);
|
||||
// 保存文件
|
||||
FileInfo fileInfo = FileInfo.builder()
|
||||
.name(fileName)
|
||||
.type(fileType)
|
||||
.path(filePath)
|
||||
.size(fileSize)
|
||||
.fileView(view)
|
||||
.biz(biz)
|
||||
.hashValue(hashValue)
|
||||
.build();
|
||||
fileInfoService.save(fileInfo);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user