Commit 2eca6b14 authored by ysongq's avatar ysongq

commit

parent eeae9c4a
...@@ -34,4 +34,13 @@ public enum AuthModeEnum { ...@@ -34,4 +34,13 @@ public enum AuthModeEnum {
public String getText() { public String getText() {
return text; return text;
} }
public static AuthModeEnum fromTypeName(String typeName) {
for (AuthModeEnum type : AuthModeEnum.values()) {
if (type.name().equals(typeName)) {
return type;
}
}
return null;
}
} }
...@@ -29,4 +29,6 @@ public enum AuthTypeEnum { ...@@ -29,4 +29,6 @@ public enum AuthTypeEnum {
public String getText() { public String getText() {
return text; return text;
} }
} }
package com.jz.common.utils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* @ClassName:
* @Author: Carl
* @Date: 2020/12/31
* @Version:
*/
public class RestTemplateUtils {
private static class SingletonRestTemplate {
static final RestTemplate INSTANCE = new RestTemplate();
}
private RestTemplateUtils() {
}
public static RestTemplate getInstance() {
return SingletonRestTemplate.INSTANCE;
}
/**
* post 请求
* @param url 请求路径
* @param data body数据
* @param token JWT所需的Token,不需要的可去掉
* @return
*/
public static String post(String url, String data) {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Encoding", "UTF-8");
headers.add("Content-Type", "application/json; charset=UTF-8");
HttpEntity<String> requestEntity = new HttpEntity<>(data, headers);
return RestTemplateUtils.getInstance().postForObject(url, requestEntity, String.class);
}
/**
* get 请求
* @param url 请求路径
* @param token JWT所需的Token,不需要的可去掉
* @return
*/
public static String get(String url, String token) {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Encoding", "UTF-8");
headers.add("Content-Type", "application/json; charset=UTF-8");
if (token != null) {
headers.add("Authorization", token);
}
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
ResponseEntity<String> response = RestTemplateUtils.getInstance().exchange(url, HttpMethod.GET, requestEntity, String.class);
String responseBody = response.getBody();
return responseBody;
}
}
\ No newline at end of file
...@@ -3,8 +3,10 @@ package com.jz.dm.mall; ...@@ -3,8 +3,10 @@ package com.jz.dm.mall;
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.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
@EnableRedisHttpSession @EnableRedisHttpSession
...@@ -18,4 +20,9 @@ public class Application { ...@@ -18,4 +20,9 @@ public class Application {
} }
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
} }
...@@ -78,6 +78,9 @@ public class DataGoodsApiDto implements Serializable { ...@@ -78,6 +78,9 @@ public class DataGoodsApiDto implements Serializable {
@ApiModelProperty(value = "返回类型") @ApiModelProperty(value = "返回类型")
private String returnType; private String returnType;
@ApiModelProperty(value = "apiKey")
private String apiKey;
/** /**
* 更新时间 * 更新时间
*/ */
......
...@@ -5,7 +5,6 @@ import com.jz.common.constant.Constants; ...@@ -5,7 +5,6 @@ import com.jz.common.constant.Constants;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.bean.OrderDto; import com.jz.dm.mall.moduls.controller.order.bean.OrderDto;
import com.jz.dm.mall.moduls.controller.order.bean.OrderRequest; import com.jz.dm.mall.moduls.controller.order.bean.OrderRequest;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import com.jz.dm.mall.moduls.service.OrderService; import com.jz.dm.mall.moduls.service.OrderService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
......
package com.jz.dm.mall.moduls.controller.pay; package com.jz.dm.mall.moduls.controller.pay;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto; import com.jz.dm.mall.moduls.controller.pay.dto.PayDto;
import com.jz.dm.mall.moduls.service.PayService; import com.jz.dm.mall.moduls.service.PayService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
*/ */
@RestController @RestController
@RequestMapping("/pay") @RequestMapping("/pay")
@CrossOrigin
@Api(tags = "支付controller") @Api(tags = "支付controller")
public class PayController { public class PayController {
...@@ -25,6 +26,7 @@ public class PayController { ...@@ -25,6 +26,7 @@ public class PayController {
@PostMapping("/payment") @PostMapping("/payment")
@ApiOperation(value = "支付功能") @ApiOperation(value = "支付功能")
public Result payController(@RequestBody PayDto payDto) throws Exception { public Result payController(@RequestBody PayDto payDto) throws Exception {
// payDto是请求
Result result = new Result(); Result result = new Result();
try{ try{
result = payService.goodsPay(payDto); result = payService.goodsPay(payDto);
......
package com.jz.dm.mall.moduls.controller.order.dto; package com.jz.dm.mall.moduls.controller.pay.dto;
import com.jz.common.enums.auth.AuthModeEnum; import com.jz.common.enums.auth.AuthModeEnum;
import com.jz.common.enums.auth.AuthTypeEnum; import com.jz.common.enums.auth.AuthTypeEnum;
...@@ -27,6 +27,9 @@ public class PayDto implements Serializable { ...@@ -27,6 +27,9 @@ public class PayDto implements Serializable {
@ApiModelProperty(value = "企业id") @ApiModelProperty(value = "企业id")
private Long departmentId; private Long departmentId;
@ApiModelProperty(value = "apiKey")
private String apiKey;
@ApiModelProperty(value = "资产账户id") @ApiModelProperty(value = "资产账户id")
private String assetsId; private String assetsId;
......
...@@ -8,6 +8,7 @@ import lombok.Data; ...@@ -8,6 +8,7 @@ import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* @ClassName: * @ClassName:
...@@ -43,9 +44,9 @@ public class AuthMallUserApiReq implements Serializable { ...@@ -43,9 +44,9 @@ public class AuthMallUserApiReq implements Serializable {
private AuthModeEnum authMode; private AuthModeEnum authMode;
@ApiModelProperty(value = "开始时间", required = false) @ApiModelProperty(value = "开始时间", required = false)
private String validStartTime; private Date validStartTime;
@ApiModelProperty(value = "结束时间", required = false) @ApiModelProperty(value = "结束时间", required = false)
private String validEndTime; private Date validEndTime;
@ApiModelProperty(value = "备注", required = false) @ApiModelProperty(value = "备注", required = false)
private String remark; private String remark;
......
package com.jz.dm.mall.moduls.controller.pay.req;
import lombok.Data;
/**
* @ClassName:
* @Author: Carl
* @Date: 2021/1/3
* @Version:
*/
@Data
public class StatusReq {
private Boolean success;
private String message;
private String code;
private String[] data;
}
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -17,6 +18,7 @@ import java.util.Date; ...@@ -17,6 +18,7 @@ import java.util.Date;
*/ */
@TableName("t_finance_trade_flow") @TableName("t_finance_trade_flow")
@ApiModel @ApiModel
@Data
public class FinanceTradeFlow implements Serializable { public class FinanceTradeFlow implements Serializable {
private static final long serialVersionUID = -55257582310832314L; private static final long serialVersionUID = -55257582310832314L;
/** /**
...@@ -58,97 +60,15 @@ public class FinanceTradeFlow implements Serializable { ...@@ -58,97 +60,15 @@ public class FinanceTradeFlow implements Serializable {
* 创建人 * 创建人
*/ */
private String crePerson; private String crePerson;
private Date uptTime;
private String uptPerson;
/** /**
* 删除标识 * 删除标识
*/ */
private String delFlag; private String delFlag;
public Long getAssetsId() {
return AssetsId;
}
public void setAssetsId(Long assetsId) {
AssetsId = assetsId;
}
public Long getTradeFlowId() {
return tradeFlowId;
}
public void setTradeFlowId(Long tradeFlowId) {
this.tradeFlowId = tradeFlowId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Long getCashOutId() {
return cashOutId;
}
public void setCashOutId(Long cashOutId) {
this.cashOutId = cashOutId;
}
public Long getCustomerBalanceId() {
return customerBalanceId;
}
public void setCustomerBalanceId(Long customerBalanceId) {
this.customerBalanceId = customerBalanceId;
}
public String getTradeFlowNumber() {
return tradeFlowNumber;
}
public void setTradeFlowNumber(String tradeFlowNumber) {
this.tradeFlowNumber = tradeFlowNumber;
}
public BigDecimal getTradeMoney() {
return tradeMoney;
}
public void setTradeMoney(BigDecimal tradeMoney) {
this.tradeMoney = tradeMoney;
}
public String getTradeType() {
return tradeType;
}
public void setTradeType(String tradeType) {
this.tradeType = tradeType;
}
public Date getCreTime() {
return creTime;
}
public void setCreTime(Date creTime) {
this.creTime = creTime;
}
public String getCrePerson() {
return crePerson;
}
public void setCrePerson(String crePerson) {
this.crePerson = crePerson;
}
public String getDelFlag() {
return delFlag;
}
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
} }
\ No newline at end of file
...@@ -26,5 +26,7 @@ public interface FinanceCustomerAssetsDao extends BaseMapper<FinanceCustomerAsse ...@@ -26,5 +26,7 @@ public interface FinanceCustomerAssetsDao extends BaseMapper<FinanceCustomerAsse
FinanceCustomerAssets findById(@Param("assetsId")Long assetsId); FinanceCustomerAssets findById(@Param("assetsId")Long assetsId);
void addAssets(FinanceCustomerAssets assets);
void updateAssets(FinanceCustomerAssets assets);
} }
\ No newline at end of file
...@@ -4,7 +4,6 @@ import com.jz.common.base.BaseMapper; ...@@ -4,7 +4,6 @@ import com.jz.common.base.BaseMapper;
import com.jz.dm.mall.moduls.controller.order.bean.DataGoodsApiDto; import com.jz.dm.mall.moduls.controller.order.bean.DataGoodsApiDto;
import com.jz.dm.mall.moduls.controller.order.bean.DataGoodsApiParamsDto; import com.jz.dm.mall.moduls.controller.order.bean.DataGoodsApiParamsDto;
import com.jz.dm.mall.moduls.controller.order.bean.OrderDto; import com.jz.dm.mall.moduls.controller.order.bean.OrderDto;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import com.jz.dm.mall.moduls.entity.Order; import com.jz.dm.mall.moduls.entity.Order;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
......
package com.jz.dm.mall.moduls.service; package com.jz.dm.mall.moduls.service;
import com.jz.common.bean.PageInfoResponse; import com.jz.common.bean.PageInfoResponse;
import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.bean.OrderDto; import com.jz.dm.mall.moduls.controller.order.bean.OrderDto;
import com.jz.dm.mall.moduls.controller.order.bean.OrderRequest; import com.jz.dm.mall.moduls.controller.order.bean.OrderRequest;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Map; import java.util.Map;
......
package com.jz.dm.mall.moduls.service; package com.jz.dm.mall.moduls.service;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto; import com.jz.dm.mall.moduls.controller.pay.dto.PayDto;
/** /**
* @ClassName: * @ClassName:
......
...@@ -6,10 +6,7 @@ import com.jz.common.bean.PageInfoResponse; ...@@ -6,10 +6,7 @@ import com.jz.common.bean.PageInfoResponse;
import com.jz.common.constant.Constants; import com.jz.common.constant.Constants;
import com.jz.common.utils.DateUtils; import com.jz.common.utils.DateUtils;
import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.bean.*; import com.jz.dm.mall.moduls.controller.order.bean.*;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import com.jz.dm.mall.moduls.entity.Order;
import com.jz.dm.mall.moduls.mapper.OrderDao; import com.jz.dm.mall.moduls.mapper.OrderDao;
import com.jz.dm.mall.moduls.service.OrderService; import com.jz.dm.mall.moduls.service.OrderService;
......
package com.jz.dm.mall.moduls.service.impl; package com.jz.dm.mall.moduls.service.impl;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.jz.common.constant.ResultCode; import com.jz.common.constant.ResultCode;
import com.jz.common.constant.ResultMsg; import com.jz.common.constant.ResultMsg;
import com.jz.common.enums.auth.AuthModeEnum;
import com.jz.common.enums.auth.AuthTypeEnum;
import com.jz.common.utils.DateUtils; import com.jz.common.utils.DateUtils;
import com.jz.common.utils.NumberUtils; import com.jz.common.utils.NumberUtils;
import com.jz.common.utils.RestTemplateUtils;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto; import com.jz.dm.mall.moduls.controller.pay.dto.PayDto;
import com.jz.dm.mall.moduls.controller.pay.req.AuthMallUserApiReq;
import com.jz.dm.mall.moduls.controller.pay.req.StatusReq;
import com.jz.dm.mall.moduls.entity.*; import com.jz.dm.mall.moduls.entity.*;
import com.jz.dm.mall.moduls.mapper.*; import com.jz.dm.mall.moduls.mapper.*;
import com.jz.dm.mall.moduls.service.PayService; import com.jz.dm.mall.moduls.service.PayService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -43,6 +58,9 @@ public class PayServiceImpl implements PayService { ...@@ -43,6 +58,9 @@ public class PayServiceImpl implements PayService {
@Autowired @Autowired
private FinanceTradeFlowDao financeTradeFlowDao; private FinanceTradeFlowDao financeTradeFlowDao;
@Autowired
private RestTemplate restTemplate;
/** /**
* 新增订单 * 新增订单
* *
...@@ -112,11 +130,28 @@ public class PayServiceImpl implements PayService { ...@@ -112,11 +130,28 @@ public class PayServiceImpl implements PayService {
return Result.error("金额不足!请充值!"); return Result.error("金额不足!请充值!");
} }
BigDecimal subtract = bigDecimal.subtract(bigDecima2); BigDecimal subtract = bigDecimal.subtract(bigDecima2);
String uri = "http://127.0.0.1:8088/api/auth/mall-user-auth-api";
AuthMallUserApiReq apiReq = new AuthMallUserApiReq();
apiReq.setApiKey(payDto.getApiKey());
apiReq.setAuthMode(AuthModeEnum.RECORD_TIME_MODE);
apiReq.setAuthType(AuthTypeEnum.DATA_BANK_AUTH);
apiReq.setOrgCode("WAISJYX40E3e"); // TODO
apiReq.setOrgType("OUT");
apiReq.setUserId(payDto.getCustomerId() + "");
apiReq.setValidStartTime(order.getTakeEffectTime());
apiReq.setValidEndTime(order.getInvalidTime());
String post = RestTemplateUtils.post(uri, JSON.toJSONString(apiReq));
JSONObject params = JSONObject.parseObject(post);
if (params.get("success").equals("false") || StringUtils.isEmpty(params.get("data"))){
return Result.of_error("授权失败!");
}
assets.setUseMoney(subtract); assets.setUseMoney(subtract);
assets.setTotalMoney(subtract); assets.setTotalMoney(subtract);
assets.setCreTime(DateUtils.getToday()); assets.setUptTime(DateUtils.getToday());
assets.setCrePerson(payDto.getCustomerId()+ ""); assets.setUptPerson(payDto.getCustomerId()+ "");
financeCustomerAssetsDao.addAssets(assets); financeCustomerAssetsDao.updateAssets(assets);
// 新增记录表 // 新增记录表
Long assetsId = assets.getAssetsId(); Long assetsId = assets.getAssetsId();
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
t1.upt_time AS uptTime, t1.upt_time AS uptTime,
t1.return_data_example AS returnDataExample, t1.return_data_example AS returnDataExample,
t1.request_example AS requestExample, t1.request_example AS requestExample,
t1.api_key as apiKey,
t2.data_picture as dataPicture, t2.data_picture as dataPicture,
t3.supplier_name AS supplierName, t3.supplier_name AS supplierName,
t4.api_params_id AS apiParamsId, t4.api_params_id AS apiParamsId,
......
...@@ -169,9 +169,28 @@ ...@@ -169,9 +169,28 @@
where assets_id = #{assetsId} where assets_id = #{assetsId}
</select> </select>
<insert id="addAssets" keyProperty="assetsId" useGeneratedKeys="true"> <insert id="updateAssets" parameterType="com.jz.dm.mall.moduls.entity.FinanceCustomerAssets">
INSERT INTO t_finance_customer_assets ( department_id, use_money, total_money, cre_time, cre_person) update t_finance_customer_assets
VALUES <set>
(#{departmentId}, #{useMoney}, #{totalMoney}, #{creTime}, #{crePerson}) <if test="departmentId != null">
department_id = #{departmentId},
</if>
<if test="useMoney != null">
use_money = #{useMoney},
</if>
<if test="totalMoney != null">
total_money = #{totalMoney},
</if>
<if test="uptTime != null">
upt_time = #{uptTime},
</if>
<if test="uptPerson != null and uptPerson != ''">
upt_person = #{uptPerson},
</if>
<if test="delFlag != null and delFlag != ''">
del_flag = #{delFlag},
</if>
</set>
where assets_id = #{assetsId}
</insert> </insert>
</mapper> </mapper>
\ No newline at end of file
...@@ -24,19 +24,19 @@ public class MakeDataBankApiReq implements Serializable { ...@@ -24,19 +24,19 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull(message = "api类型不能为空") @NotNull(message = "api类型不能为空")
public String apiType; public String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true) // @ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空") // @NotNull(message = "apiId不能为空")
public String apiId; // public String apiId;
@ApiModelProperty(value = "接口描述",required = false) @ApiModelProperty(value = "接口描述",required = false)
public String apiDesc; public String apiDesc;
@ApiModelProperty(value = "api版本",required = false) // @ApiModelProperty(value = "api版本",required = false)
public String version; // public String version;
@ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true) @ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true)
@NotNull(message = "传输方式不能为空") @NotNull(message = "传输方式不能为空")
public String transMode; public String apiProtocl;
@ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true) @ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true)
@NotNull(message = "加密方式不能为空") @NotNull(message = "加密方式不能为空")
......
package com.jz.manage.moduls.service.impl; package com.jz.manage.moduls.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -12,10 +14,8 @@ import com.jz.common.constant.Constants; ...@@ -12,10 +14,8 @@ import com.jz.common.constant.Constants;
import com.jz.common.constant.RedisMessageConstant; import com.jz.common.constant.RedisMessageConstant;
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.*;
import com.jz.common.utils.Result;
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;
import com.jz.manage.moduls.controller.goods.bean.dto.DataGoodsListDto; 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;
...@@ -29,6 +29,7 @@ import com.jz.manage.moduls.mapper.DataGoodsApiParamsDao; ...@@ -29,6 +29,7 @@ import com.jz.manage.moduls.mapper.DataGoodsApiParamsDao;
import com.jz.manage.moduls.mapper.DataGoodsDao; import com.jz.manage.moduls.mapper.DataGoodsDao;
import com.jz.manage.moduls.service.DataGoodsService; import com.jz.manage.moduls.service.DataGoodsService;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -37,6 +38,13 @@ import java.util.Map; ...@@ -37,6 +38,13 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -283,19 +291,20 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -283,19 +291,20 @@ public class DataGoodsServiceImpl implements DataGoodsService {
apiReq.setApiDesc(dataApiUpReq.getApiDesc()); apiReq.setApiDesc(dataApiUpReq.getApiDesc());
apiReq.setApiExample(""); apiReq.setApiExample("");
apiReq.setApiFunction(dataApiUpReq.getApiFunction()); apiReq.setApiFunction(dataApiUpReq.getApiFunction());
apiReq.setApiId(dataApiUpReq.getApiKey()); // apiReq.setApiId(dataApiUpReq.getApiKey());
apiReq.setApiType(dataApiUpReq.getApiType()); apiReq.setApiType(dataApiUpReq.getApiType());
apiReq.setVersion(dataApiUpReq.getVersionNumber());
apiReq.setTransMode(dataApiUpReq.getTransMode());
apiReq.setType(dataApiUpReq.getEncryMode()); apiReq.setType(dataApiUpReq.getEncryMode());
apiReq.setTargetUrl(dataApiUpReq.getTargetUrl()); apiReq.setTargetUrl(dataApiUpReq.getTargetUrl());
apiReq.setTimeout(dataApiUpReq.getOverTime() + ""); apiReq.setTimeout(dataApiUpReq.getOverTime() + "");
apiReq.setReqHeaders("sdadasd"); apiReq.setReqHeaders("sdadasd");
apiReq.setRequestParam("sdadasdd");
apiReq.setResponseParam("fklfhklfhlh");
apiReq.setRespCode("sdkadlahlf");
// apiReq.setFileId(1L);
// apiReq.setFileId(1L);
String url= "http://127.0.0.1:8088/api/producer/addDataBankApiInfo";
System.out.println(JSON.toJSONString(apiReq));
// String post = RestTemplateUtils.post(url, JSON.toJSONString(apiReq) );
// String post = WebUtils.post(url, JSON.toJSONString(apiReq));
String s = doPostJson(url, JSON.toJSONString(apiReq));
System.out.println("dopost:" + s);
// 赋值params // 赋值params
Long goodsApi = dataGoodsApi.getGoodsApi(); Long goodsApi = dataGoodsApi.getGoodsApi();
...@@ -307,15 +316,18 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -307,15 +316,18 @@ 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);
} }
} }
} }
//
try { try {
String url= "http://192.168.1.114:8088/api/producer/addDataBankApiInfo"; String url= "http://127.0.0.1:8088/api/producer/addDataBankApiInfo";
WebUtils.postJSON(url, apiReq); System.out.println(JSON.toJSONString(apiReq));
// String post = RestTemplateUtils.post(url, JSON.toJSONString(apiReq) );
// String post = WebUtils.post(url, JSON.toJSONString(apiReq));
// JSONObject object = doPOst(url, JSON.toJSONString(apiReq));
// System.out.println(object);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
...@@ -325,5 +337,31 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -325,5 +337,31 @@ public class DataGoodsServiceImpl implements DataGoodsService {
// return Result.of_success(ResultMsg.SUCCESS, ResultCode.SUCCESS); // return Result.of_success(ResultMsg.SUCCESS, ResultCode.SUCCESS);
return Result.of_success(ResultMsg.SUCCESS, dataApiUpReq); return Result.of_success(ResultMsg.SUCCESS, dataApiUpReq);
} }
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
} }
\ No newline at end of file
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