package com.ruoyi.device.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.deepoove.poi.XWPFTemplate;
|
import com.deepoove.poi.config.Configure;
|
import com.ruoyi.device.excel.DeviceMaintenanceExport;
|
import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
|
import com.ruoyi.device.mapper.DeviceMapper;
|
import com.ruoyi.device.pojo.DeviceMaintenance;
|
import com.ruoyi.device.service.DeviceMaintenanceService;
|
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.util.HashMap;
|
import java.util.List;
|
|
@Service
|
public class DeviceMaintenanceImpl extends ServiceImpl<DeviceMaintenanceMapper, DeviceMaintenance> implements DeviceMaintenanceService {
|
|
@Override
|
public IPage<DeviceMaintenance> getDeviceMaintenancePage(Page page, Integer deviceId, String deviceNumber) {
|
return baseMapper.selectPage(page, Wrappers.<DeviceMaintenance>lambdaQuery()
|
.eq(DeviceMaintenance::getDeviceId, deviceId)
|
.like(DeviceMaintenance::getDeviceNumber, deviceNumber));
|
}
|
|
@Override
|
public void exportMaintenanceRecord(Integer deviceId, HttpServletResponse response) {
|
// 查询cnas设备维修记录
|
List<DeviceMaintenance> deviceMaintenanceList = baseMapper.selectList(Wrappers.<DeviceMaintenance>lambdaQuery()
|
.eq(DeviceMaintenance::getDeviceId, deviceId)
|
.select(DeviceMaintenance::getDate,
|
DeviceMaintenance::getDeviceNumber,
|
DeviceMaintenance::getDeviceName,
|
DeviceMaintenance::getManagementNumber,
|
DeviceMaintenance::getContent,
|
DeviceMaintenance::getName,
|
DeviceMaintenance::getComments));
|
|
|
// 获取路径
|
InputStream inputStream = this.getClass().getResourceAsStream("/static/word/maintenance-records.docx");
|
Configure configure = Configure.builder()
|
.bind("deviceMaintenanceList", new HackLoopTableRenderPolicy())
|
.build();
|
// 获取设备 名称 和 编号
|
DeviceMaintenance deviceMaintenance = deviceMaintenanceList.get(0);
|
String deviceName = deviceMaintenance.getDeviceName();
|
String managementNumber = deviceMaintenance.getManagementNumber();
|
XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
|
new HashMap<String, Object>() {{
|
put("deviceMaintenanceList", deviceMaintenanceList);
|
put("deviceName", deviceName);
|
put("managementNumber", managementNumber);
|
}});
|
|
try {
|
response.setContentType("application/msword");
|
String fileName = URLEncoder.encode(
|
"设备维护保养记录", "UTF-8");
|
response.setHeader("Content-disposition",
|
"attachment;filename=" + fileName + ".docx");
|
OutputStream os = response.getOutputStream();
|
template.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new RuntimeException("导出失败");
|
}
|
}
|
|
}
|