首页>代码>springboot2+mybatis+thymeleaf+layui整合开发物流仓库后台管理系统>/src/main/java/com/dev/warehouse/bus/controller/CustomerController.java
package com.dev.warehouse.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.dev.warehouse.bus.entity.Customer;
import com.dev.warehouse.bus.service.ICustomerService;
import com.dev.warehouse.bus.vo.CustomerVo;
import com.dev.warehouse.sys.common.Constast;
import com.dev.warehouse.sys.common.DataGridView;
import com.dev.warehouse.sys.common.ResultObj;
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.RestController;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@RestController
@RequestMapping("/customer")
public class CustomerController {
@Autowired
private ICustomerService customerService;
/**
* 查询所有的客户
* @param customerVo
* @return
*/
@RequestMapping("loadAllCustomer")
public DataGridView loadAllCustomer(CustomerVo customerVo){
//1.声明一个分页page对象
IPage<Customer> page = new Page(customerVo.getPage(),customerVo.getLimit());
//2.声明一个queryWrapper
QueryWrapper<Customer> queryWrapper = new QueryWrapper();
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());
}
/**
* 添加一个客户
* @param customerVo
* @return
*/
@RequestMapping("addCustomer")
public ResultObj addCustomer(CustomerVo customerVo){
try {
customerService.save(customerVo);
return ResultObj.ADD_SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ResultObj.ADD_ERROR;
}
}
/**
* 修改一个客户
* @param customerVo
* @return
*/
@RequestMapping("updateCustomer")
public ResultObj updateCustomer(CustomerVo customerVo){
try {
customerService.updateById(customerVo);
return ResultObj.UPDATE_SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ResultObj.UPDATE_ERROR;
}
}
/**
* 删除一个客户
* @param id 客户的ID
* @return
*/
@RequestMapping("deleteCustomer")
public ResultObj deleteCustomer(Integer id){
try {
customerService.removeById(id);
return ResultObj.DELETE_SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ResultObj.DELETE_ERROR;
}
}
/**
* 批量删除客户
* @param customerVo 选中的客户
* @return
*/
@RequestMapping("batchDeleteCustomer")
public ResultObj batchDeleteCustomer(CustomerVo customerVo){
try {
Collection<Serializable> idList = new ArrayList<Serializable>();
for (Integer id : customerVo.getIds()) {
idList.add(id);
}
customerService.removeByIds(idList);
return ResultObj.DELETE_SUCCESS;
} catch (Exception e) {
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);
}
}
最近下载更多
hubugai1 LV11
4月24日
sshiqi LV2
2024年12月12日
haomc052829 LV4
2024年12月3日
微信网友_6377331253415936 LV3
2024年11月15日
微信网友_7134912998903808 LV15
2024年9月2日
gnnhka LV10
2024年7月8日
tt867309 LV1
2024年7月7日
TY0165 LV20
2024年6月23日
胡闹的番茄精 LV2
2024年6月17日
heweimin LV13
2024年5月20日
最近浏览更多
青丘忆尘
9月10日
暂无贡献等级
微信网友_7648434064986112
8月20日
暂无贡献等级
myl227
7月21日
暂无贡献等级
andywahaha1 LV1
7月14日
limufu LV1
6月17日
微信网友_7534422160363520
5月31日
暂无贡献等级
2225906816
5月26日
暂无贡献等级
lkke23047 LV1
5月26日
sk123456
4月11日
暂无贡献等级
DanBMZ
3月27日
暂无贡献等级

