package com.yunzhi.marketing.xlk.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.yunzhi.marketing.base.BaseController;
import com.yunzhi.marketing.base.ResponseBean;
import com.yunzhi.marketing.xlk.dto.ChannelCustomerDTO;
import com.yunzhi.marketing.xlk.dto.MarkingChannelCustomerDTO;
import com.yunzhi.marketing.xlk.entity.ChannelCustomer;
import com.yunzhi.marketing.xlk.service.IChannelCustomerService;
import io.swagger.annotations.Api;
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.*;

/**
 * <p>
    * 渠道报备客户表  前端控制器
    * </p>
 *
 * @author jobob
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/api")
@Api(value = "森哥看这里-渠道报备客户表", tags = "森哥看这里-xlk-渠道报备客户表")
public class ChannelCustomerController extends BaseController {

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

    @Autowired
    public IChannelCustomerService iChannelCustomerService;


    /**
     * 分页查询列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "admin-渠道报备客户表", notes = "admin-渠道报备客户表")
    @RequestMapping(value="/admin/channelCustomer",method= RequestMethod.GET)
    public ResponseBean channelCustomerList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
                                            @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
        ResponseBean responseBean = new ResponseBean();
        try {
            //使用分页插件
		    IPage<ChannelCustomer> pg = new Page<>(pageNum, pageSize);
            LambdaQueryWrapper<ChannelCustomer> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ChannelCustomer::getStatus,"1");
            queryWrapper.orderByDesc(ChannelCustomer::getCreateDate);

            IPage<ChannelCustomer> result = iChannelCustomerService.page(pg, queryWrapper);
            responseBean.addSuccess(result);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("channelCustomerList -=- {}",e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 审核
     * @param id  实体ID
     * @param channelCustomerDTO 实体对象
     * @return
     */
    @ApiOperation(value = "admin-渠道报备客户审核", notes = "admin-渠道报备客户审核")
    @RequestMapping(value="/admin/channelCustomer/{id}",method= RequestMethod.PUT)
    public ResponseBean channelCustomerUpdate(@PathVariable Integer id,
                                        @RequestBody ChannelCustomerDTO channelCustomerDTO){
        return iChannelCustomerService.auditCustomer(id,channelCustomerDTO);
    }


    /**
     * 驻场 确认到访
     *
     * @param
     * @return
     */
    @ApiOperation(value = "森哥看这里-wx-驻场确认到访", notes = "森哥看这里-wx-驻场确认到访")
    @RequestMapping(value="/wx/marking/channelCustomer",method= RequestMethod.PUT)
    public ResponseBean channelCustomerUpdate(@RequestBody MarkingChannelCustomerDTO params){
        return iChannelCustomerService.markingChannelCustomer(params);
    }


    /**
     * 驻场 无效报备
     *
     * @param
     * @return
     */
    @ApiOperation(value = "森哥看这里-wx-无效报备", notes = "森哥看这里-wx-无效报备")
    @RequestMapping(value="/wx/marking/invalidCustomer",method= RequestMethod.PUT)
    public ResponseBean invalidCustomerUpdate(@RequestBody MarkingChannelCustomerDTO params){
        return iChannelCustomerService.invalidCustomerUpdate(params);
    }

    /**
     * 根据id查询对象
     * @param id  实体ID
     */
    @RequestMapping(value="/admin/channelCustomer/{id}",method= RequestMethod.GET)
    public ResponseBean channelCustomerGet(@PathVariable Integer id){
        ResponseBean responseBean = new ResponseBean();
        try {
            responseBean.addSuccess(iChannelCustomerService.getById(id));
        }catch (Exception e){
            e.printStackTrace();
            logger.error("channelCustomerDelete -=- {}",e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }
}
