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.
130 lines
5.2 KiB
130 lines
5.2 KiB
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.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;
|
|
|
|
/**
|
|
* <p>
|
|
* InnoDB free: 9216 kB 前端销售退货控制器
|
|
* </p>
|
|
*
|
|
* @author luoyi-
|
|
* @since 2019-12-23
|
|
*/
|
|
@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 ResultObj 操作结果对象,表示添加退货信息操作是否成功
|
|
*/
|
|
@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 DataGridView 包含分页数据和总记录数的数据视图对象
|
|
*/
|
|
@RequestMapping("loadAllSalesback")
|
|
public DataGridView loadAllSalesback(SalesbackVo salesbackVo){
|
|
// 创建分页对象,根据传入的分页信息(页码和每页记录数)初始化
|
|
IPage<Salesback> page = new Page<Salesback>(salesbackVo.getPage(),salesbackVo.getLimit());
|
|
// 创建查询包装器,用于构建查询条件
|
|
QueryWrapper<Salesback> queryWrapper = new QueryWrapper<Salesback>();
|
|
//对客户进行查询,当 customerid 不为空且不为 0 时添加查询条件
|
|
queryWrapper.eq(salesbackVo.getCustomerid()!=null&&salesbackVo.getCustomerid()!=0,"customerid",salesbackVo.getCustomerid());
|
|
//对商品进行查询,当 goodsid 不为空且不为 0 时添加查询条件
|
|
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());
|
|
// 按照商品退货时间降序排序
|
|
queryWrapper.orderByDesc("salesbacktime");
|
|
// 调用服务层进行分页查询
|
|
salesbackService.page(page, queryWrapper);
|
|
List<Salesback> records = page.getRecords();
|
|
// 遍历查询结果
|
|
for (Salesback salesback : records) {
|
|
System.out.println("============================");
|
|
// 根据客户 ID 获取客户信息
|
|
Customer customer = customerService.getById(salesback.getCustomerid());
|
|
if (customer!=null){
|
|
//设置客户姓名
|
|
salesback.setCustomername(customer.getCustomername());
|
|
}
|
|
// 根据商品 ID 获取商品信息
|
|
Goods goods = goodsService.getById(salesback.getGoodsid());
|
|
if (goods!=null){
|
|
//设置商品名称
|
|
salesback.setGoodsname(goods.getGoodsname());
|
|
//设置商品规格
|
|
salesback.setSize(goods.getSize());
|
|
}
|
|
}
|
|
// 将查询结果封装到 DataGridView 中并返回,包含总记录数和记录列表
|
|
return new DataGridView(page.getTotal(),page.getRecords());
|
|
}
|
|
|
|
/**
|
|
* 删除商品销售退回信息
|
|
* @param id 要删除的商品销售退回信息的 ID
|
|
* @return ResultObj 操作结果对象,表示删除操作是否成功
|
|
*/
|
|
@RequestMapping("deleteSalesback")
|
|
public ResultObj deleteSalesback(Integer id){
|
|
try {
|
|
// 调用服务层的方法删除商品销售退回信息
|
|
salesbackService.removeById(id);
|
|
return ResultObj.DELETE_SUCCESS;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return ResultObj.DELETE_ERROR;
|
|
}
|
|
}
|
|
|
|
}
|
|
|