package com.lf.server.controller.all; import com.lf.server.annotation.SysLog; import com.lf.server.entity.all.ResponseMsg; import com.lf.server.entity.data.DirEntity; import com.lf.server.entity.sys.RoleEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.StringHelper; import com.lf.server.service.data.DirService; import com.lf.server.service.sys.RoleService; import com.lf.server.service.sys.TokenService; import com.lf.server.service.sys.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * FME接口控制器 * @author WWW */ @Api(tags = "系统对接\\FME") @RestController @RequestMapping("/fmeIt") public class FmeItController extends BaseController { @Autowired UserService userService; @Autowired RoleService roleService; @Autowired TokenService tokenService; @Autowired DirService dirService; @SysLog() @ApiOperation(value = "查询是/否为管理员") @GetMapping(value = "/selectForIsAdmin") public ResponseMsg selectForIsAdmin(HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue == null) { return fail("用户未登录", false); } Integer rows = userService.selectForIsAdmin(ue.getId()); return success("成功", rows > 0); } catch (Exception ex) { return fail(ex, false); } } @SysLog() @ApiOperation(value = "根据ID查询") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectUser") public ResponseMsg selectUser(int id) { try { UserEntity userEntity = userService.selectUser(id); return success(userEntity); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "根据用户ID查询") @ApiImplicitParams({ @ApiImplicitParam(name = "uid", value = "用户ID", dataType = "String", paramType = "query", example = "admin") }) @GetMapping(value = "/selectByUid") public ResponseMsg selectByUid(String uid) { try { if (StringHelper.isEmpty(uid)) { fail("用户ID不能为空", null); } UserEntity userEntity = userService.selectByUid(uid); return success(userEntity); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "分页查询用户并返回记录数") @ApiImplicitParams({ @ApiImplicitParam(name = "uname", value = "用户名", dataType = "String", paramType = "query", example = "室"), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"), @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectByPageForUser") public ResponseMsg> selectByPageForUser(String uname, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("每页页数或分页数小于1", null); } int count = userService.selectCount(uname, null); if (count == 0) { return success(0, null); } List rs = userService.selectByPage(uname, null, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询是/否为管理员") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectIsAdmin") public ResponseMsg selectIsAdmin(Integer id) { try { UserEntity ue = userService.selectUser(id); if (ue == null) { return fail("用户不存在", false); } Integer rows = userService.selectForIsAdmin(ue.getId()); return success("成功", rows > 0); } catch (Exception ex) { return fail(ex, false); } } @SysLog() @ApiOperation(value = "查询管理员用户") @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "管理员类别", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectAdminUsers") public ResponseMsg selectAdminUsers(Integer type) { try { if (null == type || type < 1) { return fail("管理员类别不能为空或小于1", false); } List rs = userService.selectAdminUsers(type); return success(rs); } catch (Exception ex) { return fail(ex, false); } } @SysLog() @ApiOperation(value = "根据用户ID查询角色") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectRoleByUserId") public ResponseMsg selectRoleByUserId(Integer id) { try { if (null == id || id < 1) { return fail("用户ID不能为空或小于1", false); } List rs = userService.selectRoleByUserId(id); return success(rs); } catch (Exception ex) { return fail(ex, false); } } @SysLog() @ApiOperation(value = "根据角色查询用户") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "角色ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectUserByRoleId") public ResponseMsg selectUserByRoleId(Integer id) { try { if (null == id || id < 1) { return fail("用户ID不能为空或小于1", false); } List rs = userService.selectUserByRoleId(id); return success(rs); } catch (Exception ex) { return fail(ex, false); } } @SysLog() @ApiOperation(value = "根据ID查询") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectRole") public ResponseMsg selectRole(int id) { try { RoleEntity roleEntity = roleService.selectRole(id); return success(roleEntity); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "分页查询角色并返回记录数") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = "Admin"), @ApiImplicitParam(name = "depid", value = "单位ID", dataType = "Integer", paramType = "query", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"), @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectByPageForRole") public ResponseMsg> selectByPageForRole(String name, Integer depid, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("每页页数或分页数小于1", null); } int count = roleService.selectCount(name, depid); if (count == 0) { return success(0, null); } List rs = roleService.selectByPage(name, depid, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询根目录") @GetMapping(value = "/selectDirRoot") public ResponseMsg> selectDirRoot() { try { List list = dirService.selectDirRoot(); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询项目") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = "西") }) @GetMapping(value = "/selectProject") public ResponseMsg> selectProject(String name) { try { List list = dirService.selectProject(name); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "查询项目目录树") @GetMapping(value = "/selectDirsForPrj") public ResponseMsg> selectDirsForPrj() { try { List list = dirService.selectDirsForPrj(); return success(list); } catch (Exception ex) { return fail(ex, null); } } }