chenhj
4 天以前 4b9dc71d162f3fcd79bc88b170154b7516fc4962
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.ruoyi.device.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.StorageBlobDTO;
import com.ruoyi.basic.pojo.StorageAttachment;
import com.ruoyi.basic.service.StorageAttachmentService;
import com.ruoyi.common.constant.StorageAttachmentConstants;
import com.ruoyi.common.enums.StorageAttachmentRecordType;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
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 org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
 
@Service
public class DeviceMaintenanceServiceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements IDeviceMaintenanceService {
 
 
 
    @Autowired
    private DeviceMaintenanceMapper deviceMaintenanceMapper;
    @Autowired
    private StorageAttachmentService storageAttachmentService;
 
    @Override
    public IPage<DeviceMaintenanceDto> queryPage(Page page, DeviceMaintenanceDto deviceMaintenanceDto) {
 
        return deviceMaintenanceMapper.queryPage(page, deviceMaintenanceDto);
    }
 
    @Override
    public AjaxResult saveDeviceRepair(DeviceMaintenanceDto deviceMaintenance) {
        boolean save = this.save(deviceMaintenance);
        storageAttachmentService.saveStorageAttachmentByStorageBlob(deviceMaintenance.getFiles(),
                deviceMaintenance.getId(), StorageAttachmentRecordType.DeviceMaintenanceImage,
                StorageAttachmentConstants.StorageAttachmentImage);
        if (save){
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
 
    @Override
    public AjaxResult updateDeviceDeviceMaintenance(DeviceMaintenanceDto deviceMaintenance) {
        if (this.updateById(deviceMaintenance)) {
            storageAttachmentService.saveStorageAttachmentByStorageBlob(deviceMaintenance.getFiles(),
                    deviceMaintenance.getId(), StorageAttachmentRecordType.DeviceMaintenanceImage,
                    StorageAttachmentConstants.StorageAttachmentImage);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
 
    @Override
    public void export(HttpServletResponse response, Long[] ids) {
        List<DeviceMaintenance> supplierManageList = deviceMaintenanceMapper.selectList(null);
        ArrayList<DeviceMaintenanceExeclDto> deviceLedgerExeclDtos = new ArrayList<>();
        supplierManageList.forEach(deviceMaintenance -> {
            DeviceMaintenanceExeclDto deviceRepairExeclDto = new DeviceMaintenanceExeclDto();
            BeanUtils.copyProperties(deviceMaintenance,deviceRepairExeclDto);
            deviceRepairExeclDto.setStatus(deviceMaintenance.getStatus() == 0 ? "待维修" : "完结");
            deviceRepairExeclDto.setMaintenanceResult(deviceMaintenance.getMaintenanceResult() != null && deviceMaintenance.getMaintenanceResult() == 0 ? "维修" : "完好");
 
            deviceLedgerExeclDtos.add(deviceRepairExeclDto);
        });
        ExcelUtil<DeviceMaintenanceExeclDto> util = new ExcelUtil<DeviceMaintenanceExeclDto>(DeviceMaintenanceExeclDto.class);
        util.exportExcel(response, deviceLedgerExeclDtos, "设备报修导出");
    }
 
    @Override
    public DeviceMaintenanceDto detailById(Long id) {
        DeviceMaintenanceDto deviceMaintenanceDto = deviceMaintenanceMapper.detailById(id);
        List<StorageAttachment> storageAttachments = storageAttachmentService.selectStorageAttachments(id, StorageAttachmentRecordType.DeviceMaintenanceImage,
                StorageAttachmentConstants.StorageAttachmentImage);
        if (CollectionUtils.isNotEmpty(storageAttachments)) {
            List<StorageBlobDTO> storageBlobs = storageAttachments.stream().map(StorageAttachment::getStorageBlobDTO).collect(Collectors.toList());
            deviceMaintenanceDto.setFiles(storageBlobs);
        }
        return deviceMaintenanceDto;
    }
}