| | |
| | | package com.yuanchu.limslaboratory.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.limslaboratory.clients.UserLoginUtils; |
| | | import com.yuanchu.limslaboratory.pojo.Enterprise; |
| | | import com.yuanchu.limslaboratory.pojo.User; |
| | | import com.yuanchu.limslaboratory.service.RoleManagerService; |
| | | import com.yuanchu.limslaboratory.service.UserService; |
| | | import com.yuanchu.limslaboratory.shiro.realm.ShiroRealm; |
| | | import com.yuanchu.limslaboratory.utils.SpringUtils; |
| | | import com.yuanchu.limslaboratory.utils.JackSonUtil; |
| | | import com.yuanchu.limslaboratory.utils.RedisUtil; |
| | | import com.yuanchu.limslaboratory.utils.SpringUtil; |
| | | import com.yuanchu.limslaboratory.pojo.vo.NewPersonnelVo; |
| | | import com.yuanchu.limslaboratory.vo.Result; |
| | | import com.yuanchu.limslaboratory.pojo.vo.UpdatePersonnelVo; |
| | | import io.swagger.annotations.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.IncorrectCredentialsException; |
| | |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private RoleManagerService roleManagerService; |
| | | |
| | | @ApiOperation("用户登录") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "account", value = "账号", dataTypeClass = String.class, required = true), |
| | | @ApiImplicitParam(name = "password", value = "密码", dataTypeClass = String.class, required = true) |
| | | }) |
| | | @PostMapping("/login") |
| | | public Result<?> UserLogin(String account, String password){ |
| | | public Result<?> userLogin(String account, String password){ |
| | | boolean loginSuccess = false; |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | if (!subject.isAuthenticated()) { |
| | |
| | | } |
| | | if (loginSuccess) { |
| | | // 获取shiroRealm中的数据 |
| | | ShiroRealm bean = SpringUtils.getBean(ShiroRealm.class); |
| | | ShiroRealm bean = SpringUtil.getBean(ShiroRealm.class); |
| | | User user = bean.user; |
| | | user.setPassword(null); |
| | | UserLoginUtils bean1 = SpringUtils.getBean(UserLoginUtils.class); |
| | | UserLoginUtils bean1 = SpringUtil.getBean(UserLoginUtils.class); |
| | | return bean1.LoginExamine(user); |
| | | }else { |
| | | return Result.fail("登录失败"); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/getUserById") |
| | | @ApiOperation("获取指定用户id的用户信息和企业信息") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(value = "用户id", name = "userId", dataTypeClass = Integer.class, required = true) |
| | | }) |
| | | public Result<?> getUserById(int userId) { |
| | | try { |
| | | Map<String, String> map = userService.selectUserByUserId(userId); |
| | | User user = new User(map.get("account"),map.get("uname"),map.get("phone"),map.get("email"),map.get("info")); |
| | | Enterprise enterprise = new Enterprise(map.get("name"),map.get("byname"),map.get("link_name"),map.get("link_phone")); |
| | | Map map1 = new HashMap<>(); |
| | | map1.put("enterprise", enterprise); |
| | | map1.put("user", user); |
| | | return Result.success(map1); |
| | | } catch (Exception e) { |
| | | return Result.fail("用户id为空!"); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("新增用户获取角色权限信息") |
| | | @GetMapping("/list") |
| | | public Result<?> getUserListRole(){ |
| | | List<Map<String,Object>> data = roleManagerService.getUserListRole(); |
| | | return Result.success(data); |
| | | } |
| | | |
| | | @ApiOperation("登录-->获取用户信息") |
| | | @GetMapping("/info") |
| | | public Result<?> getUserInfo(@RequestHeader("X-Token") String token){ |
| | | //根据token获取用户信息 |
| | | Map<String,Object> data = userService.getUserInfo(token); |
| | | if (data != null){ |
| | | return Result.success(data); |
| | | } |
| | | return Result.fail(202,"用户登录信息无效,请重新登录"); |
| | | } |
| | | |
| | | @PostMapping("/getUserById") |
| | | @ApiOperation("获取指定用户id的用户信息和企业信息") |
| | | public Result<?> getUserById(@RequestHeader("X-Token") String token) throws Exception { |
| | | Object o = RedisUtil.get(token); |
| | | Map<String, Object> unmarshal = null; |
| | | if (!ObjectUtils.isEmpty(o)){ |
| | | unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(o), Map.class); |
| | | Map<String, String> map = userService.selectUserByUserId((Integer) unmarshal.get("id")); |
| | | return Result.success(map); |
| | | } |
| | | return Result.fail("Token错误!"); |
| | | } |
| | | |
| | | @PostMapping("/add_new_personnel") |
| | | @ApiOperation("实验室管理-->人员管理-->新增人员") |
| | | public Result<?> addNewPersonnel(@RequestHeader("X-Token") String token, @RequestBody NewPersonnelVo newPersonnelVo) throws Exception { |
| | | Object redisUserMessage = RedisUtil.get(token); |
| | | Map<String, Object> user = null; |
| | | Integer isAddSuccess = 0; |
| | | if (!ObjectUtils.isEmpty(redisUserMessage)) { |
| | | user = JackSonUtil.unmarshal(JackSonUtil.marshal(redisUserMessage), Map.class); |
| | | newPersonnelVo.setPassword("123456"); |
| | | isAddSuccess = userService.addNewPersonnel(newPersonnelVo, user.get("enterpriseId").toString()); |
| | | } |
| | | |
| | | if (isAddSuccess == 1){ |
| | | return Result.success("添加【" + newPersonnelVo.getName() + "】成功,默认密码为:" + newPersonnelVo.getPassword()); |
| | | } |
| | | return Result.fail("添加失败!"); |
| | | } |
| | | |
| | | @PutMapping("/update_new_personnel") |
| | | @ApiOperation("实验室管理-->人员管理-->编辑操作") |
| | | public Result<?> updateNewPersonnel(@RequestBody UpdatePersonnelVo updatePersonnelVo) { |
| | | Integer isUpdateSuccess = userService.updateNewPersonnel(updatePersonnelVo); |
| | | if (isUpdateSuccess == 1){ |
| | | return Result.success("更新【" + updatePersonnelVo.getName() + "】成功"); |
| | | } |
| | | return Result.fail("更新【" + updatePersonnelVo.getName() + "】失败"); |
| | | } |
| | | |
| | | @GetMapping("/list_new_personnel") |
| | | @ApiOperation("实验室管理-->人员管理-->分页查询") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "pageNo", value = "起始页", dataTypeClass = Integer.class, required = true), |
| | | @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true), |
| | | @ApiImplicitParam(name = "name", value = "人员名称", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "status", value = "在职状态", dataTypeClass = Integer.class) |
| | | }) |
| | | public Result<Map<String, Object>> getNewPersonnelPage(Integer pageNo, Integer pageSize, String name, Integer status) { |
| | | IPage<Map<String, Object>> PageList = userService.getNewPersonnelPage(name, new Page<Objects>(pageNo, pageSize), status); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("row", PageList.getRecords()); |
| | | map.put("total", PageList.getTotal()); |
| | | return Result.success(map); |
| | | } |
| | | } |