kongdeqiang
昨天 973f7a2b420dddb06553489d72d4aa6fdea3c1c0
src/main/java/com/boying/controller/phone/YCPayController.java
@@ -13,8 +13,7 @@
import com.boying.service.*;
import com.boying.util.DateUtilOther;
import com.google.gson.Gson;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
@@ -36,6 +35,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
@@ -48,7 +48,6 @@
@RestController
@RequestMapping("/ffzf/api")
@RequiredArgsConstructor
@Tag(description = "ffzf/api" , name = "邮储/邢台银行 对接支付接口" )
public class YCPayController {
    private final OutParkService outParkService;
    private final PayLogService payLogService;
@@ -71,7 +70,6 @@
     * @return
     */
    @GetMapping("/getByQueryId")
    @Operation(summary = "根据出场id获取出场数据" , description = "根据出场id获取出场数据" )
    public Object getByQueryId(Long queryId){
        if(queryId == null){
            return R.failed("参数为空");
@@ -87,7 +85,6 @@
     * 缴款书
     */
    @PostMapping("park")
    @Operation(summary = "邮储申请缴款书" , description = "邮储申请缴款书" )
    public Object park(Long id){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
        OutPark outPark =  outParkService.getById(id);
@@ -157,7 +154,6 @@
     * @return
     */
    @PostMapping("parkJudg")
    @Operation(summary = "判断支付端是否已经申请过支付" , description = "判断支付端是否已经申请过支付" )
    public Object parkJudg(Long id){
        if(id == null){
            return R.failed("未找到数据,请稍后重新点击");
@@ -188,7 +184,6 @@
     * 判断是否缴费
     */
    @PostMapping("parkXT")
    @Operation(summary = "邢台银行申请缴费" , description = "邢台银行申请缴费" )
    public Object parkXT(Long id){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
        OutPark outPark =  outParkService.getById(id);
@@ -263,7 +258,6 @@
     * 阿里缴费
     */
    @PostMapping("payByAli")
    @Operation(summary = "邢台银行支付宝缴费" , description = "邢台银行支付宝缴费" )
    public Object payByAli(Long id){
        OutPark outPark =  outParkService.getById(id);
        String xtyhpay = systemConfigProperties.getXTYHPAY();
@@ -339,7 +333,6 @@
     * 获取微信openid
     */
    @PostMapping("getOpenId")
    @Operation(summary = "邢台银行获取微信用户openid" , description = "邢台银行获取微信用户openid" )
    public Object park(Long id,String code){
        OutPark outPark =  outParkService.getById(id);
        String openIdByCode = wxService.getOpenIdByCode(code);
@@ -351,7 +344,6 @@
     * 微信缴费
     */
    @PostMapping("payByWX")
    @Operation(summary = "邢台银行微信支付" , description = "邢台银行微信支付" )
    public Object payByWX(Long id,String openId){
        System.out.println("开始支付");
        OutPark outPark =  outParkService.getById(id);
@@ -444,7 +436,6 @@
     * @return
     */
    @GetMapping("/result")
    @Operation(summary = "邮储获得支付回调" , description = "邮储获得支付回调" )
    public Object result(Long queryId,int success,int msg){
        OutPark byId = outParkService.getById(queryId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
@@ -479,7 +470,6 @@
     * @return
     */
    @PostMapping("/getResult")
    @Operation(summary = "邢台银行支付回调接口" , description = "邢台银行支付回调接口" )
    public Object getResult(HttpServletRequest request){
        System.out.println("getResult收到访问");
        String respCode = request.getParameter("respCode");
@@ -534,7 +524,6 @@
     * @return
     */
    @PostMapping ("/checkbill")
    @Operation(summary = "邮储对账接口" , description = "邮储对账接口" )
    public Object checkbill(@RequestBody Map params){
        String checkDate = (String) params.get("checkDate");
        String tranDate = (String) params.get("tranDate");
@@ -556,7 +545,6 @@
     * @return
     */
    @PostMapping ("/checkbillXTYH")
    @Operation(summary = "邢台银行对账接口" , description = "邢台银行对账接口" )
    public Object checkbillXTYH(String date){
        String xtyhpay = systemConfigProperties.getXTYHPAY();
        Map<String,Object> map = new HashMap<>();
@@ -601,7 +589,6 @@
     * @return
     */
    @PostMapping ("/searchPayStatus")
    @Operation(summary = "交易状态查询" , description = "交易状态查询" )
    public Object searchPayStatus(String txnOrderId,String txnOrderTime){
        OutPark outPark = outParkService.findByOrderId(txnOrderId);
        if(outPark == null){
@@ -728,7 +715,48 @@
                outParkService.saveOrUpdate(outPark);
                //缓存在redis里
                String jsonValue = JSON.toJSONString(outPark);
                redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue);
                String redisKey = "outPark-"+outPark.getBarrierId();
                String parkChangeKey = "park_change_in_"+outPark.getParkId();
                int retryCount = 0;
                int maxRetry = 3;
                boolean cacheSuccess = false;
                while(retryCount < maxRetry && !cacheSuccess){
                    try {
                        redisTemplate.opsForValue().set(redisKey, jsonValue);
                        redisTemplate.opsForValue().set(parkChangeKey,"true",1, TimeUnit.DAYS);
                        cacheSuccess = true;
                        String logs = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss").format(new Date())+
                                " 车牌号为:"+outPark.getCarNo()+
                                ",Redis缓存设置成功,道闸ID:"+outPark.getBarrierId()+"\n";
                        writeTxt2(logs);
                    } catch (Exception e) {
                        retryCount++;
                        String errorLogs = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss").format(new Date())+
                                " 车牌号为:"+outPark.getCarNo()+
                                ",Redis缓存设置失败,第"+retryCount+"次重试,错误信息:"+e.getMessage()+"\n";
                        writeTxt2(errorLogs);
                        e.printStackTrace();
                        if(retryCount < maxRetry){
                            try {
                                Thread.sleep(100); // 等待100ms后重试
                            } catch (InterruptedException ie) {
                                Thread.currentThread().interrupt();
                            }
                        }
                    }
                }
                if(!cacheSuccess){
                    String errorLogs = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss").format(new Date())+
                            " 车牌号为:"+outPark.getCarNo()+
                            ",Redis缓存设置失败,已重试"+maxRetry+"次,请检查Redis服务状态!\n";
                    writeTxt2(errorLogs);
                    // 虽然Redis缓存失败,但数据库已更新,心跳接口可以通过数据库查询获取数据
                }
//                redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue);
//                redisTemplate.opsForValue().set("park_change_in_"+outPark.getParkId(),"true",1, TimeUnit.DAYS);
            }
        }
    }