Search in sources :

Example 1 with MaterialProjectEditorVO

use of com.bc.pmpheep.back.vo.MaterialProjectEditorVO 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();
}
Also used : MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) Gson(com.google.gson.Gson) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) CmsContent(com.bc.pmpheep.back.po.CmsContent) MaterialProjectEditor(com.bc.pmpheep.back.po.MaterialProjectEditor) PmphUser(com.bc.pmpheep.back.po.PmphUser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) Date(java.util.Date) ByteArrayInputStream(java.io.ByteArrayInputStream) TypeToken(com.google.gson.reflect.TypeToken) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 2 with MaterialProjectEditorVO

use of com.bc.pmpheep.back.vo.MaterialProjectEditorVO in project pmph by BCSquad.

the class MaterialServiceImpl method getMaterialVO.

@Override
public MaterialVO getMaterialVO(Long id) throws CheckedServiceException {
    if (null == id) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材主键为空");
    }
    // 教材主要信息
    Material material = materialDao.getMaterialById(id);
    // 教材主任
    PmphUser director = pmphUserService.get(material.getDirector());
    // 教材类型字符串
    MaterialType materialType = materialTypeService.getMaterialTypeById(material.getMaterialType());
    String mtype = "[]";
    if (null != materialType) {
        mtype = "[" + materialType.getPath().replace("-", ",") + "," + material.getMaterialType() + "]";
        // 去掉 0
        mtype = mtype.replace("[0,", "[").replace("[0", "[");
    }
    // 教材通知备注表
    MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(id);
    Gson gson = new Gson();
    // 联系人
    List<MaterialContact> materialContactList = materialContactService.listMaterialContactByMaterialId(id);
    String materialContacts = gson.toJson(materialContactList);
    // 扩展项
    List<MaterialExtension> materialExtensionList = materialExtensionService.getMaterialExtensionByMaterialId(id);
    String materialExtensions = gson.toJson(materialExtensionList);
    // 项目编辑
    List<MaterialProjectEditorVO> materialProjectEditorVOList = materialProjectEditorService.listMaterialProjectEditors(id);
    String materialProjectEditorVOs = gson.toJson(materialProjectEditorVOList);
    // 通知附件信息
    List<MaterialNoticeAttachment> materialNoticeAttachmentList = new ArrayList<MaterialNoticeAttachment>(5);
    if (null != materialExtra) {
        materialNoticeAttachmentList = materialNoticeAttachmentService.getMaterialNoticeAttachmentsByMaterialExtraId(materialExtra.getId());
    }
    String materialNoticeAttachments = gson.toJson(materialNoticeAttachmentList);
    // 通知备注附件信息
    List<MaterialNoteAttachment> materialNoteAttachmentList = new ArrayList<MaterialNoteAttachment>(5);
    if (null != materialExtra) {
        materialNoteAttachmentList = materialNoteAttachmentService.getMaterialNoteAttachmentByMaterialExtraId(materialExtra.getId());
    }
    String materialNoteAttachments = gson.toJson(materialNoteAttachmentList);
    return new MaterialVO(material, director == null ? null : director.getRealname(), mtype, materialExtra, materialContacts, materialExtensions, materialProjectEditorVOs, materialNoticeAttachments, materialNoteAttachments, StringUtil.tentToBinary(material.getPlanPermission()), StringUtil.tentToBinary(material.getProjectPermission()));
}
Also used : MaterialVO(com.bc.pmpheep.back.vo.MaterialVO) MaterialNoticeAttachment(com.bc.pmpheep.back.po.MaterialNoticeAttachment) PmphUser(com.bc.pmpheep.back.po.PmphUser) MaterialNoteAttachment(com.bc.pmpheep.back.po.MaterialNoteAttachment) MaterialContact(com.bc.pmpheep.back.po.MaterialContact) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) MaterialExtension(com.bc.pmpheep.back.po.MaterialExtension) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) MaterialType(com.bc.pmpheep.back.po.MaterialType) MaterialExtra(com.bc.pmpheep.back.po.MaterialExtra)

Example 3 with MaterialProjectEditorVO

use of com.bc.pmpheep.back.vo.MaterialProjectEditorVO in project pmph by BCSquad.

the class PmphUserServiceImpl method getListPmphUser.

