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.ApiList; import com.zy.asrs.common.openapi.service.ApiListService; 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 ApiListController extends BaseController { @Autowired private ApiListService apiListService; @RequestMapping(value = "/apiList/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(apiListService.getById(String.valueOf(id))); } @RequestMapping(value = "/apiList/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 param) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(ApiList::getId, condition); } if (!Cools.isEmpty(timeRange)) { String[] range = timeRange.split(RANGE_TIME_LINK); wrapper.ge(ApiList::getCreateTime, DateUtils.convert(range[0])); wrapper.le(ApiList::getCreateTime, DateUtils.convert(range[1])); } if (!Cools.isEmpty(param.get("url"))) { wrapper.eq(ApiList::getUrl, param.get("url")); } if (!Cools.isEmpty(param.get("type"))) { wrapper.eq(ApiList::getType, param.get("type")); } if (!Cools.isEmpty(param.get("status"))) { wrapper.eq(ApiList::getStatus, param.get("status")); } if (!Cools.isEmpty(param.get("hostId"))) { wrapper.eq(ApiList::getHostId, param.get("hostId")); } return R.ok(apiListService.page(new Page<>(curr, limit), wrapper)); } @RequestMapping(value = "/apiList/add/auth") @ManagerAuth public R add(ApiList apiList) { ApiList one = apiListService.getOne(new LambdaQueryWrapper() .eq(ApiList::getUrl, apiList.getUrl()) .eq(ApiList::getType, apiList.getType()) .eq(ApiList::getHostId, apiList.getHostId())); if (one != null) { apiListService.removeById(one.getId()); } apiList.setCreateTime(new Date()); apiListService.save(apiList); return R.ok(); } @RequestMapping(value = "/apiList/update/auth") @ManagerAuth public R update(ApiList apiList){ if (Cools.isEmpty(apiList) || null==apiList.getId()){ return R.error(); } apiList.setCreateTime(new Date()); apiListService.updateById(apiList); return R.ok(); } @RequestMapping(value = "/apiList/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ apiListService.removeById(id); } return R.ok(); } @RequestMapping(value = "/apiListQuery/auth") @ManagerAuth public R query(String condition) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.like(ApiList::getId, condition); Page page = apiListService.page(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (ApiList apiList : page.getRecords()){ Map map = new HashMap<>(); map.put("id", apiList.getId()); map.put("value", apiList.getId()); result.add(map); } return R.ok(result); } @RequestMapping("/apiList/all/get/kv") @ManagerAuth public R getDataKV(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(ApiList::getId, condition); } apiListService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); return R.ok().add(vos); } }