diff --git a/open-api/src/main/java/com/api/controller/v1/TradeController.java b/open-api/src/main/java/com/api/controller/v1/TradeController.java index cc111d6..deefb8f 100644 --- a/open-api/src/main/java/com/api/controller/v1/TradeController.java +++ b/open-api/src/main/java/com/api/controller/v1/TradeController.java @@ -282,6 +282,42 @@ public class TradeController { } } + @RequestMapping(value="/tradeRefundBills",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "账单退款下载") + public ResponseData tradeRefundBills(@RequestBody RequestTradeRefundBillsModel body) { + log.info("========= Start 账单退款下载 Start ==========="); + log.info("请求参数:" + JSONObject.toJSONString(body)); + try { + // 验证签名 + if (!SignatureUtil.checkSign(body.getSign(), body, merKeyService.getKeyByMerNo(body.getMerchantNo()))) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_SIGN_ERR, ""); + } + if (body.getBillDateS().compareTo(body.getBillDateE()) >= 0) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "开始时间必须小于结束时间"); + } + // 最大周期范围3个月 90天 + Long maxTime = 60*24*90L; + if (maxTime.compareTo(DateUtil.getMinutesDiff(new Date(body.getBillDateS()), new Date(body.getBillDateE()))) < 0) { + throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "时间范围大于3个月"); + } + List tradeBills = openApiTradeOrderService.tradeRefundBills(body.getMerchantNo(), body.getBillDateS(), body.getBillDateE()); + String fileName = "/temporary/" + System.currentTimeMillis() + ".xlsx"; + EasyExcel.write(CommonSysConst.getSysConfig().getFilesystem() + fileName, TradeRefundBillsModel.class) + .sheet(body.getMerchantNo()) + .doWrite(tradeBills); + + String fileUrl = CommonSysConst.getSysConfig().getDomainName() + "/filesystem" + fileName; + log.info("返回参数:" + fileUrl); + return ResponseMsgUtil.success(fileUrl); + + } catch (Exception e) { + log.info("出现异常:", e); + return ResponseMsgUtil.exception(e); + } finally { + log.info("========= END 账单退款下载 END ==========="); + } + } } diff --git a/service/src/main/java/com/hfkj/dao/OpenApiTradeOrderMapper.java b/service/src/main/java/com/hfkj/dao/OpenApiTradeOrderMapper.java index c0e420f..2954e3f 100644 --- a/service/src/main/java/com/hfkj/dao/OpenApiTradeOrderMapper.java +++ b/service/src/main/java/com/hfkj/dao/OpenApiTradeOrderMapper.java @@ -1,6 +1,7 @@ package com.hfkj.dao; import com.hfkj.openapi.v1.model.TradeBillsModel; +import com.hfkj.openapi.v1.model.TradeRefundBillsModel; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; @@ -54,4 +55,33 @@ public interface OpenApiTradeOrderMapper { }) List queryTradeBills(@Param("merNo") String merNo,@Param("billDateS") String billDateS, @Param("billDateE") String billDateE); + + @Select({ + "" + }) + List queryRefundBills(@Param("merNo") String merNo, @Param("billDateS") String billDateS, @Param("billDateE") String billDateE); + } diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/TradeRefundBillsModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/TradeRefundBillsModel.java new file mode 100644 index 0000000..fb70ff3 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/v1/model/TradeRefundBillsModel.java @@ -0,0 +1,63 @@ +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 TradeRefundBillsModel { + + @ColumnWidth(25) + @ExcelProperty("申请退款时间") + private Date createTime; + + @ColumnWidth(35) + @ExcelProperty("商户退款单号") + private String refundNo; + + @ColumnWidth(25) + @ExcelProperty("退款状态") + private String refundStatus; + + @ColumnWidth(25) + @ExcelProperty("退款成功时间") + private Date refundTime; + + @ColumnWidth(25) + @ExcelProperty("退款金额") + private BigDecimal refundAmount; + + @ColumnWidth(35) + @ExcelProperty("商户交易单号") + private String outTradeNo; + + @ColumnWidth(35) + @ExcelProperty("账户端交易单号") + private String accTradeNo; + + @ColumnWidth(30) + @ExcelProperty("商户号") + private String merNo; + + @ColumnWidth(25) + @ExcelProperty("交易金额") + private BigDecimal accSettleAmount; + + @ColumnWidth(30) + @ExcelProperty("退款原因") + private String refundReason; + + @ColumnWidth(25) + @ExcelProperty("操作人") + private String operatorName; + +} diff --git a/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestTradeRefundBillsModel.java b/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestTradeRefundBillsModel.java new file mode 100644 index 0000000..e193b99 --- /dev/null +++ b/service/src/main/java/com/hfkj/openapi/v1/model/request/RequestTradeRefundBillsModel.java @@ -0,0 +1,40 @@ +package com.hfkj.openapi.v1.model.request; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * 请求账单下载模型 + * @className: TradePreorderModel + * @author: HuRui + * @date: 2023/5/23 + **/ +@Data +public class RequestTradeRefundBillsModel { + + /** + * 商户号 + */ + @NotBlank(message = "商户号必填项") + private String merchantNo; + + /** + * 报表开始时间 + */ + @NotBlank(message = "开始时间必填项") + private Long billDateS; + + /** + * 报表结束时间 + */ + @NotBlank(message = "结束时间必填项") + private Long billDateE; + + /** + * 签名参数 + */ + @NotBlank(message = "签名必填项") + private String sign; + +} diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java b/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java index 06cc353..a25a9fb 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java +++ b/service/src/main/java/com/hfkj/openapi/v1/service/OpenApiTradeOrderService.java @@ -2,6 +2,7 @@ package com.hfkj.openapi.v1.service; import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrderRefund; +import com.hfkj.openapi.v1.model.TradeRefundBillsModel; import com.hfkj.openapi.v1.model.request.RequestRefundTradeModel; import com.hfkj.openapi.v1.model.response.ResponseRefundTradeModel; import com.hfkj.openapi.v1.model.TradeBillsModel; @@ -51,4 +52,13 @@ public interface OpenApiTradeOrderService { * @return */ List tradeBills(String merNo, Long billDateS, Long billDateE); + + /** + * 交易退款账单 + * @param merNo + * @param billDateS + * @param billDateE + * @return + */ + List tradeRefundBills(String merNo, Long billDateS, Long billDateE); } diff --git a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java index 8879806..2408049 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/openapi/v1/service/impl/OpenApiTradeOrderServiceImpl.java @@ -9,6 +9,7 @@ import com.hfkj.common.utils.DateUtil; import com.hfkj.entity.BsTradeOrder; import com.hfkj.entity.BsTradeOrderRefund; import com.hfkj.dao.OpenApiTradeOrderMapper; +import com.hfkj.openapi.v1.model.TradeRefundBillsModel; import com.hfkj.openapi.v1.model.request.RequestRefundTradeModel; import com.hfkj.openapi.v1.model.response.ResponseRefundTradeModel; import com.hfkj.openapi.v1.model.TradeBillsModel; @@ -122,6 +123,7 @@ public class OpenApiTradeOrderServiceImpl implements OpenApiTradeOrderService { tradeOrder.setRefundPrice(tradeOrder.getRefundPrice().add(orderRefund.getRefundAmount())); if (tradeOrder.getRefundPrice().compareTo(tradeOrder.getTradeActualAmount()) == 0) { tradeOrder.setRefundType(TradeOrderRefundTypeEnum.type1.getNumber()); + tradeOrder.setStatus(TradeOrderStatusEnum.status6.getNumber()); } else { tradeOrder.setRefundType(TradeOrderRefundTypeEnum.type2.getNumber()); } @@ -142,4 +144,12 @@ public class OpenApiTradeOrderServiceImpl implements OpenApiTradeOrderService { ); } + @Override + public List tradeRefundBills(String merNo, Long billDateS, Long billDateE) { + return openApiTradeOrderMapper.queryRefundBills(merNo, + DateUtil.date2String(new Date(billDateS), DateUtil.Y_M_D_HMS), + DateUtil.date2String(new Date(billDateE), DateUtil.Y_M_D_HMS) + ); + } + } diff --git a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java index 50fa4e1..7790dce 100644 --- a/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java +++ b/service/src/main/java/com/hfkj/openapi/v1/utils/SignatureUtil.java @@ -82,15 +82,11 @@ public class SignatureUtil { public static void main(String[] args) throws Exception { String paramStr = "{\n" + - " \"merchantNo\": \"2023041916292112804\",\n" + - " \"outTradeNo\": \"ZF1130202305051459532538970009\",\n" + - " \"payMode\": \"UQRCODEPAY\",\n" + - " \"totalAmount\": 0.01,\n" + - " \"transType\": \"NATIVE\",\n" + - " \"profitSharing\": 0,\n" + - " \"specialField\": \"测试\"" + + " \"merchantNo\": \"2023051910562136809\",\n" + + " \"billDateS\": 1684568344000,\n" + + " \"billDateE\": 1690527064867" + "}"; - String sign = createSign(JSONObject.parseObject(paramStr), "2jLO2WjXcSRSzTCaca0Kmv0OFrfYBbrA"); + String sign = createSign(JSONObject.parseObject(paramStr), "NGixVhkzVYFFMj8tjj4zOkYQtUiU3bd4"); System.out.println(sign); } }