|
@@ -15,11 +15,13 @@ import com.rongwe.scentity.vo.CheckItemsTypeVo;
|
|
|
import com.rongwe.scentity.vo.ImportCheckItemsVo;
|
|
|
import com.rongwe.scentity.vo.UserMailOrgVo;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
|
+import com.rongwei.rwadmincommon.system.service.SysConfigFeignService;
|
|
|
import com.rongwei.rwadmincommon.system.service.impl.SysDictServiceImpl;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import com.rongwei.rwcommon.vo.MailDo;
|
|
|
import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
import com.rongwei.safecommon.utils.CXCommonUtils;
|
|
|
import com.rongwei.sfcommon.sys.dao.CheckItemsDao;
|
|
@@ -35,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
@@ -57,6 +60,7 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
public static final List<String> ROLE_CODE_LIST = new ArrayList<String>() {{
|
|
|
add("code-safe");
|
|
|
add("role031");
|
|
|
+ add("produce");
|
|
|
}};
|
|
|
// 设备使用状态数据字典
|
|
|
public static final String SBSYZT_DICT = "sbsyzt";
|
|
@@ -91,6 +95,8 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
private SysDictServiceImpl sysDictService;
|
|
|
@Autowired
|
|
|
private ClassExcelVerifyHandler verifyHandler;
|
|
|
+ @Resource
|
|
|
+ private SysConfigFeignService sysConfigFeignService;
|
|
|
|
|
|
/**
|
|
|
* 设备列表删除验证是否存在点检记录
|
|
@@ -182,7 +188,7 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
|
|
|
@Override
|
|
|
public R stateUpdateScheduledTasks() {
|
|
|
- // 获取所有的安全附件
|
|
|
+ // 获取所有的特种设备
|
|
|
List<CheckItemsDo> safeAttachmentsDos = this.list(new LambdaQueryWrapper<CheckItemsDo>().eq(CheckItemsDo::getSource, 1));
|
|
|
if (safeAttachmentsDos.isEmpty()) {
|
|
|
return R.ok("暂无设备需要检验");
|
|
@@ -192,9 +198,19 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
List<CheckItemsDo> saveData = new ArrayList<>();
|
|
|
// 发送消息提醒的参数
|
|
|
Map<CheckItemsDo, List<String>> sendNotifyMap = new HashMap<CheckItemsDo, List<String>>();
|
|
|
+ // 发送邮件的集合《用户ID,List<设备信息>》
|
|
|
+ Map<String, List<CheckItemsDo>> sendMailMap = new HashMap<>();
|
|
|
+ // 用户的信息集合
|
|
|
+ Map<String, UserMailOrgVo> userMap = new HashMap<>();
|
|
|
dataMap.forEach((k, v) -> {
|
|
|
- //获取工厂对应的 安全管理员和特种设备管理员
|
|
|
+ //获取工厂对应的 安全管理员和特种设备管理员 和生产副总
|
|
|
List<UserMailOrgVo> userInfO = saveCheckCommonDao.getUserInfoByTenantIdAndRoleCode(k, ROLE_CODE_LIST);
|
|
|
+ for (UserMailOrgVo userMailOrgVo : userInfO) {
|
|
|
+ if (ObjectUtil.isNotEmpty(userMailOrgVo.getEmail())) {
|
|
|
+ sendMailMap.put(userMailOrgVo.getId(), new LinkedList<>());
|
|
|
+ userMap.put(userMailOrgVo.getId(), userMailOrgVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
Date manufacturedate;
|
|
|
long daysBetween;
|
|
|
List<String> alertUser;
|
|
@@ -208,10 +224,20 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
data.setReminderstate(HIGH);
|
|
|
alertUser = userInfO.stream().map(UserMailOrgVo::getId).collect(Collectors.toList());
|
|
|
sendNotifyMap.put(data, alertUser);
|
|
|
+ for (String userId : alertUser) {
|
|
|
+ if (sendMailMap.containsKey(userId)) {
|
|
|
+ sendMailMap.get(userId).add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else if (daysBetween <= 90) {
|
|
|
alertUser = userInfO.stream().filter(user -> SPECIAL_EQUIPMENT_ADMINISTRATOR.equals(user.getRoleCode())).map(UserMailOrgVo::getId).collect(Collectors.toList());
|
|
|
sendNotifyMap.put(data, alertUser);
|
|
|
data.setReminderstate(MIDDLE);
|
|
|
+ for (String userId : alertUser) {
|
|
|
+ if (sendMailMap.containsKey(userId)) {
|
|
|
+ sendMailMap.get(userId).add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
data.setReminderstate(LOW);
|
|
|
}
|
|
@@ -221,9 +247,58 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
});
|
|
|
this.updateBatchById(saveData);
|
|
|
sendNotify(sendNotifyMap);
|
|
|
+
|
|
|
+ sendMail(sendMailMap, userMap);
|
|
|
+
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ private void sendMail(Map<String, List<CheckItemsDo>> sendMailMap, Map<String, UserMailOrgVo> userMap) {
|
|
|
+ if (ObjectUtil.isEmpty(sendMailMap)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取数据字典
|
|
|
+ List<SysDictDo> aspCheckItemType = sysDictService.getDictsByType("asp_check_item_type");
|
|
|
+ sendMailMap.forEach((key, value) -> {
|
|
|
+ if (ObjectUtil.isEmpty(value)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringBuilder mailContent = new StringBuilder("您好!有如下特种设备即将年检到期,请及时处理!\n");
|
|
|
+ for (int i = 0; i < value.size(); i++) {
|
|
|
+ CheckItemsDo checkItemsDo = value.get(i);
|
|
|
+
|
|
|
+ SysDictDo sysDictDo = aspCheckItemType.stream().filter(info -> info.getValue().equals(checkItemsDo.getCheckitemtype())).findFirst().orElse(null);
|
|
|
+ //设备类型
|
|
|
+ String checkitemtype = "";
|
|
|
+ if (ObjectUtil.isNotEmpty(sysDictDo) && ObjectUtil.isNotEmpty(checkItemsDo.getCheckitemtype())) {
|
|
|
+ checkitemtype = sysDictDo.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ //设备编号
|
|
|
+ String deviceoutcode = ObjectUtil.isNotEmpty(checkItemsDo.getDeviceoutcode()) ? checkItemsDo.getDeviceoutcode() : "";
|
|
|
+ //设备名称
|
|
|
+ String checkitemname = ObjectUtil.isNotEmpty(checkItemsDo.getCheckitemname()) ? checkItemsDo.getCheckitemname() : "";
|
|
|
+ //检验日期
|
|
|
+ Date devicecheckdate = checkItemsDo.getDevicecheckdate();
|
|
|
+ String checkDate = "";
|
|
|
+ if (ObjectUtil.isNotEmpty(devicecheckdate)) {
|
|
|
+ checkDate = DateUtil.format(devicecheckdate, "yyyy-MM-dd");
|
|
|
+ }
|
|
|
+ mailContent.append((i + 1) + "、设备类型:【" + checkitemtype + "】,设备编号:【" + deviceoutcode + "】,设备名称:【" + checkitemname + "】,检验日期:【" + checkDate + "】\n");
|
|
|
+ }
|
|
|
+ mailContent.append("详见安全生产平台,如果无法点击请复制链接到浏览器中:http://192.168.100.78/#/page/lr/9329c07dd31b4b8b95d4decaa021adc3");
|
|
|
+
|
|
|
+ //发送邮件
|
|
|
+ MailDo mailDo = new MailDo();
|
|
|
+ mailDo.setSubject("特种设备年检提醒");
|
|
|
+ mailDo.setReceiveEmail(new String[]{userMap.get(key).getEmail()});
|
|
|
+ mailDo.setNeedTransReceive(false);
|
|
|
+ mailDo.setContent(mailContent.toString());
|
|
|
+ sysConfigFeignService.sendTextMail(mailDo);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public void sendNotify(Map<CheckItemsDo, List<String>> sendNotifyMap) {
|
|
|
if (sendNotifyMap.isEmpty()) {
|
|
|
return;
|
|
@@ -235,7 +310,7 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
|
|
|
// 发送消息提醒
|
|
|
CXCommonUtils.sendNotify(EQUIPMENT_CHECK_TITLE,
|
|
|
- String.format(EQUIPMENT_CHECK_CONTENT, sysDictDo == null ? "" : sysDictDo.getName(), k.getCheckitemcode(), k.getCheckitemname(),
|
|
|
+ String.format(EQUIPMENT_CHECK_CONTENT, sysDictDo == null ? "" : sysDictDo.getName(), k.getDeviceoutcode(), k.getCheckitemname(),
|
|
|
k.getNextcheckdate()), null, v.stream().distinct().collect(Collectors.toList()),
|
|
|
k.getId(), SPECIALEQUIPMENT, false);
|
|
|
});
|