package com.hssx.pcbms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hssx.pcbms.entity.Idea;
import com.hssx.pcbms.entity.vo.GoodsVO;
import com.hssx.pcbms.entity.vo.IdeaVO;
import com.hssx.pcbms.service.IdeaService;
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.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;

/**
 * @author 吴涛涛
 * @since 2019-11-02
 */
@Controller
@RequestMapping("/idea")
public class IdeaController {

    @Autowired
    private IdeaService ideaService;
    /**
     * 建议的发表/修改
     * 参数：
     * uid :当前发表人的id，content：建议的内容，isDraft:（提交传0 退出传1）
     * 注：修改时传 id:建议的id(以上参数isDraft也需要传)
     * @return
     */
    @ApiOperation(value = "建议的发表/修改", notes = "建议的发表/修改方法")
    @RequestMapping("/addOrUpdate")
    @ResponseBody
    public HttpRespMsg addOrUpdate(Idea idea) {
        HttpRespMsg msg = ideaService.add(idea);
        return msg;
    }

    /**
     * 获取草稿
     * 参数：
     * uid :当前发表人的id
     * @return
     */
    @ApiOperation(value = "获取草稿", notes = "获取草稿方法")
    @RequestMapping("/getDraft")
    @ResponseBody
    public HttpRespMsg getDraft(Idea idea) {
        HttpRespMsg msg = ideaService.getDraft(idea);
        return msg;
    }

    /**
     * 删除建议
     * 参数：
     * id:建议的id
     * @return
     */
    @ApiOperation(value = "删除建议", notes = "删除建议方法")
    @RequestMapping("/del")
    @ResponseBody
    public HttpRespMsg del(Idea idea) {
        HttpRespMsg msg = ideaService.del(idea);
        return msg;
    }

    /**
     * 建议列表
     * 参数：
     * uid:用户id，pageNum:当前页，pageSize：每页多少条
     * @return
     */
    @ApiOperation(value = "建议列表", notes = "建议列表方法")
    @RequestMapping("/ideaList")
    @ResponseBody
    public HttpRespMsg ideaList(Idea idea, PageUtil page) {
        HttpRespMsg msg = ideaService.ideaList(idea,page);
        return msg;
    }

    /**
     * 打分根据年月去获取他的建议列表
     * 参数：
     * uid:用户id，time:时间 如:2019-8，scoreId:打分id
     * @return
     */
    @ApiOperation(value = "打分根据年月去获取他的建议列表", notes = "打分根据年月去获取他的建议列表方法")
    @RequestMapping("/ideaListByTime")
    @ResponseBody
    public HttpRespMsg ideaListByTime(Idea idea,String time,String scoreId) {
        HttpRespMsg msg = ideaService.ideaListByTime(idea,time,scoreId);
        return msg;
    }

    /**
     * 获取建议得分
     * 有两种情况
     * 参数：
     * 1.打分：time:建议时间如：2019-11 ，uid:发表建议人的id,scoreId:打分的数据的id
     * 2.修改打分：scoreId:打分的数据的id,time:建议时间如：2019-11,uid:发表建议人的id
     * @return
     */
    @ApiOperation(value = "获取建议得分", notes = "获取建议得分方法")
    @RequestMapping("/getAdviceScore")
    @ResponseBody
    public HttpRespMsg getAdviceScore(IdeaVO ideaVO) {
        HttpRespMsg msg = new HttpRespMsg();
        try {
            msg = ideaService.getAdviceScore(ideaVO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return msg;
    }

}

