package com.huiju.estateagents.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.entity.TaNewsType;
import com.huiju.estateagents.service.ITaNewsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
    * 资讯类型表  前端控制器
    * </p>
 *
 * @author jobob
 * @since 2019-07-25
 */
@RestController
@RequestMapping("/api")
@Api(value = "资讯类型", tags = "资讯类型")
public class TaNewsTypeController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(TaNewsTypeController.class);

    @Autowired
    public ITaNewsTypeService iTaNewsTypeService;


    /**
     * 分页查询列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "查询资讯类型", notes = "查询资讯类型")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageNum", paramType = "query",value = "第几页"),
            @ApiImplicitParam(dataTypeClass = Integer.class, name = "pageSize", paramType = "query",value = "一页多少行"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "buildingId", paramType = "query",value = "项目id")
    })
    @RequestMapping(value="/admin/taNewsType",method= RequestMethod.GET)
    public ResponseBean taNewsTypeList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "buildingId", required = false) String buildingId,
                                       HttpServletRequest request){
        ResponseBean responseBean = iTaNewsTypeService.getList(pageNum, pageSize, buildingId, getOrgId(request),getTaPersonBuildingListByUserId(request));
        return responseBean;
    }

    /**
     * 保存对象
     * @param taNewsType 实体对象
     * @return
     */
    @ApiOperation(value = "保存资讯类型", notes = "保存资讯类型")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "TaNewsType", name = "taNewsType", paramType = "body",value = "资讯类型数据")
    })
    @RequestMapping(value="/admin/taNewsType",method= RequestMethod.POST)
    public ResponseBean taNewsTypeAdd(@RequestBody TaNewsType taNewsType, HttpServletRequest request){
        ResponseBean responseBean = iTaNewsTypeService.addTaNewsType(taNewsType, getOrgId(request));
        return responseBean;
    }

    /**
     * 根据id删除对象
     * @param id  实体ID
     */
    @ResponseBody
    @RequestMapping(value="/admin/taNewsType/{id}", method= RequestMethod.DELETE)
    public ResponseBean taNewsTypeDelete(@PathVariable Integer id){
        ResponseBean responseBean = iTaNewsTypeService.deleteTaNewsType(id);
        return responseBean;
    }

    /**
     * 修改对象
     * @param id  实体ID
     * @param taNewsType 实体对象
     * @return
     */
    @ApiOperation(value = "修改资讯类型", notes = "根据ID修改资讯类型")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "TaNewsType", name = "taNewsType", paramType = "body",value = "资讯类型数据"),
            @ApiImplicitParam(dataType = "Integer", name = "id", paramType = "path",value = "资讯id")
    })
    @RequestMapping(value="/admin/taNewsType/{id}",method= RequestMethod.PUT)
    public ResponseBean taNewsTypeUpdate(@PathVariable Integer id,
                                        @RequestBody TaNewsType taNewsType, HttpServletRequest request){
        taNewsType.setNewsTypeId(id);
        taNewsType.setOrgId(getOrgId(request));
        ResponseBean responseBean = iTaNewsTypeService.updateTaNewsType(taNewsType);
        return responseBean;
    }

    /**
     * 根据id查询对象
     * @param id  实体ID
     */
    @ApiOperation(value = "咨询类型详情", notes = "咨询类型详情")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", paramType = "path",value = "资讯id")
    })
    @RequestMapping(value="/admin/taNewsType/{id}",method= RequestMethod.GET)
    public ResponseBean taNewsTypeGet(@PathVariable Integer id){
        ResponseBean responseBean = iTaNewsTypeService.getTaNewsTypeById(id);
        return responseBean;
    }

}
