|
|
|
@ -1,25 +1,24 @@
|
|
|
|
|
package com.yeqifu.bus.controller;
|
|
|
|
|
package com.yeqifu.bus.controller; // 定义包路径
|
|
|
|
|
|
|
|
|
|
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; // 导入Swagger参数注解
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams; // 导入Swagger参数列表注解
|
|
|
|
|
import io.swagger.annotations.ApiOperation; // 导入Swagger操作注解
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; // 导入字符串工具类
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的依赖注入注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; // 导入请求映射注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; // 导入请求方法注解
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; // 导入控制器注解
|
|
|
|
|
|
|
|
|
|
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; // 导入列表类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
@ -29,29 +28,27 @@ import java.util.List;
|
|
|
|
|
* @author luoyi-
|
|
|
|
|
* @since 2019-12-05
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/customer")
|
|
|
|
|
@RestController // 标注为REST控制器
|
|
|
|
|
@RequestMapping("/customer") // 设置请求路径为/customer
|
|
|
|
|
public class CustomerController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ICustomerService customerService;
|
|
|
|
|
@Autowired // 自动注入客户服务接口实现类
|
|
|
|
|
private ICustomerService customerService; // 定义客户服务接口实例
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有的客户
|
|
|
|
|
* @param customerVo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("loadAllCustomer")
|
|
|
|
|
public DataGridView loadAllCustomer(CustomerVo customerVo){
|
|
|
|
|
//1.声明分页page对象
|
|
|
|
|
IPage<Customer> page = new Page<Customer>(customerVo.getPage(),customerVo.getLimit());
|
|
|
|
|
//2.声明queryWrapper
|
|
|
|
|
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());
|
|
|
|
|
@RequestMapping("loadAllCustomer") // 映射路径为/loadAllCustomer
|
|
|
|
|
public DataGridView loadAllCustomer(CustomerVo customerVo){ // 查询所有客户方法
|
|
|
|
|
IPage<Customer> page = new Page<Customer>(customerVo.getPage(),customerVo.getLimit()); // 声明分页对象
|
|
|
|
|
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()); // 返回分页数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -59,14 +56,14 @@ public class CustomerController {
|
|
|
|
|
* @param customerVo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("addCustomer")
|
|
|
|
|
public ResultObj addCustomer(CustomerVo customerVo){
|
|
|
|
|
@RequestMapping("addCustomer") // 映射路径为/addCustomer
|
|
|
|
|
public ResultObj addCustomer(CustomerVo customerVo){ // 添加客户方法
|
|
|
|
|
try {
|
|
|
|
|
customerService.save(customerVo);
|
|
|
|
|
return ResultObj.ADD_SUCCESS;
|
|
|
|
|
customerService.save(customerVo); // 保存客户数据
|
|
|
|
|
return ResultObj.ADD_SUCCESS; // 返回添加成功结果
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultObj.ADD_ERROR;
|
|
|
|
|
e.printStackTrace(); // 打印异常堆栈信息
|
|
|
|
|
return ResultObj.ADD_ERROR; // 返回添加失败结果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -75,14 +72,14 @@ public class CustomerController {
|
|
|
|
|
* @param customerVo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("updateCustomer")
|
|
|
|
|
public ResultObj updateCustomer(CustomerVo customerVo){
|
|
|
|
|
@RequestMapping("updateCustomer") // 映射路径为/updateCustomer
|
|
|
|
|
public ResultObj updateCustomer(CustomerVo customerVo){ // 修改客户方法
|
|
|
|
|
try {
|
|
|
|
|
customerService.updateById(customerVo);
|
|
|
|
|
return ResultObj.UPDATE_SUCCESS;
|
|
|
|
|
customerService.updateById(customerVo); // 根据ID更新客户数据
|
|
|
|
|
return ResultObj.UPDATE_SUCCESS; // 返回更新成功结果
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultObj.UPDATE_ERROR;
|
|
|
|
|
e.printStackTrace(); // 打印异常堆栈信息
|
|
|
|
|
return ResultObj.UPDATE_ERROR; // 返回更新失败结果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -91,31 +88,29 @@ public class CustomerController {
|
|
|
|
|
* @param id 客户的ID
|
|
|
|
|
* @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 = "删除一个客户") // Swagger注解,描述操作内容
|
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "客户ID",required = true,paramType = "query",dataType = "Integer")}) // Swagger注解,描述参数信息
|
|
|
|
|
@RequestMapping(value = "deleteCustomer",method = RequestMethod.DELETE) // 映射路径为/deleteCustomer,方法为DELETE
|
|
|
|
|
public ResultObj deleteCustomer(Integer id){ // 删除客户方法
|
|
|
|
|
try {
|
|
|
|
|
customerService.deleteCustomerById(id);
|
|
|
|
|
return ResultObj.DELETE_SUCCESS;
|
|
|
|
|
customerService.deleteCustomerById(id); // 调用服务删除客户
|
|
|
|
|
return ResultObj.DELETE_SUCCESS; // 返回删除成功结果
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultObj.DELETE_ERROR;
|
|
|
|
|
e.printStackTrace(); // 打印异常堆栈信息
|
|
|
|
|
return ResultObj.DELETE_ERROR; // 返回删除失败结果
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载所有客户的下拉列表
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("loadAllCustomerForSelect")
|
|
|
|
|
public DataGridView loadAllCustomerForSelect(){
|
|
|
|
|
QueryWrapper<Customer> queryWrapper = new QueryWrapper<Customer>();
|
|
|
|
|
queryWrapper.eq("available", Constast.AVAILABLE_TRUE);
|
|
|
|
|
List<Customer> list = customerService.list(queryWrapper);
|
|
|
|
|
return new DataGridView(list);
|
|
|
|
|
@RequestMapping("loadAllCustomerForSelect") // 映射路径为/loadAllCustomerForSelect
|
|
|
|
|
public DataGridView loadAllCustomerForSelect(){ // 加载客户下拉列表方法
|
|
|
|
|
QueryWrapper<Customer> queryWrapper = new QueryWrapper<Customer>(); // 声明查询包装器
|
|
|
|
|
queryWrapper.eq("available", Constast.AVAILABLE_TRUE); // 查询可用客户数据
|
|
|
|
|
List<Customer> list = customerService.list(queryWrapper); // 获取客户列表
|
|
|
|
|
return new DataGridView(list); // 返回客户数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|