liyong
4 小时以前 1ca5584d7e3200a9af65a099bd26d3593e2ba702
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
package com.ruoyi.device.controller;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.device.dto.DeviceMaintenanceDto;
import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.device.pojo.DeviceMaintenance;
import com.ruoyi.device.service.IDeviceLedgerService;
import com.ruoyi.device.service.IDeviceMaintenanceService;
import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.Arrays;
 
@Tag(name = "设备保养")
@RestController
@RequestMapping("/device/maintenance")
@AllArgsConstructor
public class DeviceMaintenanceController {
 
 
    private IDeviceMaintenanceService deviceMaintenanceService;
    private IDeviceLedgerService deviceLedgerService;
 
    @Operation(summary = "设备保养列表")
    @GetMapping("/page")
    public AjaxResult page(Page page , DeviceMaintenanceDto deviceMaintenanceDto) {
        return AjaxResult.success(deviceMaintenanceService.queryPage(page,deviceMaintenanceDto));
    }
 
    @PostMapping()
    @Operation(summary = "添加设备保养")
    public AjaxResult add(@RequestBody DeviceMaintenanceDto deviceMaintenance) {
        DeviceLedger byId = deviceLedgerService.getById(deviceMaintenance.getDeviceLedgerId());
        deviceMaintenance.setDeviceName(byId.getDeviceName());
        deviceMaintenance.setDeviceModel(byId.getDeviceModel());
        return deviceMaintenanceService.saveDeviceRepair(deviceMaintenance);
    }
 
    @Operation(summary = "根据id查询设备保养")
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        return AjaxResult.success(deviceMaintenanceService.detailById(id));
    }
 
    @PutMapping ()
    @Operation(summary = "修改设备保养")
    public AjaxResult update(@RequestBody DeviceMaintenanceDto deviceMaintenance) {
        DeviceLedger byId = deviceLedgerService.getById(deviceMaintenance.getDeviceLedgerId());
        deviceMaintenance.setDeviceName(byId.getDeviceName());
        deviceMaintenance.setDeviceModel(byId.getDeviceModel());
        return deviceMaintenanceService.updateDeviceDeviceMaintenance(deviceMaintenance);
    }
 
    @PostMapping ("maintenance")
    @Operation(summary = "修改设备保养")
    public AjaxResult maintenance(@RequestBody DeviceMaintenanceDto deviceMaintenance) {
        return deviceMaintenanceService.updateDeviceDeviceMaintenance(deviceMaintenance);
    }
 
 
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除设备保养")
    public AjaxResult delete(@PathVariable("ids") Long[] ids) {
        boolean b = deviceMaintenanceService.removeBatchByIds(Arrays.asList(ids));
        if (!b) {
            return AjaxResult.error("删除失败");
        }
        return AjaxResult.success();
    }
 
    @PostMapping("export")
    @Operation(summary = "导出设备保养")
    public void export(HttpServletResponse response, Long[] ids) {
        deviceMaintenanceService.export(response, ids);
    }
 
 
}