| | |
| | | JSONArray jsonArray = jSONObject.getJSONArray("detailData"); |
| | | List<CuttingScrapDetail> list = jsonArray.toJavaList(CuttingScrapDetail.class); |
| | | |
| | | //做判断,申请报废的时候一个刀具只能申请一次 |
| | | for (CuttingScrapDetail temp : list) { |
| | | //判断刀具是否已经申请报废 |
| | | QueryWrapper<CuttingScrapDetail> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("inventory_id", temp.getInventoryId()); |
| | | // 检查数据库中是否已存在相同inventoryId的报废申请 |
| | | if (cuttingScrapDetailService.count(queryWrapper) > 0) { |
| | | cuttingScrapService.removeById(cuttingScrap.getId());//同时删除本表单 |
| | | return Result.error("刀具" + temp.getInventoryId() + "已经申请报废,请不要重复申请"); |
| | | } |
| | | } |
| | | // 所有检查通过后,保存所有明细数据 |
| | | for (CuttingScrapDetail temp : list) { |
| | | temp.setOrderId(cuttingScrap.getId()); |
| | | cuttingScrapDetailService.save(temp); |
| | | } |
| | | |
| | | // 更新库存刀具状态为"已出库" |
| | | if (!list.isEmpty()) { |
| | | // 收集所有需要更新状态的库存ID |
| | | List<String> inventoryIds = list.stream() |
| | | .map(CuttingScrapDetail::getInventoryId) // 假设CuttingScrapDetail中有inventoryId字段 |
| | | .filter(id -> id != null && !id.isEmpty()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!inventoryIds.isEmpty()) { |
| | | // 更新库存状态为"已出库" |
| | | cuttingInventoryService.updateStatus(inventoryIds, "待报废"); |
| | | } |
| | | } |
| | | return Result.OK("添加成功!"); |
| | | |
| | | // // 更新库存刀具状态为"待报废" |
| | | // if (!list.isEmpty()) { |
| | | // // 收集所有需要更新状态的库存ID |
| | | // List<String> inventoryIds = list.stream() |
| | | // .map(CuttingScrapDetail::getInventoryId) // 假设CuttingScrapDetail中有inventoryId字段 |
| | | // .filter(id -> id != null && !id.isEmpty()) |
| | | // .collect(Collectors.toList()); |
| | | // |
| | | // if (!inventoryIds.isEmpty()) { |
| | | // // 更新库存状态为"待报废" |
| | | // cuttingInventoryService.updateStatus(inventoryIds, "待报废"); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | //@RequiresPermissions("org.jeecg.modules:cms_cutting_scrap:delete") |
| | | @DeleteMapping(value = "/delete") |
| | | public Result<String> delete(@RequestParam(name = "id", required = true) String id) { |
| | | cuttingScrapService.removeById(id); |
| | | cuttingScrapService.removeById(id);//删除主表数据 |
| | | //删除刀具报废明细表的数据 |
| | | cuttingScrapDetailService.remove |
| | | (new QueryWrapper<CuttingScrapDetail>().eq("order_id", id)); |
| | | return Result.OK("删除成功!"); |
| | | } |
| | | |
| | |
| | | return Result.ok(inventoryTooList); |
| | | } |
| | | |
| | | @GetMapping("/submit") |
| | | public Result<?> submit(@RequestParam("orderId") String orderId) { |
| | | return cuttingScrapService.submit(orderId); |
| | | } |
| | | |
| | | } |