Pu Zhibing
2024-12-12 cc6ef4d39b154077445fa1e4e84c1b0ca9674b60
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TFaultMessageController.java
@@ -1,16 +1,21 @@
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;
@@ -55,6 +60,7 @@
     * @param basePage
     * @return
     */
    @RequiresPermissions(value = {"/faultInformationList"}, logical = Logical.OR)
    @ResponseBody
    @GetMapping("/getFaultMessageList")
    @ApiOperation(value = "获取故障信息列表数据", tags = {"管理后台-设备监控"})
@@ -66,21 +72,60 @@
    }
    
    
    @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")));
    }
}