Browse Source

# 安全工器具消息提醒改造

zhongwei
haungxing 11 months ago
parent
commit
a293b1a45c
  1. 6
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/RedisConstants.java
  2. 3
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/SafetyToolEntity.java
  3. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/dto/SafetyToolBatchRecheckDTO.java
  4. 25
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafetyToolServiceImpl.java

6
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/RedisConstants.java

@ -0,0 +1,6 @@
package com.hnac.hzims.safeproduct.constants;
public interface RedisConstants {
/**安全工器具提醒记录**/
String TOOLS_REMIND_MSG = "200000:hzims:safeproduct:tools:remind";
}

3
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/SafetyToolEntity.java

@ -9,6 +9,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import java.io.Serializable;
import java.util.Date;
@ -21,7 +22,7 @@ import java.util.Date;
@TableName("hzims_safe_safety_tool")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "SafetyTool对象", description = "")
public class SafetyToolEntity extends TenantEntity {
public class SafetyToolEntity extends TenantEntity implements Serializable {
private static final long serialVersionUID = 1L;

5
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/dto/SafetyToolBatchRecheckDTO.java

@ -1,8 +1,11 @@
package com.hnac.hzims.safeproduct.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
@ -27,6 +30,8 @@ public class SafetyToolBatchRecheckDTO implements Serializable {
private Set<Long> toolIds;
@ApiModelProperty(value = "复核时间")
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
private Date checkTime;
@ApiModelProperty(value = "备注")

25
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafetyToolServiceImpl.java

@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.zxing.BarcodeFormat;
import com.hnac.hzims.message.dto.PlanMsgRecordDto;
import com.hnac.hzims.safeproduct.constants.RedisConstants;
import com.hnac.hzims.safeproduct.dto.SafetyToolBatchRecheckDTO;
import com.hnac.hzims.safeproduct.dto.SafetyToolDTO;
import com.hnac.hzims.safeproduct.entity.SafeProductPdf;
@ -44,6 +45,7 @@ import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
@ -126,7 +128,6 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf
@Override
public void doBatchRecheck(SafetyToolBatchRecheckDTO req) {
//更新工器具记录数据
Date checkTime = Func.isNotEmpty(req.getCheckTime()) ? req.getCheckTime() : new Date();
Long userId = AuthUtil.getUserId();
String userName = AuthUtil.getUserName();
@ -134,24 +135,22 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf
for (SafetyToolEntity item : safetyTools) {
item.setLastCheckTime(checkTime);
item.setNextCheckTime(DateUtil.plusDays(checkTime, Long.valueOf(item.getSafeTime().toString())));
}
if (!super.updateBatchById(safetyTools)) {
throw new ServiceException("数据库update操作失败!");
}
//插入复核记录
List<SafetyToolRecheckEntity> safetyToolRechecks = new ArrayList<>(safetyTools.size());
for (SafetyToolEntity item : safetyTools) {
super.updateById(item);
SafetyToolRecheckEntity entity = new SafetyToolRecheckEntity();
entity.setCheckUserName(userName);
entity.setCheckUserId(userId);
entity.setToolId(item.getId());
entity.setCheckTime(checkTime);
entity.setRemark(req.getRemark());
safetyToolRechecks.add(entity);
}
if (safetyToolRecheckMapper.insertBatch(safetyToolRechecks) == 0) {
throw new ServiceException("数据库insert操作失败!");
safetyToolRecheckMapper.insert(entity);
// 计算下次推送时间
Date noticeDate = DateUtil.minusDays(item.getNextCheckTime(), item.getAdvanceNoticeDays());
String redisKey = RedisConstants.TOOLS_REMIND_MSG + ":" + item.getId();
// 删除提醒记录
redisTemplate.delete(redisKey);
// 创建新的提醒记录
redisTemplate.opsForZSet().add(redisKey,item,noticeDate.getTime());
log.info("key为:"+redisTemplate.keys(RedisConstants.TOOLS_REMIND_MSG+"*"));
}
}

Loading…
Cancel
Save