| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package com.ylx.web.controller.massage;
- import cn.hutool.core.collection.CollectionUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.StringUtils;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.ylx.common.core.domain.R;
- import com.ylx.massage.domain.Area;
- import com.ylx.massage.domain.dto.CoordinateDTO;
- import com.ylx.massage.domain.vo.AreaTreeNode;
- import com.ylx.massage.domain.vo.CityInfoVo;
- import com.ylx.massage.service.AreaService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.io.Serializable;
- import java.util.List;
- /**
- * 区域数据(Area)表控制层
- *
- * @author makejava
- * @since 2024-07-01 09:22:27
- */
- @RestController
- @Api(tags = {"区域数据表控制层"})
- @RequestMapping("area")
- public class AreaController {
- /**
- * 服务对象
- */
- @Resource
- private AreaService areaService;
- /**
- * 分页查询所有数据
- *
- * @param page 分页对象
- * @param area 查询实体
- * @return 所有数据
- */
- @GetMapping
- public R selectAll(Page<Area> page, Area area) {
- return R.ok(this.areaService.page(page, new QueryWrapper<>(area)));
- }
- @GetMapping("/select")
- @ApiOperation("按层级查询")
- public R select(Area area) {
- LambdaQueryWrapper<Area> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
- objectLambdaQueryWrapper.eq(null != area.getLevel(),Area::getLevel, area.getLevel())
- .eq(StringUtils.isNotBlank(area.getParentCode()),Area::getParentCode, area.getParentCode());
- return R.ok(this.areaService.list(objectLambdaQueryWrapper));
- }
- /**
- * 通过主键查询单条数据
- *
- * @param id 主键
- * @return 单条数据
- */
- @GetMapping("{id}")
- public R selectOne(@PathVariable Serializable id) {
- return R.ok(this.areaService.getById(id));
- }
- /**
- * 新增数据
- *
- * @param area 实体对象
- * @return 新增结果
- */
- @PostMapping
- public R insert(@RequestBody Area area) {
- return R.ok(this.areaService.save(area));
- }
- /**
- * 修改数据
- *
- * @param area 实体对象
- * @return 修改结果
- */
- @PutMapping
- public R update(@RequestBody Area area) {
- return R.ok(this.areaService.updateById(area));
- }
- /**
- * 删除数据
- *
- * @param idList 主键结合
- * @return 删除结果
- */
- @DeleteMapping
- public R delete(@RequestParam("idList") List<Long> idList) {
- return R.ok(this.areaService.removeByIds(idList));
- }
- /**
- * 根据城市名称查询编码
- * @param name
- * @return R
- */
- @GetMapping("/code")
- @ApiOperation("name获取code")
- public R getCodeByName(@RequestParam String name) {
- LambdaQueryWrapper<Area> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(Area::getName, name);
- List<Area> list = this.areaService.list(queryWrapper);
- if (CollectionUtil.isEmpty(list)) {
- return R.fail("未找到此数据");
- }
- return R.ok(CollectionUtil.getFirst(list).getCode());
- }
- @GetMapping("/tree")
- @ApiOperation("获取全量区域树形结构")
- public R<List<AreaTreeNode>> getAreaTree() {
- List<AreaTreeNode> tree = this.areaService.getAreaTree();
- return R.ok(tree);
- }
- @PostMapping("/city")
- @ApiOperation("根据经纬度获取城市信息")
- public R<CityInfoVo> getCityInfoByCoordinates(@RequestBody CoordinateDTO dto) {
- CityInfoVo cityInfoVo = this.areaService.getCityInfoByCoordinates(dto);
- return R.ok(cityInfoVo);
- }
- }
|