| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | |
| | | import com.ruoyi.system.dto.SysVisitAreaEditRequest; |
| | | import com.ruoyi.system.dto.SysVisitAreaTreeRequest; |
| | | import com.ruoyi.system.service.ISysVisitAreaService; |
| | | import com.ruoyi.web.controller.tool.MiddlePlatformDataQuery; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * 访问区域管理接口 |
| | |
| | | @Autowired |
| | | private ISysVisitAreaService visitAreaService; |
| | | |
| | | @Autowired |
| | | private RuoYiConfig ruoyiConfig; |
| | | |
| | | /** |
| | | * 查询访问区域树 |
| | | */ |
| | | @Log(title = "访问区域管理", businessType = BusinessType.SELECT) |
| | | @PreAuthorize("@ss.hasAnyPermi('visitor:area:view,visitor:machine:view,visitor:door:view,visitor:record:view')") |
| | | @PostMapping("/tree") |
| | | public AjaxResult tree(@RequestBody(required = false) SysVisitAreaTreeRequest request) |
| | | { |
| | | // 集群版对接中台时,区域属于中台主数据,查询直接切到基础信息中台。 |
| | | if (ruoyiConfig.isConnectMiddlePlatform()) |
| | | { |
| | | try |
| | | { |
| | | return success(MiddlePlatformDataQuery.areaTree(request)); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | return middlePlatformError(e); |
| | | } |
| | | } |
| | | return success(visitAreaService.tree(request)); |
| | | } |
| | | |
| | |
| | | * 查询访问区域详情 |
| | | */ |
| | | @Log(title = "访问区域管理", businessType = BusinessType.SELECT) |
| | | @PreAuthorize("@ss.hasAnyPermi('visitor:area:view,visitor:area:edit')") |
| | | @PostMapping("/detail") |
| | | public AjaxResult detail(@RequestBody SysVisitAreaDetailRequest request) |
| | | { |
| | | // 详情接口同样走中台,避免列表来自中台、详情来自本地导致数据不一致。 |
| | | if (ruoyiConfig.isConnectMiddlePlatform()) |
| | | { |
| | | try |
| | | { |
| | | return success(MiddlePlatformDataQuery.areaDetail(request.getAreaId())); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | return middlePlatformError(e); |
| | | } |
| | | } |
| | | return success(visitAreaService.detail(request)); |
| | | } |
| | | |
| | |
| | | * 新增访问区域 |
| | | */ |
| | | @Log(title = "访问区域管理", businessType = BusinessType.INSERT) |
| | | @PreAuthorize("@ss.hasPermi('visitor:area:add')") |
| | | @PostMapping("/add") |
| | | public AjaxResult add(@RequestBody SysVisitAreaAddRequest request) |
| | | { |
| | |
| | | * 编辑访问区域 |
| | | */ |
| | | @Log(title = "访问区域管理", businessType = BusinessType.UPDATE) |
| | | @PreAuthorize("@ss.hasPermi('visitor:area:edit')") |
| | | @PostMapping("/edit") |
| | | public AjaxResult edit(@RequestBody SysVisitAreaEditRequest request) |
| | | { |
| | |
| | | * 删除访问区域 |
| | | */ |
| | | @Log(title = "访问区域管理", businessType = BusinessType.DELETE) |
| | | @PreAuthorize("@ss.hasPermi('visitor:area:remove')") |
| | | @PostMapping("/delete") |
| | | public AjaxResult delete(@RequestBody SysVisitAreaDeleteRequest request) |
| | | { |
| | | return toAjax(visitAreaService.delete(request, getUsername())); |
| | | } |
| | | |
| | | /** |
| | | * 目的:中台查询异常时返回统一业务错误,避免异常栈直接暴露给前端。 |
| | | */ |
| | | private AjaxResult middlePlatformError(IOException e) |
| | | { |
| | | return error("中台数据查询失败:" + e.getMessage()); |
| | | } |
| | | } |