Search in sources :

Example 71 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class FilePathUtils method saveImg.

/**
 * 保存图片信息
 *
 * @param imgDir
 * @param file
 * @param fileBase64
 * @param fileType
 * @param itemType
 * @return
 * @throws IOException
 * @throws UserInfoServiceException
 * @throws ServiceNullException
 */
public File saveImg(File imgDir, MultipartFile file, String fileBase64, String fileType, String itemType) throws IOException, UserInfoServiceException, ServiceNullException {
    String filename = System.currentTimeMillis() + itemType + getRandom() + fileType;
    // 创建磁盘文件
    File imgFile = new File(imgDir, filename);
    if (file != null && !file.isEmpty())
        file.transferTo(imgFile);
    else if (StringUtils.isNotBlank(fileBase64) && StringUtils.isNotBlank(fileType)) {
        imageByBase64.saveImage(fileBase64, imgFile);
        if (imgFile.length() > IMG_MAX_SIZE) {
            throw new UserInfoServiceException("图片大小不能超过" + (IMG_MAX_SIZE / 1024) + "K");
        }
    } else
        return null;
    return imgFile;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) File(java.io.File) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException)

Example 72 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class FilePathUtils method savepdf.

/**
 * 保存pdf
 * @param dir
 * @param bfile
 * @param bfile
 * @param fileType
 * @param itemType
 * @return
 * @throws IOException
 * @throws UserInfoServiceException
 * @throws ServiceNullException
 */
