| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.api.BaseController; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.annotation.EncryptionReq; |
| | | import com.doumee.config.annotation.EncryptionResp; |
| | | import com.doumee.core.annotation.trace.Trace; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | |
| | | import com.doumee.core.model.ApiResponse; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.FtpUtil; |
| | | import com.doumee.core.utils.azure.AzureBlobUtil; |
| | | import com.doumee.core.utils.huaweiOBS.ObsUtil; |
| | | import com.doumee.core.utils.qiyeweixin.QywxUtil; |
| | | import com.doumee.core.utils.qiyeweixin.model.response.QywxUploadMediaResponse; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.service.common.EmailService; |
| | | import com.doumee.core.utils.ImageWatermarkUtil; |
| | | import com.doumee.core.utils.aliyun.ALiYunUtil; |
| | | import com.doumee.core.utils.geocode.MapUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @ApiOperation(value = "上传OBS", notes = "上传OBS", httpMethod = "POST", position = 6) |
| | | @ApiOperation(value = "上传OSS", notes = "上传OSS,可传入经纬度自动添加时间+地址水印", httpMethod = "POST", position = 6) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "folder", value = "文件夹", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "file", value = "文件夹", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "latitude", value = "纬度(非必填,传入时添加水印)", paramType = "query", dataType = "Double"), |
| | | @ApiImplicitParam(name = "longitude", value = "经度(非必填,传入时添加水印)", paramType = "query", dataType = "Double"), |
| | | }) |
| | | @PostMapping(value = "/upload", headers = "content-type=multipart/form-data") |
| | | @ResponseBody |
| | | public void upload(HttpServletRequest request, HttpServletResponse response, String folder,String flag) throws Exception { |
| | | public void upload(HttpServletRequest request, HttpServletResponse response, String folder, String flag, |
| | | @RequestParam(required = false) Double latitude, |
| | | @RequestParam(required = false) Double longitude) throws Exception { |
| | | Date d1 = new Date(); |
| | | log.error("总得上传文件成功=============开始========="+DateUtil.getPlusTime2(d1)); |
| | | if(Objects.isNull(folder)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"目标文件夹错误"); |
| | | } |
| | | String prefixPath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode(); |
| | | String prefixPath = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(); |
| | | InputStream is = null; |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("text/html;charset=UTF-8"); |
| | |
| | | System.out.println(file.getSize()); |
| | | String originname = file.getOriginalFilename(); |
| | | is = file.getInputStream(); |
| | | |
| | | // 经纬度水印处理 |
| | | InputStream uploadStream = is; |
| | | if (latitude != null && longitude != null) { |
| | | try { |
| | | JSONObject geoResult = MapUtil.reverseGeocode(latitude, longitude); |
| | | String address = geoResult != null ? geoResult.getString("formatted_addresses") : ""; |
| | | String timeText = DateUtil.getPlusTime2(new Date()); |
| | | uploadStream = ImageWatermarkUtil.addWatermark(is, timeText, address, latitude, longitude); |
| | | log.info("图片水印添加成功: time={}, address={}", timeText, address); |
| | | } catch (Exception e) { |
| | | log.warn("水印处理失败,使用原图上传: {}", e.getMessage()); |
| | | try { is.reset(); } catch (Exception ignored) {} |
| | | uploadStream = is; |
| | | } |
| | | } |
| | | |
| | | String endType = ".jpg"; |
| | | if(originname.indexOf(".")>0){ |
| | | endType=originname.substring(originname.lastIndexOf("."),originname.length()); |
| | |
| | | String fName = date+"/"+ UUID.randomUUID()+endType; |
| | | String fileName = folder+"/"+fName; |
| | | boolean r =false; |
| | | ObsUtil obsUtil = new ObsUtil( systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ACCESSID).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ACCESSKEY).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ENDPOINT).getCode()); |
| | | r = obsUtil.uploadFile( systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_BUCKET).getCode(),is,fileName);//上传 |
| | | |
| | | ALiYunUtil obs = new ALiYunUtil(systemDictDataBiz.queryByCode(Constants.OSS,Constants.ENDPOINT).getCode(),systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_ID).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.OSS,Constants.ACCESS_KEY).getCode()); |
| | | |
| | | r = obs.uploadOnlineObject(uploadStream,systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode(), fileName,null); |
| | | if(r){ |
| | | context.put("success", true); |
| | | context.put("code", 200); |
| | | context.put("errno",0); |
| | | JSONObject fileJSON = new JSONObject(); |
| | | // fileJSON.put("prefixPath", prefixPath); |
| | | // fileJSON.put("folder", folder); |
| | | fileJSON.put("url", prefixPath+fileName); |
| | | fileJSON.put("imgaddr", fName); |
| | | fileJSON.put("imgname", fileName); |