Search in sources :

Example 1 with MaterialOrg

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

the class MaterialOrgServiceTest method testDeleteMaterialOrgByOrgId.

@Test
@Rollback(Const.ISROLLBACK)
public void testDeleteMaterialOrgByOrgId() {
    MaterialOrg materialOrg1 = new MaterialOrg(1L, 1L);
    MaterialOrg materialOrg3 = new MaterialOrg(2L, 1L);
    Assert.assertTrue("addMaterialOrg 添加失败", materialOrgService.addMaterialOrg(materialOrg1).getId() > 0);
    Assert.assertTrue("addMaterialOrg 添加失败", materialOrgService.addMaterialOrg(materialOrg3).getId() > 0);
    // 根据orgId删除materialOrg
    Assert.assertTrue("deleteMaterialOrgByMaterialId删除失败", materialOrgService.deleteMaterialOrgByOrgId(1L) > 0);
    Assert.assertTrue("deleteMaterialOrgByMaterialId删除失败", materialOrgService.deleteMaterialOrgByOrgId(r.nextLong()) >= 0);
}
Also used : MaterialOrg(com.bc.pmpheep.back.po.MaterialOrg) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 2 with MaterialOrg

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

the class MaterialOrgServiceTest method testAddMaterialOrg.

@Test
@Rollback(Const.ISROLLBACK)
public void testAddMaterialOrg() {
    MaterialOrg materialOrg1 = new MaterialOrg(1L, 1L);
    // 添加
    Assert.assertTrue("addMaterialOrg 添加失败", materialOrgService.addMaterialOrg(materialOrg1).getId() > 0);
}
Also used : MaterialOrg(com.bc.pmpheep.back.po.MaterialOrg) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with MaterialOrg

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

the class MaterialOrgServiceTest method testDeleteMaterialOrgByMaterialId.

@Test
@Rollback(Const.ISROLLBACK)
public void testDeleteMaterialOrgByMaterialId() {
    MaterialOrg materialOrg1 = new MaterialOrg(1L, 1L);
    MaterialOrg materialOrg2 = new MaterialOrg(1L, 2L);
    Assert.assertTrue("addMaterialOrg 添加失败", materialOrgService.addMaterialOrg(materialOrg1).getId() > 0);
    Assert.assertTrue("addMaterialOrg 添加失败", materialOrgService.addMaterialOrg(materialOrg2).getId() > 0);
    // 根据materialId删除materialOrg
    Assert.assertTrue("deleteMaterialOrgByMaterialId删除失败", materialOrgService.deleteMaterialOrgByMaterialId(1L) > 0);
    Assert.assertTrue("deleteMaterialOrgByMaterialId删除失败", materialOrgService.deleteMaterialOrgByMaterialId(r.nextLong()) >= 0);
}
Also used : MaterialOrg(com.bc.pmpheep.back.po.MaterialOrg) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with MaterialOrg

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

the class MaterialExtraServiceImpl method noticePublished.

@Override
public Integer noticePublished(Long materialId, List<Long> orgIds, String sessionId) throws CheckedServiceException, IOException {
    if (CollectionUtil.isEmpty(orgIds)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "机构为空");
    }
    // 防止网络延迟重复提交
    Set<Long> newOrgIdSet = new HashSet<>();
    newOrgIdSet.addAll(orgIds);
    List<Long> listOrgIds = new ArrayList<Long>(newOrgIdSet.size());
    listOrgIds.addAll(newOrgIdSet);
    // 获取当前用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    Integer count = 0;
    List<MaterialOrg> materialOrgList = new ArrayList<MaterialOrg>(listOrgIds.size());
    // 根据教材ID查询教材-机构关联表
    List<Long> OrgIds = materialOrgService.getListMaterialOrgByMaterialId(materialId);
    if (CollectionUtil.isEmpty(OrgIds)) {
        // 为空,初次发布
        for (Long orgId : listOrgIds) {
            materialOrgList.add(new MaterialOrg(materialId, orgId));
        }
        count = materialOrgService.addMaterialOrgs(materialOrgList);
        if (count > 0) {
            systemMessageService.materialSend(materialId, listOrgIds);
        }
    } else {
        // 不为空
        // 新选中的机构
        List<Long> newOrgIds = new ArrayList<Long>();
        for (Long orgId : listOrgIds) {
            if (!OrgIds.contains(orgId)) {
                newOrgIds.add(orgId);
                materialOrgList.add(new MaterialOrg(materialId, orgId));
            }
        }
        if (CollectionUtil.isEmpty(materialOrgList)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.ILLEGAL_PARAM, "当前选中的学校已收到消息,无需要再次发送");
        }
        count = materialOrgService.addMaterialOrgs(materialOrgList);
        if (count > 0) {
            systemMessageService.materialSend(materialId, newOrgIds);
        }
    }
    CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
    if (ObjectUtil.notNull(cmsContent)) {
        // throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA,
        // CheckedExceptionResult.NULL_PARAM, "没有找到对应的教材通知信息");
        cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), true, false, Const.CMS_AUTHOR_STATUS_2, // authUserId
        0L, // 为0代表系统审核
        DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
    }
    count = materialService.updateMaterial(new Material(materialId, true), sessionId);
    return count;
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) MaterialOrg(com.bc.pmpheep.back.po.MaterialOrg) HashSet(java.util.HashSet)

Example 5 with MaterialOrg

use of com.bc.pmpheep.back.po.MaterialOrg 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)

Aggregations

MaterialOrg (com.bc.pmpheep.back.po.MaterialOrg)6 BaseTest (com.bc.pmpheep.test.BaseTest)4 Test (org.junit.Test)4 Rollback (org.springframework.test.annotation.Rollback)4 ArrayList (java.util.ArrayList)2 CmsContent (com.bc.pmpheep.back.po.CmsContent)1 Material (com.bc.pmpheep.back.po.Material)1 Org (com.bc.pmpheep.back.po.Org)1 PmphUser (com.bc.pmpheep.back.po.PmphUser)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1