package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.model.TpAnnouncement;
import com.community.huiju.service.TpAnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "公告管理API", description = "公告管理API")
public class TpAnnouncementController extends BaseController {
    @Autowired
    private TpAnnouncementService tpAnnouncementService;

    @ApiOperation(value = "获取公告管理列表",nickname ="获取公告管理列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:公告编号,announcementTitle:公告标题 ,current:每页显示多少条,current:每页显示多少条,pageSzie:当前页数")})
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value="/tpAnnouncement",method = RequestMethod.POST)
    public ResponseBean tpAnnouncement(@RequestBody String paramets, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean tpAnnouncementList=tpAnnouncementService.tpAnnouncemenList(paramets,userElement.getCommunityId());
        return tpAnnouncementList;
    }

    @ApiOperation(value = "添加公告",nickname ="添加公告")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="announcementTitle:公告标题，" +
                    "announcementCarouselImg:轮播图，announcementContent：内容，contentImg:内容图片，sort:权重值,status:'0 是已作废 1 是已发布   2 是草稿 3 是已修改',")})
    @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    @RequestMapping(value="/addAnnouncement",method = RequestMethod.POST)
    public ResponseBean addAnnouncement(@RequestBody String paramets, HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean  addAnnouncement= tpAnnouncementService.addAnnouncement(paramets,userElement.getCommunityId(),userElement.getId());
        return addAnnouncement;
    }

    @ApiOperation(value = "查询公告详情",nickname ="查询公告详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:公告id")})
    @RequestMapping(value="/announcementById",method = RequestMethod.POST)
    public ResponseBean announcementById(@RequestBody String paramets){
        ResponseBean tpAnnouncement= tpAnnouncementService.announcementById(paramets);
        return tpAnnouncement;
    }

    @ApiOperation(value = "修改公告",nickname ="修改公告")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:公告id，announcementTitle:公告标题，" +
                    "announcementCarouselImg:轮播图，announcementContent：内容，contentImg:内容图片，sort:权重值,status:'0 是已作废 1 是已发布   2 是草稿 3 是已修改',")})
    @RequestMapping(value="/updateAnnouncement",method = RequestMethod.POST)
    public ResponseBean updateAnnouncement(@RequestBody String paramets,HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean tpAnnouncement= tpAnnouncementService.updateAnnouncement(paramets,userElement.getCommunityId(),userElement.getId());
        return tpAnnouncement;
    }

    @ApiOperation(value = "批量删除公告",nickname ="批量删除公告")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:公告id(多个)")})
    @RequestMapping(value="/deleteAnnouncement",method = RequestMethod.POST)
    public ResponseBean deleteAnnouncement(@RequestBody String paramets,HttpSession session){
        UserElement userElement = getUserElement(session);
        ResponseBean tpAnnouncement= tpAnnouncementService.deleteAnnouncement(paramets,userElement.getCommunityId(),userElement.getId());
        return tpAnnouncement;
    }


}
