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());
}
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);
}
}
}
Aggregations