| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.system.model.TFaultAreaDic; |
| | | import com.ruoyi.system.model.TFaultDescribeDic; |
| | | import com.ruoyi.system.model.TItem; |
| | | import com.ruoyi.system.model.TItemType; |
| | | import com.ruoyi.system.query.TFaultAreaDicQuery; |
| | | import com.ruoyi.system.service.TFaultAreaDicService; |
| | | import com.ruoyi.system.service.TFaultDescribeDicService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author xiaochen |
| | | * @since 2025-01-17 |
| | | */ |
| | | @Api(tags = "故障区域") |
| | | @RestController |
| | | @RequestMapping("/t-fault-area-dic") |
| | | public class TFaultAreaDicController { |
| | | |
| | | private final TFaultAreaDicService faultAreaDicService; |
| | | private final TFaultDescribeDicService faultDescribeDicService; |
| | | @Autowired |
| | | public TFaultAreaDicController(TFaultAreaDicService faultAreaDicService, TFaultDescribeDicService faultDescribeDicService) { |
| | | this.faultAreaDicService = faultAreaDicService; |
| | | this.faultDescribeDicService = faultDescribeDicService; |
| | | } |
| | | |
| | | /** |
| | | * 获取故障区域管理列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:list')") |
| | | @ApiOperation(value = "获取故障区域分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<TFaultAreaDic>> pageList(@RequestBody TFaultAreaDicQuery query) { |
| | | return R.ok(faultAreaDicService.pageList(query)); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:list')") |
| | | @ApiOperation(value = "获取故障区域列表") |
| | | @PostMapping(value = "/list") |
| | | public R<List<TFaultAreaDic>> list() { |
| | | return R.ok(faultAreaDicService.list(Wrappers.lambdaQuery(TFaultAreaDic.class).orderByDesc(TFaultAreaDic::getSortBy).orderByDesc(TFaultAreaDic::getCreateTime))); |
| | | } |
| | | |
| | | /** |
| | | * 添加故障区域管理 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:add')") |
| | | @Log(title = "故障区域信息-新增故障区域", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "添加故障区域") |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> add(@Validated @RequestBody TFaultAreaDic dto) { |
| | | if (faultAreaDicService.isExit(dto)) { |
| | | return R.fail("故障区域名称已存在"); |
| | | } |
| | | return R.ok(faultAreaDicService.save(dto)); |
| | | } |
| | | |
| | | /** |
| | | * 修改故障区域 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:update')") |
| | | @Log(title = "故障区域信息-修改故障区域", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "修改故障区域") |
| | | @PostMapping(value = "/update") |
| | | public R<Boolean> update(@Validated @RequestBody TFaultAreaDic dto) { |
| | | if (faultAreaDicService.isExit(dto)) { |
| | | return R.fail("故障区域名称已存在"); |
| | | } |
| | | return R.ok(faultAreaDicService.updateById(dto)); |
| | | } |
| | | |
| | | /** |
| | | * 查看故障区域详情 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:detail')") |
| | | @ApiOperation(value = "查看故障区域详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public R<TFaultAreaDic> getDetailById(@RequestParam String id) { |
| | | return R.ok(faultAreaDicService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 删除故障区域 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:delete')") |
| | | @Log(title = "故障区域信息-删除故障区域", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "删除故障区域") |
| | | @DeleteMapping(value = "/deleteById") |
| | | public R<Boolean> deleteById(@RequestParam String id) { |
| | | long count = faultDescribeDicService.count(Wrappers.lambdaQuery(TFaultDescribeDic.class).eq(TFaultDescribeDic::getFaultId, id)); |
| | | if (count>0) { |
| | | return R.fail("该区域下有故障描述,无法删除"); |
| | | } |
| | | return R.ok(faultAreaDicService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除故障区域 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:faultArea:delete')") |
| | | @Log(title = "故障区域信息-删除故障区域", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "批量删除故障区域") |
| | | @DeleteMapping(value = "/deleteByIds") |
| | | public R<Boolean> deleteByIds(@RequestBody List<String> ids) { |
| | | List<TFaultDescribeDic> items = faultDescribeDicService.list(Wrappers.lambdaQuery(TFaultDescribeDic.class).in(TFaultDescribeDic::getFaultId, ids)); |
| | | for (String id : ids) { |
| | | if (items.stream().anyMatch(t -> t.getFaultId().equals(id))) { |
| | | TFaultAreaDic faultAreaDic = faultAreaDicService.getById(id); |
| | | return R.fail("该区域["+faultAreaDic.getFaultAreaName()+"]下有故障描述,无法删除"); |
| | | } |
| | | } |
| | | return R.ok(faultAreaDicService.removeByIds(ids)); |
| | | } |
| | | |
| | | } |
| | | |