package com.crm.ib.task.controller.manager;

import com.crm.ib.task.configuration.IbReportAnnotation;
import com.crm.ib.task.service.report.VolumeReportService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.constant.FeignClientAnnotation;
import com.crm.rely.backend.core.dto.base.BaseReportResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.model.dto.report.SalesCommissionReportListDto;
import com.crm.rely.backend.model.dto.report.SalesCommissionReportSumDto;
import com.crm.rely.backend.model.dto.report.VolumeReportListDto;
import com.crm.rely.backend.model.dto.report.VolumeReportSumDto;
import com.crm.rely.backend.model.entity.report.VolumeReportEntity;
import com.crm.rely.backend.model.entity.user.info.UserInfoEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 报表
 *
 * @author y
 * @create 2022/5/5
 */
@RestController
@RequestMapping("/manager/service/report")
public class ReportMsController {

    @Autowired
    private VolumeReportService volumeReportService;

    /**
     * 交易量报表
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/volume")
    @FeignClientAnnotation
    @IbReportAnnotation
    public BaseReportResultDto<List<VolumeReportListDto>, VolumeReportSumDto> volume(@RequestBody VolumeReportEntity entity, UserInfoEntity infoEntity) throws Exception {
        if (StringUtils.isEmpty(entity.getPlatform())) {
            entity.setPlatform(Constants.MT4);
        }
        return volumeReportService.pageList(entity);
    }

    /**
     * 交易量报表导出
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/volume/export")
    @FeignClientAnnotation
    @IbReportAnnotation
    public BaseResultDto<List<VolumeReportListDto>> volumeExport(@RequestBody VolumeReportEntity entity, UserInfoEntity infoEntity) throws Exception {
        if (StringUtils.isEmpty(entity.getPlatform())) {
            entity.setPlatform(Constants.MT4);
        }
        return volumeReportService.exportList(entity);
    }

    /**
     * 销售佣金报表
     * @param entity
     * @param infoEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/sales/volume")
    @FeignClientAnnotation
    @IbReportAnnotation
    public BaseReportResultDto<List<SalesCommissionReportListDto>, SalesCommissionReportSumDto> salesVolume(@RequestBody VolumeReportEntity entity, UserInfoEntity infoEntity) throws Exception {
        return volumeReportService.pageSalesVolumeList(entity);
    }

    /**
     * 销售佣金报表导出列表
     * @param entity
     * @param infoEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/sales/volume/export")
    @FeignClientAnnotation
    @IbReportAnnotation
    public BaseResultDto<List<SalesCommissionReportListDto>> salesVolumeExport(@RequestBody VolumeReportEntity entity, UserInfoEntity infoEntity) throws Exception {
        return volumeReportService.exportSalesVolumeList(entity);
    }
}