@Override
public PageResult<PmphUserManagerVO> getListPmphUser(PageParameter<PmphUserManagerVO> pageParameter, Long groupId) throws CheckedServiceException {
    String name = pageParameter.getParameter().getName();
    if (StringUtil.notEmpty(name)) {
        pageParameter.getParameter().setName(name);
    }
    String path = pageParameter.getParameter().getPath();
    Long departmentId = pageParameter.getParameter().getDepartmentId();
    if (StringUtil.notEmpty(path) && ObjectUtil.notNull(departmentId)) {
        pageParameter.getParameter().setPath(path + "-" + java.lang.String.valueOf(departmentId) + '-');
    }
    PageResult<PmphUserManagerVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    int total = pmphUserDao.getListPmphUserTotal(pageParameter);
    if (total > 0) {
        List<PmphUserManagerVO> list = pmphUserDao.getListPmphUser(pageParameter);
        for (PmphUserManagerVO pmphUserManagerVO : list) {
            List<PmphRoleVO> pmphRoles = pmphRoleDao.listPmphUserRoleByUserId(pmphUserManagerVO.getId());
            pmphUserManagerVO.setPmphRoles(pmphRoles);
        }
        pageResult.setRows(list);
    }
    pageResult.setTotal(total);
    // 设置职位
    if (null != pageResult.getRows() && pageResult.getRows().size() > 0 && null != groupId) {
        // 清空职位
        for (PmphUserManagerVO pmphUserManagerVO : pageResult.getRows()) {
            pmphUserManagerVO.setPosition("无");
        }
        PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
        Long bookId = pmphGroup.getBookId();
        if (null != bookId && bookId.intValue() > 0) {
            Textbook textbook = textbookService.getTextbookById(bookId);
            Material material = materialService.getMaterialById(textbook.getMaterialId());
            List<MaterialProjectEditorVO> projects = materialProjectEditorService.listMaterialProjectEditors(textbook.getMaterialId());
            for (PmphUserManagerVO pmphUserManagerVO : pageResult.getRows()) {
                Long pmphUserId = pmphUserManagerVO.getId();
                String posotion = null;
                if (material.getDirector().intValue() == pmphUserId.intValue()) {
                    posotion = "主任";
                }
                if (null != projects && projects.size() > 0) {
                    for (MaterialProjectEditorVO item : projects) {
                        if (item.getEditorId().intValue() == pmphUserId.intValue()) {
                            posotion += (posotion == null) ? "项目编辑" : ",项目编辑";
                            break;
                        }
                    }
                }
                if (textbook.getPlanningEditor().intValue() == pmphUserId.intValue()) {
                    posotion += (posotion == null) ? "策划编辑" : ",策划编辑";
                }
                pmphUserManagerVO.setPosition(posotion == null ? "无" : posotion);
            }
        }
    }
    // 设置职位 end
    return pageResult;
}
Also used : Material(com.bc.pmpheep.back.po.Material) PageResult(com.bc.pmpheep.back.plugin.PageResult) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) Textbook(com.bc.pmpheep.back.po.Textbook) PmphUserManagerVO(com.bc.pmpheep.back.vo.PmphUserManagerVO) PmphRoleVO(com.bc.pmpheep.back.vo.PmphRoleVO)

Example 4 with MaterialProjectEditorVO

use of com.bc.pmpheep.back.vo.MaterialProjectEditorVO in project pmph by BCSquad.

the class MaterialServiceImpl method getMaterialMainInfoById.

@Override
public MaterialMainInfoVO getMaterialMainInfoById(Long materialId, String sessionId) throws CheckedServiceException {
    // 验证用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    // 教材权限的检查
    List<PmphRole> pmphRoles = pmphUserService.getListUserRole(pmphUser.getId());
    // 下面进行授权
    Integer projectEditorPowers = 0;
    Integer role = 0;
    // 系统管理员权限检查
    for (PmphRole pmphRole : pmphRoles) {
        if (null != pmphRole && null != pmphRole.getRoleName() && "系统管理员".equals(pmphRole.getRoleName())) {
            // 我是系统管理原
            // "11111111";
            projectEditorPowers = 255;
            role = 1;
        }
    }
    // 教材主任检查
    Material material = this.getMaterialById(materialId);
    if (null != material && null != material.getDirector() && pmphUser.getId().equals(material.getDirector())) {
        // 我是教材的主任
        projectEditorPowers = 255;
        role = (0 == role.intValue() ? 2 : role);
    }
    // 教材项目编辑检查
    List<MaterialProjectEditorVO> materialProjectEditors = materialProjectEditorService.listMaterialProjectEditors(materialId);
    if (null != materialProjectEditors && materialProjectEditors.size() > 0) {
        for (MaterialProjectEditorVO materialProjectEditor : materialProjectEditors) {
            if (null != materialProjectEditor && null != materialProjectEditor.getEditorId() && materialProjectEditor.getEditorId().equals(pmphUser.getId())) {
                // 我是教材的项目编辑
                projectEditorPowers = (projectEditorPowers | material.getProjectPermission());
                role = (0 == role.intValue() ? 3 : role);
            }
        }
    }
    // 教材策划编辑检查
    Integer num = this.getPlanningEditorSum(materialId, pmphUser.getId());
    if (null != num && num.intValue() > 0) {
        // 我是教材的策划编辑编辑
        projectEditorPowers = (projectEditorPowers | material.getPlanPermission());
        role = (0 == role.intValue() ? 4 : role);
    }
    MaterialMainInfoVO materialMainInfoVO = new MaterialMainInfoVO(materialId, material.getMaterialName(), material.getIsPublished(), material.getIsAllTextbookPublished(), material.getIsForceEnd(), material.getIsDeleted(), StringUtil.tentToBinary(projectEditorPowers), role);
    return materialMainInfoVO;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) MaterialMainInfoVO(com.bc.pmpheep.back.vo.MaterialMainInfoVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) PmphRole(com.bc.pmpheep.back.po.PmphRole)

Example 5 with MaterialProjectEditorVO

