Search in sources :

Example 1 with PmphDepartment

use of com.bc.pmpheep.back.po.PmphDepartment in project pmph by BCSquad.

the class PmphUserServiceImpl method getListByUsernameAndRealname.

@Override
public PageResult<PmphUserManagerVO> getListByUsernameAndRealname(String name, int number, int size) throws CheckedServiceException {
    if (null == name || "".equals(name)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "模糊查询条件为空");
    }
    List<PmphUser> pmphUsers = pmphUserDao.getListByUsernameAndRealname(name, (number - 1) * size, size);
    PageResult<PmphUserManagerVO> page = new PageResult<>();
    page.setFirst(true);
    page.setLast(true);
    page.setPageNumber(number);
    page.setPageSize(size);
    if (!pmphUsers.isEmpty()) {
        List<PmphUserManagerVO> list = new ArrayList<>();
        for (PmphUser user : pmphUsers) {
            PmphUserManagerVO userVO = new PmphUserManagerVO();
            PmphDepartment department = pmphDepartmentDao.getPmphDepartmentById(user.getDepartmentId());
            if (null != department) {
                userVO.setDepartmentName(department.getDpName());
            }
            try {
                BeanUtils.copyProperties(userVO, user);
            } catch (BeansException ex) {
                throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.VO_CONVERSION_FAILED, ex.getMessage());
            }
            list.add(userVO);
        }
        page.setRows(list);
    }
    return page;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageResult(com.bc.pmpheep.back.plugin.PageResult) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment) BeansException(org.springframework.beans.BeansException)

Example 2 with PmphDepartment

use of com.bc.pmpheep.back.po.PmphDepartment in project pmph by BCSquad.

the class AddTestUser method addTestUser.

