Search in sources :

Example 1 with NewDecPosition

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

the class DecPositionServiceImpl method saveBooks.

@Override
public long saveBooks(DecPositionVO decPositionVO, HttpServletRequest request) throws IOException {
    List<NewDecPosition> list = decPositionVO.getList();
    if (CollectionUtil.isEmpty(list)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "添加内容不能为空");
    }
    List<DecPosition> istDecPositions = decPositionDao.listDecPositions(list.get(0).getDeclarationId());
    if (CollectionUtil.isEmpty(istDecPositions)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "内容不能为空");
    }
    String newId = ",";
    for (NewDecPosition newDecPosition : list) {
        // 遍历所有的id
        newId += newDecPosition.getId() + ",";
    }
    for (DecPosition DecPosition : istDecPositions) {
        // 遍历原数据
        if (!newId.contains("," + DecPosition.getId() + ",")) {
            if (ObjectUtil.notNull(DecPosition.getId())) {
                decPositionDao.deleteDecPosition(DecPosition.getId());
            }
        }
    }
    for (NewDecPosition newDecPosition : list) {
        Long id = newDecPosition.getId();
        Long declarationId = newDecPosition.getDeclarationId();
        Long textbookId = newDecPosition.getTextbookId();
        String file = newDecPosition.getFile();
        String showPosition = newDecPosition.getShowPosition();
        DecPosition decPosition = new DecPosition();
        if ("编委".equals(showPosition)) {
            decPosition.setPresetPosition(1);
        } else if ("副主编".equals(showPosition)) {
            decPosition.setPresetPosition(2);
        } else if ("副主编,编委".equals(showPosition)) {
            decPosition.setPresetPosition(3);
        } else if ("主编".equals(showPosition)) {
            decPosition.setPresetPosition(4);
        } else if ("主编,编委".equals(showPosition)) {
            decPosition.setPresetPosition(5);
        } else if ("主编,副主编".equals(showPosition)) {
            decPosition.setPresetPosition(6);
        } else if ("主编,副主编,编委".equals(showPosition)) {
            decPosition.setPresetPosition(7);
        } else if ("数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(8);
        } else if ("编委,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(9);
        } else if ("副主编,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(10);
        } else if ("副主编,编委,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(11);
        } else if ("主编,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(12);
        } else if ("主编,编委,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(13);
        } else if ("主编,副主编,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(14);
        } else if ("主编,副主编,编委,数字编委".equals(showPosition)) {
            decPosition.setPresetPosition(15);
        }
        File files = null;
        String fileName = null;
        if (StringUtil.isEmpty(file)) {
            decPosition.setSyllabusId(null);
            decPosition.setSyllabusName(null);
        } else {
            files = new File(file);
            if (files.exists()) {
                // 获取原文件名字
                fileName = files.getName();
                decPosition.setSyllabusName(fileName);
            } else {
                decPosition.setSyllabusId(null);
                decPosition.setSyllabusName(null);
            }
        }
        decPosition.setDeclarationId(declarationId);
        decPosition.setTextbookId(textbookId);
        decPosition.setId(id);
        if (ObjectUtil.isNull(id)) {
            // 保存或者修改
            decPositionDao.addDecPosition(decPosition);
            String fileNames = null;
            String mongoId = null;
            if (ObjectUtil.notNull(decPosition.getId()) && StringUtil.notEmpty(file)) {
                // mongoId = fileService.saveLocalFile(files, FileType.SYLLABUS,
                // decPosition.getId());
                byte[] fileByte = (byte[]) request.getSession(false).getAttribute(file);
                fileNames = (String) request.getSession(false).getAttribute("fileName_" + file);
                InputStream input = new ByteArrayInputStream(fileByte);
                mongoId = fileService.save(input, fileNames, FileType.SYLLABUS, decPosition.getId());
                if (StringUtil.isEmpty(mongoId)) {
                    throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.FILE_UPLOAD_FAILED, "文件上传失败!");
                }
            }
            if (StringUtil.notEmpty(mongoId)) {
                decPosition.setSyllabusId(mongoId);
                decPosition.setSyllabusName(fileNames);
                decPositionDao.updateDecPosition(decPosition);
            }
        } else {
            decPositionDao.updateDecPosition(decPosition);
        }
    }
    return list.size();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DecPosition(com.bc.pmpheep.back.po.DecPosition) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) File(java.io.File) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition)

Aggregations

DecPosition (com.bc.pmpheep.back.po.DecPosition)1 NewDecPosition (com.bc.pmpheep.back.vo.NewDecPosition)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1