use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class CmsExtraServiceTest method testDeleteCmsExtraById.
@Test
public void testDeleteCmsExtraById() {
CmsExtra cmsExtra = this.addCmsExtra();
Assert.assertTrue("是否删除成功", cmsExtraService.deleteCmsExtraById(cmsExtra.getId()) > 0);
CmsExtra ce = this.addCmsExtra();
List<Long> idList = new ArrayList<Long>(1);
idList.add(ce.getId());
Assert.assertTrue("批量删除是否成功", cmsExtraService.deleteCmsExtraByIds(idList) > 0);
}
use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class CmsExtraServiceTest method testGetCmsExtraById.
@Test
public void testGetCmsExtraById() {
CmsExtra cmsExtra = this.addCmsExtra();
CmsExtra cms = cmsExtraService.getCmsExtraById(cmsExtra.getId());
logger.info(cms.toString());
Assert.assertNotNull("按ID查询是否该对象", cms);
}
use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class CmsExtraServiceTest method testAddCmsExtra.
/**
* <pre>
* 功能描述:add 方法测试
* 使用示范:
*
* </pre>
*/
@Test
public void testAddCmsExtra() {
CmsExtra cmsExtra = this.addCmsExtra();
logger.info(cmsExtra.toString());
Assert.assertNotNull("插入内容后返回的CmsExtra.id不应为空", cmsExtra.getId());
}
use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class MaterialExtraServiceImpl method updateMaterialExtraAndNoticeFile.
/**
* <pre>
* 功能描述:编辑通知详情
* 使用示范:
*
* @param materialExtraVO MaterialExtraVO
* @return Map<String, Object>集合
* @throws CheckedServiceException
* </pre>
*/
@Override
public Integer updateMaterialExtraAndNoticeFile(MaterialExtraVO materialExtraVO) throws CheckedServiceException, IOException {
// 教材ID
Long materialId = materialExtraVO.getMaterialId();
if (ObjectUtil.isNull(materialId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
}
String materialName = materialExtraVO.getMaterialName();
if (StringUtil.isEmpty(materialName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材名称为空");
}
String content = materialExtraVO.getContent();
if (StringUtil.isEmpty(content)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知为空");
}
// MongoDB 内容插入
Content contentObj = contentService.add(new Content(content));
if (ObjectUtil.isNull(contentObj)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.OBJECT_NOT_FOUND, "教材通知保存失败");
}
Material material = materialService.getMaterialById(materialId);
if (StringUtil.isEmpty(materialExtraVO.getContent())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "教材通知内容为空");
}
// 内容ID
Long cmsContentId = null;
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
cmsContentId = cmsContent.getId();
String mid = null;
if (StringUtil.notEmpty(cmsContent.getMid())) {
mid = cmsContent.getMid();
}
// 存在就更新
Integer count = cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), contentObj.getId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
if (count > 0) {
// 删除之前教材通知内容
contentService.delete(mid);
}
} else {
// 保存CMSContent内容
CmsContent cmsContentObj = cmsContentService.addCmsContent(new CmsContent(0L, "0", contentObj.getId(), materialName, Const.CMS_AUTHOR_TYPE_0, false, true, material.getFounderId(), DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()), materialId, Const.CMS_CATEGORY_ID_3, Const.TRUE, "DEFAULT"));
if (ObjectUtil.isNull(cmsContentObj.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "创建教材通知公告失败");
}
cmsContentId = cmsContentObj.getId();
}
// 先删除教材通知附件
List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(cmsContentId);
if (CollectionUtil.isNotEmpty(cmsExtras)) {
List<Long> cmsExtraIds = new ArrayList<Long>();
for (CmsExtra cmsExtra : cmsExtras) {
cmsExtraIds.add(cmsExtra.getId());
}
cmsExtraService.deleteCmsExtraByIds(cmsExtraIds);
}
// 教材通知附件
List<MaterialNoticeAttachment> materialNoticeAttachments = null;
// 教材备注附件
List<MaterialNoteAttachment> materialNoteAttachments = null;
// 教材通知备注
MaterialExtra materialExtra = this.getMaterialExtraByMaterialId(materialId);
if (ObjectUtil.notNull(materialExtra)) {
Long materialExtraId = materialExtra.getId();
if (ObjectUtil.notNull(materialExtraId)) {
// 教材通知附件
materialNoticeAttachments = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtraId);
// 教材备注附件
materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtraId);
// 教材通知附件保存到CMS附件表中
for (MaterialNoticeAttachment mna : materialNoticeAttachments) {
cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, mna.getAttachment(), mna.getAttachmentName(), 0L));
}
for (MaterialNoteAttachment ma : materialNoteAttachments) {
cmsExtraService.addCmsExtra(new CmsExtra(cmsContentId, ma.getAttachment(), ma.getAttachmentName(), 0L));
}
}
}
// 教材通知附件
// String[] noticeFiles = materialExtraVO.getNoticeFiles();
// if (ArrayUtil.isNotEmpty(noticeFiles)) {
// this.saveFileToMongoDB(noticeFiles, materialExtraId, NOTICE);
// }
// 教材通知附件MongoDB对应ID
String[] noticeAttachments = materialExtraVO.getNoticeAttachments();
if (ArrayUtil.isNotEmpty(noticeAttachments)) {
// 删除MaterialNoticeAttachment 表
materialNoticeAttachmentService.deleteMaterialNoticeAttachmentByAttachments(noticeAttachments);
// 删除MongoDB对应的文件
for (int i = 0; i < noticeAttachments.length; i++) {
fileService.remove(noticeAttachments[i]);
}
}
// 教材备注附件
// String[] noteFiles = materialExtraVO.getNoteFiles();
// if (ArrayUtil.isNotEmpty(noteFiles)) {
// this.saveFileToMongoDB(noteFiles, materialExtraId, NOTE);
// }
// 教材备注附件MongoDB对应ID
String[] noteAttachments = materialExtraVO.getNoteAttachments();
if (ArrayUtil.isNotEmpty(noteAttachments)) {
// 删除MaterialNoteAttachment 表
materialNoteAttachmentService.deleteMaterialNoteAttachmentByAttachments(noteAttachments);
// 删除MongoDB对应的文件
for (int i = 0; i < noteAttachments.length; i++) {
fileService.remove(noteAttachments[i]);
}
}
return 1;
}
use of com.bc.pmpheep.back.po.CmsExtra in project pmph by BCSquad.
the class CmsContentServiceImpl method saveFileToMongoDB.
/**
* <pre>
* 功能描述:保存文件到MongoDB
* 使用示范:
*
* @param files 临时文件路径
* @param contentId cms内容ID
* @throws CheckedServiceException
* </pre>
*/
private void saveFileToMongoDB(HttpServletRequest request, String[] files, String[] imgFile, Long contentId) throws CheckedServiceException, IOException {
// 保存附件到MongoDB
if (ArrayUtil.isNotEmpty(files)) {
for (int i = 0; i < files.length; i++) {
byte[] fileByte = (byte[]) request.getSession(false).getAttribute(files[i]);
String fileName = (String) request.getSession(false).getAttribute("fileName_" + files[i]);
InputStream sbs = new ByteArrayInputStream(fileByte);
String gridFSFileId = fileService.save(sbs, fileName, FileType.CMS_ATTACHMENT, contentId);
if (StringUtil.isEmpty(gridFSFileId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
}
// 保存对应数据
CmsExtra cmsExtra = cmsExtraService.addCmsExtra(new CmsExtra(contentId, gridFSFileId, fileName, null));
if (ObjectUtil.isNull(cmsExtra.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "CmsExtra对象新增失败");
}
}
}
if (ArrayUtil.isNotEmpty(imgFile)) {
for (int i = 0; i < imgFile.length; i++) {
byte[] fileByte = (byte[]) request.getSession(false).getAttribute(imgFile[i]);
String gridFSFileId = imgFile[i];
if (ObjectUtil.notNull(fileByte)) {
String fileName = (String) request.getSession(false).getAttribute("fileName_" + imgFile[i]);
InputStream sbs = new ByteArrayInputStream(fileByte);
gridFSFileId = fileService.save(sbs, fileName, ImageType.CMS_CONTENT_COVER_IMG, contentId);
if (StringUtil.isEmpty(gridFSFileId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
}
// 保存对应数据
CmsExtra cmsExtra = cmsExtraService.addCmsExtra(new CmsExtra(contentId, gridFSFileId, fileName, null));
if (ObjectUtil.isNull(cmsExtra.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.PO_ADD_FAILED, "上传封面失败");
}
}
// 更新封面ID
this.updateCmsContent(new CmsContent(contentId, gridFSFileId));
}
}
}
Aggregations