package com.hssx.pcbms.controller;


import com.hssx.pcbms.entity.Idea;
import com.hssx.pcbms.entity.Score;
import com.hssx.pcbms.entity.vo.IdeaVO;
import com.hssx.pcbms.service.ScoreService;
import com.hssx.pcbms.util.HttpRespMsg;
import com.hssx.pcbms.util.PageUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴涛涛
 * @since 2019-11-02
 */
@Controller
@RequestMapping("/score")
@EnableScheduling
public class ScoreController {
    @Autowired
    private ScoreService scoreService;

    /**
     * 打分/修改打分
     * 参数：
     * uid :被打分人的id，personalScore：个人分，ideaScore:建议分,reason:评分原因,
     * total:总得分，scoringYearMonth：打分日期如：2019-10,raterId:打分人id
     * 注：修改时传 scoreId:打分数据的id（以上参数修改的传，没修改的不传）
     * @return
     */
    @ApiOperation(value = "打分/修改打分", notes = "打分/修改打分方法")
    @RequestMapping("/addOrUpdate")
    @ResponseBody
    public HttpRespMsg addOrUpdate(Score score) {
        HttpRespMsg msg = new HttpRespMsg();
        try {
             msg = scoreService.add(score);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return msg;
    }
    /**
     * 删除打分
     * 参数：
     * scoreId:打分数据的id
     * @return
     */
    @ApiOperation(value = "删除打分", notes = "删除打分方法")
    @RequestMapping("/del")
    @ResponseBody
    public HttpRespMsg del(Score score) {
        HttpRespMsg msg = new HttpRespMsg();
        try {
             msg = scoreService.del(score);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return msg;
    }
    /**
     * 我的评分
     * 参数：
     * uid :被打分人的id
     * @return
     */
    @ApiOperation(value = "我的评分", notes = "我的评分方法")
    @RequestMapping("/myList")
    @ResponseBody
    public HttpRespMsg myList(Score score, PageUtil page) {
        HttpRespMsg msg = new HttpRespMsg();
        try {
             msg = scoreService.getList(score,page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return msg;
    }
    /**
     * 评分详情
     * 参数：
     * scoreId :打分id
     * @return
     */
    @ApiOperation(value = "评分详情", notes = "评分详情方法")
    @RequestMapping("/detail")
    @ResponseBody
    public HttpRespMsg detail(Score score) {
        HttpRespMsg msg = new HttpRespMsg();
        try {
             msg = scoreService.detail(score);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return msg;
    }
    /**
     * 根据日期获取评分详情
     * 参数：time:时间 2019-12 ，uid：被打分人id
     *
     * @return
     */
    @ApiOperation(value = "评分详情", notes = "评分详情方法")
    @RequestMapping("/getDetailByTimeAndUid")
    @ResponseBody
    public HttpRespMsg getDetailByTimeAndUid(Score score,String time) {
        HttpRespMsg msg = new HttpRespMsg();
        try {
             msg = scoreService.getDetailByTimeAndUid(score,time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return msg;
    }
    /**
     * 打分通知定时任务
     * 参数：
     * @return
     */
    @ApiOperation(value = "打分通知定时任务", notes = "打分通知定时任务")
    @RequestMapping("/scoringTaskNotice")
    @ResponseBody
    @Scheduled(cron = "0 23 0 1 * ?")//配置时间点触发(每月1号的23点执行)
    public HttpRespMsg scoringTaskNotice() {
        HttpRespMsg msg = new HttpRespMsg();
        try {
             msg = scoreService.scoringTaskNotice();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return msg;
    }




}

