| | |
| | | import org.primefaces.model.LazyDataModel; |
| | | import org.primefaces.model.SortOrder; |
| | | import org.primefaces.model.UploadedFile; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Scope; |
| | | import org.springframework.stereotype.Controller; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.math.BigDecimal; |
| | | import java.nio.charset.CharacterCodingException; |
| | | import java.security.NoSuchAlgorithmException; |
| | |
| | | private BaseRoleService baseRoleService; |
| | | @Resource |
| | | private SysProjectService sysProjectService; |
| | | |
| | | @Value("${personImgPath}") |
| | | private String personImgPath; |
| | | |
| | | private LazyDataModel<SysUser> dataModel; |
| | | private SysUser sysUser; |
| | |
| | | } |
| | | } |
| | | |
| | | // 文件上传 |
| | | public void handleImageUpload(FileUploadEvent event) { |
| | | UploadedFile file = event.getFile(); |
| | | try { |
| | | // 1.上传文件 |
| | | InputStream is = file.getInputstream(); |
| | | String oldName = file.getFileName(); |
| | | String newName = new Date().getTime() + oldName.substring(oldName.lastIndexOf(".")); |
| | | String realPath = personImgPath; |
| | | File dest = new File(realPath, newName); |
| | | if (!dest.getParentFile().exists()) { |
| | | boolean rel = dest.getParentFile().mkdirs(); |
| | | if (!rel) { |
| | | throw new Exception("文件夹创建失败"); |
| | | } |
| | | } |
| | | |
| | | OutputStream os = new FileOutputStream(dest); |
| | | try { |
| | | byte[] buffer = new byte[8 * 1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = is.read(buffer)) != -1) { |
| | | os.write(buffer, 0, bytesRead); |
| | | } |
| | | // 更新用户url |
| | | sysUser.setUrl("upload/upload/" + newName); |
| | | // 清空图片文件以便再次上传 |
| | | RequestContext.getCurrentInstance().update("dialogForm2"); |
| | | // 更新用户表单 |
| | | RequestContext.getCurrentInstance().update("dialogForm"); |
| | | // 隐藏上传框 |
| | | RequestContext.getCurrentInstance().execute("PF('imgDialog').hide()"); |
| | | |
| | | } catch (Exception e) { |
| | | FacesUtils.warn("文件上传失败。"); |
| | | throw e; |
| | | } finally { |
| | | if (is != null) { |
| | | is.close(); |
| | | } |
| | | if (os != null) { |
| | | os.close(); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | FacesUtils.warn("操作失败。"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | public void initPage() { |
| | | sysUser = sysUserService.getSysUser(getUser().getId()); |
| | |
| | | } |
| | | public boolean isAccess(String info) { |
| | | String permission = role.getBtnPermission(); |
| | | return permission.contains(info); |
| | | if(StringUtils.isEmpty(permission)){ |
| | | return true; |
| | | }else{ |
| | | return permission.contains(info); |
| | | } |
| | | } |
| | | |
| | | public LazyDataModel<SysUser> getDataModel() { |
| | |
| | | try { |
| | | //做可见人员过滤 |
| | | String userPermission = role.getUserPermission(); |
| | | userPermission="11"; |
| | | if (userPermission.contains("自己")) { |
| | | list = Collections.singletonList(sysUserService.getSysUser(UserMngController.this.sysUser.getId())); |
| | | this.setRowCount(1); |