package cn.stylefeng.rest.modular.home.controller;
|
|
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.json.JSONUtil;
|
import cn.stylefeng.guns.modular.business.entity.Area;
|
import cn.stylefeng.guns.modular.business.entity.SystemSet;
|
import cn.stylefeng.guns.modular.business.service.IAreaService;
|
import cn.stylefeng.guns.modular.business.service.ISystemSetService;
|
import cn.stylefeng.guns.utils.ObsUtil;
|
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
import cn.stylefeng.roses.kernel.rule.enums.*;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 主页接口-html富文本页面
|
*
|
* @author goupan
|
* @date 2024/01/02
|
*/
|
@RestController
|
@Api(tags = "公共接口")
|
@ApiResource(name = "公共接口")
|
@RequestMapping("/public")
|
public class PublicController {
|
|
@Resource
|
private ObsUtil obsUtil;
|
|
@Resource
|
private CacheOperatorApi<Object> objectCacheOperatorApi;
|
|
@Resource
|
private IAreaService areaService;
|
|
@Resource
|
private ISystemSetService systemSetService;
|
|
@ApiOperation("获取地区码表")
|
@GetResource(name = "获取地区码表", path = "/areaList", requiredPermission = false)
|
public ResponseData<List<Area>> areaList() {
|
List<Area> areaList;
|
// 缓存获取地区码表
|
Object areaCache = objectCacheOperatorApi.get(RuleConstants.AREA_CACHE_KEY);
|
if (ObjUtil.isNotEmpty(areaCache)){
|
areaList = JSONUtil.parseArray(areaCache).toList(Area.class);
|
return new SuccessResponseData<>(areaList);
|
}
|
|
// 查询p0级地区
|
areaList = areaService.list(
|
Wrappers.<Area>lambdaQuery()
|
.select(Area::getId, Area::getPid, Area::getName)
|
.eq(Area::getPid, 0)
|
.orderByAsc(Area::getId)
|
);
|
// 查询p1/2级地区
|
List<Area> areaListP12 = areaService.list(
|
Wrappers.<Area>lambdaQuery()
|
.select(Area::getId, Area::getPid, Area::getName)
|
.eq(Area::getLevel, 2)
|
.or().eq(Area::getLevel, 3)
|
.orderByAsc(Area::getId)
|
);
|
|
// pid相同地区分组
|
Map<Integer, List<Area>> groupAreasByPidMap = new HashMap<>();
|
for (Area area : areaListP12) {
|
Integer pid = area.getPid();
|
// 如果pid不存在,则添加一个新的空列表
|
groupAreasByPidMap.putIfAbsent(pid, new ArrayList<>());
|
// 将当前Area添加到对应pid的列表中
|
groupAreasByPidMap.get(pid).add(area);
|
}
|
|
areaList.stream().forEach(p0 -> {
|
List<Area> p1Area = groupAreasByPidMap.get(p0.getId());
|
p1Area.forEach(p1 -> {
|
List<Area> p2Area = groupAreasByPidMap.get(p1.getId());
|
p1.setChildAreaList(p2Area);
|
});
|
p0.setChildAreaList(p1Area);
|
});
|
|
// 地区码表存入缓存
|
objectCacheOperatorApi.put(RuleConstants.AREA_CACHE_KEY, areaList);
|
|
return new SuccessResponseData<>(areaList);
|
}
|
|
@ApiOperation("配置(H5、客服电话、启动页)目录")
|
@GetMapping(RuleConstants.NOT_LOGIN + "/setList")
|
@GetResource(name = "配置(H5、客服电话、启动页)目录", path = RuleConstants.NOT_LOGIN + "/setList", requiredPermission = false, requiredLogin = false)
|
public ResponseData<List<SystemSet>> setList() {
|
// 查询列表
|
List<SystemSet> list = systemSetService.list(
|
Wrappers.<SystemSet>lambdaQuery()
|
.select(SystemSet::getId, SystemSet::getKeyStr, SystemSet::getRemark)
|
);
|
return new SuccessResponseData(list);
|
}
|
|
@ApiOperation(value = "配置(H5、客服电话、启动页)信息", notes = "通过h5配置目录,获取id查询")
|
@GetMapping(RuleConstants.NOT_LOGIN + "/setDetail/{id}")
|
@GetResource(name = "配置(H5、客服电话、启动页)信息", path = RuleConstants.NOT_LOGIN + "/setDetail/{id}", requiredPermission = false, requiredLogin = false)
|
public ResponseData<SystemSet> setDetail(@PathVariable("id") Long id) {
|
// 查询详情
|
SystemSet obj = systemSetService.getById(id);
|
return new SuccessResponseData(obj);
|
}
|
|
@ApiOperation("文件上传")
|
@PostResource(name = "文件上传", path = "/uploadFile")
|
public ResponseData uploadFile(@RequestPart("file") MultipartFile file) {
|
String url = obsUtil.upload(file);
|
if (StrUtil.isEmpty(url)) {
|
return new ErrorResponseData("文件上传失败");
|
}
|
return new SuccessResponseData(url);
|
}
|
|
@ApiOperation("枚举说明")
|
@PostResource(name = "枚举说明", path = RuleConstants.NOT_LOGIN + "/enumDesc")
|
public ResponseData enumDesc() {
|
return new SuccessResponseData(Arrays.asList(
|
Arrays.stream(CustomerMentalAnalysisStatusEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(DeleteEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(ImPushTypeEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(ImStatusEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(MentalAppointmentStatusEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(OrderStatusFlagEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(PostIdEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(PostTypeEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(SexEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(StatusEnum.values()).map(e -> e.toString()).collect(Collectors.toList()),
|
Arrays.stream(SystemSetEnum.values()).map(e -> e.toString()).collect(Collectors.toList())
|
));
|
}
|
|
}
|