功能完善

master
薛宏祥 1 year ago
parent 199dbb1383
commit 29aeb0623f
  1. 323
      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<Apply> 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<IPage<Apply>> list(ApplyDTO apply, Query query) {
LambdaQueryWrapper<Apply> wrapper = Wrappers.lambdaQuery(Apply.class);
wrapper.orderByDesc(Apply::getCreateTime);
IPage<Apply> pages = applyService.page(Condition.getPage(query), wrapper);
List<Apply> records = pages.getRecords();
if (CollectionUtil.isNotEmpty(records)) {
List<Long> ids = records.stream().map(Apply::getId).collect(Collectors.toList());
List<ApplyDetail> 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<Apply> 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<IPage<Apply>> list(ApplyDTO apply, Query query) {
LambdaQueryWrapper<Apply> wrapper = Wrappers.lambdaQuery(Apply.class);
wrapper.orderByDesc(Apply::getCreateTime);
wrapper.eq(apply.getIsReturn() != null, Apply::getIsReturn, apply.getIsReturn());
IPage<Apply> pages = applyService.page(Condition.getPage(query), wrapper);
List<Apply> records = pages.getRecords();
if (CollectionUtil.isNotEmpty(records)) {
List<Long> ids = records.stream().map(Apply::getId).collect(Collectors.toList());
List<ApplyDetail> 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<ApplyDetail> details = apply.getDetails();
List<ApplyDetail> 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<ApplyDetail> detailList = apply.getDetails();
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList());
List<Goods> 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<ApplyDetail> detailList = apply.getDetails();
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList());
List<Goods> 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<ApplyDetail> detailList = apply.getDetails();
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList());
List<Goods> 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<ApplyDetail> detailList = apply.getDetails();
List<Long> ids = detailList.stream().map(ApplyDetail::getProductId).collect(Collectors.toList());
List<Goods> 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)));
}
}

Loading…
Cancel
Save