package com.qs.mp.web.controller.api.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qs.mp.channel.domain.Channel;
import com.qs.mp.channel.domain.param.PromoterListQueryParam;
import com.qs.mp.channel.domain.vo.PromoterListVO;
import com.qs.mp.channel.service.IChannelService;
import com.qs.mp.common.core.domain.AjaxResult;
import com.qs.mp.common.core.page.TableDataInfo;
import com.qs.mp.web.controller.common.BaseApiController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.number.AbstractNumberFormatter;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 推广员管理API
 *
 * @author Cup
 * @date 2022/8/9
 */
@Api(tags = "推广员管理API")
@RestController
@RequestMapping("/api/v1/mp/admin/promoter")
public class PromoterMsgController extends BaseApiController {


    @Autowired
    private IChannelService channelService;

    @PostMapping("/list")
    @ApiOperation("推广员列表")
    @ApiResponses(
        @ApiResponse(code = 200, message = "推广员列表", response = PromoterListVO.class)
    )
    public TableDataInfo list(@RequestBody PromoterListQueryParam param) {
        startPage();
        QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("t1.level", -1);
        queryWrapper.eq("t1.is_deleted", 0);

        queryWrapper.like(StringUtils.isNotBlank(param.getSiteName()), "t2.name", param.getSiteName());
        queryWrapper.like(StringUtils.isNotBlank(param.getName()), "t1.name", param.getName());
        queryWrapper.eq(StringUtils.isNotBlank(param.getMobile()), "t1.mobile", param.getMobile());

        if (param.getStartDate() != null && param.getEndDate() != null) {
            queryWrapper.between("t1.created_time", param.getStartDate(), param.getEndDate());
        }

        List<PromoterListVO> list = channelService.listPromoterByQueryWrapper(queryWrapper);
        return getDataTable(list);
    }

}
