Search in sources :

Example 1 with WriterUserCertification

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

the class WriterUserCertificationServiceTest method testGetWriterUserCertificationById.

@Test
@Rollback(Const.ISROLLBACK)
public void testGetWriterUserCertificationById() {
    WriterUserCertification writerUserCertification = this.addWriterUserCertification();
    Assert.assertNotNull("获取数据失败", writerUserCertificationService.getWriterUserCertificationById(writerUserCertification.getId()));
}
Also used : WriterUserCertification(com.bc.pmpheep.back.po.WriterUserCertification) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 2 with WriterUserCertification

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

the class WriterUserCertificationServiceImpl method updateWriterUserCertificationProgressByUserId.

@Override
public Integer updateWriterUserCertificationProgressByUserId(Short progress, Long[] userIds, HttpServletRequest request) throws CheckedServiceException, Exception {
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser pmphuser = SessionUtil.getPmphUserBySessionId(sessionId);
    List<WriterUserCertification> writerUserCertifications = this.getWriterUserCertificationByUserIds(userIds);
    if (ObjectUtil.isNull(progress)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "参数为空");
    }
    Integer count = 0;
    List<WriterUserCertification> wUserCertifications = new ArrayList<WriterUserCertification>(writerUserCertifications.size());
    List<WriterUser> writerUsers = new ArrayList<>();
    for (WriterUserCertification writerUserCertification : writerUserCertifications) {
        if (Const.WRITER_PROGRESS_0 == writerUserCertification.getProgress()) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户信息未提交,不能审核");
        }
        if (Const.WRITER_PROGRESS_2 == writerUserCertification.getProgress() || Const.WRITER_PROGRESS_3 == writerUserCertification.getProgress()) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "已审核的用户不能再次审核");
        }
        wUserCertifications.add(new WriterUserCertification(writerUserCertification.getUserId(), progress));
        writerUsers.add(new WriterUser(writerUserCertification.getUserId()));
    }
    if (CollectionUtil.isNotEmpty(wUserCertifications)) {
        // 教师审核通过的同时修改普通用户级别为教师
        count = writerUserCertificationDao.updateWriterUserCertificationProgressByUserId(wUserCertifications);
        List<WriterUser> list = writerUserService.getWriterUserRankList(writerUsers);
        for (WriterUser writerUser : list) {
            // 当级别为0并且是通过的时候修改
            if (0 == writerUser.getRank() && 3 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setRank(1);
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(true);
                    writerUserService.updateWriterUserRank(wrs);
                }
            // 当级别为0并且是退回的时候修改
            } else if (0 == writerUser.getRank() && 2 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(false);
                    writerUserService.updateWriterUser(wrs);
                }
            // 当级别为1并且是通过的时候修改
            } else if (1 == writerUser.getRank() && 3 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(true);
                    writerUserService.updateWriterUserRank(wrs);
                }
            // 当级别为1并且是退回的时候修改
            } else if (1 == writerUser.getRank() && 2 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(false);
                    writerUserService.updateWriterUser(wrs);
                }
            // 当级别为2并且是通过的时候修改
            } else if (2 == writerUser.getRank() && 3 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(true);
                    writerUserService.updateWriterUserRank(wrs);
                }
            // 当级别为2并且是退回的时候修改
            } else if (2 == writerUser.getRank() && 2 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(false);
                    writerUserService.updateWriterUser(wrs);
                }
            // 当级别为3并且是通过的时候修改
            } else if (3 == writerUser.getRank() && 3 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(true);
                    writerUserService.updateWriterUserRank(wrs);
                }
            // 当级别为2并且是退回的时候修改
            } else if (3 == writerUser.getRank() && 2 == progress.intValue()) {
                for (WriterUser wrs : writerUsers) {
                    wrs.setAuthUserType(1);
                    wrs.setAuthUserId(pmphuser.getId());
                    wrs.setIsTeacher(false);
                    writerUserService.updateWriterUser(wrs);
                }
            }
        }
    }
    // 认证通过或退回的推送消息
    Boolean isPass = null;
    if (2 == progress) {
        isPass = false;
    }
    if (3 == progress) {
        isPass = true;
    }
    if (null != isPass) {
        List<Long> teacherIds = new ArrayList<>();
        for (int i = 0; i < userIds.length; i++) {
            teacherIds.add(userIds[0]);
        }
        // 获取用户认证类型和认证人
        List<WriterUser> users = writerUserService.getWriterUserList(userIds);
        for (WriterUser writerUser : users) {
            if (1 == writerUser.getAuthUserType()) {
                // 社内用户
                PmphUser pmphUser = pmphUserService.get(writerUser.getAuthUserId());
                systemMessageService.sendWhenTeacherCertificationAudit(pmphUser.getRealname(), teacherIds, isPass);
            }
            if (2 == writerUser.getAuthUserType()) {
                // 学校机构用户
                OrgUser orgUsers = orgUserService.getOrgUserById(writerUser.getAuthUserId());
                Org org = orgService.getOrgById(orgUsers.getOrgId());
                systemMessageService.sendWhenTeacherCertificationAudit(org.getOrgName(), teacherIds, isPass);
            }
        }
    }
    return count;
}
Also used : WriterUserCertification(com.bc.pmpheep.back.po.WriterUserCertification) PmphUser(com.bc.pmpheep.back.po.PmphUser) Org(com.bc.pmpheep.back.po.Org) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 3 with WriterUserCertification

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

