|
@@ -1,237 +1,237 @@
|
|
|
-package com.metro.controller;
|
|
|
-
|
|
|
-import com.auth0.jwt.JWT;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.metro.baseRe.AjaxResult;
|
|
|
-import com.metro.baseRe.BaseResponse;
|
|
|
-import com.metro.config.Config;
|
|
|
-import com.metro.entity.model.UserOperateModel;
|
|
|
-import com.metro.entity.po.Account;
|
|
|
-import com.metro.entity.ro.account.*;
|
|
|
-import com.metro.restful.RestResponse;
|
|
|
-import com.metro.restful.RestResult;
|
|
|
-import com.metro.security.Authority;
|
|
|
-import com.metro.security.JWTUtils;
|
|
|
-import com.metro.service.AccountService;
|
|
|
-import com.metro.utils.StringUtils;
|
|
|
-import com.metro.utils.file.FileUtils;
|
|
|
-import com.metro.utils.poi.ExcelUtil;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiParam;
|
|
|
-import lombok.extern.log4j.Log4j2;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import javax.validation.Valid;
|
|
|
-import java.awt.*;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-/**
|
|
|
- * @ClassName: AccountController
|
|
|
- * @Description: TODO
|
|
|
- * @Author: ZS
|
|
|
- * @CreateName: lws
|
|
|
- * @Date 2022/3/9 10:59
|
|
|
- * ...
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("/account")
|
|
|
-@Api(tags = "账号管理")
|
|
|
-@Log4j2
|
|
|
-public class AccountController extends BaseController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AccountService service;
|
|
|
-
|
|
|
- /**
|
|
|
- * 登录
|
|
|
- *
|
|
|
- * @param req 账号密码
|
|
|
- * @return 是否成功
|
|
|
- */
|
|
|
- @ApiOperation("后台管理登录")
|
|
|
- @PostMapping("/login")
|
|
|
- @Authority(required = false)
|
|
|
- public BaseResponse<LoginAccountResp> doLogin(@Valid @RequestBody LoginAccountReq req) {
|
|
|
- return BaseResponse.ok(service.login(req));
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("后台管理退出登录")
|
|
|
- @Authority(required = false)
|
|
|
- @GetMapping("/doLogout")
|
|
|
- public RestResult<Boolean> doLogout() {
|
|
|
- return RestResponse.ok(service.logout());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取用户信息
|
|
|
- *
|
|
|
- * @return 是否成功
|
|
|
- */
|
|
|
- @ApiOperation("获取用户信息")
|
|
|
- @GetMapping("/getUserInfo")
|
|
|
- public RestResult<LoginAccountResp> getUserInfo() {
|
|
|
- return RestResponse.ok(service.getUserInfo(getUserId()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 账号列表查询
|
|
|
- *
|
|
|
- * @param req 查询条件
|
|
|
- * @return page列表
|
|
|
- */
|
|
|
- @PostMapping("/page")
|
|
|
- @Authority
|
|
|
- @ApiOperation("账号列表查询")
|
|
|
- public BaseResponse<IPage<SelectAccountPageResp>> page(@Valid @RequestBody(required = false) SelectAccountPageReq req) {
|
|
|
- return BaseResponse.ok(service.page(req));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加账号
|
|
|
- *
|
|
|
- * @param req 账号信息
|
|
|
- * @return 影响行数
|
|
|
- */
|
|
|
- @PostMapping("/add")
|
|
|
- @Authority
|
|
|
- @ApiOperation("添加账号")
|
|
|
- public BaseResponse<InsertAccountResp> add(@Valid @RequestBody InsertAccountReq req) {
|
|
|
- return BaseResponse.ok(service.add(req));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验账号是否存在
|
|
|
- *
|
|
|
- * @param req 账号
|
|
|
- * @return true/false
|
|
|
- */
|
|
|
- @PostMapping("/validAccount")
|
|
|
- @ApiOperation("校验账号是否存在")
|
|
|
- public BaseResponse<ValidAccountResp> validAccount(@Valid @RequestBody ValidAccountReq req) {
|
|
|
- return BaseResponse.ok(service.validAccount(req));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除账号
|
|
|
- *
|
|
|
- * @param req 主键
|
|
|
- * @return 影响行数
|
|
|
- */
|
|
|
- @PostMapping("/delete")
|
|
|
- @Authority
|
|
|
- @ApiOperation("删除账号")
|
|
|
- public BaseResponse<DeleteAccountResp> delete(@Valid @RequestBody DeleteAccountReq req) {
|
|
|
- return BaseResponse.ok(service.delete(req));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 账号详情
|
|
|
- *
|
|
|
- * @param req 主键
|
|
|
- * @return 账号详情
|
|
|
- */
|
|
|
- @PostMapping("/detail")
|
|
|
- @Authority
|
|
|
- @ApiOperation("帐号详情")
|
|
|
- public BaseResponse<DetailAccountResp> detail(@Valid @RequestBody DetailAccountReq req) {
|
|
|
- return BaseResponse.ok(service.detail(req));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改账号
|
|
|
- *
|
|
|
- * @param req 主键
|
|
|
- * @return 影响行数
|
|
|
- */
|
|
|
- @PostMapping("/update")
|
|
|
- @Authority
|
|
|
- @ApiOperation("修改账号")
|
|
|
- public BaseResponse<UpdateAccountResp> update(@Valid @RequestBody UpdateAccountReq req) {
|
|
|
- return BaseResponse.ok(service.update(req));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上传文件
|
|
|
- *
|
|
|
- * @param file 文件
|
|
|
- * @return 返回信息
|
|
|
- */
|
|
|
- @ApiOperation("上传附件")
|
|
|
- @Authority
|
|
|
- @PostMapping(value = "/uploadPhoto")
|
|
|
- public BaseResponse<String> uploadPhoto(@RequestParam("file") @ApiParam(value = "二进制文件流,文件类型后端未做限制,前端只允许上传照片") MultipartFile file) {
|
|
|
- return service.uploadPhoto(file);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 预览照片
|
|
|
- *
|
|
|
- * @param response response
|
|
|
- * @param fileUrl fileUrl
|
|
|
- */
|
|
|
- @ApiOperation("预览照片")
|
|
|
- @Authority
|
|
|
- @GetMapping("/showPhoto")
|
|
|
- public BaseResponse<Integer> showPhoto(HttpServletResponse response, @RequestParam("fileUrl") @ApiParam("文件路径") String fileUrl) {
|
|
|
- service.showPhoto(response, fileUrl);
|
|
|
- return BaseResponse.ok();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通用下载请求
|
|
|
- *
|
|
|
- * @param fileName 文件名称
|
|
|
- * @param delete 是否删除
|
|
|
- */
|
|
|
- @GetMapping("/download")
|
|
|
- @ApiOperation("下载文件")
|
|
|
- public void fileDownload(String fileName, Boolean delete, HttpServletResponse response) {
|
|
|
- try {
|
|
|
- if (!FileUtils.checkAllowDownload(fileName)) {
|
|
|
- throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
|
|
- }
|
|
|
- String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
|
- String filePath = Config.getDownloadPath() + fileName;
|
|
|
-
|
|
|
- response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
- FileUtils.setAttachmentResponseHeader(response, realFileName);
|
|
|
- FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
|
- if (delete) {
|
|
|
- FileUtils.deleteFile(filePath);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("下载文件失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 下载模板
|
|
|
- */
|
|
|
- @GetMapping("/importTemplate")
|
|
|
- @ApiOperation("获取下载文件名")
|
|
|
- public AjaxResult importTemplate() {
|
|
|
- ExcelUtil<UserOperateModel> util = new ExcelUtil<UserOperateModel>(UserOperateModel.class);
|
|
|
- return util.importTemplateExcel("用户数据");
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 导入
|
|
|
- * */
|
|
|
- @ApiOperation("导入用户数据")
|
|
|
- @PostMapping("/importData")
|
|
|
- public AjaxResult importData(MultipartFile file, String type) throws Exception {
|
|
|
- ExcelUtil<UserOperateModel> util = new ExcelUtil<>(UserOperateModel.class);
|
|
|
- List<UserOperateModel> userList = util.importExcel(file.getInputStream());
|
|
|
- return AjaxResult.success(service.importUser(userList, type));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
+//package com.metro.controller;
|
|
|
+//
|
|
|
+//import com.auth0.jwt.JWT;
|
|
|
+//import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+//import com.metro.baseRe.AjaxResult;
|
|
|
+//import com.metro.baseRe.BaseResponse;
|
|
|
+//import com.metro.config.Config;
|
|
|
+//import com.metro.entity.model.UserOperateModel;
|
|
|
+//import com.metro.entity.po.Account;
|
|
|
+//import com.metro.entity.ro.account.*;
|
|
|
+//import com.metro.restful.RestResponse;
|
|
|
+//import com.metro.restful.RestResult;
|
|
|
+//import com.metro.security.Authority;
|
|
|
+//import com.metro.security.JWTUtils;
|
|
|
+//import com.metro.service.AccountService;
|
|
|
+//import com.metro.utils.StringUtils;
|
|
|
+//import com.metro.utils.file.FileUtils;
|
|
|
+//import com.metro.utils.poi.ExcelUtil;
|
|
|
+//import io.swagger.annotations.Api;
|
|
|
+//import io.swagger.annotations.ApiOperation;
|
|
|
+//import io.swagger.annotations.ApiParam;
|
|
|
+//import lombok.extern.log4j.Log4j2;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.http.MediaType;
|
|
|
+//import org.springframework.web.bind.annotation.*;
|
|
|
+//import org.springframework.web.multipart.MultipartFile;
|
|
|
+//
|
|
|
+//import javax.servlet.http.HttpServletResponse;
|
|
|
+//import javax.validation.Valid;
|
|
|
+//import java.awt.*;
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @ClassName: AccountController
|
|
|
+// * @Description: TODO
|
|
|
+// * @Author: ZS
|
|
|
+// * @CreateName: lws
|
|
|
+// * @Date 2022/3/9 10:59
|
|
|
+// * ...
|
|
|
+// */
|
|
|
+//@RestController
|
|
|
+//@RequestMapping("/account")
|
|
|
+//@Api(tags = "账号管理")
|
|
|
+//@Log4j2
|
|
|
+//public class AccountController extends BaseController {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private AccountService service;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 登录
|
|
|
+// *
|
|
|
+// * @param req 账号密码
|
|
|
+// * @return 是否成功
|
|
|
+// */
|
|
|
+// @ApiOperation("后台管理登录")
|
|
|
+// @PostMapping("/login")
|
|
|
+// @Authority(required = false)
|
|
|
+// public BaseResponse<LoginAccountResp> doLogin(@Valid @RequestBody LoginAccountReq req) {
|
|
|
+// return BaseResponse.ok(service.login(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @ApiOperation("后台管理退出登录")
|
|
|
+// @Authority(required = false)
|
|
|
+// @GetMapping("/doLogout")
|
|
|
+// public RestResult<Boolean> doLogout() {
|
|
|
+// return RestResponse.ok(service.logout());
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取用户信息
|
|
|
+// *
|
|
|
+// * @return 是否成功
|
|
|
+// */
|
|
|
+// @ApiOperation("获取用户信息")
|
|
|
+// @GetMapping("/getUserInfo")
|
|
|
+// public RestResult<LoginAccountResp> getUserInfo() {
|
|
|
+// return RestResponse.ok(service.getUserInfo(getUserId()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 账号列表查询
|
|
|
+// *
|
|
|
+// * @param req 查询条件
|
|
|
+// * @return page列表
|
|
|
+// */
|
|
|
+// @PostMapping("/page")
|
|
|
+// @Authority
|
|
|
+// @ApiOperation("账号列表查询")
|
|
|
+// public BaseResponse<IPage<SelectAccountPageResp>> page(@Valid @RequestBody(required = false) SelectAccountPageReq req) {
|
|
|
+// return BaseResponse.ok(service.page(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 添加账号
|
|
|
+// *
|
|
|
+// * @param req 账号信息
|
|
|
+// * @return 影响行数
|
|
|
+// */
|
|
|
+// @PostMapping("/add")
|
|
|
+// @Authority
|
|
|
+// @ApiOperation("添加账号")
|
|
|
+// public BaseResponse<InsertAccountResp> add(@Valid @RequestBody InsertAccountReq req) {
|
|
|
+// return BaseResponse.ok(service.add(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 校验账号是否存在
|
|
|
+// *
|
|
|
+// * @param req 账号
|
|
|
+// * @return true/false
|
|
|
+// */
|
|
|
+// @PostMapping("/validAccount")
|
|
|
+// @ApiOperation("校验账号是否存在")
|
|
|
+// public BaseResponse<ValidAccountResp> validAccount(@Valid @RequestBody ValidAccountReq req) {
|
|
|
+// return BaseResponse.ok(service.validAccount(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 删除账号
|
|
|
+// *
|
|
|
+// * @param req 主键
|
|
|
+// * @return 影响行数
|
|
|
+// */
|
|
|
+// @PostMapping("/delete")
|
|
|
+// @Authority
|
|
|
+// @ApiOperation("删除账号")
|
|
|
+// public BaseResponse<DeleteAccountResp> delete(@Valid @RequestBody DeleteAccountReq req) {
|
|
|
+// return BaseResponse.ok(service.delete(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 账号详情
|
|
|
+// *
|
|
|
+// * @param req 主键
|
|
|
+// * @return 账号详情
|
|
|
+// */
|
|
|
+// @PostMapping("/detail")
|
|
|
+// @Authority
|
|
|
+// @ApiOperation("帐号详情")
|
|
|
+// public BaseResponse<DetailAccountResp> detail(@Valid @RequestBody DetailAccountReq req) {
|
|
|
+// return BaseResponse.ok(service.detail(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 修改账号
|
|
|
+// *
|
|
|
+// * @param req 主键
|
|
|
+// * @return 影响行数
|
|
|
+// */
|
|
|
+// @PostMapping("/update")
|
|
|
+// @Authority
|
|
|
+// @ApiOperation("修改账号")
|
|
|
+// public BaseResponse<UpdateAccountResp> update(@Valid @RequestBody UpdateAccountReq req) {
|
|
|
+// return BaseResponse.ok(service.update(req));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 上传文件
|
|
|
+// *
|
|
|
+// * @param file 文件
|
|
|
+// * @return 返回信息
|
|
|
+// */
|
|
|
+// @ApiOperation("上传附件")
|
|
|
+// @Authority
|
|
|
+// @PostMapping(value = "/uploadPhoto")
|
|
|
+// public BaseResponse<String> uploadPhoto(@RequestParam("file") @ApiParam(value = "二进制文件流,文件类型后端未做限制,前端只允许上传照片") MultipartFile file) {
|
|
|
+// return service.uploadPhoto(file);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 预览照片
|
|
|
+// *
|
|
|
+// * @param response response
|
|
|
+// * @param fileUrl fileUrl
|
|
|
+// */
|
|
|
+// @ApiOperation("预览照片")
|
|
|
+// @Authority
|
|
|
+// @GetMapping("/showPhoto")
|
|
|
+// public BaseResponse<Integer> showPhoto(HttpServletResponse response, @RequestParam("fileUrl") @ApiParam("文件路径") String fileUrl) {
|
|
|
+// service.showPhoto(response, fileUrl);
|
|
|
+// return BaseResponse.ok();
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 通用下载请求
|
|
|
+// *
|
|
|
+// * @param fileName 文件名称
|
|
|
+// * @param delete 是否删除
|
|
|
+// */
|
|
|
+// @GetMapping("/download")
|
|
|
+// @ApiOperation("下载文件")
|
|
|
+// public void fileDownload(String fileName, Boolean delete, HttpServletResponse response) {
|
|
|
+// try {
|
|
|
+// if (!FileUtils.checkAllowDownload(fileName)) {
|
|
|
+// throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
|
|
+// }
|
|
|
+// String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
|
+// String filePath = Config.getDownloadPath() + fileName;
|
|
|
+//
|
|
|
+// response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+// FileUtils.setAttachmentResponseHeader(response, realFileName);
|
|
|
+// FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
|
+// if (delete) {
|
|
|
+// FileUtils.deleteFile(filePath);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("下载文件失败", e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 下载模板
|
|
|
+// */
|
|
|
+// @GetMapping("/importTemplate")
|
|
|
+// @ApiOperation("获取下载文件名")
|
|
|
+// public AjaxResult importTemplate() {
|
|
|
+// ExcelUtil<UserOperateModel> util = new ExcelUtil<UserOperateModel>(UserOperateModel.class);
|
|
|
+// return util.importTemplateExcel("用户数据");
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*
|
|
|
+// * 导入
|
|
|
+// * */
|
|
|
+// @ApiOperation("导入用户数据")
|
|
|
+// @PostMapping("/importData")
|
|
|
+// public AjaxResult importData(MultipartFile file, String type) throws Exception {
|
|
|
+// ExcelUtil<UserOperateModel> util = new ExcelUtil<>(UserOperateModel.class);
|
|
|
+// List<UserOperateModel> userList = util.importExcel(file.getInputStream());
|
|
|
+// return AjaxResult.success(service.importUser(userList, type));
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|
|
|
+//
|
|
|
+//
|