main
YangT-ao 2 years ago
commit 963b9e1ec5

1
.gitignore vendored

@ -1,6 +1,7 @@
.DS_Store
node_modules/
/dist/
target
npm-debug.log*
yarn-debug.log*
yarn-error.log*

@ -58,6 +58,12 @@
<version>1.18.28</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>

@ -0,0 +1,12 @@
package org.example.common;
/**
*
*/
public interface CommonResp {
String getCode(); // 获取响应码
String getMsg(); // 获取消息
CommonResp setMsg(String msg); // 设置消息
}

@ -0,0 +1,63 @@
package org.example.common;
public enum ResponseStatusEnum implements CommonResp{
SUCCESS("0","请求成功!"),
LOGIN_SUCCESS("0", "登录成功!"),
LOGOUT_SUCCESS("0", "注销成功!"),
ERROR("500","服务器系统错误!"),
/** 10XX 表示用户错误*/
USER_REGISTER_FAILED("1001", "注册失败"),
USER_ACCOUNT_EXISTED("1002","用户名已存在"),
USER_ACCOUNT_NOT_EXIST("1003","用户名不存在"),
USERNAME_PASSWORD_ERROR("1004","用户名或密码错误"),
PASSWORD_ERROR("1005","密码错误"),
USER_ACCOUNT_EXPIRED("1006","账号过期"),
USER_PASSWORD_EXPIRED("1007","密码过期"),
USER_ACCOUNT_DISABLE("1008","账号不可用"),
USER_ACCOUNT_LOCKED("1009","账号锁定"),
USER_NOT_LOGIN("1010","用户未登陆"),
USER_NO_PERMISSIONS("1011","用户权限不足"),
USER_SESSION_INVALID("1012","会话已超时"),
USER_ACCOUNT_LOGIN_IN_OTHER_PLACE("1013","账号超时或账号在另一个地方登陆,建议修改密码"),
TOKEN_NOT_VALID("1014","非法Token请重新登陆"),
TOKEN_EXPIRED("1015", "token过期"),
AUTHENTICATE_FAIL("1016", "认证失败,无法访问系统资源"),
REQUEST_BODY_MISSING("1017", "请求数据体缺失"),
LOGIN_NOT_ADMIN("1018", "管理员登录失败,不是管理员"),
/** 20XX 表示服务器错误 */
PICTURE_UPLOAD_FAILED("2001","上传图片失败"),
GIVE_LIKE_FAILED("2002","点赞失败"),
PICTURE_LOAD_FAILED("2003","图片加载失败"),
UPDATE_USER_INFO_FAILED("2004","修改用户信息失败"),
UPDATE_USER_PASSWORD_FAILED("2005","修改密码失败"),
;
private final String code;
private String msg;
ResponseStatusEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public String getCode() {
return this.code;
}
@Override
public String getMsg() {
return this.msg;
}
@Override
public CommonResp setMsg(String msg) {
this.msg=msg;
return this;
}
}

