Search in sources :

Example 6 with Org

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

the class SystemMessageService method sendWhenPubfinalResult.

/**
 * 某一本书的最终结果公布 或者 整套教材全部公布时 向当选者和学校管理员发送消息
 *
 * @author Mryang
 * @createDate 2017年11月19日 上午11:24:31
 * @param textBookId
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenPubfinalResult(Long textBookId, List<DecPositionPublished> decPositionPublishedLst) throws CheckedServiceException, IOException {
    Textbook textbook = textbookService.getTextbookById(textBookId);
    Material material = materialService.getMaterialById(textbook.getMaterialId());
    // 给主编、副主编、编委、数字编委发送
    String msg = "";
    for (DecPositionPublished decPosition : decPositionPublishedLst) {
        if (null != decPosition.getChosenPosition()) {
            if (decPosition.getChosenPosition() == 8) {
                msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的数字编委";
            }
            if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                if (null != decPosition.getRank() && decPosition.getRank() == 1) {
                    if (decPosition.getChosenPosition() == 4) {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的第一主编";
                    } else {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的第一主编、数字编委";
                    }
                } else {
                    if (decPosition.getChosenPosition() == 4) {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的主编";
                    } else {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的主编、数字编委";
                    }
                }
            }
            if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                if (decPosition.getChosenPosition() == 2) {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的副主编";
                } else {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的副主编、数字编委";
                }
            }
            if (decPosition.getChosenPosition() == 1 || 9 == decPosition.getChosenPosition()) {
                if (decPosition.getChosenPosition() == 1) {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的编委";
                } else {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的编委、数字编委";
                }
            }
            // 获取申报表
            Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
            // 存入消息主体
            Message message = new Message(msg);
            message = messageService.add(message);
            String msg_id = message.getId();
            // 发送消息给申报者
            userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), declaration.getUserId(), new Short("2"), null));
            // websocket推送页面消息
            WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msg, DateUtil.getCurrentTime());
            List<String> userIds = new ArrayList<String>(1);
            userIds.add("2_" + declaration.getUserId());
            myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
        }
    }
    // 给学校管理员发送消息
    if (material.getIsAllTextbookPublished()) {
        // 所有都发布了
        String orgMsg = "《<font color='red'>" + material.getMaterialName() + "</font>》的编写团队遴选已结束,贵校共[{sum}]位老师当选,名单如下:";
        // 根据教材Id查询对应的书籍集合
        List<Textbook> textbooks = textbookService.getTextbookByMaterialId(material.getId());
        List<Long> bookIds = new ArrayList<Long>();
        for (Textbook book : textbooks) {
            bookIds.add(book.getId());
        }
        // 根据书籍获取当选了该书籍的人员所属机构
        List<Org> orgs = orgService.listBeElectedOrgByBookIds(bookIds);
        for (Org org : orgs) {
            // 根据orgid和bookid获取该机构某些已公布的书的申报职位
            List<DecPosition> decPositions = decPositionService.listDecPositionsByTextbookIdAndOrgid(bookIds, org.getId());
            if (null != decPositions && decPositions.size() > 0) {
                String msgContent = orgMsg;
                int sum = 0;
                for (int i = 0; i < decPositions.size(); i++) {
                    DecPosition decPosition = decPositions.get(i);
                    Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
                    msgContent += "</br>" + "[<font color='red'>" + declaration.getRealname() + "</font>]";
                    msgContent += " - " + textbookService.getTextbookById(decPosition.getTextbookId()).getTextbookName() + " - ";
                    if (null != decPosition.getChosenPosition()) {
                        if (decPosition.getChosenPosition() == 8) {
                            msgContent += "数字编委";
                        }
                        if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                            if (decPosition.getRank() == 1) {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "第一主编";
                                } else {
                                    msgContent += "第一主编、数字编委";
                                }
                            } else {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "主编";
                                } else {
                                    msgContent += "主编、数字编委";
                                }
                            }
                        }
                        if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                            if (decPosition.getChosenPosition() == 2) {
                                msgContent += "副主编";
                            } else {
                                msgContent += "副主编、数字编委";
                            }
                        }
                        if (decPosition.getChosenPosition() == 1 || decPosition.getChosenPosition() == 9) {
                            if (decPosition.getChosenPosition() == 1) {
                                msgContent += "编委";
                            } else {
                                msgContent += "编委、数字编委";
                            }
                        }
                    }
                    sum++;
                }
                msgContent.replace("{sum}", String.valueOf(sum));
                // 存入消息主体
                Message message = new Message(msgContent);
                message = messageService.add(message);
                String msg_id = message.getId();
                // 获取机构管理员
                OrgUser orgUser = orgUserService.getOrgUserByOrgId(org.getId());
                // 发送消息给申报者
                userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null));
                // websocket推送页面消息
                WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
                List<String> userIds = new ArrayList<String>(1);
                userIds.add("3_" + orgUser.getId());
                myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
            }
        }
    // 《全国高等学校五年制临床医学专业第九轮规划教材》的编写团队遴选已结束,贵校共[5]位老师当选,名单如下:
    // [丁志国] - 局部解剖学 - 第一主编
    // [王海滨] - 医学影像学 - 第二主编
    // [雷国华] - 医学计算机应用 - 副主编
    // [孙风梅] - 医学文献检索与论文写作 - 编委
    // [宋守君] - 医患沟通 - 编委
    } else {
        String orgMsg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,贵校老师";
        // 《全国高等学校五年制临床医学专业第九轮规划教材》[传染病学]的最终结果已公布,贵校老师[丁志国]当选第一主编,[丁志国]当选第一主编,[丁志国]当选第一主编
        // 先要将学校分队
        List<Long> bookIds = new ArrayList<Long>();
        bookIds.add(textBookId);
        // 根据教材Id查询对应的书籍集合
        List<Org> orgs = orgService.listBeElectedOrgByBookIds(bookIds);
        for (Org org : orgs) {
            // 根据orgid和bookid获取该机构某些已公布的书的申报职位
            List<DecPosition> decPositions = decPositionService.listDecPositionsByTextbookIdAndOrgid(bookIds, org.getId());
            if (null != decPositions && decPositions.size() > 0) {
                // 拼装消息
                String msgContent = orgMsg;
                for (int i = 0; i < decPositions.size(); i++) {
                    DecPosition decPosition = decPositions.get(i);
                    Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
                    if (i > 0) {
                        msgContent += ",";
                    }
                    msgContent += "[<font color='red'>" + declaration.getRealname() + "</font>]当选";
                    if (null != decPosition.getChosenPosition()) {
                        if (decPosition.getChosenPosition() == 8) {
                            msgContent += "数字编委";
                        }
                        if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                            if (decPosition.getRank() == 1) {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "第一主编";
                                } else {
                                    msgContent += "第一主编、数字编委";
                                }
                            } else {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "主编";
                                } else {
                                    msgContent += "主编、数字编委";
                                }
                            }
                        }
                        if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                            if (decPosition.getChosenPosition() == 2) {
                                msgContent += "副主编";
                            } else {
                                msgContent += "副主编、数字编委";
                            }
                        }
                        if (decPosition.getChosenPosition() == 1 || decPosition.getChosenPosition() == 9) {
                            if (decPosition.getChosenPosition() == 1) {
                                msgContent += "编委";
                            } else {
                                msgContent += "编委、数字编委";
                            }
                        }
                    }
                }
                // 存入消息主体
                Message message = new Message(msgContent);
                message = messageService.add(message);
                String msg_id = message.getId();
                // 获取机构管理员
                OrgUser orgUser = orgUserService.getOrgUserByOrgId(org.getId());
                // 发送消息给申报者
                userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null));
                // websocket推送页面消息
                WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
                List<String> userIds = new ArrayList<String>(1);
                userIds.add("3_" + orgUser.getId());
                myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
            }
        }
    }
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) Org(com.bc.pmpheep.back.po.Org) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) Material(com.bc.pmpheep.back.po.Material) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) DecPosition(com.bc.pmpheep.back.po.DecPosition) Textbook(com.bc.pmpheep.back.po.Textbook) Declaration(com.bc.pmpheep.back.po.Declaration)

Example 7 with Org

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

the class MigrationStageFour method materialOrg.

protected void materialOrg() {
    String sql = "select * from ( " + "select   " + "a.pushschoolid , " + "b.new_pk materid, " + "c.new_pk orgid, " + "a.orgid  oldorgid " + "from teach_pushschool  a  " + "LEFT JOIN teach_material  b on b.materid = a.materid " + "LEFT JOIN ba_organize c on c.orgid = a.orgid " + "where 1=1 " + ") temp  ";
    // 获取到所有数据表
    String tableName = "teach_pushschool";
    // 增加new_pk字段
    JdbcHelper.addColumn(tableName);
    List<Map<String, Object>> pubList = JdbcHelper.getJdbcTemplate().queryForList(sql + " where materid is not null  GROUP BY CONCAT(materid,'_',orgid) UNION  " + sql + " where materid is  null ");
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    int correctCount = 0;
    int[] state = { 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    // 模块名称
    excptionList.add(new Object[] { "教材发布学校" });
    // 模块标题
    excptionList.add(new Object[] { "机构名称", "问题", "原因分析", "处理方式" });
    int excptionListOldSize = excptionList.size();
    for (Map<String, Object> object : pubList) {
        String pushschoolId = (String) object.get("pushschoolid");
        StringBuilder exception = new StringBuilder();
        Long materid = (Long) object.get("materid");
        Long orgid = (Long) object.get("orgid");
        if (ObjectUtil.isNull(materid)) {
            // 查询机构名称
            Org org = (orgid == null ? null : orgService.getOrgById(orgid));
            String orgName = (org == null ? "" : org.getOrgName());
            object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id为空。"));
            excptionList.add(new Object[] { orgName, "找不到对应教材", "新建的教材被删除", "不导入该条数据" });
            excel.add(object);
            if (state[0] == 0) {
                reason.append("找不到对应的教材。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        if (ObjectUtil.isNull(orgid)) {
            // 查询机构名称
            Org org = (orgid == null ? null : orgService.getOrgById(orgid));
            String orgName = (org == null ? "" : org.getOrgName());
            object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("机构id为空。"));
            excel.add(object);
            excptionList.add(new Object[] { orgName, "找不到对应的发布学校", "", "不导入该条数据" });
            if (state[1] == 0) {
                reason.append("找不到教材对应的发布学校。");
                dealWith.append("放弃迁移。");
                state[1] = 1;
            }
            continue;
        }
        MaterialOrg materialOrg = new MaterialOrg();
        materialOrg.setMaterialId(materid);
        materialOrg.setOrgId(orgid);
        materialOrg = materialOrgService.addMaterialOrg(materialOrg);
        count++;
        long pk = materialOrg.getId();
        if (ObjectUtil.notNull(pk)) {
            // 更新旧表中new_pk字段
            JdbcHelper.updateNewPrimaryKey(tableName, pk, "pushschoolid", pushschoolId);
        }
        if (null == object.get("exception")) {
            correctCount++;
        }
    }
    // 没有错误数据
    if (excptionList.size() == excptionListOldSize) {
        excptionList.remove(excptionList.size() - 1);
        excptionList.remove(excptionList.size() - 1);
    } else {
        // 插入一个空行
        excptionList.add(new String[] { "" });
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "教材-机构关联表", "material_org");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != pubList.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_org");
        result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材—机构关联表");
        result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, pubList.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, pubList.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("'{}'表迁移完成,异常条目数量:{}", tableName, excel.size());
    logger.info("原数据库中共有{}条数据,迁移了{}条数据", pubList.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "" + tableName + "  表迁移完成" + count + "/" + pubList.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : Org(com.bc.pmpheep.back.po.Org) MaterialOrg(com.bc.pmpheep.back.po.MaterialOrg) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) MaterialOrg(com.bc.pmpheep.back.po.MaterialOrg) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Org

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

the class MigrationStageOne method org.

protected void org() {
    // 机构类型方法已添加过new_pk,此处无需再添加
    String tableName = "ba_organize";
    String sql = "SELECT a.*,b.new_pk FROM ba_organize a " + "LEFT JOIN ba_areacode b ON b.AreaID =a.orgprovince " + "WHERE a.orgcode NOT LIKE '15%' AND a.parentid !=0 ORDER BY a.isdelete,a.orgcode";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    List<Map<String, Object>> excel = new LinkedList<>();
    /*除主键外有其他列有唯一值约束,用此集合放此列已经插入新表的值作为判断重复的条件*/
    List<String> list = new ArrayList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    int correctCount = 0;
    int[] state = { 0, 0, 0, 0, 0, 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    for (Map<String, Object> map : maps) {
        /*因此表有主要级字段和次要级字段,次要级字段插入新表同时也需导出Excel,因此异常信息不止一条,
			 * 用StringBulider进行拼接成最终的异常信息
             */
        StringBuilder sb = new StringBuilder();
        Integer isDeleted = (Integer) map.get("isdelete");
        if (ObjectUtil.isNull(isDeleted)) {
            isDeleted = 0;
        }
        /* 此数据为被逻辑删除的数据,待客户反馈再决定是否迁移,现阶段暂时不迁移 */
        if (isDeleted.intValue() == 1) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("被逻辑删除的数据。"));
            excel.add(map);
            if (state[0] == 0) {
                reason.append("被逻辑删除的数据。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        String orgId = (String) map.get("orgid");
        String orgName = (String) map.get("orgname");
        if (StringUtil.isEmpty(orgName)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("找不到机构名称。"));
            excel.add(map);
            if (state[1] == 0) {
                reason.append("找不到机构名称。");
                dealWith.append("放弃迁移。");
                state[1] = 1;
            }
            continue;
        }
        if (JdbcHelper.nameDuplicate(list, orgName)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("机构名称重复。"));
            excel.add(map);
            if (state[2] == 0) {
                reason.append("机构名称重复。");
                dealWith.append("放弃迁移。");
                state[2] = 1;
            }
            continue;
        }
        if (StringUtil.strLength(orgName) > 20) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("机构名称过长。"));
            excel.add(map);
            if (state[3] == 0) {
                reason.append("机构名称过长。");
                dealWith.append("放弃迁移。");
                state[3] = 1;
            }
            continue;
        }
        // 依据客户反馈不迁移的机构
        if ("江苏建康职业学院".equals(orgName) || "北京大学".equals(orgName) || "民办山东万杰医学高等专科学校".equals(orgName) || "天津大学".equals(orgName) || "协和医院".equals(orgName) || "华西医院".equals(orgName) || "技术学校".equals(orgName) || "qthzyxy".equals(orgName) || "河南中医学院".equals(orgName) || "陕西中医学院".equals(orgName)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("缺少管理员账号。"));
            excel.add(map);
            if (state[4] == 0) {
                reason.append("缺少管理员账号。");
                dealWith.append("依据客户反馈,放弃迁移。");
                state[4] = 1;
            }
            continue;
        }
        list.add(orgName);
        Integer orgType = (Integer) map.get("orgtype");
        Long areaId = (Long) map.get("new_pk");
        if (ObjectUtil.isNull(orgType)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("找不到机构所属类型。"));
            excel.add(map);
            if (state[5] == 0) {
                reason.append("找不到机构所属类型。");
                dealWith.append("放弃迁移。");
                state[5] = 1;
            }
            continue;
        }
        // 找不到所属区域根据客户要求删除不导入
        if (ObjectUtil.isNull(areaId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("已删除。"));
            excel.add(map);
            if (state[6] == 0) {
                reason.append("找不到所属区域。");
                dealWith.append("依据客户反馈,放弃迁移。");
                state[6] = 1;
            }
            continue;
        }
        Long orgTypeId = JdbcHelper.getPrimaryKey(tableName, "orgid", String.valueOf(orgType));
        String contactPerson = (String) map.get("linker");
        String contactPhone = (String) map.get("linktel");
        Integer sort = (Integer) map.get("sortno");
        if (ObjectUtil.notNull(sort) && sort < 0) {
            sort = 999;
        }
        String note = (String) map.get("remark");
        Org org = new Org();
        org.setOrgName(orgName);
        org.setOrgTypeId(orgTypeId);
        org.setAreaId(areaId);
        org.setContactPerson(contactPerson);
        org.setContactPhone(contactPhone);
        org.setSort(sort);
        org.setNote(note);
        org.setIsDeleted(isDeleted == 1);
        org = orgService.addOrg(org);
        Long pk = org.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "orgid", orgId);
        count++;
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "机构信息表", "org");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "org");
        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("org表迁移完成");
    logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "org表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : Org(com.bc.pmpheep.back.po.Org) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinkedList(java.util.LinkedList) WriterPoint(com.bc.pmpheep.back.po.WriterPoint) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 9 with Org

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

