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.ZhuceyonghuInfoService;
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 ZhuceyonghuInfoService zhuceyonghuInfoService;
@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 = zhuceyonghuInfoService.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(zhuceyonghuInfoService.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();
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于微信小程序的互动打卡小程序的实现(后端java+mysql).zip 小程序: 打卡功能:打卡功能是小程序的主要功能,打卡功能主要目的是实现单人或多人创建社区并打卡的需求。 今日目标:用户可以在今日待办模块记录清单,把今日需要完成的事情写出来,当任务完成的时候标记已完成的功能。 个人中心模块: (1)数据统计:数据统计功能是实现用户的数据可视化的要求。用户的每天打卡情况可以在数据统计模块实现。 (2)用户积分:我的积分功能实现的是根据用户的打卡天数通过积分的方式给用户奖励。 积分兑换:可以兑换一些小商品等。 后台服务端: 打卡信息管理 进入目标管理:查看用户制定的目标,并且可以删除等 数据统计(统计用户的每日打卡,哪天空缺,) 积分管理:查看管理用户的积分 积分兑换商品管理:
资源推荐
资源详情
资源评论
收起资源包目录
基于微信小程序的互动打卡小程序的实现(后端java+mysql).zip (1248个子文件)
02add20b581be471b8d17f887b8e8337070546 194B
034ccce28a21cdd1d8500e03a3a19950a24840 135B
06718f8e6a9de9438b6501aff2f83152c53f25 2KB
06bfdeb5ad13a02a29eb9b8b8b57e1d69cedf5 124B
07d6d5f654346606542e80ea09e9983f07705c 85B
0841a689acfc75f16b91e8e49d4daa3cb01df9 831B
0887a714f0134b8dc77a89f648ad7af5219624 2KB
0c0812bb527be6b50c8a043d1e291ddd0d0b0f 135B
0f96ef21c70252c670fbb021f9ddf4e17d7e2a 2KB
132b89c93c82fb7d83523022c3d606b0cdce55 78B
136700c3f750c5b13756b0dc040c0f73168f9c 1KB
17db6db9c5f9d9ffa753ba24dbae05c63a71c6 643B
1988e9f039d279a680e8b915fe5e1d56dd385c 7KB
1a4f51d6e7d104f36ebd32906ca09c7f7ef82a 8KB
1bddcf8c0d37b912fba31db4b7261959e166b2 4KB
1d566316c654a00f15a8fa8605adcc0887ca78 134B
1d5abdfb44d57b8c2e9f70fe5e82ddc71b6040 242B
27b9ee1bdfda2aff5098f63ce7668e0bfc2d51 395B
302da08c7b072cd19358dbb503c18d08fb2143 168B
333cd8c19ff05f2b316c1e8c7d067593702854 5KB
3475a344ade362d397c92f42bafce7f4357dbd 145B
35af0699ccec004cbe685ef938cd2d63ea7037 43B
36c5aae34facbdeb0bd8ee16feba3cdacc8a2e 670B
370e54f9f9ccbc0483f91ed17cd4d0ca7d1a70 361B
395ba95c5c84d41771f4cb2b9df6cc965ee60f 1KB
39747192cd7402c2784c27bb13b8d4e6021d7a 6KB
3b32372fa0114d56ecc4e9f1d0ea4ac1ce4f5e 3KB
42709e1cd615263236d0ee23117795e95a586e 82B
47196fb87ade0fd21217c28577b489ed536b34 2KB
499d747924a8c5aa0ad42ca020ab1dcba50613 417B
50f112453e93931726340632087f9f173cfec4 965B
538c295a79e1ccc89a476f6432a0f8bbef04f9 1KB
559ee67ff7916e39e897c0ec7e140669be3ff1 676B
59f2720d04769b18523ecfd19ab1ade5ccbb9d 998B
5bf3a9933976efe33f1364f35ea29bfc1e9b26 135B
62a356e02e047d41dc875951245df07784d393 85B
6355f833fa1631a2aff819ff01633262da105e 309B
640e0dc44a0e9b160f85b9124714ea071ae7b6 39B
66f3d96d389c73495bbc9cc29d885fc5686bbf 7KB
67afb3a76618078d09086794e323dfe3a29c67 464B
69302c397adc425d760404292f4e9f519553a3 547B
6adec7200d72d6e908125b68cd1c67870bb0f8 85B
6ae0a20376ab441fbb25ed51daef83edb01fa9 135B
7021ccbae905b1e6d5242870e02123f6802b0d 85B
70aad1425a244da356e277ad9bc0607ab5f1dd 3KB
70ab1985689e06f05f658e06e2c39d05753296 407B
71f0df9ae63c39b48b150016cf5a922d540a85 673B
720f7a8e2ffa773538b1ed03222a3b7b20308f 4KB
752381bbf3cf1e8fe80266ebdf35f072df4e98 419B
763277e84151db2255d4000b7dbb91ada84a2b 1KB
767e3032a1cf829c00c7e147d494447d90652e 90B
784a5ce22115b67892b535f3c60fe024cf0e74 2KB
7aa4936e5edd996855413f9ca3fd9edcef7603 794B
7e73b461960e9b46ab3930aa4ed7ea0b252f3e 316B
7f19b5f9c2c88d7c8d0c2f5dd31a9699997f1a 388B
8114571df8026ac96009c567edbe5fef81ed09 52B
858121553fb20a1275407abcd7ee57c634fb3f 135B
87a25525aa06dba166ccdba796671feaae184b 1KB
87db04fd8716eb3a4b88f97041126b9da7bde9 761B
894d1a278e3ed8c42e639570a0ceb1ac36326c 135B
89a34ee050b5e68e6ae70f41cbfd776421f541 84B
8b9b1520e9a72765a0721ad12c58acb627039f 928B
8bb93e7ebffecf9b3a7fe1582c2d54be32f75e 345B
8e4079810a018090ba597cc7a7afd41ea79bfb 2KB
8f6d71951e182e79255a2b94cb4ea4aa840da5 134B
8fb1d865a89e6d04e3a0c387535ad4d6aa34c0 1KB
92d638e2a2710cc72eac649710cbf560127d22 1KB
968af357ba7583984746b29aa400ff1bcb224c 245B
96f859f54e491950d60868ef72455f47fac058 464B
97c9bf6abab5bfb1d540e49408165e52cdeff3 151B
9960aa4c4d20d830655c87be19faa59a01682c 134B
9c108783e453961d68b9f44a7dd505927a380f 1KB
9cee8e7b376a4b493efd229ef5246561865764 135B
9d7c0880fe6a8db908fe6e365c370df7aaccb6 135B
9da67f1cdf39347ffd1ad0cb4012580cf34415 832B
9df324b450d0cb30d6cd6ee76845ba67ab748e 72B
a262d800b44df5ce408b97627d6711a064c07c 982B
a4ad3f5871c4b3815694f776d304ae29851227 48B
a7e960684704ca3d756a2719cd0e554aa5396c 850B
a803e63eeee1a27918f6c36ca41c80ea7933c8 85B
aba0b2d291bbf2ad9178ed9a8c621ca523b888 134B
ac38830e1d734727cdf659c6d6005674f8167e 805B
additional-method 13KB
additional-method 13KB
af40cadf2e21c8e03aa284fb4af3e7eeacc82b 788B
animated-overlay 2KB
animated-overlay 2KB
atelier-dune 2KB
atelier-dune 2KB
atelier-fore 2KB
atelier-fore 2KB
atelier-heat 2KB
atelier-heat 2KB
atelier-lake 2KB
atelier-lake 2KB
atelier-seas 2KB
atelier-seas 2KB
b9149ea2f49f24e39fd6a3e78241969a6b48a4 408B
b9902204bec6686f1c9b066ef459979346c4c4 2KB
bef88f62c0e917ecb8d4dda3e422983063e6bf 466B
共 1248 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
程序猿阿存
- 粉丝: 1245
- 资源: 1804
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功