use of com.bc.pmpheep.back.po.MaterialExtra 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.MaterialExtra in project pmph by BCSquad.
the class MigrationStageFour method materialExtra.
protected void materialExtra() {
String sql = "select " + "new_pk, " + "introduction, " + "remark " + "from teach_material ";
// 获取到所有数据表
List<Map<String, Object>> materialExtraList = JdbcHelper.getJdbcTemplate().queryForList(sql);
int count = 0;
List<Map<String, Object>> excel = new LinkedList<>();
List<Long> materids = new ArrayList<>();
Map<String, Object> result = new LinkedHashMap<>();
// 统计正常数据的数量
int correctCount = 0;
// 判断该数据是否有相应异常状况的标识;
int[] state = { 0, 0, 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 : materialExtraList) {
StringBuilder exception = new StringBuilder();
Long materid = (Long) object.get("new_pk");
String matername = (materid == null ? "" : materialService.getMaterialNameById(materid));
if (ObjectUtil.isNull(materid)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id为空。"));
excel.add(object);
excptionList.add(new Object[] { matername, "找不到对应的教材", "新建的教材已删除", "不导入该条数据" });
if (state[0] == 0) {
reason.append("找不到教材的唯一标识。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
if (materids.contains(materid)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id重复。"));
excel.add(object);
if (state[1] == 0) {
reason.append("教材唯一标识重复。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
String notice = (String) object.get("introduction");
if (StringUtil.isEmpty(notice)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("通知内容为空。"));
excel.add(object);
notice = "-";
excptionList.add(new Object[] { matername, "教材通知内容为空", "原专家平台或者在运平台没有填写通知内容", "设置为'-'导入新库表" });
if (state[2] == 0) {
reason.append("找不到教材的通知内容。");
dealWith.append("设为默认值迁入数据库。");
state[2] = 1;
}
}
String note = (String) object.get("remark");
if (StringUtil.isEmpty(note)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("备注。"));
excel.add(object);
if (state[3] == 0) {
reason.append("找不到教材的备注内容。");
dealWith.append("备注可以为空,照常迁入数据路。");
state[3] = 1;
}
// note="-";
// excptionList.add(new
// Object[]{matername,"教材备注内容为空","原专家平台或者在运平台没有填写通知备注","设置为'-'导入新库表"});
}
MaterialExtra materialExtra = new MaterialExtra();
materialExtra.setMaterialId(materid);
materialExtra.setNotice(notice);
materialExtra.setNote(note);
materialExtra = materialExtraService.addMaterialExtra(materialExtra);
count++;
mps.put(materialExtra.getMaterialId(), materialExtra.getId());
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_extra");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != materialExtraList.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_extra");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材通知备注表");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, materialExtraList.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, materialExtraList.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("'{}'表迁移完成,异常条目数量:{}", "material_extra", count);
// 记录信息
Map<String, Object> msg = new HashMap<String, Object>();
msg.put("result", "material_extra 表迁移完成" + count + "/" + materialExtraList.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.MaterialExtra in project pmph by BCSquad.
the class MigrationStageFour method addMaterialCommunity.
protected void addMaterialCommunity() {
// 保存教材社区相关的信息
for (Material material : materials) {
MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
if (null == materialExtra) {
materialExtra = new MaterialExtra();
}
String detail = "<p>简介:驱蚊器</p>" + "<p><br/></p>" + "<p>邮寄地址:驱蚊器翁</p>" + "<p><br/></p>" + "<p>联 系 人:陈慧 (电话:18610032992,Emali:147258369@qq.com)</p>" + "<p><br/>/p>";
detail = detail + "<p>简介:" + null == materialExtra.getNotice() ? "" : materialExtra.getNotice() + "</p>";
detail = detail + "<p><br/></p><p>邮寄地址:" + material.getMailAddress() + "</p>";
List<MaterialContact> materialContacts = materialContactService.listMaterialContactByMaterialId(material.getId());
for (MaterialContact materialContact : materialContacts) {
detail = detail + "<p><br/></p><p>联 系 人:" + materialContact.getContactUserName() + " (电话:" + materialContact.getContactPhone() + ",Emali:" + materialContact.getContactEmail() + ")</p>";
}
Content content = new Content(detail);
content = contentService.add(content);
CmsContent cmsContent = new CmsContent();
cmsContent.setParentId(0L);
cmsContent.setPath("0");
cmsContent.setMid(content.getId());
cmsContent.setCategoryId(3L);
cmsContent.setTitle(material.getMaterialName());
cmsContent.setAuthorType(new Short("0"));
cmsContent.setAuthorId(material.getFounderId());
cmsContent.setIsPublished(material.getIsPublished());
cmsContent.setAuthStatus(material.getIsPublished() ? new Short("2") : new Short("0"));
cmsContent.setAuthDate(DateUtil.date2Str(material.getGmtUpdate() == null ? material.getGmtCreate() : material.getGmtUpdate()));
cmsContent.setAuthUserId(material.getFounderId());
cmsContent.setGmtCreate(material.getGmtCreate());
cmsContent.setGmtUpdate(material.getGmtUpdate() == null ? material.getGmtCreate() : material.getGmtUpdate());
cmsContent.setIsMaterialEntry(true);
cmsContent.setMaterialId(material.getId());
cmsContentService.addCmsContent(cmsContent);
}
}
use of com.bc.pmpheep.back.po.MaterialExtra in project pmph by BCSquad.
the class MigrationStageTen method materialNotice.
public void materialNotice() {
List<Material> materials = materialService.getListMaterial("轮");
List<CmsCategory> categorys = cmsCategoryService.getCmsCategoryListByCategoryName("公告");
Long categoryId = categorys.get(0).getId();
final String html = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$f</span></strong>$d</p>";
final String htmlS1 = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$d</span></strong></p>";
final String htmlS2 = "<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; padding: 0px;\">$d</p>";
for (Material material : materials) {
CmsContent cmsContent = new CmsContent();
cmsContent.setParentId(0L);
cmsContent.setCategoryId(categoryId);
cmsContent.setPath("0");
cmsContent.setTitle(material.getMaterialName());
cmsContent.setAuthorType((short) 0);
cmsContent.setMaterialId(material.getId());
/* 生成通知内容 */
StringBuilder sb = new StringBuilder();
String str = html.replace("$f", "截止日期:");
str = str.replace("$d", sdf.format(material.getDeadline()));
sb.append(str);
/* 获取教材联系人 */
List<MaterialContact> contacts = materialContactService.listMaterialContactByMaterialId(categoryId);
if (CollectionUtil.isNotEmpty(contacts)) {
str = htmlS1.replace("$f", "联系人:");
sb.append(str);
for (MaterialContact contact : contacts) {
/* 裴中惠 (电话:010-59787110 , Email:pzh@pmph.com) */
StringBuilder builder = new StringBuilder(contact.getContactUserName());
builder.append(" (电话:");
builder.append(contact.getContactPhone());
builder.append(" , Email:");
builder.append(contact.getContactEmail());
builder.append(")");
str = htmlS2.replace("$d", builder.toString());
sb.append(str);
}
}
str = html.replace("$f", "邮寄地址:");
str = str.replace("$d", material.getMailAddress());
sb.append(str);
/* 获取通知内容和备注 */
MaterialExtra extra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
str = htmlS1.replace("$d", "简 介:");
sb.append(str);
if (null != extra) {
// str = htmlS2.replace("$d", extra.getNotice()) /* 存入MongoDB */
}
Content content = new Content(sb.toString());
content = contentService.add(content);
cmsContent.setMid(content.getId());
}
}
use of com.bc.pmpheep.back.po.MaterialExtra in project pmph by BCSquad.
the class CmsContentServiceImpl method getCmsContentAndContentAndAttachmentById.
@Override
public Map<String, Object> getCmsContentAndContentAndAttachmentById(Long id) throws CheckedServiceException {
Map<String, Object> resultMap = new HashMap<String, Object>();
if (ObjectUtil.isNull(id)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
// 按id 获取CmsContent对象
CmsContent cmsContent = cmsContentDao.getCmsContentById(id);
String authDate = cmsContent.getAuthDate();
if (StringUtil.notEmpty(authDate)) {
cmsContent.setAuthDate(DateUtil.date2Str(DateUtil.str2Date(authDate)));
}
String deadlinePromote = cmsContent.getDeadlinePromote();
if (StringUtil.notEmpty(deadlinePromote)) {
cmsContent.setDeadlinePromote(DateUtil.date2Str(DateUtil.str2Date(deadlinePromote)));
}
String deadlineStick = cmsContent.getDeadlineStick();
if (StringUtil.notEmpty(deadlineStick)) {
cmsContent.setDeadlineStick(DateUtil.date2Str(DateUtil.str2Date(deadlineStick)));
}
String deadlineHot = cmsContent.getDeadlineHot();
if (StringUtil.notEmpty(deadlineHot)) {
cmsContent.setDeadlineHot(DateUtil.date2Str(DateUtil.str2Date(deadlineHot)));
}
resultMap.put("cmsContent", cmsContent);
// 判断内容是否已经发布或审核通过
String fileDownLoadType = null;
if (cmsContent.getIsPublished() || Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue()) {
fileDownLoadType = Const.CMS_FILE_DOWNLOAD;
} else {
fileDownLoadType = Const.FILE_DOWNLOAD;
}
// 按mid 获取Content对象
Content content = contentService.get(cmsContent.getMid());
if (ObjectUtil.isNull(content)) {
content = new Content();
content.setId(cmsContent.getMid());
content.setContent("");
}
resultMap.put("content", content);
// 按contentId 获取CMS内容附件
List<CmsExtra> cmsExtras = cmsExtraService.getCmsExtraByContentId(id);
List<CmsExtra> cmsList = new ArrayList<CmsExtra>(cmsExtras.size());
for (CmsExtra cmsExtra : cmsExtras) {
String attachment = cmsExtra.getAttachment();
if (!attachment.equals(cmsContent.getCover())) {
// 拼接附件下载路径
cmsExtra.setAttachment(fileDownLoadType + attachment);
cmsList.add(cmsExtra);
}
}
resultMap.put("cmsExtras", cmsList);
// 根据MaterialId 获取教材备注附件
List<MaterialNoteAttachment> materialNoteAttachments = null;
if (cmsContent.getIsMaterialEntry()) {
MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(cmsContent.getMaterialId());
if (ObjectUtil.notNull(materialExtra)) {
// 教材备注附件
materialNoteAttachments = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
}
}
resultMap.put("MaterialNoteAttachment", materialNoteAttachments);
if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue()) {
// 文章封面图片
CmsExtra cmsExtra = cmsExtraService.getCmsExtraByAttachment(cmsContent.getCover());
String imgFileName = "默认封面.png";
String imgFilePath = RouteUtil.DEFAULT_USER_AVATAR;
if (ObjectUtil.notNull(cmsExtra)) {
imgFileName = cmsExtra.getAttachmentName();
} else {
GridFSDBFile file = fileService.get(cmsContent.getCover());
if (ObjectUtil.notNull(file)) {
imgFileName = file.getFilename();
}
}
resultMap.put("imgFileName", imgFileName);
if (!"DEFAULT".equals(cmsContent.getCover())) {
imgFilePath = cmsContent.getCover();
}
resultMap.put("imgFilePath", imgFilePath);
}
return resultMap;
}
Aggregations