@ -1,9 +1,7 @@
package org.example.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.example.pojo.User;
import org.example.service.UserService;
import org.example.utils.Result;
@ -21,13 +19,13 @@ public class UserController {
@PostMapping("/regist")
public Result regist(@RequestBody User user){
System.out.println(user);
return userService.regist(user);
return userService.register(user);
}
@Operation(summary = "登录", description = "用户登录接口")
@GetMapping("/login")
public Result login(@Parameter(description = "用户名") @Param("username") String username,@Parameter(description = "用户密码") @Param("password") String password){
return userService.login(username, password);
@PostMapping("/login")
public Result login(@RequestBody User user){
return userService.login(user);
}
@Operation(summary = "修改", description = "修改用户信息接口传用户名其他修改哪个传哪个不需要传的设为null")

@ -0,0 +1,41 @@
package org.example.exception;
import org.example.common.CommonResp;
public class CustomException extends RuntimeException implements CommonResp {
private final CommonResp commonResp;
public CustomException(CommonResp commonResp) {
super(); // 调用父类的无参构造方法
this.commonResp = commonResp;
}
@Override
public String getMessage() {
return this.commonResp.getMsg();
}
// 接收自定义msg的方式构造业务异常
public CustomException(String msg, CommonResp commonResp) {
super();
this.commonResp = commonResp;
this.commonResp.setMsg(msg);
}
@Override
public String getCode() {
return this.commonResp.getCode();
}
@Override
public String getMsg() {
return this.commonResp.getMsg();
}
@Override
public CommonResp setMsg(String msg) {
this.commonResp.setMsg(msg);
return this;
}
}

@ -0,0 +1,50 @@
package org.example.exception;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.hutool.log.level.Level;
import org.example.common.ResponseStatusEnum;
import org.example.utils.Result;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice // 返回json
public class GlobalExceptionHandler {
private static final Log log = LogFactory.get();
// 统一异常处理@ExceptionHandler,主要用于Exception 运行时异常
@ExceptionHandler(RuntimeException.class)
public Result handler(RuntimeException e) {
log.error("运行时异常:", e);
return Result.error("-1", "后台运行异常,请联系系统管理员!");
}
/**
*
* @param e
* @return
*/
@ExceptionHandler(Exception.class)
public Result handler(Exception e) {
log.error("系统异常:", e);
return Result.error("-1", "系统异常,请联系系统管理员!");
}
//统一异常处理@ExceptionHandler,主要用于Exception 自定义异常
@ExceptionHandler(value = CustomException.class)
public Result handler(CustomException e) {
log.error("发生业务异常!原因是:{}", e.getMsg());
return Result.error(e.getCode(), e.getMsg());
}
@ExceptionHandler(value = HttpMessageNotReadableException.class)
public Result handler(HttpMessageNotReadableException exception) {
log.log(Level.ERROR, exception.getMessage());
return Result.error(ResponseStatusEnum.REQUEST_BODY_MISSING);
}
}

@ -4,7 +4,9 @@ import org.example.pojo.User;
import org.example.utils.Result;
public interface UserService {
public Result regist(User user);
public Result login(String username, String password);
public Result update(User user);
public Result register(User user);
public Result login(User user);
}

@ -14,7 +14,7 @@ public class UserServiceImpl implements UserService {
@Autowired
UserMapper userMapper;
public Result regist(User user){
public Result register(User user){
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username",user.getUsername());
boolean isExist = userMapper.exists(queryWrapper);
@ -30,13 +30,15 @@ public class UserServiceImpl implements UserService {
}
@Override
public Result login(String username, String password) {
public Result login(User user) {
String username = user.getUsername();
String password = user.getPassword();
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username",username).eq("password",MD5Util.encrypt(password));
User user = userMapper.selectOne(queryWrapper);
user.setPassword(null);
if(user != null){
return Result.success(user);
User res = userMapper.selectOne(queryWrapper);
if(res != null){
res.setPassword(null);
return Result.success(res);
}
return Result.error("-1","账号或者密码错误");
}

@ -2,15 +2,22 @@ package org.example.utils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.example.common.CommonResp;
import org.example.common.ResponseStatusEnum;
import java.util.HashMap;
/**
*
*/
@ApiModel(value = "响应结果实体", description = "响应结果实体")
public class Result<T> {
public class Result {
@ApiModelProperty(value = "响应提示码")
private String code;
@ApiModelProperty(value = "提示信息")
private String msg;
@ApiModelProperty(value = "响应数据")
private T data;
private Object data = null;
public String getCode() {
return code;
@ -28,32 +35,41 @@ public class Result<T> {
this.msg = msg;
}
public T getData() {
public Object getData() {
return data;
}
public void setData(T data) {
public void setData(Object data) {
this.data = data;
}
public Result() {
}
public Result(T data) {
public Result(Object data) {
this.data = data;
}
public Result(CommonResp commonResp) {
this.setCode(commonResp.getCode());
this.setMsg(commonResp.getMsg());
}
public static Result success() {
Result result = new Result<>();
result.setCode("0");
result.setMsg("成功");
return Result.success(null);
}
public static Result success(String code, String msg) {
Result result = new Result();
result.setCode(code);
result.setMsg(msg);
return result;
}
public static <T> Result<T> success(T data) {
Result<T> result = new Result<>(data);
result.setCode("0");
result.setMsg("成功");
public static Result success(Object data) {
Result result = new Result(data);
result.setCode(ResponseStatusEnum.SUCCESS.getCode());
result.setMsg(ResponseStatusEnum.SUCCESS.getMsg());
return result;
}
@ -63,4 +79,36 @@ public class Result<T> {
result.setMsg(msg);
return result;
}
public static Result error(ResponseStatusEnum responseStatusEnum, Object data) {
Result result = new Result(data);
result.setCode(responseStatusEnum.getCode());
result.setMsg(responseStatusEnum.getMsg());
return result;
}
public static Result error(ResponseStatusEnum responseStatusEnum) {
return error(responseStatusEnum, null);
}
// 添加数据信息 链式编程
public Result put(String key, Object value) {
if (this.data == null) {
// 新建一个哈希映射,用于存储数据
this.data = new HashMap<String, Object>();
}
// data不为空且不是一个HashMap的实例则不能put
if (!(this.data instanceof HashMap)) return this;
((HashMap<String, Object>) this.data).put(key, value);
return this;
}
@Override
public String toString() {
return "Result{" +
"code='" + code + '\'' +
", msg='" + msg + '\'' +
", data=" + data +
'}';
}
}

@ -25,72 +25,72 @@ export default {
dataList: [
{
name: "常德市",
value: 3,
per: 0
num: 3,
value: 0
},
{
name: "郴州市",
value: 4,
per: 0
num: 4,
value: 0
},
{
name: "衡阳市",
value: 1,
per: 0
num: 1,
value: 0
},
{
name: "怀化市",
value: 1,
per: 0
num: 1,
value: 0
},{
name: "娄底市",
value: 4,
per: 0
num: 4,
value: 0
},
{
name: "邵阳市",
value: 2,
per: 0
num: 2,
value: 0
},
{
name: "湘潭市",
value: 1,
per: 0
num: 1,
value: 0
},
{
name: "湘西土家族苗族自治州",
value: 6,
per: 0
num: 10,
value: 0
},
{
name: "益阳市",
value: 1,
per: 0
num: 1,
value: 0
},
{
name: "永州市",
value: 1,
per: 0
num: 1,
value: 0
},
{
name: "岳阳市",
value: 0,
per: 0
num: 0,
value: 0
},
{
name: "张家界市",
value: 1,
per: 0
num: 1,
value: 0
},
{
name: "长沙市",
value: 1,
per: 0
num: 1,
value: 0
},
{
name: "株洲市",
value: 2,
per: 0
num: 2,
value: 0
},
]
}
@ -99,18 +99,18 @@ export default {
initWorldMapChart(){
let sum = 0
this.dataList.map((item)=>{
sum += item.value;
sum += item.num;
})
for(let i = 0; i < this.dataList.length; i++){
this.dataList[i].per = Math.round(this.dataList[i].value / sum * 100)
this.dataList[i].value = Math.round(this.dataList[i].num / sum * 100)
}
this.option = {
tooltip: {
//
formatter: function(params) {
return (
params.name + " 共" + params.value + "个,占:"+
params.data.per+"%"
params.name + " 共" + params.data.num + "个,占:"+
params.value+"%"
);
},
backgroundColor: 'rgba(19, 25, 47, 0.6)',
@ -156,9 +156,9 @@ export default {
roam: true, //
zoom: 1, //
label: {
show: false,//
show: true,//
fontSize: this.screenWidth * 0.0066,
color: "rgba(201,174,174,0.7)",
color: "rgb(13,43,133)",
},
nameMap:{
"常德": "常德市",

Loading…
Cancel
Save