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);
|
}
|
|
}
|