Commit ff9a774e authored by lining's avatar lining

feat: common/tree接口

parent 53916982
......@@ -14,6 +14,8 @@ public class RedisKeyConstants {
*/
public static final String BASE_AREA_TREE = "base:area_tree";
public static final String SERVICE_AREA_TREE = "service:area_tree";
public static final String CHECK_CODE_KEY = "code:%s:%s";
public static final int CODE_EXPIRED = 10 * 60 * 1000;
......
package com.onsiteservice.miniapp.controller.area;
import com.onsiteservice.entity.area.ServiceArea;
import com.onsiteservice.miniapp.service.area.ServiceAreaService;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.common.page.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import javax.validation.constraints.Positive;
import static com.onsiteservice.core.result.ResultGenerator.success;
import static com.onsiteservice.core.result.ResultGenerator.fail;
/**
* @author 潘维吉
* @date 2022-07-08 09:11
* @description ServiceAreaController控制类
*/
@ApiIgnore
@Api(tags = "ServiceAreaController")
@RestController
@RequestMapping("/service/area")
@Validated
public class ServiceAreaController {
@Resource
private ServiceAreaService serviceAreaService;
@ApiOperation(value = "分页查询列表", notes = "作者: 潘维吉")
@PostMapping("/page")
public Result<PageInfoVO> getPage(@RequestBody @NonNull @Validated PageParams param) {
return success(serviceAreaService.getPage(param), "获取分页列表");
}
@ApiOperation(value = "根据id查询", notes = "作者: 潘维吉")
@GetMapping("/{id}")
public Result<ServiceArea> getDetails(@PathVariable @Positive Long id) {
return success(serviceAreaService.selectByPrimaryKey(id), "根据id获取详情");
}
@ApiOperation(value = "新增或修改", notes = "作者: 潘维吉")
@PostMapping("/save-or-update")
public Result saveOrUpdate(@RequestBody @NonNull @Validated ServiceArea serviceArea) {
return success(serviceAreaService.saveOrUpdate(serviceArea), serviceArea.getId() == null ? "新增成功" : "修改成功");
}
@ApiOperation(value = "根据id删除", notes = "作者: 潘维吉")
@DeleteMapping("/{id}")
public Result deleteById(@PathVariable @Positive Long id) {
return success(serviceAreaService.deleteByPrimaryKey(id), "删除成功");
}
}
......@@ -2,6 +2,7 @@ package com.onsiteservice.miniapp.controller.category;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.miniapp.controller.category.vo.HomeViewVO;
import com.onsiteservice.miniapp.controller.category.vo.ServiceAreaVO;
import com.onsiteservice.miniapp.service.category.HomeCommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* <P>服务大类模块</P>
......@@ -36,5 +38,11 @@ public class HomeCommonController {
return homeCommonService.home();
}
@ApiOperation(value = "地域树")
@GetMapping("tree")
public Result tree() {
return homeCommonService.tree();
}
}
package com.onsiteservice.miniapp.controller.category.vo;
import com.onsiteservice.common.controller.vo.AreaTreeVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel("服务区域值对象")
public class ServiceAreaVO {
@ApiModelProperty("主键")
private Long id;
@ApiModelProperty("编码")
private String code;
@ApiModelProperty("父编码")
private String parentCode;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("名称路径")
private String namePath;
@ApiModelProperty("市区街道 city district street")
private String level;
@ApiModelProperty("经度,纬度")
private String center;
@ApiModelProperty("子节点")
private List<ServiceAreaVO> children;
}
\ No newline at end of file
package com.onsiteservice.miniapp.service.category;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.constant.constant.RedisKeyConstants;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
import com.onsiteservice.dao.mapper.banner.BannerMapper;
import com.onsiteservice.dao.mapper.home.HomeNoticeMapper;
import com.onsiteservice.dao.mapper.service.ServiceAreaMapper;
import com.onsiteservice.entity.area.ServiceArea;
import com.onsiteservice.entity.banner.Banner;
import com.onsiteservice.entity.home.HomeNotice;
import com.onsiteservice.miniapp.controller.category.vo.BannerVO;
import com.onsiteservice.miniapp.controller.category.vo.HomeNoticeVO;
import com.onsiteservice.miniapp.controller.category.vo.HomeViewVO;
import com.onsiteservice.miniapp.controller.category.vo.ServiceCategoryVO;
import com.onsiteservice.miniapp.controller.category.vo.*;
import com.onsiteservice.util.AttrCopyUtils;
import com.onsiteservice.util.tree.TreeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
......@@ -21,6 +29,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class HomeCommonService {
......@@ -31,9 +40,15 @@ public class HomeCommonService {
@Resource
private HomeNoticeMapper homeNoticeMapper;
@Resource
private ServiceAreaMapper serviceAreaMapper;
@Resource
private ServiceCategoryService serviceCategoryService;
@Autowired
private StringRedisTemplate redisTemplate;
public Result<HomeViewVO> home() {
// 轮播图
......@@ -60,5 +75,24 @@ public class HomeCommonService {
return ResultGenerator.success(homeViewVO);
}
public Result tree() {
String value = redisTemplate.opsForValue().get(RedisKeyConstants.SERVICE_AREA_TREE);
try {
List<ServiceAreaVO> data = JSONArray.parseArray(value, ServiceAreaVO.class);
if (!CollectionUtils.isEmpty(data)) {
return ResultGenerator.success(data);
}
} catch (Exception e) {
log.error("common tree, 转型失败 ", e);
}
List<ServiceArea> serviceAreaList = serviceAreaMapper.selectAll();
List<ServiceAreaVO> serviceAreaVOList = serviceAreaList.parallelStream().map(e -> AttrCopyUtils.copy(e, new ServiceAreaVO())).collect(Collectors.toList());
List<ServiceAreaVO> list = TreeUtils.getTree(serviceAreaVOList, ServiceAreaVO::getCode, ServiceAreaVO::getParentCode, ServiceAreaVO::setChildren);
redisTemplate.opsForValue().set(RedisKeyConstants.SERVICE_AREA_TREE, JSON.toJSONString(list));
return ResultGenerator.success(list);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment