Search in sources :

Example 11 with Admin

use of com.itrus.portal.db.Admin in project portal by ixinportal.

the class AdminController method list.

// 列表所有信息
@RequestMapping(produces = "text/html")
public String list(@Valid Admin admin, @RequestParam(value = "project", required = false) Long project, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    uiModel.addAttribute("project", project);
    uiModel.addAttribute("adminRole", admin.getAdminRole());
    uiModel.addAttribute("status", admin.getStatus());
    uiModel.addAttribute("account", admin.getAccount());
    uiModel.addAttribute("name", admin.getName());
    // page,size
    if (page == null || page < 1)
        page = 1;
    if (size == null || size < 1)
        size = 10;
    AdminExample adminex = new AdminExample();
    AdminExample.Criteria criteria = adminex.or();
    if (project != null && project > 0)
        criteria.andProjectEqualTo(project);
    if (admin.getAdminRole() != null && admin.getAdminRole() > 0) {
        criteria.andAdminRoleEqualTo(admin.getAdminRole());
    }
    if (admin.getStatus() != null && admin.getStatus().length() > 0)
        criteria.andStatusEqualTo(admin.getStatus());
    if (admin.getAccount() != null && admin.getAccount().length() > 0)
        criteria.andAccountLike("%" + admin.getAccount() + "%");
    if (admin.getName() != null && admin.getName().length() > 0)
        criteria.andNameLike("%" + admin.getName() + "%");
    // count,pages
    Integer count = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.countByExample", adminex);
    uiModel.addAttribute("count", count);
    uiModel.addAttribute("pages", (count + size - 1) / size);
    // page, size
    if (page > 1 && size * (page - 1) >= count) {
        page = (count + size - 1) / size;
    }
    uiModel.addAttribute("page", page);
    uiModel.addAttribute("size", size);
    // query data
    Integer offset = size * (page - 1);
    adminex.setOffset(offset);
    adminex.setLimit(size);
    List<Admin> adminall = sqlSession.selectList("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
    List<Admin> adminList = new ArrayList<Admin>();
    boolean flag = false;
    for (Admin admini : adminall) {
        if (admini.getProjects().contains(",")) {
            String[] strs = admini.getProjects().split(",");
            for (String s : strs) {
                if (s.equals("0")) {
                    // 包含所有项目
                    flag = true;
                    break;
                } else {
                    flag = false;
                }
            }
        }
        String projectName = getProjectNameByAdminId(admini.getId());
        admini.setProjects(projectName);
        if (flag)
            admini.setProjects("所有项目");
        adminList.add(admini);
        flag = false;
    }
    uiModel.addAttribute("admins", adminList);
    // itemcount
    uiModel.addAttribute("itemcount", adminall.size());
    Map<Long, Admin> adminmap = sqlSession.selectMap("com.itrus.portal.db.AdminMapper.selectByExample", adminex, "id");
    for (Long adminid : adminmap.keySet()) adminmap.get(adminid).setPassword(null);
    uiModel.addAttribute("adminmap", adminmap);
    ProjectExample projectex = new ProjectExample();
    Map projectmap = sqlSession.selectMap("com.itrus.portal.db.ProjectMapper.selectByExample", projectex, "id");
    uiModel.addAttribute("projectmap", projectmap);
    List projects = sqlSession.selectList("com.itrus.portal.db.ProjectMapper.selectByExample", projectex);
    uiModel.addAttribute("projects", projects);
    Map adminroles = sqlSession.selectMap("com.itrus.portal.db.AdminRoleMapper.selectByExample", "id");
    uiModel.addAttribute("adminroles", adminroles);
    return "admins/list";
}
Also used : ProjectExample(com.itrus.portal.db.ProjectExample) ArrayList(java.util.ArrayList) Admin(com.itrus.portal.db.Admin) ArrayList(java.util.ArrayList) List(java.util.List) AdminExample(com.itrus.portal.db.AdminExample) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Admin

use of com.itrus.portal.db.Admin in project portal by ixinportal.

the class AdminController method delete.

// 删除
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, HttpServletRequest request, Model uiModel) {
    Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByPrimaryKey", id);
    String retPath = getReferer(request, "redirect:/admins", true);
    if (admin == null) {
        uiModel.addAttribute("message", "未找到要删除管理员");
    } else {
        try {
            sqlSession.delete("com.itrus.portal.db.AdminMapper.deleteByPrimaryKey", id);
            String oper = "删除管理员";
            String info = "管理员账号: " + admin.getAccount();
            LogUtil.adminlog(sqlSession, oper, info);
        } catch (Exception e) {
            uiModel.addAttribute("message", "要删除管理员【" + admin.getName() + "】存在关联,无法删除");
        }
    }
    return retPath;
}
Also used : Admin(com.itrus.portal.db.Admin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Admin

use of com.itrus.portal.db.Admin in project portal by ixinportal.

the class AdminPinController method modify.

// 修改处理
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String modify(AdminPinModify adminpinmodify, Model uiModel) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    String adminName = securityContext.getAuthentication().getName();
    // 新口令和确认口令不能为空
    if (adminpinmodify.getNewpass() == null || adminpinmodify.getNewpass1() == null) {
        uiModel.addAttribute("errormsg", "新口令和确认口令不能为空");
        String oper = "修改口令失败";
        String info = "修改口令失败,管理员账号: " + adminName + ",新口令和确认口令不能为空";
        LogUtil.adminlog(sqlSession, oper, info);
        return "adminpin/modifyerror";
    }
    // 验证新口令和确认口令是否相同
    if (adminpinmodify.getNewpass().compareTo(adminpinmodify.getNewpass1()) != 0l) {
        uiModel.addAttribute("errormsg", "新口令和确认口令不一致");
        String oper = "修改口令失败";
        String info = "修改口令失败,管理员账号: " + adminName + ",新口令和确认口令不一致";
        LogUtil.adminlog(sqlSession, oper, info);
        return "adminpin/modifyerror";
    }
    // 查询管理员信息
    AdminExample adminex = new AdminExample();
    adminex.or().andAccountEqualTo(adminName);
    Admin admin0 = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
    // 验证员口令是否匹配
    String oldpass0 = admin0.getPassword();
    if (oldpass0 != null && oldpass0.length() != 40) {
        // 原口令为非加密口令
        if (oldpass0.compareTo(adminpinmodify.getOldpass()) != 0) {
            uiModel.addAttribute("errormsg", "旧口令不正确");
            String oper = "修改口令失败";
            String info = "修改口令失败,管理员账号: " + adminName + ",旧口令不正确";
            LogUtil.adminlog(sqlSession, oper, info);
            return "adminpin/modifyerror";
        }
    } else if (oldpass0 != null && oldpass0.length() == 40) {
        // 原口令为加密口令
        // String oldpasssha =  new String(PassUtil.doDigestSHA1(adminpinmodify.getOldpass(), adminName));
        String oldpasssha = passwordEncoder.encodePassword(adminpinmodify.getOldpass(), adminName);
        if (oldpass0.compareTo(oldpasssha) != 0) {
            uiModel.addAttribute("errormsg", "旧口令不正确");
            String oper = "修改口令失败";
            String info = "修改口令失败,管理员账号: " + adminName + ",旧口令不正确";
            LogUtil.adminlog(sqlSession, oper, info);
            return "adminpin/modifyerror";
        }
    }
    // 修改口令
    // String newpasssha =  new String(PassUtil.doDigestSHA1(adminpinmodify.getNewpass(), adminName));
    String newpasssha = passwordEncoder.encodePassword(adminpinmodify.getNewpass(), adminName);
    admin0.setPassword(newpasssha);
    sqlSession.update("com.itrus.portal.db.AdminMapper.updateByPrimaryKey", admin0);
    String oper = "修改口令";
    String info = "修改口令,管理员账号: " + admin0.getAccount();
    LogUtil.adminlog(sqlSession, oper, info);
    return "adminpin/modifyok";
}
Also used : SecurityContext(org.springframework.security.core.context.SecurityContext) Admin(com.itrus.portal.db.Admin) AdminExample(com.itrus.portal.db.AdminExample) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Admin

