Search in sources :

Example 6 with TempPic

use of com.itrus.portal.db.TempPic in project portal by ixinportal.

the class TempPicService method getTempPicByRandomAndTime.

/**
 * 根据随机数,图片上传时间,找到对应的临时文件
 *
 * @param random
 * @param uploadTime
 * @return
 */
public TempPic getTempPicByRandomAndTime(String random, Date uploadTime) {
    TempPic tempPic = null;
    TempPicExample tempPicExample = new TempPicExample();
    TempPicExample.Criteria tempPicCriteria = tempPicExample.or();
    tempPicCriteria.andImgFileAIsNotNull();
    tempPicCriteria.andRandomEqualTo(random);
    tempPicCriteria.andUploadTimeEqualTo(uploadTime);
    tempPic = sqlSession.selectOne("com.itrus.portal.db.TempPicMapper.selectByExample", tempPicExample);
    return tempPic;
}
Also used : TempPicExample(com.itrus.portal.db.TempPicExample) TempPic(com.itrus.portal.db.TempPic)

Example 7 with TempPic

use of com.itrus.portal.db.TempPic in project portal by ixinportal.

the class TempPicService method hasImg.

/**
 * 根据random查看是否有上传图片
 *
 * @param random
 * @return
 */
public boolean hasImg(String random) {
    List<TempPic> tempPicList = new ArrayList<TempPic>();
    TempPicExample tempPicExample = new TempPicExample();
    TempPicExample.Criteria tempPicCriteria = tempPicExample.or();
    tempPicCriteria.andRandomEqualTo(random);
    tempPicCriteria.andUploadTimeIsNotNull();
    tempPicExample.setOrderByClause("upload_time desc");
    tempPicList = sqlSession.selectList("com.itrus.portal.db.TempPicMapper.selectByExample", tempPicExample);
    if (tempPicList.size() > 0) {
        return true;
    }
    return false;
}
Also used : TempPicExample(com.itrus.portal.db.TempPicExample) ArrayList(java.util.ArrayList) TempPic(com.itrus.portal.db.TempPic)

Example 8 with TempPic

use of com.itrus.portal.db.TempPic in project portal by ixinportal.

the class TempPicService method findTempPicByRandom.

/**
 * 根据随机数 查询有效的(有图片或无图片)的随机数实例
 *
 * @param random
 * @return
 */
public TempPic findTempPicByRandom(String random) {
    List<TempPic> tempPicList = new ArrayList<TempPic>();
    TempPic tempPic = null;
    TempPicExample tempPicExample = new TempPicExample();
    TempPicExample.Criteria tempPicCriteria = tempPicExample.or();
    tempPicCriteria.andRandomEqualTo(random);
    tempPicExample.setOrderByClause("upload_time desc");
    tempPicList = sqlSession.selectList("com.itrus.portal.db.TempPicMapper.selectByExample", tempPicExample);
    if (tempPicList.size() > 0) {
        tempPic = tempPicList.get(0);
    }
    return tempPic;
}
Also used : TempPicExample(com.itrus.portal.db.TempPicExample) ArrayList(java.util.ArrayList) TempPic(com.itrus.portal.db.TempPic)

Example 9 with TempPic

use of com.itrus.portal.db.TempPic 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

TempPic (com.itrus.portal.db.TempPic)9 TempPicExample (com.itrus.portal.db.TempPicExample)4 ServiceNullException (com.itrus.portal.exception.ServiceNullException)4 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)4 File (java.io.File)4 IOException (java.io.IOException)4 Date (java.util.Date)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 SigningServerException (com.itrus.cryptorole.SigningServerException)3 CertificateException (java.security.cert.CertificateException)3 HashMap (java.util.HashMap)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 EditBill (com.itrus.portal.db.EditBill)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1