diff --git a/hchyun-ui/src/api/system/file.js b/hchyun-ui/src/api/system/file.js new file mode 100644 index 0000000..3551fc3 --- /dev/null +++ b/hchyun-ui/src/api/system/file.js @@ -0,0 +1,66 @@ +import request from '@/utils/request' + + +// 查询文件信息列表 +export function listFile(data) { + return request({ + url: '/system/file/list', + method: 'put', + data: data + }) +} + +// 导出文件信息 +export function exportFile(data) { + return request({ + url: '/system/file/export', + method: 'put', + data: data + }) +} + +// 查询文件信息详细 +export function getFile(fileId) { + return request({ + url: '/system/file/' + fileId, + method: 'get' + }) +} + +// 新增文件信息 +export function addFile(data) { + return request({ + url: '/system/file', + method: 'post', + data: data + }) +} + +// 修改文件信息 +export function updateFile(data) { + return request({ + url: '/system/file', + method: 'put', + data: data + }) +} + +// 删除文件信息 +export function delFile(fileId) { + return request({ + url: '/system/file/' + fileId, + method: 'delete' + }) +} + +// 获取角色选择框列表 +export function getRoleAll(){ + return request({ + url:'/system/role/optionselect', + method:'get', + params:{ + type:2 + } + }) + +} diff --git a/hchyun-ui/src/components/FileUpload/index.vue b/hchyun-ui/src/components/FileUpload/index.vue index 69942aa..42dd992 100644 --- a/hchyun-ui/src/components/FileUpload/index.vue +++ b/hchyun-ui/src/components/FileUpload/index.vue @@ -43,6 +43,7 @@ import { getToken } from "@/utils/auth"; export default { props: { + // 值 value: [String, Object, Array], // 大小限制(MB) @@ -110,7 +111,7 @@ export default { return false; }); if (!isTypeOk) { - this.$message.error(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); + this.$message.error('文件格式不正确, 请上传${this.fileType.join("/")}格式文件!'); return false; } } @@ -118,7 +119,7 @@ export default { if (this.fileSize) { const isLt = file.size / 1024 / 1024 < this.fileSize; if (!isLt) { - this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`); + this.$message.error('提交文件大小不能超过 ${this.fileSize} MB!'); return false; } } @@ -126,16 +127,17 @@ export default { }, // 文件个数超出 handleExceed() { - this.$message.error(`只允许上传单个文件`); + this.$message.error('只允许提交单个文件'); }, // 上传失败 handleUploadError(err) { - this.$message.error("上传失败, 请重试"); + this.$message.error("提交失败!, 请重试"); }, // 上传成功回调 handleUploadSuccess(res, file) { - this.$message.success("上传成功"); + this.$message.success("提交成功!"); this.$emit("input", res.url); + this.$emit("changeAddress",res.fileName); }, // 删除文件 handleDelete(index) { @@ -176,4 +178,4 @@ export default { .ele-upload-list__item-content-action .el-link { margin-right: 10px; } - \ No newline at end of file + diff --git a/hchyun-ui/src/components/ImageUpload/index.vue b/hchyun-ui/src/components/ImageUpload/index.vue index 8996329..c887a54 100644 --- a/hchyun-ui/src/components/ImageUpload/index.vue +++ b/hchyun-ui/src/components/ImageUpload/index.vue @@ -61,6 +61,7 @@ export default { }, handleUploadSuccess(res) { this.$emit("input", res.url); + this.$emit("changeAddress",res.fileName); this.loading.close(); }, handleBeforeUpload() { @@ -73,7 +74,7 @@ export default { handleUploadError() { this.$message({ type: "error", - message: "上传失败", + message: "提交失败!", }); this.loading.close(); }, @@ -97,4 +98,4 @@ export default { opacity: 1; } } - \ No newline at end of file + diff --git a/hchyun-ui/src/views/system/file/index.vue b/hchyun-ui/src/views/system/file/index.vue new file mode 100644 index 0000000..2b2e483 --- /dev/null +++ b/hchyun-ui/src/views/system/file/index.vue @@ -0,0 +1,441 @@ + + + diff --git a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java index 234a6c5..08113e9 100644 --- a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java +++ b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java @@ -72,6 +72,7 @@ public class CommonController { AjaxResult ajax = AjaxResult.success(); ajax.put("fileName" , fileName); ajax.put("url" , url); + ajax.put("addres","/test"); return ajax; } catch (Exception e) { return AjaxResult.error(e.getMessage()); diff --git a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/FileController.java b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/FileController.java new file mode 100644 index 0000000..9a07663 --- /dev/null +++ b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/FileController.java @@ -0,0 +1,183 @@ +package com.hchyun.web.controller.system; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + + +import com.hchyun.common.constant.ReturnConstants; +import com.hchyun.common.core.controller.HcyBaseController; +import com.hchyun.common.utils.ServerResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.hchyun.common.annotation.Log; +import com.hchyun.common.core.entity.AjaxResult; +import com.hchyun.common.enums.BusinessType; +import com.hchyun.system.entity.File; +import com.hchyun.system.service.FileService; +import com.hchyun.common.utils.poi.ExcelUtil; + +/** + * 文件信息Controller + * + * @author hchyun + * @date 2021-02-17 + */ + +@Api(value = "文件信息管理",tags = "文件信息管理") +@RestController +@RequestMapping("/system/file") +public class FileController extends HcyBaseController { + protected final Logger logger = LoggerFactory.getLogger(FileController.class); + + @Autowired + private FileService fileService; + + /** + * 查询文件信息列表 + */ + @ApiOperation("查询文件信息列表") + @PreAuthorize("@ss.hasPermi('system:file:list')") + @PutMapping("/list") + public Serializable list(@Validated @RequestBody File file) { + try { + startPage(file.getParams()); + ServerResult> serverResult = fileService.selectFileList(file); + if (serverResult.isStart()) { + return getDataTable(serverResult.getData()); + } else { + return AjaxResult.info(serverResult.getMsg()); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + return AjaxResult.error(ReturnConstants.SYS_ERROR); + } + } + + /** + * 导出文件信息列表 + */ + @ApiOperation("导出文件信息列表") + @PreAuthorize("@ss.hasPermi('system:file:export')") + @Log(title = "文件信息", businessType = BusinessType.EXPORT) + @PutMapping("/export") + public AjaxResult export(@Validated @RequestBody File file) { + try { + ServerResult> serverResult = fileService.selectFileList(file); + ExcelUtil util = new ExcelUtil(File. class); + if (serverResult.isStart()) { + return util.exportExcel(serverResult.getData(), "file"); + } else { + return AjaxResult.error(serverResult.getMsg()); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + return AjaxResult.error(ReturnConstants.SYS_ERROR); + } + } + + /** + * 获取文件信息详细信息 + */ + @ApiOperation("获取文件信息详细信息") + @ApiImplicitParam(name = "fileId" , value = "文件信息fileId" , required = true, dataType = "Long" , paramType = "path") + @PreAuthorize("@ss.hasPermi('system:file:query')") + @GetMapping(value = "/{fileId}") + public AjaxResult getInfo(@PathVariable("fileId") Long fileId) { + try { + ServerResult serverResult = fileService.selectFileById(fileId); + if (serverResult.isStart()) { + return AjaxResult.success(serverResult.getData()); + } else { + return AjaxResult.info(serverResult.getMsg()); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + return AjaxResult.error(ReturnConstants.SYS_ERROR); + } + } + + /** + * 新增文件信息 + */ + @ApiOperation("新增文件信息") + @ApiImplicitParam(name = "file" , value = "新增文件信息信息" , dataType = "File") + @PreAuthorize("@ss.hasPermi('system:file:add')") + @Log(title = "文件信息", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody File file) { + try { + ServerResult serverResult = fileService.insertFile(file); + if (serverResult.isStart()) { + return AjaxResult.success(); + } else { + return AjaxResult.error(serverResult.getMsg()); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + return AjaxResult.error(ReturnConstants.SYS_ERROR); + } + } + + /** + * 修改文件信息 + */ + @ApiOperation("修改文件信息") + @ApiImplicitParam(name = "file" , value = "修改文件信息信息" , dataType = "File") + @PreAuthorize("@ss.hasPermi('system:file:edit')") + @Log(title = "文件信息", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody File file) { + try { + + ServerResult serverResult = fileService.updateFile(file); + if (serverResult.isStart()) { + return AjaxResult.success(); + } else { + return AjaxResult.error(serverResult.getMsg()); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + return AjaxResult.error(ReturnConstants.SYS_ERROR); + } + } + + /** + * 删除文件信息 + */ + @ApiOperation("删除文件信息") + @ApiImplicitParam(name = "fileIds" , value = "文件信息fileIds" , required = true, dataType = "Long" , paramType = "path") + @PreAuthorize("@ss.hasPermi('system:file:remove')") + @Log(title = "文件信息", businessType = BusinessType.DELETE) + @DeleteMapping("/{fileIds}") + public AjaxResult remove(@PathVariable Long[] fileIds) { + try { + if (fileIds.length<0){ + return AjaxResult.error("id不能为空!"); + } + ServerResult serverResult = fileService.deleteFileByIds(fileIds); + if (serverResult.isStart()) { + return AjaxResult.success(); + } else { + return AjaxResult.error(serverResult.getMsg()); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return AjaxResult.error(ReturnConstants.SYS_ERROR); + } + } +} diff --git a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysRoleController.java b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysRoleController.java index 4e5f99d..8fb36ea 100644 --- a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysRoleController.java +++ b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysRoleController.java @@ -2,6 +2,7 @@ package com.hchyun.web.controller.system; import java.util.List; +import com.hchyun.common.constant.ReturnConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -30,6 +31,8 @@ import com.hchyun.framework.web.service.TokenService; import com.hchyun.system.service.ISysRoleService; import com.hchyun.system.service.ISysUserService; +import javax.servlet.http.HttpServletRequest; + /** * 角色信息 * @@ -159,7 +162,11 @@ public class SysRoleController extends BaseController { */ @PreAuthorize("@ss.hasPermi('system:role:query')") @GetMapping("/optionselect") - public AjaxResult optionselect() { - return AjaxResult.success(roleService.selectRoleAll()); + public AjaxResult optionselect(Integer type) { + if (type == 1 || type == 2) { + return AjaxResult.success(roleService.selectRoleAll(type)); + } else { + return AjaxResult.error(ReturnConstants.STATE_ERROR); + } } } diff --git a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysUserController.java b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysUserController.java index ab1f545..9924b92 100644 --- a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysUserController.java +++ b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/system/SysUserController.java @@ -98,7 +98,7 @@ public class SysUserController extends BaseController { @GetMapping(value = {"/" , "/{userId}"}) public AjaxResult getInfo(@PathVariable(value = "userId" , required = false) Long userId) { AjaxResult ajax = AjaxResult.success(); - List roles = roleService.selectRoleAll(); + List roles = roleService.selectRoleAll(1); ajax.put("roles" , SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); ajax.put("posts" , postService.selectPostAll()); if (StringUtils.isNotNull(userId)) { diff --git a/hchyun/hchyun-common/src/main/java/com/hchyun/common/core/entity/entity/SysRole.java b/hchyun/hchyun-common/src/main/java/com/hchyun/common/core/entity/entity/SysRole.java index 68db1ab..c93e69b 100644 --- a/hchyun/hchyun-common/src/main/java/com/hchyun/common/core/entity/entity/SysRole.java +++ b/hchyun/hchyun-common/src/main/java/com/hchyun/common/core/entity/entity/SysRole.java @@ -2,6 +2,7 @@ package com.hchyun.common.core.entity.entity; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; + import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.hchyun.common.annotation.Excel; @@ -10,217 +11,225 @@ import com.hchyun.common.core.entity.BaseEntity; /** * 角色表 sys_role - * + * * @author hchyun */ -public class SysRole extends BaseEntity -{ +public class SysRole extends BaseEntity { - /** 角色ID */ - @Excel(name = "角色序号", cellType = ColumnType.NUMERIC) + /** + * 角色ID + */ + @Excel(name = "角色序号" , cellType = ColumnType.NUMERIC) private Long roleId; - /** 角色名称 */ + /** + * 角色名称 + */ @Excel(name = "角色名称") private String roleName; - /** 角色权限 */ + /** + * 角色权限 + */ @Excel(name = "角色权限") private String roleKey; - /** 角色排序 */ + /** + * 角色排序 + */ @Excel(name = "角色排序") private String roleSort; - /** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限) */ - @Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限") + /** + * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限) + */ + @Excel(name = "数据范围" , readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限") private String dataScope; - /** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */ + /** + * 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) + */ private boolean menuCheckStrictly; - /** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */ + /** + * 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) + */ private boolean deptCheckStrictly; - /** 角色状态(0正常 1停用) */ - @Excel(name = "角色状态", readConverterExp = "0=正常,1=停用") + /** + * 角色状态(0正常 1停用) + */ + @Excel(name = "角色状态" , readConverterExp = "0=正常,1=停用") private String status; - /** 删除标志(0代表存在 2代表删除) */ + /** + * 删除标志(0代表存在 2代表删除) + */ private String delFlag; - /** 用户是否存在此角色标识 默认不存在 */ + /** + * 用户是否存在此角色标识 默认不存在 + */ private boolean flag = false; - /** 菜单组 */ + /** + * 菜单组 + */ private Long[] menuIds; - /** 部门组(数据权限) */ + /** + * 部门组(数据权限) + */ private Long[] deptIds; - public SysRole() - { + private Integer roleType = 1; + public SysRole() { } - public SysRole(Long roleId) - { + public SysRole(Integer roleType) { + this.roleType = roleType; + } + + public Integer getRoleType() { + return roleType; + } + + public void setRoleType(Integer roleType) { + this.roleType = roleType; + } + + public SysRole(Long roleId) { this.roleId = roleId; } - public Long getRoleId() - { + public Long getRoleId() { return roleId; } - public void setRoleId(Long roleId) - { + public void setRoleId(Long roleId) { this.roleId = roleId; } - public boolean isAdmin() - { + public boolean isAdmin() { return isAdmin(this.roleId); } - public static boolean isAdmin(Long roleId) - { + public static boolean isAdmin(Long roleId) { return roleId != null && 1L == roleId; } @NotBlank(message = "角色名称不能为空") @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符") - public String getRoleName() - { + public String getRoleName() { return roleName; } - public void setRoleName(String roleName) - { + public void setRoleName(String roleName) { this.roleName = roleName; } @NotBlank(message = "权限字符不能为空") @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符") - public String getRoleKey() - { + public String getRoleKey() { return roleKey; } - public void setRoleKey(String roleKey) - { + public void setRoleKey(String roleKey) { this.roleKey = roleKey; } @NotBlank(message = "显示顺序不能为空") - public String getRoleSort() - { + public String getRoleSort() { return roleSort; } - public void setRoleSort(String roleSort) - { + public void setRoleSort(String roleSort) { this.roleSort = roleSort; } - public String getDataScope() - { + public String getDataScope() { return dataScope; } - public void setDataScope(String dataScope) - { + public void setDataScope(String dataScope) { this.dataScope = dataScope; } - public boolean isMenuCheckStrictly() - { + public boolean isMenuCheckStrictly() { return menuCheckStrictly; } - public void setMenuCheckStrictly(boolean menuCheckStrictly) - { + public void setMenuCheckStrictly(boolean menuCheckStrictly) { this.menuCheckStrictly = menuCheckStrictly; } - public boolean isDeptCheckStrictly() - { + public boolean isDeptCheckStrictly() { return deptCheckStrictly; } - public void setDeptCheckStrictly(boolean deptCheckStrictly) - { + public void setDeptCheckStrictly(boolean deptCheckStrictly) { this.deptCheckStrictly = deptCheckStrictly; } - public String getStatus() - { + public String getStatus() { return status; } - public void setStatus(String status) - { + public void setStatus(String status) { this.status = status; } - public String getDelFlag() - { + public String getDelFlag() { return delFlag; } - public void setDelFlag(String delFlag) - { + public void setDelFlag(String delFlag) { this.delFlag = delFlag; } - public boolean isFlag() - { + public boolean isFlag() { return flag; } - public void setFlag(boolean flag) - { + public void setFlag(boolean flag) { this.flag = flag; } - public Long[] getMenuIds() - { + public Long[] getMenuIds() { return menuIds; } - public void setMenuIds(Long[] menuIds) - { + public void setMenuIds(Long[] menuIds) { this.menuIds = menuIds; } - public Long[] getDeptIds() - { + public Long[] getDeptIds() { return deptIds; } - public void setDeptIds(Long[] deptIds) - { + public void setDeptIds(Long[] deptIds) { this.deptIds = deptIds; } - + @Override public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("roleId", getRoleId()) - .append("roleName", getRoleName()) - .append("roleKey", getRoleKey()) - .append("roleSort", getRoleSort()) - .append("dataScope", getDataScope()) - .append("menuCheckStrictly", isMenuCheckStrictly()) - .append("deptCheckStrictly", isDeptCheckStrictly()) - .append("status", getStatus()) - .append("delFlag", getDelFlag()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .toString(); + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("roleId" , getRoleId()) + .append("roleName" , getRoleName()) + .append("roleKey" , getRoleKey()) + .append("roleSort" , getRoleSort()) + .append("dataScope" , getDataScope()) + .append("menuCheckStrictly" , isMenuCheckStrictly()) + .append("deptCheckStrictly" , isDeptCheckStrictly()) + .append("status" , getStatus()) + .append("delFlag" , getDelFlag()) + .append("createBy" , getCreateBy()) + .append("createTime" , getCreateTime()) + .append("updateBy" , getUpdateBy()) + .append("updateTime" , getUpdateTime()) + .append("remark" , getRemark()) + .toString(); } } diff --git a/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUploadUtils.java b/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUploadUtils.java index 886186e..39aeef7 100644 --- a/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUploadUtils.java +++ b/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUploadUtils.java @@ -109,7 +109,10 @@ public class FileUploadUtils { public static final String extractFilename(MultipartFile file) { String fileName = file.getOriginalFilename(); String extension = getExtension(file); - fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; + + fileName = DateUtils.datePath() + "/" + fileName; + // todo IdUtils.fastUUID() 获取文件映射名 +// fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; return fileName; } @@ -125,6 +128,13 @@ public class FileUploadUtils { return desc; } + /** + * + * @param uploadDir + * @param fileName + * @return + * @throws IOException + */ private static final String getPathFileName(String uploadDir, String fileName) throws IOException { int dirLastIndex = HchYunConfig.getProfile().length() + 1; String currentDir = StringUtils.substring(uploadDir, dirLastIndex); @@ -163,7 +173,6 @@ public class FileUploadUtils { throw new InvalidExtensionException(allowedExtension, extension, fileName); } } - } /** diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/web/service/TokenService.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/web/service/TokenService.java index ec82931..4b96389 100644 --- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/web/service/TokenService.java +++ b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/web/service/TokenService.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -26,8 +27,7 @@ import io.jsonwebtoken.SignatureAlgorithm; * @author hchyun */ @Component -public class TokenService -{ +public class TokenService { // 令牌自定义标识 @Value("${token.header}") private String header; @@ -54,12 +54,10 @@ public class TokenService * * @return 用户信息 */ - public LoginUser getLoginUser(HttpServletRequest request) - { + public LoginUser getLoginUser(HttpServletRequest request) { // 获取请求携带的令牌 String token = getToken(request); - if (StringUtils.isNotEmpty(token)) - { + if (StringUtils.isNotEmpty(token)) { Claims claims = parseToken(token); // 解析对应的权限以及用户信息 String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); @@ -73,10 +71,8 @@ public class TokenService /** * 设置用户身份信息 */ - public void setLoginUser(LoginUser loginUser) - { - if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) - { + public void setLoginUser(LoginUser loginUser) { + if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) { refreshToken(loginUser); } } @@ -84,10 +80,8 @@ public class TokenService /** * 删除用户身份信息 */ - public void delLoginUser(String token) - { - if (StringUtils.isNotEmpty(token)) - { + public void delLoginUser(String token) { + if (StringUtils.isNotEmpty(token)) { String userKey = getTokenKey(token); redisCache.deleteObject(userKey); } @@ -99,8 +93,7 @@ public class TokenService * @param loginUser 用户信息 * @return 令牌 */ - public String createToken(LoginUser loginUser) - { + public String createToken(LoginUser loginUser) { String token = IdUtils.fastUUID(); loginUser.setToken(token); setUserAgent(loginUser); @@ -117,12 +110,10 @@ public class TokenService * @param loginUser * @return 令牌 */ - public void verifyToken(LoginUser loginUser) - { + public void verifyToken(LoginUser loginUser) { long expireTime = loginUser.getExpireTime(); long currentTime = System.currentTimeMillis(); - if (expireTime - currentTime <= MILLIS_MINUTE_TEN) - { + if (expireTime - currentTime <= MILLIS_MINUTE_TEN) { refreshToken(loginUser); } } @@ -132,8 +123,7 @@ public class TokenService * * @param loginUser 登录信息 */ - public void refreshToken(LoginUser loginUser) - { + public void refreshToken(LoginUser loginUser) { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); // 根据uuid将loginUser缓存 @@ -146,8 +136,7 @@ public class TokenService * * @param loginUser 登录信息 */ - public void setUserAgent(LoginUser loginUser) - { + public void setUserAgent(LoginUser loginUser) { UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); loginUser.setIpaddr(ip); @@ -162,8 +151,7 @@ public class TokenService * @param claims 数据声明 * @return 令牌 */ - private String createToken(Map claims) - { + private String createToken(Map claims) { String token = Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS512, secret).compact(); @@ -176,8 +164,7 @@ public class TokenService * @param token 令牌 * @return 数据声明 */ - private Claims parseToken(String token) - { + private Claims parseToken(String token) { return Jwts.parser() .setSigningKey(secret) .parseClaimsJws(token) @@ -190,8 +177,7 @@ public class TokenService * @param token 令牌 * @return 用户名 */ - public String getUsernameFromToken(String token) - { + public String getUsernameFromToken(String token) { Claims claims = parseToken(token); return claims.getSubject(); } @@ -202,18 +188,15 @@ public class TokenService * @param request * @return token */ - private String getToken(HttpServletRequest request) - { + private String getToken(HttpServletRequest request) { String token = request.getHeader(header); - if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) - { + if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { token = token.replace(Constants.TOKEN_PREFIX, ""); } return token; } - private String getTokenKey(String uuid) - { + private String getTokenKey(String uuid) { return Constants.LOGIN_TOKEN_KEY + uuid; } } diff --git a/hchyun/hchyun-generator/src/main/resources/vm/java/dao.java.vm b/hchyun/hchyun-generator/src/main/resources/vm/java/dao.java.vm index 3c2a5ec..0f9e5e9 100644 --- a/hchyun/hchyun-generator/src/main/resources/vm/java/dao.java.vm +++ b/hchyun/hchyun-generator/src/main/resources/vm/java/dao.java.vm @@ -82,7 +82,7 @@ public interface ${ClassName}Dao { /** * 通过${functionName}ID删除${subTable.functionName}信息 * - * @param roleId 角色ID + * @param roleIds 角色ID * @return 结果 */ int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/FileDao.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/FileDao.java new file mode 100644 index 0000000..c0dbfcb --- /dev/null +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/FileDao.java @@ -0,0 +1,62 @@ +package com.hchyun.system.dao; + +import java.util.List; +import java.util.Map; + +import com.hchyun.system.entity.File; + +/** + * 文件信息Mapper接口 + * + * @author hchyun + * @date 2021-02-17 + */ +public interface FileDao { + /** + * 查询文件信息 + * + * @param fileId 文件信息ID + * @return 文件信息 + */ + File selectFileById(Long fileId); + + /** + * 查询文件信息列表 + * + * @param file 文件信息 + * @return 文件信息集合 + */ + List selectFileList(File file); + + /** + * 新增文件信息 + * + * @param file 文件信息 + * @return 结果 + */ + int insertFile(File file); + + /** + * 修改文件信息 + * + * @param file 文件信息 + * @return 结果 + */ + int updateFile(File file); + + /** + * 删除文件信息 + * + * @param fileId 文件信息ID + * @return 结果 + */ + int deleteFileById(Long fileId); + + /** + * 批量删除文件信息 + * + * @param fileIds 需要删除的数据ID + * @return 结果 + */ + int deleteFileByIds(Long[] fileIds); +} diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/SysRoleDao.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/SysRoleDao.java index 3ccfe73..98cef2e 100644 --- a/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/SysRoleDao.java +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/dao/SysRoleDao.java @@ -1,18 +1,18 @@ package com.hchyun.system.dao; import java.util.List; + import com.hchyun.common.core.entity.entity.SysRole; /** * 角色表 数据层 - * + * * @author hchyun */ -public interface SysRoleDao -{ +public interface SysRoleDao { /** * 根据条件分页查询角色数据 - * + * * @param role 角色信息 * @return 角色数据集合信息 */ @@ -20,7 +20,7 @@ public interface SysRoleDao /** * 根据用户ID查询角色 - * + * * @param userId 用户ID * @return 角色列表 */ @@ -28,14 +28,14 @@ public interface SysRoleDao /** * 查询所有角色 - * + * * @return 角色列表 */ public List selectRoleAll(); /** * 根据用户ID获取角色选择框列表 - * + * * @param userId 用户ID * @return 选中角色ID列表 */ @@ -43,7 +43,7 @@ public interface SysRoleDao /** * 通过角色ID查询角色 - * + * * @param roleId 角色ID * @return 角色对象信息 */ @@ -51,7 +51,7 @@ public interface SysRoleDao /** * 根据用户ID查询角色 - * + * * @param userName 用户名 * @return 角色列表 */ @@ -59,7 +59,7 @@ public interface SysRoleDao /** * 校验角色名称是否唯一 - * + * * @param roleName 角色名称 * @return 角色信息 */ @@ -67,7 +67,7 @@ public interface SysRoleDao /** * 校验角色权限是否唯一 - * + * * @param roleKey 角色权限 * @return 角色信息 */ @@ -75,7 +75,7 @@ public interface SysRoleDao /** * 修改角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -83,7 +83,7 @@ public interface SysRoleDao /** * 新增角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -91,7 +91,7 @@ public interface SysRoleDao /** * 通过角色ID删除角色 - * + * * @param roleId 角色ID * @return 结果 */ @@ -99,7 +99,7 @@ public interface SysRoleDao /** * 批量删除角色信息 - * + * * @param roleIds 需要删除的角色ID * @return 结果 */ diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/entity/File.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/entity/File.java new file mode 100644 index 0000000..dc1f70f --- /dev/null +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/entity/File.java @@ -0,0 +1,161 @@ +package com.hchyun.system.entity; + +import com.hchyun.common.annotation.Excel; +import com.hchyun.common.core.entity.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 文件信息对象 sys_file + * + * @author hchyun + * @date 2021-02-17 + */ +@ApiModel("文件信息") +public class File extends BaseEntity { + + /** + * 文件id + */ + @ApiModelProperty("文件id") + private Long fileId; + /** + * 文件夹id + */ + @ApiModelProperty("文件夹id") + private Long pId; + /** + * 角色id + */ + @ApiModelProperty("角色id") + private String roleIds; + /** + * 文件名称 + */ + @Excel(name = "文件名称") + @ApiModelProperty("文件名称") + private String fileName; + /** + * 映射名称 + */ + @ApiModelProperty("映射名称") + private String mapping; + /** + * 文件路径 + */ + @Excel(name = "文件路径") + @ApiModelProperty("文件路径") + private String fileAddr; + /** + * 文件类型(文件夹:folder,文件:file) + */ + @Excel(name = "文件类型") + @ApiModelProperty("文件类型") + private String fileType; + /** + * 文件大小(MB) + */ + @Excel(name = "文件大小(MB)") + @ApiModelProperty("文件大小(MB)") + private String fileSize; + /** + * 是否公开 + */ + @Excel(name = "是否公开") + @ApiModelProperty("是否公开") + private String isPublic; + + + public void setFileId(Long fileId) { + this.fileId = fileId; + } + + public Long getFileId() { + return fileId; + } + + public void setpId(Long pId) { + this.pId = pId; + } + + public Long getpId() { + return pId; + } + + public String getRoleIds() { + return roleIds; + } + + public void setRoleIds(String roleIds) { + this.roleIds = roleIds; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFileName() { + return fileName; + } + + public void setMapping(String mapping) { + this.mapping = mapping; + } + + public String getMapping() { + return mapping; + } + + public void setFileAddr(String fileAddr) { + this.fileAddr = fileAddr; + } + + public String getFileAddr() { + return fileAddr; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } + + public String getFileType() { + return fileType; + } + + public void setFileSize(String fileSize) { + this.fileSize = fileSize; + } + + public String getFileSize() { + return fileSize; + } + + public void setIsPublic(String isPublic) { + this.isPublic = isPublic; + } + + public String getIsPublic() { + return isPublic; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("fileId" , getFileId()) + .append("pId" , getpId()) + .append("roleIds" , getRoleIds()) + .append("fileName" , getFileName()) + .append("mapping" , getMapping()) + .append("fileAddr" , getFileAddr()) + .append("fileType" , getFileType()) + .append("fileSize" , getFileSize()) + .append("isPublic" , getIsPublic()) + .append("createBy" , getCreateBy()) + .append("createTime" , getCreateTime()) + .append("updateBy" , getUpdateBy()) + .append("updateTime" , getUpdateTime()) + .toString(); + } +} diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/FileService.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/FileService.java new file mode 100644 index 0000000..f2a0ae3 --- /dev/null +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/FileService.java @@ -0,0 +1,64 @@ +package com.hchyun.system.service; + +import java.util.List; +import java.util.Map; + +import com.hchyun.common.utils.ServerResult; +import com.hchyun.system.entity.File; + +/** + * 文件信息Service接口 + * + * @author hchyun + * @date 2021-02-17 + */ +public interface FileService { + /** + * 查询文件信息 + * + * @param fileId 文件信息ID + * @return 文件信息 + */ + ServerResult selectFileById(Long fileId); + + /** + * 查询文件信息列表 + * + * @param file 文件信息 + * @return 文件信息集合 + */ + ServerResult> selectFileList(File file); + + /** + * 新增文件信息 + * + * @param file 文件信息 + * @return 结果 + */ + ServerResult insertFile(File file); + + /** + * 修改文件信息 + * + * @param file 文件信息 + * @return 结果 + */ + ServerResult updateFile(File file); + + /** + * 批量删除文件信息 + * + * @param fileIds 需要删除的文件信息ID + * @return 结果 + */ + ServerResult deleteFileByIds(Long[] fileIds); + + /** + * 删除文件信息信息 + * + * @param fileId 文件信息ID + * @return 结果 + */ + ServerResult deleteFileById(Long fileId); + +} diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/ISysRoleService.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/ISysRoleService.java index 363a54b..c0daac4 100644 --- a/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/ISysRoleService.java +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/ISysRoleService.java @@ -31,8 +31,9 @@ public interface ISysRoleService * 查询所有角色 * * @return 角色列表 + * @param type */ - public List selectRoleAll(); + public List selectRoleAll(Integer type); /** * 根据用户ID获取角色选择框列表 diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/FileServiceImpl.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/FileServiceImpl.java new file mode 100644 index 0000000..fbbff0b --- /dev/null +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/FileServiceImpl.java @@ -0,0 +1,161 @@ +package com.hchyun.system.service.impl; + +import java.util.List; +import java.util.Map; + +import com.hchyun.common.constant.ReturnConstants; +import com.hchyun.common.utils.SecurityUtils; +import com.hchyun.common.utils.DateUtils; +import com.hchyun.common.utils.SecurityUtils; +import com.hchyun.common.utils.DateUtils; +import com.hchyun.common.utils.ServerResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.hchyun.system.dao.FileDao; +import com.hchyun.system.entity.File; +import com.hchyun.system.service.FileService; + +/** + * 文件信息Service业务层处理 + * + * @author hchyun + * @date 2021-02-17 + */ +@Service +public class FileServiceImpl implements FileService { + private Logger logger = LoggerFactory.getLogger(FileServiceImpl.class); + + @Autowired + private FileDao fileDao; + + /** + * 查询文件信息 + * + * @param fileId 文件信息ID + * @return 文件信息 + */ + @Override + public ServerResult selectFileById(Long fileId) { + try { + File file = fileDao.selectFileById(fileId); + if (file != null){ + return new ServerResult(true,file); + }else { + return new ServerResult(false, ReturnConstants.RESULT_EMPTY); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return new ServerResult(false,ReturnConstants.DB_EX); + } + } + + /** + * 查询文件信息列表 + * + * @param file 文件信息 + * @return 文件信息 + */ + @Override + public ServerResult> selectFileList(File file) { + try { + List fileList = fileDao.selectFileList(file); + if (fileList.size()>0){ + return new ServerResult>(true,fileList); + }else { + return new ServerResult>(false,ReturnConstants.RESULT_EMPTY); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return new ServerResult>(false,ReturnConstants.DB_EX); + } + } + + /** + * 新增文件信息 + * + * @param file 文件信息 + * @return 结果 + */ + @Override + public ServerResult insertFile(File file) { + try { + file.setCreateBy(SecurityUtils.getUserId()); + Integer renewal = fileDao.insertFile(file); + if (renewal >0){ + return new ServerResult(true,renewal); + }else { + return new ServerResult(false,ReturnConstants.SYS_FAILL); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return new ServerResult(false,ReturnConstants.DB_EX); + } + } + + /** + * 修改文件信息 + * + * @param file 文件信息 + * @return 结果 + */ + @Override + public ServerResult updateFile(File file) { + try { + file.setUpdateBy(SecurityUtils.getUserId()); + Integer renewal = fileDao.updateFile(file); + if (renewal >0){ + return new ServerResult(true,renewal); + }else { + return new ServerResult(false,ReturnConstants.SYS_FAILL); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return new ServerResult(false,ReturnConstants.DB_EX); + } + } + + /** + * 批量删除文件信息 + * + * @param fileIds 需要删除的文件信息ID + * @return 结果 + */ + @Override + public ServerResult deleteFileByIds(Long[] fileIds) { + try { + Integer renewal = fileDao.deleteFileByIds(fileIds); + if (renewal >0){ + return new ServerResult(true,renewal); + }else { + return new ServerResult(false,ReturnConstants.SYS_FAILL); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return new ServerResult(false,ReturnConstants.DB_EX); + } + } + + /** + * 删除文件信息信息 + * + * @param fileId 文件信息ID + * @return 结果 + */ + @Override + public ServerResult deleteFileById(Long fileId) { + try { + Integer renewal = fileDao.deleteFileById(fileId); + if (renewal >0){ + return new ServerResult(true,renewal); + }else { + return new ServerResult(false,ReturnConstants.SYS_FAILL); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + return new ServerResult(false,ReturnConstants.DB_EX); + } + } + +} diff --git a/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/SysRoleServiceImpl.java b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/SysRoleServiceImpl.java index ce3dca6..8363abb 100644 --- a/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/SysRoleServiceImpl.java +++ b/hchyun/hchyun-system/src/main/java/com/hchyun/system/service/impl/SysRoleServiceImpl.java @@ -80,11 +80,12 @@ public class SysRoleServiceImpl implements ISysRoleService * 查询所有角色 * * @return 角色列表 + * @param type */ @Override - public List selectRoleAll() + public List selectRoleAll(Integer type) { - return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); + return SpringUtils.getAopProxy(this).selectRoleList(new SysRole(type)); } /** diff --git a/hchyun/hchyun-system/src/main/resources/mapper/system/FileMapper.xml b/hchyun/hchyun-system/src/main/resources/mapper/system/FileMapper.xml new file mode 100644 index 0000000..8826717 --- /dev/null +++ b/hchyun/hchyun-system/src/main/resources/mapper/system/FileMapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + select file_id, p_id, role_ids, file_name, mapping, file_addr, file_type, file_size, is_public, create_by, create_time, update_by, update_time from sys_file + + + + + + + + insert into sys_file + + p_id, + role_ids, + file_name, + mapping, + file_addr, + file_type, + file_size, + is_public, + create_by, + update_by, + + + #{pId}, + #{roleIds}, + #{fileName}, + #{mapping}, + #{fileAddr}, + #{fileType}, + #{fileSize}, + #{isPublic}, + #{createBy}, + #{updateBy}, + + + + + update sys_file + + p_id = #{pId}, + role_ids = #{roleIds}, + is_public = #{isPublic}, + update_by = #{updateBy}, + + where file_id = #{fileId} + + + + delete from sys_file where file_id = #{fileId} + + + + delete from sys_file where file_id in + + #{fileId} + + + + \ No newline at end of file diff --git a/hchyun/hchyun-system/src/main/resources/mapper/system/SysRoleMapper.xml b/hchyun/hchyun-system/src/main/resources/mapper/system/SysRoleMapper.xml index 2dbbc6b..7269b3e 100644 --- a/hchyun/hchyun-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/hchyun/hchyun-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -19,11 +19,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly, - r.status, r.del_flag, r.create_time, r.remark + r.status, r.del_flag, r.create_time, r.remark ,r.role_type from sys_role r left join sys_user_role ur on ur.role_id = r.role_id left join sys_user u on u.user_id = ur.user_id @@ -33,6 +34,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"