package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxBusiness;
import com.iformall.domain.po.WxCUser;
import com.iformall.service.WxBusinessService;
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.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/wxBusiness")
@Api(description = "业态查询接口")
public class WxBusinessController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxBusinessService wxBusinessService;

    @ApiOperation("分页列表接口")
    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData list(WxBusiness wxBusiness, Integer pageNum, Integer pageSize) {
        if (null == wxBusiness) wxBusiness = new WxBusiness();
        WxCUser user = getUser();
        final PageInfo<WxBusiness> page = wxBusinessService.listAsPage(wxBusiness, pageNum, pageSize);
        return new ResultData(page);
    }

    @ApiOperation("成长值业态列表接口")
    @GetMapping("busListForScore")
    public ResultData getList(@ModelAttribute WxBusiness wxBusiness) {
        if (null == wxBusiness) wxBusiness = new WxBusiness();
        final List<WxBusiness> busList = wxBusinessService.getList(wxBusiness);
        // 业态 全部 不返回
        List<WxBusiness> busList2 = busList.stream().filter(b -> !b.getId().equals(0L)).collect(Collectors.toList());
        return new ResultData(busList2);
    }

    @ApiOperation("业态全列表接口")
    @GetMapping("allist")
    public ResultData getAllList(@ModelAttribute WxBusiness wxBusiness) {
        if (null == wxBusiness) wxBusiness = new WxBusiness();
        final List<WxBusiness> busList = wxBusinessService.getList(wxBusiness);
        return new ResultData(busList);
    }
}