public void addTestUser() {
    String pmphUserData = "[" + "{'username':'yewutest01','realname':'业务测试账号A','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest02','realname':'业务测试账号B','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'系统管理员'},{'roleName':'项目编辑'}]}," + "{'username':'yewutest03','realname':'业务测试账号C','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest04','realname':'业务测试账号D','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest05','realname':'业务测试账号E','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest06','realname':'业务测试账号F','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest07','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest08','realname':'业务测试账号H','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[]}," + "{'username':'yewutest09','realname':'业务测试账号I','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'}]}," + "{'username':'yewutest10','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'},{'roleName':'其他用户'}]}" + "]";
    Gson gson = new Gson();
    List<TestPmphUserBo> testPmphUsers = gson.fromJson(pmphUserData, new TypeToken<ArrayList<TestPmphUserBo>>() {
    }.getType());
    for (TestPmphUserBo user : testPmphUsers) {
        PmphDepartment pmphDepartment = pmphDepartmentService.getPmphDepartmentByName(user.getDepartment());
        PmphUser pmphUser = new PmphUser();
        pmphUser.setUsername(user.getUsername());
        pmphUser.setRealname(user.getRealname());
        pmphUser.setPassword(user.getPassword());
        pmphUser.setDepartmentId(pmphDepartment == null ? 0L : pmphDepartment.getId());
        pmphUser.setAvatar(user.getAvatar());
        pmphUser = pmphUserService.add(pmphUser);
        for (PmphRole pmphRole : user.getRoles()) {
            pmphRole = pmphRoleService.getByName(pmphRole.getRoleName());
            PmphUserRole pmphUserRole = new PmphUserRole();
            pmphUserRole.setUserId(pmphUser.getId());
            pmphUserRole.setRoleId(pmphRole == null ? 0L : pmphRole.getId());
            pmphUserRoleService.addPmphUserRole(pmphUserRole);
        }
    }
    String orgData = "[" + "{'orgName':'北京测试学校','orgType':'本科','areaName':'北京市','username':'bjcsxxtest','password':'123456','realname':'北京学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'bjzuojia01','password':'888888','nickname':'北京作家01','realname':'北京作家01'}," + "{'username':'bjzuojia02','password':'888888','nickname':'北京作家02','realname':'北京作家02'}," + "{'username':'bjzuojia03','password':'888888','nickname':'北京作家03','realname':'北京作家03'}," + "{'username':'bjzuojia04','password':'888888','nickname':'北京作家04','realname':'北京作家04'}," + "{'username':'bjzuojia05','password':'888888','nickname':'北京作家05','realname':'北京作家05'}," + "{'username':'bjzuojia06','password':'888888','nickname':'北京作家06','realname':'北京作家06'}," + "{'username':'bjzuojia07','password':'888888','nickname':'北京作家07','realname':'北京作家07'}," + "{'username':'bjzuojia08','password':'888888','nickname':'北京作家08','realname':'北京作家08'}," + "{'username':'bjzuojia09','password':'888888','nickname':'北京作家09','realname':'北京作家09'}," + "{'username':'bjzuojia10','password':'888888','nickname':'北京作家10','realname':'北京作家10'}," + "{'username':'bjzuojia11','password':'888888','nickname':'北京作家11','realname':'北京作家11'}" + "]" + "}," + "{'orgName':'天津测试学校','orgType':'本科','areaName':'天津市','username':'tjcsxxtest','password':'123456','realname':'天津学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'tjzuojia01','password':'888888','nickname':'天津作家01','realname':'天津作家01'}," + "{'username':'tjzuojia02','password':'888888','nickname':'天津作家02','realname':'天津作家02'}," + "{'username':'tjzuojia03','password':'888888','nickname':'天津作家03','realname':'天津作家03'}," + "{'username':'tjzuojia04','password':'888888','nickname':'天津作家04','realname':'天津作家04'}," + "{'username':'tjzuojia05','password':'888888','nickname':'天津作家05','realname':'天津作家05'}," + "{'username':'tjzuojia06','password':'888888','nickname':'天津作家06','realname':'天津作家06'}," + "{'username':'tjzuojia07','password':'888888','nickname':'天津作家07','realname':'天津作家07'}," + "{'username':'tjzuojia08','password':'888888','nickname':'天津作家08','realname':'天津作家08'}," + "{'username':'tjzuojia09','password':'888888','nickname':'天津作家09','realname':'天津作家09'}," + "{'username':'tjzuojia10','password':'888888','nickname':'天津作家10','realname':'天津作家10'}," + "{'username':'tjzuojia11','password':'888888','nickname':'天津作家11','realname':'天津作家11'}" + "]" + "}" + "]";
    List<TestOrgBo> orgBos = gson.fromJson(orgData, new TypeToken<ArrayList<TestOrgBo>>() {
    }.getType());
    for (TestOrgBo testOrgBo : orgBos) {
        Org org = new Org();
        org.setParentId(0L);
        org.setOrgName(testOrgBo.getOrgName());
        org.setOrgTypeId(orgTypeService.listOrgTypeByTypeName(testOrgBo.getOrgType()).get(0).getId());
        org.setAreaId(areaService.getAreaIdByName(testOrgBo.getAreaName()));
        org = orgService.addOrg(org);
        OrgUser orgUser = new OrgUser();
        orgUser.setUsername(testOrgBo.getUsername());
        orgUser.setPassword(new DesRun("", testOrgBo.getPassword()).enpsw);
        orgUser.setOrgId(org.getId());
        orgUser.setRealname(testOrgBo.getRealname());
        orgUser.setAvatar(testOrgBo.getAreaName());
        orgUser = orgUserService.addOrgUser(orgUser);
        for (WriterUser writerUser : testOrgBo.getWriterUsers()) {
            writerUser.setOrgId(org.getId());
            writerUserService.add(writerUser);
        }
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) Org(com.bc.pmpheep.back.po.Org) OrgUser(com.bc.pmpheep.back.po.OrgUser) Gson(com.google.gson.Gson) PmphRole(com.bc.pmpheep.back.po.PmphRole) TypeToken(com.google.gson.reflect.TypeToken) DesRun(com.bc.pmpheep.back.util.DesRun) WriterUser(com.bc.pmpheep.back.po.WriterUser) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment) PmphUserRole(com.bc.pmpheep.back.po.PmphUserRole)

