Commit 9f89f026 authored by linruibiao's avatar linruibiao

接口编写

parent b0407853
......@@ -58,6 +58,8 @@ public class BaseRestController {
protected String variableHistoryDataList;
@Value("${dc_client.interfaces.variableRealTimeDataList}")
protected String variableRealTimeDataList;
@Value("${dc_client.interfaces.filedValue}")
protected String filedValue;
......
package com.syc.slm.slmbi.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syc.slm.common.core.util.R;
import com.syc.slm.slmbi.dto.BusinessDTO;
import com.syc.slm.slmbi.entity.CurrentUser;
......@@ -57,4 +58,15 @@ public class BusinessConfigController extends BaseRestController{
return businessConfigService.getBusinessData(dto,dcClientHost+businessFiledData,currentUser);
});
}
@GetMapping("/filed-value/{tableName}/{filed}")
@ApiOperation("根据字段以及表名查询对应的字段")
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class)
public R<IPage<String>> filedValue(HttpServletRequest request,
@PathVariable String appId, @PathVariable String tableName, @PathVariable String filed, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "size",defaultValue = "100") Integer size, @RequestParam(value = "name", required = false) String name) {
return call(() -> {
CurrentUser currentUser = getCurrentUser(request);
return businessConfigService.filedValue(currentUser,tableName, filed,current,size,name,dcClientHost+filedValue);
});
}
}
package com.syc.slm.slmbi.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.syc.slm.slmbi.dto.BusinessDTO;
import com.syc.slm.slmbi.entity.BusinessConfig;
......@@ -37,4 +38,18 @@ public interface BusinessConfigService extends IService<BusinessConfig> {
* @return
*/
List<Map<String, Object>> getBusinessData(BusinessDTO dto,String uri, CurrentUser user);
/**
* 根据字段以及表名查询对应的字段
* @param currentUser
* @param tableName
* @param filed
* @param current
* @param size
* @param name
* @param uri
* @return
*/
IPage<String> filedValue(CurrentUser currentUser,String tableName, String filed, Integer current, Integer size,String name,String uri);
}
package com.syc.slm.slmbi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
......@@ -22,6 +24,7 @@ import com.syc.slm.slmbi.vo.BusinessConfigVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
......@@ -110,4 +113,35 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
R<List<Map<String, Object>>> result = RestTemplateUtils.post(uri, heads,dto, new TypeToken<R<List<Map<String, Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
@Override
@Transactional(readOnly = true)
public IPage<String> filedValue(CurrentUser currentUser,String tableName, String filed, Integer current, Integer size,String name,String uri) {
if(StringUtils.isBlank(tableName)){
throw new SysException("表名必填");
}
if(StringUtils.isBlank(filed)){
throw new SysException("对应检索字段必填");
}
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", currentUser.getToken());
Map<String, Object> uriVariables = Maps.newHashMap();
uriVariables.put("appId", currentUser.getAppId());
uriVariables.put("filed", filed);
uriVariables.put("tableName", tableName);
uriVariables.put("current", current);
uriVariables.put("size", size);
uriVariables.put("name", name);
IPage<String> page = new Page<>(current,size);
R<Map<String,Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
Map<String, Object> resultMaps = result.detach();
if(CollectionUtils.isNotEmpty(resultMaps)){
page.setTotal(new BigDecimal(resultMaps.get("total")+"").longValue());
List<String> records = SlmConstants.gson.fromJson(SlmConstants.gson.toJson(resultMaps.get("records")), new TypeToken<List<String>>() {}.getType());
page.setRecords(records);
}else{
page.setTotal(0L);
}
return page;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment