4.1 查询食品
@RequestMapping(value = "/getByPage", method = RequestMethod.GET)
@ApiOperation(value = "查询食品")
public Result<IPage<Food>> getByPage(@ModelAttribute Food food ,@ModelAttribute PageVo page){
QueryWrapper<Food> qw = new QueryWrapper<>();
if(!ZwzNullUtils.isNull(food.getTitle())) {
qw.like("title",food.getTitle());
}
if(!ZwzNullUtils.isNull(food.getContent())) {
qw.like("content",food.getContent());
}
if(!ZwzNullUtils.isNull(food.getType())) {
qw.eq("type",food.getType());
}
IPage<Food> data = iFoodService.page(PageUtil.initMpPage(page),qw);
return new ResultUtil<IPage<Food>>().setData(data);
}
4.2 查询加工厂
@RequestMapping(value = "/getByPage", method = RequestMethod.GET)
@ApiOperation(value = "查询加工厂")
public Result<IPage<ProcessingFactory>> getByPage(@ModelAttribute ProcessingFactory processingFactory ,@ModelAttribute PageVo page){
QueryWrapper<ProcessingFactory> qw = new QueryWrapper<>();
if(!ZwzNullUtils.isNull(processingFactory.getTitle())) {
qw.like("title",processingFactory.getTitle());
}
if(!ZwzNullUtils.isNull(processingFactory.getAddress())) {
qw.like("address",processingFactory.getAddress());
}
if(!ZwzNullUtils.isNull(processingFactory.getDutyName())) {
qw.like("duty_name",processingFactory.getDutyName());
}
IPage<ProcessingFactory> data = iProcessingFactoryService.page(PageUtil.initMpPage(page),qw);
return new ResultUtil<IPage<ProcessingFactory>>().setData(data);
}
4.3 新增生产订单
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ApiOperation(value = "新增生产订单")
public Result<ProduceOrder> insert(ProduceOrder produceOrder){
Food food = iFoodService.getById(produceOrder.getFoodId());
if(food == null) {
return ResultUtil.error("食品不存在");
}
produceOrder.setFoodName(food.getTitle());
produceOrder.setContent(food.getContent());
produceOrder.setImage(food.getImage());
produceOrder.setType(food.getType());
iProduceOrderService.saveOrUpdate(produceOrder);
food.setStock(food.getStock().add(produceOrder.getNumber()));
iFoodService.saveOrUpdate(food);
return new ResultUtil<ProduceOrder>().setData(produceOrder);
}
4.4 新增销售订单
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ApiOperation(value = "新增销售订单")
public Result<SalesOrder> insert(SalesOrder salesOrder){
Food food = iFoodService.getById(salesOrder.getFoodId());
if(food == null) {
return ResultUtil.error("食品不存在");
}
if(food.getStock().compareTo(salesOrder.getNumber()) < 0) {
return ResultUtil.error("库存不足");
}
salesOrder.setFoodName(food.getTitle());
salesOrder.setContent(food.getContent());
salesOrder.setImage(food.getImage());
salesOrder.setType(food.getType());
Customer customer = iCustomerService.getById(salesOrder.getBuyId());
if(customer == null) {
return ResultUtil.error("客户不存在");
}
salesOrder.setBuyName(customer.getTitle());
iSalesOrderService.saveOrUpdate(salesOrder);
food.setStock(food.getStock().subtract(salesOrder.getNumber()));
iFoodService.saveOrUpdate(food);
return new ResultUtil<SalesOrder>().setData(salesOrder);
}
4.5 查询客户
@RequestMapping(value = "/getByPage", method = RequestMethod.GET)
@ApiOperation(value = "查询客户")
public Result<IPage<Customer>> getByPage(@ModelAttribute Customer customer ,@ModelAttribute PageVo page){
QueryWrapper<Customer> qw = new QueryWrapper<>();
if(!ZwzNullUtils.isNull(customer.getTitle())) {
qw.like("title",customer.getTitle());
}
if(!ZwzNullUtils.isNull(customer.getSex())) {
qw.eq("sex",customer.getSex());
}
if(!ZwzNullUtils.isNull(customer.getChannel())) {
qw.eq("channel",customer.getChannel());
}
IPage<Customer> data = iCustomerService.page(PageUtil.initMpPage(page),qw);
return new ResultUtil<IPage<Customer>>().setData(data);
}