package com.fjhx.customer.controller.customer;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.customer.entity.customer.dto.CustomerDto;
import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
import com.fjhx.customer.entity.customer.vo.CustomerVo;
import com.fjhx.customer.service.customer.CustomerService;
import com.ruoyi.common.core.domain.BaseSelectDto;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;

import java.util.Map;

/**
 * <p>
 * 客户表 前端控制器
 * </p>
 *
 * @author
 * @since 2023-04-04
 */
@DS(SourceConstant.CUSTOMER)
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 客户表分页
     */
    @PostMapping("/page")
    public Page<CustomerVo> page(@RequestBody CustomerSelectDto dto) {
        return customerService.getPage(dto);
    }

    /**
     * 私海客户表分页（添加权限自己看自己）
     */
    @PostMapping("/privateSeaPage")
    public Page<CustomerVo> privateSeaPage(@RequestBody CustomerSelectDto dto) {
        dto.setUserId(SecurityUtils.getUserId());
        return customerService.getPage(dto);
    }

    /**
     * 客户表明细
     */
    @PostMapping("/detail")
    public CustomerVo detail(@RequestBody BaseSelectDto dto) {
        return customerService.detail(dto.getId());
    }

    /**
     * 客户表新增
     */
    @PostMapping("/add")
    public void add(@RequestBody CustomerDto customerDto) {
        customerService.add(customerDto);
    }

    /**
     * 客户表编辑
     */
    @PostMapping("/edit")
    public void edit(@RequestBody CustomerDto customerDto) {
        customerService.edit(customerDto);
    }

    /**
     * 客户表删除
     */
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        customerService.delete(dto.getId());
    }


    /**
     * 客户分配
     */
    @PostMapping("/CustomerAllocation")
    public void customerAllocation(@RequestBody CustomerDto dto) {
        customerService.customerAllocation(dto);
    }

    /**
     * 修改客户标签
     */
    @PostMapping("/editTag")
    public void editTag(@RequestBody CustomerDto customerDto) {
        customerService.editTag(customerDto);
    }

    /**
     * 客户来源统计
     */
    @PostMapping("/sourceStatistics")
    public Map<String,Object> sourceStatistics(@RequestBody  CustomerSelectDto  customerDto){
        return customerService.sourceStatistics(customerDto);
    }

}
