Files
jsowell-charger-web/jsowell-admin/src/main/java/com/jsowell/api/uniapp/TempController.java
2023-08-03 18:59:26 +08:00

241 lines
9.7 KiB
Java

package com.jsowell.api.uniapp;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.adapay.dto.BalancePaymentRequestDTO;
import com.jsowell.adapay.service.AdapayMemberService;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.DateUtils;
import com.jsowell.pile.domain.AdapayMemberAccount;
import com.jsowell.pile.domain.MemberPlateNumberRelation;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.dto.CarVinDTO;
import com.jsowell.pile.dto.QueryOrderDTO;
import com.jsowell.pile.service.IAdapayMemberAccountService;
import com.jsowell.pile.service.IMemberPlateNumberRelationService;
import com.jsowell.pile.service.IOrderBasicInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 用于临时接口
*/
@Anonymous
@RestController
@RequestMapping("/temp")
public class TempController extends BaseController {
@Autowired
private IOrderBasicInfoService orderBasicInfoService;
@Autowired
private IMemberPlateNumberRelationService memberPlateNumberRelationService;
@Autowired
private IAdapayMemberAccountService adapayMemberAccountService;
@Autowired
private AdapayMemberService adapayMemberService;
/**
* 临时刷数据接口
* http://localhost:8080/temp/tempUpdateVirtualAmount
* @param request
* @return
*/
@PostMapping("tempUpdateVirtualAmount")
public RestApiResponse<?> tempUpdateVirtualAmount(HttpServletRequest request, @RequestBody QueryOrderDTO dto) {
logger.info("临时刷数据接口 param:{}", dto);
RestApiResponse<?> response = null;
try {
String s = orderBasicInfoService.tempUpdateVirtualAmount(dto);
response = new RestApiResponse<>(s);
} catch (BusinessException e) {
logger.warn("临时刷数据接口 warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("临时刷数据接口 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_GET_PILE_DETAIL_ERROR);
}
logger.info("临时刷数据接口 result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 临时订单退款
* http://localhost:8080/temp/tempOrderRefund
* @return
*/
@GetMapping("tempOrderRefund")
public RestApiResponse<?> tempOrderRefund() {
RestApiResponse<?> response = null;
try {
// orderBasicInfoService.tempOrderRefund();
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.warn("临时订单退款接口 warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("临时订单退款接口 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("临时刷数据接口 result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 批量退款接口
* http://localhost:8080/temp/batchRefund
* @param dto
* @return
*/
@PostMapping("/batchRefund")
public RestApiResponse<?> batchRefund(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response = null;
try {
orderBasicInfoService.batchRefund(dto);
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.warn("临时订单退款接口 warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("临时订单退款接口 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("临时刷数据接口 result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 临时接口,计算站点订单报表
* http://localhost:8080/temp/tempGenerateDailyOrderReports
* @param dto
* @return
*/
@PostMapping("/tempGenerateDailyOrderReports")
public RestApiResponse<?> tempGenerateDailyOrderReports(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response = null;
try {
String startTime = dto.getStartTime();
String endTime = dto.getEndTime();
// 获取日期区间内所有日期
List<String> dateList = DateUtils.getAllDatesInTheDateRange(startTime, endTime);
dto.getStationIdList().parallelStream().forEach(stationId -> {
for (String tradeDate : dateList) {
orderBasicInfoService.generateDailyOrderReports(stationId, tradeDate);
}
});
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.warn("临时接口计算站点订单报表 warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("临时接口计算站点订单报表 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("临时接口计算站点订单报表 result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 临时接口测试vin查询方法
* @param dto
* @return
*/
@PostMapping("/tempTestVinCode")
public RestApiResponse<?> tempTestVinCode(@RequestBody CarVinDTO dto) {
RestApiResponse<?> response = null;
try {
MemberPlateNumberRelation memberPlateInfoByVinCode = memberPlateNumberRelationService.getMemberPlateInfoByVinCode(dto.getVinCode());
response = new RestApiResponse<>(memberPlateInfoByVinCode);
} catch (Exception e) {
logger.error("临时接口测试vin查询方法 error,", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("临时接口测试vin查询方法 result:{}", response);
return response;
}
/**
* 交易确认接口
* http://localhost:8080/temp/tempPaymentConfirm
*/
@PostMapping("/tempPaymentConfirm")
public RestApiResponse<?> tempPaymentConfirm(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response = null;
try {
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(dto.getOrderCode());
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId("1");
if (orderBasicInfo == null || adapayMemberAccount == null) {
throw new BusinessException("", "查询信息为空");
}
orderBasicInfoService.doPaymentConfirm(orderBasicInfo, adapayMemberAccount);
} catch (Exception e) {
logger.error("临时接口交易确认接口 error,", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("临时接口交易确认接口 result:{}", response);
return response;
}
/**
* 运营商分账手动接口
* http://localhost:8080/temp/orderSplittingOperations
* @return
*/
@PostMapping("/orderSplittingOperations")
public RestApiResponse<?> orderSplittingOperations(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response = null;
try {
String startTime = dto.getStartTime();
String endTime = dto.getEndTime();
// 获取日期区间内所有日期
List<String> dateList = DateUtils.getAllDatesInTheDateRange(startTime, endTime);
for (String tradeDate : dateList) {
// orderBasicInfoService.tempOrderSplittingOperations(dto.getMerchantId(), tradeDate);
orderBasicInfoService.orderSplittingOperations(dto.getMerchantId(), tradeDate);
}
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.warn("运营商分账手动接口warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("运营商分账手动接口error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("运营商分账手动接口result:{}", JSONObject.toJSONString(response));
return response;
}
/**
* 测试余额支付接口
* http://localhost:8080/temp/testCreateBalancePayment
*/
@PostMapping("/testCreateBalancePayment")
public RestApiResponse<?> testCreateBalancePayment(@RequestBody BalancePaymentRequestDTO dto) {
RestApiResponse<?> response = null;
try {
adapayMemberService.createBalancePaymentRequest(dto.getOutMemberId(), dto.getInMemberId(), dto.getTransAmt());
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.warn("测试余额支付接口warn", e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("测试余额支付接口error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_WEIXIN_REFUND_ERROR);
}
logger.info("测试余额支付接口result:{}", JSONObject.toJSONString(response));
return response;
}
}