package com.ssj.aijia.load.data.es;


import com.alibaba.dubbo.config.annotation.Reference;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.framework.core.security.manager.TokenManager;
import com.ssj.framework.core.util.ResponseConstant;
import com.ssj.framework.core.util.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "后台加载数据至ES", tags = "后台加载数据至ES")
@RestController
@RequestMapping("/api/load/data")
public class LoadDataController extends BaseController {

    private  final  static String beginDate ="2017-03-01";

    private  final  static String endDate ="2020-04-01";

    @Autowired
    private TokenManager tokenManager;

    @Reference(version = "1.0" ,timeout = 60000)
    private com.ssj.service.load.data.LoadDataService loadDataService;


    @ApiOperation(value = "学生往期反馈记录列表")
    @RequestMapping(value = "feedbackHistory", method = RequestMethod.POST)
    public ResponseEntity feedbackHistory(@RequestParam(name = "accessToken") String accessToken,
                                          @RequestParam(required = false, defaultValue = "1000") int count ) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity= loadDataService.loadfeedbackHistoryES(beginDate,endDate,
                    "feedbackhistory","学生往期反馈记录列表",count);
        } catch (Exception e) {
            logger.error("查询学生往期反馈记录列表异常", e);
            responseEntity.failure(ResponseConstant.CODE_000, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }



    @ApiOperation(value = "学习成长报告(周)v2")
    @RequestMapping(value = "findweeklyreport", method = RequestMethod.POST)
    public ResponseEntity findweeklyreport(@RequestParam(name = "accessToken") String accessToken,
    @RequestParam(required = false, defaultValue = "1000") int count) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity= loadDataService.findWeeklyReportBeginDateAndEndDateES(beginDate,endDate,
                    "findweeklyreport","学习成长报告(周)v2",count);
        } catch (Exception e) {
            logger.error("学习成长报告(周)v2异常", e);
            responseEntity.failure(ResponseConstant.CODE_000, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }


    @ApiOperation(value = "加载表scon_homework_count")
    @RequestMapping(value = "scon_homework_count", method = RequestMethod.POST)
    public ResponseEntity sconHomeworkCount(@RequestParam(name = "accessToken") String accessToken,
                                            @RequestParam(required = false, defaultValue = "1000") int count) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity= loadDataService.sconHomeworkCount(beginDate,endDate,
                    "scon_homework_count","加载表scon_homework_count",count);
        } catch (Exception e) {
            logger.error("加载表scon_homework_count异常", e);
            responseEntity.failure(ResponseConstant.CODE_000, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }

    @ApiOperation(value = "周报历史记录")
    @RequestMapping(value = "esWeeklyReportHistory", method = RequestMethod.POST)
    public ResponseEntity esWeeklyReportHistory(@RequestParam(name = "accessToken") String accessToken,
                                            @RequestParam(required = false, defaultValue = "1000") int count) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity= loadDataService.loadWeeklyReportHisToES(beginDate,endDate,
                    "weeklyreporthistory","周报历史记录",count);
        } catch (Exception e) {
            logger.error("加载周报历史记录异常", e);
            responseEntity.failure(ResponseConstant.CODE_000, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }

    @ApiOperation(value = "月报历史记录")
    @RequestMapping(value = "esMonthlyReportHistory", method = RequestMethod.POST)
    public ResponseEntity esMonthlyReportHistory(@RequestParam(name = "accessToken") String accessToken,
                                                @RequestParam(required = false, defaultValue = "1000") int count) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity= loadDataService.loadMonthlyReportHistoryToES(beginDate,endDate,
                    "monthlyreporthistory","月报历史记录",count);
        } catch (Exception e) {
            logger.error("加载月报历史记录异常", e);
            responseEntity.failure(ResponseConstant.CODE_000, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }

    @RequestMapping(value = "/esLearningSituationAbstract", method = RequestMethod.POST)
    @ApiOperation(value = "学情整体情况", httpMethod = "POST", notes = "学情整体情况")
    public ResponseEntity esLearningSituationAbstract(@RequestParam(name = "accessToken") String accessToken, @RequestParam(required = false, defaultValue = "1000") int count) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity= loadDataService.loadLearningSituationAbstractToES(beginDate,endDate,
                    "learningsituationabstract","学情整体情况",count);
        } catch (Exception e) {
            logger.error("加载学情整体情况异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

}
