|
|
|
|
@ -1,119 +1,129 @@
|
|
|
|
|
package com.yeqifu.bus.controller;
|
|
|
|
|
package com.yeqifu.bus.controller; // 定义包名,表示该类属于com.yeqifu.bus.controller包
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; // 导入MyBatis-Plus的查询条件构造器
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; // 导入MyBatis-Plus的分页接口
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; // 导入MyBatis-Plus的分页实现类
|
|
|
|
|
import com.yeqifu.bus.entity.Customer; // 导入Customer实体类
|
|
|
|
|
import com.yeqifu.bus.service.ICustomerService; // 导入Customer服务接口
|
|
|
|
|
import com.yeqifu.bus.vo.CustomerVo; // 导入CustomerVo类,用于封装请求参数
|
|
|
|
|
import com.yeqifu.sys.common.Constast; // 导入常量类
|
|
|
|
|
import com.yeqifu.sys.common.DataGridView; // 导入DataGridView类,用于封装数据表格响应
|
|
|
|
|
import com.yeqifu.sys.common.ResultObj; // 导入ResultObj类,用于封装操作结果
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam; // 导入Swagger的注解,用于描述API参数
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams; // 导入Swagger的注解,用于描述多个API参数
|
|
|
|
|
import io.swagger.annotations.ApiOperation; // 导入Swagger的注解,用于描述API操作
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; // 导入Apache Commons Lang工具类,用于字符串操作
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的@Autowired注解,用于自动注入依赖
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; // 导入Spring的RequestMapping注解,用于映射请求路径
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; // 导入Spring的RequestMethod枚举,用于指定HTTP方法
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; // 导入Spring的RestController注解,用于标记Restful控制器
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.yeqifu.bus.entity.Customer;
|
|
|
|
|
import com.yeqifu.bus.service.ICustomerService;
|
|
|
|
|
import com.yeqifu.bus.vo.CustomerVo;
|
|
|
|
|
import com.yeqifu.sys.common.Constast;
|
|
|
|
|
import com.yeqifu.sys.common.DataGridView;
|
|
|
|
|
import com.yeqifu.sys.common.ResultObj;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.List; // 导入Java的List接口
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
* InnoDB free: 9216 kB 前端控制器
|
|
|
|
|
* </p>
|
|
|
|
|
*
|
|
|
|
|
* 客户管理的前端控制器
|
|
|
|
|
* 提供客户相关的增删改查和下拉列表功能
|
|
|
|
|
* @author luoyi-
|
|
|
|
|
* @since 2019-12-05
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/customer")
|
|
|
|
|
@RestController // 标记为RestController,返回的数据将直接作为HTTP响应体
|
|
|
|
|
@RequestMapping("/customer") // 定义类级别的请求路径前缀为"/customer"
|
|
|
|
|
public class CustomerController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
@Autowired // 自动注入Customer服务接口的实现类
|
|
|
|
|
private ICustomerService customerService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有的客户
|
|
|
|
|
* @param customerVo
|
|
|
|
|
* @return
|
|
|
|
|
* 查询所有的客户并返回分页数据
|
|
|
|
|
* @param customerVo 封装查询条件和分页参数
|
|
|
|
|
* @return DataGridView 包含总记录数和客户数据列表
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("loadAllCustomer")
|
|
|
|
|
public DataGridView loadAllCustomer(CustomerVo customerVo){
|
|
|
|
|
//1.声明分页page对象
|
|
|
|
|
IPage<Customer> page = new Page<Customer>(customerVo.getPage(),customerVo.getLimit());
|
|
|
|
|
//2.声明queryWrapper
|
|
|
|
|
@RequestMapping("loadAllCustomer") // 映射请求路径为"customer/loadAllCustomer"
|
|
|
|
|
public DataGridView loadAllCustomer(CustomerVo customerVo) {
|
|
|
|
|
// 1. 创建分页对象,传入当前页码和每页显示条数
|
|
|
|
|
IPage<Customer> page = new Page<Customer>(customerVo.getPage(), customerVo.getLimit());
|
|
|
|
|
// 2. 创建查询条件构造器对象
|
|
|
|
|
QueryWrapper<Customer> queryWrapper = new QueryWrapper<Customer>();
|
|
|
|
|
queryWrapper.like(StringUtils.isNotBlank(customerVo.getCustomername()),"customername",customerVo.getCustomername());
|
|
|
|
|
queryWrapper.like(StringUtils.isNotBlank(customerVo.getConnectionpersion()),"connectionpersion",customerVo.getConnectionpersion());
|
|
|
|
|
queryWrapper.like(StringUtils.isNotBlank(customerVo.getPhone()),"phone",customerVo.getPhone());
|
|
|
|
|
customerService.page(page,queryWrapper);
|
|
|
|
|
return new DataGridView(page.getTotal(),page.getRecords());
|
|
|
|
|
// 根据客户名称模糊查询(如果输入了客户名称)
|
|
|
|
|
queryWrapper.like(StringUtils.isNotBlank(customerVo.getCustomername()), "customername", customerVo.getCustomername());
|
|
|
|
|
// 根据联系人模糊查询(如果输入了联系人)
|
|
|
|
|
queryWrapper.like(StringUtils.isNotBlank(customerVo.getConnectionpersion()), "connectionpersion", customerVo.getConnectionpersion());
|
|
|
|
|
// 根据电话号码模糊查询(如果输入了电话号码)
|
|
|
|
|
queryWrapper.like(StringUtils.isNotBlank(customerVo.getPhone()), "phone", customerVo.getPhone());
|
|
|
|
|
// 执行分页查询
|
|
|
|
|
customerService.page(page, queryWrapper);
|
|
|
|
|
// 返回DataGridView对象,包含总记录数和客户记录列表
|
|
|
|
|
return new DataGridView(page.getTotal(), page.getRecords());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加一个客户
|
|
|
|
|
* @param customerVo
|
|
|
|
|
* @return
|
|
|
|
|
* @param customerVo 封装客户信息
|
|
|
|
|
* @return 操作结果对象
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("addCustomer")
|
|
|
|
|
public ResultObj addCustomer(CustomerVo customerVo){
|
|
|
|
|
@RequestMapping("addCustomer") // 映射请求路径为"customer/addCustomer"
|
|
|
|
|
public ResultObj addCustomer(CustomerVo customerVo) {
|
|
|
|
|
try {
|
|
|
|
|
// 调用服务保存客户
|
|
|
|
|
customerService.save(customerVo);
|
|
|
|
|
return ResultObj.ADD_SUCCESS;
|
|
|
|
|
return ResultObj.ADD_SUCCESS; // 返回添加成功的结果
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultObj.ADD_ERROR;
|
|
|
|
|
e.printStackTrace(); // 打印异常信息
|
|
|
|
|
return ResultObj.ADD_ERROR; // 返回添加失败的结果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改一个客户
|
|
|
|
|
* @param customerVo
|
|
|
|
|
* @return
|
|
|
|
|
* @param customerVo 封装客户信息
|
|
|
|
|
* @return 操作结果对象
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("updateCustomer")
|
|
|
|
|
public ResultObj updateCustomer(CustomerVo customerVo){
|
|
|
|
|
@RequestMapping("updateCustomer") // 映射请求路径为"customer/updateCustomer"
|
|
|
|
|
public ResultObj updateCustomer(CustomerVo customerVo) {
|
|
|
|
|
try {
|
|
|
|
|
// 调用服务更新客户信息
|
|
|
|
|
customerService.updateById(customerVo);
|
|
|
|
|
return ResultObj.UPDATE_SUCCESS;
|
|
|
|
|
return ResultObj.UPDATE_SUCCESS; // 返回更新成功的结果
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultObj.UPDATE_ERROR;
|
|
|
|
|
e.printStackTrace(); // 打印异常信息
|
|
|
|
|
return ResultObj.UPDATE_ERROR; // 返回更新失败的结果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除一个客户
|
|
|
|
|
* @param id 客户的ID
|
|
|
|
|
* @return
|
|
|
|
|
* @return 操作结果对象
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "删除一个客户",notes = "删除一个客户")
|
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "客户ID",required = true,paramType = "query",dataType = "Integer")})
|
|
|
|
|
@RequestMapping(value = "deleteCustomer",method = RequestMethod.DELETE)
|
|
|
|
|
public ResultObj deleteCustomer(Integer id){
|
|
|
|
|
@ApiOperation(value = "删除一个客户", notes = "根据ID删除指定客户") // Swagger注解,描述API功能
|
|
|
|
|
@ApiImplicitParams({ // Swagger注解,描述API参数
|
|
|
|
|
@ApiImplicitParam(name = "id", value = "客户ID", required = true, paramType = "query", dataType = "Integer")
|
|
|
|
|
})
|
|
|
|
|
@RequestMapping(value = "deleteCustomer", method = RequestMethod.DELETE) // 映射请求路径为"customer/deleteCustomer",指定HTTP方法为DELETE
|
|
|
|
|
public ResultObj deleteCustomer(Integer id) {
|
|
|
|
|
try {
|
|
|
|
|
// 调用服务根据ID删除客户
|
|
|
|
|
customerService.deleteCustomerById(id);
|
|
|
|
|
return ResultObj.DELETE_SUCCESS;
|
|
|
|
|
return ResultObj.DELETE_SUCCESS; // 返回删除成功的结果
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultObj.DELETE_ERROR;
|
|
|
|
|
e.printStackTrace(); // 打印异常信息
|
|
|
|
|
return ResultObj.DELETE_ERROR; // 返回删除失败的结果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载所有客户的下拉列表
|
|
|
|
|
* @return
|
|
|
|
|
* 加载所有客户的下拉列表数据
|
|
|
|
|
* @return DataGridView 包含所有可用客户的列表
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("loadAllCustomerForSelect")
|
|
|
|
|
public DataGridView loadAllCustomerForSelect(){
|
|
|
|
|
@RequestMapping("loadAllCustomerForSelect") // 映射请求路径为"customer/loadAllCustomerForSelect"
|
|
|
|
|
public DataGridView loadAllCustomerForSelect() {
|
|
|
|
|
// 创建查询条件构造器
|
|
|
|
|
QueryWrapper<Customer> queryWrapper = new QueryWrapper<Customer>();
|
|
|
|
|
// 添加条件:客户状态为可用
|
|
|
|
|
queryWrapper.eq("available", Constast.AVAILABLE_TRUE);
|
|
|
|
|
// 查询所有满足条件的客户
|
|
|
|
|
List<Customer> list = customerService.list(queryWrapper);
|
|
|
|
|
// 返回DataGridView对象,包含客户列表
|
|
|
|
|
return new DataGridView(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|