package com.example.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.*;
import com.example.exception.CustomException;
import com.example.service.AdminInfoService;
import com.example.service.YonghuxinxiInfoService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import cn.hutool.json.JSONUtil;
import java.util.*;
import java.util.stream.Collectors;
@RestController
public class AccountController {
@Value("${authority.info}")
private String authorityStr;
@Resource
private AdminInfoService adminInfoService;
@Resource
private YonghuxinxiInfoService yonghuxinxiInfoService;
@PostMapping("/login")
public Result<Account> login(@RequestBody Account account, HttpServletRequest request) {
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getMima()) || account.getLevel() == null) {
throw new CustomException(ResultCode.PARAM_LOST_ERROR);
}
String level = account.getLevel();
Account login = new Account();
if (level.equals("管理员")) {
login = adminInfoService.login(account.getUsername(), account.getMima());
}
if (level.equals("注册用户")) {
login = yonghuxinxiInfoService.login(account.getUsername(), account.getMima());
//yoxusxhenhe if(login.getStatus().equals("否")){return Result.error("500","帐号未审核通过,请联系管理员");}
}
// if (2 == level) {
// login = sellerInfoService.login(account.getUsername(), account.getMima());
// }
// if (level.equals("用户")) {
// login = userInfoService.login(account.getUsername(), account.getMima());
// if(login.getStatus().equals("否")){
// return Result.error("500","状态异常,请联系管理员");
// }
// }
// if (level.equals("员工")) {
// login = yuangongxinxiInfoService.login(account.getUsername(), account.getMima());
// if(login.getStatus().equals("否")){
// return Result.error("500","状态异常,请联系管理员");
// }
// }
request.getSession().setAttribute("user", login);
return Result.success(login);
}
@GetMapping("/logout")
public Result logout(HttpServletRequest request) {
request.getSession().setAttribute("user", null);
return Result.success();
}
@GetMapping("/auth")
public Result getAuth(HttpServletRequest request) {
Object user = request.getSession().getAttribute("user");
if(user == null) {
return Result.error("401", "未登录");
}
return Result.success(user);
}
@GetMapping("/getAccountInfo")
public Result<Object> getAccountInfo(HttpServletRequest request) {
Account account = (Account) request.getSession().getAttribute("user");
if (account == null) {
return Result.success(new Object());
}
String level = account.getLevel();
if (level.equals("管理员")) {
return Result.success(adminInfoService.findById(account.getId()));
}
if (level.equals("注册用户")) { return Result.success(yonghuxinxiInfoService.findById(account.getId())); }
// if (level.equals("管理员")) {
// return Result.success(sellerInfoService.findById(account.getId()));
// }
// if (level.equals("用户")) {
// return Result.success(userInfoService.findById(account.getId()));
// }
//
// if (level.equals("医生")) {
// return Result.success(yishengxinxiInfoService.findById(account.getId()));
// }
// if (level.equals("员工")) {
// return Result.success(yuangongxinxiInfoService.findById(account.getId()));
// }
return Result.success(new Object());
}
@GetMapping("/getSession")
public Result<Map<String, String>> getSession(HttpServletRequest request) {
Account account = (Account) request.getSession().getAttribute("user");
if (account == null) {
return Result.success(new HashMap<>(1));
}
Map<String, String> map = new HashMap<>(1);
map.put("username", account.getUsername());
return Result.success(map);
}
@GetMapping("/getAuthority")
public Result<List<AuthorityInfo>> getAuthorityInfo() {
List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class);
return Result.success(authorityInfoList);
}
/**
* 获取当前用户所能看到的模块信息
* @param request
* @return
*/
@GetMapping("/authority")
public Result<List<Integer>> getAuthorityInfo(HttpServletRequest request) {
Account user = (Account) request.getSession().getAttribute("user");
if (user == null) {
return Result.success(new ArrayList<>());
}
JSONArray objects = JSONUtil.parseArray(authorityStr);
for (Object object : objects) {
JSONObject jsonObject = (JSONObject) object;
if (user.getLevel().equals(jsonObject.getStr("level"))) {
JSONArray array = JSONUtil.parseArray(jsonObject.getStr("models"));
List<Integer> modelIdList = array.stream().map((o -> {
JSONObject obj = (JSONObject) o;
return obj.getInt("modelId");
})).collect(Collectors.toList());
return Result.success(modelIdList);
}
}
return Result.success(new ArrayList<>());
}
@GetMapping("/permission/{modelId}")
public Result<List<Integer>> getPermission(@PathVariable Integer modelId, HttpServletRequest request) {
List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class);
Account user = (Account) request.getSession().getAttribute("user");
if (user == null) {
return Result.success(new ArrayList<>());
}
Optional<AuthorityInfo> optional = authorityInfoList.stream().filter(x -> x.getLevel().equals(user.getLevel())).findFirst();
if (optional.isPresent()) {
Optional<AuthorityInfo.Model> firstOption = optional.get().getModels().stream().filter(x -> x.getModelId().equals(modelId)).findFirst();
if (firstOption.isPresent()) {
List<Integer> info = firstOption.get().getOperation();
return Result.success(info);
}
}
return Result.success(new ArrayList<>());
}
@PutMapping("/updateMima")
public Result updateMima(@RequestBody Account info, HttpServletRequest request) {
Account account = (Account) request.getSession().getAttribute("user");
if (account == null) {
return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);
}
String oldMima = SecureUtil.md5(info.getMima());
if (!oldMima.equals(account.getMima())) {
return Result.error(ResultCode.PARAM_PASSWORD_ERROR.code, ResultCode.PARAM_PASSWORD_ERROR.msg);
}
info.setMima(SecureUtil.md5(info.getNewMima()));
String level = account.getLevel();
if (level.equals("管理员")) {
AdminInfo adminInfo = new AdminInfo();
BeanUtils.co
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Java项目实战,Java项目开发实例,基于springboot的毕设 【项目技术】 java+mysql+b/s+springboot 【实现功能】 本系统的开发主要可以分为以下四个模块,其包含的内容如下所示: (1)用户信息管理模块:注册、登录、基本信息的修改 (2)商品信息登记及管理模块:发布商品信息、删除修改商品信息 (3)商品查询及商品讨论模块:商品查询、商品讨论、评价 (4)系统管理模块:用户信息管理、商品管理、商品基本属性管理
资源推荐
资源详情
资源评论
收起资源包目录
Java毕业设计-基于springboot的基于微服务框架的智慧商城平台(源码+演示视频).zip (1087个子文件)
alipay_md5.asp 11KB
alipay_md5.asp 11KB
alipay_function.asp 6KB
alipay_function.asp 6KB
alipay_notify.asp 5KB
alipay_notify.asp 5KB
alipay_service.asp 2KB
alipay_service.asp 2KB
ShangpinxinxiInfoController.class 13KB
XinwentongzhiInfoController.class 13KB
GoumaiInfoController.class 13KB
DingdanxinxiInfoController.class 13KB
XitongjianjieInfoController.class 12KB
YonghuxinxiInfoController.class 12KB
LiuyanbanInfoController.class 12KB
AccountController.class 11KB
AdminInfoController.class 9KB
NxSystemFileController.class 8KB
EchartsController.class 5KB
YonghuxinxiInfoService.class 5KB
XinwentongzhiInfoService.class 5KB
GoumaiInfoService.class 5KB
AdminInfoService.class 5KB
ShangpinxinxiInfoService.class 5KB
AdminInfo.class 4KB
DingdanxinxiInfoService.class 4KB
CommentInfoService.class 4KB
ShangpinxinxiInfo.class 4KB
YonghuxinxiInfo.class 4KB
XitongjianjieInfoService.class 4KB
XinwentongzhiInfo.class 4KB
CollectInfoController.class 4KB
LiuyanbanInfoService.class 4KB
CommentInfoController.class 4KB
RichtextInfoController.class 3KB
GoumaiInfo.class 3KB
CollectInfoService.class 3KB
DingdanxinxiInfo.class 3KB
RichtextInfoService.class 3KB
NxSystemFileInfoService.class 3KB
LiuyanbanInfo.class 3KB
CollectInfo.class 3KB
CommentInfo.class 3KB
Account.class 3KB
Result.class 2KB
EchartsData.class 2KB
ResultCode.class 2KB
MyInterceptor.class 2KB
XitongjianjieInfo.class 2KB
GlobalExceptionHandler.class 2KB
DingdanxinxiInfoDao.class 2KB
GoumaiInfoDao.class 2KB
XinwentongzhiInfoDao.class 2KB
ShangpinxinxiInfoDao.class 2KB
EchartsData$Data.class 2KB
WebMvcConfig.class 2KB
CommentInfoDao.class 1KB
EchartsData$Series.class 1KB
MyInterceptorConfig.class 1KB
AuthorityInfo.class 1KB
NxSystemFileInfo.class 1KB
CollectInfoDao.class 1KB
RichtextInfo.class 1KB
LiuyanbanInfoDao.class 1KB
YonghuxinxiInfoDao.class 1KB
AuthorityInfo$Model.class 1KB
CustomException.class 1KB
XitongjianjieInfoDao.class 1KB
AdminInfoDao.class 928B
Application.class 793B
NxSystemFileInfoDao.class 773B
RichtextInfoDao.class 641B
XinwentongzhiInfoVo.class 332B
XitongjianjieInfoVo.class 332B
ShangpinxinxiInfoVo.class 332B
DingdanxinxiInfoVo.class 328B
YonghuxinxiInfoVo.class 324B
LiuyanbanInfoVo.class 316B
RichtextInfoVo.class 312B
CollectInfoVo.class 308B
GoumaiInfoVo.class 304B
AdminInfoVo.class 300B
style.css 240KB
style.css 240KB
index.css 227KB
index.css 227KB
index.css 227KB
index.css 227KB
bootstrap.min.css 141KB
bootstrap.min.css 141KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 116KB
bootstrap.min.css 116KB
bootstrap.min.css 116KB
bootstrap.min.css 116KB
共 1087 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
岛上程序猿
- 粉丝: 5536
- 资源: 4237
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功