| @@ -8,9 +8,11 @@ import com.iformall.domain.po.base.BaseEntity; | |||||
| import com.iformall.domain.po.sm.MouldPatch; | import com.iformall.domain.po.sm.MouldPatch; | ||||
| import com.iformall.domain.po.sm.MouldPatchSign; | import com.iformall.domain.po.sm.MouldPatchSign; | ||||
| import com.iformall.domain.po.sm.UserMouldVideo; | import com.iformall.domain.po.sm.UserMouldVideo; | ||||
| import com.iformall.domain.vo.WxCouponOrderBVo; | |||||
| import com.iformall.enums.EnumMouldSendType; | import com.iformall.enums.EnumMouldSendType; | ||||
| import com.iformall.enums.EnumVideoStatus; | import com.iformall.enums.EnumVideoStatus; | ||||
| import com.iformall.enums.EnumaMouldPatchStatus; | import com.iformall.enums.EnumaMouldPatchStatus; | ||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.sm.MouldPatchService; | import com.iformall.service.sm.MouldPatchService; | ||||
| import com.iformall.service.sm.MouldPatchSignService; | import com.iformall.service.sm.MouldPatchSignService; | ||||
| import com.iformall.service.sm.UserMouldVideoService; | import com.iformall.service.sm.UserMouldVideoService; | ||||
| @@ -20,12 +22,18 @@ import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import lombok.SneakyThrows; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.*; | |||||
| import java.net.URL; | |||||
| import java.nio.charset.StandardCharsets; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -198,4 +206,55 @@ public class UserMouldVideoController extends BaseController { | |||||
| } | } | ||||
| } | } | ||||
| @SneakyThrows | |||||
| @GetMapping("exportVideo") | |||||
| public void exportVideo(Long id, HttpServletRequest request, HttpServletResponse response) { | |||||
| logger.debug("[" + getIpAddr() + "] UserMouldVideoController::exportVideo"); | |||||
| response.reset(); | |||||
| OutputStream outputStream = null; | |||||
| try { | |||||
| outputStream = response.getOutputStream(); | |||||
| } catch (IOException e) { | |||||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); | |||||
| } | |||||
| try{ | |||||
| if(id == null){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| UserMouldVideo mouldVideo = userMouldVideoService.getById(id); | |||||
| if(mouldVideo == null || !mouldVideo.getUserId().equals(getMemberId())){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到用户数据"); | |||||
| } | |||||
| if(!EnumVideoStatus.upload_success.getCode().equals(mouldVideo.getVideoStatus())){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"视频未生成成功"); | |||||
| } | |||||
| //获取响应的输出流 | |||||
| InputStream inputStream = new URL(mouldVideo.getVideoPlayUrl()).openStream(); | |||||
| response.setHeader("Content-Disposition", "attachment; filename="+mouldVideo.getTitle() ); | |||||
| //解决编码问题 | |||||
| response.setHeader("Content-Type","application/octet-stream"); | |||||
| byte[] cache = new byte[1024 * 300]; | |||||
| int flag; | |||||
| while ((flag = inputStream.read(cache))!=-1){ | |||||
| outputStream.write(cache, 0, flag); | |||||
| } | |||||
| }catch(MallinkException e){ | |||||
| ResultData resultData = new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| //解决编码问题 | |||||
| response.setHeader("Content-Type","application/json"); | |||||
| outputStream.write(JSONObject.toJSONString(resultData).getBytes(StandardCharsets.UTF_8)); | |||||
| }finally { | |||||
| outputStream.flush(); | |||||
| outputStream.close(); | |||||
| } | |||||
| } | |||||
| } | } | ||||