| | |
| | | import com.nanometer.smartlab.entity.enumtype.SeeFlag; |
| | | import com.nanometer.smartlab.entity.enumtype.ValidFlag; |
| | | import com.nanometer.smartlab.entity.enumtype.Waster; |
| | | import com.nanometer.smartlab.realm.ShiroDbRealm; |
| | | import com.nanometer.smartlab.service.BaseMetaService; |
| | | import com.nanometer.smartlab.service.BaseRoleService; |
| | | import com.nanometer.smartlab.service.SysProjectService; |
| | | import com.nanometer.smartlab.service.SysUserService; |
| | | import com.nanometer.smartlab.util.Constants; |
| | | import com.nanometer.smartlab.util.FacesUtils; |
| | | import com.nanometer.smartlab.util.IDUtils; |
| | | import com.nanometer.smartlab.util.MD5Utils; |
| | | import com.nanometer.smartlab.util.*; |
| | | import org.apache.log4j.Logger; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | |
| | | 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; |
| | |
| | | @Resource |
| | | private SysProjectService sysProjectService; |
| | | |
| | | @Value("${personImgPath}") |
| | | private String personImgPath; |
| | | |
| | | private LazyDataModel<SysUser> dataModel; |
| | | private SysUser sysUser; |
| | | private List<SysUser> selectedList; |
| | |
| | | private List<BaseMeta> codeList; |
| | | private List<BaseRole> roleList; |
| | | private List<Waster> wasterSelectList; |
| | | private String project; |
| | | private String company; |
| | | private BaseRole role; |
| | | |
| | | public List<BaseRole> getRoleList() { |
| | | return roleList; |
| | |
| | | |
| | | public void onNewBtnClick() { |
| | | this.sysUser = new SysUser(); |
| | | if (this.selectedList.size() > 1) { |
| | | FacesUtils.warn("不能多选"); |
| | | return; |
| | | } |
| | | if (this.selectedList.size() == 1) { |
| | | this.sysUser = this.sysUserService.getSysUser(this.selectedList.get(0).getId()); |
| | | this.sysUser.setId(null); |
| | | } |
| | | this.action = Constants.ACTION_ADD; |
| | | } |
| | | |
| | |
| | | int totalRows = sheet.getPhysicalNumberOfRows(); |
| | | List<SysUser> userList=new ArrayList<>(); |
| | | System.out.println("totalRows=========="+totalRows); |
| | | String errorMsg = null; |
| | | String errorMsg = ""; |
| | | |
| | | for (int i = 1; i < totalRows; i++) { |
| | | row=sheet.getRow(i); |
| | |
| | | } |
| | | valuesList.add(id); |
| | | }else if(t==6){ |
| | | cellInfo=new BigDecimal(""+cellInfo).toString(); |
| | | valuesList.add(cellInfo); |
| | | if (!StringUtils.isEmpty(cellInfo)){ |
| | | cellInfo=new BigDecimal(""+cellInfo).toString(); |
| | | valuesList.add(cellInfo); |
| | | }else{ |
| | | valuesList.add(cellInfo); |
| | | } |
| | | } |
| | | else { |
| | | valuesList.add(cellInfo); |
| | | } |
| | | |
| | | } |
| | | System.out.println("size : "+valuesList.size()); |
| | | System.out.println("value : "+valuesList); |
| | | |
| | | SysUser sysUser=new SysUser(); |
| | | sysUser.setCompany(valuesList.get(0));//单位 |
| | | sysUser.setDepartment(valuesList.get(1));//部门 |
| | | sysUser.setArp((int)Double.parseDouble(valuesList.get(2))+"");//arp号 |
| | | sysUser.setName(valuesList.get(3));//姓名 |
| | | sysUser.setAccount(valuesList.get(4));//账号 |
| | | |
| | | String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}"; |
| | | if (!valuesList.get(5).matches(PW_PATTERN)){ |
| | | errorMsg += "第"+i+"行,密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上"; |
| | | if (valuesList.get(0) != null && !StringUtils.isEmpty(valuesList.get(0))){ |
| | | sysUser.setCompany(valuesList.get(0));//单位 |
| | | }else { |
| | | errorMsg += "第"+i+"行,单位不能为空"; |
| | | continue; |
| | | } |
| | | |
| | | sysUser.setPassword(MD5Utils.encode(valuesList.get(5))+"");//密码 |
| | | if (valuesList.get(1) != null && !StringUtils.isEmpty(valuesList.get(1))){ |
| | | sysUser.setDepartment(valuesList.get(1));//部门 |
| | | }else { |
| | | errorMsg += "第"+i+"行,部门不能为空"; |
| | | continue; |
| | | } |
| | | if (valuesList.get(2) != null && !StringUtils.isEmpty(valuesList.get(2))){ |
| | | sysUser.setArp((int)Double.parseDouble(valuesList.get(2))+"");//arp号 |
| | | }else { |
| | | errorMsg += "第"+i+"行,arp不能为空"; |
| | | continue; |
| | | } |
| | | if (valuesList.get(3) != null && !StringUtils.isEmpty(valuesList.get(3))){ |
| | | sysUser.setName(valuesList.get(3));//姓名 |
| | | }else { |
| | | errorMsg += "第"+i+"行,姓名不能为空"; |
| | | continue; |
| | | } |
| | | if (valuesList.get(4) != null && !StringUtils.isEmpty(valuesList.get(4))){ |
| | | sysUser.setAccount(valuesList.get(4));//账号 |
| | | }else { |
| | | errorMsg += "第"+i+"行,账号不能为空"; |
| | | continue; |
| | | } |
| | | if (valuesList.get(5) != null && !StringUtils.isEmpty(valuesList.get(5))){ |
| | | String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}"; |
| | | if (!valuesList.get(5).matches(PW_PATTERN)){ |
| | | errorMsg += "第"+i+"行,密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上"; |
| | | continue; |
| | | } |
| | | sysUser.setPassword(MD5Utils.encode(valuesList.get(5))+"");//密码 |
| | | }else { |
| | | errorMsg += "第"+i+"行,密码不能为空"; |
| | | continue; |
| | | } |
| | | |
| | | //valuesList.get(8) id卡号检查 |
| | | if (valuesList.get(8) != null && valuesList.get(8).length()>0){ |
| | |
| | | //8位补齐20位,否则不做操作 |
| | | String idCard = "E0E01E000A" + idCardUpper + "01"; |
| | | sysUser.setIdCard(idCard);//id卡号 |
| | | }else { |
| | | sysUser.setIdCard(idCardUpper);//id卡号 |
| | | } |
| | | }else{ |
| | | FacesUtils.warn("第"+i+"行,id卡号需要8位或者20位"); |
| | | return; |
| | | errorMsg += ("第"+i+"行,id卡号需要8位或者20位"); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // 检查ARP号 |
| | | if (this.sysUserService.isSysUserExist(sysUser.getArp(), null, null, null)) { |
| | | errorMsg += ("第"+i+"行,ARP已存在"); |
| | | continue; |
| | | } |
| | | // 检查登陆账号 |
| | | if (this.sysUserService.isSysUserExist(null, sysUser.getAccount(), null, null)) { |
| | | errorMsg += ("第"+i+"行,登陆账号已存在"); |
| | | continue; |
| | | } |
| | | if (!StringUtils.isEmpty(sysUser.getIdCard()) && this.sysUserService.isSysUserExist(null, null, sysUser.getIdCard(), null)) { |
| | | errorMsg += ("第"+i+"行,ID卡号已存在"); |
| | | continue; |
| | | } |
| | | sysUser.setPhone(valuesList.get(6));//电话 |
| | | sysUser.setEmail(valuesList.get(7));//邮箱 |
| | | sysUser.setPoint((int)Double.parseDouble(valuesList.get(9)));//分数 |
| | | sysUser.setRoleId(valuesList.get(10));//角色 |
| | | if (valuesList.get(9) != null){ |
| | | sysUser.setPoint((int)Double.parseDouble(valuesList.get(9)));//分数 |
| | | }else { |
| | | errorMsg += "第"+i+"行,分数不能为空"; |
| | | continue; |
| | | } |
| | | if (valuesList.get(10) != null){ |
| | | sysUser.setRoleId(valuesList.get(10));//角色 |
| | | }else { |
| | | errorMsg += "第"+i+"行,角色不能为空"; |
| | | continue; |
| | | } |
| | | if (valuesList.get(12) == null){ |
| | | errorMsg += "第"+i+"行,可见度不能为空"; |
| | | continue; |
| | | } |
| | | if(valuesList.get(11).equals("是")){ |
| | | sysUser.setApproverFlag(ApproverFlag.YES); |
| | | }else { |
| | |
| | | sysUser.setSeeFlag(SeeFlag.LEADING); |
| | | } |
| | | |
| | | |
| | | if (valuesList.size() > 13 && !valuesList.get(13).replace(" ","").isEmpty()){ |
| | | String[] projects = valuesList.get(13).split(","); |
| | | for (String project : projects) { |
| | | //不存再就直接推出 |
| | | if (!sysProjectService.isExistProject(project)) { |
| | | throw new Exception("课题组不存在,(" + i + "行)"); |
| | | errorMsg += ("课题组不存在,(" + i + "行)"); |
| | | continue; |
| | | } |
| | | } |
| | | //都存在就设置 |
| | |
| | | sysUser.setValidFlag(ValidFlag.VALID); |
| | | userList.add(sysUser); |
| | | } |
| | | if (errorMsg != null){ |
| | | FacesUtils.warn(errorMsg); |
| | | } |
| | | |
| | | this.sysUserService.insertSysUserList(userList); |
| | | System.out.println("=========导入结束====="); |
| | | FacesUtils.info("导入成功。"); |
| | | if (errorMsg != null && !StringUtils.isEmpty(errorMsg)){ |
| | | FacesUtils.warn(errorMsg); |
| | | }else { |
| | | FacesUtils.info("导入成功。"); |
| | | } |
| | | }catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | FacesUtils.info("导入失败。"); |
| | |
| | | return; |
| | | } |
| | | |
| | | // 检查ARP号 |
| | | if (this.sysUserService.isSysUserExist(this.sysUser.getArp(), null, null, this.sysUser.getId())) { |
| | | // 检查ARP号 //除自己外的arp |
| | | // if (this.sysUserService.isSysUserExist(this.sysUser.getArp(), null, null, this.sysUser.getId())) { |
| | | // FacesUtils.warn("ARP已存在。"); |
| | | // return; |
| | | // } |
| | | List<SysUser> list = sysUserService.getUserByArp(this.sysUser.getArp()); |
| | | assert list.size() < 2; |
| | | if (list.size() > 0 && !list.get(0).getId().equals(this.sysUser.getId())) { |
| | | FacesUtils.warn("ARP已存在。"); |
| | | return; |
| | | } |
| | |
| | | if(sysUser.getPassword()==null || sysUser.getPassword().equals("")){ |
| | | sysUser.setPassword(this.editPasswor); |
| | | }else { |
| | | String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}"; |
| | | if (!sysUser.getPassword().matches(PW_PATTERN)){ |
| | | FacesUtils.warn("密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上"); |
| | | return; |
| | | } |
| | | sysUser.setPassword(MD5Utils.encode(sysUser.getPassword())); |
| | | } |
| | | this.sysUserService.updateSysUser(sysUser); |
| | | ShiroDbRealm shiroDbRealm= SpringUtil.getBean("authorizationRealm",ShiroDbRealm.class); |
| | | shiroDbRealm.removeUserCache(sysUser.getAccount()); |
| | | |
| | | FacesUtils.info("修改成功。"); |
| | | RequestContext.getCurrentInstance().execute("PF('dialog').hide()"); |
| | |
| | | } |
| | | } |
| | | |
| | | // 文件上传 |
| | | 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()); |
| | | role = baseRoleService.getRoleByUserId(sysUser.getId()); |
| | | } |
| | | public boolean isAccess(String info) { |
| | | String permission = role.getBtnPermission(); |
| | | if(StringUtils.isEmpty(permission)){ |
| | | return true; |
| | | }else{ |
| | | return permission.contains(info); |
| | | } |
| | | } |
| | | |
| | | public LazyDataModel<SysUser> getDataModel() { |
| | | if (this.dataModel == null) { |
| | | this.dataModel = new LazyDataModel<SysUser>() { |
| | |
| | | public List<SysUser> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { |
| | | List<SysUser> list = null; |
| | | try { |
| | | int count = sysUserService.getSysUserTotalCount(arp, name,departmentName); |
| | | this.setRowCount(count); |
| | | if (count > 0) { |
| | | list = sysUserService.getSysUserList(arp, name,departmentName, first, pageSize); |
| | | //做可见人员过滤 |
| | | String userPermission = role.getUserPermission(); |
| | | userPermission="11"; |
| | | if (userPermission.contains("自己")) { |
| | | list = Collections.singletonList(sysUserService.getSysUser(UserMngController.this.sysUser.getId())); |
| | | this.setRowCount(1); |
| | | |
| | | }else if (userPermission.contains("课题组")){ |
| | | project = sysUser.getProject(); |
| | | int count = sysUserService.getUserCountInProject(arp, name,departmentName,project,company); |
| | | this.setRowCount(count); |
| | | if (count > 0) { |
| | | list = sysUserService.getUserInProject(arp, name,departmentName,project,company, first, pageSize); |
| | | } |
| | | |
| | | }else{ |
| | | int count = sysUserService.getSysUserTotalCount(arp, name,departmentName,project,company); |
| | | this.setRowCount(count); |
| | | if (count > 0) { |
| | | list = sysUserService.getSysUserList(arp, name,departmentName,project,company, first, pageSize); |
| | | } |
| | | } |
| | | |
| | | selectedList = new ArrayList<>(); |
| | | } catch (Exception e) { |
| | | logger.error(e); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public SysUser getRowData(String rowKey) { |
| | | Iterator<SysUser> iterator = this.iterator(); |
| | | if (iterator != null) { |
| | | SysUser su = null; |
| | | while (iterator.hasNext()) { |
| | | su = iterator.next(); |
| | | if (rowKey.equals(su.getId())) { |
| | | return su; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | // Iterator<SysUser> iterator = this.iterator(); |
| | | // if (iterator != null) { |
| | | // SysUser su = null; |
| | | // while (iterator.hasNext()) { |
| | | // su = iterator.next(); |
| | | // if (rowKey.equals(su.getId())) { |
| | | // return su; |
| | | // } |
| | | // } |
| | | // } |
| | | return sysUserService.getSysUser(rowKey); |
| | | } |
| | | }; |
| | | } |
| | | return dataModel; |
| | | } |
| | | |
| | | public void exportLab2Excel(){ |
| | | try { |
| | | List<Map> list = sysUserService.getExportUserList(arp, name,departmentName,project,company); |
| | | sysUserService.exportUser2Excel(list); |
| | | FacesUtils.info("导出成功"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | FacesUtils.warn("导出失败"); |
| | | } |
| | | } |
| | | |
| | | public SysUser getSysUser() { |
| | |
| | | public void setDepartmentName(String departmentName) { |
| | | this.departmentName = departmentName; |
| | | } |
| | | |
| | | public String getProject() { |
| | | return project; |
| | | } |
| | | |
| | | public void setProject(String project) { |
| | | this.project = project; |
| | | } |
| | | |
| | | public String getCompany() { |
| | | return company; |
| | | } |
| | | |
| | | public void setCompany(String company) { |
| | | this.company = company; |
| | | } |
| | | } |