package com.huiju.estateagents.property.controller;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.common.UserElement;
import com.huiju.estateagents.property.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.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.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController

@RequestMapping("/api")
@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:当前页数")})

    @RequestMapping(value="/admin/tpAnnouncement",method = RequestMethod.POST)
    public ResponseBean tpAnnouncement(@RequestBody String paramets, HttpServletRequest request){
        TaUser userElement = getTaUser(request);
        ResponseBean tpAnnouncementList=tpAnnouncementService.tpAnnouncemenList(paramets,userElement.getOrgId());
        return tpAnnouncementList;
    }

    // @ApiOperation(value = "添加公告",nickname ="添加公告")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="announcementTitle:公告标题，" +
                    "announcementCarouselImg:轮播图，announcementContent：内容，contentImg:内容图片，sort:权重值,status:'0 是已作废 1 是已发布   2 是草稿 3 是已修改',")})

    @RequestMapping(value="/admin/addAnnouncement",method = RequestMethod.POST)
    public ResponseBean addAnnouncement(@RequestBody String paramets, HttpServletRequest request){
        TaUser userElement = getTaUser(request);
        ResponseBean  addAnnouncement= tpAnnouncementService.addAnnouncement(paramets,userElement.getOrgId(),userElement.getUserId());
        return addAnnouncement;
    }

    // @ApiOperation(value = "查询公告详情",nickname ="查询公告详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:公告id")})
    @RequestMapping(value="/admin/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="/admin/updateAnnouncement",method = RequestMethod.POST)
    public ResponseBean updateAnnouncement(@RequestBody String paramets, HttpServletRequest request){
        TaUser userElement = getTaUser(request);
        ResponseBean tpAnnouncement= tpAnnouncementService.updateAnnouncement(paramets,userElement.getOrgId(),userElement.getUserId());
        return tpAnnouncement;
    }

    // @ApiOperation(value = "批量删除公告",nickname ="批量删除公告")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "String", name = "paramets", value ="id:公告id(多个)")})
    @RequestMapping(value="/admin/deleteAnnouncement",method = RequestMethod.POST)
    public ResponseBean deleteAnnouncement(@RequestBody String paramets, HttpServletRequest request){
        TaUser userElement = getTaUser(request);
        ResponseBean tpAnnouncement= tpAnnouncementService.deleteAnnouncement(paramets,userElement.getOrgId(),userElement.getUserId());
        return tpAnnouncement;
    }


}
