| | |
| | | import com.ruoyi.customervisits.mapper.CustomerVisitsMapper; |
| | | import com.ruoyi.customervisits.pojo.CustomerVisits; |
| | | import com.ruoyi.customervisits.service.CustomerVisitsService; |
| | | import com.ruoyi.quality.pojo.QualityUnqualified; |
| | | import com.ruoyi.other.service.impl.TempFileServiceImpl; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author :yys |
| | |
| | | |
| | | @Autowired |
| | | private CommonFileMapper commonFileMapper; |
| | | |
| | | @Autowired |
| | | private TempFileServiceImpl tempFileService; |
| | | |
| | | @Override |
| | | public IPage<CustomerVisitsDto> listPage(Page page, CustomerVisits customerVisits) { |
| | |
| | | |
| | | return updateById(customerVisits); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateCustomerVisit(CustomerVisitsDto customerVisitsDto) throws Exception { |
| | | CustomerVisits customerVisits = new CustomerVisits(); |
| | | BeanUtils.copyProperties(customerVisitsDto, customerVisits); |
| | | boolean updateResult = updateCustomerVisit(customerVisits); |
| | | if (!updateResult) { |
| | | return false; |
| | | } |
| | | |
| | | Long businessId = customerVisits.getId().longValue(); |
| | | List<CommonFile> existingFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>() |
| | | .eq(CommonFile::getCommonId, businessId) |
| | | .eq(CommonFile::getType, FileNameType.CUSTOMER_VISITS.getValue())); |
| | | Set<Long> retainedFileIds = customerVisitsDto.getCommonFileList() == null |
| | | ? Collections.emptySet() |
| | | : customerVisitsDto.getCommonFileList().stream() |
| | | .map(CommonFile::getId) |
| | | .filter(java.util.Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | for (CommonFile commonFile : existingFiles) { |
| | | if (commonFile.getId() == null || retainedFileIds.contains(commonFile.getId())) { |
| | | continue; |
| | | } |
| | | if (commonFile.getUrl() != null && !commonFile.getUrl().isEmpty()) { |
| | | Files.deleteIfExists(Paths.get(commonFile.getUrl())); |
| | | } |
| | | commonFileMapper.deleteById(commonFile.getId()); |
| | | } |
| | | tempFileService.migrateTempFilesToFormal(businessId, customerVisitsDto.getTempFileIds(), FileNameType.CUSTOMER_VISITS.getValue()); |
| | | return true; |
| | | } |
| | | } |