#
Junjie
2024-01-08 8d530a2bc48f5f28937e0b4507b7deccf9e34e92
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
package com.zy.asrs.openapi.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.common.openapi.entity.ApiLog;
import com.zy.asrs.common.openapi.service.ApiLogService;
import com.zy.asrs.framework.annotations.ManagerAuth;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.domain.KeyValueVo;
import com.zy.asrs.framework.common.DateUtils;
import com.zy.asrs.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
public class ApiLogController extends BaseController {
 
    @Autowired
    private ApiLogService apiLogService;
 
    @RequestMapping(value = "/apiLog/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(apiLogService.getById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/apiLog/page/auth")
    @ManagerAuth
    public R page(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "10") Integer limit,
                  @RequestParam(required = false) String condition,
                  @RequestParam(required = false) String timeRange,
                  @RequestParam Map<String, Object> param) {
        LambdaQueryWrapper<ApiLog> wrapper = new LambdaQueryWrapper<>();
        if (!Cools.isEmpty(condition)) {
            wrapper.like(ApiLog::getUuid, condition);
        }
        if (!Cools.isEmpty(timeRange)) {
            String[] range = timeRange.split(RANGE_TIME_LINK);
            wrapper.ge(ApiLog::getCreateTime, DateUtils.convert(range[0]));
            wrapper.le(ApiLog::getCreateTime, DateUtils.convert(range[1]));
        }
        return R.ok(apiLogService.page(new Page<>(curr, limit), wrapper));
    }
 
 
    @RequestMapping(value = "/apiLog/add/auth")
    @ManagerAuth
    public R add(ApiLog apiLog) {
        apiLogService.save(apiLog);
        return R.ok();
    }
 
    @RequestMapping(value = "/apiLog/update/auth")
    @ManagerAuth
    public R update(ApiLog apiLog){
        if (Cools.isEmpty(apiLog) || null==apiLog.getId()){
            return R.error();
        }
        apiLogService.updateById(apiLog);
        return R.ok();
    }
 
    @RequestMapping(value = "/apiLog/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
            apiLogService.removeById(id);
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/apiLogQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        LambdaQueryWrapper<ApiLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ApiLog::getUuid, condition);
        Page<ApiLog> page = apiLogService.page(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (ApiLog apiLog : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", apiLog.getId());
            map.put("value", apiLog.getUuid());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping("/apiLog/all/get/kv")
    @ManagerAuth
    public R getDataKV(@RequestParam(required = false) String condition) {
        List<KeyValueVo> vos = new ArrayList<>();
        LambdaQueryWrapper<ApiLog> wrapper = new LambdaQueryWrapper<>();
        if (!Cools.isEmpty(condition)) {
            wrapper.like(ApiLog::getUuid, condition);
        }
        apiLogService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getUuid()), item.getId())));
        return R.ok().add(vos);
    }
 
}