use of com.itrus.portal.db.TempPic in project portal by ixinportal.
the class TempPicSerController method getRandom.
/**
* pc端获取随机数
*
* @return
*/
@RequestMapping("/getRandom")
@ResponseBody
public Map<String, Object> getRandom(@RequestParam(value = "type", required = false) Integer type) {
Map<String, Object> retMap = new HashMap<String, Object>();
// retCode:0表示获取随机数失败
retMap.put("retCode", 0);
// }
try {
// 根据certbase64获取证书信息
// UserCert userCert = userCertService.getUserCert(certBase64);
// 创建TempPic实例
TempPic temPic = new TempPic();
String random = getRandomStr();
random += "_" + type;
// set createTime
temPic.setCreateTime(new Date());
// set random
temPic.setRandom(random);
sqlSession.insert("com.itrus.portal.db.TempPicMapper.insert", temPic);
log.error("insert random:" + random);
retMap.put("retCode", 1);
retMap.put("random", random);
retMap.put("createTime", temPic.getCreateTime());
} catch (Exception e) {
log.error("getRandom fail", e);
retMap.put("retMsg", e.getMessage());
}
return retMap;
}
use of com.itrus.portal.db.TempPic in project portal by ixinportal.
the class TempPicSerController method getImg.
// /**
// * 接收上传的临时图片
// *
// * @param random
// * @param imgABase64
// * @param imgBBase64
// * @param imgA
// * @param imgB
// * @param businessImgBase64
// * @param businessImg
// * @return
// * @throws Exception
// */
// @RequestMapping("/uploadImg2")
// public @ResponseBody Map<String, Object> uploadImg2(
// @RequestParam(value = "random", required = true) String random,
// @RequestParam(value = "imgABase64", required = false) String imgABase64,
// @RequestParam(value = "imgBBase64", required = false) String imgBBase64,
// @RequestParam(value = "imgA", required = false) MultipartFile imgA,
// @RequestParam(value = "imgB", required = false) MultipartFile imgB,
// @RequestParam(value = "businessImgBase64", required = false) String businessImgBase64,
// @RequestParam(value = "businessImg", required = false) MultipartFile businessImg)
// throws Exception {
// Map<String, Object> retMap = new HashMap<String, Object>();
// retMap.put("retCode", 0);// retCode:0表示上传图片失败
// if (StringUtils.isBlank(random)
// || (null == imgA && null == imgB && null == businessImg
// && StringUtils.isBlank(imgABase64)
// && StringUtils.isBlank(imgBBase64) && StringUtils
// .isBlank(businessImgBase64))) {
// retMap.put("retMsg", "请检查参数完整性");
// return retMap;
// }
//
// // 1、根据random查找TempPic
// TempPic tempPic = tempPicService.findTemPicByRadom(random);
// if (null == tempPic) {
// retMap.put("retMsg", "无效的请求");
// return retMap;
// }
// // 判断随机数创建的时间与当前时间是否超过了2分钟
// if (System.currentTimeMillis() - tempPic.getCreateTime().getTime() > TempPicService.VALIDITY) {
// retMap.put("retMsg", "该请求已失效");
// return retMap;
// }
// // 假如是第一次上传图片,则设置使用时间
// if (null == tempPic.getUploadTime()) {
// tempPic.setUseTime(new Date());
// }
// File imgDir = tempPicService.getDir(random);// 创建目录
// File businessImgFile = null;
// File imgAFile = null;
// File imgBFile = null;
// // 营业执照图片
// // 假如上传了file格式的图片,则不处理base64,没有上传file格式图片,有base64,则处理,否则不进行处理
// if (null != businessImg && !businessImg.isEmpty()) {
// if (verifyImg(businessImg)) {
// // 保存file格式图片
// // 保存营业执照图片到磁盘
// businessImgFile = saveImg(imgDir, businessImg, null, "business");
// } else {
// retMap.put("retMsg", "请检查图片大小和格式");
// return retMap;
// }
// } else {
// if (StringUtils.isNotBlank(businessImgBase64)) {
// // 保存base64格式图片
// businessImgFile = saveImg(imgDir, null, businessImgBase64,
// "business");
// }
// }
// if (null != businessImgFile && businessImgFile.isFile()) {
//
// tempPic.setBusinessImg(businessImgFile.getName());
// tempPic.setBusinessImgHash(HMACSHA1
// .genSha1HashOfFile(businessImgFile));
// }
// // 证件图片A
// if (null != imgA && !imgA.isEmpty()) {
// if (verifyImg(imgA)) {
// imgAFile = saveImg(imgDir, imgA, null, "imgA");
// } else {
// retMap.put("retMsg", "请检查图片大小和格式");
// return retMap;
// }
// } else {
// if (StringUtils.isNotBlank(imgABase64)) {
// imgAFile = saveImg(imgDir, null, imgABase64, "imgA");
// }
// }
// if (null != imgAFile && imgAFile.isFile()) {
// tempPic.setImgFileA(imgAFile.getName());
// tempPic.setImgFileHashA(HMACSHA1.genSha1HashOfFile(imgAFile));
// }
// // 证件图片B
// if (null != imgB && !imgB.isEmpty()) {
// if (verifyImg(imgB)) {
// imgBFile = saveImg(imgDir, imgB, null, "imgB");
// } else {
// retMap.put("retMsg", "请检查图片大小和格式");
// return retMap;
// }
// } else {
// if (StringUtils.isNotBlank(imgBBase64)) {
// imgBFile = saveImg(imgDir, null, imgBBase64, "imgB");
// }
// }
// if (null != imgBFile && imgBFile.isFile()) {
//
// tempPic.setImgFileB(imgBFile.getName());
// tempPic.setImgFileHashB(HMACSHA1.genSha1HashOfFile(imgBFile));
// }
//
// tempPic.setUploadTime(new Date());// 设置图片上传时间
// tempPic.setStatus(1);// 状态:1有图片,2无图片,3无效
// sqlSession.update("com.itrus.ukey.db.TempPicMapper.updateByPrimaryKey",
// tempPic);
//
// // 将random,usercert有关联的小于当前插入数据时间的信息设置为无效,并删除图片
// tempPicService.removeRandomUserCert(tempPic);
// retMap.put("retCode", 1);// 上传图片成功
//
// return retMap;
// }
// /**
// * 根据random查看是否有上传图片
// *
// * @param random
// * @return
// */
// @RequestMapping(value = "/hasImg")
// public @ResponseBody Map<String, Object> hasImg(
// @RequestParam(value = "random", required = true) String random) {
// Map<String, Object> retMap = new HashMap<String, Object>();
// retMap.put("retCode", 0);// 0表示没有图片,1表示有
// if (tempPicService.hasImg(random)) {
// retMap.put("retCode", 1);
// return retMap;
// }
// return retMap;
// }
/**
* 给客户端返回图片的url地址
*
* @param random
* @return
*/
@RequestMapping(value = "/imgUrl/{random}")
@ResponseBody
public Map<String, Object> getImg(@PathVariable("random") String random) {
Map<String, Object> retMap = new HashMap<String, Object>();
// 0表示没有图片,1表示有
retMap.put("retCode", 0);
if (StringUtils.isEmpty(random)) {
retMap.put("retMsg", "请输入完整参数");
return retMap;
}
TempPic tempPic = tempPicService.findTempPicByRandom(random);
if (null == tempPic) {
retMap.put("retMsg", "没有上传图片");
return retMap;
}
String img = tempPic.getImgFileA();
if (img == null) {
retMap.put("retMsg", "没有找到图片");
return retMap;
}
try {
retMap.put("imgUrl1", systemConfigService.getTsAddress() + "/tempPic/img/1/" + random + "?t=" + tempPic.getUploadTime().getTime());
if (null != tempPic.getImgFileB()) {
retMap.put("imgUrl2", systemConfigService.getTsAddress() + "/tempPic/img/2/" + random + "?t=" + tempPic.getUploadTime().getTime());
}
retMap.put("retCode", 1);
} catch (Exception e) {
retMap.put("retMsg", "获取终端服务地址失败");
e.printStackTrace();
}
return retMap;
}
use of com.itrus.portal.db.TempPic in project portal by ixinportal.
the class TempPicSerController method getImg.
/**
* 下载图片
*
* @param random
* @param type
* 获取的图片类型(1营业执照图片,2证件图片A,3证件图片B)
* @param response
* @return
*/
@RequestMapping(value = "/img/{type}/{random}")
public ResponseEntity<byte[]> getImg(@PathVariable("type") Integer type, @PathVariable("random") String random, HttpServletResponse response) {
ResponseEntity<byte[]> responseEntity;
HttpHeaders headers = new HttpHeaders();
OutputStream os = null;
FileInputStream fis = null;
try {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
headers.setCacheControl("no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
headers.setPragma("no-cache");
if (StringUtils.isEmpty(random)) {
responseEntity = new ResponseEntity<byte[]>(headers, HttpStatus.NOT_FOUND);
return responseEntity;
}
TempPic tempPic = tempPicService.findTempPicByRandom(random);
if (null == tempPic) {
responseEntity = new ResponseEntity<byte[]>(headers, HttpStatus.NOT_FOUND);
return responseEntity;
}
String img = null;
if (type == TempPicService.IMGFILEA) {
img = tempPic.getImgFileA();
} else if (type == TempPicService.IMGFILEB) {
img = tempPic.getImgFileB();
}
if (img == null) {
responseEntity = new ResponseEntity<byte[]>(headers, HttpStatus.NOT_FOUND);
return responseEntity;
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;fileName=\"" + new String(img.getBytes("UTF-8"), "iso-8859-1") + "\"");
File imgFile = new File(tempPicService.getDir(random), img);
fis = new FileInputStream(imgFile);
byte[] bb = IOUtils.toByteArray(fis);
response.addHeader("Content-Length", bb.length + "");
os = response.getOutputStream();
os.write(bb);
os.flush();
} catch (Exception e) {
e.printStackTrace();
responseEntity = new ResponseEntity<byte[]>(headers, HttpStatus.NOT_FOUND);
return responseEntity;
} finally {
try {
if (null != fis) {
fis.close();
}
if (null != os) {
os.close();
}
} catch (IOException e) {
}
}
return null;
}
use of com.itrus.portal.db.TempPic in project portal by ixinportal.
the class TempPicSerController method uploadImg.
/**
* pc端获取随机数
*
* @return
*/
// @RequestMapping("/getName")
// public @ResponseBody Map<String, Object> getName(
// @RequestParam(value = "random", required = true) String random) {
// Map<String, Object> retMap = new HashMap<String, Object>();
// retMap.put("retCode", 0);// retCode:0表示获取随机数失败
// try {
// // ThreeInOne threeInOne = null;
// // String rids[] = random.split("_");
// if(rids.length>1){
// Long id=Long.parseLong(rids[1]);
// threeInOne = sqlSession.selectOne(
// "com.itrus.ukey.db.ThreeInOneMapper.selectByPrimaryKey", id);
// }
//
// if(threeInOne!=null){
// retMap.put("retCode", 0);
// retMap.put("taxName", threeInOne.getTaxName());
// }
// else{
// retMap.put("retCode", 1);
// retMap.put("retMsg", "没有查询到企业名称");
// }
// } catch (Exception e) {
// log.error("getRandom fail", e);
// retMap.put("retCode", 2);// retCode:0表示获取随机数失败
// retMap.put("retMsg", e.getMessage());
// }
// return retMap;
// }
/**
* 接收上传的临时图片
*
* @param random
* @param imgABase64
* @param imgBBase64
* @return
* @throws Exception
*/
@RequestMapping("/uploadImg")
@ResponseBody
public Map<String, Object> uploadImg(@RequestParam(value = "random", required = true) String random, @RequestParam(value = "imgABase64", required = false) String imgABase64, @RequestParam(value = "imgBBase64", required = false) String imgBBase64) throws Exception {
Map<String, Object> retMap = new HashMap<String, Object>();
// retCode:0表示上传图片失败
retMap.put("retCode", 0);
if (StringUtils.isBlank(random) || (StringUtils.isBlank(imgABase64) && StringUtils.isBlank(imgBBase64))) {
retMap.put("retMsg", "请检查参数完整性");
return retMap;
}
// 1、根据random查找TempPic
TempPic tempPic = tempPicService.findTempPicByRandom(random);
log.error("find random:" + random);
if (null == tempPic) {
log.error("cannot find random:" + random);
retMap.put("retMsg", "无效的请求");
return retMap;
}
// 判断随机数创建的时间与当前时间是否超过了2分钟
log.error(System.currentTimeMillis() + "," + tempPic.getCreateTime().getTime() + "," + TempPicService.VALIDITY);
log.error(System.currentTimeMillis() - tempPic.getCreateTime().getTime());
if (System.currentTimeMillis() - tempPic.getCreateTime().getTime() > TempPicService.VALIDITY) {
retMap.put("retMsg", "该请求已失效");
return retMap;
}
// 假如是第一次上传图片,则设置使用时间
if (null == tempPic.getUploadTime()) {
tempPic.setUseTime(new Date());
}
// 创建目录
File imgDir = tempPicService.getDir(random);
File imgAFile = null;
File imgBFile = null;
// 证件图片A
if (StringUtils.isNotBlank(imgABase64)) {
imgAFile = saveImg(imgDir, null, imgABase64, "imgA");
}
if (null != imgAFile && imgAFile.isFile()) {
// 检查是否存在旧的图片
if (StringUtils.isNotBlank(tempPic.getImgFileA())) {
FileUtils.deleteQuietly(new File(imgDir, tempPic.getImgFileA()));
}
tempPic.setImgFileA(imgAFile.getName());
tempPic.setImgFileHashA(HMACSHA1.genSha1HashOfFile(imgAFile));
}
// 证件图片B
if (StringUtils.isNotBlank(imgBBase64)) {
imgBFile = saveImg(imgDir, null, imgBBase64, "imgB");
}
if (null != imgBFile && imgBFile.isFile()) {
// 检查是否存在旧的图片
if (StringUtils.isNotBlank(tempPic.getImgFileB())) {
FileUtils.deleteQuietly(new File(imgDir, tempPic.getImgFileB()));
}
tempPic.setImgFileB(imgBFile.getName());
tempPic.setImgFileHashB(HMACSHA1.genSha1HashOfFile(imgBFile));
}
// 设置图片上传时间
tempPic.setUploadTime(new Date());
sqlSession.update("com.itrus.portal.db.TempPicMapper.updateByPrimaryKey", tempPic);
// 将random,usercert有关联的小于当前插入数据时间的信息设置为无效,并删除图片
tempPicService.removeRandomUserCert(tempPic);
// 上传图片成功
retMap.put("retCode", 1);
return retMap;
}
use of com.itrus.portal.db.TempPic in project portal by ixinportal.
the class TempPicService method removeRandomUserCert.
/**
* 将旧的临时图片删除,并设置为无效状态
*
* @param temPic
* @throws Exception
*/
public void removeRandomUserCert(TempPic temPic) throws Exception {
TempPicExample tempPicExample = new TempPicExample();
TempPicExample.Criteria tempPicCriteria = tempPicExample.or();
tempPicCriteria.andCreateTimeLessThan(new Date(temPic.getCreateTime().getTime() - DAY));
// 2:上传时间为空
// TempPicExample.Criteria tempPicCriteria2 = tempPicExample.or();
// tempPicCriteria2.andUploadTimeIsNull();
List<TempPic> tempPicList = sqlSession.selectList("com.itrus.portal.db.TempPicMapper.selectByExample", tempPicExample);
if (tempPicList.size() > 0) {
for (TempPic tempPic : tempPicList) {
File imgDir = getDir(tempPic.getRandom());
// }
if (StringUtils.isNotBlank(tempPic.getImgFileA())) {
FileUtils.deleteQuietly(imgDir);
}
if (StringUtils.isNotBlank(tempPic.getImgFileB())) {
FileUtils.deleteQuietly(imgDir);
}
// 删除无效的临时记录
sqlSession.delete("com.itrus.portal.db.TempPicMapper.deleteByPrimaryKey", tempPic);
}
}
}
Aggregations