public File savepdf(File dir, byte[] bfile, String fileType, String itemType) throws IOException, UserInfoServiceException, ServiceNullException {
    BufferedOutputStream bos = null;
    FileOutputStream fos = null;
    String filename = itemType + fileType;
    // 创建磁盘文件
    File file = null;
    try {
        // dir = new File(fileURI.substring(0,fileURI.lastIndexOf("/")+1).replace("/", "\\"));
        if (!dir.exists() && dir.isDirectory()) {
            // 判断文件目录是否存在
            dir.mkdirs();
        }
        file = new File(dir, filename);
        fos = new FileOutputStream(file);
        bos = new BufferedOutputStream(fos);
        bos.write(bfile);
        if (file.length() > IMG_MAX_SIZE) {
            throw new UserInfoServiceException("PDF文件大小不能超过" + (IMG_MAX_SIZE / 1024) + "K");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (bos != null) {
            try {
                bos.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return file;
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) MultipartFile(org.springframework.web.multipart.MultipartFile) File(java.io.File) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) IOException(java.io.IOException) ServiceNullException(com.itrus.portal.exception.ServiceNullException)

Example 73 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class ImageByBase64 method saveImage.

/**
 * 将图片写入磁盘
 *
 * @param fileBase64
 *            图片的base64字符串
 * @param saveFile
 *            将写入的磁盘文件
 * @throws ServiceNullException
 */
public void saveImage(String fileBase64, File saveFile) throws IOException, UserInfoServiceException, ServiceNullException {
    if (fileBase64.indexOf("/reviewWeb/img/") != -1) {
        String editbillImg = fileBase64.substring(fileBase64.indexOf("/reviewWeb/img/") + 15, fileBase64.length());
        String[] ss = editbillImg.split("/");
        Long type = Long.parseLong(ss[0]);
        Long id = Long.parseLong(ss[1]);
        Long num = Long.parseLong(ss[2]);
        File tempFile = getImg(type, id, num);
        if (null == tempFile) {
            logger.error("fileBase64:" + fileBase64);
        }
        CopyFile.copyFile(tempFile, saveFile);
        return;
    }
    // 检查传递的base64信息是否为图片地址:/img/{type}/{random}?t=uploadTime
    if (fileBase64.length() < 100 && fileBase64.indexOf("/img/") != -1) {
        try {
            String[] baseInfos = fileBase64.split("/");
            String[] uploadStr = baseInfos[3].split("=");
            String random = uploadStr[0].substring(0, uploadStr[0].indexOf("?"));
            String upload = uploadStr[1];
            // upload = upload.substring(upload.indexOf("=") + 1);
            // 上传时间
            Date uploadTime = new Date(Long.parseLong(upload));
            TempPic tempPic = tempPicService.getTempPicByRandomAndTime(random, uploadTime);
            if (null == tempPic) {
                logger.error("fileBase64:" + fileBase64);
                throw new ServiceNullException("未找到上传的临时图片记录");
            }
            String type = baseInfos[2];
            String fileName = null;
            // } else
            if ("1".equals(type)) {
                // 证件图片A
                fileName = tempPic.getImgFileA();
            } else if ("2".equals(type)) {
                // 证件图片B
                fileName = tempPic.getImgFileB();
            }
            if (null == fileName) {
                logger.error("fileBase64:" + fileBase64);
                throw new ServiceNullException("未找到上传的临时图片名称");
            }
            File tempFile = new File(tempPicService.getDir(random), fileName);
            // 将临时文件写入到需要保存的地方
            CopyFile.copyFile(tempFile, saveFile);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("fileBase64:" + fileBase64);
            throw new ServiceNullException("未找到上传的临时图片记录信息");
        }
    } else if (fileBase64.indexOf("/editbillImg/") != -1) {
        String editbillImg = fileBase64.substring(fileBase64.indexOf("/editbillImg/") + 13, fileBase64.length());
        String[] ss = editbillImg.split("/");
        String userSn = ss[2];
        Integer type = Integer.parseInt(ss[0]);
        Long editBillId = Long.parseLong(ss[1]);
        EditBill editBill = null;
        String fileName = "";
        if (null == type || StringUtils.isBlank(userSn) || null == editBillId) {
            logger.error("fileBase64:" + fileBase64);
            throw new ServiceNullException("填写中的订单的图片url不正确");
        }
        editBill = sqlsession.selectOne("com.itrus.portal.db.EditBillMapper.selectByPrimaryKey", editBillId);
        if (null == editBill) {
            logger.error("fileBase64:" + fileBase64);
            throw new ServiceNullException("找不到填写中的订单信息");
        }
        /*
			 * 0 营业执照图片, 1 组织机构代码图片, 2 税务登记图片, 3 法人正面图片
			 * 4 法人反面图片, 5 授权书图片, 6 代理人正面图片, 7 代理人反面图片
			 * */
        if (type.equals(0)) {
            fileName = editBill.getBlImgFile();
        } else if (type.equals(1)) {
            fileName = editBill.getOcImgFile();
        } else if (type.equals(2)) {
            fileName = editBill.getTrImgFile();
        } else if (type.equals(3)) {
            fileName = editBill.getIcfImgFile();
        } else if (type.equals(4)) {
            fileName = editBill.getIcbImgFile();
        } else if (type.equals(5)) {
            fileName = editBill.getPrImgFile();
        } else if (type.equals(6)) {
            fileName = editBill.getAtfImgFile();
        } else if (type.equals(7)) {
            fileName = editBill.getAtbImgFile();
        }
        File tempFile;
        try {
            tempFile = new File(filePathUtils.getDir(null, userSn), fileName);
            // 将临时文件写入到需要保存的地方
            CopyFile.copyFile(tempFile, saveFile);
        } catch (Exception e) {
            logger.error("fileBase64:" + fileBase64);
            e.printStackTrace();
            throw new ServiceNullException("填写中的订单的图片url不正确");
        }
    } else {
        // Base64解码
        byte[] b = Base64.decode(fileBase64);
        OutputStream out = new FileOutputStream(saveFile);
        out.write(b);
        out.flush();
        out.close();
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ServiceNullException(com.itrus.portal.exception.ServiceNullException) File(java.io.File) Date(java.util.Date) ServiceNullException(com.itrus.portal.exception.ServiceNullException) IOException(java.io.IOException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) EditBill(com.itrus.portal.db.EditBill) TempPic(com.itrus.portal.db.TempPic)

Aggregations

UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)73 Date (java.util.Date)39 HashMap (java.util.HashMap)31 File (java.io.File)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 Enterprise (com.itrus.portal.db.Enterprise)19 IOException (java.io.IOException)19 UserInfo (com.itrus.portal.db.UserInfo)17 TransactionStatus (org.springframework.transaction.TransactionStatus)14 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)14 SigningServerException (com.itrus.cryptorole.SigningServerException)11 IdentityCard (com.itrus.portal.db.IdentityCard)11 CertificateException (java.security.cert.CertificateException)11 BusinessLicense (com.itrus.portal.db.BusinessLicense)10 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)10 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)10 Agent (com.itrus.portal.db.Agent)9 OrgCode (com.itrus.portal.db.OrgCode)9 TaxRegisterCert (com.itrus.portal.db.TaxRegisterCert)9