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 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; /** *

* 前端控制器 *

* * @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 add(@Validated @RequestBody TFaultMessage dto) { faultMessageService.add(dto); return AjaxResult.success(); } /** * 获取故障信息列表 * @param siteId * @param basePage * @return */ @ResponseBody @GetMapping("/getFaultMessageList") @ApiOperation(value = "获取故障信息列表数据", tags = {"管理后台-设备监控"}) public AjaxResult> getFaultMessageList(Integer siteId, BasePage basePage){ PageInfo pageInfo = new PageInfo<>(basePage.getPageCurr(), basePage.getPageSize()); List faultMessageList = faultMessageService.getFaultMessageList(pageInfo, siteId); pageInfo.setRecords(faultMessageList); return AjaxResult.success(pageInfo); } @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(); } @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 createFaultMessage(@RequestBody TFaultMessage faultMessage){ faultMessageService.save(faultMessage); return R.ok(); } /** * 修改离线故障记录 * @param faultMessage * @return */ @PostMapping("/updateFaultMessage") public R updateFaultMessage(@RequestBody TFaultMessage faultMessage){ faultMessageService.updateById(faultMessage); return R.ok(); } /** * 查询枪是否有离线或故障记录 * @param gunId * @return */ @PostMapping("/getFaultMessageByGunId/{gunId}") public R 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"))); } }