| | |
| | | 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.github.xiaoymin.knife4j.core.util.StrUtil; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.dto.DeviceMaintenanceDto; |
| | | import com.ruoyi.device.dto.DeviceRepairDto; |
| | | import com.ruoyi.device.execl.DeviceMaintenanceExeclDto; |
| | | import com.ruoyi.device.mapper.DeviceMaintenanceMapper; |
| | | import com.ruoyi.device.pojo.DeviceMaintenance; |
| | | import com.ruoyi.device.service.IDeviceMaintenanceService; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @Service |
| | | public class DeviceMaintenanceServiceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements IDeviceMaintenanceService { |
| | | |
| | | |
| | | @Autowired |
| | | private SparePartsMapper sparePartsMapper; |
| | | |
| | | @Autowired |
| | | private DeviceMaintenanceMapper deviceMaintenanceMapper; |
| | |
| | | @Override |
| | | public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) { |
| | | |
| | | return deviceMaintenanceMapper.queryPage(page, deviceMaintenanceDto); |
| | | IPage<DeviceMaintenanceDto> deviceMaintenanceDtoIPage = deviceMaintenanceMapper.queryPage(page, deviceMaintenanceDto); |
| | | List<DeviceMaintenanceDto> records = deviceMaintenanceDtoIPage.getRecords(); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | // 1. 获取所有唯一的备件ID |
| | | Set<String> allIds = records.stream() |
| | | .map(DeviceMaintenanceDto::getSparePartsIds) |
| | | .filter(StrUtil::isNotBlank) |
| | | .flatMap(ids -> Arrays.stream(StringUtils.split(ids, ","))) |
| | | .map(String::trim) |
| | | .filter(StrUtil::isNotBlank) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | if (!allIds.isEmpty()) { |
| | | // 2. 查询并创建ID到名称的映射 |
| | | Map<Long, String> idToNameMap = sparePartsMapper.selectBatchIds(new ArrayList<>(allIds)) |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | SpareParts::getId, |
| | | SpareParts::getName, |
| | | (v1, v2) -> v1 |
| | | )); |
| | | |
| | | // 3. 为每个记录设置备件名称 |
| | | records.forEach(record -> { |
| | | String names = Optional.ofNullable(record.getSparePartsIds()) |
| | | .filter(StrUtil::isNotBlank) |
| | | .map(ids -> Arrays.stream(StringUtils.split(ids, ",")) |
| | | .map(String::trim) |
| | | .map(Long::valueOf) |
| | | .map(idToNameMap::get) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.joining(","))) |
| | | .orElse(""); |
| | | record.setSparePartsNames(names); |
| | | }); |
| | | } |
| | | } |
| | | return deviceMaintenanceDtoIPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | DeviceMaintenanceExeclDto deviceRepairExeclDto = new DeviceMaintenanceExeclDto(); |
| | | BeanUtils.copyProperties(deviceMaintenance,deviceRepairExeclDto); |
| | | deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "待维修" : deviceMaintenance.getStatus() == 1 ? "完结" : "失败"); |
| | | // deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() != null && deviceMaintenance.getMaintenanceResult() == 0 ? "维修" : "完好"); |
| | | deviceLedgerExeclDtos.add(deviceRepairExeclDto); |
| | | }); |
| | | ExcelUtil<DeviceMaintenanceExeclDto> util = new ExcelUtil<DeviceMaintenanceExeclDto>(DeviceMaintenanceExeclDto.class); |