luodangjia
2024-04-24 dab3a5bc8f4dda5bf1f1e2e6b75d2c17df8e9e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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())
        ));
    }
 
}