|
|
@@ -123,6 +123,7 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
|
|
|
/**
|
|
|
* 发送归还提醒
|
|
|
+ *
|
|
|
* @param messageId
|
|
|
*/
|
|
|
@Transactional
|
|
|
@@ -139,14 +140,14 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
// && materialsLoan.getActualRestitutionTime() == null
|
|
|
// && materialsLoan.getRestitutionToId() == null) {
|
|
|
if (!"1".equals(materialsLoan.getStatus())) {
|
|
|
- // 没有归还则需要开始新增提醒消息
|
|
|
+ // 没有归还则需要开始新增提醒消息
|
|
|
IsMaterials materials = isMaterialsService.getById(materialsLoan.getMaterialsId());
|
|
|
Map<String, Object> templateParams = new HashMap<>();
|
|
|
templateParams.put("借出时间", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(materialsLoan.getLoanTime()));
|
|
|
templateParams.put("物资", materials.getMaterialsName());
|
|
|
templateParams.put("归还时间", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(materialsLoan.getRestitutionTime()));
|
|
|
notifySendService.sendSingleNotifyToMember(materialsLoan.getLoanUserId(),
|
|
|
- "REMINDER_RETURN", templateParams);
|
|
|
+ "REMINDER_RETURN", templateParams);
|
|
|
|
|
|
// 存储到is_materials_reminder
|
|
|
IsMaterialsReminder isMaterialsReminder = new IsMaterialsReminder();
|
|
|
@@ -172,6 +173,7 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
|
|
|
/**
|
|
|
* 发送归还报警
|
|
|
+ *
|
|
|
* @param messageId
|
|
|
*/
|
|
|
@Transactional
|
|
|
@@ -215,8 +217,6 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 查询物资借出
|
|
|
*
|
|
|
@@ -311,128 +311,136 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
}*/
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public int insertIsMaterialsLoan(AddLoanDTO dto) {
|
|
|
- Date nowDate = DateUtils.getNowDate();
|
|
|
- IsMaterialsLoan isMaterialsLoan = BeanUtils.toBean(dto, IsMaterialsLoan.class);
|
|
|
- isMaterialsLoan.setLoanTime(nowDate);
|
|
|
- // 存储提醒倒计时和告警倒计时
|
|
|
- Date re = null;
|
|
|
- Date al = null;
|
|
|
- // 1.物资信息
|
|
|
- IsMaterials materials = isMaterialsService.getById(isMaterialsLoan.getMaterialsId());
|
|
|
- MaterialsTypePageVO materialsTypePageVO = new MaterialsTypePageVO();
|
|
|
- // 1.1如果是从错误柜子中拿出这个物资,默认是为了更正
|
|
|
- if ("0".equals(materials.getLoanState()) && "3".equals(materials.getStatus())) {
|
|
|
- // 1.1.1纠正归还异常
|
|
|
- isMaterialsLoanExceptionService.update(Wrappers.<IsMaterialsLoanException>lambdaUpdate()
|
|
|
- .eq(IsMaterialsLoanException::getMaterialsId, isMaterialsLoan.getMaterialsId())
|
|
|
- .set(IsMaterialsLoanException::getStatus, "1")
|
|
|
- .set(IsMaterialsLoanException::getHandleTime, nowDate));
|
|
|
- // 1.1.2纠正物资状态
|
|
|
- isMaterialsService.update(Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
- .eq(IsMaterials::getMaterialsId, dto.getMaterialsId())
|
|
|
- .set(IsMaterials::getStatus, "0"));
|
|
|
- return 1;
|
|
|
- }
|
|
|
- // 1.2借用到期规则
|
|
|
- IsMailNotifyConfig reminderConf = isMailNotifyConfigService.getOne(Wrappers.<IsMailNotifyConfig>lambdaQuery()
|
|
|
- .eq(IsMailNotifyConfig::getTemplateCode, reminder));
|
|
|
- IsMailTemplate reminderTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
- .eq(IsMailTemplate::getTemplateCode, reminder));
|
|
|
- // 1.3逾期时间规则
|
|
|
- IsMailNotifyConfig alarmConf = isMailNotifyConfigService.getOne(Wrappers.<IsMailNotifyConfig>lambdaQuery()
|
|
|
- .eq(IsMailNotifyConfig::getTemplateCode, alarm));
|
|
|
- IsMailTemplate alarmTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
- .eq(IsMailTemplate::getTemplateCode, alarm));
|
|
|
- // 1.4开始读取类型和规则,然后计算归还时间,提醒时间
|
|
|
- if (materials != null) {
|
|
|
- // 1.4.1填充字段
|
|
|
- materialsTypePageVO = isMaterialsTypeService.selectIsMaterialsTypeByMaterialsTypeId(materials.getMaterialsTypeId());
|
|
|
- isMaterialsLoan.setLoanFromId(materials.getMaterialsCabinetId());
|
|
|
- if (materialsTypePageVO != null) {
|
|
|
- // 1.5填充字段
|
|
|
- isMaterialsLoan.setRestitutionRequired(materialsTypePageVO.getRestitutionRequired());
|
|
|
- // 1.6如果需要归还,则开始计算时间
|
|
|
- if (materialsTypePageVO.getRestitutionRequired() != null && materialsTypePageVO.getRestitutionRequired().equals(1)) {
|
|
|
- // 1.6.1如果借用到期有数据,则开始计算
|
|
|
- if (reminderTemp != null
|
|
|
- && reminderConf != null
|
|
|
- && "1".equals(reminderConf.getStatus())
|
|
|
- && reminderConf.getReminderTime() != null
|
|
|
- && reminderConf.getReminderTime() > 0) {
|
|
|
- // 计算提醒时间
|
|
|
- re = DateUtils.getNewDateTime(nowDate, reminderConf.getReminderTime());
|
|
|
- isMaterialsLoan.setReminderTime(re);
|
|
|
- isMaterialsLoan.setRestitutionTime(re);
|
|
|
- }
|
|
|
- // 1.6.2逾期时间规则
|
|
|
- if (alarmTemp != null
|
|
|
- && alarmConf != null
|
|
|
- && "1".equals(alarmConf.getStatus())
|
|
|
- && alarmConf.getReminderTime() != null
|
|
|
- && alarmConf.getReminderTime() > 0) {
|
|
|
- // 计算告警时间
|
|
|
- al = DateUtils.getNewDateTime(nowDate, alarmConf.getReminderTime());
|
|
|
- isMaterialsLoan.setTimeoutAlarm(al);
|
|
|
+ public int insertIsMaterialsLoan(AddLoanDTO dto) throws Exception {
|
|
|
+ try {
|
|
|
+ // 检测如果已经有一条借出,则提示异常
|
|
|
+ List<IsMaterialsLoan> loanList = list(Wrappers.<IsMaterialsLoan>lambdaQuery()
|
|
|
+ .eq(IsMaterialsLoan::getMaterialsId, dto.getMaterialsId())
|
|
|
+ .ne(IsMaterialsLoan::getStatus, "1"));
|
|
|
+ Assert.isTrue(loanList.isEmpty(), "该物资存在多条借出记录!");
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ IsMaterialsLoan isMaterialsLoan = BeanUtils.toBean(dto, IsMaterialsLoan.class);
|
|
|
+ isMaterialsLoan.setLoanTime(nowDate);
|
|
|
+ // 存储提醒倒计时和告警倒计时
|
|
|
+ Date re = null;
|
|
|
+ Date al = null;
|
|
|
+ // 1.物资信息
|
|
|
+ IsMaterials materials = isMaterialsService.getById(isMaterialsLoan.getMaterialsId());
|
|
|
+ MaterialsTypePageVO materialsTypePageVO = new MaterialsTypePageVO();
|
|
|
+ // 1.1如果是从错误柜子中拿出这个物资,默认是为了更正
|
|
|
+ if ("0".equals(materials.getLoanState()) && "3".equals(materials.getStatus())) {
|
|
|
+ // 1.1.1纠正归还异常
|
|
|
+ isMaterialsLoanExceptionService.update(Wrappers.<IsMaterialsLoanException>lambdaUpdate()
|
|
|
+ .eq(IsMaterialsLoanException::getMaterialsId, isMaterialsLoan.getMaterialsId())
|
|
|
+ .set(IsMaterialsLoanException::getStatus, "1")
|
|
|
+ .set(IsMaterialsLoanException::getHandleTime, nowDate));
|
|
|
+ // 1.1.2纠正物资状态
|
|
|
+ isMaterialsService.update(Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
+ .eq(IsMaterials::getMaterialsId, dto.getMaterialsId())
|
|
|
+ .set(IsMaterials::getStatus, "0"));
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ // 1.2借用到期规则
|
|
|
+ IsMailNotifyConfig reminderConf = isMailNotifyConfigService.getOne(Wrappers.<IsMailNotifyConfig>lambdaQuery()
|
|
|
+ .eq(IsMailNotifyConfig::getTemplateCode, reminder));
|
|
|
+ IsMailTemplate reminderTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
+ .eq(IsMailTemplate::getTemplateCode, reminder));
|
|
|
+ // 1.3逾期时间规则
|
|
|
+ IsMailNotifyConfig alarmConf = isMailNotifyConfigService.getOne(Wrappers.<IsMailNotifyConfig>lambdaQuery()
|
|
|
+ .eq(IsMailNotifyConfig::getTemplateCode, alarm));
|
|
|
+ IsMailTemplate alarmTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
+ .eq(IsMailTemplate::getTemplateCode, alarm));
|
|
|
+ // 1.4开始读取类型和规则,然后计算归还时间,提醒时间
|
|
|
+ if (materials != null) {
|
|
|
+ // 1.4.1填充字段
|
|
|
+ materialsTypePageVO = isMaterialsTypeService.selectIsMaterialsTypeByMaterialsTypeId(materials.getMaterialsTypeId());
|
|
|
+ isMaterialsLoan.setLoanFromId(materials.getMaterialsCabinetId());
|
|
|
+ if (materialsTypePageVO != null) {
|
|
|
+ // 1.5填充字段
|
|
|
+ isMaterialsLoan.setRestitutionRequired(materialsTypePageVO.getRestitutionRequired());
|
|
|
+ // 1.6如果需要归还,则开始计算时间
|
|
|
+ if (materialsTypePageVO.getRestitutionRequired() != null && materialsTypePageVO.getRestitutionRequired().equals(1)) {
|
|
|
+ // 1.6.1如果借用到期有数据,则开始计算
|
|
|
+ if (reminderTemp != null
|
|
|
+ && reminderConf != null
|
|
|
+ && "1".equals(reminderConf.getStatus())
|
|
|
+ && reminderConf.getReminderTime() != null
|
|
|
+ && reminderConf.getReminderTime() > 0) {
|
|
|
+ // 计算提醒时间
|
|
|
+ re = DateUtils.getNewDateTime(nowDate, reminderConf.getReminderTime());
|
|
|
+ isMaterialsLoan.setReminderTime(re);
|
|
|
+ isMaterialsLoan.setRestitutionTime(re);
|
|
|
+ }
|
|
|
+ // 1.6.2逾期时间规则
|
|
|
+ if (alarmTemp != null
|
|
|
+ && alarmConf != null
|
|
|
+ && "1".equals(alarmConf.getStatus())
|
|
|
+ && alarmConf.getReminderTime() != null
|
|
|
+ && alarmConf.getReminderTime() > 0) {
|
|
|
+ // 计算告警时间
|
|
|
+ al = DateUtils.getNewDateTime(nowDate, alarmConf.getReminderTime());
|
|
|
+ isMaterialsLoan.setTimeoutAlarm(al);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- int i = isMaterialsLoanMapper.insertIsMaterialsLoan(isMaterialsLoan);
|
|
|
- // 2.邮件的发送
|
|
|
- if (materialsTypePageVO != null && materialsTypePageVO.getRestitutionRequired().equals(1) && materials != null) {
|
|
|
- // 2.1获取收件人
|
|
|
- SysUser user = iSysUserService.getById(isMaterialsLoan.getLoanUserId());
|
|
|
- Assert.isFalse(user == null, "当前用户信息不存在!");
|
|
|
- IsMaterialsCabinet cabinet = iIsMaterialsCabinetService.getById(materials.getMaterialsCabinetId());
|
|
|
- // 2.2整理可配置的字段
|
|
|
- // [收件人],[物资名称],[借用时间],[到期时间],[告警时间],[归还地址],[邮件发送日期]
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("[收件人]", user.getNickName());
|
|
|
- map.put("[物资名称]", materials.getMaterialsName());
|
|
|
- map.put("[借用时间]", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, nowDate));
|
|
|
- map.put("[到期时间]", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, re));
|
|
|
- map.put("[告警时间]", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, al));
|
|
|
- map.put("[归还地址]", cabinet.getCabinetName());
|
|
|
- map.put("[发件人]", sendName);
|
|
|
- map.put("[公司名称]", company);
|
|
|
- // 2.3处理归还提醒
|
|
|
- if (isMaterialsLoan.getReminderTime() != null && reminderConf != null && "1".equals(reminderConf.getStatus())) {
|
|
|
- System.out.println("设置借用提醒邮件");
|
|
|
- // 邮件实体
|
|
|
- IsMailSendTaskItem taskItem = new IsMailSendTaskItem();
|
|
|
- taskItem.setSendToUserId(dto.getLoanUserId());
|
|
|
- taskItem.setEmailTemplateId(reminderTemp.getTemplateId());
|
|
|
- taskItem.setScheduledSendTime(re);
|
|
|
- taskItem.setBelongId(isMaterialsLoan.getMaterialsLoanId());
|
|
|
- taskItem.setSendStatus(0);
|
|
|
- taskItem.setIsCancelled(0);
|
|
|
- iIsMailSendTaskItemService.insertIsMailSendTaskItem(taskItem, map);
|
|
|
- }
|
|
|
- // 2.4处理归还告警
|
|
|
- if (isMaterialsLoan.getTimeoutAlarm() != null && alarmConf != null && "1".equals(alarmConf.getStatus())) {
|
|
|
- System.out.println("设置借用告警邮件");
|
|
|
- // 邮件实体
|
|
|
- IsMailSendTaskItem taskItem = new IsMailSendTaskItem();
|
|
|
- taskItem.setSendToUserId(dto.getLoanUserId());
|
|
|
- taskItem.setEmailTemplateId(alarmTemp.getTemplateId());
|
|
|
- taskItem.setScheduledSendTime(al);
|
|
|
- taskItem.setBelongId(isMaterialsLoan.getMaterialsLoanId());
|
|
|
- taskItem.setSendStatus(0);
|
|
|
- taskItem.setIsCancelled(0);
|
|
|
- iIsMailSendTaskItemService.insertIsMailSendTaskItem(taskItem, map);
|
|
|
+ int i = isMaterialsLoanMapper.insertIsMaterialsLoan(isMaterialsLoan);
|
|
|
+ // 2.邮件的发送
|
|
|
+ if (materialsTypePageVO != null && materialsTypePageVO.getRestitutionRequired().equals(1) && materials != null) {
|
|
|
+ // 2.1获取收件人
|
|
|
+ SysUser user = iSysUserService.getById(isMaterialsLoan.getLoanUserId());
|
|
|
+ Assert.isFalse(user == null, "当前用户信息不存在!");
|
|
|
+ IsMaterialsCabinet cabinet = iIsMaterialsCabinetService.getById(materials.getMaterialsCabinetId());
|
|
|
+ // 2.2整理可配置的字段
|
|
|
+ // [收件人],[物资名称],[借用时间],[到期时间],[告警时间],[归还地址],[邮件发送日期]
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("[收件人]", user.getNickName());
|
|
|
+ map.put("[物资名称]", materials.getMaterialsName());
|
|
|
+ map.put("[借用时间]", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, nowDate));
|
|
|
+ map.put("[到期时间]", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, re));
|
|
|
+ map.put("[告警时间]", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, al));
|
|
|
+ map.put("[归还地址]", cabinet.getCabinetName());
|
|
|
+ map.put("[发件人]", sendName);
|
|
|
+ map.put("[公司名称]", company);
|
|
|
+ // 2.3处理归还提醒
|
|
|
+ if (isMaterialsLoan.getReminderTime() != null && reminderConf != null && "1".equals(reminderConf.getStatus())) {
|
|
|
+ System.out.println("设置借用提醒邮件");
|
|
|
+ // 邮件实体
|
|
|
+ IsMailSendTaskItem taskItem = new IsMailSendTaskItem();
|
|
|
+ taskItem.setSendToUserId(dto.getLoanUserId());
|
|
|
+ taskItem.setEmailTemplateId(reminderTemp.getTemplateId());
|
|
|
+ taskItem.setScheduledSendTime(re);
|
|
|
+ taskItem.setBelongId(isMaterialsLoan.getMaterialsLoanId());
|
|
|
+ taskItem.setSendStatus(0);
|
|
|
+ taskItem.setIsCancelled(0);
|
|
|
+ iIsMailSendTaskItemService.insertIsMailSendTaskItem(taskItem, map);
|
|
|
+ }
|
|
|
+ // 2.4处理归还告警
|
|
|
+ if (isMaterialsLoan.getTimeoutAlarm() != null && alarmConf != null && "1".equals(alarmConf.getStatus())) {
|
|
|
+ System.out.println("设置借用告警邮件");
|
|
|
+ // 邮件实体
|
|
|
+ IsMailSendTaskItem taskItem = new IsMailSendTaskItem();
|
|
|
+ taskItem.setSendToUserId(dto.getLoanUserId());
|
|
|
+ taskItem.setEmailTemplateId(alarmTemp.getTemplateId());
|
|
|
+ taskItem.setScheduledSendTime(al);
|
|
|
+ taskItem.setBelongId(isMaterialsLoan.getMaterialsLoanId());
|
|
|
+ taskItem.setSendStatus(0);
|
|
|
+ taskItem.setIsCancelled(0);
|
|
|
+ iIsMailSendTaskItemService.insertIsMailSendTaskItem(taskItem, map);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 2.开始更新物资信息为借出状态
|
|
|
- LambdaUpdateWrapper<IsMaterials> set = Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
- .eq(IsMaterials::getMaterialsId, isMaterialsLoan.getMaterialsId())
|
|
|
- .set(IsMaterials::getLoanState, 0);
|
|
|
- if (materials != null && materials.getAvailableTimes() != null) {
|
|
|
- set.set(IsMaterials::getLoanState, materials.getAvailableTimes() - 1);
|
|
|
+ // 2.开始更新物资信息为借出状态
|
|
|
+ LambdaUpdateWrapper<IsMaterials> set = Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
+ .eq(IsMaterials::getMaterialsId, isMaterialsLoan.getMaterialsId())
|
|
|
+ .set(IsMaterials::getLoanState, 0);
|
|
|
+ if (materials != null && materials.getAvailableTimes() != null) {
|
|
|
+ set.set(IsMaterials::getLoanState, materials.getAvailableTimes() - 1);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception(e);
|
|
|
}
|
|
|
- return i;
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
// 格式化日期时间的方法
|
|
|
@@ -571,7 +579,7 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
.set(IsMailSendTaskItem::getIsCancelled, "1")
|
|
|
.set(IsMailSendTaskItem::getCancelTime, new Date()));
|
|
|
}
|
|
|
- } catch ( Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
throw new Exception(e);
|
|
|
}
|
|
|
return true;
|