Example 3 with PmphDepartment

use of com.bc.pmpheep.back.po.PmphDepartment in project pmph by BCSquad.

the class UserMessageServiceImpl method listMessage.

@Override
public PageResult<UserMessageVO> listMessage(PageParameter<UserMessageVO> pageParameter, String sessionId) throws CheckedServiceException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    // 如果是系统管理员,则查询所有,否则查询对应的消息
    if (Const.FALSE == pmphUser.getIsAdmin()) {
        List<Long> ids = new ArrayList<Long>();
        // 如果是主任,获取主任所在部门下的所有用户
        if (Const.TRUE == pmphUser.getIsDirector()) {
            // 社内部门父级节点ID
            Long parentId = 1L;
            PmphDepartment pmphDepartment = pmphDepartmentService.getPmphDepartmentById(pmphUser.getDepartmentId());
            // 如果是人卫社主任,则可以查看所有用户发送的消息
            if (parentId.longValue() == pmphDepartment.getId().longValue()) {
                ids = null;
            } else {
                // 如果是子级部门主任,则只可以查看子级部门下的用户发送的消息
                PageParameter<PmphUserManagerVO> parameter = new PageParameter<>(1, 2000);
                PmphUserManagerVO pmphUserManagerVO = new PmphUserManagerVO();
                pmphUserManagerVO.setPath(pmphDepartment.getPath());
                pmphUserManagerVO.setDepartmentId(pmphDepartment.getId());
                parameter.setParameter(pmphUserManagerVO);
                PageResult<PmphUserManagerVO> listPageResult = pmphUserService.getListPmphUser(parameter, null);
                List<PmphUserManagerVO> listPmphUserManagerVOs = listPageResult.getRows();
                for (PmphUserManagerVO pmManagerVO : listPmphUserManagerVOs) {
                    ids.add(pmManagerVO.getId());
                }
            }
        } else {
            ids.add(pmphUser.getId());
        }
        pageParameter.getParameter().setSenderIds(ids);
    }
    PageResult<UserMessageVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    Integer total = userMessageDao.getMessageTotal(pageParameter);
    if (total > 0) {
        List<UserMessageVO> list = userMessageDao.listMessage(pageParameter);
        Message message;
        for (UserMessageVO userMessageVO : list) {
            message = messageService.get(userMessageVO.getMsgId());
            if (ObjectUtil.notNull(message)) {
                userMessageVO.setContent(message.getContent());
            }
        }
        pageResult.setRows(list);
        pageResult.setTotal(total);
    }
    return pageResult;
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) PageResult(com.bc.pmpheep.back.plugin.PageResult) UserMessageVO(com.bc.pmpheep.back.vo.UserMessageVO) PmphUserManagerVO(com.bc.pmpheep.back.vo.PmphUserManagerVO) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment)

Example 4 with PmphDepartment

use of com.bc.pmpheep.back.po.PmphDepartment in project pmph by BCSquad.

the class MigrationStageThree method pmphDepartment.

protected void pmphDepartment() {
    // 图一此表已添加new_pk
    String tableName = "ba_organize";
    String sql = "SELECT orgid,parentid,orgname,sortno,remark " + "FROM ba_organize WHERE orgcode " + "LIKE '15%' ORDER BY LENGTH(orgcode),orgcode ;";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    List<Map<String, Object>> excel = new LinkedList<>();
    int count = 0;
    for (Map<String, Object> map : maps) {
        String departmentId = (String) map.get("orgid");
        String parentCode = (String) map.get("parentid");
        String dpName = (String) map.get("orgname");
        Integer sort = (Integer) map.get("sortno");
        if (ObjectUtil.notNull(sort) && sort < 0) {
            sort = 999;
        }
        String note = (String) map.get("remark");
        PmphDepartment pmphDepartment = new PmphDepartment();
        if ("人民卫生出版社".equals(dpName)) {
            pmphDepartment.setId(0L);
        }
        Long parentId = 0L;
        // 不为0说明有父节点
        if (!"0".equals(parentCode)) {
            parentId = JdbcHelper.getPrimaryKey(tableName, "orgid", parentCode);
        }
        pmphDepartment.setParentId(parentId);
        // 因为查询结果是排序了的,所以子节点的新id一定在父节点之后才生成
        String path = JdbcHelper.getPath(tableName, "orgid", "parentid", parentCode);
        pmphDepartment.setPath(path);
        pmphDepartment.setDpName(dpName);
        pmphDepartment.setSort(sort);
        pmphDepartment.setNote(note);
        pmphDepartment = pmphDepartmentService.add(pmphDepartment);
        Long pk = pmphDepartment.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "orgid", departmentId);
        count++;
        number = pk;
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "社内部门表", "pmph_department");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    logger.info("pmph_department表数据迁移完成");
    logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "pmph_department表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment)

