|
@@ -5,13 +5,12 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.ktg.common.core.domain.entity.SysUser;
|
|
|
import com.ktg.common.core.redis.RedisCache;
|
|
import com.ktg.common.core.redis.RedisCache;
|
|
|
import com.ktg.common.core.text.Convert;
|
|
import com.ktg.common.core.text.Convert;
|
|
|
import com.ktg.common.utils.DateUtils;
|
|
import com.ktg.common.utils.DateUtils;
|
|
|
import com.ktg.common.utils.bean.BeanUtils;
|
|
import com.ktg.common.utils.bean.BeanUtils;
|
|
|
-import com.ktg.iscs.domain.IsMaterials;
|
|
|
|
|
-import com.ktg.iscs.domain.IsMaterialsLoan;
|
|
|
|
|
-import com.ktg.iscs.domain.IsMaterialsReminder;
|
|
|
|
|
|
|
+import com.ktg.iscs.domain.*;
|
|
|
import com.ktg.iscs.domain.dto.materialsLoan.AddLoanDTO;
|
|
import com.ktg.iscs.domain.dto.materialsLoan.AddLoanDTO;
|
|
|
import com.ktg.iscs.domain.dto.materialsLoan.MaterialsLoanPageDTO;
|
|
import com.ktg.iscs.domain.dto.materialsLoan.MaterialsLoanPageDTO;
|
|
|
import com.ktg.iscs.domain.dto.materialsLoan.ReminderPageDTO;
|
|
import com.ktg.iscs.domain.dto.materialsLoan.ReminderPageDTO;
|
|
@@ -20,20 +19,21 @@ import com.ktg.iscs.domain.vo.materialsLoan.MaterialsLoanPageVO;
|
|
|
import com.ktg.iscs.domain.vo.materialsLoan.ReminderPageVO;
|
|
import com.ktg.iscs.domain.vo.materialsLoan.ReminderPageVO;
|
|
|
import com.ktg.iscs.domain.vo.materialsType.MaterialsTypePageVO;
|
|
import com.ktg.iscs.domain.vo.materialsType.MaterialsTypePageVO;
|
|
|
import com.ktg.iscs.mapper.IsMaterialsLoanMapper;
|
|
import com.ktg.iscs.mapper.IsMaterialsLoanMapper;
|
|
|
-import com.ktg.iscs.service.IIsMaterialsLoanService;
|
|
|
|
|
-import com.ktg.iscs.service.IIsMaterialsReminderService;
|
|
|
|
|
-import com.ktg.iscs.service.IIsMaterialsService;
|
|
|
|
|
-import com.ktg.iscs.service.IIsMaterialsTypeService;
|
|
|
|
|
|
|
+import com.ktg.iscs.service.*;
|
|
|
|
|
+import com.ktg.system.service.ISysUserService;
|
|
|
import com.ktg.system.service.NotifySendService;
|
|
import com.ktg.system.service.NotifySendService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
@@ -57,10 +57,26 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
private NotifySendService notifySendService;
|
|
private NotifySendService notifySendService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IIsMaterialsReminderService iIsMaterialsReminderService;
|
|
private IIsMaterialsReminderService iIsMaterialsReminderService;
|
|
|
-
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIsMailTemplateService iIsMailTemplateService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIsMailNotifyConfigService isMailNotifyConfigService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIsMailSendTaskItemService iIsMailSendTaskItemService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IIsMaterialsCabinetService iIsMaterialsCabinetService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ISysUserService iSysUserService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
-
|
|
|
|
|
|
|
+ @Value("${mail.reminder}")
|
|
|
|
|
+ private String reminder;
|
|
|
|
|
+ @Value("${mail.alarm}")
|
|
|
|
|
+ private String alarm;
|
|
|
|
|
+ @Value("${mail.name}")
|
|
|
|
|
+ private String sendName;
|
|
|
|
|
+ @Value("${mail.company}")
|
|
|
|
|
+ private String company;
|
|
|
private final ConcurrentHashMap<String, Long> messages = new ConcurrentHashMap<>();
|
|
private final ConcurrentHashMap<String, Long> messages = new ConcurrentHashMap<>();
|
|
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
|
|
|
|
|
|
@@ -71,7 +87,7 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
private static final String ALARM = "alarm";
|
|
private static final String ALARM = "alarm";
|
|
|
|
|
|
|
|
|
|
|
|
|
- @PostConstruct
|
|
|
|
|
|
|
+ /*@PostConstruct
|
|
|
public void init() {
|
|
public void init() {
|
|
|
// 在这里编写你的初始化代码
|
|
// 在这里编写你的初始化代码
|
|
|
System.out.println("项目启动时执行一次的方法");
|
|
System.out.println("项目启动时执行一次的方法");
|
|
@@ -90,7 +106,7 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
alarmMessage(materialsLoanId, delayInSeconds);
|
|
alarmMessage(materialsLoanId, delayInSeconds);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
public void reminderMessage(long materialsLoanId, long delayInSeconds) {
|
|
public void reminderMessage(long materialsLoanId, long delayInSeconds) {
|
|
|
String messageId = REMINDER + materialsLoanId;
|
|
String messageId = REMINDER + materialsLoanId;
|
|
@@ -227,7 +243,7 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
* @param dto 物资借出
|
|
* @param dto 物资借出
|
|
|
* @return 结果
|
|
* @return 结果
|
|
|
*/
|
|
*/
|
|
|
- @Transactional
|
|
|
|
|
|
|
+ /*@Transactional
|
|
|
@Override
|
|
@Override
|
|
|
public int insertIsMaterialsLoan(AddLoanDTO dto) {
|
|
public int insertIsMaterialsLoan(AddLoanDTO dto) {
|
|
|
Date nowDate = DateUtils.getNowDate();
|
|
Date nowDate = DateUtils.getNowDate();
|
|
@@ -282,6 +298,118 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }*/
|
|
|
|
|
+ @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.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) {
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ 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.开始更新物资信息为借出状态
|
|
// 2.开始更新物资信息为借出状态
|
|
|
LambdaUpdateWrapper<IsMaterials> set = Wrappers.<IsMaterials>lambdaUpdate()
|
|
LambdaUpdateWrapper<IsMaterials> set = Wrappers.<IsMaterials>lambdaUpdate()
|
|
|
.eq(IsMaterials::getMaterialsId, isMaterialsLoan.getMaterialsId())
|
|
.eq(IsMaterials::getMaterialsId, isMaterialsLoan.getMaterialsId())
|
|
@@ -373,8 +501,31 @@ public class IsMaterialsLoanServiceImpl extends ServiceImpl<IsMaterialsLoanMappe
|
|
|
.eq(IsMaterials::getMaterialsId, dto.getMaterialsId())
|
|
.eq(IsMaterials::getMaterialsId, dto.getMaterialsId())
|
|
|
.set(IsMaterials::getLoanState, 1));
|
|
.set(IsMaterials::getLoanState, 1));
|
|
|
// 4.清除缓存
|
|
// 4.清除缓存
|
|
|
- redisCache.deleteObject(MATERIALS_LOAN + REMINDER + loanList.get(0).getMaterialsLoanId());
|
|
|
|
|
- redisCache.deleteObject(MATERIALS_LOAN + ALARM + loanList.get(0).getMaterialsLoanId());
|
|
|
|
|
|
|
+ // redisCache.deleteObject(MATERIALS_LOAN + REMINDER + loanList.get(0).getMaterialsLoanId());
|
|
|
|
|
+ // redisCache.deleteObject(MATERIALS_LOAN + ALARM + loanList.get(0).getMaterialsLoanId());
|
|
|
|
|
+ // 5.检查邮件里面的数据发送了没有,没有发送就取消掉
|
|
|
|
|
+ // 1.2借用到期模板
|
|
|
|
|
+ IsMailTemplate reminderTemp = iIsMailTemplateService.getOne(Wrappers.<IsMailTemplate>lambdaQuery()
|
|
|
|
|
+ .eq(IsMailTemplate::getTemplateCode, reminder));
|
|
|
|
|
+ // 1.3逾期时间模板
|
|
|
|
|
+ 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()));
|
|
|
|
|
+ }
|
|
|
return update;
|
|
return update;
|
|
|
}
|
|
}
|
|
|
|
|
|