DataExchangeController.java 5.4 KB
package cn.fw.dalaran.server.controller.common;

import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.common.web.util.ResultBuilder;
import cn.fw.dalaran.domain.dto.LivePoolDTO;
import cn.fw.dalaran.domain.dto.VideoPoolDTO;
import cn.fw.dalaran.domain.param.SqlExecuteParam;
import cn.fw.dalaran.domain.vo.CommonAccountVO;
import cn.fw.dalaran.service.biz.AccountBizService;
import cn.fw.dalaran.service.biz.CommonBizService;
import cn.fw.dalaran.service.data.LivePoolService;
import cn.fw.dalaran.service.data.VideoPoolService;
import cn.fw.data.base.domain.common.Message;
import cn.fw.security.auth.client.annotation.Authorization;
import cn.fw.security.auth.client.enums.AuthType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

import static cn.fw.common.web.util.ResultBuilder.success;

/**
 * @author kurisu
 * @date 2021-11-17 15:02
 * @description 数据交换控制器
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@Authorization(AuthType.NONE)
@RequestMapping("/common")
public class DataExchangeController {

    private final AccountBizService accountBizService;
    private final CommonBizService commonBizService;
    private final VideoPoolService videoPoolService;
    private final LivePoolService livePoolService;
    private final JdbcTemplate jdbcTemplate;

    @PutMapping("/account/invalid")
    @ControllerMethod("账号cookie失效上报")
    public Message<Boolean> invalidReport(@NotBlank(message = "账号不能为空") String account, @NotNull(message = "账号类型不能为空") Integer type) {
        return success(accountBizService.reportInvalidAccount(account, type));
    }

    @GetMapping("/account/list")
    @ControllerMethod("查询有效账号列表")
    public Message<List<CommonAccountVO>> list(@NotNull(message = "账号类型不能为空") Integer type) {
        return success(accountBizService.getValidAccount(type));
    }

    @PutMapping("/report/accountMsg")
    @ControllerMethod("账号信息上报")
    public Message<Void> accountMsgReport(@NotBlank(message = "账号不能为空") String account, @NotNull(message = "账号类型不能为空") Integer type, Long fansCnt, String accountName) {
        accountBizService.saveAccountMsg(account, type, fansCnt, accountName);
        return success();
    }

    @PostMapping("/report/video")
    @ControllerMethod("短视频数据上报")
    public Message<Void> videoReport(@RequestBody VideoPoolDTO videoPoolDTO) {
        return commonBizService.saveVideoData(videoPoolDTO) ? success() : ResultBuilder.failure();
    }

    @PostMapping("/report/live")
    @ControllerMethod("直播数据上报")
    public Message<Void> liveReport(@RequestBody LivePoolDTO livePoolDTO) {
        return commonBizService.saveLiveData(livePoolDTO) ? success() : ResultBuilder.failure();
    }

    /**
     * 获取主题活动员工有效视频数
     *
     * @param userId  用户id
     * @param themeId 活动主题id
     * @return 有效视频数
     */
    @GetMapping("/getValidVideoCnt")
    @ControllerMethod("获取主题活动员工有效视频数")
    public Message<Integer> getValidVideoCnt(@NotNull(message = "用户id不能为空") Long userId, @NotNull(message = "活动主题id不能为空") Long themeId) {
        return success(videoPoolService.getValidVideoCnt(userId, themeId));
    }

    /**
     * 获取主题活动员工有效直播数
     *
     * @param userId  用户id
     * @param themeId 活动主题id
     * @return 有效直播数
     */
    @GetMapping("/getValidLiveCnt")
    @ControllerMethod("获取主题活动员工有效直播数")
    public Message<Integer> getValidLiveCnt(@NotNull(message = "用户id不能为空") Long userId, @NotNull(message = "活动主题id不能为空") Long themeId) {
        return success(livePoolService.getValidLiveCnt(userId, themeId));
    }

    /**
     * SQL语句执行器
     *
     * @param param SQL语句及其参数封装
     * @return 执行结果
     */
    @PostMapping("/sqlExecute")
    public Message<Object> sqlExecutor(@RequestBody @Validated SqlExecuteParam param) {
        return success(jdbcTemplate.update(param.getSql(), param.getParams()));
    }

    /**
     * 计算图片相似度
     *
     * @param theme    主题名
     * @param themeId  主题id
     * @param fid      服务器图片id
     * @param coverUrl 作品封面图地址
     * @param itemId   作品id
     * @param type     作品类型
     * @return 相似度%
     * @throws Exception
     */
    @GetMapping("/calcSimilarity")
    public Message<BigDecimal> calcSimilarity(String theme, Long themeId, String fid, String coverUrl, String account, String itemId, Integer type) throws Exception {
        return success(commonBizService.validCover(theme, themeId, fid, coverUrl, account, itemId, type));
    }

    /**
     * 标识最佳直播
     *
     * @param liveId 直播数据id
     * @return 操作成败
     */
    @GetMapping("/markBestLive")
    @ControllerMethod("标识最佳直播")
    public Message<Boolean> markBestLive(@NotNull(message = "直播数据id不能为空") Long liveId) {
        return success(livePoolService.markBestLive(liveId));
    }

}