Example 5 with PmphDepartment

use of com.bc.pmpheep.back.po.PmphDepartment in project pmph by BCSquad.

the class DataTransfer method pmphDepartment.

/**
 * 社内部门表迁移
 */
public int pmphDepartment() {
    String sql = "SELECT a.orgid,a.parentid,a.orgcode,a.orgname,a.sortno,a.remark,a.isdelete,a.orgtype FROM ba_organize a WHERE a.orgcode LIKE '15%' ORDER BY LENGTH(orgcode),orgcode";
    ConnectionManager cm;
    ResultSet rs;
    try {
        cm = new ConnectionManager(url, username, password);
        rs = cm.getResultSet(sql);
    } catch (ClassNotFoundException | SQLException ex) {
        logger.error("JDBC初始化错误", ex);
        return 0;
    }
    int count = 0;
    try {
        while (rs.next()) {
            PmphDepartment pmphDepartment = new PmphDepartment();
            pmphDepartment.setId(Long.valueOf(rs.getString(3).replace("-", "")));
            String[] tree = rs.getString(3).split("-");
            if (tree.length == 1) {
                pmphDepartment.setParentId(0L);
            } else if (tree.length == 2) {
                pmphDepartment.setParentId(Long.valueOf(rs.getString(3).substring(0, rs.getString(3).indexOf("-"))));
            } else {
                pmphDepartment.setParentId(Long.valueOf(rs.getString(3).substring(0, rs.getString(3).length() - 4).replace("-", "")));
            }
            pmphDepartment.setPath(rs.getString(3));
            pmphDepartment.setDpName(rs.getString(4));
            pmphDepartment.setNote(rs.getString(3));
            count++;
            pmphDepartmentService.addPmphDepartment(pmphDepartment);
            logger.info("已经迁移{}条数据", count);
        }
        logger.info("一共迁移了{}条数据", count);
        cm.close();
    } catch (SQLException ex) {
        logger.error("SQL语句执行出错", ex);
        return count;
    }
    return count;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment)

Aggregations

PmphDepartment (com.bc.pmpheep.back.po.PmphDepartment)5 PmphUser (com.bc.pmpheep.back.po.PmphUser)3 PageResult (com.bc.pmpheep.back.plugin.PageResult)2 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 ArrayList (java.util.ArrayList)2 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)1 Org (com.bc.pmpheep.back.po.Org)1 OrgUser (com.bc.pmpheep.back.po.OrgUser)1 PmphRole (com.bc.pmpheep.back.po.PmphRole)1 PmphUserRole (com.bc.pmpheep.back.po.PmphUserRole)1 UserMessage (com.bc.pmpheep.back.po.UserMessage)1 WriterUser (com.bc.pmpheep.back.po.WriterUser)1 DesRun (com.bc.pmpheep.back.util.DesRun)1 PmphUserManagerVO (com.bc.pmpheep.back.vo.PmphUserManagerVO)1 UserMessageVO (com.bc.pmpheep.back.vo.UserMessageVO)1 Message (com.bc.pmpheep.general.po.Message)1 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 IOException (java.io.IOException)1