Commit 80a3038d authored by ysongq's avatar ysongq

commit

parent 3c1a67a6
...@@ -2,6 +2,7 @@ package com.jz.dm.gateway.org; ...@@ -2,6 +2,7 @@ package com.jz.dm.gateway.org;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.common.enums.auth.AuthTypeEnum;
import com.jz.dm.gateway.SpringTestCase; import com.jz.dm.gateway.SpringTestCase;
import com.jz.dm.models.domian.ApiOrg; import com.jz.dm.models.domian.ApiOrg;
import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq; import com.jz.dm.models.req.organizationManage.OrganizationManageAddReq;
...@@ -54,11 +55,13 @@ public class TestOrganizationManage extends SpringTestCase { ...@@ -54,11 +55,13 @@ public class TestOrganizationManage extends SpringTestCase {
@Test @Test
public void addOrg(){ public void addOrg(){
OrganizationManageAddReq req = new OrganizationManageAddReq(); OrganizationManageAddReq req = new OrganizationManageAddReq();
req.setOrgName("ABCOO"); req.setOrgName("数据银行");
req.setOrgDesc("粗这次"); req.setOrgDesc("粗这次");
req.setOrgCnName("AOKK"); req.setOrgCnName("databank");
req.setOrgMail("7273JA@QQ.COM"); req.setOrgMail("7273JA@QQ.COM");
req.setRemark("sfsihsio"); req.setRemark("sfsihsio");
req.setOrgPhone("18279668524");
req.setOrgType(AuthTypeEnum.DATA_BANK_AUTH.name());
Result result = organizationManageService.add(req); Result result = organizationManageService.add(req);
System.out.println(result.getMessage()); System.out.println(result.getMessage());
} }
......
package com.jz.common.utils; package com.jz.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONWriter; import com.alibaba.fastjson.JSONWriter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.*; import org.apache.http.*;
...@@ -193,6 +194,62 @@ public final class WebUtils { ...@@ -193,6 +194,62 @@ public final class WebUtils {
return readContent; 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; ...@@ -3,9 +3,11 @@ package com.jz.manage;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
...@@ -17,4 +19,9 @@ public class manageApplication { ...@@ -17,4 +19,9 @@ public class manageApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(manageApplication.class, args); SpringApplication.run(manageApplication.class, args);
} }
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
} }
...@@ -7,6 +7,7 @@ import lombok.Data; ...@@ -7,6 +7,7 @@ import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -19,7 +20,7 @@ import java.util.List; ...@@ -19,7 +20,7 @@ import java.util.List;
*/ */
@Data @Data
@ApiModel(value = "自营数据--api上传参数对象", description = "api上传参数对象") @ApiModel(value = "自营数据--api上传参数对象", description = "api上传参数对象")
public class DataApiUpReq { public class DataApiUpReq implements Serializable {
/** /**
* api表 * 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; ...@@ -13,6 +13,8 @@ import com.jz.common.constant.ResultCode;
import com.jz.common.constant.ResultMsg; import com.jz.common.constant.ResultMsg;
import com.jz.common.entity.DataGoods; import com.jz.common.entity.DataGoods;
import com.jz.common.utils.DateUtils; import com.jz.common.utils.DateUtils;
import com.jz.common.utils.HttpClientUtils;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.common.utils.WebUtils; import com.jz.common.utils.WebUtils;
import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsDto; import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsDto;
...@@ -20,6 +22,7 @@ import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsListDto; ...@@ -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.DataApiUpReq;
import com.jz.manage.moduls.controller.goods.bean.request.DataGoodsListRequest; 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.DataGoodsRequest;
import com.jz.manage.moduls.controller.goods.bean.request.MakeDataBankApiReq;
import com.jz.manage.moduls.entity.DataGoodsApi; import com.jz.manage.moduls.entity.DataGoodsApi;
import com.jz.manage.moduls.entity.DataGoodsApiParams; import com.jz.manage.moduls.entity.DataGoodsApiParams;
import com.jz.manage.moduls.mapper.DataGoodsApiDao; import com.jz.manage.moduls.mapper.DataGoodsApiDao;
...@@ -63,7 +66,8 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -63,7 +66,8 @@ public class DataGoodsServiceImpl implements DataGoodsService {
@Autowired @Autowired
private DataGoodsApiDao tDataGoodsApiDao; private DataGoodsApiDao tDataGoodsApiDao;
@Autowired
private RestTemplate restTemplate;
/** /**
* 条件分页查询数据列表 * 条件分页查询数据列表
* *
...@@ -215,7 +219,7 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -215,7 +219,7 @@ public class DataGoodsServiceImpl implements DataGoodsService {
if (!StringUtils.isNotEmpty(dataApiUpReq.getEncryMode())) { if (!StringUtils.isNotEmpty(dataApiUpReq.getEncryMode())) {
return Result.error("加密方式不能为空!"); return Result.error("加密方式不能为空!");
} }
MakeDataBankApiReq apiReq = new MakeDataBankApiReq();
DataGoods dataGoods = new DataGoods(); DataGoods dataGoods = new DataGoods();
dataApiUpReq.setApiOpenId("wj"+DateUtils.getHMS()); dataApiUpReq.setApiOpenId("wj"+DateUtils.getHMS());
dataApiUpReq.setCreTime(DateUtils.getToday()); dataApiUpReq.setCreTime(DateUtils.getToday());
...@@ -231,6 +235,7 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -231,6 +235,7 @@ public class DataGoodsServiceImpl implements DataGoodsService {
Long dataGoodsId = dataGoods.getDataGoodsId(); Long dataGoodsId = dataGoods.getDataGoodsId();
if (dataGoodsId != null) { if (dataGoodsId != null) {
DataGoodsApi dataGoodsApi = new DataGoodsApi(); DataGoodsApi dataGoodsApi = new DataGoodsApi();
dataGoodsApi.setDataGoodsId(dataGoodsId); dataGoodsApi.setDataGoodsId(dataGoodsId);
dataApiUpReq.setCreTime(DateUtils.getToday()); dataApiUpReq.setCreTime(DateUtils.getToday());
dataApiUpReq.setCrePerson(user.getUserId() + ""); dataApiUpReq.setCrePerson(user.getUserId() + "");
...@@ -240,6 +245,20 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -240,6 +245,20 @@ public class DataGoodsServiceImpl implements DataGoodsService {
BeanUtils.copyProperties(dataApiUpReq, dataGoodsApi); BeanUtils.copyProperties(dataApiUpReq, dataGoodsApi);
tDataGoodsApiDao.insert(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 // 赋值params
Long goodsApi = dataGoodsApi.getGoodsApi(); Long goodsApi = dataGoodsApi.getGoodsApi();
if (goodsApi != null) { if (goodsApi != null) {
...@@ -250,11 +269,19 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -250,11 +269,19 @@ public class DataGoodsServiceImpl implements DataGoodsService {
dataApiUpReq.setCrePerson(user.getUserId() + ""); dataApiUpReq.setCrePerson(user.getUserId() + "");
BeanUtils.copyProperties(dataApiUpReq, params); BeanUtils.copyProperties(dataApiUpReq, params);
apiParamsDao.insert(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); // return Result.of_success(ResultMsg.SUCCESS, ResultCode.SUCCESS);
......
package com.jz.manage; 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.SysUserService;
import com.jz.manage.moduls.service.TestUserService; import com.jz.manage.moduls.service.TestUserService;
import org.junit.Test; import org.junit.Test;
...@@ -8,6 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,6 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
public class manageApplicationTests { public class manageApplicationTests {
...@@ -15,6 +23,8 @@ public class manageApplicationTests { ...@@ -15,6 +23,8 @@ public class manageApplicationTests {
private TestUserService userService; private TestUserService userService;
@Autowired @Autowired
private SysUserService sysUserService; private SysUserService sysUserService;
@Autowired
private DataGoodsService dataGoodsService;
@Test @Test
public void contextLoads() { public void contextLoads() {
...@@ -27,8 +37,30 @@ public class manageApplicationTests { ...@@ -27,8 +37,30 @@ public class manageApplicationTests {
} }
@Test @Test
public void getUserRoleByAccount() { public void getUserRoleByAccount() throws Exception {
sysUserService.getUserRoleByAccount("moduls"); DataApiUpReq dataApiUpReq = new DataApiUpReq();
//System.out.print(sysUserService.getTest().toString()); 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