领料管理--增加事务、异常处理

This commit is contained in:
syruan 2024-11-13 16:45:17 +08:00
parent edafce611a
commit b099235b48
1 changed files with 17 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import com.bonus.material.lease.mapper.LeaseApplyInfoMapper; import com.bonus.material.lease.mapper.LeaseApplyInfoMapper;
import com.bonus.material.lease.domain.LeaseApplyInfo; import com.bonus.material.lease.domain.LeaseApplyInfo;
import com.bonus.material.lease.service.ILeaseApplyInfoService; import com.bonus.material.lease.service.ILeaseApplyInfoService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -140,6 +141,7 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
* @param leaseApplyInfo 领料任务info * @param leaseApplyInfo 领料任务info
*/ */
@Override @Override
@Transactional
public AjaxResult publish(LeaseApplyInfo leaseApplyInfo) { public AjaxResult publish(LeaseApplyInfo leaseApplyInfo) {
if (leaseApplyInfo.getId() == null) { if (leaseApplyInfo.getId() == null) {
return AjaxResult.error("ID为空,请完善后重新发布!"); return AjaxResult.error("ID为空,请完善后重新发布!");
@ -150,6 +152,7 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
leaseApplyInfo.setUpdateTime(DateUtils.getNowDate()); leaseApplyInfo.setUpdateTime(DateUtils.getNowDate());
leaseApplyInfo.setStatus(String.valueOf(PurchaseTaskStatusEnum.LEASE_TASK_PUBLISHED.getStatus())); leaseApplyInfo.setStatus(String.valueOf(PurchaseTaskStatusEnum.LEASE_TASK_PUBLISHED.getStatus()));
try {
int result = leaseApplyInfoMapper.updateLeaseApplyInfo(leaseApplyInfo); int result = leaseApplyInfoMapper.updateLeaseApplyInfo(leaseApplyInfo);
if (result > 0) { if (result > 0) {
// 同步修改tm_task任务状态 // 同步修改tm_task任务状态
@ -158,8 +161,13 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService {
tmTask.setStatus(String.valueOf(PurchaseTaskStatusEnum.LEASE_TASK_PUBLISHED.getStatus())); tmTask.setStatus(String.valueOf(PurchaseTaskStatusEnum.LEASE_TASK_PUBLISHED.getStatus()));
tmTaskMapper.updateTmTask(tmTask); tmTaskMapper.updateTmTask(tmTask);
return AjaxResult.success("发布成功"); return AjaxResult.success("发布成功");
} else { }
return AjaxResult.error("发布失败"); return AjaxResult.error("发布失败");
} catch (DataAccessException e) {
// 抛出异常回滚数据
throw new RuntimeException();
} catch (Exception e) {
return AjaxResult.error("发布失败:" + e.getMessage());
} }
} }