mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-25 14:37:40 +08:00
fix 修复上传图片失效的bug
fix 没法修改用户资料的bug feat 同步短信发送的逻辑
This commit is contained in:
@@ -74,34 +74,4 @@ public class IndexController {
|
||||
List<String> list = iIndexService.hotSearch();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@NotLogin
|
||||
@PostMapping("/sendSms")
|
||||
@ApiOperation(value="发送短信")
|
||||
public AjaxResult<Object> sendSms(@Validated @RequestBody SmsValidate smsValidate) {
|
||||
NoticeRecord noticeRecord = noticeRecordMapper.selectOne(new QueryWrapper<NoticeRecord>()
|
||||
.eq("account", smsValidate.getMobile())
|
||||
.eq("scene", smsValidate.getScene())
|
||||
.eq("status", Arrays.asList(NoticeEnum.STATUS_WAIT, NoticeEnum.STATUS_OK))
|
||||
.orderByDesc("id")
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNotNull(noticeRecord)) {
|
||||
if (noticeRecord.getCreateTime() >= (System.currentTimeMillis() / 1000 - 60)){
|
||||
throw new OperateException("操作频繁,请稍后再试!");
|
||||
}
|
||||
}
|
||||
|
||||
NoticeSmsVo params = new NoticeSmsVo()
|
||||
.setScene(smsValidate.getScene())
|
||||
.setMobile(smsValidate.getMobile())
|
||||
.setExpire(900)
|
||||
.setParams(new String[] {
|
||||
"code:" + ToolUtils.randomInt(4)
|
||||
});
|
||||
|
||||
NoticeDriver.handle(params);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.notice.NoticeRecord;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.notice.NoticeRecordMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeDriver;
|
||||
import com.mdd.common.plugin.notice.vo.NoticeSmsVo;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import com.mdd.front.service.IIndexService;
|
||||
import com.mdd.front.validate.common.SmsValidate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/sms")
|
||||
@Api(tags = "主页管理")
|
||||
public class SmsController {
|
||||
|
||||
@Resource
|
||||
NoticeRecordMapper noticeRecordMapper;
|
||||
|
||||
@NotLogin
|
||||
@PostMapping("/sendCode")
|
||||
@ApiOperation(value="发送短信")
|
||||
public AjaxResult<Object> sendSms(@Validated @RequestBody SmsValidate smsValidate) {
|
||||
NoticeRecord noticeRecord = noticeRecordMapper.selectOne(new QueryWrapper<NoticeRecord>()
|
||||
.eq("account", smsValidate.getMobile())
|
||||
.eq("scene", smsValidate.getScene())
|
||||
.eq("status", Arrays.asList(NoticeEnum.STATUS_WAIT, NoticeEnum.STATUS_OK))
|
||||
.orderByDesc("id")
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNotNull(noticeRecord)) {
|
||||
if (noticeRecord.getCreateTime() >= (System.currentTimeMillis() / 1000 - 60)){
|
||||
throw new OperateException("操作频繁,请稍后再试!");
|
||||
}
|
||||
}
|
||||
|
||||
NoticeSmsVo params = new NoticeSmsVo()
|
||||
.setScene(NoticeEnum.getSceneByTag(smsValidate.getScene()))
|
||||
.setMobile(smsValidate.getMobile())
|
||||
.setExpire(900)
|
||||
.setParams(new String[] {
|
||||
"code:" + ToolUtils.randomInt(4)
|
||||
});
|
||||
|
||||
NoticeDriver.handle(params);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,14 @@ package com.mdd.front.controller;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.enums.AlbumEnum;
|
||||
import com.mdd.common.enums.FileEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.plugin.storage.StorageDriver;
|
||||
import com.mdd.common.plugin.storage.UploadFilesVo;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.IFileService;
|
||||
import com.mdd.front.vo.upload.UploadImagesVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -15,17 +19,23 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/upload")
|
||||
@Api(tags = "上传管理")
|
||||
public class UploadController {
|
||||
|
||||
@Resource
|
||||
IFileService iFileService;
|
||||
|
||||
@NotLogin
|
||||
@PostMapping("/image")
|
||||
@ApiOperation(value="上传图片")
|
||||
public AjaxResult<UploadFilesVo> image(HttpServletRequest request) {
|
||||
public AjaxResult<UploadImagesVo> image(HttpServletRequest request) {
|
||||
MultipartFile multipartFile;
|
||||
try {
|
||||
multipartFile = ((MultipartRequest) request).getFile("file");
|
||||
@@ -44,7 +54,25 @@ public class UploadController {
|
||||
|
||||
StorageDriver storageDriver = new StorageDriver();
|
||||
UploadFilesVo vo = storageDriver.upload(multipartFile, folder, AlbumEnum.IMAGE.getCode());
|
||||
return AjaxResult.success(vo);
|
||||
System.out.println(vo);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("cid", "0");
|
||||
params.put("uid", String.valueOf(LikeFrontThreadLocal.getUserId()));
|
||||
params.put("source", String.valueOf(FileEnum.SOURCE_USER.getCode()));
|
||||
params.put("type", String.valueOf(FileEnum.IMAGE_TYPE.getCode()));
|
||||
params.put("name", vo.getName());
|
||||
params.put("url", vo.getUrl());
|
||||
Integer id = iFileService.fileAdd(params);
|
||||
|
||||
UploadImagesVo upVo = new UploadImagesVo();
|
||||
upVo.setUrl(vo.getUrl());
|
||||
upVo.setUri(vo.getPath());
|
||||
upVo.setId(id);
|
||||
upVo.setType(FileEnum.IMAGE_TYPE.getCode());
|
||||
upVo.setName(vo.getName());
|
||||
upVo.setCid(0);
|
||||
return AjaxResult.success(upVo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ public class UserController {
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
@PostMapping("/edit")
|
||||
@PostMapping("/setInfo")
|
||||
@ApiOperation(value="编辑信息")
|
||||
public AjaxResult<Object> edit(@Validated @RequestBody UserUpdateValidate updateValidate) {
|
||||
public AjaxResult<Object> setInfo(@Validated @RequestBody UserUpdateValidate updateValidate) {
|
||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||
|
||||
iUserService.edit(updateValidate, userId);
|
||||
iUserService.setInfo(updateValidate, userId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mdd.front.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件服务接口类
|
||||
*/
|
||||
public interface IFileService {
|
||||
/**
|
||||
* 文件新增
|
||||
*
|
||||
* @author fzr
|
||||
* @param params 文件信息参数
|
||||
*/
|
||||
Integer fileAdd(Map<String, String> params);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public interface IUserService {
|
||||
* @param updateValidate 参数
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void edit(UserUpdateValidate updateValidate, Integer userId);
|
||||
void setInfo(UserUpdateValidate updateValidate, Integer userId);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.file.File;
|
||||
import com.mdd.common.entity.file.FileCate;
|
||||
import com.mdd.common.mapper.album.FileCateMapper;
|
||||
import com.mdd.common.mapper.album.FileMapper;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.service.IFileService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class FileServiceImpl implements IFileService {
|
||||
|
||||
@Resource
|
||||
FileMapper fileMapper;
|
||||
|
||||
@Resource
|
||||
FileCateMapper fileCateMapper;
|
||||
|
||||
/**
|
||||
* 文件新增
|
||||
*
|
||||
* @author fzr
|
||||
* @param params 文件信息参数
|
||||
*/
|
||||
@Override
|
||||
public Integer fileAdd(Map<String, String> params) {
|
||||
String name = params.get("name");
|
||||
if (name.length() >= 100) {
|
||||
name = name.substring(0, 99);
|
||||
}
|
||||
|
||||
File album = new File();
|
||||
album.setCid(Integer.parseInt(params.get("cid") == null ? "0" : params.get("cid")));
|
||||
album.setSourceId(Integer.parseInt(params.get("uid") == null ? "0" : params.get("uid")));
|
||||
album.setType(Integer.parseInt(params.get("type")));
|
||||
album.setSource(Integer.parseInt(params.get("source") == null ? "0" : params.get("source")));
|
||||
album.setName(name);
|
||||
album.setUri(params.get("url"));
|
||||
album.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
album.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
fileMapper.insert(album);
|
||||
return album.getId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
@Override
|
||||
public LoginTokenVo mobileLogin(String mobile, String code, Integer terminal) {
|
||||
// 校验验证码
|
||||
int sceneCode = NoticeEnum.LOGIN_CODE.getCode();
|
||||
int sceneCode = NoticeEnum.LOGIN_CAPTCHA.getCode();
|
||||
if (!NoticeCheck.verify(sceneCode, code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class UserServiceImpl implements IUserService {
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@Override
|
||||
public void edit(UserUpdateValidate updateValidate, Integer userId) {
|
||||
public void setInfo(UserUpdateValidate updateValidate, Integer userId) {
|
||||
String field = updateValidate.getField();
|
||||
String value = updateValidate.getValue();
|
||||
|
||||
@@ -142,11 +142,11 @@ public class UserServiceImpl implements IUserService {
|
||||
avatarUser.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(avatarUser);
|
||||
break;
|
||||
case "username":
|
||||
case "account":
|
||||
User usernameUser = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,username")
|
||||
.eq("username", value)
|
||||
.eq("is_delete", 0)
|
||||
.select("id,account")
|
||||
.eq("account", value)
|
||||
.isNull("delete_time")
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNotNull(usernameUser) && !usernameUser.getId().equals(userId)) {
|
||||
@@ -194,7 +194,7 @@ public class UserServiceImpl implements IUserService {
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,password,salt")
|
||||
.eq("id", userId)
|
||||
.eq("is_delete", 0)
|
||||
.isNull("delete_time")
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(user, "用户不存在");
|
||||
@@ -227,15 +227,15 @@ public class UserServiceImpl implements IUserService {
|
||||
@Override
|
||||
public void forgotPwd(String password, String mobile, String code) {
|
||||
// 校验验证码
|
||||
int sceneCode = NoticeEnum.FORGOT_PASSWORD_CODE.getCode();
|
||||
int sceneCode = NoticeEnum.FIND_LOGIN_PASSWORD_CAPTCHA.getCode();
|
||||
if (!NoticeCheck.verify(sceneCode, code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
// 查询手机号
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,username,mobile,is_disable")
|
||||
.eq("is_delete", 0)
|
||||
.select("id,account,mobile,is_disable")
|
||||
.isNull("delete_time")
|
||||
.eq("mobile", mobile)
|
||||
.last("limit 1"));
|
||||
|
||||
@@ -265,15 +265,15 @@ public class UserServiceImpl implements IUserService {
|
||||
String code = mobileValidate.getCode().toLowerCase();
|
||||
|
||||
// 校验验证码
|
||||
int sceneCode = type.equals("bind") ? NoticeEnum.BIND_MOBILE_CODE.getCode() : NoticeEnum.CHANGE_MOBILE_CODE.getCode() ;
|
||||
int sceneCode = type.equals("bind") ? NoticeEnum.BIND_MOBILE_CAPTCHA.getCode() : NoticeEnum.CHANGE_MOBILE_CAPTCHA.getCode() ;
|
||||
if (!NoticeCheck.verify(sceneCode, code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.select("id,username,mobile")
|
||||
.select("id,account,mobile")
|
||||
.eq("mobile", mobile)
|
||||
.eq("is_delete", 0)
|
||||
.isNull("delete_time")
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNotNull(user) && user.getId().equals(userId)) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SmsValidate implements Serializable {
|
||||
|
||||
@NotNull(message = "scene参数缺失")
|
||||
@ApiModelProperty(value = "场景码")
|
||||
private Integer scene;
|
||||
private String scene;
|
||||
|
||||
@NotNull(message = "mobile参数缺失")
|
||||
@NotEmpty(message = "手机号不能为空")
|
||||
|
||||
@@ -15,8 +15,8 @@ public class UserUpdateValidate implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "field参数缺失")
|
||||
@StringContains(values = {"avatar", "username", "nickname", "sex"})
|
||||
@ApiModelProperty(value = "操作字段", required = true, example = "avatar,username,nickname,sex")
|
||||
@StringContains(values = {"avatar", "account", "nickname", "sex"})
|
||||
@ApiModelProperty(value = "操作字段", required = true, example = "avatar,account,nickname,sex")
|
||||
private String field;
|
||||
|
||||
@NotNull(message = "value参数缺失")
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mdd.front.vo.upload;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class UploadImagesVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
private Integer cid;
|
||||
private Integer type;
|
||||
private String name;
|
||||
private String url;
|
||||
private String uri;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user