无关风月
2024-12-11 4d7a208f388e42e7dd83dab0e38eadfa0847de1c
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
package com.ruoyi.chargingPile.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.chargingPile.api.dto.TChargingGunDTO;
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.model.TFaultMessage;
import com.ruoyi.chargingPile.service.TChargingPileService;
import com.ruoyi.chargingPile.service.TFaultMessageService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.BasePage;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.log.enums.OperatorType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-08
 */
@RestController
@RequestMapping("/t-fault-message")
public class TFaultMessageController {
 
    private final TFaultMessageService faultMessageService;
 
    @Autowired
    public TFaultMessageController(TFaultMessageService faultMessageService) {
        this.faultMessageService = faultMessageService;
    }
 
    /**
     * 添加故障报修管理
     */
    @Log(title = "添加故障报修管理", businessType = BusinessType.INSERT,operatorType = OperatorType.MOBILE)
    @ApiOperation(tags = {"小程序-故障报修"},value = "添加故障报修管理")
    @PostMapping(value = "/add")
    public AjaxResult<String> add(@Validated @RequestBody TFaultMessage dto) {
        faultMessageService.add(dto);
        return AjaxResult.success();
    }
    
    
    /**
     * 获取故障信息列表
     * @param siteId
     * @param basePage
     * @return
     */
    @RequiresPermissions(value = {"/faultInformationList"}, logical = Logical.OR)
    @ResponseBody
    @GetMapping("/getFaultMessageList")
    @ApiOperation(value = "获取故障信息列表数据", tags = {"管理后台-设备监控"})
    public AjaxResult<PageInfo<TFaultMessage>> getFaultMessageList(Integer siteId, BasePage basePage){
        PageInfo<TFaultMessage> pageInfo = new PageInfo<>(basePage.getPageCurr(), basePage.getPageSize());
        List<TFaultMessage> faultMessageList = faultMessageService.getFaultMessageList(pageInfo, siteId);
        pageInfo.setRecords(faultMessageList);
        return AjaxResult.success(pageInfo);
    }
    
    
    @RequiresPermissions(value = {"/faultInformationList/add"}, logical = Logical.OR)
    @ResponseBody
    @PostMapping("/addFaultMessage")
    @ApiOperation(value = "添加故障信息", tags = {"管理后台-设备监控"})
    @Log(title = "【设备监控】添加故障信息", businessType = BusinessType.INSERT,operatorType = OperatorType.MANAGE)
    public AjaxResult addFaultMessage(@RequestBody TFaultMessage faultMessage){
        faultMessageService.save(faultMessage);
        return AjaxResult.success();
    }
    
    
    @RequiresPermissions(value = {"/faultInformationList/del"}, logical = Logical.OR)
    @ResponseBody
    @DeleteMapping("/delFaultMessage/{id}")
    @ApiOperation(value = "删除故障信息", tags = {"管理后台-设备监控"})
    @Log(title = "【设备监控】删除故障信息", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    public AjaxResult delFaultMessage(@PathVariable Integer id){
        faultMessageService.removeById(id);
        return AjaxResult.success();
    }
 
    /**
     * 添加离线故障记录
     * @param faultMessage
     * @return
     */
    @PostMapping("/createFaultMessage")
    public R<String> createFaultMessage(@RequestBody TFaultMessage faultMessage){
        faultMessageService.save(faultMessage);
        return R.ok();
    }
    /**
     * 修改离线故障记录
     * @param faultMessage
     * @return
     */
    @PostMapping("/updateFaultMessage")
    public R<String> updateFaultMessage(@RequestBody TFaultMessage faultMessage){
        faultMessageService.updateById(faultMessage);
        return R.ok();
    }
    /**
     * 查询枪是否有离线或故障记录
     * @param gunId
     * @return
     */
    @PostMapping("/getFaultMessageByGunId/{gunId}")
    public R<TFaultMessage> getFaultMessageByGunId(@PathVariable("gunId") Integer gunId){
        return R.ok(faultMessageService.getOne(Wrappers.lambdaQuery(TFaultMessage.class)
                .eq(TFaultMessage::getChargingGunId,gunId)
                .and(e->e.eq(TFaultMessage::getStatus,1).or().eq(TFaultMessage::getStatus,2))
                .isNull(TFaultMessage::getEndTime)
                .orderByDesc(TFaultMessage::getDownTime)
                .last("LIMIT 1")));
    }
}