the class MigrationStageTwo method writerUserCertification.

protected void writerUserCertification() {
    String sql = "SELECT a.userid,a.new_pk user_new_pk,d.new_pk org_new_pk,b.handset,b.idcard," + "CASE WHEN b.isteacher = 2 THEN 3 WHEN b.isteacher = 1 THEN 2 WHEN b.isteacher = 0 " + "THEN 1 ELSE 0 END progress,e.filedir,e.operdate " + "FROM sys_user a LEFT JOIN sys_userext b ON a.userid = b.userid " + "LEFT JOIN sys_userorganize c ON a.userid = c.userid " + "LEFT JOIN ba_organize d ON c.orgid = d.orgid " + "LEFT JOIN (SELECT * FROM pub_addfileinfo y WHERE y.fileid IN (SELECT MAX(p.fileid) " + "FROM pub_addfileinfo p WHERE p.childsystemname='sys_userext_teacher' GROUP BY p.operuserid))e " + "ON a.userid = e.operuserid " + "WHERE a.sysflag=1 AND b.usertype !=2 AND e.filedir IS NOT NULL ;";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    // 统计正常数据的数量
    int correctCount = 0;
    int[] state = { 0, 0, 0, 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    for (Map<String, Object> map : maps) {
        StringBuilder sb = new StringBuilder();
        Long userId = (Long) map.get("user_new_pk");
        if (ObjectUtil.isNull(userId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("此用户不存在。"));
            excel.add(map);
            if (state[0] == 0) {
                reason.append("用户不存在。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        if (userId == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("用户为社内用户。"));
            excel.add(map);
            if (state[1] == 0) {
                reason.append("用户为社内用户。");
                dealWith.append("放弃迁移。");
                state[1] = 1;
            }
            continue;
        }
        Long orgId = (Long) map.get("org_new_pk");
        if (ObjectUtil.isNull(orgId) || orgId == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("用户没有教师认证单位,可以" + "通过申报表和专家平台再次确定。"));
            excel.add(map);
            if (state[2] == 0) {
                reason.append("用户没有教师认证单位。");
                dealWith.append("放弃迁移。");
                state[2] = 1;
            }
            continue;
        }
        if (orgId == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("用户认证单位为社内部门" + "或认证单位在表里存在重复情况,可以通过申报表及专家平台再次确定。"));
            excel.add(map);
            if (state[3] == 0) {
                reason.append("用户认证单位为社内部门。");
                dealWith.append("放弃迁移。");
                state[3] = 1;
            }
            continue;
        }
        String handphone = (String) map.get("handset");
        String idcard = (String) map.get("idcard");
        Long progressNum = (Long) map.get("progress");
        short progress = progressNum.shortValue();
        String cert = (String) map.get("filedir");
        Timestamp gmtCreate = (Timestamp) map.get("operdate");
        WriterUserCertification writerUserCertification = new WriterUserCertification();
        writerUserCertification.setUserId(userId);
        writerUserCertification.setOrgId(orgId);
        writerUserCertification.setHandphone(handphone);
        writerUserCertification.setIdcard(idcard);
        writerUserCertification.setProgress(progress);
        writerUserCertification.setGmtCreate(gmtCreate);
        writerUserCertification = writerCertificationService.addWriterUserCertification(writerUserCertification);
        count++;
        Long pk = writerUserCertification.getId();
        if (StringUtil.notEmpty(cert)) {
            String mongoId;
            try {
                mongoId = fileService.migrateFile(cert, ImageType.WRITER_USER_CERT, pk);
            } catch (IOException ex) {
                mongoId = "DEFAULT";
                map.put(SQLParameters.EXCEL_EX_HEADER, "文件读取异常。");
                excel.add(map);
                logger.error("文件读取异常,路径<{}>,异常信息:{}", cert, ex.getMessage());
                if (state[4] == 0) {
                    reason.append("教师资格证文件丢失。");
                    dealWith.append("设为默认文件迁入数据库。");
                    state[4] = 1;
                }
            }
            writerUserCertification.setCert(mongoId);
            writerCertificationService.updateWriterUserCertification(writerUserCertification);
        }
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "教师资格认证表", "writer_user_certification");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "writer_user_certification");
        result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教师资格认证表");
        result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.size());
        result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
        result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
        result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
        result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, maps.size() - count);
        result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
        result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
        SQLParameters.STATISTICS_RESULT.add(result);
    }
    logger.info("writer_user_certification");
    logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "writer_user_certification表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : WriterUserCertification(com.bc.pmpheep.back.po.WriterUserCertification) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with WriterUserCertification

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

