package com.ard.web.controller.data; import com.ard.common.annotation.Log; import com.ard.common.core.controller.BaseController; import com.ard.common.core.domain.AjaxResult; import com.ard.common.core.page.TableDataInfo; import com.ard.common.enums.BusinessType; import com.ard.common.utils.poi.ExcelUtil; import com.ard.data.region.domain.ArdDeptRegion; import com.ard.data.region.domain.ConflictCheckResult; import com.ard.data.region.domain.PointQueryDTO; import com.ard.data.region.service.IArdDeptRegionService; 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.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; /** * 部门区域Controller * * @author ruoyi */ @Api(tags = "部门区域接口") @RestController @RequestMapping("/data/region") public class ArdDeptRegionController extends BaseController { @Autowired private IArdDeptRegionService ardDeptRegionService; /** * 查询部门区域列表 */ @ApiOperation("查询部门区域列表") @PreAuthorize("@ss.hasPermi('data:region:list')") @GetMapping("/list") public TableDataInfo list(ArdDeptRegion ardDeptRegion) { startPage(); List list = ardDeptRegionService.selectArdDeptRegionList(ardDeptRegion); return getDataTable(list); } /** * 导出部门区域列表 */ @ApiOperation("导出部门区域列表") @PreAuthorize("@ss.hasPermi('data:region:export')") @Log(title = "部门区域", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(ArdDeptRegion ardDeptRegion) { List list = ardDeptRegionService.selectArdDeptRegionList(ardDeptRegion); ExcelUtil util = new ExcelUtil(ArdDeptRegion.class); return util.exportExcel(list, "部门区域数据"); } /** * 获取部门区域详细信息 */ @ApiOperation("获取部门区域详细信息") @PreAuthorize("@ss.hasPermi('data:region:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(ardDeptRegionService.selectArdDeptRegionById(id)); } /** * 检查区域冲突(画区域时调用) */ @ApiOperation("检查区域冲突") @PostMapping("/check") public AjaxResult checkConflict(@Valid @RequestBody ArdDeptRegion ardDeptRegion) { ConflictCheckResult result = ardDeptRegionService.checkConflict(ardDeptRegion); if (result.getHasConflict()) { return AjaxResult.error(result.getMessage(), result); } return AjaxResult.success(result.getMessage(), result); } /** * 新增部门区域 */ @ApiOperation("新增部门区域") @PreAuthorize("@ss.hasPermi('data:region:add')") @Log(title = "部门区域", businessType = BusinessType.INSERT) @PostMapping("/add") public AjaxResult add(@Valid @RequestBody ArdDeptRegion ardDeptRegion) { if (!ardDeptRegionService.checkRegionNameUnique(ardDeptRegion)) { return error("新增区域'" + ardDeptRegion.getRegionName() + "'失败,区域名称已存在"); } return toAjax(ardDeptRegionService.insertArdDeptRegion(ardDeptRegion)); } /** * 修改部门区域 */ @ApiOperation("修改部门区域") @PreAuthorize("@ss.hasPermi('data:region:edit')") @Log(title = "部门区域", businessType = BusinessType.UPDATE) @PutMapping("/edit") public AjaxResult edit(@RequestBody ArdDeptRegion ardDeptRegion) { if (!ardDeptRegionService.checkRegionNameUnique(ardDeptRegion)) { return error("修改区域'" + ardDeptRegion.getRegionName() + "'失败,区域名称已存在"); } return toAjax(ardDeptRegionService.updateArdDeptRegion(ardDeptRegion)); } /** * 修改状态(启用/禁用) */ @ApiOperation("修改状态") @PreAuthorize("@ss.hasPermi('data:region:edit')") @Log(title = "部门区域", businessType = BusinessType.UPDATE) @PutMapping("/changeStatus") public AjaxResult changeStatus(@RequestBody ArdDeptRegion ardDeptRegion) { return toAjax(ardDeptRegionService.updateStatus(ardDeptRegion.getId(), ardDeptRegion.getStatus())); } /** * 删除部门区域 */ @ApiOperation("删除部门区域") @PreAuthorize("@ss.hasPermi('data:region:remove')") @Log(title = "部门区域", businessType = BusinessType.DELETE) @DeleteMapping("/remove/{ids}") public AjaxResult remove(@PathVariable String[] ids) { return toAjax(ardDeptRegionService.deleteArdDeptRegionByIds(ids)); } /** * 根据坐标查询所属区域 */ @ApiOperation("根据坐标查询所属区域") @PostMapping("/getByPoint") public AjaxResult getRegionByPoint(@RequestBody PointQueryDTO query) { ArdDeptRegion region = ardDeptRegionService.selectRegionByPoint(query.getLat(), query.getLng()); if (region == null) { return error("该坐标不在任何区域内"); } return success(region); } }