| | |
| | | import com.ruoyi.device.excel.DeviceMaintenanceExport; |
| | | import com.ruoyi.device.pojo.DeviceMaintenance; |
| | | import com.ruoyi.device.service.DeviceMaintenanceService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.VerticalAlignment; |
| | |
| | | * todo: 孙河滨 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/device-maintain") |
| | | @Api(tags = "设备维护保养") |
| | | @RequestMapping("/deviceMaintain") |
| | | public class DeviceMaintenanceController { |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Autowired |
| | | private NumberGenerator<DeviceMaintenance> numberGenerator; |
| | | //增 |
| | | @PostMapping() |
| | | public Result create(@RequestBody DeviceMaintenance deviceMaintenance){ |
| | | |
| | | /** |
| | | * 新增设备维护保养 |
| | | * @param deviceMaintenance |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "新增设备维护保养") |
| | | @PostMapping("/addDeviceMaintenance") |
| | | public Result addDeviceMaintenance(@RequestBody DeviceMaintenance deviceMaintenance){ |
| | | String year = new SimpleDateFormat("yy", Locale.CHINESE).format(new Date()); |
| | | String month = new SimpleDateFormat("MM", Locale.CHINESE).format(new Date()); |
| | | String processNumber = numberGenerator.generateNumberWithPrefix(3, "DG-TC-23FM " + month + "-" + year + month, DeviceMaintenance::getDeviceNumber); |
| | |
| | | return Result.success(deviceMaintenanceService.save(deviceMaintenance)); |
| | | } |
| | | |
| | | //通过deviceId查询维护数据 |
| | | /** |
| | | * 通过设备id查询设备维护保养信息 |
| | | * @param deviceId |
| | | * @param page |
| | | * @param deviceNumber |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "通过设备id查询设备维护保养信息") |
| | | @GetMapping("/getDeviceMaintenancePage") |
| | | public Result getDeviceMaintenancePage(@RequestParam("deviceId") Integer deviceId, Page page, String deviceNumber){ |
| | | return Result.success(deviceMaintenanceService.getDeviceMaintenancePage(page, deviceId, deviceNumber)); |
| | | } |
| | | |
| | | //删 |
| | | @DeleteMapping("/delete/{id}") |
| | | public void deleteDeviceFault(@PathVariable Integer id) { |
| | | /** |
| | | * 删除设备维护保养 |
| | | * @param id |
| | | */ |
| | | @ApiOperation(value = "新增设备维护保养") |
| | | @DeleteMapping("/deleteDeviceMaintenance") |
| | | public void deleteDeviceMaintenance( Integer id) { |
| | | deviceMaintenanceService.removeById(id); |
| | | } |
| | | |
| | | @GetMapping("/deviceMaintenanceExport") |
| | | public Result deviceMaintenanceExport(@RequestParam("deviceId") Integer deviceId, HttpServletResponse response) throws IOException { |
| | | List<DeviceMaintenanceExport> list = deviceMaintenanceService.deviceMaintenanceExport(deviceId); |
| | | response.setHeader("requestType","excel"); |
| | | response.setHeader("Access-Control-Expose-Headers", "requestType"); |
| | | // 设置单元格样式 |
| | | // 保存到第一个sheet中 |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .head(DeviceMaintenanceExport.class) |
| | | .registerWriteHandler(getHorizontalCellStyleStrategy((short) 12)) |
| | | .sheet() |
| | | .doWrite(list); |
| | | return Result.success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "设备维护记录导出") |
| | | @GetMapping("/exportMaintenanceRecord") |
| | |
| | | deviceMaintenanceService.exportMaintenanceRecord(deviceId, response); |
| | | } |
| | | |
| | | /** |
| | | * 单元格样式策略 |
| | | */ |
| | | public static HorizontalCellStyleStrategy getHorizontalCellStyleStrategy(Short fontHeightInPoints) { |
| | | // 内容的策略 |
| | | WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
| | | |
| | | // 【水平居中需要使用以下两行】 |
| | | // 设置文字左右居中 |
| | | contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); |
| | | // 设置文字上下居中 |
| | | contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置 自动换行 |
| | | contentWriteCellStyle.setWrapped(true); |
| | | |
| | | // 样式策略 |
| | | return new HorizontalCellStyleStrategy(null, contentWriteCellStyle); |
| | | } |
| | | } |