use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.
the class CmsContentServiceImpl method addHelp.
@Override
public CmsContent addHelp(CmsContent cmsContent, String content, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (StringUtil.isEmpty(content)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容参数为空");
}
List<CmsContent> listContents = this.listCmsContentByTitle(cmsContent.getTitle());
if (CollectionUtil.isNotEmpty(listContents)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "添加的常见问题已存在,请确认后再添加");
}
// MongoDB 内容插入
Content contentObj = contentService.add(new Content(content));
if (StringUtil.isEmpty(contentObj.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "Content对象内容保存失败");
}
// 内容保存
cmsContent.setCategoryId(Const.CMS_CATEGORY_ID_4);
// 上级id
cmsContent.setParentId(Const.CMS_CATEGORY_ID_4);
cmsContent.setPath("0");
// 内容id
cmsContent.setMid(contentObj.getId());
// 作者类型
cmsContent.setAuthorType(Const.CMS_AUTHOR_TYPE_1);
// 作者id
cmsContent.setAuthorId(pmphUser.getId());
// 获取新增后的主键ID
Long contentId = this.addCmsContent(cmsContent).getId();
if (ObjectUtil.isNull(contentId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "CmsContent添加内容失败");
}
return cmsContent;
}
use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.
the class MaterialExtraServiceImpl method getMaterialExtraAndNoticeDetail.
/**
* <pre>
* 功能描述:根据教材ID查询教材通知详情及附件
* 使用示范:
*
* @param materialId 教材ID
* @return Map<String, Object> 集合
* @throws CheckedServiceException
* </pre>
*
* @throws UnsupportedEncodingException
*/
@Override
public Map<String, Object> getMaterialExtraAndNoticeDetail(Long materialId) throws CheckedServiceException {
if (ObjectUtil.isNull(materialId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材主键为空");
}
Map<String, Object> resultMap = new HashMap<String, Object>();
// 教材通知备注
MaterialExtra materialExtra = null;
// MongoDB中教材通知
String contentText = null;
// 联系人
List<MaterialContact> materialContacts = null;
// 教材通知附件
List<MaterialNoticeAttachment> materialNoticeAttachments = null;
// 教材备注附件
List<MaterialNoteAttachment> materialNoteAttachments = null;
// 教材
Material material = materialService.getMaterialById(materialId);
if (ObjectUtil.notNull(material)) {
// 联系人
materialContacts = materialContactService.listMaterialContactByMaterialId(materialId);
materialExtra = this.getMaterialExtraByMaterialId(materialId);
if (ObjectUtil.notNull(materialExtra)) {
Long materialExtraId = materialExtra.getId();
// 教材通知附件
materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
// 教材备注附件
materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
}
// 判断内容是否已经发布或审核通过
String fileNoticeDownLoadType = null;
String fileNoteDownLoadType = null;
if (Const.TRUE.booleanValue() == material.getIsPublished().booleanValue()) {
fileNoticeDownLoadType = Const.MATERIAL_NOTICE_FILE_DOWNLOAD;
fileNoteDownLoadType = Const.MATERIAL_NOTE_FILE_DOWNLOAD;
} else {
fileNoticeDownLoadType = Const.FILE_DOWNLOAD;
fileNoteDownLoadType = Const.FILE_DOWNLOAD;
}
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
Content content = contentService.get(cmsContent.getMid());
if (ObjectUtil.notNull(content)) {
contentText = content.getContent();
}
}
if (CollectionUtil.isNotEmpty(materialNoticeAttachments)) {
for (MaterialNoticeAttachment materialNoticeAttachment : materialNoticeAttachments) {
String attachment = materialNoticeAttachment.getAttachment();
// 拼接附件下载路径
materialNoticeAttachment.setAttachment(fileNoticeDownLoadType + attachment);
}
}
if (CollectionUtil.isNotEmpty(materialNoteAttachments)) {
for (MaterialNoteAttachment materialNoteAttachment : materialNoteAttachments) {
String attachment = materialNoteAttachment.getAttachment();
// 拼接附件下载路径
materialNoteAttachment.setAttachment(fileNoteDownLoadType + attachment);
}
}
}
// 教材
resultMap.put("materialName", material);
// 联系人
resultMap.put("materialContacts", materialContacts);
// 教材通知备注
resultMap.put("materialExtra", materialExtra);
// MongoDB中教材通知
resultMap.put("content", contentText);
// 教材通知附件
resultMap.put("materialNoticeAttachments", materialNoticeAttachments);
// 教材备注附件
resultMap.put("materialNoteAttachments", materialNoteAttachments);
return resultMap;
}
use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.
the class ContentService method update.
/**
* 更新Content对象
*
* @param content Content对象
*/
public void update(Content content) {
if (null == content) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容更新对象为空");
}
if (null == content.getId() || content.getId().isEmpty()) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "内容更新对象id为空");
}
if (null == content.getContent() || content.getContent().isEmpty()) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "Content更新对象内容为空");
}
Content ctn = get(content.getId());
if (null == ctn) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.OBJECT_NOT_FOUND, "未找到更新对象");
}
ctn.setContent(content.getContent());
contentDao.save(ctn);
}
use of com.bc.pmpheep.general.po.Content 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);
}
}
}
use of com.bc.pmpheep.general.po.Content in project pmph by BCSquad.
the class ContentServiceTest method delete.
@Test
public void delete() {
Content content = new Content(html);
Content cnt = contentService.add(content);
Assert.assertNotNull("插入内容后返回的Content.id不应为空", cnt.getId());
contentService.delete(cnt.getId());
Assert.assertNull("删除内容失败", contentService.get(cnt.getId()));
}
Aggregations