package cn.iocoder.yudao.module.partner.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.core.text.Convert;
import cn.iocoder.yudao.module.core.text.ServletUtils;
import cn.iocoder.yudao.module.inspection.service.AppInspectionPartnerService;
import cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo;
import cn.iocoder.yudao.module.partner.service.IPartnerCustomerInfoService;
import cn.iocoder.yudao.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户信息Controller
 *
 * @author zcy
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/admin-api/customerInfo/customerInfo")
public class PartnerCustomerInfoController extends BaseController
{
    @Autowired
    private IPartnerCustomerInfoService partnerCustomerInfoService;
    @Autowired
    private AppInspectionPartnerService partnerService;

    /**
     * 查询客户信息列表
     */
    @GetMapping("/list")
    public CommonResult<IPage<?>> list(PartnerCustomerInfo partnerCustomerInfo,
                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {
        Page<PartnerCustomerInfo> page = new Page<>(pageNo, pageSize);
        return success(partnerCustomerInfoService.queryListPage(partnerCustomerInfo, page));
//        ShopMallPartners partners = partnerService.shopInfo();
//        partnerCustomerInfo.setPartnerId(partners.getPartnerId());
//        startPage();
//        List<PartnerCustomerInfo> list = partnerCustomerInfoService.selectPartnerCustomerInfoList(partnerCustomerInfo);
//        return getDataTable(list);
    }


    /**
     * 导出客户信息列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, PartnerCustomerInfo partnerCustomerInfo)
    {
        Page<PartnerCustomerInfo> page = new Page<>();
        List<PartnerCustomerInfo> list = partnerCustomerInfoService.selectPartnerCustomerInfoList(partnerCustomerInfo);
        ExcelUtil<PartnerCustomerInfo> util = new ExcelUtil<PartnerCustomerInfo>(PartnerCustomerInfo.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(partnerCustomerInfoService.selectPartnerCustomerInfoById(id));
    }

    /**
     * 新增客户信息
     */

    @PostMapping
    public CommonResult add(@RequestBody PartnerCustomerInfo partnerCustomerInfo) throws Exception {
        return toAjax(partnerCustomerInfoService.insertPartnerCustomerInfo(partnerCustomerInfo));
    }

    /**
     * 修改客户信息
     */

    @PutMapping
    public CommonResult edit(@RequestBody PartnerCustomerInfo partnerCustomerInfo)
    {
        return toAjax(partnerCustomerInfoService.updatePartnerCustomerInfo(partnerCustomerInfo));
    }

    /**
     * 删除客户信息
     */

	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(partnerCustomerInfoService.deletePartnerCustomerInfoByIds(ids));
    }
}
