| | |
| | | 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.ruoyi.project.system.domain.SysNotice; |
| | | import com.ruoyi.project.system.mapper.SysNoticeMapper; |
| | | import com.ruoyi.project.system.service.ISysNoticeService; |
| | | import com.ruoyi.project.system.service.impl.SysNoticeServiceImpl; |
| | | import com.ruoyi.safe.dto.SafeHiddenDto; |
| | | import com.ruoyi.safe.pojo.SafeHidden; |
| | | import com.ruoyi.safe.mapper.SafeHiddenMapper; |
| | | import com.ruoyi.safe.service.SafeHiddenService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.mapper.StorageAttachmentMapper; |
| | | import com.ruoyi.basic.mapper.StorageBlobMapper; |
| | | import com.ruoyi.basic.pojo.StorageAttachment; |
| | | import com.ruoyi.project.system.domain.SysNotice; |
| | | import com.ruoyi.project.system.service.ISysDictDataService; |
| | | import com.ruoyi.project.system.service.ISysNoticeService; |
| | | import com.ruoyi.safe.dto.SafeHiddenDto; |
| | | import com.ruoyi.safe.mapper.SafeHiddenFileMapper; |
| | | import com.ruoyi.safe.mapper.SafeHiddenMapper; |
| | | import com.ruoyi.safe.pojo.SafeHidden; |
| | | import com.ruoyi.safe.pojo.SafeHiddenFile; |
| | | import com.ruoyi.safe.service.SafeHiddenService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequiredArgsConstructor |
| | | public class SafeHiddenServiceImpl extends ServiceImpl<SafeHiddenMapper, SafeHidden> implements SafeHiddenService { |
| | | |
| | | @Autowired |
| | | private SafeHiddenMapper safeHiddenMapper; |
| | | @Autowired |
| | | private ISysNoticeService sysNoticeService; |
| | | |
| | | private final SafeHiddenMapper safeHiddenMapper; |
| | | private final ISysNoticeService sysNoticeService; |
| | | private final ISysDictDataService sysDictDataService; |
| | | private final StorageAttachmentMapper storageAttachmentMapper; |
| | | private final StorageBlobMapper storageBlobMapper; |
| | | private final SafeHiddenFileMapper safeHiddenFileMapper; |
| | | |
| | | @Override |
| | | public IPage<SafeHiddenDto> pageSafeHidden(Page page, SafeHiddenDto safeHiddenDto) { |
| | |
| | | @Override |
| | | public int add(SafeHidden safeHidden) { |
| | | safeHiddenMapper.insert(safeHidden); |
| | | String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")); |
| | | String no = "YH" + String.format("%s%03d", datePrefix, safeHidden.getId()); |
| | | safeHidden.setHiddenCode(no); |
| | | safeHiddenMapper.updateById(safeHidden); |
| | | //消息通知 |
| | | |
| | | String type = sysDictDataService.selectDictLabel("hidden_danger_type", safeHidden.getType()); |
| | | sysNoticeService.simpleNoticeByUser("隐患排查上报整改", |
| | | "隐患类型:"+safeHidden.getType()+"\n"+ |
| | | "隐患风险等级:"+safeHidden.getRiskLevel()+"\n"+ |
| | | "隐患具体位置:"+safeHidden.getLocation()+"\n"+ |
| | | "隐患描述:"+safeHidden.getHiddenDesc()+"\n"+ |
| | | "整改完成期限(日期):"+safeHidden.getRectifyTime(), |
| | | "隐患类型:" + type + "\t" + |
| | | "隐患风险等级:" + safeHidden.getRiskLevel() + "\t" + |
| | | "隐患具体位置:" + safeHidden.getLocation() + "\t" + |
| | | "隐患描述:" + safeHidden.getHiddenDesc() + "\t" + |
| | | "整改完成期限(日期):" + safeHidden.getRectifyTime(), |
| | | Arrays.asList(Long.valueOf(safeHidden.getRectifyUserId())), |
| | | "/safeProduction/dangerInvestigation?id=" + safeHidden.getId()); |
| | | return 0; |
| | |
| | | |
| | | @Override |
| | | public int delSafeHidden(List<Integer> ids) { |
| | | if (ids == null || ids.isEmpty()) { |
| | | return 0; |
| | | } |
| | | |
| | | List<SafeHidden> safeHiddens = safeHiddenMapper.selectBatchIds(ids); |
| | | List<String> rectifiedHiddenCodes = safeHiddens.stream() |
| | | .filter(this::isRectified) |
| | | .map(item -> StringUtils.hasText(item.getHiddenCode()) ? item.getHiddenCode() : String.valueOf(item.getId())) |
| | | .collect(Collectors.toList()); |
| | | if (!rectifiedHiddenCodes.isEmpty()) { |
| | | throw new RuntimeException("已整改的隐患不能删除:" + String.join("、", rectifiedHiddenCodes)); |
| | | } |
| | | |
| | | for (SafeHidden safeHidden : safeHiddens) { |
| | | // 删除对应的消息通知 |
| | | sysNoticeService.remove(new LambdaQueryWrapper<SysNotice>() |
| | | .eq(SysNotice::getNoticeTitle, "隐患排查上报整改") |
| | | .eq(SysNotice::getSenderId, safeHidden.getCreateUser()) |
| | | .apply("CAST(notice_content AS CHAR) LIKE CONCAT('%', {0}, '%')", safeHidden.getId())); |
| | | } |
| | | deleteAttachments(ids); |
| | | safeHiddenMapper.deleteBatchIds(ids); |
| | | return 0; |
| | | } |
| | | |
| | | private boolean isRectified(SafeHidden safeHidden) { |
| | | return safeHidden.getRectifyActualTime() != null |
| | | || StringUtils.hasText(safeHidden.getRectifyMeasures()) |
| | | || safeHidden.getVerifyTime() != null |
| | | || StringUtils.hasText(safeHidden.getVerifyResult()) |
| | | || StringUtils.hasText(safeHidden.getVerifyRemark()); |
| | | } |
| | | |
| | | private void deleteAttachments(List<Integer> ids) { |
| | | List<Long> recordIds = ids.stream() |
| | | .filter(Objects::nonNull) |
| | | .map(Integer::longValue) |
| | | .collect(Collectors.toList()); |
| | | if (recordIds.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordType, RecordTypeEnum.SAFE_HIDDEN.getType()) |
| | | .in(StorageAttachment::getRecordId, recordIds)); |
| | | if (!storageAttachments.isEmpty()) { |
| | | List<Long> storageAttachmentIds = storageAttachments.stream() |
| | | .map(StorageAttachment::getId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | List<Long> storageBlobIds = storageAttachments.stream() |
| | | .map(StorageAttachment::getStorageBlobId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (!storageAttachmentIds.isEmpty()) { |
| | | storageAttachmentMapper.deleteByIds(storageAttachmentIds); |
| | | } |
| | | if (!storageBlobIds.isEmpty()) { |
| | | storageBlobMapper.deleteByIds(storageBlobIds); |
| | | } |
| | | } |
| | | |
| | | safeHiddenFileMapper.delete(new LambdaQueryWrapper<SafeHiddenFile>().in(SafeHiddenFile::getSafeHiddenId, ids)); |
| | | } |
| | | } |