package com.ruoyi.basic.controller; 
 | 
  
 | 
import com.baomidou.mybatisplus.core.metadata.IPage; 
 | 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
 | 
import com.ruoyi.basic.pojo.Customer; 
 | 
import com.ruoyi.basic.service.ICustomerService; 
 | 
import com.ruoyi.common.utils.poi.ExcelUtil; 
 | 
import com.ruoyi.framework.aspectj.lang.annotation.Log; 
 | 
import com.ruoyi.framework.aspectj.lang.enums.BusinessType; 
 | 
import com.ruoyi.framework.web.controller.BaseController; 
 | 
import com.ruoyi.framework.web.domain.AjaxResult; 
 | 
import lombok.AllArgsConstructor; 
 | 
import org.springframework.web.bind.annotation.*; 
 | 
import org.springframework.web.multipart.MultipartFile; 
 | 
  
 | 
import javax.servlet.http.HttpServletResponse; 
 | 
import java.util.List; 
 | 
  
 | 
/** 
 | 
 * 客户档案Controller 
 | 
 * 
 | 
 * @author ruoyi 
 | 
 * @date 2025-05-07 
 | 
 */ 
 | 
@RestController 
 | 
@RequestMapping("/basic/customer") 
 | 
@AllArgsConstructor 
 | 
public class CustomerController extends BaseController { 
 | 
    private ICustomerService customerService; 
 | 
  
 | 
    /** 
 | 
     * 查询客户档案列表 
 | 
     */ 
 | 
    @GetMapping("/list") 
 | 
    public IPage<Customer> list(Page page, Customer customer) { 
 | 
        return customerService.selectCustomerList(page, customer); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 导出客户档案列表 
 | 
     */ 
 | 
    @Log(title = "客户档案", businessType = BusinessType.EXPORT) 
 | 
    @PostMapping("/export") 
 | 
    public void export(HttpServletResponse response, Customer customer) { 
 | 
        Long[] ids = customer.getIds(); 
 | 
        List<Customer> list; 
 | 
        if (ids != null && ids.length > 0) { 
 | 
            list = customerService.selectCustomerListByIds(ids); 
 | 
        } else { 
 | 
            list = customerService.selectCustomerLists(customer); 
 | 
        } 
 | 
        ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class); 
 | 
        util.exportExcel(response, list, "客户档案数据"); 
 | 
    } 
 | 
  
 | 
    @PostMapping("/downloadTemplate") 
 | 
    @Log(title = "客户档案-下载模板", businessType = BusinessType.EXPORT) 
 | 
    public void downloadTemplate(HttpServletResponse response) { 
 | 
        ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class); 
 | 
        util.importTemplateExcel(response, "客户档案模板"); 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 导入客户档案 
 | 
     */ 
 | 
    @Log(title = "客户档案", businessType = BusinessType.IMPORT) 
 | 
    @PostMapping("/importData") 
 | 
    public AjaxResult importData(MultipartFile file) throws Exception { 
 | 
  
 | 
        return customerService.importData(file); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取客户档案详细信息 
 | 
     */ 
 | 
    @GetMapping(value = "/{id}") 
 | 
    public AjaxResult getInfo(@PathVariable("id") Long id) { 
 | 
        return success(customerService.selectCustomerById(id)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 新增客户档案 
 | 
     */ 
 | 
    @Log(title = "客户档案", businessType = BusinessType.INSERT) 
 | 
    @PostMapping("/addCustomer") 
 | 
    public AjaxResult add(@RequestBody Customer customer) { 
 | 
        return toAjax(customerService.insertCustomer(customer)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 修改客户档案 
 | 
     */ 
 | 
    @Log(title = "客户档案", businessType = BusinessType.UPDATE) 
 | 
    @PostMapping("/updateCustomer") 
 | 
    public AjaxResult edit(@RequestBody Customer customer) { 
 | 
        return toAjax(customerService.updateCustomer(customer)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 删除客户档案 
 | 
     */ 
 | 
    @Log(title = "客户档案", businessType = BusinessType.DELETE) 
 | 
    @DeleteMapping("/delCustomer") 
 | 
    public AjaxResult remove(@RequestBody Long[] ids) { 
 | 
        if (ids == null || ids.length == 0) { 
 | 
            return AjaxResult.error("请传入要删除的ID"); 
 | 
        } 
 | 
        return toAjax(customerService.deleteCustomerByIds(ids)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 查询客户 
 | 
     */ 
 | 
    @GetMapping("/customerList") 
 | 
    public List customerList(Customer customer) { 
 | 
        return customerService.customerList(customer); 
 | 
    } 
 | 
} 
 |