259 lines
8.5 KiB
Java
259 lines
8.5 KiB
Java
package com.ruoyi.system.controller;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
import com.ruoyi.system.domain.DiyCity;
|
|
import com.ruoyi.system.service.IDiyCityService;
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 自定义地区Controller
|
|
*
|
|
* @author ruoyi
|
|
* @date 2025-05-30
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/system/DiyCity")
|
|
public class DiyCityController extends BaseController
|
|
{
|
|
@Autowired
|
|
private IDiyCityService diyCityService;
|
|
|
|
/**
|
|
* 查询自定义地区列表
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:list')")
|
|
@GetMapping("/list")
|
|
public TableDataInfo list(DiyCity diyCity)
|
|
{
|
|
startPage();
|
|
List<DiyCity> list = diyCityService.selectDiyCityList(diyCity);
|
|
return getDataTable(list);
|
|
}
|
|
/**
|
|
* 获取自定义地区树形结构数据
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:query')")
|
|
@GetMapping("/getTreeData")
|
|
public AjaxResult getTreeData() {
|
|
List<DiyCity> list = diyCityService.selectDiyCityList(new DiyCity());
|
|
|
|
List<Map<String, Object>> rootList = new ArrayList<>();
|
|
for (DiyCity city : list) {
|
|
Long parentId = city.getParentId();
|
|
Long id = Long.valueOf(city.getId());
|
|
// 一级节点
|
|
if (parentId == null || parentId == 0L) {
|
|
Map<String, Object> node = toMap(city);
|
|
// 组装children
|
|
List<Map<String, Object>> children = new ArrayList<>();
|
|
for (DiyCity child : list) {
|
|
Long childParentId = child.getParentId();
|
|
if (id != null && Objects.equals(id, childParentId)) {
|
|
children.add(toMap(child));
|
|
}
|
|
}
|
|
node.put("children", children);
|
|
rootList.add(node);
|
|
}
|
|
}
|
|
return success(rootList);
|
|
}
|
|
|
|
private Map<String, Object> toMap(DiyCity city) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("id", city.getId());
|
|
map.put("label", city.getTitle());
|
|
map.put("parentId", city.getParentId());
|
|
// 其他字段按需添加
|
|
return map;
|
|
}
|
|
/**
|
|
* 导出自定义地区列表
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:export')")
|
|
@Log(title = "自定义地区", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(HttpServletResponse response, DiyCity diyCity)
|
|
{
|
|
List<DiyCity> list = diyCityService.selectDiyCityList(diyCity);
|
|
ExcelUtil<DiyCity> util = new ExcelUtil<DiyCity>(DiyCity.class);
|
|
util.exportExcel(response, list, "自定义地区数据");
|
|
}
|
|
|
|
/**
|
|
* 获取自定义地区详细信息
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:query')")
|
|
@GetMapping(value = "/{id}")
|
|
public AjaxResult getInfo(@PathVariable("id") Integer id)
|
|
{
|
|
return success(diyCityService.selectDiyCityById(id));
|
|
}
|
|
|
|
/**
|
|
* 新增自定义地区
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:add')")
|
|
@Log(title = "自定义地区", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
public AjaxResult add(@RequestBody DiyCity diyCity)
|
|
{
|
|
return toAjax(diyCityService.insertDiyCity(diyCity));
|
|
}
|
|
|
|
/**
|
|
* 修改自定义地区
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:edit')")
|
|
@Log(title = "自定义地区", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
public AjaxResult edit(@RequestBody DiyCity diyCity)
|
|
{
|
|
return toAjax(diyCityService.updateDiyCity(diyCity));
|
|
}
|
|
|
|
/**
|
|
* 删除自定义地区
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:DiyCity:remove')")
|
|
@Log(title = "自定义地区", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{ids}")
|
|
public AjaxResult remove(@PathVariable Integer[] ids)
|
|
{
|
|
return toAjax(diyCityService.deleteDiyCityByIds(ids));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//package com.ruoyi.system.controller;
|
|
//
|
|
//import java.util.ArrayList;
|
|
//import java.util.HashMap;
|
|
//import java.util.List;
|
|
//import java.util.Map;
|
|
//import javax.servlet.http.HttpServletResponse;
|
|
//import org.springframework.security.access.prepost.PreAuthorize;
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
//import org.springframework.web.bind.annotation.GetMapping;
|
|
//import org.springframework.web.bind.annotation.PostMapping;
|
|
//import org.springframework.web.bind.annotation.PutMapping;
|
|
//import org.springframework.web.bind.annotation.DeleteMapping;
|
|
//import org.springframework.web.bind.annotation.PathVariable;
|
|
//import org.springframework.web.bind.annotation.RequestBody;
|
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
|
//import org.springframework.web.bind.annotation.RestController;
|
|
//import com.ruoyi.common.annotation.Log;
|
|
//import com.ruoyi.common.core.controller.BaseController;
|
|
//import com.ruoyi.common.core.domain.AjaxResult;
|
|
//import com.ruoyi.common.enums.BusinessType;
|
|
//import com.ruoyi.system.domain.DiyCity;
|
|
//import com.ruoyi.system.service.IDiyCityService;
|
|
//import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
//import com.ruoyi.common.core.page.TableDataInfo;
|
|
//
|
|
///**
|
|
// * 自定义地区Controller
|
|
// *
|
|
// * @author ruoyi
|
|
// * @date 2025-05-13
|
|
// */
|
|
//@RestController
|
|
//@RequestMapping("/system/DiyCity")
|
|
//public class DiyCityController extends BaseController
|
|
//{
|
|
// @Autowired
|
|
// private IDiyCityService diyCityService;
|
|
//
|
|
// /**
|
|
// * 查询自定义地区列表
|
|
// */
|
|
// @PreAuthorize("@ss.hasPermi('system:DiyCity:list')")
|
|
// @GetMapping("/list")
|
|
// public TableDataInfo list(DiyCity diyCity)
|
|
// {
|
|
// startPage();
|
|
// List<DiyCity> list = diyCityService.selectDiyCityList(diyCity);
|
|
// return getDataTable(list);
|
|
// }
|
|
//
|
|
//
|
|
|
|
//
|
|
// /**
|
|
// * 导出自定义地区列表
|
|
// */
|
|
// @PreAuthorize("@ss.hasPermi('system:DiyCity:export')")
|
|
// @Log(title = "自定义地区", businessType = BusinessType.EXPORT)
|
|
// @PostMapping("/export")
|
|
// public void export(HttpServletResponse response, DiyCity diyCity)
|
|
// {
|
|
// List<DiyCity> list = diyCityService.selectDiyCityList(diyCity);
|
|
// ExcelUtil<DiyCity> util = new ExcelUtil<DiyCity>(DiyCity.class);
|
|
// util.exportExcel(response, list, "自定义地区数据");
|
|
// }
|
|
//
|
|
// /**
|
|
// * 获取自定义地区详细信息
|
|
// */
|
|
// @PreAuthorize("@ss.hasPermi('system:DiyCity:query')")
|
|
// @GetMapping(value = "/{id}")
|
|
// public AjaxResult getInfo(@PathVariable("id") Integer id)
|
|
// {
|
|
// return success(diyCityService.selectDiyCityById(id));
|
|
// }
|
|
//
|
|
// /**
|
|
// * 新增自定义地区
|
|
// */
|
|
// @PreAuthorize("@ss.hasPermi('system:DiyCity:add')")
|
|
// @Log(title = "自定义地区", businessType = BusinessType.INSERT)
|
|
// @PostMapping
|
|
// public AjaxResult add(@RequestBody DiyCity diyCity)
|
|
// {
|
|
// return toAjax(diyCityService.insertDiyCity(diyCity));
|
|
// }
|
|
//
|
|
// /**
|
|
// * 修改自定义地区
|
|
// */
|
|
// @PreAuthorize("@ss.hasPermi('system:DiyCity:edit')")
|
|
// @Log(title = "自定义地区", businessType = BusinessType.UPDATE)
|
|
// @PutMapping
|
|
// public AjaxResult edit(@RequestBody DiyCity diyCity)
|
|
// {
|
|
// return toAjax(diyCityService.updateDiyCity(diyCity));
|
|
// }
|
|
//
|
|
// /**
|
|
// * 删除自定义地区
|
|
// */
|
|
// @PreAuthorize("@ss.hasPermi('system:DiyCity:remove')")
|
|
// @Log(title = "自定义地区", businessType = BusinessType.DELETE)
|
|
// @DeleteMapping("/{ids}")
|
|
// public AjaxResult remove(@PathVariable Integer[] ids)
|
|
// {
|
|
// return toAjax(diyCityService.deleteDiyCityByIds(ids));
|
|
// }
|
|
//}
|