From 29aeb0623f816b975b99371972da6bea556691c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=8F=E7=A5=A5?= <14281818+xue-hongxiang@user.noreply.gitee.com> Date: Sat, 4 Jan 2025 16:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contraller/supplies/ApplyController.java | 323 +++++++++--------- 1 file changed, 162 insertions(+), 161 deletions(-) diff --git a/src/main/java/org/springblade/modules/business/contraller/supplies/ApplyController.java b/src/main/java/org/springblade/modules/business/contraller/supplies/ApplyController.java index b942612..9dedc40 100644 --- a/src/main/java/org/springblade/modules/business/contraller/supplies/ApplyController.java +++ b/src/main/java/org/springblade/modules/business/contraller/supplies/ApplyController.java @@ -39,169 +39,170 @@ import java.util.stream.Collectors; @RequestMapping("/apply") public class ApplyController extends BladeController { - private final IApplyService applyService; - private final IApplyDetailService applyDetailService; - private final IGoodsService goodsService; - - /** - * 物品申领表 详情 - */ - @GetMapping("/detail") - public R detail(Apply apply) { - Apply detail = applyService.getOne(Condition.getQueryWrapper(apply)); - detail.setDetails(applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).eq(ApplyDetail::getApplyId, apply.getId()))); - return R.data(detail); - } - - /** - * 物品申领表 分页 - */ - @GetMapping("/list") - public R> list(ApplyDTO apply, Query query) { - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(Apply.class); - wrapper.orderByDesc(Apply::getCreateTime); - IPage pages = applyService.page(Condition.getPage(query), wrapper); - List records = pages.getRecords(); - if (CollectionUtil.isNotEmpty(records)) { - List ids = records.stream().map(Apply::getId).collect(Collectors.toList()); - List details = applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).in(ApplyDetail::getApplyId, ids)); - for (Apply record : records) { - record.setDetails(details.stream().filter(applyDetail -> applyDetail.getApplyId().equals(record.getId())).collect(Collectors.toList())); - } - } - return R.data(pages); - } - - /** - * 物品申领表 新增 - */ - @PostMapping("/save") - @ApiOperationSupport(order = 4) - public R save(@Valid @RequestBody ApplyDTO apply) { + private final IApplyService applyService; + private final IApplyDetailService applyDetailService; + private final IGoodsService goodsService; + + /** + * 物品申领表 详情 + */ + @GetMapping("/detail") + public R detail(Apply apply) { + Apply detail = applyService.getOne(Condition.getQueryWrapper(apply)); + detail.setDetails(applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).eq(ApplyDetail::getApplyId, apply.getId()))); + return R.data(detail); + } + + /** + * 物品申领表 分页 + */ + @GetMapping("/list") + public R> list(ApplyDTO apply, Query query) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(Apply.class); + wrapper.orderByDesc(Apply::getCreateTime); + wrapper.eq(apply.getIsReturn() != null, Apply::getIsReturn, apply.getIsReturn()); + IPage pages = applyService.page(Condition.getPage(query), wrapper); + List records = pages.getRecords(); + if (CollectionUtil.isNotEmpty(records)) { + List ids = records.stream().map(Apply::getId).collect(Collectors.toList()); + List details = applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).in(ApplyDetail::getApplyId, ids)); + for (Apply record : records) { + record.setDetails(details.stream().filter(applyDetail -> applyDetail.getApplyId().equals(record.getId())).collect(Collectors.toList())); + } + } + return R.data(pages); + } + + /** + * 物品申领表 新增 + */ + @PostMapping("/save") + @ApiOperationSupport(order = 4) + public R save(@Valid @RequestBody ApplyDTO apply) { // User user = UserCache.getUser(AuthUtil.getUserId()); - List details = apply.getDetails(); + List details = apply.getDetails(); // apply.setApplyTime(new Date()); // apply.setApplyUserId(user.getId()); // apply.setApplyUser(user.getRealName()); - apply.setIsUpdate(-1); - apply.setCode("编码格式待定"); - apply.setApplyTypeNum(details.size()); - long count = details.stream().filter(applyDetail -> applyDetail.getReturnTime() != null).count(); - apply.setIsReturn(count > 0 ? 1 : 0); - boolean save = applyService.save(apply); - - if (CollectionUtil.isNotEmpty(details)) { - for (ApplyDetail applyDetail : details) { - applyDetail.setApplyId(apply.getId()); - applyDetail.setIsCk(0); - applyDetail.setReturnNum(0); - applyDetail.setOutNum(0); - applyDetail.setIsReturn(applyDetail.getReturnTime() != null ? 1 : 0); - } - applyDetailService.saveBatch(details); - } - return R.status(save); - } - - /** - * 物品申领表 修改 - */ - @PostMapping("/update") - @ApiOperationSupport(order = 5) - public R update(@Valid @RequestBody Apply apply) { - apply.setApproveTime(new Date()); - return R.status(applyService.updateById(apply)); - } - - /** - * 审批 - */ - @PostMapping("/approve") - public R approve(@RequestBody Apply apply) { - User user = UserCache.getUser(AuthUtil.getUserId()); - apply.setApproveUserId(user.getId()); - apply.setApproveUser(user.getRealName()); - apply.setApproveTime(new Date()); - return R.status(applyService.updateById(apply)); - } - - /** - * 出库 - */ - @PostMapping("/out") - public R out(@RequestBody ApplyDTO apply) { - apply.setIsUpdate(0); - apply.setStatus(apply.getIsReturn() == 1 ? 3 : 2); - apply.setCkTime(new Date()); - List detailList = apply.getDetails(); - List ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); - List goodsList = goodsService.listByIds(ids); - if (CollectionUtil.isNotEmpty(goodsList)) { - for (Goods goods : goodsList) { - for (ApplyDetail applyDetail : detailList) { - if (goods.getId().equals(applyDetail.getProductId())) { - applyDetail.setIsCk(1); - applyDetail.setCkTime(new Date()); - int i = goods.getNum() - applyDetail.getApplyNum(); - applyDetail.setOutNum(i > 0 ? applyDetail.getApplyNum() : goods.getNum()); - goods.setNum(Math.max(i, 0)); - break; - } - } - } - goodsService.updateBatchById(goodsList); - } - - if (CollectionUtil.isNotEmpty(detailList)) { - applyDetailService.updateBatchById(detailList); - } - return R.status(applyService.updateById(apply)); - } - - /** - * 归还 - */ - @PostMapping("/return") - public R applyReturn(@RequestBody ApplyDTO apply) { - apply.setStatus(2); - List detailList = apply.getDetails(); - List ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); - List goodsList = goodsService.listByIds(ids); - if (CollectionUtil.isNotEmpty(goodsList)) { - for (Goods goods : goodsList) { - for (ApplyDetail applyDetail : detailList) { - if (goods.getId().equals(applyDetail.getProductId())) { - applyDetail.setReturnTime(new Date()); - applyDetail.setIsReturn(1); - goods.setNum(goods.getNum() + applyDetail.getReturnNum()); - break; - } - } - } - goodsService.updateBatchById(goodsList); - } - - if (CollectionUtil.isNotEmpty(detailList)) { - applyDetailService.updateBatchById(detailList); - } - return R.status(applyService.updateById(apply)); - } - - /** - * 物品申领表 新增或修改 - */ - @PostMapping("/submit") - @ApiOperationSupport(order = 6) - public R submit(@Valid @RequestBody Apply apply) { - return R.status(applyService.saveOrUpdate(apply)); - } - - /** - * 物品申领表 删除 - */ - @PostMapping("/remove") - @ApiOperationSupport(order = 7) - public R remove(@RequestParam String ids) { - return R.status(applyService.deleteLogic(Func.toLongList(ids))); - } + apply.setIsUpdate(-1); + apply.setCode("编码格式待定"); + apply.setApplyTypeNum(details.size()); + long count = details.stream().filter(applyDetail -> applyDetail.getReturnTime() != null).count(); + apply.setIsReturn(count > 0 ? 1 : 0); + boolean save = applyService.save(apply); + + if (CollectionUtil.isNotEmpty(details)) { + for (ApplyDetail applyDetail : details) { + applyDetail.setApplyId(apply.getId()); + applyDetail.setIsCk(0); + applyDetail.setReturnNum(0); + applyDetail.setOutNum(0); + applyDetail.setIsReturn(applyDetail.getReturnTime() != null ? 1 : 0); + } + applyDetailService.saveBatch(details); + } + return R.status(save); + } + + /** + * 物品申领表 修改 + */ + @PostMapping("/update") + @ApiOperationSupport(order = 5) + public R update(@Valid @RequestBody Apply apply) { + apply.setApproveTime(new Date()); + return R.status(applyService.updateById(apply)); + } + + /** + * 审批 + */ + @PostMapping("/approve") + public R approve(@RequestBody Apply apply) { + User user = UserCache.getUser(AuthUtil.getUserId()); + apply.setApproveUserId(user.getId()); + apply.setApproveUser(user.getRealName()); + apply.setApproveTime(new Date()); + return R.status(applyService.updateById(apply)); + } + + /** + * 出库 + */ + @PostMapping("/out") + public R out(@RequestBody ApplyDTO apply) { + apply.setIsUpdate(0); + apply.setStatus(apply.getIsReturn() == 1 ? 3 : 2); + apply.setCkTime(new Date()); + List detailList = apply.getDetails(); + List ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); + List goodsList = goodsService.listByIds(ids); + if (CollectionUtil.isNotEmpty(goodsList)) { + for (Goods goods : goodsList) { + for (ApplyDetail applyDetail : detailList) { + if (goods.getId().equals(applyDetail.getProductId())) { + applyDetail.setIsCk(1); + applyDetail.setCkTime(new Date()); + int i = goods.getNum() - applyDetail.getApplyNum(); + applyDetail.setOutNum(i > 0 ? applyDetail.getApplyNum() : goods.getNum()); + goods.setNum(Math.max(i, 0)); + break; + } + } + } + goodsService.updateBatchById(goodsList); + } + + if (CollectionUtil.isNotEmpty(detailList)) { + applyDetailService.updateBatchById(detailList); + } + return R.status(applyService.updateById(apply)); + } + + /** + * 归还 + */ + @PostMapping("/return") + public R applyReturn(@RequestBody ApplyDTO apply) { + apply.setStatus(2); + List detailList = apply.getDetails(); + List ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); + List goodsList = goodsService.listByIds(ids); + if (CollectionUtil.isNotEmpty(goodsList)) { + for (Goods goods : goodsList) { + for (ApplyDetail applyDetail : detailList) { + if (goods.getId().equals(applyDetail.getProductId())) { + applyDetail.setReturnTime(new Date()); + applyDetail.setIsReturn(1); + goods.setNum(goods.getNum() + applyDetail.getReturnNum()); + break; + } + } + } + goodsService.updateBatchById(goodsList); + } + + if (CollectionUtil.isNotEmpty(detailList)) { + applyDetailService.updateBatchById(detailList); + } + return R.status(applyService.updateById(apply)); + } + + /** + * 物品申领表 新增或修改 + */ + @PostMapping("/submit") + @ApiOperationSupport(order = 6) + public R submit(@Valid @RequestBody Apply apply) { + return R.status(applyService.saveOrUpdate(apply)); + } + + /** + * 物品申领表 删除 + */ + @PostMapping("/remove") + @ApiOperationSupport(order = 7) + public R remove(@RequestParam String ids) { + return R.status(applyService.deleteLogic(Func.toLongList(ids))); + } }