Commit 80a3038d authored by ysongq's avatar ysongq

commit

parent 3c1a67a6
......@@ -2,6 +2,7 @@ package com.jz.dm.gateway.org;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jz.common.utils.Result;
import com.jz.dm.common.enums.auth.AuthTypeEnum;
import com.jz.dm.gateway.SpringTestCase;
import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq;
......@@ -54,11 +55,13 @@ public class TestOrganizationManage extends SpringTestCase {
@Test
public void addOrg(){
OrganizationManageAddReq req = new OrganizationManageAddReq();
req.setOrgName("ABCOO");
req.setOrgName("数据银行");
req.setOrgDesc("粗这次");
req.setOrgCnName("AOKK");
req.setOrgCnName("databank");
req.setOrgMail("7273JA@QQ.COM");
req.setRemark("sfsihsio");
req.setOrgPhone("18279668524");
req.setOrgType(AuthTypeEnum.DATA_BANK_AUTH.name());
Result result = organizationManageService.add(req);
System.out.println(result.getMessage());
}
......
package com.jz.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONWriter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.*;
......@@ -193,6 +194,62 @@ public final class WebUtils {
return readContent;
}
/**
* 通过流方式传数据
*
* @param uri
* @param data
* @return
*/
public static String postJSON(String uri, Object data) {
log.info("向银行发起参数:{}", JSONObject.toJSONString(data));
CloseableHttpClient httpClient = getHttpClient(uri);
HttpPost method = new HttpPost(uri);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(CONNECT_TIMEOUT)
.setConnectTimeout(CONNECT_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT).build();
method.setConfig(requestConfig);
String readContent = null;
try {
method.addHeader("Content-type", "application/json; charset=ISO-8859-1");
//method.setHeader("Accept", "application/xml");
method.setEntity(new StringEntity(data.toString(), Charset.forName("utf-8")));
HttpResponse response = httpClient.execute(method, HttpClientContext.create());
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
return "failed";
}
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
int count = 0;
while (count == 0) {
count = Integer.parseInt("" + entity.getContentLength());// in.available();
}
if (count <= 0) {
return EntityUtils.toString(entity);
}
byte[] bytes = new byte[count];
int readCount = 0; // 已经成功读取的字节的个数
while (readCount <= count) {
if (readCount == count) {
break;
}
readCount += in.read(bytes, readCount, count - readCount);
}
readContent = new String(bytes, 0, readCount, "UTF-8");
log.info("Get Response Content():\n {}", readContent);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return readContent;
}
/**
* 关闭连接池
*/
......
......@@ -3,9 +3,11 @@ package com.jz.manage;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableTransactionManagement
......@@ -17,4 +19,9 @@ public class manageApplication {
public static void main(String[] args) {
SpringApplication.run(manageApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
......@@ -7,6 +7,7 @@ import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
......@@ -19,7 +20,7 @@ import java.util.List;
*/
@Data
@ApiModel(value = "自营数据--api上传参数对象", description = "api上传参数对象")
public class DataApiUpReq {
public class DataApiUpReq implements Serializable {
/**
* api表
......
package com.jz.manage.moduls.controller.goods.bean.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.req.make
* @PROJECT_NAME: jz-dm-parent
* @NAME: MakeDataBankApiReq
* @DATE: 2020-12-30/15:32
* @DAY_NAME_SHORT: 周三
* @Description:
**/
@Data
@ApiModel("数据银行api制作")
public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty(value = "api类型:1 实时接入 2 数据银行制作API, 3 数据银行制作数据包 6标签查询 9自定义",required = true)
@NotNull(message = "api类型不能为空")
public String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空")
public String apiId;
@ApiModelProperty(value = "接口描述",required = false)
public String apiDesc;
@ApiModelProperty(value = "api版本",required = false)
public String version;
@ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true)
@NotNull(message = "传输方式不能为空")
public String transMode;
@ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true)
@NotNull(message = "加密方式不能为空")
public String type;
@ApiModelProperty(value = "目标地址",required = false)
public String targetUrl;
@ApiModelProperty(value = "超时时间",required = false)
public String timeout;
@ApiModelProperty(value = "api描述",required = false)
public String apiFunction;
@ApiModelProperty(value = "请求头",required = false)
public String reqHeaders;
@ApiModelProperty(value = "请求参数",required = false)
public String requestParam;
@ApiModelProperty(value = "响应参数",required = false)
public String responseParam;
@ApiModelProperty(value = "响应状态码",required = false)
public String respCode;
@ApiModelProperty(value = "api样例",required = false)
public String apiExample;
}
......@@ -13,6 +13,8 @@ import com.jz.common.constant.ResultCode;
import com.jz.common.constant.ResultMsg;
import com.jz.common.entity.DataGoods;
import com.jz.common.utils.DateUtils;
import com.jz.common.utils.HttpClientUtils;
import com.jz.common.utils.Result;
import com.jz.common.utils.WebUtils;
import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsDto;
......@@ -20,6 +22,7 @@ import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsListDto;
import com.jz.manage.moduls.controller.goods.bean.request.DataApiUpReq;
import com.jz.manage.moduls.controller.goods.bean.request.DataGoodsListRequest;
import com.jz.manage.moduls.controller.goods.bean.request.DataGoodsRequest;
import com.jz.manage.moduls.controller.goods.bean.request.MakeDataBankApiReq;
import com.jz.manage.moduls.entity.DataGoodsApi;
import com.jz.manage.moduls.entity.DataGoodsApiParams;
import com.jz.manage.moduls.mapper.DataGoodsApiDao;
......@@ -63,7 +66,8 @@ public class DataGoodsServiceImpl implements DataGoodsService {
@Autowired
private DataGoodsApiDao tDataGoodsApiDao;
@Autowired
private RestTemplate restTemplate;
/**
* 条件分页查询数据列表
*
......@@ -215,7 +219,7 @@ public class DataGoodsServiceImpl implements DataGoodsService {
if (!StringUtils.isNotEmpty(dataApiUpReq.getEncryMode())) {
return Result.error("加密方式不能为空!");
}
MakeDataBankApiReq apiReq = new MakeDataBankApiReq();
DataGoods dataGoods = new DataGoods();
dataApiUpReq.setApiOpenId("wj"+DateUtils.getHMS());
dataApiUpReq.setCreTime(DateUtils.getToday());
......@@ -231,6 +235,7 @@ public class DataGoodsServiceImpl implements DataGoodsService {
Long dataGoodsId = dataGoods.getDataGoodsId();
if (dataGoodsId != null) {
DataGoodsApi dataGoodsApi = new DataGoodsApi();
dataGoodsApi.setDataGoodsId(dataGoodsId);
dataApiUpReq.setCreTime(DateUtils.getToday());
dataApiUpReq.setCrePerson(user.getUserId() + "");
......@@ -240,6 +245,20 @@ public class DataGoodsServiceImpl implements DataGoodsService {
BeanUtils.copyProperties(dataApiUpReq, dataGoodsApi);
tDataGoodsApiDao.insert(dataGoodsApi);
apiReq.setApiDesc(dataApiUpReq.getApiDesc());
apiReq.setApiExample("");
apiReq.setApiFunction(dataApiUpReq.getApiFunction());
apiReq.setApiId(dataApiUpReq.getApiKey());
apiReq.setApiType(dataApiUpReq.getApiType());
apiReq.setVersion(dataApiUpReq.getVersionNumber());
apiReq.setTransMode(dataApiUpReq.getTransMode());
apiReq.setType(dataApiUpReq.getEncryMode());
apiReq.setTargetUrl(dataApiUpReq.getTargetUrl());
apiReq.setTimeout(dataApiUpReq.getOverTime() + "");
apiReq.setReqHeaders("sdadasd");
apiReq.setRequestParam("sdadasdd");
apiReq.setResponseParam("fklfhklfhlh");
apiReq.setRespCode("sdkadlahlf");
// 赋值params
Long goodsApi = dataGoodsApi.getGoodsApi();
if (goodsApi != null) {
......@@ -250,11 +269,19 @@ public class DataGoodsServiceImpl implements DataGoodsService {
dataApiUpReq.setCrePerson(user.getUserId() + "");
BeanUtils.copyProperties(dataApiUpReq, params);
apiParamsDao.insert(params);
}
}
}
WebUtils.post("http://localhost:8088/apigateway/", JSONObject.toJSONString(dataApiUpReq));
try {
String url= "http://192.168.1.114:8088/api/producer/addDataBankApiInfo";
// HttpClientUtils.doPost("", );
WebUtils.postJSON(url, apiReq);
} catch (Exception e) {
e.printStackTrace();
}
// return Result.of_success(ResultMsg.SUCCESS, ResultCode.SUCCESS);
......
package com.jz.manage;
import com.jz.common.utils.DateUtils;
import com.jz.manage.moduls.controller.goods.bean.request.DataApiUpReq;
import com.jz.manage.moduls.entity.DataGoodsApiParams;
import com.jz.manage.moduls.service.DataGoodsService;
import com.jz.manage.moduls.service.SysUserService;
import com.jz.manage.moduls.service.TestUserService;
import org.junit.Test;
......@@ -8,6 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class manageApplicationTests {
......@@ -15,6 +23,8 @@ public class manageApplicationTests {
private TestUserService userService;
@Autowired
private SysUserService sysUserService;
@Autowired
private DataGoodsService dataGoodsService;
@Test
public void contextLoads() {
......@@ -27,8 +37,30 @@ public class manageApplicationTests {
}
@Test
public void getUserRoleByAccount() {
sysUserService.getUserRoleByAccount("moduls");
//System.out.print(sysUserService.getTest().toString());
public void getUserRoleByAccount() throws Exception {
DataApiUpReq dataApiUpReq = new DataApiUpReq();
dataApiUpReq.setApiName("华为");
dataApiUpReq.setRequestType("的撒旦");
dataApiUpReq.setApiUrl("http://localhost/dataGoods/uploadApi");
dataApiUpReq.setReturnDataExample("dadasdadafaf");
dataApiUpReq.setApiKey("5");
dataApiUpReq.setEncryMode("MD5");
dataApiUpReq.setTransMode("http");
dataApiUpReq.setApiFunction("fafafaffaf");
dataApiUpReq.setVersionNumber("1.0");
dataApiUpReq.setPriceType("01");
dataApiUpReq.setApiType("1");
dataApiUpReq.setApiDesc("fafsafafasff");
dataApiUpReq.setDataPicture("http://wx4.sinaimg.cn/bmiddle/006GJQvhly1gkx4ezwcr4j328g28g1kx.jpg");
dataApiUpReq.setYearType(BigDecimal.valueOf(1));
List<DataGoodsApiParams> paramsList = new ArrayList<>();
for (DataGoodsApiParams params : paramsList) {
params.setParamsDiff("01");
params.setParamsName("xiaomi");
params.setParamsType("哒哒哒");
params.setCreTime(DateUtils.getToday());
}
dataApiUpReq.setParamsList(paramsList);
dataGoodsService.uploadApi(dataApiUpReq);
}
}
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