@ -4,6 +4,8 @@ package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.fasterxml.jackson.annotation.JsonFormat ;
import com.zh.project0512.annotation.AdminCheckAuthorityAnnotation ;
import com.zh.project0512.annotation.AdminTokenValid ;
import com.zh.project0512.mapper.UserEffectRecordsMapper ;
@ -13,6 +15,7 @@ import com.zh.project0512.service.IUserService;
import com.zh.project0512.service.IVideoEffectSettingService ;
import com.zh.project0512.service.IVideoService ;
import com.zh.project0512.utils.AppMessageUtil ;
import com.zh.project0512.utils.ExcelUtil ;
import com.zh.project0512.utils.HttpUtil ;
import com.zh.project0512.utils.MybatisPlusUtil ;
import com.zh.project0512.utils.result.HttpStatusEnum ;
@ -21,19 +24,24 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema ;
import io.swagger.v3.oas.annotations.tags.Tag ;
import lombok.Data ;
import org.apache.poi.ss.usermodel.Workbook ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.validation.annotation.Validated ;
import org.springframework.web.bind.annotation.* ;
import javax.servlet.http.HttpServletResponse ;
import javax.validation.constraints.Max ;
import javax.validation.constraints.Min ;
import javax.validation.constraints.NotNull ;
import java.io.IOException ;
import java.io.OutputStream ;
import java.io.UnsupportedEncodingException ;
import java.net.URLEncoder ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.time.format.DateTimeFormatter ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.* ;
/ * *
* < p >
@ -73,6 +81,12 @@ public class VideoController {
private Integer departmentId ;
@Schema ( title = "任务标题" )
private String taskTitle ;
@Schema ( title = "开始时间(yyyy-MM-dd HH:mm:ss)" )
@JsonFormat ( pattern = "yyyy-MM-dd HH:mm:ss" )
private LocalDateTime beginTime ;
@Schema ( title = "结束时间(yyyy-MM-dd HH:mm:ss)" )
@JsonFormat ( pattern = "yyyy-MM-dd HH:mm:ss" )
private LocalDateTime endTime ;
}
@Operation ( summary = "审核视频列表" )
@ -84,9 +98,51 @@ public class VideoController {
qw . like ( param . providerName ! = null , "t2.name" , param . getProviderName ( ) ) ;
qw . eq ( param . getDepartmentId ( ) ! = null , "t3.departmentId" , param . getDepartmentId ( ) ) ;
qw . like ( param . getTaskTitle ( ) ! = null , "t4.title" , param . getTaskTitle ( ) ) ;
qw . ge ( param . getBeginTime ( ) ! = null , "t1.creatAt" , param . getBeginTime ( ) ) ;
qw . le ( param . getEndTime ( ) ! = null , "t1.creatAt" , param . getEndTime ( ) ) ;
return Result . success ( videoService . pageList ( MybatisPlusUtil . SetNumPage ( param . getPageNum ( ) , param . getPageSize ( ) ) , qw ) ) ;
}
@Operation ( summary = "导出excel" , description = "审核视频列表导出" )
@PostMapping ( "/excel" )
@AdminTokenValid
public void excel ( HttpServletResponse response , @Validated @RequestBody VParam param ) throws IOException {
//这是表头及格式
String [ ] [ ] array = {
{ "申请人" , "任务标题" , "平台" , "传播链接" , "播放数" , "点赞数" , "收藏数" , "评论数" , "转发数" , "推荐数" , "提交时间" } ,
{ "providerName" , "taskTitle" , "type" , "url" , "playNum" , "commendNum" , "collectionNum" , "commentNum" , "reSendNum" , "recommendNum" , "creatAt" } ,
{ "String" , "String" , "String" , "String" , "int" , "int" , "int" , "int" , "int" , "int" , "LocalDateTime" }
} ;
QueryWrapper < Video > qw = new QueryWrapper < > ( ) ;
qw . eq ( "t1.status" , param . getStatus ( ) ) ;
qw . like ( param . providerName ! = null , "t2.name" , param . getProviderName ( ) ) ;
qw . eq ( param . getDepartmentId ( ) ! = null , "t3.departmentId" , param . getDepartmentId ( ) ) ;
qw . like ( param . getTaskTitle ( ) ! = null , "t4.title" , param . getTaskTitle ( ) ) ;
qw . ge ( param . getBeginTime ( ) ! = null , "t1.creatAt" , param . getBeginTime ( ) ) ;
qw . le ( param . getEndTime ( ) ! = null , "t1.creatAt" , param . getEndTime ( ) ) ;
IPage < Map > iPage = videoService . pageList ( MybatisPlusUtil . SetNumPage ( param . getPageNum ( ) , param . getPageSize ( ) ) , qw ) ;
List < Map > records = iPage . getRecords ( ) ;
for ( Map m : records ) {
//平台: 1抖音; 2快手; 3朋友圈; 4视频号
Integer platform = ( Integer ) m . get ( "type" ) ;
if ( platform ! = null ) {
m . replace ( "type" , platform = = 1 ? "抖音" : ( platform = = 2 ? "快手" : ( platform = = 3 ? "朋友圈" : platform = = 4 ? "朋友圈" : null ) ) ) ;
}
}
Workbook wb = ExcelUtil . writeToExcelByList ( array , records ) ;
OutputStream output = response . getOutputStream ( ) ;
String fileName = "审核视频数据.xlsx" ;
try {
fileName = URLEncoder . encode ( fileName , "UTF-8" ) ;
} catch ( UnsupportedEncodingException e ) {
e . printStackTrace ( ) ;
}
response . setHeader ( "Content-disposition" , "attachment;filename=" + fileName + ";" + "filename*=utf-8''" + fileName ) ;
wb . write ( output ) ;
output . close ( ) ;
}
@Data
static class VVParam {
@NotNull ( message = "id不能为空" )
@ -136,6 +192,22 @@ public class VideoController {
public Result valid ( @Validated @RequestBody VVParam param ) {
int id = param . getId ( ) ;
Video video = videoService . getById ( id ) ;
String platForm = "未知平台" ;
switch ( video . getType ( ) ) {
case 1 :
platForm = "抖音" ;
break ;
case 2 :
platForm = "快手" ;
break ;
case 3 :
platForm = "朋友圈" ;
break ;
case 4 :
platForm = "视频号" ;
break ;
default :
}
if ( null = = video ) {
return Result . fail ( HttpStatusEnum . CUSTOM_EXCEPTION , "未找到该视频" ) ;
}
@ -155,7 +227,7 @@ public class VideoController {
if ( ! op ) {
return Result . fail ( HttpStatusEnum . CUSTOM_EXCEPTION , "无效操作" ) ;
}
appMessage . setDescription ( "您的 抖音 传播效果审核未通过,未通过原因:" + param . getReason ( ) + "。" ) ;
appMessage . setDescription ( "您的 " + platForm + " 传播效果审核未通过,未通过原因:" + param . getReason ( ) + "。" ) ;
// 企业微信消息通知
if ( touser ! = null ) {
appMessage . setTouser ( touser ) ;
@ -184,29 +256,14 @@ public class VideoController {
up . set ( "updateAt" , LocalDateTime . now ( ) ) ;
videoService . update ( up ) ;
userEffectRecordsMapper . saveEffectResult ( new UserEffectRecords ( ) . setUserId ( video . getUserId ( ) ) . setEffectResultTran ( effectResult - originEffectResult ) . setCreateAt ( LocalDateTime . now ( ) ) ) ;
String platForm = "未知平台" ;
switch ( video . getType ( ) ) {
case 1 :
platForm = "抖音" ;
break ;
case 2 :
platForm = "快手" ;
break ;
case 3 :
platForm = "朋友圈" ;
break ;
case 4 :
platForm = "视频号" ;
break ;
default :
}
appMessage . setDescription ( "恭喜您," + platForm + "传播效果审核通过,平台评定传播值为" + effectResult + "。" ) ;
// 企业微信消息通知
if ( touser ! = null ) {
appMessage . setTouser ( touser ) ;
List < JSONObject > content_item = new ArrayList < > ( ) ;
content_item . add ( new JSONObject ( ) . fluentPut ( "key" , "审核结果" ) . fluentPut ( "value" , appMessage . getDescription ( ) ) ) ;
content_item . add ( new JSONObject ( ) . fluentPut ( "key" , "审核时间" ) . fluentPut ( "value" , LocalDateTime . now ( ) . format ( DateTimeFormatter . ofPattern ( "yyyy-MM-dd HH:mm:ss" ) ) ) ) ;
String format = DateTimeFormatter . ofPattern ( "yyyy-MM-dd HH:mm:ss" ) . format ( LocalDateTime . ofInstant ( new Date ( ) . toInstant ( ) , ZoneId . of ( "GMT+08:00" ) ) ) ;
content_item . add ( new JSONObject ( ) . fluentPut ( "key" , "审核时间" ) . fluentPut ( "value" , format ) ) ;
httpUtil . qywxMessage ( httpUtil . qywxGetToken ( ) , touser , "传播效果审核" , null , appMessage . getUrl ( ) , content_item ) ;
}
AppMessageUtil . sendMessage ( appMessage ) ;