From bf0d3beb840ea1fa6cc117bc6ba569d89e880e15 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期二, 07 三月 2023 13:40:30 +0800
Subject: [PATCH] 新增邮储对接接口

---
 src/main/java/com/boying/controller/phone/YCPayController.java |  239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 239 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/boying/controller/phone/YCPayController.java b/src/main/java/com/boying/controller/phone/YCPayController.java
new file mode 100644
index 0000000..8d18b3b
--- /dev/null
+++ b/src/main/java/com/boying/controller/phone/YCPayController.java
@@ -0,0 +1,239 @@
+package com.boying.controller.phone;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.boying.common.R;
+import com.boying.common.SystemConfigProperties;
+import com.boying.entity.*;
+import com.boying.service.*;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author kdq
+ * @version 1.0.0
+ * @ClassName YCPayController.java
+ * @Description 閭偍瀵规帴鏀粯鎺ュ彛
+ * @createTime 2023骞�03鏈�07鏃� 08:22:00
+ */
+@RestController
+@RequestMapping("/ffzf/api")
+@RequiredArgsConstructor
+public class YCPayController {
+    private final OutParkService outParkService;
+    private final OrderRecordService orderRecordService;
+    private final TicketService ticketService;
+    private final TicketBlackService ticketBlackService;
+    private final SystemConfigProperties systemConfigProperties;
+    private final WhiteListService whiteListService;
+
+    /**
+     * 鏌ヨ璁㈠崟鎺ュ彛
+     * @param queryId
+     * @return
+     */
+    @GetMapping("/getByQueryId")
+    public Object getByQueryId(Long queryId){
+        OutPark byId = outParkService.getById(queryId);
+        return R.ok(byId,"璇锋眰鎴愬姛");
+    }
+
+    /**
+     * 缂存涔�
+     */
+    @PostMapping("park")
+    public Object park(Long id){
+        OutPark outPark =  outParkService.getById(id);
+        if(outPark.getPrice()==0){
+            updateOutPark(outPark.getId(),"03");
+            return R.failed("鏈鍋滆溅鏃犻渶鏀粯璐圭敤");
+        }
+
+        //鍒ゆ柇鏄惁鍦ㄧ櫧鍚嶅崟
+        QueryWrapper<WhiteList> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(WhiteList::getCarNo,outPark.getCarNo());
+        List<WhiteList> all = whiteListService.list(wrapper);
+        for(WhiteList w : all){
+            if(w.getType()==0){
+                updateOutPark(outPark.getId(),"03");
+                return R.failed("鏈鍋滆溅鏃犻渶鏀粯璐圭敤!");
+            }else{
+                if(w.getParkId()!=null){
+                    if(w.getEndTime()!=null){
+                        if(w.getParkId().equals(outPark.getParkId())&&System.currentTimeMillis()<w.getEndTime().getTime()){
+                            updateOutPark(outPark.getId(),"03");
+                            return R.failed("鏈鍋滆溅鏃犻渶鏀粯璐圭敤!");
+                        }
+                    }
+                }
+            }
+        }
+        if(outPark.getStatus() == 0){
+            return R.ok("璺宠浆閭偍鏀粯", "https://hbfs.govpay.ccb.com/online/fssm?fee=130000000001&PyfScnCgycd=01&pyfTpcd=3&BNo="+outPark.getPayCode());
+        }else if(outPark.getStatus() == 1){
+            return R.failed("宸茬即璐�");
+        }else {
+            return R.failed("绯荤粺寮傚父");
+        }
+    }
+
+    /**
+     * 鏀粯鍥炶皟鎺ュ彛
+     * @param queryId
+     * @return
+     */
+    @GetMapping("/result")
+    public Object result(Long queryId,int success,int msg){
+        OutPark byId = outParkService.getById(queryId);
+        if(byId == null){
+            return R.failed("鏈煡璇㈠埌璁㈠崟");
+        }else {
+            //淇敼璁㈠崟鐘舵�� 0鎴愬姛
+            if(success==0){
+                updateOrderRecord(queryId,"03");
+                return R.ok(null,"璇锋眰鎴愬姛");
+            }else {
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
+                String logs = sdf.format(new Date())+" 鍑哄満id涓猴細"+queryId+",缂磋垂澶辫触------銆媆n";
+                logs += "鍥炴墽鍘熷洜锛�"+msg+",\n";
+                writeTxt(logs);
+            }
+        }
+        return R.ok(byId,"璇锋眰鎴愬姛");
+    }
+
+    /**
+     * 瀵硅处鎺ュ彛
+     * @param checkDate,tranDate,fileName
+     * @return
+     */
+    @GetMapping("/checkbill")
+    public Object checkbill(String checkDate,String tranDate,String fileName){
+        checkDate=checkDate.replaceAll("-","");
+        String name = "E:\\Bank_PSBC_"+checkDate+".txt";
+        File file = new File(name);
+        Boolean aBoolean = judeFileExists(file);
+        if(aBoolean){
+            return R.ok();
+        }else {
+            return R.failed(null,"鏂囦欢涓嶅瓨鍦�");
+        }
+    }
+
+
+
+    //鏇存柊璁㈠崟璁板綍
+    public void updateOrderRecord(Long queryId,String status){
+        QueryWrapper<OrderRecord> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(OrderRecord::getQueryId,queryId)
+                .orderByDesc(OrderRecord::getCreateTime);
+        List<OrderRecord> all = orderRecordService.list(wrapper);
+        if(all.size()>=1){
+            OrderRecord orderRecord = all.get(0);
+            if(status.equals("01")){
+                orderRecord.setStatus(0);
+            }
+            if(status.equals("03")){
+                orderRecord.setStatus(1);
+            }
+            if(status.equals("04")||status.equals("05")||status.equals("06")){
+                orderRecord.setStatus(2);
+            }
+            orderRecordService.saveOrUpdate(orderRecord);
+            if(orderRecord.getType()==0){
+                updateTicket(orderRecord.getQueryId(),status);
+            }else{
+               updateOutPark(orderRecord.getQueryId(),status);
+            }
+        }
+    }
+
+    //鏇存柊缃氬崟鐨勭姸鎬�
+    public void updateTicket(Integer ticketId,String status){
+        Ticket ticket = ticketService.getById(ticketId);
+        if(ticket!=null){
+            if(status.equals("01")){
+                ticket.setPayStatus(0);
+            }
+            if(status.equals("03")){
+                ticket.setPayStatus(1);
+                dealCar(ticket.getCarNo());
+            }
+            if(status.equals("04")||status.equals("05")||status.equals("06")){
+                ticket.setPayStatus(2);
+            }
+            ticketService.saveOrUpdate(ticket);
+        }
+    }
+
+    //鏇存柊缃氬崟缂磋垂鐘舵��
+    private void dealCar(String carNo){
+        QueryWrapper<Ticket> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(Ticket::getCarNo,carNo)
+                .eq(Ticket::getPayStatus,1);
+        List<Ticket> tickets = ticketService.list(wrapper);
+        if(tickets.size()==0){
+            //鏇存柊缂磋垂鐘舵��
+            QueryWrapper<TicketBlack> wrapper1 = new QueryWrapper<>();
+            wrapper1.lambda()
+                    .eq(TicketBlack::getCarNo,carNo);
+            List<TicketBlack> all = ticketBlackService.list(wrapper1);
+            for(TicketBlack ticketBlack:all){
+                ticketBlack.setStatus(1);
+                ticketBlack.setBlackType(0);
+                ticketBlackService.saveOrUpdate(ticketBlack);
+            }
+        }
+    }
+
+
+    //鏇存柊鍑哄満
+    public void updateOutPark(Integer outParkId, String status){
+        OutPark outPark = outParkService.getById(outParkId);
+        if(outPark!=null){
+            if(status.equals("03")){
+                outPark.setStatus(1);
+                outParkService.saveOrUpdate(outPark);
+            }
+        }
+    }
+
+    //鍒ゆ柇鏂囦欢鏄惁瀛樺湪
+    public Boolean judeFileExists(File file){
+        if(file.exists()){
+            return true;
+        }else {
+            return false;
+        }
+    }
+
+    private void writeTxt( String txt)
+    {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+        try
+        {
+            FileWriter f = new FileWriter(systemConfigProperties.getLogPath()+"鏀粯鏃ュ織"+sdf.format(new Date())+".txt",true);
+            BufferedWriter bw=new BufferedWriter(f);
+            bw.write(txt);
+            bw.newLine();
+            bw.close();
+        }
+        catch(Exception e)
+        {
+            System.out.println("鎵撳嵃閿欒");
+        }
+    }
+}

--
Gitblit v1.9.1