package com.zy.asrs.wms.asrs.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.zy.asrs.framework.common.Cools;
|
import com.zy.asrs.framework.common.R;
|
import com.zy.asrs.framework.exception.CoolException;
|
import com.zy.asrs.wms.asrs.entity.OrderType;
|
import com.zy.asrs.wms.asrs.entity.param.CreateOrderParam;
|
import com.zy.asrs.wms.asrs.entity.param.UpdateOrderParam;
|
import com.zy.asrs.wms.asrs.service.OrderTypeService;
|
import com.zy.asrs.wms.common.annotation.OperationLog;
|
import com.zy.asrs.wms.common.domain.BaseParam;
|
import com.zy.asrs.wms.common.domain.KeyValVo;
|
import com.zy.asrs.wms.common.domain.PageParam;
|
import com.zy.asrs.wms.asrs.entity.Order;
|
import com.zy.asrs.wms.asrs.service.OrderService;
|
import com.zy.asrs.wms.system.controller.BaseController;
|
import com.zy.asrs.wms.utils.ExcelUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.*;
|
|
@RestController
|
@RequestMapping("/api")
|
public class OrderController extends BaseController {
|
|
@Autowired
|
private OrderService orderService;
|
@Autowired
|
private OrderTypeService orderTypeService;
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/page")
|
public R page(@RequestBody Map<String, Object> map) {
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
|
return R.ok().add(orderService.page(pageParam, pageParam.buildWrapper(true)));
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/in/page")
|
public R pageIn(@RequestBody Map<String, Object> map) {
|
String condition = map.getOrDefault("condition", "").toString();
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
|
// QueryWrapper<Order> wrapper = pageParam.buildWrapper(true);
|
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
|
|
ArrayList<Long> types = new ArrayList<>();
|
for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, 1))) {
|
types.add(orderType.getId());
|
}
|
|
wrapper.in(Order::getOrderType, types);
|
|
if (!Cools.isEmpty(condition)) {
|
wrapper.and(wrapper1 -> {
|
wrapper1.or().like(Order::getOrderNo, condition);
|
wrapper1.or().like(Order::getMemo, condition);
|
});
|
}
|
return R.ok().add(orderService.page(pageParam, wrapper));
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/out/page")
|
public R pageOut(@RequestBody Map<String, Object> map) {
|
String condition = map.getOrDefault("condition", "").toString();
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
PageParam<Order, BaseParam> pageParam = new PageParam<>(baseParam, Order.class);
|
// QueryWrapper<Order> wrapper = pageParam.buildWrapper(true);
|
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
|
|
ArrayList<Long> types = new ArrayList<>();
|
for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, 2))) {
|
types.add(orderType.getId());
|
}
|
|
wrapper.in(Order::getOrderType, types);
|
|
if (!Cools.isEmpty(condition)) {
|
wrapper.and(wrapper1 -> {
|
wrapper1.or().like(Order::getOrderNo, condition);
|
wrapper1.or().like(Order::getMemo, condition);
|
});
|
}
|
return R.ok().add(orderService.page(pageParam, wrapper));
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/list")
|
public R list(@RequestBody Map<String, Object> map) {
|
return R.ok().add(orderService.list());
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@GetMapping("/order/{id}")
|
public R get(@PathVariable("id") Long id) {
|
return R.ok().add(orderService.getById(id));
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:save')")
|
@OperationLog("添加订单")
|
@PostMapping("/order/save")
|
@Transactional
|
public R save(@RequestBody CreateOrderParam param) {
|
orderService.createOrder(param);
|
return R.ok("添加成功");
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:update')")
|
@OperationLog("修改订单")
|
@PostMapping("/order/update")
|
@Transactional
|
public R update(@RequestBody UpdateOrderParam param) {
|
orderService.updateOrder(param);
|
return R.ok("修改成功");
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:remove')")
|
@OperationLog("删除订单")
|
@PostMapping("/order/remove/{ids}")
|
@Transactional
|
public R remove(@PathVariable Long[] ids) {
|
for (Long id : ids) {
|
boolean result = orderService.deleteOrder(id);
|
if (!result) {
|
throw new CoolException("删除失败");
|
}
|
}
|
return R.ok("删除成功");
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/query")
|
public R query(@RequestParam(required = false) String condition) {
|
List<KeyValVo> vos = new ArrayList<>();
|
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
|
if (!Cools.isEmpty(condition)) {
|
wrapper.like(Order::getOrderNo, condition);
|
}
|
orderService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
|
item -> vos.add(new KeyValVo(item.getId(), item.getOrderNo()))
|
);
|
return R.ok().add(vos);
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/export")
|
public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
String ioModel = map.getOrDefault("ioModel", "").toString();
|
List<Order> list = orderService.list();
|
if (!Cools.isEmpty(ioModel)) {
|
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
|
ArrayList<Long> types = new ArrayList<>();
|
for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper<OrderType>().eq(OrderType::getType, ioModel.equals("in") ? 1 : 2))) {
|
types.add(orderType.getId());
|
}
|
wrapper.in(Order::getOrderType, types);
|
list = orderService.list(wrapper);
|
}
|
ExcelUtil.build(ExcelUtil.create(list, Order.class), response);
|
}
|
|
@PreAuthorize("hasAuthority('asrs:order:list')")
|
@PostMapping("/order/exportTemplate")
|
public void exportTemplate(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
ArrayList<Order> list = new ArrayList<>();
|
ExcelUtil.build(ExcelUtil.create(list, Order.class), response);
|
}
|
|
}
|