|
@@ -2,35 +2,62 @@ package com.rongwei.sfcommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwe.scentity.domian.CheckItemsDo;
|
|
|
import com.rongwe.scentity.domian.PointCheckDo;
|
|
|
import com.rongwe.scentity.vo.CheckItemsTypeVo;
|
|
|
+import com.rongwe.scentity.vo.UserMailOrgVo;
|
|
|
+import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
|
+import com.rongwei.rwadmincommon.system.service.impl.SysDictServiceImpl;
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.safecommon.utils.CXCommonUtils;
|
|
|
import com.rongwei.sfcommon.sys.dao.CheckItemsDao;
|
|
|
+import com.rongwei.sfcommon.sys.dao.SaveCheckCommonDao;
|
|
|
import com.rongwei.sfcommon.sys.service.CheckItemsService;
|
|
|
import com.rongwei.sfcommon.sys.service.PointCheckService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import static com.rongwei.safecommon.utils.SaveConstans.NotifyContent.SPECIALEQUIPMENT_CONTENT;
|
|
|
-import static com.rongwei.safecommon.utils.SaveConstans.NotifyContent.SPECIALEQUIPMENT_CONTENT_PREFIX;
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.*;
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.NotifyContent.*;
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.NotifyTitle.EQUIPMENT_CHECK_TITLE;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyTitle.SPECIALEQUIPMENT_TITLE;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.SPECIALEQUIPMENT;
|
|
|
|
|
|
@Service("checkItemsService")
|
|
|
public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItemsDo> implements CheckItemsService {
|
|
|
|
|
|
+ /**
|
|
|
+ * 组织机构代码
|
|
|
+ */
|
|
|
+ public static final List<String> ROLE_CODE_LIST = new ArrayList<String>() {{
|
|
|
+ add("code-safe");
|
|
|
+ add("role031");
|
|
|
+ }};
|
|
|
+ /**
|
|
|
+ * 特种设备管理员
|
|
|
+ */
|
|
|
+ public static final String SPECIAL_EQUIPMENT_ADMINISTRATOR = "role031";
|
|
|
@Autowired
|
|
|
+ @Lazy
|
|
|
private PointCheckService pointCheckService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private CheckItemsDao checkItemsDao;
|
|
|
+ @Autowired
|
|
|
+ private SaveCheckCommonDao saveCheckCommonDao;
|
|
|
+ @Autowired
|
|
|
+ private SysDictServiceImpl sysDictService;
|
|
|
|
|
|
/**
|
|
|
* 设备列表删除验证是否存在点检记录
|
|
@@ -109,7 +136,7 @@ public class CheckItemsServiceImpl extends ServiceImpl<CheckItemsDao, CheckItems
|
|
|
|
|
|
//发送消息
|
|
|
CXCommonUtils.sendNotify(SPECIALEQUIPMENT_TITLE,
|
|
|
- SPECIALEQUIPMENT_CONTENT_PREFIX + String.format(SPECIALEQUIPMENT_CONTENT,typeName,checkItemCode,checkItemName,nextCheckDate),
|
|
|
+ SPECIALEQUIPMENT_CONTENT_PREFIX + String.format(SPECIALEQUIPMENT_CONTENT, typeName, checkItemCode, checkItemName, nextCheckDate),
|
|
|
null,
|
|
|
equManager.get(item.getTenantid()),
|
|
|
item.getId(),
|
|
@@ -120,4 +147,64 @@ 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("暂无设备需要检验");
|
|
|
+ }
|
|
|
+ // 对数据按照租户ID 分组
|
|
|
+ Map<String, List<CheckItemsDo>> dataMap = safeAttachmentsDos.stream().collect(Collectors.groupingBy(CheckItemsDo::getTenantid));
|
|
|
+ List<CheckItemsDo> saveData = new ArrayList<>();
|
|
|
+ // 发送消息提醒的参数
|
|
|
+ Map<CheckItemsDo, List<String>> sendNotifyMap = new HashMap<CheckItemsDo, List<String>>();
|
|
|
+ dataMap.forEach((k, v) -> {
|
|
|
+ //获取工厂对应的 安全管理员和特种设备管理员
|
|
|
+ List<UserMailOrgVo> userInfO = saveCheckCommonDao.getUserInfoByTenantIdAndRoleCode(k, ROLE_CODE_LIST);
|
|
|
+ Date manufacturedate;
|
|
|
+ long daysBetween;
|
|
|
+ List<String> alertUser;
|
|
|
+ for (CheckItemsDo data : v) {
|
|
|
+ manufacturedate = data.getNextcheckdate();
|
|
|
+ LocalDate date1 = manufacturedate.toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDate();
|
|
|
+ daysBetween = ChronoUnit.DAYS.between(LocalDate.now(), date1);
|
|
|
+ if (daysBetween <= 30) {
|
|
|
+ data.setReminderstate(HIGH);
|
|
|
+ alertUser = userInfO.stream().map(UserMailOrgVo::getId).collect(Collectors.toList());
|
|
|
+ sendNotifyMap.put(data, alertUser);
|
|
|
+ } 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);
|
|
|
+ } else {
|
|
|
+ data.setReminderstate(LOW);
|
|
|
+ }
|
|
|
+
|
|
|
+ saveData.add(data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.updateBatchById(saveData);
|
|
|
+ sendNotify(sendNotifyMap);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendNotify(Map<CheckItemsDo, List<String>> sendNotifyMap) {
|
|
|
+ if (sendNotifyMap.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取数据字典
|
|
|
+ List<SysDictDo> aspCheckItemType = sysDictService.getDictsByType("asp_check_item_type");
|
|
|
+ sendNotifyMap.forEach((k, v) -> {
|
|
|
+ SysDictDo sysDictDo = aspCheckItemType.stream().filter(info -> info.getValue().equals(k.getCheckitemtype())).findFirst().orElse(null);
|
|
|
+
|
|
|
+ // 发送消息提醒
|
|
|
+ CXCommonUtils.sendNotify(EQUIPMENT_CHECK_TITLE,
|
|
|
+ String.format(EQUIPMENT_CHECK_CONTENT, sysDictDo == null ? "" : sysDictDo.getName(), k.getCheckitemcode(), k.getCheckitemname(),
|
|
|
+ k.getNextcheckdate()), null, v.stream().distinct().collect(Collectors.toList()),
|
|
|
+ k.getId(), SPECIALEQUIPMENT, false);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|