|
|
|
@ -39,169 +39,170 @@ import java.util.stream.Collectors; |
|
|
|
@RequestMapping("/apply") |
|
|
|
@RequestMapping("/apply") |
|
|
|
public class ApplyController extends BladeController { |
|
|
|
public class ApplyController extends BladeController { |
|
|
|
|
|
|
|
|
|
|
|
private final IApplyService applyService; |
|
|
|
private final IApplyService applyService; |
|
|
|
private final IApplyDetailService applyDetailService; |
|
|
|
private final IApplyDetailService applyDetailService; |
|
|
|
private final IGoodsService goodsService; |
|
|
|
private final IGoodsService goodsService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 物品申领表 详情 |
|
|
|
* 物品申领表 详情 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("/detail") |
|
|
|
@GetMapping("/detail") |
|
|
|
public R<Apply> detail(Apply apply) { |
|
|
|
public R<Apply> detail(Apply apply) { |
|
|
|
Apply detail = applyService.getOne(Condition.getQueryWrapper(apply)); |
|
|
|
Apply detail = applyService.getOne(Condition.getQueryWrapper(apply)); |
|
|
|
detail.setDetails(applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).eq(ApplyDetail::getApplyId, apply.getId()))); |
|
|
|
detail.setDetails(applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).eq(ApplyDetail::getApplyId, apply.getId()))); |
|
|
|
return R.data(detail); |
|
|
|
return R.data(detail); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 物品申领表 分页 |
|
|
|
* 物品申领表 分页 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("/list") |
|
|
|
@GetMapping("/list") |
|
|
|
public R<IPage<Apply>> list(ApplyDTO apply, Query query) { |
|
|
|
public R<IPage<Apply>> list(ApplyDTO apply, Query query) { |
|
|
|
LambdaQueryWrapper<Apply> wrapper = Wrappers.lambdaQuery(Apply.class); |
|
|
|
LambdaQueryWrapper<Apply> wrapper = Wrappers.lambdaQuery(Apply.class); |
|
|
|
wrapper.orderByDesc(Apply::getCreateTime); |
|
|
|
wrapper.orderByDesc(Apply::getCreateTime); |
|
|
|
IPage<Apply> pages = applyService.page(Condition.getPage(query), wrapper); |
|
|
|
wrapper.eq(apply.getIsReturn() != null, Apply::getIsReturn, apply.getIsReturn()); |
|
|
|
List<Apply> records = pages.getRecords(); |
|
|
|
IPage<Apply> pages = applyService.page(Condition.getPage(query), wrapper); |
|
|
|
if (CollectionUtil.isNotEmpty(records)) { |
|
|
|
List<Apply> records = pages.getRecords(); |
|
|
|
List<Long> ids = records.stream().map(Apply::getId).collect(Collectors.toList()); |
|
|
|
if (CollectionUtil.isNotEmpty(records)) { |
|
|
|
List<ApplyDetail> details = applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).in(ApplyDetail::getApplyId, ids)); |
|
|
|
List<Long> ids = records.stream().map(Apply::getId).collect(Collectors.toList()); |
|
|
|
for (Apply record : records) { |
|
|
|
List<ApplyDetail> details = applyDetailService.list(Wrappers.lambdaQuery(ApplyDetail.class).in(ApplyDetail::getApplyId, ids)); |
|
|
|
record.setDetails(details.stream().filter(applyDetail -> applyDetail.getApplyId().equals(record.getId())).collect(Collectors.toList())); |
|
|
|
for (Apply record : records) { |
|
|
|
} |
|
|
|
record.setDetails(details.stream().filter(applyDetail -> applyDetail.getApplyId().equals(record.getId())).collect(Collectors.toList())); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.data(pages); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.data(pages); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
|
|
|
|
* 物品申领表 新增 |
|
|
|
/** |
|
|
|
*/ |
|
|
|
* 物品申领表 新增 |
|
|
|
@PostMapping("/save") |
|
|
|
*/ |
|
|
|
@ApiOperationSupport(order = 4) |
|
|
|
@PostMapping("/save") |
|
|
|
public R save(@Valid @RequestBody ApplyDTO apply) { |
|
|
|
@ApiOperationSupport(order = 4) |
|
|
|
|
|
|
|
public R save(@Valid @RequestBody ApplyDTO apply) { |
|
|
|
// User user = UserCache.getUser(AuthUtil.getUserId());
|
|
|
|
// User user = UserCache.getUser(AuthUtil.getUserId());
|
|
|
|
List<ApplyDetail> details = apply.getDetails(); |
|
|
|
List<ApplyDetail> details = apply.getDetails(); |
|
|
|
// apply.setApplyTime(new Date());
|
|
|
|
// apply.setApplyTime(new Date());
|
|
|
|
// apply.setApplyUserId(user.getId());
|
|
|
|
// apply.setApplyUserId(user.getId());
|
|
|
|
// apply.setApplyUser(user.getRealName());
|
|
|
|
// apply.setApplyUser(user.getRealName());
|
|
|
|
apply.setIsUpdate(-1); |
|
|
|
apply.setIsUpdate(-1); |
|
|
|
apply.setCode("编码格式待定"); |
|
|
|
apply.setCode("编码格式待定"); |
|
|
|
apply.setApplyTypeNum(details.size()); |
|
|
|
apply.setApplyTypeNum(details.size()); |
|
|
|
long count = details.stream().filter(applyDetail -> applyDetail.getReturnTime() != null).count(); |
|
|
|
long count = details.stream().filter(applyDetail -> applyDetail.getReturnTime() != null).count(); |
|
|
|
apply.setIsReturn(count > 0 ? 1 : 0); |
|
|
|
apply.setIsReturn(count > 0 ? 1 : 0); |
|
|
|
boolean save = applyService.save(apply); |
|
|
|
boolean save = applyService.save(apply); |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(details)) { |
|
|
|
if (CollectionUtil.isNotEmpty(details)) { |
|
|
|
for (ApplyDetail applyDetail : details) { |
|
|
|
for (ApplyDetail applyDetail : details) { |
|
|
|
applyDetail.setApplyId(apply.getId()); |
|
|
|
applyDetail.setApplyId(apply.getId()); |
|
|
|
applyDetail.setIsCk(0); |
|
|
|
applyDetail.setIsCk(0); |
|
|
|
applyDetail.setReturnNum(0); |
|
|
|
applyDetail.setReturnNum(0); |
|
|
|
applyDetail.setOutNum(0); |
|
|
|
applyDetail.setOutNum(0); |
|
|
|
applyDetail.setIsReturn(applyDetail.getReturnTime() != null ? 1 : 0); |
|
|
|
applyDetail.setIsReturn(applyDetail.getReturnTime() != null ? 1 : 0); |
|
|
|
} |
|
|
|
} |
|
|
|
applyDetailService.saveBatch(details); |
|
|
|
applyDetailService.saveBatch(details); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.status(save); |
|
|
|
return R.status(save); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 物品申领表 修改 |
|
|
|
* 物品申领表 修改 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/update") |
|
|
|
@PostMapping("/update") |
|
|
|
@ApiOperationSupport(order = 5) |
|
|
|
@ApiOperationSupport(order = 5) |
|
|
|
public R update(@Valid @RequestBody Apply apply) { |
|
|
|
public R update(@Valid @RequestBody Apply apply) { |
|
|
|
apply.setApproveTime(new Date()); |
|
|
|
apply.setApproveTime(new Date()); |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 审批 |
|
|
|
* 审批 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/approve") |
|
|
|
@PostMapping("/approve") |
|
|
|
public R approve(@RequestBody Apply apply) { |
|
|
|
public R approve(@RequestBody Apply apply) { |
|
|
|
User user = UserCache.getUser(AuthUtil.getUserId()); |
|
|
|
User user = UserCache.getUser(AuthUtil.getUserId()); |
|
|
|
apply.setApproveUserId(user.getId()); |
|
|
|
apply.setApproveUserId(user.getId()); |
|
|
|
apply.setApproveUser(user.getRealName()); |
|
|
|
apply.setApproveUser(user.getRealName()); |
|
|
|
apply.setApproveTime(new Date()); |
|
|
|
apply.setApproveTime(new Date()); |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 出库 |
|
|
|
* 出库 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/out") |
|
|
|
@PostMapping("/out") |
|
|
|
public R out(@RequestBody ApplyDTO apply) { |
|
|
|
public R out(@RequestBody ApplyDTO apply) { |
|
|
|
apply.setIsUpdate(0); |
|
|
|
apply.setIsUpdate(0); |
|
|
|
apply.setStatus(apply.getIsReturn() == 1 ? 3 : 2); |
|
|
|
apply.setStatus(apply.getIsReturn() == 1 ? 3 : 2); |
|
|
|
apply.setCkTime(new Date()); |
|
|
|
apply.setCkTime(new Date()); |
|
|
|
List<ApplyDetail> detailList = apply.getDetails(); |
|
|
|
List<ApplyDetail> detailList = apply.getDetails(); |
|
|
|
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); |
|
|
|
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); |
|
|
|
List<Goods> goodsList = goodsService.listByIds(ids); |
|
|
|
List<Goods> goodsList = goodsService.listByIds(ids); |
|
|
|
if (CollectionUtil.isNotEmpty(goodsList)) { |
|
|
|
if (CollectionUtil.isNotEmpty(goodsList)) { |
|
|
|
for (Goods goods : goodsList) { |
|
|
|
for (Goods goods : goodsList) { |
|
|
|
for (ApplyDetail applyDetail : detailList) { |
|
|
|
for (ApplyDetail applyDetail : detailList) { |
|
|
|
if (goods.getId().equals(applyDetail.getProductId())) { |
|
|
|
if (goods.getId().equals(applyDetail.getProductId())) { |
|
|
|
applyDetail.setIsCk(1); |
|
|
|
applyDetail.setIsCk(1); |
|
|
|
applyDetail.setCkTime(new Date()); |
|
|
|
applyDetail.setCkTime(new Date()); |
|
|
|
int i = goods.getNum() - applyDetail.getApplyNum(); |
|
|
|
int i = goods.getNum() - applyDetail.getApplyNum(); |
|
|
|
applyDetail.setOutNum(i > 0 ? applyDetail.getApplyNum() : goods.getNum()); |
|
|
|
applyDetail.setOutNum(i > 0 ? applyDetail.getApplyNum() : goods.getNum()); |
|
|
|
goods.setNum(Math.max(i, 0)); |
|
|
|
goods.setNum(Math.max(i, 0)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
goodsService.updateBatchById(goodsList); |
|
|
|
goodsService.updateBatchById(goodsList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(detailList)) { |
|
|
|
if (CollectionUtil.isNotEmpty(detailList)) { |
|
|
|
applyDetailService.updateBatchById(detailList); |
|
|
|
applyDetailService.updateBatchById(detailList); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 归还 |
|
|
|
* 归还 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/return") |
|
|
|
@PostMapping("/return") |
|
|
|
public R applyReturn(@RequestBody ApplyDTO apply) { |
|
|
|
public R applyReturn(@RequestBody ApplyDTO apply) { |
|
|
|
apply.setStatus(2); |
|
|
|
apply.setStatus(2); |
|
|
|
List<ApplyDetail> detailList = apply.getDetails(); |
|
|
|
List<ApplyDetail> detailList = apply.getDetails(); |
|
|
|
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); |
|
|
|
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList()); |
|
|
|
List<Goods> goodsList = goodsService.listByIds(ids); |
|
|
|
List<Goods> goodsList = goodsService.listByIds(ids); |
|
|
|
if (CollectionUtil.isNotEmpty(goodsList)) { |
|
|
|
if (CollectionUtil.isNotEmpty(goodsList)) { |
|
|
|
for (Goods goods : goodsList) { |
|
|
|
for (Goods goods : goodsList) { |
|
|
|
for (ApplyDetail applyDetail : detailList) { |
|
|
|
for (ApplyDetail applyDetail : detailList) { |
|
|
|
if (goods.getId().equals(applyDetail.getProductId())) { |
|
|
|
if (goods.getId().equals(applyDetail.getProductId())) { |
|
|
|
applyDetail.setReturnTime(new Date()); |
|
|
|
applyDetail.setReturnTime(new Date()); |
|
|
|
applyDetail.setIsReturn(1); |
|
|
|
applyDetail.setIsReturn(1); |
|
|
|
goods.setNum(goods.getNum() + applyDetail.getReturnNum()); |
|
|
|
goods.setNum(goods.getNum() + applyDetail.getReturnNum()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
goodsService.updateBatchById(goodsList); |
|
|
|
goodsService.updateBatchById(goodsList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(detailList)) { |
|
|
|
if (CollectionUtil.isNotEmpty(detailList)) { |
|
|
|
applyDetailService.updateBatchById(detailList); |
|
|
|
applyDetailService.updateBatchById(detailList); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
return R.status(applyService.updateById(apply)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 物品申领表 新增或修改 |
|
|
|
* 物品申领表 新增或修改 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/submit") |
|
|
|
@PostMapping("/submit") |
|
|
|
@ApiOperationSupport(order = 6) |
|
|
|
@ApiOperationSupport(order = 6) |
|
|
|
public R submit(@Valid @RequestBody Apply apply) { |
|
|
|
public R submit(@Valid @RequestBody Apply apply) { |
|
|
|
return R.status(applyService.saveOrUpdate(apply)); |
|
|
|
return R.status(applyService.saveOrUpdate(apply)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 物品申领表 删除 |
|
|
|
* 物品申领表 删除 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/remove") |
|
|
|
@PostMapping("/remove") |
|
|
|
@ApiOperationSupport(order = 7) |
|
|
|
@ApiOperationSupport(order = 7) |
|
|
|
public R remove(@RequestParam String ids) { |
|
|
|
public R remove(@RequestParam String ids) { |
|
|
|
return R.status(applyService.deleteLogic(Func.toLongList(ids))); |
|
|
|
return R.status(applyService.deleteLogic(Func.toLongList(ids))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|