package com.huiju.estateagents.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.common.CommConstant;
import com.huiju.estateagents.entity.TpNewsType;
import com.huiju.estateagents.service.ITpNewsTypeService;
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.*;

import javax.servlet.http.HttpServletRequest;

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

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

    @Autowired
    public ITpNewsTypeService iTpNewsTypeService;


    /**
     * 分页查询列表
     * @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/tpNewsType",method= RequestMethod.GET)
    public ResponseBean tpNewsTypeList(@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 = iTpNewsTypeService.getList(pageNum, pageSize, buildingId, getOrgId(request),getTaPersonBuildingListByUserId(request));
        return responseBean;
    }

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

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

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

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

    @ApiOperation(value = "查询物业服务类型列表", notes = "查询物业服务类型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "buildingId", paramType = "query",value = "项目id")
    })
    @RequestMapping(value="/wx/tpNewsType/list",method= RequestMethod.GET)
    public ResponseBean getWxTpNewsTypeList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "buildingId", required = false) String buildingId,
                                       HttpServletRequest request){
        QueryWrapper<TpNewsType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_id",getOrgId(request));
        queryWrapper.eq("status", CommConstant.STATUS_NORMAL);
        queryWrapper.orderByDesc("create_date");

        return ResponseBean.success(iTpNewsTypeService.list(queryWrapper));
    }

}