the class OrgController method excel.

@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "解析批量导入的发布学校数据")
@RequestMapping(value = "/orgExport", method = RequestMethod.POST)
public ResponseBean excel(MultipartFile file, HttpServletRequest req) {
    if (null == file || file.isEmpty()) {
        return new ResponseBean("没有文件");
    }
    // 文件名称
    String name = file.getOriginalFilename();
    // 文件类型
    String fileType = name.substring(name.lastIndexOf("."));
    InputStream in = null;
    try {
        in = file.getInputStream();
    } catch (FileNotFoundException e) {
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("未获取到文件");
    } catch (Exception e) {
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("未知异常");
    }
    Workbook workbook = null;
    try {
        if ((".xls").equals(fileType)) {
            workbook = new HSSFWorkbook(in);
        } else if ((".xlsx").equals(fileType)) {
            workbook = new XSSFWorkbook(in);
        } else {
            if (null != in) {
                try {
                    in.close();
                } catch (Exception ee) {
                } finally {
                    in = null;
                }
            }
            return new ResponseBean("读取的不是Excel文件");
        }
    } catch (IOException e) {
        if (null != workbook) {
            try {
                workbook.close();
            } catch (Exception ee) {
            } finally {
                workbook = null;
            }
        }
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("读取文件异常");
    } catch (Exception e) {
        if (null != workbook) {
            try {
                workbook.close();
            } catch (Exception ee) {
            } finally {
                workbook = null;
            }
        }
        if (null != in) {
            try {
                in.close();
            } catch (Exception ee) {
            } finally {
                in = null;
            }
        }
        return new ResponseBean("未知异常");
    }
    // sheet数目
    // int sheetTotal = workbook.getNumberOfSheets() ;
    Sheet sheet = workbook.getSheetAt(0);
    List<Org> orgs = new ArrayList<Org>(sheet.getLastRowNum());
    List<String> erros = new ArrayList<String>(sheet.getLastRowNum());
    for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
        Row row = sheet.getRow(rowNum);
        if (null == row) {
            continue;
        }
        Cell cell1 = row.getCell(0);
        Cell cell2 = row.getCell(1);
        Cell cell3 = row.getCell(2);
        String value1 = StringUtil.getCellValue(cell1);
        String value2 = StringUtil.getCellValue(cell2);
        String value3 = StringUtil.getCellValue(cell3);
        if (StringUtil.notEmpty(value2) && StringUtil.notEmpty(value3)) {
            Org org = orgService.getOrgByNameAndUserName(value2, value3);
            if (null != org) {
                orgs.add(org);
            } else {
                erros.add("系统找不到机构名称为\"" + value2 + "\",机构代码为\"" + value3 + "\"的机构");
            }
        } else {
            if (StringUtil.isEmpty(value1) && StringUtil.isEmpty(value2) && StringUtil.isEmpty(value3)) {
            } else {
                erros.add("第" + rowNum + "条数据填写不完整 ");
            }
        }
    }
    if (null != workbook) {
        try {
            workbook.close();
        } catch (Exception e) {
        } finally {
            workbook = null;
        }
    }
    if (null != in) {
        try {
            in.close();
        } catch (Exception e) {
        } finally {
            in = null;
        }
    }
    Map<String, Object> res = new HashMap<String, Object>();
    res.put("orgs", orgs);
    res.put("erros", erros);
    return new ResponseBean(res);
}
Also used : Org(com.bc.pmpheep.back.po.Org) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Org (com.bc.pmpheep.back.po.Org)9 OrgUser (com.bc.pmpheep.back.po.OrgUser)6 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 PmphUser (com.bc.pmpheep.back.po.PmphUser)2 WriterUser (com.bc.pmpheep.back.po.WriterUser)2 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 BaseTest (com.bc.pmpheep.test.BaseTest)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Test (org.junit.Test)2 LogDetail (com.bc.pmpheep.annotation.LogDetail)1 DecPosition (com.bc.pmpheep.back.po.DecPosition)1 DecPositionPublished (com.bc.pmpheep.back.po.DecPositionPublished)1 Declaration (com.bc.pmpheep.back.po.Declaration)1 Material (com.bc.pmpheep.back.po.Material)1 MaterialOrg (com.bc.pmpheep.back.po.MaterialOrg)1 PmphDepartment (com.bc.pmpheep.back.po.PmphDepartment)1