package com.ruixuan.live.controller;

import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.AjaxResult;
import com.ruixuan.common.core.domain.ResultResponse;
import com.ruixuan.common.core.page.TableDataInfo;
import com.ruixuan.live.entity.KuaishouLiveCustomer;
import com.ruixuan.live.entity.KuaishouLiveCustomerInvoice;
import com.ruixuan.live.service.IKuaishouLiveCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户管理Controller
 *
 * @author ruoyi
 * @date 2022-08-01
 */
@Api(tags = "客户管理")
@RestController
@RequestMapping("/live/customer")
public class KuaishouLiveCustomerController extends BaseController {
    @Autowired
    private IKuaishouLiveCustomerService kuaishouLiveCustomerService;

    /**
     * 查询客户管理列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询客户列表")
    public TableDataInfo list(KuaishouLiveCustomer kuaishouLiveCustomer) {
        startPage();
        List<KuaishouLiveCustomer> list = kuaishouLiveCustomerService.selectKuaishouLiveCustomerList(kuaishouLiveCustomer);
        return getDataTable(list);
    }

    /**
     * 获取客户管理详细信息
     */
    @GetMapping(value = "/queryByKsId")
    @ApiOperation(value = "获取客户管理详细信息")
    public AjaxResult getInfo(@ApiParam("ksid") @RequestParam(value = "ksId", required = true) Long ksId) {
        return AjaxResult.success(kuaishouLiveCustomerService.selectKuaishouLiveCustomerByKsId(ksId));
    }

    /**
     * 新增客户管理
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增客户管理")
    public ResultResponse add(@RequestBody KuaishouLiveCustomer kuaishouLiveCustomer) {
        try {
            return kuaishouLiveCustomerService.insertKuaishouLiveCustomer(kuaishouLiveCustomer);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultResponse.error("新增失败");
    }


    /**
     * 上传发票信息
     */
    @PostMapping(value = "/addInvoice")
    @ApiOperation(value = "上传发票信息")
    public ResultResponse addInvoice(@RequestBody KuaishouLiveCustomerInvoice invoice) {
        try {
            return kuaishouLiveCustomerService.addInvoice(invoice);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultResponse.error("上传失败");
    }

    /**
     * 修改客户管理
     */
    @PostMapping(value = "/edit")
    @ApiOperation(value = "修改客户管理")
    public ResultResponse edit(@RequestBody KuaishouLiveCustomer kuaishouLiveCustomer) {
        try {
            return kuaishouLiveCustomerService.updateKuaishouLiveCustomer(kuaishouLiveCustomer);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultResponse.error("修改失败");
    }

}
