package com.bohuikeji.delivery.backstage.controller.api.other;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bohuikeji.delivery.backstage.entity.TCourier;
import com.bohuikeji.frame.module.admin.entity.TFranchiseeInformation;
import com.bohuikeji.frame.module.admin.service.ITFranchiseeInformationService;
import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.entity.back.DataPage;
import com.bohuikeji.frame.module.admin.utils.StringUtils;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"加盟商相关接口"})
@RestController
@RequestMapping("/api/franchiseeInfo")
@Slf4j
public class FranchiseeInformationApi extends ApiController {

    @Autowired
    ITFranchiseeInformationService franchiseeInformationService;

    /**
     * 查询全部加盟商
     * @return
     */
    @ApiOperation("查询全部加盟商")
    @GetMapping("/order/list")
    //配置忽略参数
    @ApiOperationSupport(ignoreParameters = {"records","total","searchCount"})
    /*@ApiImplicitParams({
            @ApiImplicitParam(name="orderStatus",value="订单状态",dataType="String", paramType = "query"),
            @ApiImplicitParam(name="courierId",value="订单状态",dataType="String", paramType = "query",required=true)})*/
    public APIEntity<IPage<TFranchiseeInformation>> orderListAll(DataPage<TFranchiseeInformation> page){
        page.setSize(10000);
        return APIEntity.success(franchiseeInformationService.page(page,new QueryWrapper<TFranchiseeInformation>().eq("fran_status","启用")));
    }

    /**
     * 查询全部加盟商
     * @return
     */
    @ApiOperation("根据搜索条件查询")
    @GetMapping("/get/list/key")
    //配置忽略参数
    @ApiOperationSupport(ignoreParameters = {"records","total","searchCount"})
    @ApiImplicitParams({
            @ApiImplicitParam(name="franName",value="查询值",dataType="String", paramType = "query")})
    public APIEntity<List<TFranchiseeInformation>> getListKey(String franName){
        //franchiseeInformationService.list(new QueryWrapper<TFranchiseeInformation>().eq("fran_status","启用").like("fran_name",franName).or().eq("fran_name","平台"))
        log.info("加盟商查询条件：[{}]",franName);
        QueryWrapper<TFranchiseeInformation> qu= new QueryWrapper<>();
        List<TFranchiseeInformation> frans = null;
        if(StringUtils.isBlank(franName)){
            frans = franchiseeInformationService.list(new QueryWrapper<TFranchiseeInformation>().eq("fran_status","启用"));
        }else {
            frans = franchiseeInformationService.list(new QueryWrapper<TFranchiseeInformation>().eq("fran_status","启用").like("fran_name",franName));
        }
        return APIEntity.success(frans);
    }

}
