You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
5.0 KiB
124 lines
5.0 KiB
package 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; // 客户实体类
|
|
import com.yeqifu.bus.entity.Goods; // 商品实体类
|
|
import com.yeqifu.bus.entity.Salesback; // 销售退货实体类
|
|
import com.yeqifu.bus.service.ICustomerService; // 客户服务接口
|
|
import com.yeqifu.bus.service.IGoodsService; // 商品服务接口
|
|
import com.yeqifu.bus.service.ISalesbackService; // 销售退货服务接口
|
|
import com.yeqifu.bus.vo.SalesbackVo; // 销售退货请求参数封装类
|
|
import com.yeqifu.sys.common.DataGridView; // 封装表格数据类
|
|
import com.yeqifu.sys.common.ResultObj; // 操作结果封装类
|
|
import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解
|
|
import org.springframework.web.bind.annotation.RequestMapping; // 请求映射注解
|
|
import org.springframework.web.bind.annotation.RestController; // RESTful 控制器注解
|
|
|
|
import java.util.List; // 集合类
|
|
|
|
/**
|
|
* 销售退货管理前端控制器
|
|
* 提供销售退货的增删改查功能
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/salesback") // 定义接口基础路径
|
|
public class SalesbackController {
|
|
|
|
@Autowired
|
|
private ISalesbackService salesbackService; // 自动注入销售退货服务
|
|
|
|
@Autowired
|
|
private ICustomerService customerService; // 自动注入客户服务
|
|
|
|
@Autowired
|
|
private IGoodsService goodsService; // 自动注入商品服务
|
|
|
|
/**
|
|
* 添加销售退货信息
|
|
* @param id 销售单ID
|
|
* @param number 退货数量
|
|
* @param remark 备注
|
|
* @return 操作结果
|
|
*/
|
|
@RequestMapping("addSalesback")
|
|
public ResultObj addSalesback(Integer id, Integer number, String remark) {
|
|
try {
|
|
// 调用销售退货服务,处理退货
|
|
salesbackService.addSalesback(id, number, remark);
|
|
return ResultObj.BACKINPORT_SUCCESS; // 返回成功结果
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return ResultObj.BACKINPORT_ERROR; // 返回失败结果
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 查询商品销售退货信息
|
|
* @param salesbackVo 包含查询条件和分页参数
|
|
* @return 分页后的销售退货数据
|
|
*/
|
|
@RequestMapping("loadAllSalesback")
|
|
public DataGridView loadAllSalesback(SalesbackVo salesbackVo) {
|
|
// 1. 声明分页对象
|
|
IPage<Salesback> page = new Page<>(salesbackVo.getPage(), salesbackVo.getLimit());
|
|
// 2. 创建查询条件构造器
|
|
QueryWrapper<Salesback> queryWrapper = new QueryWrapper<>();
|
|
// 3. 根据客户ID进行查询
|
|
queryWrapper.eq(salesbackVo.getCustomerid() != null && salesbackVo.getCustomerid() != 0, "customerid", salesbackVo.getCustomerid());
|
|
// 4. 根据商品ID进行查询
|
|
queryWrapper.eq(salesbackVo.getGoodsid() != null && salesbackVo.getGoodsid() != 0, "goodsid", salesbackVo.getGoodsid());
|
|
// 5. 根据时间范围进行查询
|
|
queryWrapper.ge(salesbackVo.getStartTime() != null, "salesbacktime", salesbackVo.getStartTime());
|
|
queryWrapper.le(salesbackVo.getEndTime() != null, "salesbacktime", salesbackVo.getEndTime());
|
|
// 6. 根据销售退货时间降序排序
|
|
queryWrapper.orderByDesc("salesbacktime");
|
|
|
|
// 7. 执行分页查询
|
|
salesbackService.page(page, queryWrapper);
|
|
|
|
// 8. 获取查询结果
|
|
List<Salesback> records = page.getRecords();
|
|
// 9. 填充客户和商品信息
|
|
for (Salesback salesback : records) {
|
|
System.out.println("============================");
|
|
// 查询客户信息
|
|
Customer customer = customerService.getById(salesback.getCustomerid());
|
|
if (customer != null) {
|
|
// 设置客户姓名
|
|
salesback.setCustomername(customer.getCustomername());
|
|
}
|
|
// 查询商品信息
|
|
Goods goods = goodsService.getById(salesback.getGoodsid());
|
|
if (goods != null) {
|
|
// 设置商品名称和规格
|
|
salesback.setGoodsname(goods.getGoodsname());
|
|
salesback.setSize(goods.getSize());
|
|
}
|
|
}
|
|
|
|
// 10. 返回分页结果
|
|
return new DataGridView(page.getTotal(), page.getRecords());
|
|
}
|
|
|
|
/**
|
|
* 删除商品销售退货信息
|
|
* @param id 销售退货ID
|
|
* @return 操作结果
|
|
*/
|
|
@RequestMapping("deleteSalesback")
|
|
public ResultObj deleteSalesback(Integer id) {
|
|
try {
|
|
// 调用销售退货服务,删除记录
|
|
salesbackService.removeById(id);
|
|
return ResultObj.DELETE_SUCCESS; // 返回成功结果
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return ResultObj.DELETE_ERROR; // 返回失败结果
|
|
}
|
|
}
|
|
|
|
}
|
|
|