Commit 2eca6b14 authored by ysongq's avatar ysongq

commit

parent eeae9c4a
......@@ -34,4 +34,13 @@ public enum AuthModeEnum {
public String getText() {
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 {
public String getText() {
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;
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.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableRedisHttpSession
......@@ -18,4 +20,9 @@ public class Application {
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
......@@ -78,6 +78,9 @@ public class DataGoodsApiDto implements Serializable {
@ApiModelProperty(value = "返回类型")
private String returnType;
@ApiModelProperty(value = "apiKey")
private String apiKey;
/**
* 更新时间
*/
......
......@@ -5,7 +5,6 @@ import com.jz.common.constant.Constants;
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.OrderRequest;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import com.jz.dm.mall.moduls.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......
package com.jz.dm.mall.moduls.controller.pay;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@RequestMapping("/pay")
@CrossOrigin
@Api(tags = "支付controller")
public class PayController {
......@@ -25,6 +26,7 @@ public class PayController {
@PostMapping("/payment")
@ApiOperation(value = "支付功能")
public Result payController(@RequestBody PayDto payDto) throws Exception {
// payDto是请求
Result result = new Result();
try{
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.AuthTypeEnum;
......@@ -27,6 +27,9 @@ public class PayDto implements Serializable {
@ApiModelProperty(value = "企业id")
private Long departmentId;
@ApiModelProperty(value = "apiKey")
private String apiKey;
@ApiModelProperty(value = "资产账户id")
private String assetsId;
......
......@@ -8,6 +8,7 @@ import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* @ClassName:
......@@ -43,9 +44,9 @@ public class AuthMallUserApiReq implements Serializable {
private AuthModeEnum authMode;
@ApiModelProperty(value = "开始时间", required = false)
private String validStartTime;
private Date validStartTime;
@ApiModelProperty(value = "结束时间", required = false)
private String validEndTime;
private Date validEndTime;
@ApiModelProperty(value = "备注", required = false)
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;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
......@@ -17,6 +18,7 @@ import java.util.Date;
*/
@TableName("t_finance_trade_flow")
@ApiModel
@Data
public class FinanceTradeFlow implements Serializable {
private static final long serialVersionUID = -55257582310832314L;
/**
......@@ -58,97 +60,15 @@ public class FinanceTradeFlow implements Serializable {
* 创建人
*/
private String crePerson;
private Date uptTime;
private String uptPerson;
/**
* 删除标识
*/
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
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;
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.OrderDto;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import com.jz.dm.mall.moduls.entity.Order;
import org.apache.ibatis.annotations.Param;
......
package com.jz.dm.mall.moduls.service;
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.OrderRequest;
import com.jz.dm.mall.moduls.controller.order.dto.PayDto;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
......
package com.jz.dm.mall.moduls.service;
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:
......
......@@ -6,10 +6,7 @@ import com.jz.common.bean.PageInfoResponse;
import com.jz.common.constant.Constants;
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.dto.PayDto;
import com.jz.dm.mall.moduls.entity.Order;
import com.jz.dm.mall.moduls.mapper.OrderDao;
import com.jz.dm.mall.moduls.service.OrderService;
......
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.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.NumberUtils;
import com.jz.common.utils.RestTemplateUtils;
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.mapper.*;
import com.jz.dm.mall.moduls.service.PayService;
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.transaction.annotation.Propagation;
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;
......@@ -43,6 +58,9 @@ public class PayServiceImpl implements PayService {
@Autowired
private FinanceTradeFlowDao financeTradeFlowDao;
@Autowired
private RestTemplate restTemplate;
/**
* 新增订单
*
......@@ -112,11 +130,28 @@ public class PayServiceImpl implements PayService {
return Result.error("金额不足!请充值!");
}
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.setTotalMoney(subtract);
assets.setCreTime(DateUtils.getToday());
assets.setCrePerson(payDto.getCustomerId()+ "");
financeCustomerAssetsDao.addAssets(assets);
assets.setUptTime(DateUtils.getToday());
assets.setUptPerson(payDto.getCustomerId()+ "");
financeCustomerAssetsDao.updateAssets(assets);
// 新增记录表
Long assetsId = assets.getAssetsId();
......
......@@ -35,6 +35,7 @@
t1.upt_time AS uptTime,
t1.return_data_example AS returnDataExample,
t1.request_example AS requestExample,
t1.api_key as apiKey,
t2.data_picture as dataPicture,
t3.supplier_name AS supplierName,
t4.api_params_id AS apiParamsId,
......
......@@ -169,9 +169,28 @@
where assets_id = #{assetsId}
</select>
<insert id="addAssets" keyProperty="assetsId" useGeneratedKeys="true">
INSERT INTO t_finance_customer_assets ( department_id, use_money, total_money, cre_time, cre_person)
VALUES
(#{departmentId}, #{useMoney}, #{totalMoney}, #{creTime}, #{crePerson})
<insert id="updateAssets" parameterType="com.jz.dm.mall.moduls.entity.FinanceCustomerAssets">
update t_finance_customer_assets
<set>
<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>
</mapper>
\ No newline at end of file
......@@ -24,19 +24,19 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull(message = "api类型不能为空")
public String apiType;
@ApiModelProperty(value = "apiId 等价于apiKey",required = true)
@NotNull(message = "apiId不能为空")
public String apiId;
// @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 = "api版本",required = false)
// public String version;
@ApiModelProperty(value = "传输方式(1为HTTPS,2为HTTP)",required = true)
@NotNull(message = "传输方式不能为空")
public String transMode;
public String apiProtocl;
@ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true)
@NotNull(message = "加密方式不能为空")
......
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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -12,10 +14,8 @@ import com.jz.common.constant.Constants;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.constant.ResultMsg;
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.DataGoodsListDto;
import com.jz.manage.moduls.controller.goods.bean.request.DataApiUpReq;
......@@ -29,6 +29,7 @@ import com.jz.manage.moduls.mapper.DataGoodsApiParamsDao;
import com.jz.manage.moduls.mapper.DataGoodsDao;
import com.jz.manage.moduls.service.DataGoodsService;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -37,6 +38,13 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
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.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
......@@ -283,19 +291,20 @@ public class DataGoodsServiceImpl implements DataGoodsService {
apiReq.setApiDesc(dataApiUpReq.getApiDesc());
apiReq.setApiExample("");
apiReq.setApiFunction(dataApiUpReq.getApiFunction());
apiReq.setApiId(dataApiUpReq.getApiKey());
// 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");
// 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
Long goodsApi = dataGoodsApi.getGoodsApi();
......@@ -307,15 +316,18 @@ public class DataGoodsServiceImpl implements DataGoodsService {
dataApiUpReq.setCrePerson(user.getUserId() + "");
BeanUtils.copyProperties(dataApiUpReq, params);
apiParamsDao.insert(params);
}
}
}
//
try {
String url= "http://192.168.1.114:8088/api/producer/addDataBankApiInfo";
WebUtils.postJSON(url, apiReq);
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));
// JSONObject object = doPOst(url, JSON.toJSONString(apiReq));
// System.out.println(object);
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -325,5 +337,31 @@ public class DataGoodsServiceImpl implements DataGoodsService {
// return Result.of_success(ResultMsg.SUCCESS, ResultCode.SUCCESS);
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