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.wms.asrs.entity.OrderType; 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.OrderLog; import com.zy.asrs.wms.asrs.service.OrderLogService; 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.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @RestController @RequestMapping("/api") public class OrderLogController extends BaseController { @Autowired private OrderLogService orderLogService; @Autowired private OrderTypeService orderTypeService; @PreAuthorize("hasAuthority('asrs:orderLog:list')") @PostMapping("/orderLog/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, OrderLog.class); return R.ok().add(orderLogService.page(pageParam, pageParam.buildWrapper(true))); } @PreAuthorize("hasAuthority('asrs:orderLog:list')") @PostMapping("/orderLog/in/page") public R pageIn(@RequestBody Map map) { String condition = map.getOrDefault("condition", "").toString(); BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, OrderLog.class); // QueryWrapper wrapper = pageParam.buildWrapper(true); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); ArrayList types = new ArrayList<>(); for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper().eq(OrderType::getType, 1))) { types.add(orderType.getId()); } wrapper.in(OrderLog::getOrderType, types); if (!Cools.isEmpty(condition)) { wrapper.and(wrapper1 -> { wrapper1.or().like(OrderLog::getOrderNo, condition); wrapper1.or().like(OrderLog::getMemo, condition); }); } return R.ok().add(orderLogService.page(pageParam, wrapper)); } @PreAuthorize("hasAuthority('asrs:orderLog:list')") @PostMapping("/orderLog/out/page") public R pageOut(@RequestBody Map map) { String condition = map.getOrDefault("condition", "").toString(); BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, OrderLog.class); // QueryWrapper wrapper = pageParam.buildWrapper(true); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); ArrayList types = new ArrayList<>(); for (OrderType orderType : orderTypeService.list(new LambdaQueryWrapper().eq(OrderType::getType, 2))) { types.add(orderType.getId()); } wrapper.in(OrderLog::getOrderType, types); if (!Cools.isEmpty(condition)) { wrapper.and(wrapper1 -> { wrapper1.or().like(OrderLog::getOrderNo, condition); wrapper1.or().like(OrderLog::getMemo, condition); }); } return R.ok().add(orderLogService.page(pageParam, wrapper)); } @PreAuthorize("hasAuthority('asrs:orderLog:list')") @PostMapping("/orderLog/list") public R list(@RequestBody Map map) { return R.ok().add(orderLogService.list()); } @PreAuthorize("hasAuthority('asrs:orderLog:list')") @GetMapping("/orderLog/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(orderLogService.getById(id)); } @PreAuthorize("hasAuthority('asrs:orderLog:save')") @OperationLog("添加订单历史管理") @PostMapping("/orderLog/save") public R save(@RequestBody OrderLog orderLog) { if (!orderLogService.save(orderLog)) { return R.error("添加失败"); } return R.ok("添加成功"); } @PreAuthorize("hasAuthority('asrs:orderLog:update')") @OperationLog("修改订单历史管理") @PostMapping("/orderLog/update") public R update(@RequestBody OrderLog orderLog) { if (!orderLogService.updateById(orderLog)) { return R.error("修改失败"); } return R.ok("修改成功"); } @PreAuthorize("hasAuthority('asrs:orderLog:remove')") @OperationLog("删除订单历史管理") @PostMapping("/orderLog/remove/{ids}") public R remove(@PathVariable Long[] ids) { if (!orderLogService.removeByIds(Arrays.asList(ids))) { return R.error("删除失败"); } return R.ok("删除成功"); } @PreAuthorize("hasAuthority('asrs:orderLog:list')") @PostMapping("/orderLog/query") public R query(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(OrderLog::getId, condition); } orderLogService.page(new Page<>(1, 30), wrapper).getRecords().forEach( item -> vos.add(new KeyValVo(item.getId(), item.getId())) ); return R.ok().add(vos); } @PreAuthorize("hasAuthority('asrs:orderLog:list')") @PostMapping("/orderLog/export") public void export(@RequestBody Map map, HttpServletResponse response) throws Exception { ExcelUtil.build(ExcelUtil.create(orderLogService.list(), OrderLog.class), response); } }