use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class CmsContentServiceImpl method deleteCmsContentById.
@Override
public Integer deleteCmsContentById(Long id) throws CheckedServiceException {
if (ObjectUtil.isNull(id)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
List<CmsContent> list = this.getCmsContentByParentId(id);
List<Long> ids = new ArrayList<Long>(list.size());
for (CmsContent cmsContent : list) {
ids.add(cmsContent.getId());
}
Integer count = 0;
count = cmsContentDao.deleteCmsContentById(id);
if (CollectionUtil.isNotEmpty(ids)) {
count = this.deleteCmsContentByIds(ids);
}
return count;
}
use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class CmsContentServiceImpl method updateCmsContent.
@Override
public Integer updateCmsContent(CmsContent cmsContent, String[] files, String[] imgFile, String content, String[] attachment, String[] imgAttachment, String scheduledTime, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
Integer count = 0;
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (StringUtil.notEmpty(content)) {
// 更新MongoDB 内容
contentService.update(new Content(cmsContent.getMid(), content));
}
if (ObjectUtil.isNull(cmsContent)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (ObjectUtil.isNull(cmsContent.getMaterialId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
}
// 信息快报/公告管理(发布),审核时间就为当前时间
if (Const.CMS_AUTHOR_STATUS_2 == cmsContent.getAuthStatus().shortValue()) {
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
cmsContent.setIsStaging(Const.FALSE);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsPublished(true);
} else if (Const.CMS_AUTHOR_STATUS_0 == cmsContent.getAuthStatus().shortValue()) {
if (cmsContent.getIsStaging()) {
// 信息快报/公告管理(暂存)
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_0);
cmsContent.setAuthDate(null);
cmsContent.setIsPublished(false);
}
} else if (Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
// 文章管理,退回
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_1);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsDeleted(false);
cmsContent.setIsPublished(false);
}
if (cmsContent.getCategoryId() == Const.CMS_CATEGORY_ID_1 && cmsContent.getAuthorType() == Const.CMS_AUTHOR_TYPE_2 && cmsContent.getAuthStatus() == Const.CMS_AUTHOR_STATUS_0 && Const.TRUE == cmsContent.getIsStaging()) {
cmsContent.setIsStaging(false);
}
// 再次编辑时间
cmsContent.setGmtReedit(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
// 撤销
if (null != cmsContent.getIsPublished()) {
cmsContent.setIsStaging(cmsContent.getIsPublished());
} else {
cmsContent.setIsStaging(false);
}
count = cmsContentDao.updateCmsContent(cmsContent);
if (// 内容管理,退回发送消息
count > 0 && Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
// MongoDB 消息插入
String categoryName = "文章管理";
if (Const.CMS_CATEGORY_ID_2.longValue() == cmsContent.getCategoryId().longValue()) {
categoryName = "信息快报管理";
} else if (Const.CMS_CATEGORY_ID_3.longValue() == cmsContent.getCategoryId().longValue()) {
categoryName = "公告管理";
}
// 退回时发送消息内容
StringBuilder sb = new StringBuilder();
sb.append(categoryName);
sb.append("中您添加的《 ");
sb.append(cmsContent.getTitle());
sb.append(" 》已被退回 !");
if (StringUtil.notEmpty(cmsContent.getReturnReason())) {
sb.append("<br/><br/>退回理由为:");
sb.append(cmsContent.getReturnReason());
}
Message message = messageService.add(new Message(sb.toString()));
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
String returnContentTitle = "内容管理审核退回";
// 系统消息
List<UserMessage> userMessageList = new ArrayList<UserMessage>(4);
userMessageList.add(new UserMessage(message.getId(), returnContentTitle, Const.MSG_TYPE_1, pmphUser.getId(), Const.SENDER_TYPE_1, cmsContent.getAuthorId(), cmsContent.getAuthorType(), 0L));
// 发送消息
if (CollectionUtil.isNotEmpty(userMessageList)) {
// 插入消息发送对象数据
userMessageService.addUserMessageBatch(userMessageList);
// websocket发送的id集合
List<String> websocketUserIds = new ArrayList<String>();
for (UserMessage userMessage : userMessageList) {
websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
}
// webscokt发送消息
if (CollectionUtil.isNotEmpty(websocketUserIds)) {
WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, pmphUser.getId(), pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, returnContentTitle, message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
}
}
}
// 当文章通过的时候给用户增加积分
if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue() && Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue() && Const.CMS_AUTHOR_TYPE_2 == cmsContent.getAuthorType()) {
String ruleName = "发表文章";
writerPointLogService.addWriterPointLogByRuleName(ruleName, cmsContent.getAuthorId());
}
// 删除附件
if (ArrayUtil.isNotEmpty(attachment)) {
// 删除CmsExtra 表
cmsExtraService.deleteCmsExtraByAttachment(attachment);
// 删除MongoDB对应的文件
for (int i = 0; i < attachment.length; i++) {
fileService.remove(attachment[i]);
}
}
// 文章封面
if (ArrayUtil.isNotEmpty(imgAttachment)) {
// 删除CmsExtra 表
cmsExtraService.deleteCmsExtraByAttachment(imgAttachment);
// 删除MongoDB对应的文件
for (int i = 0; i < imgAttachment.length; i++) {
fileService.remove(imgAttachment[i]);
}
if (ArrayUtil.isEmpty(imgFile)) {
// 如果删除了封面没上传,就使用默认封面
this.updateCmsContent(new CmsContent(cmsContent.getId(), "DEFAULT"));
}
}
// 保存附件到MongoDB
this.saveFileToMongoDB(request, files, imgFile, cmsContent.getId());
return count;
}
use of com.bc.pmpheep.back.po.CmsContent 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.CmsContent in project pmph by BCSquad.
the class MaterialExtraServiceImpl method noticePublished.
@Override
public Integer noticePublished(Long materialId, List<Long> orgIds, String sessionId) throws CheckedServiceException, IOException {
if (CollectionUtil.isEmpty(orgIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "机构为空");
}
// 防止网络延迟重复提交
Set<Long> newOrgIdSet = new HashSet<>();
newOrgIdSet.addAll(orgIds);
List<Long> listOrgIds = new ArrayList<Long>(newOrgIdSet.size());
listOrgIds.addAll(newOrgIdSet);
// 获取当前用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
}
Integer count = 0;
List<MaterialOrg> materialOrgList = new ArrayList<MaterialOrg>(listOrgIds.size());
// 根据教材ID查询教材-机构关联表
List<Long> OrgIds = materialOrgService.getListMaterialOrgByMaterialId(materialId);
if (CollectionUtil.isEmpty(OrgIds)) {
// 为空,初次发布
for (Long orgId : listOrgIds) {
materialOrgList.add(new MaterialOrg(materialId, orgId));
}
count = materialOrgService.addMaterialOrgs(materialOrgList);
if (count > 0) {
systemMessageService.materialSend(materialId, listOrgIds);
}
} else {
// 不为空
// 新选中的机构
List<Long> newOrgIds = new ArrayList<Long>();
for (Long orgId : listOrgIds) {
if (!OrgIds.contains(orgId)) {
newOrgIds.add(orgId);
materialOrgList.add(new MaterialOrg(materialId, orgId));
}
}
if (CollectionUtil.isEmpty(materialOrgList)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.ILLEGAL_PARAM, "当前选中的学校已收到消息,无需要再次发送");
}
count = materialOrgService.addMaterialOrgs(materialOrgList);
if (count > 0) {
systemMessageService.materialSend(materialId, newOrgIds);
}
}
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA,
// CheckedExceptionResult.NULL_PARAM, "没有找到对应的教材通知信息");
cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), true, false, Const.CMS_AUTHOR_STATUS_2, // authUserId
0L, // 为0代表系统审核
DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
}
count = materialService.updateMaterial(new Material(materialId, true), sessionId);
return count;
}
use of com.bc.pmpheep.back.po.CmsContent in project pmph by BCSquad.
the class MaterialServiceImpl method addOrUpdateMaterial.
@Override
public Long addOrUpdateMaterial(HttpServletRequest request, MaterialVO materialVO, // MultipartFile[] noteFiles,
boolean isUpdate) throws CheckedServiceException, IOException {
if (null == request.getSession(false)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "会话过期");
}
// 获取当前用户
String sessionId = CookiesUtil.getSessionId(request);
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
}
Material material = materialVO.getMaterial();
// 如果是更新教材,判断主键
if (isUpdate && (null == material.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材更新时主键为空");
}
// 教材名称的验证
if (StringUtil.isEmpty(material.getMaterialName())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材名称为空");
}
if (material.getMaterialName().length() > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材名称过长");
}
// 教材轮次验证
if (null == material.getMaterialRound()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材轮次为空");
}
// 显示报名截止时间
if (null == material.getDeadline()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "显示报名截止时间为空");
}
// 如果是新建教材,显示报名截止时间必须大于当前时间
if (!isUpdate && material.getDeadline().getTime() <= new Date().getTime()) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
// CheckedExceptionResult.ILLEGAL_PARAM,
// "显示报名截止时间必须大于当前时间");
}
// 实际报名截止日期
if (null == material.getActualDeadline()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "实际报名截止日期为空");
}
// 如果是新建教材,实际报名截止日期必须大于当前时间
if (!isUpdate && material.getActualDeadline().getTime() <= new Date().getTime()) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
// CheckedExceptionResult.ILLEGAL_PARAM,
// "实际报名截止日期必须大于当前时间");
}
// 实际报名截止日期和显示报名截止时间比较
if (material.getActualDeadline().getTime() < material.getDeadline().getTime()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "实际报名截止日期不能小于显示报名截止时间");
}
// 年龄计算截止日期
if (null == material.getAgeDeadline()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "年龄计算截止日期为空");
}
// 邮寄地址验证
if (StringUtil.isEmpty(material.getMailAddress())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "邮寄地址为空");
}
if (material.getMailAddress().length() > 100) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "邮寄地址过长");
}
// 教材类型验证
String materialType = materialVO.getMaterialType();
if (StringUtil.isEmpty(materialType) || "[]".equals(materialType.replace(" ", "")) || "[NaN]".equals(materialType.replace(" ", ""))) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材类型为空");
}
if (null == material.getDirector()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材主任为空");
}
// 教材通知备注内容验证
MaterialExtra materialExtra = materialVO.getMaterialExtra();
if (StringUtil.isEmpty(materialExtra.getNotice())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材通知内容为空");
}
if (materialExtra.getNotice().length() > 2000) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材通知内容过长");
}
// }
if ("null".equals(materialExtra.getNote()) || "[]".equals(materialExtra.getNote())) {
materialExtra.setNote("");
}
if (null != materialExtra.getNote() && materialExtra.getNote().length() > 2000) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材备注内容过长");
}
Gson gson = new Gson();
// 获取主任
PmphUser director = pmphUserService.get(material.getDirector());
if (null == director) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "找不到对应的主任");
} else if (null == director.getDepartmentId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "主任对应的机构为空");
}
// //给主任添加角色
// String roleName="主任";//通过roleName查询roleid
// List<PmphRole> pmphRoles=pmphRoleService.getList(roleName);
// if (ObjectUtil.isNull(material.getDirector()) ||
// ObjectUtil.isNull(pmphRoles.get(0).getId())) {
// throw new CheckedServiceException(CheckedExceptionBusiness.ROLE_MANAGEMENT,
// CheckedExceptionResult.NULL_PARAM, "角色ID或主任ID为空时禁止新增");
// }
// //先查看该主任是否已有主任角色 没有则新加
// List<PmphUserRole>
// pmphUserRoles=pmphRoleService.getUserRoleList(material.getDirector(),pmphRoles.get(0).getId());
// if(ObjectUtil.isNull(pmphUserRoles)&&pmphUserRoles.size() == 0){
// pmphRoleService.addUserRole(material.getDirector(),
// pmphRoles.get(0).getId());
// }
// 教材所属部门
material.setDepartmentId(director.getDepartmentId());
// 修改人
material.setMenderId(pmphUser.getId());
// 教材类型
List<Long> materialTypeList = gson.fromJson(materialType, new TypeToken<ArrayList<Long>>() {
}.getType());
material.setMaterialType(materialTypeList.get(materialTypeList.size() - 1));
// 设置权限
material.setPlanPermission(Integer.valueOf(materialVO.getCehuaPowers(), 2));
material.setProjectPermission(Integer.valueOf(materialVO.getProjectEditorPowers(), 2));
// 保存或者更新教材
if (isUpdate) {
materialDao.updateMaterial(material);
} else {
// 创建人
material.setFounderId(pmphUser.getId());
materialDao.addMaterial(material);
}
Long materialId = material.getId();
// 扩展项转换
List<MaterialExtension> oldMaterialExtensionlist = materialExtensionService.getMaterialExtensionByMaterialId(materialId);
String newMaterialExtensionIds = ",";
String materialExtensions = materialVO.getMaterialExtensions();
if (!StringUtil.isEmpty(materialExtensions)) {
List<MaterialExtension> materialExtensionlist = gson.fromJson(materialExtensions, new TypeToken<ArrayList<MaterialExtension>>() {
}.getType());
for (MaterialExtension materialExtension : materialExtensionlist) {
if (null == materialExtension) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "扩展项对象为空");
}
if (StringUtil.isEmpty(materialExtension.getExtensionName())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "扩展项名称为空");
}
if (materialExtension.getExtensionName().length() > 100) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "扩展项名称太长");
}
materialExtension.setMaterialId(materialId);
if (null == materialExtension.getId()) {
// 保存或者修改扩展项
materialExtensionService.addMaterialExtension(materialExtension);
} else {
materialExtensionService.updateMaterialExtension(materialExtension);
}
newMaterialExtensionIds += materialExtension.getId() + ",";
}
}
for (MaterialExtension oldMaterialExtension : oldMaterialExtensionlist) {
// 删除删除的MaterialExtension
if (!newMaterialExtensionIds.contains("," + oldMaterialExtension.getId() + ",")) {
// 不包含
// 删除扩展项
materialExtensionService.deleteMaterialExtensionById(oldMaterialExtension.getId());
// 删除扩展值
decExtensionService.deleteDecExtensionByExtensionId(oldMaterialExtension.getId());
}
}
// 联系人转换
String materialContacts = materialVO.getMaterialContacts();
// 删除已经有的联系人
materialContactService.deleteMaterialContactsByMaterialId(materialId);
if (StringUtil.isEmpty(materialContacts)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材联系人参数有误");
}
List<MaterialContact> materialContactlist = gson.fromJson(materialContacts, new TypeToken<ArrayList<MaterialContact>>() {
}.getType());
if (null == materialContactlist || materialContactlist.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材联系人为空");
}
for (MaterialContact materialContact : materialContactlist) {
if (null == materialContact) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材联系人对象为空");
}
if (null == materialContact.getContactUserId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系人为空");
}
if (StringUtil.isEmpty(materialContact.getContactUserName())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系人姓名为空");
}
if (materialContact.getContactUserName().length() > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系人姓名太长");
}
if (StringUtil.isEmpty(materialContact.getContactPhone())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系电话为空");
}
if (materialContact.getContactPhone().length() > 25) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系电话太长");
}
if (StringUtil.isEmpty(materialContact.getContactEmail())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系邮箱为空");
}
if (materialContact.getContactEmail().length() > 40) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "联系邮箱太长");
}
if (null == materialContact.getSort()) {
materialContact.setSort(999);
}
materialContact.setMaterialId(materialId);
// 保存联系人
materialContactService.addMaterialContact(materialContact);
}
// 项目编辑转换
// 先删除该教材下的项目编辑
materialProjectEditorService.deleteMaterialProjectEditorByMaterialId(materialId);
String materialProjectEditors = materialVO.getMaterialProjectEditors();
if (StringUtil.isEmpty(materialProjectEditors)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "教材项目编辑参数有误");
}
List<MaterialProjectEditorVO> materialProjectEditorVOlist = gson.fromJson(materialProjectEditors, new TypeToken<ArrayList<MaterialProjectEditorVO>>() {
}.getType());
for (MaterialProjectEditorVO materialProjectEditorVO : materialProjectEditorVOlist) {
if (null == materialProjectEditorVO || null == materialProjectEditorVO.getEditorId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "项目编辑为空");
}
MaterialProjectEditor materialProjectEditor = new MaterialProjectEditor();
materialProjectEditor.setEditorId(materialProjectEditorVO.getEditorId());
materialProjectEditor.setMaterialId(materialId);
// 保存项目编辑
materialProjectEditorService.addMaterialProjectEditor(materialProjectEditor);
// // 项目编辑绑定角色
// String rolename="项目编辑";//通过roleName查询roleid
// List<PmphRole> pmphRoleList=pmphRoleService.getList(rolename);
// if (ObjectUtil.isNull(materialId) ||
// ObjectUtil.isNull(pmphRoleList.get(0).getId())) {
// throw new CheckedServiceException(CheckedExceptionBusiness.ROLE_MANAGEMENT,
// CheckedExceptionResult.NULL_PARAM, "角色ID或项目编辑ID为空时禁止新增");
// }
// //判断该用户是否有项目编辑角色 若没有则新加
// List<PmphUserRole> pmphUserRoles2=pmphRoleService.getUserRoleList(materialId,
// pmphRoleList.get(0).getId());
// if(ObjectUtil.isNull(pmphUserRoles2) && pmphUserRoles2.size() == 0){
// roleDao.addUserRole(materialId, pmphRoleList.get(0).getId());//给项目编辑绑定角色
// }
}
// 保存教材通知备注
materialExtra.setMaterialId(materialId);
if (null == materialExtra.getId()) {
materialExtraService.addMaterialExtra(materialExtra);
} else {
materialExtraService.updateMaterialExtra(materialExtra);
}
// 保存通知附件
String materialNoticeAttachments = materialVO.getMaterialNoticeAttachments();
if (StringUtil.isEmpty(materialNoticeAttachments)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材通知附件为空");
}
List<MaterialNoticeAttachment> materialNoticeAttachmentlist = gson.fromJson(materialNoticeAttachments, new TypeToken<ArrayList<MaterialNoticeAttachment>>() {
}.getType());
// 原来有的通知附件
List<MaterialNoticeAttachment> oldMaterialNoticeAttachmentlist = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtra.getId());
String newTempNoticeFileIds = ",";
for (MaterialNoticeAttachment materialNoticeAttachment : materialNoticeAttachmentlist) {
if (null == materialNoticeAttachment.getId()) {
String tempFileId = materialNoticeAttachment.getAttachment();
byte[] fileByte = (byte[]) request.getSession(false).getAttribute(tempFileId);
String fileName = (String) request.getSession(false).getAttribute("fileName_" + tempFileId);
materialNoticeAttachment.setAttachment(String.valueOf(new Date().getTime()));
materialNoticeAttachment.setAttachmentName(fileName);
materialNoticeAttachment.setDownload(0L);
materialNoticeAttachment.setMaterialExtraId(materialExtra.getId());
// 保存通知
materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
String noticeId;
// 保存通知文件
InputStream sbs = new ByteArrayInputStream(fileByte);
noticeId = fileService.save(sbs, fileName, FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoticeAttachment.getId());
materialNoticeAttachment.setAttachment(noticeId);
// 更新通知
materialNoticeAttachmentService.updateMaterialNoticeAttachment(materialNoticeAttachment);
// 移除session的文件
// request.getSession(false).removeAttribute(tempFileId);
// request.getSession(false).removeAttribute("fileName_" + tempFileId);
} else {
newTempNoticeFileIds += materialNoticeAttachment.getId() + ",";
}
}
for (MaterialNoticeAttachment materialNoticeAttachment : oldMaterialNoticeAttachmentlist) {
if (!newTempNoticeFileIds.contains("," + materialNoticeAttachment.getId() + ",")) {
// 不包含
// 删除文件
fileService.remove(materialNoticeAttachment.getAttachment());
materialNoticeAttachmentService.deleteMaterialNoticeAttachmentById(materialNoticeAttachment.getId());
}
}
// 备注附件保存
String materialNoteAttachments = materialVO.getMaterialNoteAttachments();
if (StringUtil.isEmpty(materialNoteAttachments)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材备注附件为空");
}
List<MaterialNoteAttachment> materialNoteAttachmentList = gson.fromJson(materialNoteAttachments, new TypeToken<ArrayList<MaterialNoteAttachment>>() {
}.getType());
// 原来的备注文件
List<MaterialNoteAttachment> oldMaterialNoteAttachmentlist = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
String newTempNoteFileIds = ",";
for (MaterialNoteAttachment materialNoteAttachment : materialNoteAttachmentList) {
if (null == materialNoteAttachment.getId()) {
String tempFileId = materialNoteAttachment.getAttachment();
byte[] file = (byte[]) request.getSession(false).getAttribute(tempFileId);
String fileName = (String) request.getSession(false).getAttribute("fileName_" + tempFileId);
materialNoteAttachment.setAttachment(String.valueOf(new Date().getTime()));
materialNoteAttachment.setAttachmentName(fileName);
materialNoteAttachment.setDownload(0L);
materialNoteAttachment.setMaterialExtraId(materialExtra.getId());
// 保存备注
materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
String noticeId;
InputStream sbs = new ByteArrayInputStream(file);
// 保存备注文件
noticeId = fileService.save(sbs, fileName, FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoteAttachment.getId());
materialNoteAttachment.setAttachment(noticeId);
// 更新备注
materialNoteAttachmentService.updateMaterialNoteAttachment(materialNoteAttachment);
// 移除session的文件
// request.getSession().removeAttribute(tempFileId);
// request.getSession().removeAttribute("fileName_" + tempFileId);
} else {
newTempNoteFileIds += materialNoteAttachment.getId() + ",";
}
}
for (MaterialNoteAttachment materialNoteAttachment : oldMaterialNoteAttachmentlist) {
if (!newTempNoteFileIds.contains("," + materialNoteAttachment.getId() + ",")) {
// 不包含
// 删除文件
fileService.remove(materialNoteAttachment.getAttachment());
materialNoteAttachmentService.deleteMaterialNoteAttachmentById(materialNoteAttachment.getId());
}
}
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
String title = material.getMaterialName();
if (null != cmsContent && null != cmsContent.getTitle() && !title.equals(cmsContent.getTitle())) {
cmsContent.setTitle(title);
cmsContentService.updateCmsContent(cmsContent);
}
/**
* // 判断教材备注附件和教材通知附件 List<MaterialNoticeAttachment>
* materialNoticeAttachmentlist = new ArrayList<MaterialNoticeAttachment>(5);
* String materialNoticeAttachments=materialVO.getMaterialNoticeAttachments();
* if (!StringUtil.isEmpty(materialNoticeAttachments)) {
* materialNoticeAttachmentlist = gson.fromJson(materialNoticeAttachments, new
* TypeToken<ArrayList<MaterialNoticeAttachment>>() { }.getType()); } if (null
* != noticeFiles && noticeFiles.length > 0) { for (MultipartFile notice :
* noticeFiles) { if (null == notice || !(notice instanceof MultipartFile)) {
* throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.NULL_PARAM, "教材通知附件为空"); } if
* (notice.getName().length() > 80) { throw new
* CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.ILLEGAL_PARAM, "教材通知附件文件名过长"); } } } if ((null ==
* noticeFiles && materialNoticeAttachmentlist.size() == 0) ||
* (materialNoticeAttachmentlist.size() + noticeFiles.length == 0)) {//
* 已有的数量加上新增的数量 throw new
* CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.NULL_PARAM, "教材通知附件为空"); }
* List<MaterialNoteAttachment> materialNoteAttachmentList = new
* ArrayList<MaterialNoteAttachment>(5); String materialNoteAttachments =
* materialVO.getMaterialNoteAttachments(); if
* (!StringUtil.isEmpty(materialNoteAttachments)) { materialNoteAttachmentList =
* gson.fromJson(materialNoteAttachments, new
* TypeToken<ArrayList<MaterialNoteAttachment>>() { }.getType()); } if (null !=
* noteFiles && noteFiles.length > 0) { for (MultipartFile note : noteFiles) {
* if (null == note || !(note instanceof MultipartFile)) { throw new
* CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.NULL_PARAM, "教材备注附件为空"); } if (note.getName().length()
* > 80) { throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.ILLEGAL_PARAM, "教材备注附件文件名过长"); } } } if ((null ==
* noteFiles && materialNoteAttachmentList.size() == 0) ||
* (materialNoteAttachmentList.size() + noteFiles.length == 0)) {// 已有的数量加上新增的数量
* throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.NULL_PARAM, "教材备注附件为空"); } // 保存教材通知附件
* List<MaterialNoticeAttachment> oldMaterialNoticeAttachmentlist =
* materialNoticeAttachmentService
* .getMaterialNoticeAttachmentsByMaterialExtraId(materialExtra.getId()); String
* newMaterialNoticeAttachmentIds = ","; for (MaterialNoticeAttachment
* materialNoticeAttachment : materialNoticeAttachmentlist) { if (null ==
* materialNoticeAttachment.getId()) { throw new
* CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.NULL_PARAM, "教材通知id为空"); }
* newMaterialNoticeAttachmentIds += materialNoticeAttachment.getId() + ","; }
* if (null != noticeFiles && noticeFiles.length > 0) { for (MultipartFile
* notice : noticeFiles) { MaterialNoticeAttachment materialNoticeAttachment =
* new MaterialNoticeAttachment();
* materialNoticeAttachment.setAttachment("---------");
* materialNoticeAttachment.setAttachmentName(notice.getOriginalFilename());
* materialNoticeAttachment.setDownload(0L);
* materialNoticeAttachment.setMaterialExtraId(materialExtra.getId()); // 保存通知
* materialNoticeAttachmentService.addMaterialNoticeAttachment(materialNoticeAttachment);
* String noticeId; // 保存通知文件 noticeId = fileService.save(notice,
* FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoticeAttachment.getId());
*
* materialNoticeAttachment.setAttachment(noticeId); // 更新通知
* materialNoticeAttachmentService.updateMaterialNoticeAttachment(materialNoticeAttachment);
* newMaterialNoticeAttachmentIds += materialNoticeAttachment.getId() + ","; } }
* for (MaterialNoticeAttachment materialNoticeAttachment :
* oldMaterialNoticeAttachmentlist) { if
* (!newMaterialNoticeAttachmentIds.contains("," +
* materialNoticeAttachment.getId() + ",")) {// 不包含
* fileService.remove(materialNoticeAttachment.getAttachment()); // 删除文件
* materialNoticeAttachmentService
* .deleteMaterialNoticeAttachmentById(materialNoticeAttachment.getId()); } } //
* 保存教材备注附件 List<MaterialNoteAttachment> oldMaterialNoteAttachmentlist =
* materialNoteAttachmentService
* .getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId()); String
* newMaterialNoteAttachmentIds = ","; for (MaterialNoteAttachment
* materialNoteAttachment : materialNoteAttachmentList) { if (null ==
* materialNoteAttachment.getId()) { throw new
* CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
* CheckedExceptionResult.NULL_PARAM, "教材备注id为空"); }
* newMaterialNoteAttachmentIds += materialNoteAttachment.getId() + ","; } if
* (null != noteFiles && noteFiles.length > 0) { for (MultipartFile note :
* noteFiles) { MaterialNoteAttachment materialNoteAttachment = new
* MaterialNoteAttachment(); materialNoteAttachment.setAttachment("---------");
* materialNoteAttachment.setAttachmentName(note.getOriginalFilename());
* materialNoteAttachment.setDownload(0L);
* materialNoteAttachment.setMaterialExtraId(materialExtra.getId()); // 保存备注
* materialNoteAttachmentService.addMaterialNoteAttachment(materialNoteAttachment);
* String noticeId; // 保存备注文件 noticeId = fileService.save(note,
* FileType.MATERIAL_NOTICE_ATTACHMENT, materialNoteAttachment.getId());
* materialNoteAttachment.setAttachment(noticeId); // 更新备注
* materialNoteAttachmentService.updateMaterialNoteAttachment(materialNoteAttachment);
* newMaterialNoteAttachmentIds += materialNoteAttachment.getId() + ","; } } for
* (MaterialNoteAttachment materialNoteAttachment :
* oldMaterialNoteAttachmentlist) { if
* (!newMaterialNoteAttachmentIds.contains("," + materialNoteAttachment.getId()
* + ",")) {// 不包含 fileService.remove(materialNoteAttachment.getAttachment());
* // 删除文件 materialNoteAttachmentService
* .deleteMaterialNoteAttachmentById(materialNoteAttachment.getId()); } }
*/
return material.getId();
}
Aggregations