Search in sources :

Example 1 with DecPosition

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

the class MigrationStageSix method decPosition.

/**
 * 作家申报职位表(多对多)
 */
protected void decPosition() {
    // 要迁移的旧库表名
    String tableName = "teach_applyposition";
    // 增加new_pk字段
    JdbcHelper.addColumn(tableName);
    String sql = "select ta.materid,ta.writerid,ta.bookid," + "GROUP_CONCAT(case when ta.positiontype=1 then 'a' when ta.positiontype=2 " + "then 'b' when ta.positiontype=3 then 'c' else 'c' " + "end ORDER BY ta.positiontype) preset_position," + "if(sum(if(tp.positiontype in (1,2,3),1,0))>0,true,false) is_on_list," + "GROUP_CONCAT(case when tp.positiontype=1 and tp.directoraudit>=11 then 'a' " + "when tp.positiontype=2 and tp.directoraudit>=11 then 'b' " + "when tp.positiontype=3 and tp.directoraudit>=41 then 'c' else 'd' " + "end ORDER BY tp.positiontype) chosen_position," + "min(tp.mastersort) mastersort,ta.outlineurl,ta.outlinename syllabus_name," + "ifnull(wd.updatedate,wd.createdate) gmt_create," + "wd.new_pk wdid,tb.new_pk tbid " + "from teach_applyposition ta " + "left join teach_positionset tp on tp.appposiid=ta.appposiid " + "left join writer_declaration wd on wd.writerid=ta.writerid " + "left join teach_bookinfo tb on tb.bookid=ta.bookid " + "WHERE ta.positiontype in (1,2,3) and wd.writerid is not null " + "and tb.bookid is not null " + "GROUP BY wd.writerid,tb.bookid ";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    // 迁移成功的条目数
    int count = 0;
    int extensionidCount = 0;
    int textbookidCount = 0;
    int outListUrlCount = 0;
    int outListCount = 0;
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int correctCount = 0;
    int[] state = { 0, 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    /* 开始遍历查询结果 */
    for (Map<String, Object> map : maps) {
        StringBuilder sb = new StringBuilder();
        // 旧表主键值
        String id = (String) map.get("materid");
        // 申报表id
        Long declarationid = (Long) map.get("wdid");
        // 书籍id
        Long textbookid = (Long) map.get("tbid");
        // 申报职务
        String temppresetPosition = (String) map.get("preset_position");
        // 是否进入预选名单
        Long isOnList = (Long) map.get("is_on_list");
        // 遴选职务
        String tempchosenPosition = (String) map.get("chosen_position");
        // 排位
        Integer mastersort = (Integer) map.get("mastersort");
        DecPosition decPosition = new DecPosition();
        if (ObjectUtil.isNull(declarationid) || declarationid.intValue() == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("未找到申报表对应的关联结果。"));
            excel.add(map);
            logger.debug("未找到申报表对应的关联结果,此结果将被记录在Excel中");
            extensionidCount++;
            if (state[0] == 0) {
                reason.append("找不带对应的申报作家。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        decPosition.setDeclarationId(declarationid);
        if (ObjectUtil.isNull(textbookid) || textbookid.intValue() == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("未找到书籍对应的关联结果。"));
            excel.add(map);
            logger.debug("未找到书籍对应的关联结果,此结果将被记录在Excel中");
            textbookidCount++;
            if (state[1] == 0) {
                reason.append("找不到申报的书籍。");
                dealWith.append("放弃迁移。");
                state[1] = 1;
            }
            continue;
        }
        decPosition.setTextbookId(textbookid);
        temppresetPosition += "," + temppresetPosition + ",";
        String Positions = "0";
        if (temppresetPosition.contains(",a,")) {
            Positions += "1";
        } else {
            Positions += "0";
        }
        if (temppresetPosition.contains(",b,")) {
            Positions += "1";
        } else {
            Positions += "0";
        }
        if (temppresetPosition.contains(",c,")) {
            Positions += "1";
        } else {
            Positions += "0";
        }
        // 转成10进制
        decPosition.setPresetPosition(Integer.valueOf(Positions, 2));
        if (ObjectUtil.isNull(isOnList)) {
            decPosition.setIsOnList(true);
        } else {
            Integer isOn = isOnList.intValue();
            if (isOn.equals(1)) {
                decPosition.setIsOnList(true);
            } else {
                decPosition.setIsOnList(false);
            }
        }
        tempchosenPosition += "," + tempchosenPosition + ",";
        Integer chosen = 0;
        if (tempchosenPosition.contains(",a,")) {
            chosen = 4;
        } else if (tempchosenPosition.contains(",b,")) {
            chosen = 2;
        } else if (tempchosenPosition.contains(",c,")) {
            chosen = 1;
        } else if (tempchosenPosition.contains(",d,")) {
            chosen = 0;
        }
        decPosition.setChosenPosition(chosen);
        decPosition.setRank(mastersort);
        // 教学大纲名称
        decPosition.setSyllabusName((String) map.get("syllabus_name"));
        // 创建时间
        decPosition.setGmtCreate((Timestamp) map.get("gmt_create"));
        // 教学大纲id
        String outLineUrl = (String) map.get("outlineurl");
        decPosition = decPositionService.addDecPosition(decPosition);
        long pk = decPosition.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "materid", id);
        count++;
        if (StringUtil.notEmpty(outLineUrl)) {
            /* 以下读取教学大纲id并保存在mongoDB中,读取失败时导出到Excel中 */
            String mongoId = "";
            try {
                mongoId = fileService.migrateFile(outLineUrl, FileType.SYLLABUS, pk);
            } catch (IOException ex) {
                map.put(SQLParameters.EXCEL_EX_HEADER, "文件读取异常");
                excel.add(map);
                logger.debug("文件读取异常,路径<{}>,异常信息:{}", outLineUrl, ex.getMessage());
                outListUrlCount++;
                if (state[2] == 0) {
                    reason.append("教学大纲文件丢失。");
                    dealWith.append("教学大纲可以没有,照常迁入数据库。");
                    state[2] = 1;
                }
            }
            decPosition.setSyllabusId(mongoId);
            decPositionService.updateDecPosition(decPosition);
        }
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "作家申报职位表", "dec_position");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "dec_position");
        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("文件读取异常数量:{}", outListUrlCount);
    logger.info("更新mongoDB的id错误数量:{}", outListCount);
    logger.info("未找到教材扩展项对应的关联结果数量:{}", extensionidCount);
    logger.info("未找到书籍对应的关联结果数量:{}", textbookidCount);
    logger.info("teach_applyposition表迁移完成,异常条目数量:{}", excel.size());
    logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "" + tableName + "  表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) DecPosition(com.bc.pmpheep.back.po.DecPosition) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DecPosition

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

the class DecPositionServiceTest method testAddDecPosition.

@Test
@Rollback(Const.ISROLLBACK)
public void testAddDecPosition() {
    DecPosition decPosition = new DecPosition();
    decPosition.setDeclarationId(6L);
    decPosition.setTextbookId(8L);
    decPosition.setPresetPosition(1);
    decPosition = decPositionService.addDecPosition(decPosition);
    Assert.assertTrue("添加数据失败", decPosition.getId() > 0);
}
Also used : DecPosition(com.bc.pmpheep.back.po.DecPosition) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with DecPosition

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

the class DecPositionServiceTest method testGetDecPosition.

@Test
@Rollback(Const.ISROLLBACK)
public void testGetDecPosition() {
    long id = add().getId();
    DecPosition decPosition = decPositionService.getDecPositionById(id);
    Assert.assertNotNull("获取作家申报职位信息失败", decPosition);
}
Also used : DecPosition(com.bc.pmpheep.back.po.DecPosition) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with DecPosition

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

the class DecPositionServiceImpl method updateDecPositionEditorSelection.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Integer updateDecPositionEditorSelection(String jsonDecPosition, Integer selectionType, Integer editorOrSubeditorType, Integer unselectedHold, Long textbookId, String sessionId) throws CheckedServiceException, IOException {
    if (StringUtil.isEmpty(jsonDecPosition)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "遴选职位不能为空");
    }
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Integer count = 0;
    List<DecPosition> decPositions = // json字符串转List对象集合
    new JsonUtil().getArrayListObjectFromStr(DecPosition.class, jsonDecPosition);
    // 编委遴选界面 (0:未选中)
    Integer unselectedHold_0 = 0;
    if (CollectionUtil.isEmpty(decPositions) && unselectedHold_0 == unselectedHold && 2 == editorOrSubeditorType && 1 == selectionType) {
        // 编委遴选界面,没有人员被选中也可以进行暂存
        // 查询书籍下所有申报id
        List<Long> ids = decPositionService.getDecPositionIdByBookId(textbookId, editorOrSubeditorType);
        // 初始化作家职位申报表
        if (CollectionUtil.isNotEmpty(ids)) {
            decPositionService.updateDecPositionSetDefault(ids, editorOrSubeditorType);
        }
    } else {
        if (CollectionUtil.isEmpty(decPositions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "遴选职位为空");
        }
        // (1:确定,2:发布)
        Integer selectionType_1 = 1;
        Integer selectionType_2 = 2;
        // 获取书籍id
        textbookId = decPositions.get(0).getTextbookId();
        // 原来的历史遴选记录
        List<DecPosition> oldlist = decPositionService.listChosenDecPositionsByTextbookId(textbookId);
        // 1:确定
        if (selectionType_1.intValue() == selectionType.intValue()) {
            // 查询书籍下所有申报id
            List<Long> ids = decPositionService.getDecPositionIdByBookId(textbookId, editorOrSubeditorType);
            if (2 == editorOrSubeditorType) {
                // 遴选的编委ID
                List<Long> newEditorialMemberIds = new ArrayList<Long>();
                for (DecPosition decPosition : decPositions) {
                    if (1 == decPosition.getChosenPosition() || 8 == decPosition.getChosenPosition()) {
                        if (!ids.contains(decPosition.getId())) {
                            newEditorialMemberIds.add(decPosition.getId());
                        }
                    }
                }
                if (newEditorialMemberIds.isEmpty()) {
                    Textbook textbook = textbookService.getTextbookById(textbookId);
                    if (0 != textbook.getRevisionTimes()) {
                        textbookService.updatRevisionTimesByTextBookId(-1, textbookId);
                    }
                } else {
                    textbookService.updatRevisionTimesByTextBookId(1, textbookId);
                }
                // 清楚dec_position_temp表
                decPositionTempService.deleteDecPositionTempByTextbookId(textbookId);
            }
            // 初始化作家职位申报表
            if (CollectionUtil.isNotEmpty(ids)) {
                decPositionService.updateDecPositionSetDefault(ids, editorOrSubeditorType);
            }
            if (CollectionUtil.isNotEmpty(decPositions)) {
                count = decPositionDao.updateDecPositionEditorSelection(decPositions);
            }
            if (ObjectUtil.isNull(textbookId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "书籍id为空");
            }
            // 用户类型
            Integer userType = 1;
            // 获取修改者id
            Long updaterId = pmphUser.getId();
            // 添加新的遴选记录
            textbookLogService.addTextbookLog(oldlist, textbookId, updaterId, userType);
        }
        // 2:发布
        if (selectionType_2.intValue() == selectionType.intValue()) {
            // 发布的时候 先确认
            this.updateDecPositionEditorSelection(jsonDecPosition, 1, editorOrSubeditorType, unselectedHold, textbookId, sessionId);
            if (ObjectUtil.isNull(textbookId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "书籍id为空");
            }
            // 获取当前书籍书申报信息(包含没有被遴选上的)
            List<DecPosition> decPositionsList = decPositionService.listDecPositionsByTextBookIds(new ArrayList<Long>(Arrays.asList(textbookId)));
            if (CollectionUtil.isEmpty(decPositionsList)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "当前书籍还未遴选主编,副主编");
            }
            // DecPositionPublished对象集合
            List<DecPositionPublished> decPositionPublisheds = new ArrayList<DecPositionPublished>(decPositionsList.size());
            for (DecPosition decPosition : decPositionsList) {
                // 筛选出遴选上的主编副主编人员
                Integer chosenPosition = decPosition.getChosenPosition();
                if (null != chosenPosition && (chosenPosition == 4 || chosenPosition == 2 || chosenPosition == 12 || chosenPosition == 10)) {
                    chosenPosition = chosenPosition > 8 ? chosenPosition - 8 : chosenPosition;
                    decPositionPublisheds.add(new DecPositionPublished(pmphUser.getId(), decPosition.getDeclarationId(), textbookId, decPosition.getPresetPosition(), chosenPosition, decPosition.getRank(), decPosition.getSyllabusId(), decPosition.getSyllabusName()));
                }
            }
            // 已经公布的列表
            List<DecPositionPublished> lst = decPositionPublishedService.getDecPositionPublishedListByBookId(textbookId);
            List<DecPositionPublished> addNew = new ArrayList<DecPositionPublished>(16);
            for (DecPositionPublished item : lst) {
                // 编委 | 数字编委
                if (item.getChosenPosition() == 1 || item.getChosenPosition() >= 8) {
                    // item.setChosenPosition(item.getChosenPosition() > 8
                    // ?(item.getChosenPosition()-8):item.getChosenPosition() );
                    addNew.add(item);
                }
            }
            // 加入主编副主编
            for (DecPositionPublished item : decPositionPublisheds) {
                boolean no = true;
                for (DecPositionPublished itemadd : addNew) {
                    if (itemadd.getDeclarationId().intValue() == item.getDeclarationId().intValue()) {
                        no = false;
                        itemadd.setChosenPosition(item.getChosenPosition() + 8);
                        break;
                    }
                }
                if (no) {
                    addNew.add(item);
                }
            }
            // clear Id
            for (DecPositionPublished item : addNew) {
                item.setId(null);
            }
            // 对比重新发布之前于之后的不同
            List<DecPositionPublished> newMessage = new ArrayList<>();
            for (DecPositionPublished now : decPositionPublisheds) {
                DecPositionPublished published = decPositionPublishedService.getDecPositionByDeclarationId(now.getDeclarationId(), now.getTextbookId());
                if (ObjectUtil.isNull(published)) {
                    newMessage.add(now);
                }
                for (DecPositionPublished old : lst) {
                    if (now.getDeclarationId().equals(old.getDeclarationId())) {
                        if (!now.getChosenPosition().equals(old.getChosenPosition()) || !now.getRank().equals(old.getRank())) {
                            newMessage.add(now);
                        }
                    }
                }
            }
            // 先删除当前发布人已发布的
            decPositionPublishedService.deleteDecPositionPublishedByTextBookId(textbookId);
            // 再添加
            decPositionPublishedService.batchInsertDecPositionPublished(addNew);
            // 发布时更新textbook表中is_chief_published(是否已公布主编/副主编)字段
            count = textbookService.updateTextbook(new Textbook(textbookId, true));
            if (count > 0) {
                // 发送消息
                systemMessageService.sendWhenConfirmFirstEditor(textbookId, newMessage);
            }
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) JsonUtil(com.bc.pmpheep.back.util.JsonUtil) DecPosition(com.bc.pmpheep.back.po.DecPosition) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition) Textbook(com.bc.pmpheep.back.po.Textbook)

