| | |
| | | package com.ruoyi.safe.specialequipment.service.impl; |
| | | |
| | | 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.ruoyi.basic.dto.StorageBlobVO; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.safe.specialequipment.mapper.SpecialEquipmentRectificationMapper; |
| | | import com.ruoyi.safe.specialequipment.pojo.SpecialEquipmentRectification; |
| | | import com.ruoyi.safe.specialequipment.service.SpecialEquipmentRectificationService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalDate; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class SpecialEquipmentRectificationServiceImpl extends ServiceImpl<SpecialEquipmentRectificationMapper, SpecialEquipmentRectification> implements SpecialEquipmentRectificationService { |
| | | private final SpecialEquipmentRectificationMapper mapper; |
| | | public IPage<SpecialEquipmentRectification> listPage(Page page, SpecialEquipmentRectification req) { return mapper.listPage(page, req); } |
| | | private final FileUtil fileUtil; |
| | | |
| | | public IPage<SpecialEquipmentRectification> listPage(Page page, SpecialEquipmentRectification req) { |
| | | IPage<SpecialEquipmentRectification> result = mapper.listPage(page, req); |
| | | fillAttachments(result.getRecords()); |
| | | return result; |
| | | } |
| | | |
| | | public boolean save(SpecialEquipmentRectification entity) { |
| | | entity.setTenantId(SecurityUtils.getLoginUser().getTenantId()); |
| | | entity.setCreateUser(SecurityUtils.getLoginUser().getUserId()); |
| | | entity.setCreateTime(LocalDateTime.now()); |
| | | entity.setRectificationStatus(entity.getRectificationStatus() == null ? 1 : entity.getRectificationStatus()); |
| | | return super.save(entity); |
| | | boolean saved = super.save(entity); |
| | | syncAttachments(saved, entity); |
| | | return saved; |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateById(SpecialEquipmentRectification entity) { |
| | | return super.updateById(entity); |
| | | if (entity.getRectificationStatus() != null && entity.getRectificationStatus() == 4 && entity.getClosedDate() == null) { |
| | | entity.setClosedDate(LocalDate.now()); |
| | | } |
| | | boolean updated = super.updateById(entity); |
| | | syncAttachments(updated, entity); |
| | | return updated; |
| | | } |
| | | |
| | | private void syncAttachments(boolean success, SpecialEquipmentRectification entity) { |
| | | if (!success || entity == null || entity.getId() == null || entity.getStorageBlobDTOs() == null) { |
| | | return; |
| | | } |
| | | fileUtil.saveStorageAttachment( |
| | | ApplicationTypeEnum.FILE, |
| | | RecordTypeEnum.SPECIAL_EQUIPMENT_RECTIFICATION, |
| | | entity.getId(), |
| | | entity.getStorageBlobDTOs() |
| | | ); |
| | | } |
| | | |
| | | private void fillAttachments(List<SpecialEquipmentRectification> records) { |
| | | if (records == null || records.isEmpty()) { |
| | | return; |
| | | } |
| | | records.forEach(record -> { |
| | | if (record.getId() == null) { |
| | | return; |
| | | } |
| | | List<StorageBlobVO> attachments = fileUtil.getStorageBlobVOsByRecordTypeAndRecordId( |
| | | RecordTypeEnum.SPECIAL_EQUIPMENT_RECTIFICATION, |
| | | record.getId() |
| | | ); |
| | | record.setStorageBlobVOs(attachments == null ? Collections.emptyList() : attachments); |
| | | }); |
| | | } |
| | | } |