the class WriterUserCertificationServiceTest method testUpdateWriterUserCertificationProgressByUserId.

@Test
@Rollback(Const.ISROLLBACK)
public void testUpdateWriterUserCertificationProgressByUserId() throws CheckedServiceException, Exception {
    WriterUserCertification writerUserCertification = this.addWriterUserCertification();
    // 教师审核按userId更新WriterUserCertification中Progress状态字段
    Short progress = 2;
    Long[] idsLongs = { 1L, 2L };
    Assert.assertTrue("修改失败", writerUserCertificationService.updateWriterUserCertificationProgressByUserId(progress, idsLongs, null) >= 0);
}
Also used : WriterUserCertification(com.bc.pmpheep.back.po.WriterUserCertification) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 5 with WriterUserCertification

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

the class WriterUserCertificationServiceTest method testAddWriterUserCertification.

@Test
@Rollback(Const.ISROLLBACK)
public void testAddWriterUserCertification() {
    WriterUserCertification writerUserCertification = this.addWriterUserCertification();
    Assert.assertTrue("添加失败", writerUserCertification.getId() > 0);
}
Also used : WriterUserCertification(com.bc.pmpheep.back.po.WriterUserCertification) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

WriterUserCertification (com.bc.pmpheep.back.po.WriterUserCertification)7 BaseTest (com.bc.pmpheep.test.BaseTest)5 Test (org.junit.Test)5 Rollback (org.springframework.test.annotation.Rollback)5 Org (com.bc.pmpheep.back.po.Org)1 OrgUser (com.bc.pmpheep.back.po.OrgUser)1 PmphUser (com.bc.pmpheep.back.po.PmphUser)1 WriterUser (com.bc.pmpheep.back.po.WriterUser)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1