Example 5 with DecPosition

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

the class DecPositionServiceImpl method batchPublishEditor.

@Override
public Integer batchPublishEditor(List<Long> textbookIds, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(textbookIds)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "未选中书籍");
    }
    Integer count = 0;
    for (Long textbookId : textbookIds) {
        // 查询当前书籍已遴选的主编,副主编
        List<DecPosition> listDecPositions = this.getEditorByTextbookId(textbookId);
        if (CollectionUtil.isEmpty(listDecPositions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "当前选中书籍还未遴选主编,副主编");
        }
        // DecPositionPublished对象集合
        List<DecPositionPublished> decPositionPublisheds = new ArrayList<DecPositionPublished>(listDecPositions.size());
        for (DecPosition decPosition : listDecPositions) {
            decPositionPublisheds.add(new DecPositionPublished(pmphUser.getId(), decPosition.getDeclarationId(), textbookId, decPosition.getPresetPosition(), decPosition.getChosenPosition(), decPosition.getRank(), decPosition.getSyllabusId(), decPosition.getSyllabusName()));
        }
        // 删除已发布的主编,副主编
        decPositionPublishedService.deletePublishedEditorByTextbookId(textbookId);
        // 重新发布
        // 再添加
        decPositionPublishedService.batchInsertDecPositionPublished(decPositionPublisheds);
        // 发布时更新textbook表中is_chief_published(是否已公布主编/副主编)字段
        count = textbookService.updateTextbook(new Textbook(textbookId, true));
        if (count > 0) {
            // 发送消息
            systemMessageService.sendWhenConfirmFirstEditor(textbookId, decPositionPublisheds);
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) DecPosition(com.bc.pmpheep.back.po.DecPosition) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition) ArrayList(java.util.ArrayList) Textbook(com.bc.pmpheep.back.po.Textbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished)

Aggregations

DecPosition (com.bc.pmpheep.back.po.DecPosition)14 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)8 ArrayList (java.util.ArrayList)7 Textbook (com.bc.pmpheep.back.po.Textbook)6 Declaration (com.bc.pmpheep.back.po.Declaration)5 DecPositionPublished (com.bc.pmpheep.back.po.DecPositionPublished)4 Material (com.bc.pmpheep.back.po.Material)4 PmphUser (com.bc.pmpheep.back.po.PmphUser)4 NewDecPosition (com.bc.pmpheep.back.vo.NewDecPosition)3 BaseTest (com.bc.pmpheep.test.BaseTest)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Rollback (org.springframework.test.annotation.Rollback)3 OrgUser (com.bc.pmpheep.back.po.OrgUser)2 UserMessage (com.bc.pmpheep.back.po.UserMessage)2 WriterUserTrendst (com.bc.pmpheep.back.po.WriterUserTrendst)2 Message (com.bc.pmpheep.general.po.Message)2 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)2 Gson (com.google.gson.Gson)2 Map (java.util.Map)2