|
|
@ -1,137 +1,219 @@
|
|
|
|
package com.yeqifu.bus.controller;
|
|
|
|
package com.yeqifu.bus.controller;
|
|
|
|
|
|
|
|
// 声明类所在的包
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
|
|
|
// 导入QueryWrapper类,用于构建查询条件
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
|
|
|
// 导入IPage接口,用于分页功能
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
|
|
|
// 导入Page类,用于创建分页对象
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.entity.Customer;
|
|
|
|
import com.yeqifu.bus.entity.Customer;
|
|
|
|
|
|
|
|
// 导入Customer实体类,表示客户信息
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.entity.Goods;
|
|
|
|
import com.yeqifu.bus.entity.Goods;
|
|
|
|
|
|
|
|
// 导入Goods实体类,表示商品信息
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.entity.Sales;
|
|
|
|
import com.yeqifu.bus.entity.Sales;
|
|
|
|
|
|
|
|
// 导入Sales实体类,表示销售信息
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.service.ICustomerService;
|
|
|
|
import com.yeqifu.bus.service.ICustomerService;
|
|
|
|
|
|
|
|
// 导入ICustomerService接口,用于处理客户业务逻辑
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.service.IGoodsService;
|
|
|
|
import com.yeqifu.bus.service.IGoodsService;
|
|
|
|
|
|
|
|
// 导入IGoodsService接口,用于处理商品业务逻辑
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.service.ISalesService;
|
|
|
|
import com.yeqifu.bus.service.ISalesService;
|
|
|
|
|
|
|
|
// 导入ISalesService接口,用于处理销售信息的业务逻辑
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.bus.vo.SalesVo;
|
|
|
|
import com.yeqifu.bus.vo.SalesVo;
|
|
|
|
|
|
|
|
// 导入SalesVo类,用于封装查询参数
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.sys.common.DataGridView;
|
|
|
|
import com.yeqifu.sys.common.DataGridView;
|
|
|
|
|
|
|
|
// 导入DataGridView类,用于返回表格数据
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.sys.common.ResultObj;
|
|
|
|
import com.yeqifu.sys.common.ResultObj;
|
|
|
|
|
|
|
|
// 导入ResultObj类,用于统一返回操作结果
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.sys.common.WebUtils;
|
|
|
|
import com.yeqifu.sys.common.WebUtils;
|
|
|
|
|
|
|
|
// 导入WebUtils工具类,用于处理会话信息
|
|
|
|
|
|
|
|
|
|
|
|
import com.yeqifu.sys.entity.User;
|
|
|
|
import com.yeqifu.sys.entity.User;
|
|
|
|
|
|
|
|
// 导入User实体类,表示用户信息
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
// 导入@Autowired注解,用于自动注入服务对象
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
// 导入@RequestMapping注解,用于映射请求路径
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
// 导入@RestController注解,标识该类为REST控制器
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
// 导入Date类,用于处理日期时间
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
// 导入Java集合类List,用于处理列表数据
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* <p>
|
|
|
|
* 商品销售控制器类
|
|
|
|
* InnoDB free: 9216 kB 前端控制器
|
|
|
|
* 负责处理与商品销售信息相关的请求
|
|
|
|
* </p>
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @author luoyi-
|
|
|
|
|
|
|
|
* @since 2019-12-21
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
|
|
|
|
// 标识该类为REST风格的控制器
|
|
|
|
@RequestMapping("/sales")
|
|
|
|
@RequestMapping("/sales")
|
|
|
|
|
|
|
|
// 将类的基础URL路径映射为"/sales"
|
|
|
|
public class SalesController {
|
|
|
|
public class SalesController {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
// 自动注入ISalesService接口的实现类
|
|
|
|
private ISalesService salesService;
|
|
|
|
private ISalesService salesService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
// 自动注入ICustomerService接口的实现类
|
|
|
|
private ICustomerService customerService;
|
|
|
|
private ICustomerService customerService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
// 自动注入IGoodsService接口的实现类
|
|
|
|
private IGoodsService goodsService;
|
|
|
|
private IGoodsService goodsService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询所有商品销售信息
|
|
|
|
* 查询所有商品销售信息
|
|
|
|
* @param salesVo
|
|
|
|
* @param salesVo 封装查询参数的对象
|
|
|
|
* @return
|
|
|
|
* @return 返回表格数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping("loadAllSales")
|
|
|
|
@RequestMapping("loadAllSales")
|
|
|
|
public DataGridView loadAllSales(SalesVo salesVo){
|
|
|
|
// 映射URL路径为"/sales/loadAllSales"
|
|
|
|
IPage<Sales> page = new Page<>(salesVo.getPage(),salesVo.getLimit());
|
|
|
|
public DataGridView loadAllSales(SalesVo salesVo) {
|
|
|
|
QueryWrapper<Sales> queryWrapper = new QueryWrapper<Sales>();
|
|
|
|
IPage<Sales> page = new Page<>(salesVo.getPage(), salesVo.getLimit());
|
|
|
|
//根据客户进行模糊查询
|
|
|
|
// 创建分页对象,指定当前页和每页记录数
|
|
|
|
queryWrapper.eq(salesVo.getCustomerid()!=null&&salesVo.getCustomerid()!=0,"customerid",salesVo.getCustomerid());
|
|
|
|
|
|
|
|
//根据商品模糊查询
|
|
|
|
QueryWrapper<Sales> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq(salesVo.getGoodsid()!=null&&salesVo.getGoodsid()!=0,"goodsid",salesVo.getGoodsid());
|
|
|
|
// 创建QueryWrapper对象,用于构建查询条件
|
|
|
|
//根据时间进行模糊查询
|
|
|
|
|
|
|
|
queryWrapper.ge(salesVo.getStartTime()!=null,"salestime",salesVo.getStartTime());
|
|
|
|
queryWrapper.eq(salesVo.getCustomerid() != null && salesVo.getCustomerid() != 0, "customerid", salesVo.getCustomerid());
|
|
|
|
queryWrapper.le(salesVo.getEndTime()!=null,"salestime",salesVo.getEndTime());
|
|
|
|
// 如果客户ID不为空且不为0,添加客户ID的查询条件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queryWrapper.eq(salesVo.getGoodsid() != null && salesVo.getGoodsid() != 0, "goodsid", salesVo.getGoodsid());
|
|
|
|
|
|
|
|
// 如果商品ID不为空且不为0,添加商品ID的查询条件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queryWrapper.ge(salesVo.getStartTime() != null, "salestime", salesVo.getStartTime());
|
|
|
|
|
|
|
|
// 如果开始时间不为空,添加大于等于开始时间的查询条件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queryWrapper.le(salesVo.getEndTime() != null, "salestime", salesVo.getEndTime());
|
|
|
|
|
|
|
|
// 如果结束时间不为空,添加小于等于结束时间的查询条件
|
|
|
|
|
|
|
|
|
|
|
|
IPage<Sales> page1 = salesService.page(page, queryWrapper);
|
|
|
|
IPage<Sales> page1 = salesService.page(page, queryWrapper);
|
|
|
|
|
|
|
|
// 调用服务层分页查询方法,获取分页数据
|
|
|
|
|
|
|
|
|
|
|
|
List<Sales> records = page1.getRecords();
|
|
|
|
List<Sales> records = page1.getRecords();
|
|
|
|
|
|
|
|
// 获取分页记录列表
|
|
|
|
|
|
|
|
|
|
|
|
for (Sales sales : records) {
|
|
|
|
for (Sales sales : records) {
|
|
|
|
//设置客户姓名
|
|
|
|
// 遍历销售信息列表
|
|
|
|
|
|
|
|
|
|
|
|
Customer customer = customerService.getById(sales.getCustomerid());
|
|
|
|
Customer customer = customerService.getById(sales.getCustomerid());
|
|
|
|
if(null!=customer){
|
|
|
|
// 根据销售信息中的客户ID查询客户信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (null != customer) {
|
|
|
|
sales.setCustomername(customer.getCustomername());
|
|
|
|
sales.setCustomername(customer.getCustomername());
|
|
|
|
|
|
|
|
// 如果客户信息存在,设置客户名称
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//设置商品名称
|
|
|
|
|
|
|
|
Goods goods = goodsService.getById(sales.getGoodsid());
|
|
|
|
Goods goods = goodsService.getById(sales.getGoodsid());
|
|
|
|
if (null!=goods){
|
|
|
|
// 根据销售信息中的商品ID查询商品信息
|
|
|
|
//设置商品名称
|
|
|
|
|
|
|
|
|
|
|
|
if (null != goods) {
|
|
|
|
sales.setGoodsname(goods.getGoodsname());
|
|
|
|
sales.setGoodsname(goods.getGoodsname());
|
|
|
|
//设置商品规格
|
|
|
|
// 如果商品信息存在,设置商品名称
|
|
|
|
|
|
|
|
|
|
|
|
sales.setSize(goods.getSize());
|
|
|
|
sales.setSize(goods.getSize());
|
|
|
|
|
|
|
|
// 设置商品规格
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new DataGridView(page1.getTotal(),page1.getRecords());
|
|
|
|
|
|
|
|
|
|
|
|
return new DataGridView(page1.getTotal(), page1.getRecords());
|
|
|
|
|
|
|
|
// 返回DataGridView对象,包含总记录数和分页记录列表
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 添加商品销售信息
|
|
|
|
* 添加商品销售信息
|
|
|
|
* @param salesVo
|
|
|
|
* @param salesVo 封装销售信息的对象
|
|
|
|
* @return
|
|
|
|
* @return 返回操作结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping("addSales")
|
|
|
|
@RequestMapping("addSales")
|
|
|
|
public ResultObj addSales(SalesVo salesVo){
|
|
|
|
// 映射URL路径为"/sales/addSales"
|
|
|
|
|
|
|
|
public ResultObj addSales(SalesVo salesVo) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//获得当前系统用户
|
|
|
|
|
|
|
|
User user = (User) WebUtils.getSession().getAttribute("user");
|
|
|
|
User user = (User) WebUtils.getSession().getAttribute("user");
|
|
|
|
//设置操作人
|
|
|
|
// 从会话中获取当前系统用户
|
|
|
|
|
|
|
|
|
|
|
|
salesVo.setOperateperson(user.getName());
|
|
|
|
salesVo.setOperateperson(user.getName());
|
|
|
|
//设置销售时间
|
|
|
|
// 设置操作人姓名
|
|
|
|
|
|
|
|
|
|
|
|
salesVo.setSalestime(new Date());
|
|
|
|
salesVo.setSalestime(new Date());
|
|
|
|
|
|
|
|
// 设置销售时间为当前时间
|
|
|
|
|
|
|
|
|
|
|
|
salesService.save(salesVo);
|
|
|
|
salesService.save(salesVo);
|
|
|
|
|
|
|
|
// 调用服务层方法保存销售信息
|
|
|
|
|
|
|
|
|
|
|
|
return ResultObj.ADD_SUCCESS;
|
|
|
|
return ResultObj.ADD_SUCCESS;
|
|
|
|
}catch (Exception e) {
|
|
|
|
// 返回添加成功的结果对象
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
|
|
|
|
return ResultObj.ADD_ERROR;
|
|
|
|
return ResultObj.ADD_ERROR;
|
|
|
|
|
|
|
|
// 返回添加失败的结果对象
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 更新商品销售信息
|
|
|
|
* 更新商品销售信息
|
|
|
|
* @param salesVo
|
|
|
|
* @param salesVo 封装需要更新的销售信息
|
|
|
|
* @return
|
|
|
|
* @return 返回操作结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping("updateSales")
|
|
|
|
@RequestMapping("updateSales")
|
|
|
|
public ResultObj updateSales(SalesVo salesVo){
|
|
|
|
// 映射URL路径为"/sales/updateSales"
|
|
|
|
|
|
|
|
public ResultObj updateSales(SalesVo salesVo) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
salesService.updateById(salesVo);
|
|
|
|
salesService.updateById(salesVo);
|
|
|
|
|
|
|
|
// 调用服务层方法根据ID更新销售信息
|
|
|
|
|
|
|
|
|
|
|
|
return ResultObj.UPDATE_SUCCESS;
|
|
|
|
return ResultObj.UPDATE_SUCCESS;
|
|
|
|
|
|
|
|
// 返回更新成功的结果对象
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
|
|
|
|
return ResultObj.UPDATE_ERROR;
|
|
|
|
return ResultObj.UPDATE_ERROR;
|
|
|
|
|
|
|
|
// 返回更新失败的结果对象
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除商品销售信息
|
|
|
|
* 删除商品销售信息
|
|
|
|
* @param id
|
|
|
|
* @param id 要删除的销售信息ID
|
|
|
|
* @return
|
|
|
|
* @return 返回操作结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping("deleteSales")
|
|
|
|
@RequestMapping("deleteSales")
|
|
|
|
public ResultObj deleteSales(Integer id){
|
|
|
|
// 映射URL路径为"/sales/deleteSales"
|
|
|
|
|
|
|
|
public ResultObj deleteSales(Integer id) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
salesService.removeById(id);
|
|
|
|
salesService.removeById(id);
|
|
|
|
|
|
|
|
// 调用服务层方法根据ID删除销售信息
|
|
|
|
|
|
|
|
|
|
|
|
return ResultObj.DELETE_SUCCESS;
|
|
|
|
return ResultObj.DELETE_SUCCESS;
|
|
|
|
|
|
|
|
// 返回删除成功的结果对象
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
// 打印异常信息
|
|
|
|
|
|
|
|
|
|
|
|
return ResultObj.DELETE_ERROR;
|
|
|
|
return ResultObj.DELETE_ERROR;
|
|
|
|
|
|
|
|
// 返回删除失败的结果对象
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|