From 14addb5937081691d9958cb65d03e0a684074af2 Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Mon, 17 May 2021 10:20:34 +0800 Subject: [PATCH 1/2] fix neupos --- .../iformall/controller/BaseController.java | 215 +----------------- .../controller/NeuPosAdminController.java | 12 + .../domain/po/NeuPosOrderMasterExt.java | 11 +- .../mapper/NeuPosOrderMasterExtMapper.xml | 102 ++++++--- 4 files changed, 90 insertions(+), 250 deletions(-) diff --git a/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/BaseController.java b/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/BaseController.java index 24d20038b..47aee76e7 100644 --- a/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/BaseController.java +++ b/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/BaseController.java @@ -44,24 +44,6 @@ public class BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - @Autowired - private boolean isFmOpen; - - @Autowired - private WxAppinfoService wxAppinfoService; - - @Autowired - private FmOpenService openService; - - @Autowired - private WxCUserBasicInfoService wxCUserBasicInfoService; - - @Autowired - private WxCUserBasicChildService wxCUserBasicChildService; - - @Autowired - private CUserTokenService cUserTokenService; - @Autowired @Qualifier("objectCommonRedisTemplate") RedisTemplate objectCommonRedisTemplate; @@ -74,7 +56,7 @@ public class BaseController { setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); } catch (ParseException e) { try { - setValue(new SimpleDateFormat("yyyy-MM-dd ").parse(value)); + setValue(new SimpleDateFormat("yyyy-MM-dd").parse(value)); } catch (ParseException e1) { setValue(null); } @@ -88,202 +70,7 @@ public class BaseController { }); } - @Deprecated - public String getTenantId() { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String tenantId = (String) request.getAttribute(Constant.TENANT_ID); - return tenantId; - } - - public TenantEntity getTenantInfo() { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String tenantId = (String) request.getAttribute(Constant.TENANT_ID); - String parentTenantId = (String) request.getAttribute(Constant.PARENT_TENANT_ID); - TenantEntity tenantEntity = new TenantEntity() ; - tenantEntity.setTenantId(tenantId); - tenantEntity.setParentTenantId(parentTenantId); - return tenantEntity; - } - - public String getFinalTenantId() { - TenantEntity tenantEntity = getTenantInfo(); - return tenantEntity.getFinalTenantId(); - } - - public Long getMemberId() { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - Long memberId = (Long) request.getAttribute(Constant.LOGIN_MEMBER_KEY); - if(memberId == null){ - throw new MallinkException(ErrorCode.USER_IS_NOT_MEMBER); - } - return memberId; - } - - /** - * 微信端获取当前用户 wx_c_user,非会员 - * 请尽量多用getTenantId, getUserId - */ - public WxCUser getWxCUser() { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - BaseCUserEntity baseuser = (BaseCUserEntity) request.getAttribute(Constant.REQUEST_C_USER_KEY); - - if (baseuser == null) { - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - if (baseuser.getRealUser() == null) { - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - WxCUser user = RedisCacheUtils.getFieldObject(baseuser, "realUser", WxCUser.class); - TenantEntity tenantEntity = getTenantInfo(); - if (user.getTenantId() == null) { - user.setTenantId(tenantEntity.getTenantId()); - } - if (user.getParentTenantId() == null) { - user.setParentTenantId(tenantEntity.getParentTenantId()); - } - return user; - } - - public void removeCacheCUser() { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - BaseCUserEntity baseuser = (BaseCUserEntity) request.getAttribute(Constant.REQUEST_C_USER_KEY); - cUserTokenService.removeTokenCache(baseuser.getToken()); - } - - public void updateCacheCUser(String token,Object cuser) { - cUserTokenService.updateTokenCache(token, cuser); - } - - private WxCUserBasicInfo getCacheMember(Long memberId,String finalTenantId,String key,long seconds) throws MallinkException { - // 缓存 - WxCUserBasicInfo member = RedisCacheUtils.getCacheObject(objectCommonRedisTemplate, key, WxCUserBasicInfo.class); - if(null == member) { - member = wxCUserBasicInfoService.getById(memberId,finalTenantId); - if (member == null) { - throw new MallinkException(ErrorCode.USER_IS_EMPTY); - } - setCUserBasicChild(member); - - RedisCacheUtils.cache(objectCommonRedisTemplate, key, member, seconds); - } - return member; - } - public WxCUserBasicInfo getCacheMember() throws MallinkException { - Long memberId = getMemberId(); - String key = "webapp:member:"+memberId; - return getCacheMember(memberId,getFinalTenantId(), key, 3600*24*3); - } - - /*此处缓存短暂时间,因为积分、成长值记录*/ - public WxCUserBasicInfo getShortCacheMember(Long memberId,String finalTenantId) throws Exception { - String key = "webapp:short:member:"+memberId; - return getCacheMember(memberId,finalTenantId, key, 100); - } - - public void removeCacheMember(Long memberId) { - String key = "webapp:member:"+memberId; - RedisCacheUtils.removeCache(objectCommonRedisTemplate, key); - String shortKey = "webapp:short:member:"+memberId; - RedisCacheUtils.removeCache(objectCommonRedisTemplate, shortKey); - } - - public WxAppinfo getAppInfo(String appId) { - return wxAppinfoService.getByAppId(appId); - } - - public WxMaService getWeappService(String appId) { - if(isFmOpen) { - return openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); - } else { - WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); - if (appinfo == null) { - return null; - } - WxMaService service = MaUtil.getWeappService(appinfo); - return service; - } - - } - - public WxMaService getWeappServiceByAppInfo(WxAppinfo appinfo) { - if(!isFmOpen) { - WxMaService service = MaUtil.getWeappService(appinfo); - return service; - } - return null; - } - - - public Long saveToBasicInfoByCUser(String userPhone,String userName,String avatarUrl,Integer sex,Long userId) { - TenantEntity tenantEntity = getTenantInfo(); - if (StringUtils.isBlank(userPhone)) - return null; - - WxCUserBasicInfo byId = null; - if (null != userId) { - byId = wxCUserBasicInfoService.getById(userId,getFinalTenantId()); - } - - WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, userPhone); - - if (basicInfo != null) { - if (byId != null) { - if (!byId.getId().equals(basicInfo.getId())) { - //数据库存在此手机号的会员,并且当前微信存在另一手机号会员 - logger.error("会员" + userId + "更换手机号时,当前手机号会员表已存在:" + userPhone); - return Long.valueOf(-1); - } - } - if (!basicInfo.getTenantId().contains("," + tenantEntity.getTenantId() + ",")) { - basicInfo.setTenantId(basicInfo.getTenantId() + tenantEntity.getTenantId() + ","); - } - basicInfo.setNickName(userName); - basicInfo.setAvatarUrl(avatarUrl); - basicInfo.setSex(sex); - wxCUserBasicInfoService.update(basicInfo); - removeCacheMember(basicInfo.getId()); - return basicInfo.getId(); - } else { - if (byId != null) { - if (!byId.getTenantId().contains("," + tenantEntity.getTenantId() + ",")) { - byId.setTenantId(byId.getTenantId() + tenantEntity.getTenantId() + ","); - } - byId.setPhone(userPhone); - byId.setNickName(userName); - byId.setAvatarUrl(avatarUrl); - byId.setSex(sex); - wxCUserBasicInfoService.update(byId); - removeCacheMember(basicInfo.getId()); - return byId.getId(); - } else { - basicInfo = new WxCUserBasicInfo(); - basicInfo.setTenantId("," + tenantEntity.getTenantId() + ","); - basicInfo.setFinalTenantId(tenantEntity.getFinalTenantId()); - basicInfo.setPhone(userPhone); - basicInfo.setNickName(userName); - basicInfo.setAvatarUrl(avatarUrl); - basicInfo.setSex(sex); - wxCUserBasicInfoService.save(basicInfo); - removeCacheMember(basicInfo.getId()); - return basicInfo.getId(); - } - } - } - - public String getIpAddr() { - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String ipaddress = IPUtil.getIpAddr(request); - return ipaddress; - } - - private void setCUserBasicChild(WxCUserBasicInfo basicInfo){ - WxCUserBasicChild child = new WxCUserBasicChild(); - child.setCUserId(basicInfo.getId()); - child.setTenantId(basicInfo.getFinalTenantId()); - List list = wxCUserBasicChildService.findList(child); - basicInfo.setChildrenList(list); - } } diff --git a/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/NeuPosAdminController.java b/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/NeuPosAdminController.java index f08a304d7..ef723de1b 100644 --- a/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/NeuPosAdminController.java +++ b/mallinkNeuPosAdmin/src/main/java/com/iformall/controller/NeuPosAdminController.java @@ -6,6 +6,8 @@ import com.iformall.common.ResultData; import com.iformall.domain.po.NeuPosOrderMasterExt; import com.iformall.domain.po.WxActivity; import com.iformall.service.NeuPosOrderService; +import com.iformall.utils.DateUtils; + import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -66,6 +68,12 @@ public class NeuPosAdminController extends BaseController { return new ResultData(maplist); } + private void setDate(NeuPosOrderMasterExt example) { + if (null != example.getCreateEnd()) { + example.setCreateEnd(DateUtils.stringToDate(DateUtils.date2String(example.getCreateEnd(), "yyyy-MM-dd") +" 23:59:59","yyyy-MM-dd HH:mm:ss")); + } + } + @ApiOperation("集团类型流水") @GetMapping("payTypeOrderlist") @ApiImplicitParams({ @@ -76,6 +84,7 @@ public class NeuPosAdminController extends BaseController { if (!tenantValid(tenantId)) { return new ResultData(Result.ERROR,"未安装POS系统"); } + setDate(example); example.setOrgId(24); PageInfo maplist = neuPosOrderService.queryShopPayOrderList(example,pageNum,pageSize); return new ResultData(maplist); @@ -89,6 +98,7 @@ public class NeuPosAdminController extends BaseController { if (!tenantValid(tenantId)) { return new ResultData(Result.ERROR,"未安装POS系统"); } + setDate(example); example.setOrgId(24); List maplist = neuPosOrderService.queryShopPayOrderSum(example); return new ResultData(maplist); @@ -104,6 +114,7 @@ public class NeuPosAdminController extends BaseController { if (!tenantValid(tenantId)) { return new ResultData(Result.ERROR,"未安装POS系统"); } + setDate(example); example.setOrgId(24); PageInfo maplist = neuPosOrderService.queryShopPayTypeTradeList(example,pageNum,pageSize); return new ResultData(maplist); @@ -119,6 +130,7 @@ public class NeuPosAdminController extends BaseController { if (!tenantValid(tenantId)) { return new ResultData(Result.ERROR,"未安装POS系统"); } + setDate(example); example.setOrgId(24); PageInfo maplist = neuPosOrderService.queryOrderList(example,pageNum,pageSize); return new ResultData(maplist); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/NeuPosOrderMasterExt.java b/mallinkService/src/main/java/com/iformall/domain/po/NeuPosOrderMasterExt.java index e9a47c2b9..27fef2ff8 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/NeuPosOrderMasterExt.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/NeuPosOrderMasterExt.java @@ -1,13 +1,7 @@ package com.iformall.domain.po; -import java.io.Serializable; -import java.math.BigDecimal; import java.util.Date; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.domain.po.base.BaseEntity; - import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -16,10 +10,9 @@ import lombok.ToString; @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) public class NeuPosOrderMasterExt extends BaseEntity{ - private Integer orgId; + private static final long serialVersionUID = 6080005017786775288L; + private Integer orgId; private Integer shopId; - @TableField(exist = false) private Date createBegin; - @TableField(exist = false) private Date createEnd; } \ No newline at end of file diff --git a/mallinkService/src/main/resources/mapper/NeuPosOrderMasterExtMapper.xml b/mallinkService/src/main/resources/mapper/NeuPosOrderMasterExtMapper.xml index dcc2a765a..3e50b3f77 100644 --- a/mallinkService/src/main/resources/mapper/NeuPosOrderMasterExtMapper.xml +++ b/mallinkService/src/main/resources/mapper/NeuPosOrderMasterExtMapper.xml @@ -6,8 +6,8 @@ SELECT shop_id as shopId, sum(real_pay_amount) as payAmount, count(0) as payCount - from order_master - where order_status = 2 and order_type != '3' + from order_master_v2 + where order_status = 4 and order_type != '3' and org_id = #{orgId} @@ -32,8 +32,8 @@ count(if(order_status=4,true,null)) refundCount, ifnull(sum(if(order_status=2,real_pay_amount,0)),0) as amount, pay_type as payType - from order_master - where pay_status = 2 and order_type != '3' + from order_master_v2 + where pay_status = 4 and order_type != '3' and org_id = #{orgId} @@ -50,27 +50,75 @@ SELECT order_number as orderNumber, serial_no as serialNo, order_amount as orderAmount,real_pay_amount as realPayAmount, discount_amount as discountAmount, pay_type as payType,paid_time as paidTime,order_status as orderStatus - from order_master - where order_status = 2 and order_type != '3' + from order_master_v2 + where order_status = 4 and order_type != '3' and org_id = #{orgId} From 3ead111d9c292252f70cf207a99be483e3638a3e Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Mon, 17 May 2021 11:33:35 +0800 Subject: [PATCH 2/2] fix video --- .../controller/video/VideoController.java | 24 ++++++++++- .../java/com/iformall/video/VideoExcutor.java | 2 + .../java/com/iformall/video/VideoFactory.java | 2 + .../video/aliyun/AliyunVideoExcutor.java | 17 ++++++-- .../aliyun/sdk/upload/AliyunVedioUpload.java | 28 +++++++++---- .../sdk/upload/PutObjectProgressListener.java | 41 ++++++++++++------- .../aliyun/sdk/upload/UploadCacheHelper.java | 37 +++++++++++++++++ 7 files changed, 122 insertions(+), 29 deletions(-) create mode 100644 mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/UploadCacheHelper.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java index 597d9d55e..e4e922d52 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java @@ -90,8 +90,7 @@ public class VideoController extends BaseController { */ @PostMapping(value = "/upload", consumes = "multipart/*", headers = "content-type=multipart/form-data") @ApiOperation("上传视频") - @SystemControllerLog(description = "文件上传") - public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map param) { + public ResultData upload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map param) { try { String title = param.get("title"); VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo(title, multiReq.getInputStream()); @@ -101,5 +100,26 @@ public class VideoController extends BaseController { return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); } } + + /** + * 上传视频 + * + * @param multiReq + * @return + * @throws Exception + */ + @GetMapping(value = "/uploadProgress") + @ApiOperation("上传视频进度") + @ApiImplicitParams({ + @ApiImplicitParam(name = "videoId", value = "视频编号", dataType = "String", paramType = "query", required = true)}) + public ResultData uploadProgress(String videoId) { + try { + String result = videoFactory.getExcutor(videoType).getVedioUploadProgress(videoId); + return new ResultData(result); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); + } + } } diff --git a/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java b/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java index 3fa6395cb..fefce84ac 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java +++ b/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java @@ -17,4 +17,6 @@ public interface VideoExcutor { //ext,后缀名 public VideUploadResult uploadNetVideo(String title,String url,String ext); + + public String getVedioUploadProgress(String videoId); } diff --git a/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java b/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java index 5f1ac6035..e8afbaddb 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java +++ b/mallinkVideo/src/main/java/com/iformall/video/VideoFactory.java @@ -4,6 +4,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import com.iformall.video.aliyun.AliyunVideoExcutor; diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java index d95fe4f24..b137e7e29 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java @@ -7,6 +7,8 @@ import java.io.IOException; import java.io.InputStream; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import com.aliyun.vod.upload.resp.UploadStreamResponse; @@ -28,6 +30,10 @@ public class AliyunVideoExcutor implements VideoExcutor { @Autowired AliyunVideoConfig config; + @Autowired + @Qualifier("objectCommonRedisTemplate") + RedisTemplate redisTemplate; + private String getUrlByVeidoId(String videoId) { try { return AliyunVedioServer.getVedioUrl(config, videoId); @@ -41,7 +47,7 @@ public class AliyunVideoExcutor implements VideoExcutor { public VideUploadResult uploadLocalVideo(String title,String localFile) { VideUploadResult result = new VideUploadResult(); try { - UploadVideoResponse response =AliyunVedioUpload.uploadVideo(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, localFile); + UploadVideoResponse response =AliyunVedioUpload.uploadVideo(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, localFile,redisTemplate); if (response.isSuccess()) { result.setVideoId(response.getVideoId()); result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); @@ -64,7 +70,7 @@ public class AliyunVideoExcutor implements VideoExcutor { VideUploadResult result = new VideUploadResult(); UploadStreamResponse response; try { - response = AliyunVedioUpload.uploadStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, "", inputStream); + response = AliyunVedioUpload.uploadStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, "", inputStream,redisTemplate); if (response.isSuccess()) { result.setVideoId(response.getVideoId()); result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); @@ -91,7 +97,7 @@ public class AliyunVideoExcutor implements VideoExcutor { @Override public VideUploadResult uploadNetVideo(String title,String url,String ext) { VideUploadResult result = new VideUploadResult(); - UploadURLStreamResponse response = AliyunVedioUpload.uploadURLStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, url, ext); + UploadURLStreamResponse response = AliyunVedioUpload.uploadURLStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, url, ext,redisTemplate); if (response.isSuccess()) { result.setVideoId(response.getVideoId()); result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); @@ -103,4 +109,9 @@ public class AliyunVideoExcutor implements VideoExcutor { } return result; } + + @Override + public String getVedioUploadProgress(String videoId) { + return AliyunVedioUpload.getUploadProgress(redisTemplate, videoId); + } } diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java index d0d30e682..a0fd76045 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java @@ -6,6 +6,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import org.springframework.data.redis.core.RedisTemplate; + import com.aliyun.vod.upload.impl.UploadAttachedMediaImpl; import com.aliyun.vod.upload.impl.UploadImageImpl; import com.aliyun.vod.upload.impl.UploadM3u8FileImpl; @@ -103,7 +105,7 @@ public class AliyunVedioUpload { // 任何上传方式文件名必须包含扩展名 String fileName = "/Users/test/video/test.mp4"; // 本地文件上传 - uploadVideo(accessKeyId, accessKeySecret,"cn-beijing", title, fileName); + uploadVideo(accessKeyId, accessKeySecret,"cn-beijing", title, fileName,null); // 待上传视频的网络流地址 String url = "http://test.aliyun.com/video/test.mp4"; @@ -111,7 +113,7 @@ public class AliyunVedioUpload { // 2.网络流上传 // 文件扩展名,当url中不包含扩展名时,需要设置该参数 String fileExtension = "mp4"; - uploadURLStream(accessKeyId, accessKeySecret, "cn-beijing",title, url, fileExtension); + uploadURLStream(accessKeyId, accessKeySecret, "cn-beijing",title, url, fileExtension,null); // 3.文件流上传 // testUploadFileStream(accessKeyId, accessKeySecret, title, fileName); @@ -130,7 +132,7 @@ public class AliyunVedioUpload { } catch (IOException e) { e.printStackTrace(); } - uploadStream(accessKeyId, accessKeySecret, "cn-beijing",title, fileName, inputStream); + uploadStream(accessKeyId, accessKeySecret, "cn-beijing",title, fileName, inputStream,null); // 二、图片上传 @@ -161,7 +163,8 @@ public class AliyunVedioUpload { * @param title * @param fileName */ - public static UploadVideoResponse uploadVideo(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName) { + public static UploadVideoResponse uploadVideo(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName, + RedisTemplate redisTemplate) { UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName); /* 可指定分片上传时每个分片的大小,默认为2M字节 */ request.setPartSize(2 * 1024 * 1024L); @@ -219,7 +222,8 @@ public class AliyunVedioUpload { * @param fileName * @param url */ - public static UploadURLStreamResponse uploadURLStream(String accessKeyId, String accessKeySecret,String regionId, String title, String url, String fileExtension) { + public static UploadURLStreamResponse uploadURLStream(String accessKeyId, String accessKeySecret,String regionId, String title, + String url, String fileExtension,RedisTemplate redisTemplate) { UploadURLStreamRequest request = new UploadURLStreamRequest(accessKeyId, accessKeySecret, title, url); /* 文件扩展名*/ @@ -271,7 +275,8 @@ public class AliyunVedioUpload { * @param title * @param fileName */ - private static void uploadFileStream(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName) { + private static void uploadFileStream(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName, + RedisTemplate redisTemplate) { UploadFileStreamRequest request = new UploadFileStreamRequest(accessKeyId, accessKeySecret, title, fileName); /* 是否使用默认水印(可选),指定模板组ID时,根据模板组配置确定是否使用默认水印*/ //request.setShowWaterMark(true); @@ -323,7 +328,8 @@ public class AliyunVedioUpload { * @param fileName * @param inputStream */ - public static UploadStreamResponse uploadStream(String accessKeyId, String accessKeySecret,String regionId, String title, String fileName, InputStream inputStream) { + public static UploadStreamResponse uploadStream(String accessKeyId, String accessKeySecret,String regionId, String title, + String fileName, InputStream inputStream,RedisTemplate redisTemplate) { UploadStreamRequest request = new UploadStreamRequest(accessKeyId, accessKeySecret, title, fileName, inputStream); /* 是否使用默认水印(可选),指定模板组ID时,根据模板组配置确定是否使用默认水印*/ //request.setShowWaterMark(true); @@ -365,7 +371,7 @@ public class AliyunVedioUpload { * @param accessKeyId * @param accessKeySecret */ - public static void uploadImageLocalFile(String accessKeyId, String accessKeySecret,String regionId) { + public static void uploadImageLocalFile(String accessKeyId, String accessKeySecret,String regionId,RedisTemplate redisTemplate) { /* 图片类型(必选)取值范围:default(默认),cover(封面),watermark(水印)*/ String imageType = "cover"; UploadImageRequest request = new UploadImageRequest(accessKeyId, accessKeySecret, imageType); @@ -409,7 +415,7 @@ public class AliyunVedioUpload { * @param accessKeyId * @param accessKeySecret */ - public static void uploadImageStream(String accessKeyId, String accessKeySecret,String regionId) { + public static void uploadImageStream(String accessKeyId, String accessKeySecret,String regionId,RedisTemplate redisTemplate) { /* 图片类型(必选)取值范围:default(默认),cover(封面),watermark(水印)*/ String imageType = "cover"; UploadImageRequest request = new UploadImageRequest(accessKeyId, accessKeySecret, imageType); @@ -682,4 +688,8 @@ public class AliyunVedioUpload { } return null; } + + public static String getUploadProgress(RedisTemplate redisTemplate,String videoId) { + return UploadCacheHelper.getUploadProgress(redisTemplate, PutObjectProgressListener.PRE_VIDEO_PROGRESS+videoId); + } } diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/PutObjectProgressListener.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/PutObjectProgressListener.java index 2868eb70b..c5b9565a3 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/PutObjectProgressListener.java +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/PutObjectProgressListener.java @@ -1,5 +1,7 @@ package com.iformall.video.aliyun.sdk.upload; +import org.springframework.data.redis.core.RedisTemplate; + import com.aliyun.oss.event.ProgressEvent; import com.aliyun.oss.event.ProgressEventType; import com.aliyun.vod.upload.impl.VoDProgressListener; @@ -33,54 +35,63 @@ public class PutObjectProgressListener implements VoDProgressListener { * 图片ID */ private String imageId; - + + public static final String PRE_VIDEO_PROGRESS = "video:progress:"; + private RedisTemplate redisTemplate; + public void progressChanged(ProgressEvent progressEvent) { long bytes = progressEvent.getBytes(); ProgressEventType eventType = progressEvent.getEventType(); switch (eventType) { // 开始上传事件 case TRANSFER_STARTED_EVENT: - if (videoId != null) { - System.out.println("qqqqStart to upload videoId " + videoId + "......"); - } - if (imageId != null) { - System.out.println("aaaStart to upload imageId " + imageId + "......"); - } + if (null != redisTemplate) { + if (videoId != null) { + UploadCacheHelper.cacheStart(redisTemplate, PRE_VIDEO_PROGRESS+videoId); + //System.out.println("qqqqStart to upload videoId " + videoId + "......"); + } + if (imageId != null) { + //System.out.println("aaaStart to upload imageId " + imageId + "......"); + } + } break; // 计算待上传文件总大小事件通知,只有调用本地文件方式上传时支持该事件 case REQUEST_CONTENT_LENGTH_EVENT: this.totalBytes = bytes; - System.out.println(this.totalBytes + "bytes in total will be uploaded to OSS."); + //System.out.println(this.totalBytes + "bytes in total will be uploaded to OSS."); break; // 已经上传成功文件大小事件通知 case REQUEST_BYTE_TRANSFER_EVENT: this.bytesWritten += bytes; if (this.totalBytes != -1) { int percent = (int) (this.bytesWritten * 100.0 / this.totalBytes); - System.out.println(bytes + " bytes have been written at this time, upload progress: " + - percent + "%(" + this.bytesWritten + "/" + this.totalBytes + ")"); + //System.out.println(bytes + " bytes have been written at this time, upload progress: " + + // percent + "%(" + this.bytesWritten + "/" + this.totalBytes + ")"); } else { - System.out.println(bytes + " bytes have been written at this time, upload sub total : " + - "(" + this.bytesWritten + ")"); + //System.out.println(bytes + " bytes have been written at this time, upload sub total : " + + // "(" + this.bytesWritten + ")"); } + UploadCacheHelper.cacheProgress(redisTemplate, PRE_VIDEO_PROGRESS+videoId,String.valueOf(this.bytesWritten)); break; // 文件全部上传成功事件通知 case TRANSFER_COMPLETED_EVENT: this.succeed = true; if (videoId != null) { - System.out.println("Succeed to upload videoId " + videoId + " , " + this.bytesWritten + " bytes have been transferred in total."); + UploadCacheHelper.cacheComplete(redisTemplate, PRE_VIDEO_PROGRESS+videoId); + //System.out.println("Succeed to upload videoId " + videoId + " , " + this.bytesWritten + " bytes have been transferred in total."); } if (imageId != null) { - System.out.println("Succeed to upload imageId " + imageId + " , " + this.bytesWritten + " bytes have been transferred in total."); + //System.out.println("Succeed to upload imageId " + imageId + " , " + this.bytesWritten + " bytes have been transferred in total."); } break; // 文件上传失败事件通知 case TRANSFER_FAILED_EVENT: if (videoId != null) { + UploadCacheHelper.cacheProgress(redisTemplate, PRE_VIDEO_PROGRESS+videoId,String.valueOf(this.bytesWritten)); System.out.println("Failed to upload videoId " + videoId + " , " + this.bytesWritten + " bytes have been transferred."); } if (imageId != null) { - System.out.println("Failed to upload imageId " + imageId + " , " + this.bytesWritten + " bytes have been transferred."); + //System.out.println("Failed to upload imageId " + imageId + " , " + this.bytesWritten + " bytes have been transferred."); } break; diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/UploadCacheHelper.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/UploadCacheHelper.java new file mode 100644 index 000000000..ef409b078 --- /dev/null +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/UploadCacheHelper.java @@ -0,0 +1,37 @@ +package com.iformall.video.aliyun.sdk.upload; + +import java.util.concurrent.TimeUnit; + +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; + +public class UploadCacheHelper { + + + public static void cacheStart(RedisTemplate template,String key) { + ValueOperations operations = template.opsForValue(); + operations.set(key, "begin", 24*3600,TimeUnit.SECONDS); + } + + public static void cacheComplete(RedisTemplate template,String key) { + ValueOperations operations = template.opsForValue(); + operations.set(key, "complete", 24*3600,TimeUnit.SECONDS); + } + + public static void cacheProgress(RedisTemplate template,String key,String bytes) { + ValueOperations operations = template.opsForValue(); + operations.set(key, bytes, 24*3600,TimeUnit.SECONDS); + } + + public static String getUploadProgress(RedisTemplate template,String key) { + if (template.hasKey(key)) { + ValueOperations operations = template.opsForValue(); + Object o = operations.get(key); + if (o instanceof String) { + return (String)o; + } + } + return null; + } + +}