| | |
| | | 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.UserService; |
| | | import com.yuanchu.limslaboratory.shiro.realm.ShiroRealm; |
| | | import com.yuanchu.limslaboratory.utils.SpringUtils; |
| | | import com.yuanchu.limslaboratory.utils.SpringUtil; |
| | | import com.yuanchu.limslaboratory.vo.NewPersonnelVo; |
| | | import com.yuanchu.limslaboratory.vo.PagePersonnelVo; |
| | | import com.yuanchu.limslaboratory.vo.Result; |
| | | import com.yuanchu.limslaboratory.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.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @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("登录失败"); |
| | | } |
| | | } |
| | | |
| | | @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") |
| | |
| | | } catch (Exception e) { |
| | | return Result.fail("用户id为空!"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @PostMapping("/add_new_personnel") |
| | | @ApiOperation("实验室管理-->人员管理-->新增人员") |
| | | public Result<?> addNewPersonnel(@RequestBody NewPersonnelVo newPersonnelVo) { |
| | | newPersonnelVo.setPassword("123456"); |
| | | Integer isAddSuccess = userService.addNewPersonnel(newPersonnelVo); |
| | | 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) |
| | | }) |
| | | public Result<Map<String, Object>> getNewPersonnelPage(Integer pageNo, Integer pageSize, String name) { |
| | | IPage<PagePersonnelVo> PageList = userService.getNewPersonnelPage(name, new Page<Objects>(pageNo, pageSize)); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("row", PageList.getRecords()); |
| | | map.put("total", PageList.getTotal()); |
| | | return Result.success(map); |
| | | } |
| | | } |