| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- package com.ims.eval.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.ims.common.utils.RSAUtils;
- import com.ims.eval.entity.dto.result.R;
- import com.ims.eval.entity.Myuser;
- import com.ims.eval.feign.RemoteServiceBuilder;
- import com.ims.eval.service.IUserService;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import java.security.KeyPair;
- import java.util.Base64;
- import java.util.List;
- import java.util.concurrent.atomic.AtomicBoolean;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author wang
- * @since 2023-03-03
- */
- @Slf4j
- @RestController
- @RequestMapping("//user")
- public class UserController {
- @Autowired
- private IUserService userService;
- @Autowired
- private RemoteServiceBuilder remoteServiceBuilder;
- @Autowired
- private HttpServletRequest request;
- @GetMapping("/publicKey")
- public R getPublicKey() throws Exception {
- try {
- KeyPair keyPair = RSAUtils.generateKeyPair(2048);
- String publicKey = Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded());
- return R.ok().data(publicKey);
- } catch (Exception e) {
- e.printStackTrace();
- return R.error("登录失败");
- }
- }
- @GetMapping("/getEncrypt")
- public String getEncrypt(String pwd) throws Exception {
- KeyPair keyPair = RSAUtils.generateKeyPair(2048);
- // 加密
- byte[] encryptedData = RSAUtils.encrypt(pwd.getBytes(), keyPair.getPublic());
- String str2 = Base64.getEncoder().encodeToString(encryptedData).replaceAll(" ", "+");
- return str2;
- }
- /**
- * 更具code获取用户信息
- *
- * @return
- */
- @GetMapping(value = "getSysUser")
- public JSONObject getSysUser(
- @RequestParam(value = "code", required = false) String code) {
- JSONObject json = null;
- try {
- json = remoteServiceBuilder.getGatewayUrl().getSysUser(code);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
- /**
- * 根据token获取code
- *
- * @return
- */
- @GetMapping(value = "getCodeByToken")
- public JSONObject getCodeByToken(
- @RequestParam(value = "token", required = false) String token) {
- JSONObject json = null;
- try {
- json = remoteServiceBuilder.getGatewayUrl().getCodeByToken(token);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return json;
- }
- /**
- * 登录接口
- *
- * @param username
- * @param password
- * @return
- */
- @PostMapping(value = "bladeAuth")
- public R bladeAuth(
- @RequestParam(value = "username", required = false) String username,
- @RequestParam(value = "password", required = false) String password) {
- JSONObject json = null;
- try {
- // json = userService.getbladeAuth("000000",username,password,"password","all","account");
- json = userService.getbladeAuth(username, password);
- } catch (Exception e) {
- log.error("错误", e);
- return R.ok().error("登录失败");
- }
- return R.ok().data(json);
- }
- @GetMapping(value = "pageList")
- public JSONObject pageList(
- @RequestParam(value = "current", required = false) Integer current,
- @RequestParam(value = "size", required = false) Integer size,
- @RequestParam(value = "orgId", required = false) String orgId,
- @RequestParam(value = "idCard", required = false) String idCard,
- @RequestParam(value = "mobile", required = false) String mobile,
- @RequestParam(value = "no", required = false) String no,
- @RequestParam(value = "name", required = false) String name,
- @RequestParam(value = "loginName", required = false) String loginName) {
- JSONObject json = null;
- try {
- json = userService.pageList(current, size, orgId, idCard, mobile, no, name, loginName, request);
- } catch (Exception e) {
- log.error("错误", e);
- return null;
- }
- return json;
- }
- @GetMapping(value = "/getLoginNameByUserInfo")
- public JSONObject getLoginNameByUserInfo(@RequestParam(value = "info") String info) {
- JSONObject json = null;
- try {
- json = userService.getLoginNameByUserInfo(info, request);
- } catch (Exception e) {
- log.error("错误", e);
- return null;
- }
- return json;
- }
- /**
- * 退出登录
- *
- * @param token
- * @return
- */
- @PostMapping(value = "removeByToken")
- public JSONObject removeByToken(@RequestParam(value = "token", required = true) String token) {
- JSONObject json = null;
- try {
- json = remoteServiceBuilder.getGatewayUrl().removeByToken(token);
- } catch (Exception e) {
- log.error("错误", e);
- }
- return json;
- }
- //@ImsPreAuth("eval:dataDictionary:edit")
- @PostMapping(value = "/save")
- @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
- public R addAll(@RequestBody List<Myuser> user) {
- AtomicBoolean b = new AtomicBoolean(false);
- user.stream().forEach(i -> {
- b.set(userService.saveOrUpdate(i));
- });
- if (b.get()) {
- return R.ok().data(b);
- } else {
- return R.error().data("保存失败!");
- }
- }
- /**
- * 查询所有数据
- *
- * @param id 主键
- * @param orgId 组织id
- * @return
- */
- //@ImsPreAuth("eval:organizationEvaluationRule:view")
- @GetMapping(value = "listAll")
- public R listAll(
- @RequestParam(value = "id", required = false) String id,
- @RequestParam(value = "orgId", required = false) String orgId,
- @RequestParam(value = "unitId", required = false) String unitId) {
- List<Myuser> list = userService.listAll(id, orgId, unitId);
- return R.ok().data(list);
- }
- /**
- * 查询所有数据
- *
- * @param id 主键
- * @return
- */
- //@ImsPreAuth("eval:organizationEvaluationRule:view")
- @GetMapping(value = "getId")
- public R getByid(
- @RequestParam(value = "id", required = false) String id) {
- Myuser user = userService.getById(id);
- return R.ok().data(user);
- }
- }
|