| | |
| | | package com.lf.server.controller.sys; |
| | | |
| | | import com.lf.server.aspect.SysLog; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.sys.TokenEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", required = false, example = "sys_token") |
| | | @ApiImplicitParam(name = "name", value = "令牌", dataType = "String", paramType = "query", required = false, example = "sys_token"), |
| | | @ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", example = "sys_token"), |
| | | }) |
| | | @GetMapping({"/selectCount"}) |
| | | public ResponseMsg<Integer> selectCount(String token) { |
| | | public ResponseMsg<Integer> selectCount(String name,Integer type) { |
| | | try { |
| | | int count = tokenService.selectCount(token); |
| | | int count = tokenService.selectCount(name,type); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", example = "sys_token"), |
| | | @ApiImplicitParam(name = "name", value = "令牌", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", example = "0"), |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectByPage") |
| | | public ResponseMsg<List<TokenEntity>> selectByPage(String token, Integer pageSize, Integer pageIndex) { |
| | | public ResponseMsg<List<TokenEntity>> selectByPage(String name, Integer type,Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | List<TokenEntity> rs = tokenService.selectByPage(token, pageSize, pageSize * (pageIndex - 1)); |
| | | List<TokenEntity> rs = tokenService.selectByPage(name,type, pageSize, pageSize * (pageIndex - 1)); |
| | | return success(rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询并返回记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", example = "sys_token"), |
| | | @ApiImplicitParam(name = "name", value = "令牌", dataType = "String", paramType = "query", example = "sys_token"), |
| | | @ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", example = "sys_token"), |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectByPageAndCount") |
| | | public ResponseMsg<List<TokenEntity>> selectByPageAndCount(String token, Integer pageSize, Integer pageIndex) { |
| | | public ResponseMsg<List<TokenEntity>> selectByPageAndCount(String name,Integer type, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | int count = tokenService.selectCount(token); |
| | | int count = tokenService.selectCount(name,type); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | List<TokenEntity> rs = tokenService.selectByPage(token, pageSize, pageSize * (pageIndex - 1)); |
| | | List<TokenEntity> rs = tokenService.selectByPage(name,type, pageSize, pageSize * (pageIndex - 1)); |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入字典") |
| | | @ApiOperation(value = "插入一条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tokenEntity", value = "字典实体类", dataType = "com.lf.server.entity.sys.TokenEntity", paramType = "body", example = "") |
| | | @ApiImplicitParam(name = "entity", value = "实体类", dataType = "com.lf.server.entity.sys.TokenEntity", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/insertToken", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> insertToken(@RequestBody TokenEntity tokenEntity) { |
| | | public ResponseMsg<Integer> insertToken(@RequestBody TokenEntity entity, HttpServletRequest req) { |
| | | try { |
| | | int count = tokenService.insertToken(tokenEntity); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | |
| | | int count = tokenService.insertToken(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入多条字典") |
| | | @ApiOperation(value = "插入多条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tokenEntity", value = "字典实体类集合", dataType = "List<TokenEntity>", paramType = "body", example = "") |
| | | @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "List<TokenEntity>", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/insertTokens", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> insertTokens(@RequestBody List<TokenEntity> tokenEntity) { |
| | | public ResponseMsg<Integer> insertTokens(@RequestBody List<TokenEntity> list, HttpServletRequest req) { |
| | | try { |
| | | int count = tokenService.insertTokens(tokenEntity); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (TokenEntity entity : list) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | } |
| | | |
| | | int count = tokenService.insertTokens(list); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "删除一条字典") |
| | | @ApiOperation(value = "删除一条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1") |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/deleteToken") |
| | | public ResponseMsg<Integer> deleteToken(int id) { |
| | |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "删除多条字典") |
| | | @ApiOperation(value = "删除多条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "字典ID集合", dataType = "List<Integer>", paramType = "query", example = "1,2") |
| | | @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "List<Integer>", paramType = "query", example = "1,2") |
| | | }) |
| | | @GetMapping(value = "/deleteTokens") |
| | | public ResponseMsg<Integer> deleteTokens(@RequestParam List<Integer> ids) { |
| | |
| | | int count = tokenService.deleteTokens(ids); |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "更新一条字典") |
| | | @ApiOperation(value = "更新一条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tokenEntity", value = "字典ID集合", dataType = "TokenEntity", paramType = "body", example = "") |
| | | @ApiImplicitParam(name = "entity", value = "实体类", dataType = "TokenEntity", paramType = "body", example = "") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/updateToken", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> updateToken(@RequestBody TokenEntity tokenEntity) { |
| | | public ResponseMsg<Integer> updateToken(@RequestBody TokenEntity entity, HttpServletRequest req) { |
| | | try { |
| | | int count = tokenService.updateToken(tokenEntity); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | entity.setUpdateUser(ue.getId()); |
| | | } |
| | | |
| | | int count = tokenService.updateToken(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), -1); |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID查询字典") |
| | | @ApiOperation(value = "根据ID查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1") |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectToken") |
| | | public ResponseMsg<TokenEntity> selectToken(int id) { |
| | |
| | | |
| | | return success(tokenEntity); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询所有字典") |
| | | @ApiOperation(value = "查询所有") |
| | | @GetMapping(value = "/selectTokenAll") |
| | | public ResponseMsg<List<TokenEntity>> selectTokenAll() { |
| | | try { |
| | | List<TokenEntity> list = tokenService.selectTokenAll(); |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | } |