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 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;
@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 (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(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.copyProperties(info, adminInfo);
adminInfoService.update(adminInfo);
}
// if (level.equals("管理员")) {
// SellerInfo sellerInfo = new SellerInfo();
// BeanUtils.copyProperties(info, sellerInfo);
// sellerInfoService.update(sellerInfo);
// }
// if (level.equals("用户")) {
// UserInfo userInfo = new UserInfo();
// BeanUtils.copyProperties(info, userInfo);
// userInfoService.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
(微信小程序毕业设计)投票评选系统(源码+说明+数据库+演示视频).zip 【项目技术】 微信小程序开发工具+mysql+java+b/s 【实现功能】 前端:投票主题查询,投票类别查询;在线投票,一个用户只能投票一个主题一次,投票也可以投票图片;投票结果查看;公告查看; 后台服务端:管理员管理、用户管理、公告管理、投票主题管理、投票结果管理,统计。
资源推荐
资源详情
资源评论
收起资源包目录
(微信小程序毕业设计)投票评选系统(源码+说明+数据库+演示视频).zip (884个子文件)
0020d180c3bc70d16cded3438699698bc29d16 580B
033654d6e74d87629f53ad1100fca15f20ff2e 2KB
0379f935c3dd24530fbf668be7f4e379ae43fc 981B
065a55381dc4f5b98f08380a7318b17dde9839 6KB
06b62dbd5a91b26ae691356c1d49ddbddb5d88 95B
06ecf087a8caa0f0b16b98eb1e2e58f419b453 798B
089476a3ca15e5d74a040ce58e3b3a53140267 666B
0acf0ea519a2163c85886cb1cf2e00cef0d3fd 707B
0b45348a119dfddc3ef7bb2568591a8c1cb0bf 787B
0d267e13dbed3e1826f2baf957ba3d252218f2 664B
0f699568089c48c2998758d6590fa72ceba8f0 1016B
104043b20eda2c184072e5139f2e1dfbe93e38 382B
105f5a0b7714ffafa8f2e201e6b0ffb782e223 64B
1372eb4664a095246f98b09f2373710d11a4d7 56B
19b50012e32e60f005a7620ca52ae4adb144fa 10KB
1b79bfb08162936523db90f0ea1e5bc0fcd9cd 1KB
1bddcf8c0d37b912fba31db4b7261959e166b2 4KB
1c4522a19e722ed6c33f48f34b84fe096c6615 175B
1c4e4273e1f58fcb49abe590ceb5b9969dd457 1KB
1d37a90319d44a9db02f2166fb8718251b2f74 2KB
1dd378f36b99c7d0b59b2d337fb27e20f7fac2 531B
1ed8d21dd5e7290a4d5dc4ce52a890770cc1f8 1KB
23996e384730b4494c23cecd839de22c2e4652 288KB
26a6c1c1ed381da27bc2d9279559963bdb7e77 918B
2b3c6c94a659044edd3b5717f99652f6e20de2 2KB
2e8d7ba1f47c1ac0f21ccc76ae7b3c54ef3038 950B
3082a216a039462c5b42a97821e508c17a893d 765B
32354adc814a689a08d408b0931f6f36068454 56B
327fed6f929d1af748ee9bb4391bf25d3dce68 518B
34b6d45b9bc5298d7b3ec2b78063639a9093c7 992B
35af0699ccec004cbe685ef938cd2d63ea7037 43B
3a7a56d6ad3c7bb9482924c6a28c8fee810273 2KB
3a7b292df8e114066d52e19ec8e8938f1daf90 271B
3c6704017d88d29caa5201a6e7e05b1e708309 55KB
3df8bb9b0029a787cf8f7030c50e40fe6d9a2c 503B
3dfd15b822849a3858e5021f5db08d81349ef9 2KB
3fb7e6b14e0913ec06fa61ca07f37ade2396fe 4KB
40ba65c26347d4a3bb9c53a8ec01d3c59a71a9 188B
40e3a1ce70c69ce7d50eb39cd9a7f782ae9da9 379B
42325e3419554d29f648591ff378e564ba032f 317B
423ae47bd3f29440179678c80e5b1e284eef0a 44KB
435eb4350d3c43b7f78830d78548a7619613bf 2KB
4587b8e582c851493b85b645091e5503d0641a 28KB
45d71dd9eebb8b53ddad0aba57b5c26b4f7fae 86KB
47290ade9b8628599c1d9a72a26f7aa4fc54bf 80B
48a7ea8f60ee5844a3a4c901d62020b8177773 895B
4ae77393c6202b22db2b34849f3f4f7c5ba69b 2KB
4c5536edbfb491224639a96ccb277f3c474ab6 5KB
4caa2514d446f805bb950d829eece100410f81 693B
4d54e58360a8a4fbc59cec53d16ef049cc0b01 292B
5247b050d616d1d9ab35b9dec4da0b673757b8 45B
54153e78b4277995291ee2d1244989baabcf21 6KB
54d03e39881c08104cb10c052670b0b8e018ee 678B
59c6c255dff7914348f84a7bc43a2bf86c15fe 1KB
5fa3b6e6d1f05d28e67ad59b85647d56678c6e 426B
5ff0ce324478a42cece77ed4278a2b9a474ff3 2KB
61e4d6a5223f3ad4d392c2f508ba8eaa0c9470 57B
640e0dc44a0e9b160f85b9124714ea071ae7b6 39B
64b10c676692e56e164cedc8437ea5d11d2717 54B
650882f3c459348174cb1aede26f4beeafe102 660B
651cd56e41351e89fa0fdefdd2423a07a231c1 559B
6afaac3c8cb53632953764f5743bd0a5eb8b8e 1KB
6b4535c25138d2c6bd15dc9333622db498206c 7KB
6bd7faacbb3d00dc6a5973bd63a20a13aa16e7 1KB
6cdc63e9ccaf7fb778a74ffdb56c64479b077d 124B
6dd56315dc088e5f90626b5db64a6da19786dc 368KB
6deb0d88644248e254aac6199e135250638831 732B
6e214953b3662052350fbc743d645394841f03 573B
6ff75f23f781c93b75db84afd5ce378083aadb 302B
70a06d84a333793acac3ab2bce2146a1828c1f 108B
70aad1425a244da356e277ad9bc0607ab5f1dd 3KB
7126badadf7190feea0b87aa77da2c1a637c29 87B
721cb682e7e00a648b703535e17f7dec2411d1 1004B
7345210441c44917f4ba5b93e8a57091f87aba 186B
7376ed8942b104e7ba24d4565310f60da85042 117B
784a5ce22115b67892b535f3c60fe024cf0e74 2KB
7aa4936e5edd996855413f9ca3fd9edcef7603 794B
7ae8c6a212a34cf00d6ee4f54b13fca8b2b80a 3KB
7d7fb1edb86f51c38cd7c76f619f15c27d7beb 380B
826d90a3abe82969f43e7de45dd137b03c9930 231B
8425da0679053e726b9bbebed21593c236d23f 233B
84701a7d5c05a91a6d24748b0131f13405c25b 221B
86a852c7f6f2bb8686324555cd6a92cfea5eac 3KB
887df82ff06342a9e4bc4dbdf431f4d37930e5 329B
8a14b85bce497667072a2daced02fc68a2ead1 2KB
8d63287131431e128f656c7eb2f3901ad68b25 787B
8d833d95d7e4e596e08a534c65c3ed1a0ed13d 584B
8ebaa50a6259dc313ed7ea1556d4ee7051e419 78B
8f1e3506af714bbaeca008705ffda25827756b 61B
90109965247f56a46f9e21b6242e69a25cc7b5 669B
9141c8b40a72016b77f08b61d2b28bbba44e2b 8KB
91d2aa7bbac20cb5b8f075d18e25c330f4eedc 980B
9648ec952b1a0c9c21b5cc4c3920a70ce583da 533B
9678cb12eae54a714203c4062dd2d75a919027 7KB
97574e040a6493ff110afc3bf0657c6b2e65d8 196B
978b6941eb1c535632f1c6ef3b66c9cc9ca542 466B
994f262101e375e0c769ae28e48eb99a26ba53 126B
99c6633112bf74faa2e6eec85958440a8d6de9 367B
9a660f2fac98b7fa44de59ada4ce87d3cd0372 2KB
9d01dcab72abfcfcff3b62903e955ba8d4775e 1KB
共 884 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
- 一帆风顺7122023-09-07支持这个资源,内容详细,主要是能解决当下的问题,感谢大佬分享~
- SAO100862024-05-22资源有很好的参考价值,总算找到了自己需要的资源啦。
- niantf2023-12-07资源很实用,对我启发很大,有很好的参考价值,内容详细。
岛上程序猿
- 粉丝: 5756
- 资源: 4245
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- LinkageError(解决方案).md
- AsyncError解决办法.md
- UnicodeTranslateError.md
- NSNetServiceError如何解决.md
- InvalidVNodeError解决办法.md
- UnsatisfiedLinkError(解决方案).md
- NSFileSystemError如何解决.md
- EnvironmentError.md
- ZeroDivisionError.md
- ReactivityError解决办法.md
- NSOperationQueueError如何解决.md
- EventEmitError解决办法.md
- NSHTTPError如何解决.md
- IncompatibleClassChangeError(解决方案).md
- EventListenerError解决办法.md
- IOError.md
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功