chenhj
5 小时以前 f3a2e64d96e59bed492bb3eec8705a5f9ca269d7
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
package com.ruoyi.device.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.approve.pojo.ApproveProcess;
import com.ruoyi.approve.service.IApproveProcessService;
import com.ruoyi.device.dto.DeviceRepairDto;
import com.ruoyi.device.pojo.DeviceRepair;
import com.ruoyi.device.service.IDeviceLedgerService;
import com.ruoyi.device.service.IDeviceRepairService;
import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
 
@Api(tags = "设备报修管理")
@RequestMapping("/device/repair")
@RestController
public class DeviceRepairController {
 
    @Autowired
    private IDeviceRepairService deviceRepairService;
 
    @Autowired
    private IDeviceLedgerService deviceLedgerService;
    @Autowired
    private IApproveProcessService approveProcessService;
 
    @ApiModelProperty("设备报修列表")
    @GetMapping("/page")
    public AjaxResult page(Page page , DeviceRepairDto deviceRepairDto) {
        return AjaxResult.success(deviceRepairService.queryPage(page,deviceRepairDto));
    }
 
    @PostMapping()
    @Transactional(rollbackFor = Exception.class)
    @ApiModelProperty("添加设备报修")
    public AjaxResult add( @RequestBody DeviceRepair deviceRepair) throws Exception {
        deviceRepairService.saveDeviceRepair(deviceRepair);
        // todo 前端代码不匹配,待处理
//        ApproveProcessVO approveProcessVO = new ApproveProcessVO();
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        // 获取当前登录公司
//        Long tenantId = loginUser.getTenantId();
//        if(null != tenantId){
//            //获取当前登录部门id
//            approveProcessVO.setApproveDeptId(tenantId);
//            //获取当前登录用户id
//            approveProcessVO.setApproveUser(loginUser.getUserId());
//            //获取当前时间
//            approveProcessVO.setApproveTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            approveProcessVO.setApproveType(4);
//            approveProcessVO.setApproveUserIds(deviceRepair.getApproverId().toString());
//            approveProcessVO.setApproveReason(deviceRepair.getRemark());
//            approveProcessVO.setDeviceRepairId(deviceRepair.getId());
//            approveProcessVO.setMaintenancePrice(deviceRepair.getMaintenancePrice());
//            approveProcessService.addApprove(approveProcessVO);
//        }
        return AjaxResult.success();
    }
 
    @ApiModelProperty("根据id查询设备报修")
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        DeviceRepairDto byId = deviceRepairService.detailById(id);
        return AjaxResult.success(byId);
    }
 
    @PutMapping ()
    @ApiModelProperty("修改设备报修")
    public AjaxResult update( @RequestBody DeviceRepair deviceRepair) {
        return deviceRepairService.updateDeviceRepair(deviceRepair);
    }
 
    @PostMapping ("repair")
    @ApiModelProperty("设备维修")
    public AjaxResult repair( @RequestBody DeviceRepair deviceRepair) {
        return deviceRepairService.updateDeviceRepair(deviceRepair);
    }
 
    @DeleteMapping("/{ids}")
    @ApiModelProperty("删除设备报修")
    public AjaxResult delete(@PathVariable("ids") Long[] ids) {
        LambdaQueryWrapper<ApproveProcess> QueryWrapper = new LambdaQueryWrapper<>();
        QueryWrapper.in(ApproveProcess::getDeviceRepairId,ids);
        List<ApproveProcess> approveProcessList = approveProcessService.list(QueryWrapper);
        if(!approveProcessList.isEmpty()){
            approveProcessList.forEach(approveProcess -> {
                if (approveProcess.getApproveStatus() != 0){
                    //抛出异常
                    throw new RuntimeException("有正在处理中的审批流程,不能删除");
                }
            });
        }
        boolean b = deviceRepairService.removeBatchByIds(Arrays.asList(ids));
        if (!b) {
            return AjaxResult.error("删除失败");
        }
        return AjaxResult.success();
    }
 
    @PostMapping("export")
    @ApiModelProperty("导出设备报修")
    public void export(HttpServletResponse response, Long[] ids) {
        deviceRepairService.export(response, ids);
    }
}