parent
0e9752e055
commit
aa756ddf1c
@ -0,0 +1,112 @@ |
||||
package com.api.controller.v1; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.ccb.wlpt.util.StringUtil; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsMer; |
||||
import com.hfkj.entity.BsTradeOrder; |
||||
import com.hfkj.entity.BsTradeOrderMsg; |
||||
import com.hfkj.entity.BsTradeOrderRefund; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.openapi.v1.model.*; |
||||
import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; |
||||
import com.hfkj.openapi.v1.utils.SignatureUtil; |
||||
import com.hfkj.service.BsMerKeyService; |
||||
import com.hfkj.service.BsMerService; |
||||
import com.hfkj.service.BsTradeOrderService; |
||||
import com.hfkj.sysenum.*; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.apache.http.protocol.HTTP; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedOutputStream; |
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@Api(value = "交易订单") |
||||
@RequestMapping(value = "/v1/payNotify") |
||||
public class NotifyController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(NotifyController.class); |
||||
|
||||
@Resource |
||||
private BsTradeOrderService tradeOrderService; |
||||
|
||||
@Resource |
||||
private OpenApiTradeOrderService openApiTradeOrderService; |
||||
|
||||
@Resource |
||||
private BsMerKeyService merKeyService; |
||||
|
||||
@RequestMapping(value="/lakala",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "拉卡拉交易通知") |
||||
public void lakala(@RequestBody String reqBody, HttpServletResponse response) { |
||||
try { |
||||
log.info("拉卡拉交易通知:", reqBody); |
||||
System.out.println(reqBody); |
||||
|
||||
JSONObject body = JSONObject.parseObject(reqBody); |
||||
// 查询订单
|
||||
BsTradeOrder order = tradeOrderService.getOrderByOutTradeNo(body.getString("out_trade_no")); |
||||
if (order != null && order.getStatus().equals(TradeOrderStatusEnum.status1.getNumber())) { |
||||
Map<String,Object> other = new HashMap<>(); |
||||
other.put("log_no", body.getString("log_no")); |
||||
other.put("acc_trade_no", body.getString("acc_trade_no")); |
||||
other.put("card_type", body.getString("card_type")); |
||||
|
||||
tradeOrderService.paySuccess( |
||||
body.getString("out_trade_no"), |
||||
body.getString("trade_no"), |
||||
PlatformTypeEnum.type1, |
||||
TradeOrderPayModeEnum.getNameByCode(body.getString("account_type")), |
||||
body.getBigDecimal("payer_amount").divide(new BigDecimal("100")), |
||||
body.getString("merchant_no"), |
||||
other |
||||
); |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(order.getPayNotifyUrl())) { |
||||
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(order.getOutTradeNo()); |
||||
ResponseQueryTradeModel responseQueryTradeModel = new ResponseQueryTradeModel(); |
||||
responseQueryTradeModel.setMerchantNo(tradeOrder.getMerNo()); |
||||
responseQueryTradeModel.setOutTradeNo(tradeOrder.getOutTradeNo()); |
||||
responseQueryTradeModel.setAccTradeNo(tradeOrder.getAccTradeNo()); |
||||
responseQueryTradeModel.setUserId(tradeOrder.getPayUserId()); |
||||
responseQueryTradeModel.setPayMode(tradeOrder.getPayMode()); |
||||
responseQueryTradeModel.setTradeAmount(tradeOrder.getTradeAmount()); |
||||
responseQueryTradeModel.setTradeActualAmount(tradeOrder.getTradeActualAmount()); |
||||
responseQueryTradeModel.setStatus(tradeOrder.getStatus()); |
||||
responseQueryTradeModel.setCreateTime(tradeOrder.getCreateTime()); |
||||
responseQueryTradeModel.setPayTime(tradeOrder.getPayTime()); |
||||
responseQueryTradeModel.setSign(SignatureUtil.createSign(responseQueryTradeModel, merKeyService.getKeyByMerNo(tradeOrder.getMerNo()))); |
||||
JSONObject result = HttpsUtils.doPost(order.getPayNotifyUrl(), JSONObject.toJSONString(responseQueryTradeModel)); |
||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
||||
out.write(result.toJSONString().getBytes()); |
||||
out.flush(); |
||||
out.close(); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("login error!",e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,56 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.openapi.v1.model.TradeBillsModel; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @className: OpenApiTradeOrderMapper |
||||
* @author: HuRui |
||||
* @date: 2023/5/25 |
||||
**/ |
||||
@Repository |
||||
public interface OpenApiTradeOrderMapper { |
||||
|
||||
@Select({ |
||||
"<script>" + |
||||
" SELECT " + |
||||
" a.pay_time payTime," + |
||||
" a.mer_no merchantNo," + |
||||
" a.platform_trade_no platformTradeNo," + |
||||
" a.out_trade_no outTradeNo, " + |
||||
" a.pay_user_id payUserId, " + |
||||
" \"JSAPI\" as tradeType," + |
||||
" case a.pay_mode" + |
||||
" when \"WECHAT\" then '微信'" + |
||||
" when \"ALIPAY\" then '支付宝'" + |
||||
" when \"UQRCODEPAY\" then '云闪付'" + |
||||
" end payMode," + |
||||
" \"交易成功\" as tradeStatus," + |
||||
" a.trade_amount tradeAmount," + |
||||
" a.trade_actual_amount tradeActualAmount," + |
||||
" case a.refund_type" + |
||||
" when 1 then '全额退款' " + |
||||
" when 2 then '部分退款'" + |
||||
" end refundType," + |
||||
" a.refund_price refundPrice," + |
||||
" subject subject," + |
||||
" case a.create_type" + |
||||
" when 1 then '扫一扫'" + |
||||
" when 2 then '被扫'" + |
||||
" when 3 then 'API'" + |
||||
" end createType" + |
||||
" FROM `bs_trade_order` a" + |
||||
" where a.mer_no = #{merNo} " + |
||||
" <![CDATA[ and pay_time >= #{billDateS} ]]>" + |
||||
" <![CDATA[ and pay_time <= #{billDateE} ]]>" + |
||||
" and a.`status` in (3,6)" + |
||||
" GROUP BY a.id" + |
||||
" </script>" |
||||
}) |
||||
List<TradeBillsModel> queryTradeBills(@Param("merNo") String merNo,@Param("billDateS") String billDateS, @Param("billDateE") String billDateE); |
||||
|
||||
} |
@ -0,0 +1,41 @@ |
||||
package com.hfkj.openapi.v1.model; |
||||
|
||||
import lombok.Data; |
||||
import org.hibernate.validator.constraints.Length; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
|
||||
/** |
||||
* 请求账单下载模型 |
||||
* @className: TradePreorderModel |
||||
* @author: HuRui |
||||
* @date: 2023/5/23 |
||||
**/ |
||||
@Data |
||||
public class RequestTradeBillsModel { |
||||
|
||||
/** |
||||
* 商户号 |
||||
*/ |
||||
@NotBlank(message = "商户号必填项") |
||||
private String merchantNo; |
||||
|
||||
/** |
||||
* 报表开始时间 |
||||
*/ |
||||
@NotBlank(message = "开始时间必填项") |
||||
private Long billDateS; |
||||
|
||||
/** |
||||
* 报表结束时间 |
||||
*/ |
||||
@NotBlank(message = "结束时间必填项") |
||||
private Long billDateE; |
||||
|
||||
/** |
||||
* 签名参数 |
||||
*/ |
||||
@NotBlank(message = "签名必填项") |
||||
private String sign; |
||||
|
||||
} |
@ -0,0 +1,70 @@ |
||||
package com.hfkj.openapi.v1.model; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||
import lombok.Data; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 交易账单模型 |
||||
* @className: TradeBillsModel |
||||
* @author: HuRui |
||||
* @date: 2023/5/25 |
||||
**/ |
||||
@Data |
||||
public class TradeBillsModel { |
||||
@ColumnWidth(25) |
||||
@ExcelProperty("交易时间") |
||||
private Date payTime; |
||||
@ColumnWidth(25) |
||||
@ExcelProperty("商户号") |
||||
private String merchantNo; |
||||
@ColumnWidth(25) |
||||
@ExcelProperty("平台交易单号") |
||||
private String platformTradeNo; |
||||
@ColumnWidth(25) |
||||
@ExcelProperty("商户交易单号") |
||||
private String outTradeNo; |
||||
@ColumnWidth(25) |
||||
@ExcelProperty("用户标识") |
||||
private String payUserId; |
||||
|
||||
@ColumnWidth(20) |
||||
@ExcelProperty("交易类型") |
||||
private String tradeType; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("交易方式") |
||||
private String payMode; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("交易方式") |
||||
private String tradeStatus; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("交易金额") |
||||
private BigDecimal tradeAmount; |
||||
|
||||
@ColumnWidth(20) |
||||
@ExcelProperty("交易实付金额") |
||||
private BigDecimal tradeActualAmount; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("退款类型") |
||||
private String refundType; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("退款金额") |
||||
private BigDecimal refundPrice; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("交易标题") |
||||
private String subject; |
||||
|
||||
@ColumnWidth(15) |
||||
@ExcelProperty("创建方式") |
||||
private String createType; |
||||
|
||||
} |
Loading…
Reference in new issue