gongchunyi
13 小时以前 1db111fdf6c65fa1debadf648e4c22bd466744f8
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.ruoyi.device.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.device.dto.DeviceLedgerDto;
import com.ruoyi.device.mapper.DeviceLedgerMapper;
import com.ruoyi.device.mapper.DeviceMaintenanceMapper;
import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.device.pojo.DeviceMaintenance;
import com.ruoyi.device.service.IDeviceLedgerService;
import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.sales.pojo.CommonFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
@Api(tags = "设备台账管理")
@RequestMapping("/device/ledger")
@RestController
public class DeviceLedgerController {
 
    @Autowired
    private IDeviceLedgerService deviceLedgerService;
 
    @Autowired
    private DeviceLedgerMapper deviceLedgerMapper;
 
    @Autowired
    private DeviceMaintenanceMapper deviceMaintenanceMapper;
 
 
 
    @ApiOperation("设备台账列表")
    @GetMapping("/page")
    public AjaxResult page(Page page , DeviceLedgerDto deviceLedger) {
        return AjaxResult.success(deviceLedgerService.queryPage(page,deviceLedger));
    }
 
    @PostMapping()
    @ApiOperation("添加设备台账")
    public AjaxResult add(@RequestBody DeviceLedger deviceLedger) {
 
        return deviceLedgerService.saveDeviceLedger(deviceLedger);
    }
 
    @ApiOperation("根据id查询设备台账")
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        return AjaxResult.success(deviceLedgerService.getDetailById(id));
    }
 
    @PutMapping ()
    @ApiOperation("修改设备台账")
    public AjaxResult update(@RequestBody DeviceLedger deviceLedger) {
        return deviceLedgerService.updateDeviceLedger(deviceLedger);
    }
 
    @DeleteMapping("/{ids}")
    @ApiOperation("删除设备台账")
    public AjaxResult delete(@PathVariable("ids") ArrayList<Long> ids) {
        boolean b = deviceLedgerService.deleteLedgerAndFiles(ids);
        if (!b) {
            return AjaxResult.error("删除失败");
        }
        return AjaxResult.success();
    }
 
    @PostMapping("export")
    @ApiOperation("导出设备台账")
    public void export(HttpServletResponse response, Long[] ids) {
         deviceLedgerService.export(response, ids);
    }
 
    @PostMapping("import")
    @ApiOperation("导入设备台账")
    public AjaxResult importData(MultipartFile file) throws IOException {
        Boolean b = deviceLedgerService.importData(file);
        if (b) {
            return AjaxResult.success("导入成功");
        }
        return AjaxResult.error("导入失败");
    }
 
 
    @GetMapping("getDeviceLedger")
    @ApiOperation("获取设备台账")
    public AjaxResult getDeviceLedger( ) {
        return AjaxResult.success(deviceLedgerService.list(new QueryWrapper<DeviceLedger>().lambda()
                .select(DeviceLedger::getId, DeviceLedger::getDeviceName,DeviceLedger::getDeviceModel)));
    }
 
    @GetMapping("scanDevice")
    @ApiOperation("获取设备台账")
    @Anonymous
    public AjaxResult scanDevice(Long id) {
        List<DeviceMaintenance> list = deviceMaintenanceMapper.list1(id);
        DeviceLedger deviceLedger = deviceLedgerMapper.selectById1(id);
        if (list.size()>0){
            deviceLedger.setUpdateTime(list.get(0).getMaintenanceActuallyTime());//最后维护时间
        }
        deviceLedger.setCreateTime(deviceLedger.getUpdateTime().plusMonths(1));//下次维护时间
        return AjaxResult.success(deviceLedger);
    }
    @PostMapping("/uploadFile")
    @ApiOperation("设备台账-附件上传")
    public AjaxResult uploadFile(MultipartFile file, Long deviceLedgerId, Integer fileType) {
        deviceLedgerService.uploadFile(file, deviceLedgerId, fileType);
        return AjaxResult.success();
    }
 
    @GetMapping("/file/{deviceLedgerId}")
    @ApiOperation("设备台账-文件列表")
    public AjaxResult getFiles(@PathVariable("deviceLedgerId") Long deviceLedgerId) {
        java.util.List<CommonFile> list = deviceLedgerService.getFiles(deviceLedgerId);
        return AjaxResult.success(list);
    }
 
    @DeleteMapping("/file/{fileId}")
    @ApiOperation("设备台账-删除文件")
    public AjaxResult deleteFile(@PathVariable("fileId") Long fileId) {
        deviceLedgerService.deleteFile(fileId);
        return AjaxResult.success();
    }
}