use of com.bc.pmpheep.back.vo.MaterialProjectEditorVO in project pmph by BCSquad.

the class SystemMessageService method sendWhenSubmitDeclarationForm.

/**
 * 作家教材申报表 给学校管理员发送或者人卫教材相关人员发送消息
 *
 * @author Mryang
 * @createDate 2017年11月17日 下午4:31:19
 * @param declarationId
 *            申报id
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenSubmitDeclarationForm(Long declarationId) throws CheckedServiceException, IOException {
    // 获取申报表
    Declaration declaration = declarationService.getDeclarationById(declarationId);
    if (null == declaration) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "申报表不存在");
    }
    if (null == declaration.getOrgId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "认证的管理员为空");
    }
    Material material = materialService.getMaterialById(declaration.getMaterialId());
    if (declaration.getOrgId() == 0) {
        // 提交的人卫社
        // 项目编辑 策划编辑 主任 id
        String msgContent = "[<font color='red'>" + declaration.getRealname() + "</font>]提交了《<font color='red'>" + material.getMaterialName() + "</font>》申报表,请及时进行资料审核";
        // 存入消息主体
        Message message = new Message(msgContent);
        message = messageService.add(message);
        String msg_id = message.getId();
        // 主任id
        Long directorId = material.getDirector();
        // 项目编辑列表
        List<MaterialProjectEditorVO> materialProjectEditorList = materialProjectEditorService.listMaterialProjectEditors(material.getId());
        // 批量保存的消息集合
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(materialProjectEditorList.size() + 1);
        List<String> userIds = new ArrayList<String>(materialProjectEditorList.size() + 1);
        userMessageList.add(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), directorId, new Short("1"), null));
        userIds.add("1_" + directorId);
        for (MaterialProjectEditorVO materialProjectEditor : materialProjectEditorList) {
            UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), materialProjectEditor.getEditorId(), new Short("1"), null);
            userMessageList.add(userMessage);
            userIds.add("1_" + materialProjectEditor.getEditorId());
        }
        // 策划编辑
        // 我申报的书籍
        List<DecPosition> decPositionList = decPositionService.listDecPositions(declarationId);
        for (DecPosition decPosition : decPositionList) {
            Textbook textbook = textbookService.getTextbookById(decPosition.getTextbookId());
            if (null != textbook && null != textbook.getPlanningEditor()) {
                UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), textbook.getPlanningEditor(), new Short("1"), null);
                userMessageList.add(userMessage);
                userIds.add("1_" + textbook.getPlanningEditor());
            }
        }
        // 发送消息
        userMessageService.addUserMessageBatch(userMessageList);
        // websocket推送页面消息
        WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
        myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
    } else {
        // 提交的机构
        String msgContent = "贵校老师[<font color='red'>" + declaration.getRealname() + "</font>]提交了《<font color='red'>" + material.getMaterialName() + "</font>》申报表,请及时进行资料审核、打印并快递申报纸质表";
        // 存入消息主体
        Message message = new Message(msgContent);
        message = messageService.add(message);
        String msg_id = message.getId();
        // 获取机构用户
        List<Long> orgIds = new ArrayList<Long>(1);
        orgIds.add(declaration.getOrgId());
        List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(orgIds);
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(orgUserList.size());
        List<String> userIds = new ArrayList<String>(orgUserList.size());
        for (OrgUser orgUser : orgUserList) {
            UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null);
            userMessageList.add(userMessage);
            userIds.add("3_" + orgUser.getId());
        }
        // 发送消息
        userMessageService.addUserMessageBatch(userMessageList);
        // websocket推送页面消息
        WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
        myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
    }
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) DecPosition(com.bc.pmpheep.back.po.DecPosition) Textbook(com.bc.pmpheep.back.po.Textbook) Declaration(com.bc.pmpheep.back.po.Declaration)

Aggregations

MaterialProjectEditorVO (com.bc.pmpheep.back.vo.MaterialProjectEditorVO)7 Material (com.bc.pmpheep.back.po.Material)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 PmphUser (com.bc.pmpheep.back.po.PmphUser)4 Gson (com.google.gson.Gson)3 PageResult (com.bc.pmpheep.back.plugin.PageResult)2 MaterialContact (com.bc.pmpheep.back.po.MaterialContact)2 MaterialExtension (com.bc.pmpheep.back.po.MaterialExtension)2 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)2 MaterialNoteAttachment (com.bc.pmpheep.back.po.MaterialNoteAttachment)2 MaterialNoticeAttachment (com.bc.pmpheep.back.po.MaterialNoticeAttachment)2 MaterialProjectEditor (com.bc.pmpheep.back.po.MaterialProjectEditor)2 PmphRole (com.bc.pmpheep.back.po.PmphRole)2 Textbook (com.bc.pmpheep.back.po.Textbook)2 TypeToken (com.google.gson.reflect.TypeToken)2 ArrayList (java.util.ArrayList)2 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)1 CmsContent (com.bc.pmpheep.back.po.CmsContent)1 DecPosition (com.bc.pmpheep.back.po.DecPosition)1 Declaration (com.bc.pmpheep.back.po.Declaration)1