Commit 2f537ebc authored by 陈炯舟's avatar 陈炯舟

Merge branch 'dev-8.9.0' into 'master'

Dev 8.9.0

See merge request !12
parents 33725a49 0a54e567
FROM registry-vpc.cn-hangzhou.aliyuncs.com/afanticar/base:ppjava8
VOLUME /tmp
ENV PROJECT="afanti-open-api"
ENV APP="/usr/src/app" \
JAR_FILE="target/${PROJECT}-1.0.1.jar"
WORKDIR $APP
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["/entrypoint.sh"]
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.afanticar</groupId>
<artifactId>afanti-open-api</artifactId>
<version>1.0.1</version>
<name>afanti-open-api</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.afanticar</groupId>
<artifactId>common-redis-cache</artifactId>
<version>1.0.2</version>
</dependency>
<!-- mybatis的分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<artifactId>jsqlparser</artifactId>
<groupId>com.github.jsqlparser</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- 多数据源 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.6.2</version>
</dependency>
<!--阿里云MQ-->
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>ons-client</artifactId>
<version>1.8.8.1.Final</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.10.2</version>
</dependency>
<!-- 运维统一日志包 -->
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>8.6.0</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.17.6</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>1.3.0.Final</version>
</dependency>
<!-- 运维类依赖-->
<dependency>
<groupId>com.afanticar</groupId>
<artifactId>ops-java-common</artifactId>
<version>0.0.1-Release</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-vault-config-databases</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-vault-config-aws</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-vault-config</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- 运维类依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<exclusions>
<exclusion>
<artifactId>mapstruct</artifactId>
<groupId>org.mapstruct</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>afanti</id>
<name>afanti maven</name>
<url>https://nexus.afanticar.cn/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>jcenter-releases</id>
<name>jcenter</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>central</id>
<name>afanti maven</name>
<url>https://nexus.afanticar.cn/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
<repository>
<id>public</id>
<name>afanticar nexus</name>
<url>https://nexus.afanticar.cn/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Amapstruct.suppressGeneratorTimestamp=true</arg>
<arg>-Amapstruct.defaultComponentModel=spring</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.afanticar.afantiopenapi;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
*
* @author Chin
*
*/
@EnableSwagger2
@SpringBootApplication
@EnableScheduling
@EnableFeignClients
@MapperScan(basePackages = {"com.afanticar.afantiopenapi.mapper"})
public class AfantiOpenApiApplication {
public static void main(String[] args) {
SpringApplication.run(AfantiOpenApiApplication.class, args);
}
}
package com.afanticar.afantiopenapi.config;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/27/027
*/
@Configuration
@Getter
public class ClientIdPrincipalConfig {
@Value("#{${client.map}}")
Map<String,String> maps;
}
package com.afanticar.afantiopenapi.config;
import com.afanticar.afantiopenapi.constant.ExceptionEnum;
import com.afanticar.afantiopenapi.controller.BaseController;
import com.afanticar.afantiopenapi.model.BaseResponse;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import java.util.StringJoiner;
@RestControllerAdvice
public class GlobalExceptionHandler {
protected final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
@ExceptionHandler(ConstraintViolationException.class)
public BaseResponse processMethodArgumentNotValidException(HttpServletResponse response, ConstraintViolationException e) {
StringJoiner message = new StringJoiner(";");
e.getConstraintViolations().forEach(constraintViolation -> message.add(constraintViolation.getMessage()));
LOGGER.error("参数校验异常 => ", e);
return handleError(ExceptionEnum.PARAM_INVALID.getCode(), String.join(":", ExceptionEnum.PARAM_INVALID.getMessage(), message.toString()), null);
}
@ExceptionHandler(Exception.class)
public BaseResponse processException(Exception e) {
LOGGER.error("未知异常 => :{}", ExceptionUtils.getStackTrace(e));
return handleError(ExceptionEnum.ERROR, e);
}
private BaseResponse<Object> handleError(int code, String message, Exception ex) {
return BaseController.error(code + "", message);
}
private BaseResponse<Object> handleError(ExceptionEnum exceptionEnum, Exception ex) {
// 状态码
Integer code = exceptionEnum.getCode();
// 状态码描述
String message = exceptionEnum.getMessage();
return handleError(code, message, ex);
}
}
package com.afanticar.afantiopenapi.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author chenjiawei
* @desc mybatis-plus配置类
* @date 2022/04/19 17:54
**/
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
package com.afanticar.afantiopenapi.config;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2022/2/14/014
*/
@Configuration
@Slf4j
public class RedissonConfig {
@Resource
private RedisProperties redisProperties;
@Bean
public RedissonClient getRedisson() {
Config config = new Config();
SingleServerConfig singleServerConfig = config.useSingleServer().setAddress("redis://" + this.redisProperties.getHost() + ":" + this.redisProperties.getPort())
.setDatabase(this.redisProperties.getDatabase()).setConnectTimeout(10000).setTimeout(3000).setRetryInterval(1500).setRetryAttempts(3);
if (StringUtil.isNotBlank(this.redisProperties.getPassword())) {
singleServerConfig.setPassword(this.redisProperties.getPassword());
}
return Redisson.create(config);
}
}
package com.afanticar.afantiopenapi.config;
import cn.hutool.core.util.StrUtil;
import com.afanticar.afantiopenapi.controller.BaseController;
import com.afanticar.afantiopenapi.utils.JWTUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Set;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Component
@Slf4j
public class TokenInterceptor implements HandlerInterceptor {
@Value("#{'${ignored.uri}'.split(',')}")
private Set<String> ignoredUris;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestUri = request.getRequestURI();
if (ignoredUris.contains(requestUri)) {
return true;
}
String token = request.getHeader("authorization");
if (StrUtil.isNotBlank(token)) {
request.setAttribute("clientId", JWTUtils.getClientId(token));
} else {
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setContentType("application/json");
response.getWriter().append(JSONObject.toJSONString(BaseController.error("401", "认证失败")));
return false;
}
return true;
}
}
package com.afanticar.afantiopenapi.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/28/028
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Resource
TokenInterceptor tokenInterceptor;
@Override
public void addInterceptors(InterceptorRegistry register) {
register.addInterceptor(tokenInterceptor);
}
}
\ No newline at end of file
package com.afanticar.afantiopenapi.constant;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/28/028
*/
public class Constant {
public static final String SUCCESS_CODE = "200";
}
package com.afanticar.afantiopenapi.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* @author Wsr
* @ClassName ExceptionEnum
* @desc 异常枚举
* @date 2023/01/06 18:59
**/
@AllArgsConstructor
@NoArgsConstructor
public enum ExceptionEnum {
/**
*
*/
USER_ERROR(400, "用户错误"),
ERROR(500, "发生未知异常,请联系管理员"),
SUCCESS(200, "成功"),
PARAM_INVALID(90001, "请求参数不合法"),
FLOW_LIMIT_ALL(10010, "访问过于频繁"),
// ==================== token ====================
/**
* token 无效 401
*/
TOKEN_INVALID(10002, "token 无效"),
/**
* token 过期
*/
TOKEN_EXPIRED(10003, "token过期"),
/**
* token 不存在
*/
TOKEN_NOT_EXIST(10004, "请求头未传递token"),
// ==================== 限流 ====================
/**
* api限流
*/
API_LIMIT_EXCEEDED(20001, "api限流"),
/**
* api-app限流
*/
API_APP_LIMIT_EXCEEDED(20002, "特殊app限流"),
/**
* app限流
*/
APP_LIMIT_EXCEEDED(20003, "app限流"),
// ==================== 授权 ====================
/**
* app未授权
*/
APP_UNAUTHORIZED(30001, "app未授权"),
/**
* app不存在
*/
APP_NOT_EXIST(30002, "app不存在"),
// ==================== 超时 ====================
/**
* 接口超时
*/
API_TIMEOUT(40001, "接口超时"),
/**
* sql超时
*/
SQL_TIMEOUT(40002, "sql超时"),
// ==================== app ====================
/**
* app未注册
*/
APP_UNREGISTERED(50001, "app未注册"),
/**
* app密钥错误 业务异常
*/
APP_ERROR_SECRET(50002, "app密钥错误"),
// ==================== data ====================
/**
* 字段重复
*/
DUPLICATE_FIELD_ERROR(60001, "字段重复");
@Getter
private Integer code;
@Getter
private String message;
public static ExceptionEnum findExceptionEnumByCode(Integer code) {
for (ExceptionEnum exceptionEnum : values()) {
if (exceptionEnum.code.equals(code)) {
return exceptionEnum;
}
}
return null;
}
}
package com.afanticar.afantiopenapi.controller;
import com.afanticar.afantiopenapi.model.BaseResponse;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* description
*
* @author LSZ 2021/01/07 16:34
* @contact 648748030@qq.com
*/
public class BaseController {
private static String CODE_SUCCESS = "200";
private static String CODE_ERROR = "500";
private static String MSG_ERROR = "发生未知异常,请联系管理员";
public static String header = "clientId";
public static <T> BaseResponse<T> success() {
BaseResponse<T> result = new BaseResponse<>();
result.setSuccess(true);
result.setCode(CODE_SUCCESS);
return result;
}
public static <T> BaseResponse<T> success(T data) {
BaseResponse<T> successResult = success();
successResult.setData(data);
return successResult;
}
public static <T> BaseResponse<T> error() {
return error(CODE_ERROR, MSG_ERROR);
}
public static <T> BaseResponse<T> error(String code, String msg) {
BaseResponse<T> result = new BaseResponse<>();
result.setSuccess(false);
result.setMessage(msg);
result.setCode(code);
return result;
}
public static <T> BaseResponse<T> error(T data, String code, String msg) {
BaseResponse<T> result = new BaseResponse<>();
result.setSuccess(false);
result.setMessage(msg);
result.setCode(code);
result.setData(data);
return result;
}
protected HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
public Map<String, String> getParameterMap() {
Map<String, String> params = new HashMap();
Map<String, String[]> parameterMap = this.getRequest().getParameterMap();
Iterator var3 = parameterMap.entrySet().iterator();
while (var3.hasNext()) {
Map.Entry<String, String[]> entry = (Map.Entry) var3.next();
if (entry.getValue() != null && ((String[]) entry.getValue()).length != 0) {
params.put(entry.getKey(), ((String[]) entry.getValue())[0]);
}
}
return params;
}
}
package com.afanticar.afantiopenapi.controller;
import com.afanticar.afantiopenapi.config.ClientIdPrincipalConfig;
import com.afanticar.afantiopenapi.model.BaseResponse;
import com.afanticar.afantiopenapi.model.dto.TokenDTO;
import com.afanticar.afantiopenapi.model.vo.ActivityInfoVO;
import com.afanticar.afantiopenapi.model.vo.BasePageVO;
import com.afanticar.afantiopenapi.model.vo.TokenVO;
import com.afanticar.afantiopenapi.service.BaseService;
import com.afanticar.afantiopenapi.service.CommonDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Max;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/27/027
*/
@Api("公共数据接口")
@RestController
@RequestMapping("/public")
@Slf4j
@Validated
public class CommonDataController extends BaseController {
@Autowired
ClientIdPrincipalConfig clientIdPrincipalConfig;
@Autowired
CommonDataService commonDataService;
@Autowired
BaseService baseService;
@Value("${common.limit.period:60}")
Integer limitPeriod;
@Value("${common.limit.threshold:8}")
Integer limit;
static String dateType = "common";
@ApiOperation(value = "活动数据信息", notes = "活动数据", produces = "application/json")
@ApiImplicitParams({
@ApiImplicitParam(name = "current_page", value = "页码", paramType = "path", dataType = "Integer"),
@ApiImplicitParam(name = "page_size", value = "页数", paramType = "path", dataType = "Integer"),
})
@GetMapping("/activity")
public BaseResponse<BasePageVO<ActivityInfoVO>> getActionData(HttpServletRequest request, @Max(value = 500,message = "单页数据page_size过大") @RequestParam(name = "page_size", defaultValue = "100", required = false) Integer pageSize,
@RequestParam(name = "current_page", defaultValue = "1", required = false) Integer pageNum) {
BaseResponse check = baseService.baseLimit(dateType, limit, limitPeriod);
if (check != null) {
return check;
}
String principalId = clientIdPrincipalConfig.getMaps().get(request.getHeader(header));
return success(commonDataService.actionData(principalId, pageNum, pageSize));
}
@ApiOperation(value = "获取token", notes = "token数据", produces = "application/json")
@PostMapping("/token")
public BaseResponse<TokenVO> getToken(@RequestBody @Valid TokenDTO dto) {
BaseResponse check = baseService.baseLimit(dateType, limit, limitPeriod);
if (check != null) {
return check;
}
TokenVO vo = commonDataService.token(dto);
if (vo == null) {
return error();
}
return success(vo);
}
}
package com.afanticar.afantiopenapi.controller;
import com.afanticar.afantiopenapi.model.BaseResponse;
import com.afanticar.afantiopenapi.model.vo.BasePageVO;
import com.afanticar.afantiopenapi.model.vo.HongqiAwemeIncentiveVO;
import com.afanticar.afantiopenapi.model.vo.HongqiLiveIncentiveVO;
import com.afanticar.afantiopenapi.service.BaseService;
import com.afanticar.afantiopenapi.service.FawOpenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Max;
import java.util.Date;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Api("红旗数据接口")
@RestController
@RequestMapping("/faw")
@Slf4j
@Validated
public class FawOpenController extends BaseController {
@Autowired
FawOpenService fawOpenService;
@Autowired
BaseService baseService;
@Value("${faw.client}")
String client;
@Value("${faw.limit.period:60}")
Integer limitPeriod;
@Value("${faw.limit.threshold:3}")
Integer limit;
static String dataType = "faw";
@ApiOperation(value = "视频数据信息", notes = "视频数据", produces = "application/json")
@ApiImplicitParams({
@ApiImplicitParam(name = "publish_date_start", value = "开始时间,格式:2023-02-01", required = true, paramType = "path", dataType = "Date"),
@ApiImplicitParam(name = "publish_date_end", value = "结束时间,格式:2023-03-01", required = true, paramType = "path", dataType = "Date"),
@ApiImplicitParam(name = "type", value = "数据类型,monthly-月度表,quarter-季度表", required = true, paramType = "path", dataType = "String"),
@ApiImplicitParam(name = "current_page", value = "页码", paramType = "path", dataType = "Integer"),
@ApiImplicitParam(name = "page_size", value = "页数", paramType = "path", dataType = "Integer"),
})
@GetMapping("/aweme")
public BaseResponse<BasePageVO<HongqiAwemeIncentiveVO>> getAwemeData(HttpServletRequest request, @Max(value = 500,message = "单页数据page_size过大") @RequestParam(name = "page_size", defaultValue = "100", required = false) Integer pageSize,
@RequestParam(name = "current_page", defaultValue = "1", required = false) Integer pageNum,
@RequestParam(name = "publish_date_start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date publishDateStart,
@RequestParam(name = "publish_date_end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date publishDateEnd,
@RequestParam(name = "type") String type) {
BaseResponse check = baseService.baseValidator(request,client, dataType, limit, limitPeriod);
if (check != null) {
return check;
}
return success(fawOpenService.awemes(publishDateStart, publishDateEnd, type, pageNum, pageSize));
}
@ApiOperation(value = "直播数据信息", notes = "直播数据", produces = "application/json")
@ApiImplicitParams({
@ApiImplicitParam(name = "publish_date_start", value = "开始时间,格式:2023-02-01", required = true, paramType = "path", dataType = "Date"),
@ApiImplicitParam(name = "publish_date_end", value = "结束时间,格式:2023-03-01", required = true, paramType = "path", dataType = "Date"),
@ApiImplicitParam(name = "type", value = "数据类型,monthly-月度表,quarter-季度表", required = true, paramType = "path", dataType = "String"),
@ApiImplicitParam(name = "current_page", value = "页码", paramType = "path", dataType = "Integer"),
@ApiImplicitParam(name = "page_size", value = "页数", paramType = "path", dataType = "Integer"),
})
@GetMapping("/live")
public BaseResponse<BasePageVO<HongqiLiveIncentiveVO>> getLiveData(HttpServletRequest request, @Max(value = 500,message = "单页数据page_size过大") @RequestParam(name = "page_size", defaultValue = "100", required = false) Integer pageSize,
@RequestParam(name = "current_page", defaultValue = "1", required = false) Integer pageNum,
@RequestParam(name = "publish_date_start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date publishDateStart,
@RequestParam(name = "publish_date_end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date publishDateEnd,
@RequestParam(name = "type") String type) {
BaseResponse check = baseService.baseValidator(request, client, dataType, limit, limitPeriod);
if (check != null) {
return check;
}
return success(fawOpenService.lives(publishDateStart, publishDateEnd, type, pageNum, pageSize));
}
}
package com.afanticar.afantiopenapi.feign;
import com.afanticar.afantiopenapi.model.BaseResponse;
import com.afanticar.afantiopenapi.model.vo.TokenVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
/**
* @author Chin
*/
@FeignClient(url = "${svc-prefix}" + "cas" + "${svc-suffix}", name = "cas", path = "/")
public interface AfantiCasFeign {
/**
* 分类标签
* @param request 参数
* @return JSONObject结果
*/
@PostMapping(value = "/oauth/token")
BaseResponse<TokenVO> predict(@RequestParam Map<String, Object> request);
}
package com.afanticar.afantiopenapi.mapper;
import com.afanticar.afantiopenapi.model.entity.ActivityInfo;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Mapper
@DS("tmp")
public interface ActivityInfoMapper extends BaseMapper<ActivityInfo> {
}
package com.afanticar.afantiopenapi.mapper;
import com.afanticar.afantiopenapi.model.entity.HongqiAwemeIncentiveMonthly;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Mapper
@DS("tmp")
public interface HongqiAwemeIncentiveMonthlyMapper extends BaseMapper<HongqiAwemeIncentiveMonthly> {
}
package com.afanticar.afantiopenapi.mapper;
import com.afanticar.afantiopenapi.model.entity.HongqiAwemeIncentiveQuarter;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Mapper
@DS("tmp")
public interface HongqiAwemeIncentiveQuarterMapper extends BaseMapper<HongqiAwemeIncentiveQuarter> {
}
package com.afanticar.afantiopenapi.mapper;
import com.afanticar.afantiopenapi.model.entity.HongqiLiveIncentiveMonthly;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Mapper
@DS("tmp")
public interface HongqiLiveIncentiveMonthlyMapper extends BaseMapper<HongqiLiveIncentiveMonthly> {
}
package com.afanticar.afantiopenapi.mapper;
import com.afanticar.afantiopenapi.model.entity.HongqiLiveIncentiveQuarter;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Mapper
@DS("tmp")
public interface HongqiLiveIncentiveQuarterMapper extends BaseMapper<HongqiLiveIncentiveQuarter> {
}
package com.afanticar.afantiopenapi.mapper.struct;
import com.afanticar.afantiopenapi.model.entity.ActivityInfo;
import com.afanticar.afantiopenapi.model.vo.ActivityInfoVO;
import org.mapstruct.Mapper;
import java.util.List;
/**
* @author Chin
*/
@Mapper(componentModel = "spring")
public interface ActivityInfoStructMapper {
List<ActivityInfoVO> listActivityInfoToVO(List<ActivityInfo> list);
}
\ No newline at end of file
package com.afanticar.afantiopenapi.mapper.struct;
import com.afanticar.afantiopenapi.model.entity.HongqiAwemeIncentiveMonthly;
import com.afanticar.afantiopenapi.model.entity.HongqiAwemeIncentiveQuarter;
import com.afanticar.afantiopenapi.model.vo.HongqiAwemeIncentiveVO;
import org.mapstruct.Mapper;
import java.util.List;
/**
* @author Chin
*/
@Mapper(componentModel = "spring")
public interface HongqiAwemeIncentiveStructMapper {
List<HongqiAwemeIncentiveVO> listLiveQuarterToVO(List<HongqiAwemeIncentiveQuarter> list);
List<HongqiAwemeIncentiveVO> listLiveMonthlyToVO(List<HongqiAwemeIncentiveMonthly> list);
}
\ No newline at end of file
package com.afanticar.afantiopenapi.mapper.struct;
import com.afanticar.afantiopenapi.model.entity.HongqiLiveIncentiveMonthly;
import com.afanticar.afantiopenapi.model.entity.HongqiLiveIncentiveQuarter;
import com.afanticar.afantiopenapi.model.vo.HongqiLiveIncentiveVO;
import org.mapstruct.Mapper;
import java.util.List;
/**
* @author Chin
*/
@Mapper(componentModel = "spring")
public interface HongqiLiveIncentiveStructMapper {
List<HongqiLiveIncentiveVO> listLiveQuarterToVO(List<HongqiLiveIncentiveQuarter> list);
List<HongqiLiveIncentiveVO> listLiveMonthlyToVO(List<HongqiLiveIncentiveMonthly> list);
}
\ No newline at end of file
package com.afanticar.afantiopenapi.model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@ApiModel("数据返回DTO")
public class BaseResponse<T> {
@ApiModelProperty(value = "状态码", example = "200")
private String code;
@ApiModelProperty(value = "状态信息", example = "success")
private String message;
@ApiModelProperty("数据")
private T data;
@ApiModelProperty(value = "是否成功", example = "true")
private Boolean success;
}
package com.afanticar.afantiopenapi.model.dto;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/27/027
*/
@Data
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
@ApiModel("token请求DTO")
public class TokenDTO {
@ApiModelProperty(value = "client_id", example = "200")
@NotNull
private String clientId;
private String grantType;
@ApiModelProperty(value = "秘钥", example = "200")
@NotNull
private String clientSecret;
}
package com.afanticar.afantiopenapi.model.entity;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
import java.util.Date;
/**
* 活动信息
* @author Chin
*/
@Data
@TableName("activity_info")
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class ActivityInfo {
/** 活动ID */
@TableId
private Integer activityId;
//private Integer principalId;
/** 活动名称 */
private String activityName;
/** 活动规则 */
private String participationRules;
/** 奖励规则 */
private String rewardRules;
/** When the data was modified */
private Date modificationTime;
/** When the data was created */
private Date creationTime;
}
package com.afanticar.afantiopenapi.model.entity;
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
import java.util.Date;
/**
* 红旗视频激励记录表_月度
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@TableName("hongqi_aweme_incentive_monthly")
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class HongqiAwemeIncentiveMonthly {
/** 活动ID */
private Integer activityId;
/** 统计日期 */
private Date statisticsDate;
private String groupName;
/** 平台 */
private String platform;
/** 大区 */
private String region;
/** 门店编码 */
private String storeCode;
/** 经销商名称 */
private String dealerName;
/** 主播ID */
private String authorId;
/** 视频ID */
private String awemeId;
/** 标题 */
private String title;
/** 链接 */
private String link;
/** 视频发布时间 */
private Date publishTime;
/** 点赞数 */
private Integer likeCount;
/** 评论数 */
private Integer commentCount;
/** 分享数 */
private Integer shareCount;
/** 播放数 */
private Integer playVolume;
/** 互动数 */
private Integer interaction;
/** 是否有效作品 1是, 0否 */
private Integer isValid;
/** 是否活动作品 1是, 0否 */
private Integer isActivity;
/** 是否爆款作品 1是, 0否 */
private Integer isPopular;
/** 是否违规作品 1是, 0否 */
private Integer isViolation;
/** 违规标签 */
private String violationTag;
/** 门店内排行 */
private String storeRanking;
/** 爆款作品奖金 */
private Long popularWorksBonus;
/** 是否删除数据 1是, 0否 */
private Integer isDeleted;
/** 创建时间 */
private Date ctime;
/** 更新时间 */
private Date mtime;
}
package com.afanticar.afantiopenapi.model.entity;
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
import java.util.Date;
/**
* 红旗视频激励记录表_季度
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@TableName("hongqi_aweme_incentive_quarter")
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class HongqiAwemeIncentiveQuarter {
/** 活动ID */
private Integer activityId;
/** 统计日期 */
private Date statisticsDate;
private String groupName;
/** 平台 */
private String platform;
/** 大区 */
private String region;
/** 门店编码 */
private String storeCode;
/** 经销商名称 */
private String dealerName;
/** 主播ID */
private String authorId;
/** 视频ID */
private String awemeId;
/** 标题 */
private String title;
/** 链接 */
private String link;
/** 视频发布时间 */
private Date publishTime;
/** 点赞数 */
private Integer likeCount;
/** 评论数 */
private Integer commentCount;
/** 分享数 */
private Integer shareCount;
/** 播放数 */
private Integer playVolume;
/** 互动数 */
private Integer interaction;
/** 是否有效作品 1是, 0否 */
private Byte isValid;
/** 是否活动作品 1是, 0否 */
private Byte isActivity;
/** 是否爆款作品 1是, 0否 */
private Byte isPopular;
/** 是否违规作品 1是, 0否 */
private Byte isViolation;
/** 违规标签 */
private String violationTag;
/** 门店内排行 */
private String storeRanking;
/** 爆款作品奖金 */
private Long popularWorksBonus;
/** 是否删除数据 1是, 0否 */
private Integer isDeleted;
/** 创建时间 */
private Date ctime;
/** 更新时间 */
private Date mtime;
}
package com.afanticar.afantiopenapi.model.entity;
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
import java.util.Date;
/**
* 红旗直播激励记录表_月度
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@TableName("hongqi_live_incentive_monthly")
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class HongqiLiveIncentiveMonthly {
/** 活动ID */
private Integer activityId;
/** 统计日期 */
private Date statisticsDate;
/** 分组 */
private String groupName;
/** 平台 */
private String platform;
/** 大区 */
private String region;
/** 门店编码 */
private String storeCode;
/** 经销商名称 */
private String dealerName;
/** 主播ID */
private String authorId;
/** 直播ID */
private String roomId;
/** 标题 */
private String title;
/** 链接 */
private String link;
/** 视频发布时间 */
private Date publishTime;
/** 点赞数 */
private Integer likeCount;
/** 评论数 */
private Integer commentCount;
/** 送礼数 */
private Integer giftCount;
/** 观看量 */
private Integer watchUserCount;
/** 直播时长(分钟) */
private Long liveDuration;
/** 互动数 */
private Integer interaction;
/** 是否有效作品 1是, 0否 */
private Integer isValid;
/** 是否活动作品 1是, 0否 */
private Integer isActivity;
/** 是否爆款作品 1是, 0否 */
private Integer isPopular;
/** 是否违规作品 1是, 0否 */
private Integer isViolation;
/** 违规标签 */
private String violationTag;
/** 门店内排行 */
private String storeRanking;
/** 爆款作品奖金 */
private Long popularWorksBonus;
/** 是否删除数据 1是, 0否 */
private Integer isDeleted;
/** 创建时间 */
private Date ctime;
/** 更新时间 */
private Date mtime;
}
package com.afanticar.afantiopenapi.model.entity;
import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;
import java.util.Date;
/**
* 红旗直播激励记录表_季度
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@TableName("hongqi_live_incentive_quarter")
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class HongqiLiveIncentiveQuarter {
/** 活动ID */
private Integer activityId;
/** 统计日期 */
private Date statisticsDate;
/** 分组 */
private String groupName;
/** 平台 */
private String platform;
/** 大区 */
private String region;
/** 门店编码 */
private String storeCode;
/** 经销商名称 */
private String dealerName;
/** 主播ID */
private String authorId;
/** 直播ID */
private String roomId;
/** 标题 */
private String title;
/** 链接 */
private String link;
/** 视频发布时间 */
private Date publishTime;
/** 点赞数 */
private Integer likeCount;
/** 评论数 */
private Integer commentCount;
/** 送礼数 */
private Integer giftCount;
/** 观看量 */
private Integer watchUserCount;
/** 直播时长(分钟) */
private Long liveDuration;
/** 互动数 */
private Integer interaction;
/** 是否有效作品 1是, 0否 */
private Integer isValid;
/** 是否活动作品 1是, 0否 */
private Integer isActivity;
/** 是否爆款作品 1是, 0否 */
private Integer isPopular;
/** 是否违规作品 1是, 0否 */
private Integer isViolation;
/** 违规标签 */
private String violationTag;
/** 门店内排行 */
private String storeRanking;
/** 爆款作品奖金 */
private Long popularWorksBonus;
/** 是否删除数据 1是, 0否 */
private Integer isDeleted;
/** 创建时间 */
private Date ctime;
/** 更新时间 */
private Date mtime;
}
package com.afanticar.afantiopenapi.model.vo;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 活动信息
* @author Chin
*/
@Data
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class ActivityInfoVO {
/** 活动ID */
@ApiModelProperty(value = "活动ID", example = "200")
private Integer activityId;
/** 活动名称 */
@ApiModelProperty(value = "活动名称", example = "3月活动")
private String activityName;
/** 活动规则 */
@ApiModelProperty(value = "活动规则", example = "规则1:等等")
private String participationRules;
/** 奖励规则 */
@ApiModelProperty(value = "奖励规则", example = "奖励规则")
private String rewardRules;
/** When the data was created */
@ApiModelProperty(value = "活动创建时间", example = "2023-03-04 10:00:00")
private Date creationTime;
}
package com.afanticar.afantiopenapi.model.vo;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 统一分页查询VO
* @author Chin
* @date 2023/04/27 14:02
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("统一分页查询VO")
public class BasePageVO<T> {
@ApiModelProperty("当前页码")
private Integer current;
@ApiModelProperty("每页大小")
private Integer size;
@ApiModelProperty("数据总量")
private Integer total;
@ApiModelProperty("总页数")
private Integer pages;
@ApiModelProperty("列表数据")
private List<T> records;
public static <T> BasePageVO<T> restPage(int current, int size, int total, int pages, List<T> records) {
BasePageVO<T> result = new BasePageVO<T>(1, 30, 0, 1, Lists.newArrayList());
result.setCurrent(current);
result.setSize(size);
result.setTotal(total);
result.setPages(pages);
result.setRecords(records);
return result;
}
}
package com.afanticar.afantiopenapi.model.vo;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 红旗视频激励记录表_月度
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class HongqiAwemeIncentiveVO {
/** 活动ID */
@ApiModelProperty(value = "活动ID", example = "200")
private Integer activityId;
/** 统计日期 */
@ApiModelProperty(value = "统计日期", example = "2023-03-03")
private Date statisticsDate;
@ApiModelProperty(value = "分组", example = "分组2")
private String groupName;
/** 平台 */
@ApiModelProperty(value = "平台", example = "抖音")
private String platform;
/** 大区 */
@ApiModelProperty(value = "大区", example = "大区20")
private String region;
/** 门店编码 */
@ApiModelProperty(value = "门店编码", example = "ABC123")
private String storeCode;
/** 经销商名称 */
@ApiModelProperty(value = "经销商名称", example = "经销商200")
private String dealerName;
/** 主播ID */
@ApiModelProperty(value = "主播ID", example = "200")
private String authorId;
/** 视频ID */
@ApiModelProperty(value = "视频ID", example = "11200")
private String awemeId;
/** 标题 */
@ApiModelProperty(value = "标题", example = "标题200")
private String title;
/** 链接 */
@ApiModelProperty(value = "链接", example = "链接200")
private String link;
/** 视频发布时间 */
@ApiModelProperty(value = "视频发布时间", example = "2023-03-01 18:00:00")
private Date publishTime;
/** 点赞数 */
@ApiModelProperty(value = "点赞数", example = "200")
private Integer likeCount;
/** 评论数 */
@ApiModelProperty(value = "评论数", example = "200")
private Integer commentCount;
/** 分享数 */
@ApiModelProperty(value = "分享数", example = "200")
private Integer shareCount;
/** 播放数 */
@ApiModelProperty(value = "播放数", example = "200")
private Integer playVolume;
/** 互动数 */
@ApiModelProperty(value = "互动数", example = "200")
private Integer interaction;
/** 是否有效作品 1是, 0否 */
@ApiModelProperty(value = "是否有效作品", example = "1")
private Integer isValid;
/** 是否活动作品 1是, 0否 */
@ApiModelProperty(value = "是否活动作品", example = "1")
private Integer isActivity;
/** 是否爆款作品 1是, 0否 */
@ApiModelProperty(value = "是否爆款作品", example = "1")
private Integer isPopular;
/** 是否违规作品 1是, 0否 */
@ApiModelProperty(value = "是否违规作品", example = "0")
private Integer isViolation;
/** 违规标签 */
@ApiModelProperty(value = "违规标签", example = "[0]")
private String violationTag;
/** 门店内排行 */
@ApiModelProperty(value = "门店内排行", example = "200")
private String storeRanking;
/** 爆款作品奖金 */
@ApiModelProperty(value = "爆款作品奖金", example = "200")
private Long popularWorksBonus;
}
package com.afanticar.afantiopenapi.model.vo;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 红旗直播激励记录表_月度
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Data
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class HongqiLiveIncentiveVO {
/** 活动ID */
@ApiModelProperty(value = "活动ID", example = "200")
private Integer activityId;
/** 统计日期 */
@ApiModelProperty(value = "统计日期", example = "2023-03-03")
private Date statisticsDate;
/** 分组 */
@ApiModelProperty(value = "分组", example = "分组2")
private String groupName;
/** 平台 */
@ApiModelProperty(value = "平台", example = "抖音")
private String platform;
/** 大区 */
@ApiModelProperty(value = "大区", example = "大区200")
private String region;
/** 门店编码 */
@ApiModelProperty(value = "门店编码", example = "ABC123")
private String storeCode;
/** 经销商名称 */
@ApiModelProperty(value = "经销商名称", example = "经销商200")
private String dealerName;
/** 主播ID */
@ApiModelProperty(value = "主播ID", example = "200")
private String authorId;
/** 直播ID */
@ApiModelProperty(value = "直播ID", example = "11200")
private String roomId;
/** 标题 */
@ApiModelProperty(value = "标题", example = "标题200")
private String title;
/** 链接 */
@ApiModelProperty(value = "链接", example = "链接")
private String link;
/** 视频发布时间 */
@ApiModelProperty(value = "视频发布时间", example = "2023-03-03 10:00:02")
private Date publishTime;
/** 点赞数 */
@ApiModelProperty(value = "点赞数", example = "200")
private Integer likeCount;
/** 评论数 */
@ApiModelProperty(value = "评论数", example = "200")
private Integer commentCount;
/** 送礼数 */
@ApiModelProperty(value = "送礼数", example = "200")
private Integer giftCount;
/** 观看量 */
@ApiModelProperty(value = "观看量", example = "200")
private Integer watchUserCount;
/** 直播时长(分钟) */
@ApiModelProperty(value = "直播时长(分钟)", example = "210")
private Long liveDuration;
/** 互动数 */
@ApiModelProperty(value = "互动数", example = "200")
private Integer interaction;
/** 是否有效作品 1是, 0否 */
@ApiModelProperty(value = "是否有效作品", example = "1")
private Integer isValid;
/** 是否活动作品 1是, 0否 */
@ApiModelProperty(value = "是否活动作品", example = "1")
private Integer isActivity;
/** 是否爆款作品 1是, 0否 */
@ApiModelProperty(value = "是否爆款作品", example = "1")
private Integer isPopular;
/** 是否违规作品 1是, 0否 */
@ApiModelProperty(value = "是否违规作品", example = "0")
private Integer isViolation;
/** 违规标签 */
@ApiModelProperty(value = "违规标签", example = "[0]")
private String violationTag;
/** 门店内排行 */
@ApiModelProperty(value = "门店内排行", example = "2")
private String storeRanking;
/** 爆款作品奖金 */
@ApiModelProperty(value = "爆款作品奖金", example = "200")
private Long popularWorksBonus;
}
package com.afanticar.afantiopenapi.model.vo;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/27/027
*/
@Data
@JsonNaming(value = com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy.class)
@JSONType(naming = com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase)
public class TokenVO {
@ApiModelProperty(value = "token,有效期30天", example = "wastehh")
private String token;
@ApiModelProperty(value = "有效时间,单位秒", example = "2591999")
private Long expiresIn;
}
package com.afanticar.afantiopenapi.service;
import com.afanticar.afantiopenapi.controller.BaseController;
import com.afanticar.afantiopenapi.model.BaseResponse;
import org.redisson.api.RRateLimiter;
import org.redisson.api.RateIntervalUnit;
import org.redisson.api.RateType;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/27/027
*/
@Service
public class BaseService {
@Autowired
RedissonClient redissonClient;
int waiting = 50;
public BaseResponse baseValidator(HttpServletRequest request, String clientId, String dataType, Integer limit, Integer limitPeriod) {
if (!clientId.equals(request.getAttribute(BaseController.header))) {
return BaseController.error("403", "认证用户无访问此数据的权限!");
}
String fawKey = String.format("%s:limit", dataType);
RRateLimiter rateLimiter = redissonClient.getRateLimiter(fawKey);
rateLimiter.trySetRate(RateType.OVERALL, limit, limitPeriod, RateIntervalUnit.SECONDS);
if (!rateLimiter.tryAcquire(1, waiting, TimeUnit.MILLISECONDS)) {
return BaseController.error("10010", "您的请求太过频繁,请稍后再试!");
}
return null;
}
public BaseResponse baseLimit(String dataType, Integer limit, Integer limitPeriod) {
String header = "token";
String fawKey = String.format("%s:%s:limit", dataType, header);
RRateLimiter rateLimiter = redissonClient.getRateLimiter(fawKey);
rateLimiter.trySetRate(RateType.OVERALL, limit,limitPeriod, RateIntervalUnit.SECONDS);
if (!rateLimiter.tryAcquire(1, waiting, TimeUnit.MILLISECONDS)) {
return BaseController.error("10010", "您的请求太过频繁,请稍后再试!");
}
return null;
}
}
package com.afanticar.afantiopenapi.service;
import com.afanticar.afantiopenapi.constant.Constant;
import com.afanticar.afantiopenapi.feign.AfantiCasFeign;
import com.afanticar.afantiopenapi.mapper.ActivityInfoMapper;
import com.afanticar.afantiopenapi.mapper.struct.ActivityInfoStructMapper;
import com.afanticar.afantiopenapi.model.BaseResponse;
import com.afanticar.afantiopenapi.model.dto.TokenDTO;
import com.afanticar.afantiopenapi.model.entity.ActivityInfo;
import com.afanticar.afantiopenapi.model.vo.ActivityInfoVO;
import com.afanticar.afantiopenapi.model.vo.BasePageVO;
import com.afanticar.afantiopenapi.model.vo.TokenVO;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/27/027
*/
@Service
@Slf4j
public class CommonDataService {
@Resource
ActivityInfoMapper activityInfoMapper;
@Resource
AfantiCasFeign afantiCasFeign;
public BasePageVO<ActivityInfoVO> actionData(String principalId, Integer pageNum, Integer pageSize) {
PageHelper.orderBy(" creation_time DESC ");
IPage<ActivityInfo> page = new Page<>(pageNum, pageSize);
QueryWrapper<ActivityInfo> queryWrapper = new QueryWrapper<>();
//queryWrapper.eq("principal_id", principalId);
IPage<ActivityInfo> activityPage = activityInfoMapper.selectPage(page, queryWrapper);
ActivityInfoStructMapper mapper = Mappers.getMapper(ActivityInfoStructMapper.class);
List<ActivityInfoVO> vos = mapper.listActivityInfoToVO(activityPage.getRecords());
return BasePageVO.restPage(pageNum, (int) activityPage.getSize(), (int) activityPage.getTotal(), (int) activityPage.getPages(), vos);
}
public TokenVO token(TokenDTO dto) {
dto.setGrantType("client_credentials");
BaseResponse<TokenVO> response = afantiCasFeign.predict(JSONObject.parseObject(JSONObject.toJSONString(dto)).getInnerMap());
if (Constant.SUCCESS_CODE.equals(response.getCode())) {
return response.getData();
}
log.error("faw请求token失败:{}", JSONObject.toJSONString(response));
return null;
}
}
package com.afanticar.afantiopenapi.service;
import com.afanticar.afantiopenapi.mapper.HongqiAwemeIncentiveMonthlyMapper;
import com.afanticar.afantiopenapi.mapper.HongqiAwemeIncentiveQuarterMapper;
import com.afanticar.afantiopenapi.mapper.HongqiLiveIncentiveMonthlyMapper;
import com.afanticar.afantiopenapi.mapper.HongqiLiveIncentiveQuarterMapper;
import com.afanticar.afantiopenapi.mapper.struct.HongqiAwemeIncentiveStructMapper;
import com.afanticar.afantiopenapi.mapper.struct.HongqiLiveIncentiveStructMapper;
import com.afanticar.afantiopenapi.model.entity.HongqiAwemeIncentiveMonthly;
import com.afanticar.afantiopenapi.model.entity.HongqiAwemeIncentiveQuarter;
import com.afanticar.afantiopenapi.model.entity.HongqiLiveIncentiveMonthly;
import com.afanticar.afantiopenapi.model.entity.HongqiLiveIncentiveQuarter;
import com.afanticar.afantiopenapi.model.vo.BasePageVO;
import com.afanticar.afantiopenapi.model.vo.HongqiAwemeIncentiveVO;
import com.afanticar.afantiopenapi.model.vo.HongqiLiveIncentiveVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
@Service
public class FawOpenService {
@Resource
HongqiAwemeIncentiveMonthlyMapper hongqiAwemeIncentiveMonthlyMapper;
@Resource
HongqiAwemeIncentiveQuarterMapper hongqiAwemeIncentiveQuarterMapper;
@Resource
HongqiLiveIncentiveMonthlyMapper hongqiLiveIncentiveMonthlyMapper;
@Resource
HongqiLiveIncentiveQuarterMapper hongqiLiveIncentiveQuarterMapper;
static String monthly = "monthly";
static String quarter = "quarter";
public BasePageVO<HongqiAwemeIncentiveVO> awemes(Date publishDateStart, Date publishDateEnd, String type, Integer pageNum, Integer pageSize) {
PageHelper.orderBy(" publish_time DESC ");
if (monthly.equals(type)) {
IPage<HongqiAwemeIncentiveMonthly> page = new Page<>(pageNum, pageSize);
QueryWrapper<HongqiAwemeIncentiveMonthly> queryWrapper = new QueryWrapper<>();
queryWrapper.between("publish_time", publishDateStart, publishDateEnd);
IPage<HongqiAwemeIncentiveMonthly> awemePage = hongqiAwemeIncentiveMonthlyMapper.selectPage(page, queryWrapper);
HongqiAwemeIncentiveStructMapper mapper = Mappers.getMapper(HongqiAwemeIncentiveStructMapper.class);
List<HongqiAwemeIncentiveVO> vos = mapper.listLiveMonthlyToVO(awemePage.getRecords());
return BasePageVO.restPage(pageNum, (int) awemePage.getSize(), (int) awemePage.getTotal(), (int) awemePage.getPages(), vos);
} else if (quarter.equals(type)) {
IPage<HongqiAwemeIncentiveQuarter> page = new Page<>(pageNum, pageSize);
QueryWrapper<HongqiAwemeIncentiveQuarter> queryWrapper = new QueryWrapper<>();
queryWrapper.between("publish_time", publishDateStart, publishDateEnd);
IPage<HongqiAwemeIncentiveQuarter> awemePage = hongqiAwemeIncentiveQuarterMapper.selectPage(page, queryWrapper);
HongqiAwemeIncentiveStructMapper mapper = Mappers.getMapper(HongqiAwemeIncentiveStructMapper.class);
List<HongqiAwemeIncentiveVO> vos = mapper.listLiveQuarterToVO(awemePage.getRecords());
return BasePageVO.restPage(pageNum, (int) awemePage.getSize(), (int) awemePage.getTotal(), (int) awemePage.getPages(), vos);
} else {
return new BasePageVO<>();
}
}
public BasePageVO<HongqiLiveIncentiveVO> lives(Date publishDateStart, Date publishDateEnd, String type, Integer pageNum, Integer pageSize) {
PageHelper.orderBy(" publish_time DESC ");
if (monthly.equals(type)) {
IPage<HongqiLiveIncentiveMonthly> page = new Page<>(pageNum, pageSize);
QueryWrapper<HongqiLiveIncentiveMonthly> queryWrapper = new QueryWrapper<>();
queryWrapper.between("publish_time", publishDateStart, publishDateEnd);
IPage<HongqiLiveIncentiveMonthly> awemePage = hongqiLiveIncentiveMonthlyMapper.selectPage(page, queryWrapper);
HongqiLiveIncentiveStructMapper mapper = Mappers.getMapper(HongqiLiveIncentiveStructMapper.class);
List<HongqiLiveIncentiveVO> vos = mapper.listLiveMonthlyToVO(awemePage.getRecords());
return BasePageVO.restPage(pageNum, (int) awemePage.getSize(), (int) awemePage.getTotal(), (int) awemePage.getPages(), vos);
} else if (quarter.equals(type)) {
IPage<HongqiLiveIncentiveQuarter> page = new Page<>(pageNum, pageSize);
QueryWrapper<HongqiLiveIncentiveQuarter> queryWrapper = new QueryWrapper<>();
queryWrapper.between("publish_time", publishDateStart, publishDateEnd);
IPage<HongqiLiveIncentiveQuarter> awemePage = hongqiLiveIncentiveQuarterMapper.selectPage(page, queryWrapper);
HongqiLiveIncentiveStructMapper mapper = Mappers.getMapper(HongqiLiveIncentiveStructMapper.class);
List<HongqiLiveIncentiveVO> vos = mapper.listLiveQuarterToVO(awemePage.getRecords());
return BasePageVO.restPage(pageNum, (int) awemePage.getSize(), (int) awemePage.getTotal(), (int) awemePage.getPages(), vos);
} else {
return new BasePageVO<>();
}
}
}
package com.afanticar.afantiopenapi.utils;
import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import java.util.Base64;
/**
* @author chin
* @contact chenyan@afanticar.com
* @since 2023/4/26/026
*/
public class JWTUtils {
public static String getClientId(String token) {
DecodedJWT jwt = JWT.decode(token);
Base64.Decoder decoder = Base64.getUrlDecoder();
String payload = new String(decoder.decode(jwt.getPayload()));
return JSONObject.parseObject(payload).getString("client_id");
}
}
#logging:
# level:
# com.afanticar.datacenter: debug
spring:
profiles:
active: local
cloud:
nacos:
config:
server-addr: https://dev-nacos.afanticar.net #local
maxRetry: 3
namespace: 09c8e0f2-6c67-4cd4-b167-5883a98a7a4f #local
ext-config:
- data-id: dynamic-db-afanti-vault.yml
- data-id: dynamic-db-afanti-tmp-vault.yml
- data-id: common-redis.yml
- data-id: afanti-open-api.yml
vault:
uri: https://vault.afanticar.com
authentication: approle
app-role:
role-id: 4681a8e7-c4bd-7da6-4dc0-8009e9cc3a58
secret-id: e158c4bb-51ae-d5c4-35ec-751fffcc1a02
config:
lifecycle:
enabled: true
# 阿里云accesskey
aws:
enabled: true
role: MqFullAccess
backend: alicloud
access-key-property: spring.rocket-mq.accessKey
secret-key-property: spring.rocket-mq.secretKey
# adb链接
generic:
enabled: true
backend: ${spring.profiles.active}
default-context: etladb
database:
enabled: true
backend: ${spring.profiles.active}db
role: app-role
username-property: spring.datasource.dynamic.datasource.master.username
password-property: spring.datasource.dynamic.datasource.master.password
#
#
#
#健康检查&监控信息
management:
metrics:
tags:
application: ${spring.application.name}
endpoints:
enabled-by-default: true
web:
exposure:
include: "prometheus,info,health"
base-path: "/"
endpoint:
health:
enabled: true
health:
elasticsearch:
enabled: false
mybatis:
configuration:
map-underscore-to-camel-case: true
mybatis-plus:
global-config:
db-config:
logic-delete-field: delete_state
logic-delete-value: 1
logic-not-delete-value: 0
insert-strategy: ignored
mapper-locations:
- classpath*:mapper/*.xml
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
logging:
level:
com.afanticar.datacenter.http.mapper.*: debug
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<contextName>Logback</contextName>
<springProfile name="local">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
</layout>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>1024</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="STDOUT"/>
</appender>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</springProfile>
<!-- 配置spring使用的参数名 -->
<springProfile name="dev,uat,pro,test,production">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<!-- 引入skywalking日志,添加tid -->
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
</layout>
</encoder>
</appender>
<!-- 配置异步输出 -->
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>1024</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="STDOUT"/>
</appender>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</springProfile>
</configuration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment