Search in sources :

Example 21 with CmsContent

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

the class CmsContentServiceTest method testAddCmsContent.

/**
 * <pre>
 * 功能描述:add 方法测试
 * 使用示范:
 *
 * </pre>
 */
@Test
public void testAddCmsContent() {
    CmsContent cmsContent = this.addCmsContent();
    logger.info(cmsContent.toString());
    Assert.assertNotNull("插入内容后返回的CmsContent.id不应为空", cmsContent.getId());
}
Also used : CmsContent(com.bc.pmpheep.back.po.CmsContent) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 22 with CmsContent

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

the class MigrationBook method clearBook.

protected void clearBook() {
    StringBuilder sns = new StringBuilder();
    InputStream is;
    Workbook workbook;
    String path = this.getClass().getClassLoader().getResource("book.xlsx").getPath();
    try {
        is = new FileInputStream(path);
    } catch (IOException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.FILE_CREATION_FAILED, "未找到模板文件");
    }
    try {
        workbook = new XSSFWorkbook(is);
    } catch (IOException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "读取文件失败");
    }
    Map<String, String> snsAndMaterNames = new HashMap<String, String>(16);
    for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
        Sheet sheet = workbook.getSheetAt(numSheet);
        if (ObjectUtil.isNull(sheet)) {
            continue;
        }
        for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
            Row row = sheet.getRow(rowNum);
            Cell sn = row.getCell(1);
            if (ObjectUtil.notNull(sn) && !"".equals(sn.toString())) {
                sns.append(",'" + sn.toString().replace(".0", "") + "'");
                snsAndMaterNames.put(sn.toString().replace(".0", ""), String.valueOf(row.getCell(8)));
            }
        }
    }
    bookDao.deleted();
    bookDetailDao.deleteBookDetailByBookIds();
    bookDao.deletedBookSupport();
    bookCorrectionDao.deleteBookCoorrectionTrackByBookIds();
    bookEditorDao.deleteBookEditorByBookIds();
    bookUserCommentDao.deleteBookUserCommentBookIds();
    bookUserLikeDao.deleteBookUserLikeByBookIds();
    bookUserMarkDao.deleteBookUserMarkByBookIds();
    bookVideoDao.deleteBookVideoByBookIds();
    // 同步更新或者插入书籍
    String sn = sns.toString().substring(1);
    JSONArray bookInfo = new InfoWorking().listBook(sn);
    // 版本号
    String[] vns = new String[bookInfo.size()];
    for (int i = 0; i < bookInfo.size(); i++) {
        JSONObject job = bookInfo.getJSONObject(i);
        vns[i] = job.getString("editionnum");
    }
    bookService.AbuttingJoint(vns, 1);
    // 初始化教材社区数据
    Map<String, Long> materNamesAndIds = new HashMap<String, Long>(16);
    for (int i = 0; i < bookInfo.size(); i++) {
        JSONObject job = bookInfo.getJSONObject(i);
        // 本版号
        String bookVn = job.getString("editionnum");
        // 书号
        String bookSn = job.getString("booknumber");
        String materName = snsAndMaterNames.get(bookSn);
        if (null == materName || "".equals(materName.trim())) {
            continue;
        }
        Long materId = materNamesAndIds.get(materName);
        if (null == materId) {
            materId = Long.MAX_VALUE - i;
            Content content = new Content(materName);
            content = contentService.add(content);
            CmsContent cmsContent = new CmsContent();
            cmsContent.setParentId(0L);
            cmsContent.setPath("0");
            cmsContent.setMid(content.getId());
            cmsContent.setCategoryId(3L);
            cmsContent.setTitle(materName);
            cmsContent.setAuthorType(new Short("0"));
            cmsContent.setAuthorId(342L);
            cmsContent.setIsPublished(true);
            cmsContent.setAuthStatus(new Short("2"));
            cmsContent.setAuthDate(DateUtil.date2Str(new Date()));
            cmsContent.setAuthUserId(342L);
            cmsContent.setGmtCreate(DateUtil.getCurrentTime());
            cmsContent.setGmtUpdate(DateUtil.getCurrentTime());
            cmsContent.setIsMaterialEntry(true);
            cmsContent.setMaterialId(materId);
            cmsContentService.addCmsContent(cmsContent);
            materNamesAndIds.put(materName, materId);
        }
        // 更新书籍
        Book book = bookDao.getBookByVn2(bookVn);
        if (null != book) {
            book.setMaterialId(materId);
            book.setSn(bookSn);
            bookDao.updateBook(book);
        }
    }
}
Also used : HashMap(java.util.HashMap) InfoWorking(com.bc.pmpheep.erp.service.InfoWorking) Book(com.bc.pmpheep.back.po.Book) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Cell(org.apache.poi.ss.usermodel.Cell) CmsContent(com.bc.pmpheep.back.po.CmsContent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JSONArray(net.sf.json.JSONArray) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) IOException(java.io.IOException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) FileInputStream(java.io.FileInputStream) Date(java.util.Date) JSONObject(net.sf.json.JSONObject) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

CmsContent (com.bc.pmpheep.back.po.CmsContent)22 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)16 Content (com.bc.pmpheep.general.po.Content)12 PmphUser (com.bc.pmpheep.back.po.PmphUser)8 ArrayList (java.util.ArrayList)7 Material (com.bc.pmpheep.back.po.Material)6 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)6 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)4 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)4 HashMap (java.util.HashMap)4 CmsExtra (com.bc.pmpheep.back.po.CmsExtra)3 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)3 BaseTest (com.bc.pmpheep.test.BaseTest)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 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