|
@@ -492,85 +492,89 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
|
@Override
|
|
@Override
|
|
|
- public Boolean returnIsMaterialsLoan(ReturnLoanDTO dto) {
|
|
|
|
|
- Assert.notNull(dto.getMaterialsId(), "物资id不能为空!");
|
|
|
|
|
- Assert.notNull(dto.getRestitutionUserId(), "归还人id不能为空!");
|
|
|
|
|
- Assert.notNull(dto.getRestitutionToId(), "归还柜id不能为空!");
|
|
|
|
|
- // 0.检查借出数据
|
|
|
|
|
- List<IsMaterialsLoan> loanList = list(Wrappers.<IsMaterialsLoan>lambdaQuery()
|
|
|
|
|
- .eq(IsMaterialsLoan::getMaterialsId, dto.getMaterialsId())
|
|
|
|
|
- .isNull(IsMaterialsLoan::getRestitutionUserId)
|
|
|
|
|
- .isNull(IsMaterialsLoan::getRestitutionToId)
|
|
|
|
|
- );
|
|
|
|
|
- Assert.isFalse(loanList.isEmpty(), "尚未找到该物资的借出信息!");
|
|
|
|
|
- Assert.isFalse(loanList.size() > 1, "该物资的借出信息出现多条!");
|
|
|
|
|
- // 1.查询物资信息
|
|
|
|
|
- IsMaterials materials = isMaterialsService.getById(dto.getMaterialsId());
|
|
|
|
|
- // 1.1 如果不是归还到原先的柜子,则不能更新归还记录,存储归还异常等待处理,并且更新物资状态异常
|
|
|
|
|
- if (!materials.getMaterialsCabinetId().equals(dto.getRestitutionToId())) {
|
|
|
|
|
- IsMaterialsLoanException loanException = new IsMaterialsLoanException();
|
|
|
|
|
- loanException.setMaterialsId(dto.getMaterialsId());
|
|
|
|
|
- loanException.setMaterialsLoanId(loanList.get(0).getMaterialsLoanId());
|
|
|
|
|
- loanException.setLoanFromId(materials.getMaterialsCabinetId());
|
|
|
|
|
- // loanException.setLoanTime(loanList.get(0).getLoanTime());
|
|
|
|
|
- loanException.setRestitutionUserId(dto.getRestitutionUserId());
|
|
|
|
|
- loanException.setRestitutionToId(dto.getRestitutionToId());
|
|
|
|
|
- // loanException.setActualRestitutionTime(new Date());
|
|
|
|
|
- loanException.setOccurTime(new Date());
|
|
|
|
|
- isMaterialsLoanExceptionService.save(loanException);
|
|
|
|
|
|
|
+ public Boolean returnIsMaterialsLoan(ReturnLoanDTO dto) throws Exception {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Assert.notNull(dto.getMaterialsId(), "物资id不能为空!");
|
|
|
|
|
+ Assert.notNull(dto.getRestitutionUserId(), "归还人id不能为空!");
|
|
|
|
|
+ Assert.notNull(dto.getRestitutionToId(), "归还柜id不能为空!");
|
|
|
|
|
+ // 0.检查借出数据
|
|
|
|
|
+ List<IsMaterialsLoan> loanList = list(Wrappers.<IsMaterialsLoan>lambdaQuery()
|
|
|
|
|
+ .eq(IsMaterialsLoan::getMaterialsId, dto.getMaterialsId())
|
|
|
|
|
+ .isNull(IsMaterialsLoan::getRestitutionUserId)
|
|
|
|
|
+ .isNull(IsMaterialsLoan::getRestitutionToId)
|
|
|
|
|
+ );
|
|
|
|
|
+ Assert.isFalse(loanList.isEmpty(), "尚未找到该物资的借出信息!");
|
|
|
|
|
+ // Assert.isFalse(loanList.size() > 1, "该物资的借出信息出现多条!");
|
|
|
|
|
+ // 1.查询物资信息
|
|
|
|
|
+ IsMaterials materials = isMaterialsService.getById(dto.getMaterialsId());
|
|
|
|
|
+ // 1.1 如果不是归还到原先的柜子,则不能更新归还记录,存储归还异常等待处理,并且更新物资状态异常
|
|
|
|
|
+ if (!materials.getMaterialsCabinetId().equals(dto.getRestitutionToId())) {
|
|
|
|
|
+ IsMaterialsLoanException loanException = new IsMaterialsLoanException();
|
|
|
|
|
+ loanException.setMaterialsId(dto.getMaterialsId());
|
|
|
|
|
+ loanException.setMaterialsLoanId(loanList.get(0).getMaterialsLoanId());
|
|
|
|
|
+ loanException.setLoanFromId(materials.getMaterialsCabinetId());
|
|
|
|
|
+ // loanException.setLoanTime(loanList.get(0).getLoanTime());
|
|
|
|
|
+ loanException.setRestitutionUserId(dto.getRestitutionUserId());
|
|
|
|
|
+ loanException.setRestitutionToId(dto.getRestitutionToId());
|
|
|
|
|
+ // loanException.setActualRestitutionTime(new Date());
|
|
|
|
|
+ loanException.setOccurTime(new Date());
|
|
|
|
|
+ isMaterialsLoanExceptionService.save(loanException);
|
|
|
|
|
+ isMaterialsService.update(Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
|
|
+ .eq(IsMaterials::getMaterialsId, materials.getMaterialsId())
|
|
|
|
|
+ .set(IsMaterials::getLoanState, "0")
|
|
|
|
|
+ .set(IsMaterials::getStatus, "3"));
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 2.开始更新loan表数据
|
|
|
|
|
+ boolean update = update(Wrappers.<IsMaterialsLoan>lambdaUpdate()
|
|
|
|
|
+ .eq(IsMaterialsLoan::getMaterialsLoanId, loanList.get(0).getMaterialsLoanId())
|
|
|
|
|
+ .set(IsMaterialsLoan::getRestitutionUserId, dto.getRestitutionUserId())
|
|
|
|
|
+ .set(IsMaterialsLoan::getRestitutionToId, dto.getRestitutionToId())
|
|
|
|
|
+ .set(IsMaterialsLoan::getStatus, 1)
|
|
|
|
|
+ .set(IsMaterialsLoan::getActualRestitutionTime, new Date()));
|
|
|
|
|
+ // 3.开始更新物资信息
|
|
|
isMaterialsService.update(Wrappers.<IsMaterials>lambdaUpdate()
|
|
isMaterialsService.update(Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
- .eq(IsMaterials::getMaterialsId, materials.getMaterialsId())
|
|
|
|
|
- .set(IsMaterials::getLoanState, "0")
|
|
|
|
|
- .set(IsMaterials::getStatus, "3"));
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- // 2.开始更新loan表数据
|
|
|
|
|
- boolean update = update(Wrappers.<IsMaterialsLoan>lambdaUpdate()
|
|
|
|
|
- .eq(IsMaterialsLoan::getMaterialsLoanId, loanList.get(0).getMaterialsLoanId())
|
|
|
|
|
- .set(IsMaterialsLoan::getRestitutionUserId, dto.getRestitutionUserId())
|
|
|
|
|
- .set(IsMaterialsLoan::getRestitutionToId, dto.getRestitutionToId())
|
|
|
|
|
- .set(IsMaterialsLoan::getStatus, 1)
|
|
|
|
|
- .set(IsMaterialsLoan::getActualRestitutionTime, new Date()));
|
|
|
|
|
- // 3.开始更新物资信息
|
|
|
|
|
- isMaterialsService.update(Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
|
|
- .eq(IsMaterials::getMaterialsId, dto.getMaterialsId())
|
|
|
|
|
- .set(IsMaterials::getLoanState, 1)
|
|
|
|
|
- .set(IsMaterials::getStatus, 0));
|
|
|
|
|
- // 3.1 检查当前物资是否有未处理的错换柜子异常,如果有,现在已经还对了,默认处理掉异常信息
|
|
|
|
|
- List<IsMaterialsLoanException> exList = isMaterialsLoanExceptionService.list(Wrappers.<IsMaterialsLoanException>lambdaQuery()
|
|
|
|
|
- .eq(IsMaterialsLoanException::getMaterialsId, dto.getMaterialsId())
|
|
|
|
|
- .eq(IsMaterialsLoanException::getStatus, "0"));
|
|
|
|
|
- if (!exList.isEmpty()) {
|
|
|
|
|
- isMaterialsLoanExceptionService.update(Wrappers.<IsMaterialsLoanException>lambdaUpdate()
|
|
|
|
|
|
|
+ .eq(IsMaterials::getMaterialsId, dto.getMaterialsId())
|
|
|
|
|
+ .set(IsMaterials::getLoanState, 1)
|
|
|
|
|
+ .set(IsMaterials::getStatus, 0));
|
|
|
|
|
+ // 3.1 检查当前物资是否有未处理的错换柜子异常,如果有,现在已经还对了,默认处理掉异常信息
|
|
|
|
|
+ List<IsMaterialsLoanException> exList = isMaterialsLoanExceptionService.list(Wrappers.<IsMaterialsLoanException>lambdaQuery()
|
|
|
.eq(IsMaterialsLoanException::getMaterialsId, dto.getMaterialsId())
|
|
.eq(IsMaterialsLoanException::getMaterialsId, dto.getMaterialsId())
|
|
|
- .eq(IsMaterialsLoanException::getStatus, "0")
|
|
|
|
|
- .set(IsMaterialsLoanException::getStatus, "1")
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- // 5.检查邮件里面的数据发送了没有,没有发送就取消掉
|
|
|
|
|
- // 6.借用到期模板
|
|
|
|
|
- IsMailTemplate reminderTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
|
|
- .eq(IsMailTemplate::getTemplateCode, reminder));
|
|
|
|
|
- // 6.1取消未发送的邮件的发送
|
|
|
|
|
- IsMailTemplate alarmTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
|
|
- .eq(IsMailTemplate::getTemplateCode, alarm));
|
|
|
|
|
- if (reminderTemp != null) {
|
|
|
|
|
- iIsMailSendTaskItemService.update(Wrappers.<IsMailSendTaskItem>lambdaUpdate()
|
|
|
|
|
- .eq(IsMailSendTaskItem::getBelongId, loanList.get(0).getMaterialsLoanId())
|
|
|
|
|
- .eq(IsMailSendTaskItem::getEmailTemplateId, reminderTemp.getTemplateId())
|
|
|
|
|
- .eq(IsMailSendTaskItem::getSendStatus, "0")
|
|
|
|
|
- .set(IsMailSendTaskItem::getIsCancelled, "1")
|
|
|
|
|
- .set(IsMailSendTaskItem::getCancelTime, new Date()));
|
|
|
|
|
- }
|
|
|
|
|
- if (alarmTemp != null) {
|
|
|
|
|
- iIsMailSendTaskItemService.update(Wrappers.<IsMailSendTaskItem>lambdaUpdate()
|
|
|
|
|
- .eq(IsMailSendTaskItem::getBelongId, loanList.get(0).getMaterialsLoanId())
|
|
|
|
|
- .eq(IsMailSendTaskItem::getEmailTemplateId, alarmTemp.getTemplateId())
|
|
|
|
|
- .eq(IsMailSendTaskItem::getSendStatus, "0")
|
|
|
|
|
- .set(IsMailSendTaskItem::getIsCancelled, "1")
|
|
|
|
|
- .set(IsMailSendTaskItem::getCancelTime, new Date()));
|
|
|
|
|
|
|
+ .eq(IsMaterialsLoanException::getStatus, "0"));
|
|
|
|
|
+ if (!exList.isEmpty()) {
|
|
|
|
|
+ isMaterialsLoanExceptionService.update(Wrappers.<IsMaterialsLoanException>lambdaUpdate()
|
|
|
|
|
+ .eq(IsMaterialsLoanException::getMaterialsId, dto.getMaterialsId())
|
|
|
|
|
+ .eq(IsMaterialsLoanException::getStatus, "0")
|
|
|
|
|
+ .set(IsMaterialsLoanException::getStatus, "1")
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ // 5.检查邮件里面的数据发送了没有,没有发送就取消掉
|
|
|
|
|
+ // 6.借用到期模板
|
|
|
|
|
+ IsMailTemplate reminderTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
|
|
+ .eq(IsMailTemplate::getTemplateCode, reminder));
|
|
|
|
|
+ // 6.1取消未发送的邮件的发送
|
|
|
|
|
+ IsMailTemplate alarmTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
|
|
+ .eq(IsMailTemplate::getTemplateCode, alarm));
|
|
|
|
|
+ if (reminderTemp != null) {
|
|
|
|
|
+ iIsMailSendTaskItemService.update(Wrappers.<IsMailSendTaskItem>lambdaUpdate()
|
|
|
|
|
+ .eq(IsMailSendTaskItem::getBelongId, loanList.get(0).getMaterialsLoanId())
|
|
|
|
|
+ .eq(IsMailSendTaskItem::getEmailTemplateId, reminderTemp.getTemplateId())
|
|
|
|
|
+ .eq(IsMailSendTaskItem::getSendStatus, "0")
|
|
|
|
|
+ .set(IsMailSendTaskItem::getIsCancelled, "1")
|
|
|
|
|
+ .set(IsMailSendTaskItem::getCancelTime, new Date()));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (alarmTemp != null) {
|
|
|
|
|
+ iIsMailSendTaskItemService.update(Wrappers.<IsMailSendTaskItem>lambdaUpdate()
|
|
|
|
|
+ .eq(IsMailSendTaskItem::getBelongId, loanList.get(0).getMaterialsLoanId())
|
|
|
|
|
+ .eq(IsMailSendTaskItem::getEmailTemplateId, alarmTemp.getTemplateId())
|
|
|
|
|
+ .eq(IsMailSendTaskItem::getSendStatus, "0")
|
|
|
|
|
+ .set(IsMailSendTaskItem::getIsCancelled, "1")
|
|
|
|
|
+ .set(IsMailSendTaskItem::getCancelTime, new Date()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch ( Exception e) {
|
|
|
|
|
+ throw new Exception(e);
|
|
|
}
|
|
}
|
|
|
- return update;
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|