107 lines
3.6 KiB
Java
107 lines
3.6 KiB
Java
package com.bycrm.controller;
|
|
|
|
import com.bycrm.common.PageResult;
|
|
import com.bycrm.common.Result;
|
|
import com.bycrm.dto.CustomerDTO;
|
|
import com.bycrm.dto.PageQuery;
|
|
import com.bycrm.entity.Customer;
|
|
import com.bycrm.service.CustomerService;
|
|
import com.bycrm.vo.CustomerVO;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiParam;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 客户控制器
|
|
*/
|
|
@Api(tags = "客户管理")
|
|
@RestController
|
|
@RequestMapping("/customer")
|
|
public class CustomerController {
|
|
|
|
private final CustomerService customerService;
|
|
|
|
public CustomerController(CustomerService customerService) {
|
|
this.customerService = customerService;
|
|
}
|
|
|
|
/**
|
|
* 分页查询客户
|
|
*/
|
|
@ApiOperation("分页查询客户")
|
|
@GetMapping("/page")
|
|
public Result<PageResult<CustomerVO>> getCustomerPage(
|
|
@ApiParam("当前页") @RequestParam(defaultValue = "1") Long current,
|
|
@ApiParam("每页大小") @RequestParam(defaultValue = "10") Long size,
|
|
@ApiParam("客户名称") @RequestParam(required = false) String name,
|
|
@ApiParam("所属行业") @RequestParam(required = false) String industry,
|
|
@ApiParam("状态") @RequestParam(required = false) Integer status) {
|
|
PageQuery query = new PageQuery();
|
|
query.setCurrent(current);
|
|
query.setSize(size);
|
|
|
|
PageResult<CustomerVO> result = customerService.getCustomerPage(query, name, industry, status);
|
|
return Result.success(result);
|
|
}
|
|
|
|
/**
|
|
* 根据ID获取客户详情
|
|
*/
|
|
@ApiOperation("根据ID获取客户详情")
|
|
@GetMapping("/{id}")
|
|
public Result<CustomerVO> getCustomerById(@ApiParam("客户ID") @PathVariable Long id) {
|
|
CustomerVO customer = customerService.getCustomerById(id);
|
|
return Result.success(customer);
|
|
}
|
|
|
|
/**
|
|
* 创建客户
|
|
*/
|
|
@ApiOperation("创建客户")
|
|
@PostMapping
|
|
public Result<Customer> createCustomer(@RequestBody CustomerDTO customerDTO, HttpServletRequest request) {
|
|
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
|
Customer customer = customerService.createCustomer(customerDTO, currentUserId);
|
|
return Result.success(customer);
|
|
}
|
|
|
|
/**
|
|
* 更新客户
|
|
*/
|
|
@ApiOperation("更新客户")
|
|
@PutMapping("/{id}")
|
|
public Result<Void> updateCustomer(
|
|
@ApiParam("客户ID") @PathVariable Long id,
|
|
@RequestBody CustomerDTO customerDTO,
|
|
HttpServletRequest request) {
|
|
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
|
customerService.updateCustomer(id, customerDTO, currentUserId);
|
|
return Result.success();
|
|
}
|
|
|
|
/**
|
|
* 删除客户
|
|
*/
|
|
@ApiOperation("删除客户")
|
|
@DeleteMapping("/{id}")
|
|
public Result<Void> deleteCustomer(@ApiParam("客户ID") @PathVariable Long id, HttpServletRequest request) {
|
|
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
|
customerService.deleteCustomer(id, currentUserId);
|
|
return Result.success();
|
|
}
|
|
|
|
/**
|
|
* 根据名称搜索客户(用于客户唯一性校验)
|
|
*/
|
|
@ApiOperation("根据名称搜索客户")
|
|
@GetMapping("/search")
|
|
public Result<List<Customer>> searchByName(@ApiParam("客户名称") @RequestParam String name) {
|
|
List<Customer> customers = customerService.searchByName(name);
|
|
return Result.success(customers);
|
|
}
|
|
}
|