| | |
| | | package com.vincent.rsf.server.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.entity.enums.OrderType; |
| | | import com.vincent.rsf.server.api.entity.enums.OrderWorkType; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.annotation.OperationLog; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.KeyValVo; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams; |
| | | import com.vincent.rsf.server.manager.controller.params.BatchUpdateParam; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrder; |
| | | import com.vincent.rsf.server.manager.entity.AsnOrderItem; |
| | | import com.vincent.rsf.server.manager.entity.Matnr; |
| | | import com.vincent.rsf.server.manager.entity.excel.AsnOrderTemplate; |
| | | import com.vincent.rsf.server.manager.enums.AsnExceStatus; |
| | | import com.vincent.rsf.server.manager.service.AsnOrderItemService; |
| | | import com.vincent.rsf.server.manager.service.AsnOrderService; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.mail.Multipart; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @Api(tags = "ASN入库通知单") |
| | | public class AsnOrderController extends BaseController { |
| | | |
| | | @Autowired |
| | | private AsnOrderService asnOrderService; |
| | | @Autowired |
| | | private AsnOrderItemService asnOrderItemService; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:list')") |
| | | @PostMapping("/asnOrder/page") |
| | |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:list')") |
| | | @OperationLog("表单查询") |
| | | @GetMapping("/asnOrder/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(asnOrderService.getById(id)); |
| | |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:save')") |
| | | @OperationLog("Create ASN单据") |
| | | @PostMapping("/asnOrder/save") |
| | | @ApiOperation("保存") |
| | | public R save(@RequestBody AsnOrder asnOrder) { |
| | | asnOrder.setCreateBy(getLoginUserId()); |
| | | asnOrder.setCreateTime(new Date()); |
| | | asnOrder.setUpdateBy(getLoginUserId()); |
| | | asnOrder.setUpdateTime(new Date()); |
| | | String code = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_ASN_ORDER, asnOrder); |
| | | if (!Objects.isNull(code)) { |
| | | asnOrder.setCode(code); |
| | | } |
| | | if (!asnOrderService.save(asnOrder)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:update')") |
| | | @OperationLog("Update ASN单据") |
| | | @PostMapping("/asnOrder/update") |
| | | @ApiOperation("更新") |
| | | public R update(@RequestBody AsnOrder asnOrder) { |
| | | asnOrder.setUpdateBy(getLoginUserId()); |
| | | asnOrder.setUpdateTime(new Date()); |
| | |
| | | |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:list')") |
| | | @PostMapping("/asnOrder/query") |
| | | @ApiOperation("查询") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<AsnOrder> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(AsnOrder::getName, condition); |
| | | wrapper.like(AsnOrder::getCode, condition); |
| | | } |
| | | asnOrderService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getCode())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:list')") |
| | | @PostMapping("/asnOrder/export") |
| | | @ApiOperation("导出") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(asnOrderService.list(), AsnOrder.class), response); |
| | | List<AsnOrder> orders = new ArrayList<>(); |
| | | if (!Objects.isNull(map.get("ids"))) { |
| | | List<Long> ids = JSONArray.parseArray(JSONObject.toJSONString(map.get("ids")), Long.class); |
| | | if (!ids.isEmpty()) { |
| | | orders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().in(AsnOrder::getId, ids)); |
| | | } else { |
| | | orders = asnOrderService.list(new LambdaQueryWrapper<>()); |
| | | } |
| | | } else { |
| | | orders = asnOrderService.list(); |
| | | } |
| | | List<AsnOrderTemplate> orderTemplates = new ArrayList<>(); |
| | | for (AsnOrder order : orders) { |
| | | List<AsnOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, order.getId())); |
| | | for (AsnOrderItem item : orderItems) { |
| | | if (Objects.isNull(item)) { |
| | | continue; |
| | | } |
| | | AsnOrderTemplate template = new AsnOrderTemplate(); |
| | | template.setCode(order.getCode()) |
| | | .setType(OrderType.getValType(order.getType())) |
| | | .setWkType(OrderWorkType.getWorkDesc(order.getWkType())) |
| | | .setExceStatus(AsnExceStatus.getExceStatus(order.getExceStatus())) |
| | | .setAnfme(item.getAnfme() + "") |
| | | .setMaktx(item.getMaktx()).setMemo(item.getMemo()) |
| | | .setMatnrCode(item.getMatnrCode()) |
| | | .setPoCode(item.getPoCode()) |
| | | .setPoId(order.getPoId() + "") |
| | | .setPackName(item.getPackName()) |
| | | .setPlatItemId(item.getPlatItemId()) |
| | | .setSplrBatch(item.getSplrBatch()) |
| | | .setSplrCode(item.getSplrCode()) |
| | | .setStockUnit(item.getStockUnit()) |
| | | .setPurQty(item.getPurQty() + "") |
| | | .setPurUnit(item.getPurUnit()); |
| | | orderTemplates.add(template); |
| | | } |
| | | } |
| | | ExcelUtil.build(ExcelUtil.create(orderTemplates, AsnOrderTemplate.class), response); |
| | | } |
| | | |
| | | /** |
| | | * 质检上报 |
| | | * |
| | | * @param orders |
| | | * @return |
| | | */ |
| | | @PostMapping("/asnOrder/inspect") |
| | | @ApiOperation("质检上报") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:list')") |
| | | public R notifyInspect(@RequestBody List<AsnOrder> orders) { |
| | | if (orders.isEmpty()) { |
| | | return R.error("上报单据不能为空!!"); |
| | | } |
| | | if (asnOrderService.notifyInspect(orders)) { |
| | | return R.ok("质检上报成功!!"); |
| | | } else { |
| | | return R.error("一键上报失败!!"); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/asnOrder/matnr/list") |
| | | @ApiOperation("物料获取订单") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:list')") |
| | | public R getListByMatnr(@RequestBody Map<String, String> params) { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("查询条件不能为空!!"); |
| | | } |
| | | return R.ok(asnOrderService.getListByMatnr(params)); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/asnOrder/items/save") |
| | | @ApiOperation("保存主单及明细") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:save')") |
| | | public R orderAndItem(@RequestBody AsnOrderAndItemsParams params) throws Exception { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | return asnOrderService.saveOrderAndItems(params, getLoginUserId()); |
| | | } |
| | | |
| | | @ApiOperation("单据信息修改") |
| | | @PostMapping("/asnOrder/items/update") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:update')") |
| | | public R orderAndrItemUpdate(@RequestBody AsnOrderAndItemsParams params) throws Exception { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | return asnOrderService.updateOrderItem(params, getLoginUserId()); |
| | | } |
| | | |
| | | @ApiOperation("单据批量修改") |
| | | @PostMapping("/asnOrder/batch/update") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:update')") |
| | | public R batchUpdate(@RequestBody BatchUpdateParam params) { |
| | | if (Objects.isNull(params)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getOrder())) { |
| | | return R.error("修改参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getIds()) || params.getIds().isEmpty()) { |
| | | return R.error("修改ID不能为空!!"); |
| | | } |
| | | return R.ok(asnOrderService.batchUpdate(params, getLoginUserId())); |
| | | } |
| | | |
| | | @ApiOperation("一键收货") |
| | | @PostMapping("/asnOrder/complete/{id}") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:update')") |
| | | public R completeOrder(@PathVariable Long id) { |
| | | if (Objects.isNull(id)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | return asnOrderService.completeOrder(id, getLoginUserId()); |
| | | } |
| | | |
| | | @ApiOperation("关闭收货单") |
| | | @PostMapping("/asnOrder/close/{id}") |
| | | @PreAuthorize("hasAuthority('manager:asnOrder:update')") |
| | | public R closeOrder(@PathVariable Long id) { |
| | | if (Objects.isNull(id)) { |
| | | return R.error("参数不能为空!!"); |
| | | } |
| | | return asnOrderService.closeOrder(id); |
| | | } |
| | | |
| | | } |