@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat ;
import com.fasterxml.jackson.annotation.JsonFormat ;
import com.zh.project0512.annotation.AdminTokenValid ;
import com.zh.project0512.annotation.AdminTokenValid ;
import com.zh.project0512.mapper.AdminMapper ;
import com.zh.project0512.mapper.AdminMapper ;
import com.zh.project0512.mapper.UserEffectRecordsMapper ;
import com.zh.project0512.model.UserEffectRecords ;
import com.zh.project0512.model.Video ;
import com.zh.project0512.model.Video ;
import com.zh.project0512.model.dto.RankListDTO ;
import com.zh.project0512.model.dto.RankListDTO ;
import com.zh.project0512.service.IRankService ;
import com.zh.project0512.service.IRankService ;
@ -23,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource ;
import javax.annotation.Resource ;
import java.time.LocalDate ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.format.DateTimeFormatter ;
import java.time.format.DateTimeFormatter ;
import java.time.temporal.ChronoUnit ;
import java.time.temporal.ChronoUnit ;
import java.util.ArrayList ;
import java.util.ArrayList ;
@ -38,8 +41,8 @@ import java.util.stream.Stream;
public class StatisticsController {
public class StatisticsController {
@Autowired
@Autowired
private AdminMapper adminMapper ;
private AdminMapper adminMapper ;
@ Resource
@ Autowired
IRankService rankService ;
private UserEffectRecordsMapper userEffectRecordsMapper ;
@Operation ( summary = "总数据" )
@Operation ( summary = "总数据" )
@PostMapping ( "/data1" )
@PostMapping ( "/data1" )
@ -67,9 +70,10 @@ public class StatisticsController {
QueryWrapper < Video > qw = new QueryWrapper < > ( ) ;
QueryWrapper < Video > qw = new QueryWrapper < > ( ) ;
DateTimeFormatter df = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ;
DateTimeFormatter df = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ;
DateTimeFormatter df2 = DateTimeFormatter . ofPattern ( "yyyy-MM" ) ;
LocalDate now = LocalDateTime . now ( ) . toLocalDate ( ) ;
LocalDate before = now . minusMonths ( 1 ) ;
if ( null ! = param . getDateCondition ( ) ) {
if ( null ! = param . getDateCondition ( ) ) {
LocalDateTime now = LocalDateTime . now ( ) ;
LocalDateTime before = null ;
switch ( param . getDateCondition ( ) ) {
switch ( param . getDateCondition ( ) ) {
case 1 :
case 1 :
before = now ;
before = now ;
@ -85,39 +89,85 @@ public class StatisticsController {
break ;
break ;
default :
default :
}
}
qw . between ( "creatAt" , before , LocalDateTime . now ( ) ) ;
} else {
} else {
qw. ge ( param . getBeginTime ( ) ! = null , "date_format(creatAt, '%Y-%m-%d')" , param . getBeginTime ( ) ! = null ? param . getBeginTime ( ) . format( df ) : null ) ;
before = param . getBeginTime ( ) ! = null ? param . getBeginTime ( ) . toLocalDate( ) : before ;
qw. le ( param . getEndTime ( ) ! = null , "date_format(creatAt, '%Y-%m-%d')" , param . getEndTime ( ) ! = null ? param . getEndTime ( ) . format( df ) : null ) ;
now = param . getEndTime ( ) ! = null ? param . getEndTime ( ) . toLocalDate( ) : now ;
}
}
List < JSONObject > videoDataBydDay = adminMapper . statistics2 ( qw ) ;
ArrayList < JSONObject > res = new ArrayList < > ( ) ;
ArrayList < JSONObject > res = new ArrayList < > ( ) ;
if ( videoDataBydDay = = null | | videoDataBydDay . size ( ) = = 0 ) {
if ( param . getDateCondition ( ) = = 4 ) {
return Result . success ( null , "请求成功" ) ;
qw . between ( "date_format(creatAt, '%Y-%m')" , before . format ( df2 ) , now . plusMonths ( 1 ) . format ( df2 ) ) ;
}
List < JSONObject > videoDataBydDay = adminMapper . statistics3 ( qw ) ;
JSONObject first = videoDataBydDay . get ( 0 ) ;
if ( videoDataBydDay = = null | | videoDataBydDay . size ( ) = = 0 ) {
JSONObject last = videoDataBydDay . get ( videoDataBydDay . size ( ) - 1 ) ;
return Result . success ( null , "请求成功" ) ;
LocalDate dat = param . getBeginTime ( ) = = null ? LocalDate . parse ( ( CharSequence ) first . get ( "dat" ) , df ) : param . getBeginTime ( ) . toLocalDate ( ) ;
}
LocalDate dat2 = param . getEndTime ( ) = = null ? LocalDate . parse ( ( CharSequence ) last . get ( "dat" ) , df ) : param . getEndTime ( ) . toLocalDate ( ) ;
for ( int i = 0 ; i < = ChronoUnit . MONTHS . between ( before , now ) ; i + + ) {
for ( int i = 0 ; i < = ChronoUnit . DAYS . between ( dat , dat2 ) ; i + + ) {
LocalDate today = before . plusMonths ( i ) ;
LocalDate today = dat . plusDays ( i ) ;
JSONObject obj = null ;
JSONObject obj = null ;
// Stream<JSONObject> dat1 = videoDataBydDay.stream().filter(x -> LocalDate.parse((CharSequence) x.get("dat"), df) == today);
// Stream<JSONObject> dat1 = videoDataBydDay.stream().filter(x -> LocalDate.parse((CharSequence) x.get("dat"), df) == today);
for ( JSONObject o : videoDataBydDay ) {
for ( JSONObject o : videoDataBydDay ) {
if ( LocalDate . parse ( ( CharSequence ) o . get ( "dat" ) , df ) . equals ( today ) ) {
if ( o . get ( "dat" ) . equals ( today . format ( df2 ) ) ) {
obj = o ;
obj = o ;
break ;
break ;
}
}
res . add ( obj = = null ? new JSONObject ( ) . fluentPut ( "dat" , today . format ( df2 ) ) : obj ) ;
}
} else {
qw . between ( "date_format(creatAt, '%Y-%m-%d')" , before , now . plusDays ( 1 ) ) ;
List < JSONObject > videoDataBydDay = adminMapper . statistics2 ( qw ) ;
if ( videoDataBydDay = = null | | videoDataBydDay . size ( ) = = 0 ) {
return Result . success ( null , "请求成功" ) ;
}
for ( int i = 0 ; i < = ChronoUnit . DAYS . between ( before , now ) ; i + + ) {
LocalDate today = before . plusDays ( i ) ;
JSONObject obj = null ;
// Stream<JSONObject> dat1 = videoDataBydDay.stream().filter(x -> LocalDate.parse((CharSequence) x.get("dat"), df) == today);
for ( JSONObject o : videoDataBydDay ) {
if ( LocalDate . parse ( ( CharSequence ) o . get ( "dat" ) , df ) . equals ( today ) ) {
obj = o ;
break ;
}
}
}
res . add ( obj = = null ? new JSONObject ( ) . fluentPut ( "dat" , today ) : obj ) ;
}
}
res . add ( obj = = null ? new JSONObject ( ) . fluentPut ( "dat" , today ) : obj ) ;
}
}
return Result . success ( res , "请求成功" ) ;
return Result . success ( res , "请求成功" ) ;
}
}
@Data
static class RankParam {
@Schema ( title = "时间条件" , description = "1今日;2本周;3本月;4全年" )
private Integer dateCondition ;
@Schema ( title = "1经销商2员工" , description = "默认1" )
private Integer type ;
}
@Operation ( summary = "排行列表" )
@Operation ( summary = "排行列表" )
@PostMapping ( "/data3" )
@PostMapping ( "/data3" )
@AdminTokenValid
@AdminTokenValid
public Result rankList ( @Validated @RequestBody RankListDTO rankListDTO ) {
public Result data3 ( @Validated @RequestBody RankParam param ) {
return Result . success ( rankService . rankList ( rankListDTO ) , "请求成功" ) ;
QueryWrapper < UserEffectRecords > qw = new QueryWrapper < > ( ) ;
DateTimeFormatter df = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ;
LocalDateTime now = LocalDateTime . of ( LocalDateTime . now ( ) . toLocalDate ( ) , LocalTime . MIN ) ;
LocalDateTime before = now . minusMonths ( 1 ) ;
if ( param . getDateCondition ( ) ! = null ) {
switch ( param . getDateCondition ( ) ) {
case 1 :
before = now ;
break ;
case 2 :
before = now . minusWeeks ( 1 ) ;
break ;
case 3 :
before = now . minusMonths ( 1 ) ;
break ;
case 4 :
before = now . minusYears ( 1 ) ;
break ;
default :
}
}
qw . between ( "t1.createAt" , before , now . plusDays ( 1 ) ) ;
return Result . success ( ( param . getType ( ) ! = null & & param . getType ( ) = = 1 ) ? userEffectRecordsMapper . rankByDepartment ( qw ) : userEffectRecordsMapper . rankByUser ( qw ) , "请求成功" ) ;
}
}
}
}