领料管理--优化修改领料任务逻辑

This commit is contained in:
syruan 2024-11-13 15:31:48 +08:00
parent e18a20bf1b
commit 67e842c62f
2 changed files with 30 additions and 10 deletions

View File

@ -76,7 +76,7 @@ public class LeaseApplyInfoController extends BaseController {
//@RequiresPermissions("lease:info:add")
@SysLog(title = "领料任务", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增领料任务")
@PostMapping
public AjaxResult add(@RequestBody TmTaskRequestVo tmTaskRequestVo) {
public AjaxResult add(@RequestBody @NotNull(message = "领料任务不能为空") TmTaskRequestVo tmTaskRequestVo) {
try {
return leaseApplyInfoService.insertLeaseApplyInfo(tmTaskRequestVo);
} catch (Exception e) {
@ -92,7 +92,7 @@ public class LeaseApplyInfoController extends BaseController {
//@RequiresPermissions("lease:info:edit")
@SysLog(title = "领料任务", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改领料任务")
@PutMapping
public AjaxResult edit(@RequestBody TmTaskRequestVo tmTaskRequestVo) {
public AjaxResult edit(@RequestBody @NotNull TmTaskRequestVo tmTaskRequestVo) {
try {
return toAjax(leaseApplyInfoService.updateLeaseApplyInfo(tmTaskRequestVo));
} catch (Exception e) {

View File

@ -3,6 +3,7 @@ package com.bonus.material.lease.service.impl;
import java.util.List;
import java.util.Optional;
import cn.hutool.core.collection.CollectionUtil;
import com.bonus.common.biz.constant.MaterialConstants;
import com.bonus.common.biz.enums.PurchaseTaskStatusEnum;
import com.bonus.common.biz.enums.TmTaskTypeEnum;
@ -101,6 +102,9 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
if (tmTaskRequestVo.getLeaseApplyInfo() == null) {
return AjaxResult.error("请先填写领料任务信息");
}
if (CollectionUtil.isEmpty(tmTaskRequestVo.getLeaseApplyDetailsList())) {
return AjaxResult.error("请先添加领料任务物资明细");
}
tmTaskRequestVo.getLeaseApplyInfo().setCreateTime(DateUtils.getNowDate());
tmTaskRequestVo.getLeaseApplyInfo().setCreateBy(SecurityUtils.getUsername());
try {
@ -168,16 +172,32 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
*/
@Override
public boolean updateLeaseApplyInfo(TmTaskRequestVo tmTaskRequestVo) {
tmTaskRequestVo.getLeaseApplyInfo().setUpdateTime(DateUtils.getNowDate());
tmTaskRequestVo.getLeaseApplyInfo().setUpdateBy(SecurityUtils.getUsername());
try {
Long[] ids = new Long[]{tmTaskRequestVo.getLeaseApplyInfo().getId()};
// 提取到局部变量中减少重复代码
LeaseApplyInfo leaseApplyInfo = tmTaskRequestVo.getLeaseApplyInfo();
if (leaseApplyInfo != null) {
leaseApplyInfo.setUpdateTime(DateUtils.getNowDate());
leaseApplyInfo.setUpdateBy(SecurityUtils.getUsername());
// 去除创建一个新的数组对象直接复用
Long[] ids = {leaseApplyInfo.getId()};
if (CollectionUtil.isNotEmpty(tmTaskRequestVo.getLeaseApplyDetailsList())) {
// 业务逻辑代码
leaseApplyDetailsMapper.deleteLeaseApplyDetailsByParentIds(ids);
insertPurchaseCheckDetails(tmTaskRequestVo.getLeaseApplyDetailsList(), tmTaskRequestVo.getLeaseApplyInfo().getTaskId());
leaseApplyInfoMapper.updateLeaseApplyInfo(tmTaskRequestVo.getLeaseApplyInfo());
insertPurchaseCheckDetails(tmTaskRequestVo.getLeaseApplyDetailsList(), leaseApplyInfo.getTaskId());
}
// 修改外层info
leaseApplyInfoMapper.updateLeaseApplyInfo(leaseApplyInfo);
return true;
}
return false;
} catch (DataAccessException dae) {
throw new ServiceException("数据访问异常: " + dae.getMessage());
} catch (IllegalArgumentException iae) {
throw new ServiceException("非法参数异常: " + iae.getMessage());
} catch (Exception e) {
throw new ServiceException("错误信息描述");
throw new ServiceException("未知异常: " + e.getMessage());
}
}