@ -1,116 +1,123 @@
|
||||
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 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.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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.List; // 集合类
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* InnoDB free: 9216 kB 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author luoyi-
|
||||
* @since 2019-12-23
|
||||
* 销售退货管理前端控制器
|
||||
* 提供销售退货的增删改查功能
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/salesback")
|
||||
@RequestMapping("/salesback") // 定义接口基础路径
|
||||
public class SalesbackController {
|
||||
|
||||
@Autowired
|
||||
private ISalesbackService salesbackService;
|
||||
private ISalesbackService salesbackService; // 自动注入销售退货服务
|
||||
|
||||
@Autowired
|
||||
private ICustomerService customerService;
|
||||
private ICustomerService customerService; // 自动注入客户服务
|
||||
|
||||
@Autowired
|
||||
private IGoodsService goodsService;
|
||||
private IGoodsService goodsService; // 自动注入商品服务
|
||||
|
||||
/**
|
||||
* 添加退货信息
|
||||
* @param id 进货单ID
|
||||
* 添加销售退货信息
|
||||
* @param id 销售单ID
|
||||
* @param number 退货数量
|
||||
* @param remark 备注
|
||||
* @return
|
||||
* @return 操作结果
|
||||
*/
|
||||
@RequestMapping("addSalesback")
|
||||
public ResultObj addSalesback(Integer id,Integer number,String remark){
|
||||
public ResultObj addSalesback(Integer id, Integer number, String remark) {
|
||||
try {
|
||||
salesbackService.addSalesback(id,number,remark);
|
||||
return ResultObj.BACKINPORT_SUCCESS;
|
||||
// 调用销售退货服务,处理退货
|
||||
salesbackService.addSalesback(id, number, remark);
|
||||
return ResultObj.BACKINPORT_SUCCESS; // 返回成功结果
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResultObj.BACKINPORT_ERROR;
|
||||
return ResultObj.BACKINPORT_ERROR; // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品销售退货
|
||||
* @param salesbackVo
|
||||
* @return
|
||||
* 查询商品销售退货信息
|
||||
* @param salesbackVo 包含查询条件和分页参数
|
||||
* @return 分页后的销售退货数据
|
||||
*/
|
||||
@RequestMapping("loadAllSalesback")
|
||||
public DataGridView loadAllSalesback(SalesbackVo salesbackVo){
|
||||
IPage<Salesback> page = new Page<Salesback>(salesbackVo.getPage(),salesbackVo.getLimit());
|
||||
QueryWrapper<Salesback> queryWrapper = new QueryWrapper<Salesback>();
|
||||
//对客户进行查询
|
||||
queryWrapper.eq(salesbackVo.getCustomerid()!=null&&salesbackVo.getCustomerid()!=0,"customerid",salesbackVo.getCustomerid());
|
||||
//对商品进行查询
|
||||
queryWrapper.eq(salesbackVo.getGoodsid()!=null&&salesbackVo.getGoodsid()!=0,"goodsid",salesbackVo.getGoodsid());
|
||||
//对时间进行查询要求大于开始时间小于结束时间
|
||||
queryWrapper.ge(salesbackVo.getStartTime()!=null,"salesbacktime",salesbackVo.getStartTime());
|
||||
queryWrapper.le(salesbackVo.getEndTime()!=null,"salesbacktime",salesbackVo.getEndTime());
|
||||
//通过商品退货时间对商品进行排序
|
||||
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){
|
||||
//设置客户姓名
|
||||
if (customer != null) {
|
||||
// 设置客户姓名
|
||||
salesback.setCustomername(customer.getCustomername());
|
||||
}
|
||||
// 查询商品信息
|
||||
Goods goods = goodsService.getById(salesback.getGoodsid());
|
||||
if (goods!=null){
|
||||
//设置商品名称
|
||||
if (goods != null) {
|
||||
// 设置商品名称和规格
|
||||
salesback.setGoodsname(goods.getGoodsname());
|
||||
//设置商品规格
|
||||
salesback.setSize(goods.getSize());
|
||||
}
|
||||
}
|
||||
return new DataGridView(page.getTotal(),page.getRecords());
|
||||
|
||||
// 10. 返回分页结果
|
||||
return new DataGridView(page.getTotal(), page.getRecords());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品销售退回信息
|
||||
* @param id
|
||||
* @return
|
||||
* 删除商品销售退货信息
|
||||
* @param id 销售退货ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
@RequestMapping("deleteSalesback")
|
||||
public ResultObj deleteSalesback(Integer id){
|
||||
public ResultObj deleteSalesback(Integer id) {
|
||||
try {
|
||||
// 调用销售退货服务,删除记录
|
||||
salesbackService.removeById(id);
|
||||
return ResultObj.DELETE_SUCCESS;
|
||||
return ResultObj.DELETE_SUCCESS; // 返回成功结果
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResultObj.DELETE_ERROR;
|
||||
return ResultObj.DELETE_ERROR; // 返回失败结果
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in new issue