package com.iailab.module.data.gateway.controller;
|
|
import com.iailab.module.data.common.utils.PageUtils;
|
import com.iailab.module.data.common.utils.R;
|
import com.iailab.module.data.gateway.service.ApiAuthorizedService;
|
import com.iailab.module.data.gateway.entity.ApiAppEntity;
|
import com.iailab.module.data.gateway.service.ApiAppService;
|
import org.apache.commons.lang3.RandomStringUtils;
|
import javax.annotation.Resource;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2022年07月15日 14:13:00
|
*/
|
@RestController
|
@RequestMapping("/api-gateway/app")
|
public class ApiAppController {
|
@Resource
|
private ApiAppService apiAppService;
|
|
@Resource
|
private ApiAuthorizedService apiAuthorizedService;
|
|
/**
|
* 合作方APP列表
|
*
|
* @param params
|
* @return
|
*/
|
@GetMapping("/list")
|
public R list(@RequestParam Map<String, Object> params) {
|
PageUtils page = apiAppService.queryPage(params);
|
return R.ok().put("page", page);
|
}
|
|
/**
|
* 新增合作方APP
|
*
|
* @param apiAppEntity
|
* @return
|
*/
|
@PostMapping("/add")
|
public R add(@RequestBody ApiAppEntity apiAppEntity) {
|
int count = apiAppService.cheack(apiAppEntity);
|
if (count > 0) {
|
return R.error("名称或数据值重复");
|
}
|
apiAppEntity.setCreateTime(new Date());
|
apiAppService.add(apiAppEntity);
|
return R.ok();
|
}
|
|
/**
|
* 更新合作方APP
|
*
|
* @param apiAppEntity
|
* @return
|
*/
|
@PostMapping("/update")
|
public R update(@RequestBody ApiAppEntity apiAppEntity) {
|
int count = apiAppService.cheack(apiAppEntity);
|
if (count > 0) {
|
return R.error("名称或数据值重复");
|
}
|
apiAppEntity.setCreateTime(new Date());
|
apiAppService.update(apiAppEntity);
|
return R.ok();
|
}
|
|
/**
|
* 重置Secret
|
*
|
* @param apiAppEntity
|
* @return
|
*/
|
@PostMapping("/restAppSecret")
|
public R restAppSecret(@RequestBody ApiAppEntity apiAppEntity) {
|
ApiAppEntity apiAppEntityUpdate = new ApiAppEntity();
|
apiAppEntityUpdate.setId(apiAppEntity.getId());
|
apiAppEntityUpdate.setAppSecret(RandomStringUtils.randomAlphanumeric(8));
|
apiAppService.update(apiAppEntity);
|
return R.ok();
|
}
|
|
/**
|
* 删除合作方APP
|
*
|
* @param params
|
* @return
|
*/
|
@PostMapping("/delete")
|
public R delete(@RequestBody Map<String, Object> params) {
|
String id = (String)params.get("id");
|
apiAppService.deleteById(id);
|
return R.ok();
|
}
|
|
/**
|
* 合作方APP详情
|
*
|
* @param id
|
* @return
|
*/
|
@RequestMapping("/info/{id}")
|
public R info(@PathVariable("id") String id){
|
ApiAppEntity apiAppEntity = apiAppService.getInfoById(id);
|
Map<String, Object> queryParams = new HashMap<>();
|
queryParams.put("appId", id);
|
apiAppEntity.setApiAuthorizedList(apiAuthorizedService.queryList(queryParams));
|
return R.ok().put("data", apiAppEntity);
|
}
|
}
|