use of com.itrus.portal.db.Admin in project portal by ixinportal.

the class AdminServiceImpl method getAdminByName.

/**
 * 根据用户名查询帐号
 *
 * @param adminName
 * @return
 */
public Admin getAdminByName(String adminName) {
    AdminExample adminExample = new AdminExample();
    AdminExample.Criteria criteria = adminExample.or();
    criteria.andAccountEqualTo(adminName);
    adminExample.setLimit(1);
    Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminExample);
    return admin;
}
Also used : Admin(com.itrus.portal.db.Admin) AdminExample(com.itrus.portal.db.AdminExample)

Example 15 with Admin

use of com.itrus.portal.db.Admin in project portal by ixinportal.

the class AdminServiceImpl method getProjectByAdminId.

/**
 * 根据管理员id获取管理的项目list
 *
 * @param adminId
 * @return
 */
public List<Project> getProjectByAdminId(Long adminId) {
    List<Project> projects = new ArrayList<Project>();
    Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByPrimaryKey", adminId);
    if (null != projects && StringUtils.isNotBlank(admin.getProjects())) {
        String[] projectIds = admin.getProjects().split(",");
        Long[] projectIdsLong = new Long[projectIds.length];
        for (int i = 0; i < projectIds.length; i++) {
            if ("0".equals(projectIds[i])) {
                // 返回所有项目id
                List<Long> allProject = sqlSession.selectList("com.itrus.portal.db.ProjectMapper.selectAllProjectIds");
                projectIdsLong = new Long[allProject.size()];
                for (int j = 0; j < allProject.size(); j++) {
                    projectIdsLong[j] = allProject.get(j);
                }
                break;
            }
            projectIdsLong[i] = Long.parseLong(projectIds[i]);
        }
        ProjectExample projectExample = new ProjectExample();
        ProjectExample.Criteria criteria = projectExample.or();
        criteria.andIdIn(Arrays.asList(projectIdsLong));
        projects = sqlSession.selectList("com.itrus.portal.db.ProjectMapper.selectByExample", projectExample);
    }
    return projects;
}
Also used : Project(com.itrus.portal.db.Project) ProjectExample(com.itrus.portal.db.ProjectExample) ArrayList(java.util.ArrayList) Admin(com.itrus.portal.db.Admin)

Aggregations

Admin (com.itrus.portal.db.Admin)16 AdminExample (com.itrus.portal.db.AdminExample)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 Project (com.itrus.portal.db.Project)4 ProjectExample (com.itrus.portal.db.ProjectExample)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 SecurityContext (org.springframework.security.core.context.SecurityContext)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 AdminRole (com.itrus.portal.db.AdminRole)2 List (java.util.List)2 Map (java.util.Map)2 AdminLog (com.itrus.portal.db.AdminLog)1 AdminLogExample (com.itrus.portal.db.AdminLogExample)1 AdminRoleExample (com.itrus.portal.db.AdminRoleExample)1 Agent (com.itrus.portal.db.Agent)1 BusinessLicense (com.itrus.portal.db.BusinessLicense)1 Certification (com.itrus.portal.db.Certification)1 DigitalCert (com.itrus.portal.db.DigitalCert)1 Enterprise (com.itrus.portal.db.Enterprise)1