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 com.boying.util.DateUtilOther;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.io.BufferedWriter;
|
import java.io.File;
|
import java.io.FileWriter;
|
import java.io.IOException;
|
import java.nio.file.Path;
|
import java.nio.file.Paths;
|
import java.nio.file.Files;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @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 ParkService parkService;
|
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){
|
if(queryId == null){
|
return R.failed("参数为空");
|
}
|
OutPark byId = outParkService.getById(queryId);
|
if(byId.getTime() > 0){
|
byId.setTimeStr(DateUtilOther.millisToDayHrMinSec(new Double(byId.getTime()).longValue()));
|
}
|
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(StringUtils.isNotBlank(w.getParkIds())){
|
if(w.getParkIds().contains(outPark.getParkId()+"")){
|
if(w.getEndTime()!=null){
|
if(System.currentTimeMillis()<w.getEndTime().getTime()){
|
updateOutPark(outPark.getId(),"03");
|
return R.failed("本次停车无需支付费用!");
|
}
|
}
|
}
|
|
}
|
}
|
}
|
if(StringUtils.isNotBlank(outPark.getPayCode()) && outPark.getStatus() == 0){
|
// "http://wxtest.smeia.cn/h5/static/router.html?rurl=router&router=psbc&appid=CUP16522400671¶ms={\"payMode\":\"B\",\"payItemNo\":\"41301106100124\",\"userNo\":"+id+"}"
|
return R.ok("跳转邮储支付","https://openpayment.psbc.com/h5/static/router.html?rurl=router&router=psbc&appid=CUP14094502391¶ms={\"payMode\":\"B\",\"payItemNo\":\"41304508000500\",\"userNo\":"+id+"}");
|
// return R.ok("跳转邮储支付","http://wxtest.smeia.cn/h5/static/router.html?rurl=router&router=psbc&appid=CUP16522400671¶ms={\"payMode\":\"B\",\"payItemNo\":\"41301106100124\",\"userNo\":"+id+"}");
|
}else if(StringUtils.isNotBlank(outPark.getPayCode()) && outPark.getStatus() == 1){
|
return R.failed("已缴费");
|
}
|
|
if(StringUtils.isBlank(outPark.getPayCode())){
|
addOrderRecord(outPark);
|
return R.ok("跳转邮储支付","https://openpayment.psbc.com/h5/static/router.html?rurl=router&router=psbc&appid=CUP14094502391¶ms={\"payMode\":\"B\",\"payItemNo\":\"41304508000500\",\"userNo\":"+id+"}");
|
}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
|
* @return
|
*/
|
@PostMapping ("/checkbill")
|
public Object checkbill(@RequestBody Map params){
|
String checkDate = (String) params.get("checkDate");
|
String tranDate = (String) params.get("tranDate");
|
String fileName = (String) params.get("fileName");
|
checkDate=checkDate.replaceAll("-","");
|
String name = "E:\\ycCheckBill\\Bank_PSBC_"+checkDate+".txt";
|
File file = new File(name);
|
Boolean aBoolean = judeFileExists(file);
|
if(aBoolean){
|
return R.ok(null,"查询文件成功");
|
}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);
|
//测试环境,暂时把开票设置为2
|
orderRecord.setTicketStatus(2);
|
}
|
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;
|
}
|
}
|
|
//插入停车订单记录
|
public void addOrderRecord(OutPark outPark){
|
outPark.setPayCode(outPark.getId()+"");
|
outParkService.saveOrUpdate(outPark);
|
Park park = parkService.getById(outPark.getParkId());
|
OrderRecord orderRecord = new OrderRecord();
|
orderRecord.setAddress(park.getName());
|
orderRecord.setCarNo(outPark.getCarNo());
|
orderRecord.setCode(outPark.getCode());
|
orderRecord.setCode2(outPark.getCode2());
|
orderRecord.setMoney(outPark.getPrice());
|
orderRecord.setQueryId(outPark.getId());
|
orderRecord.setType(1);
|
orderRecord.setTicketStatus(0);
|
orderRecord.setPayCode(outPark.getPayCode());
|
orderRecordService.saveOrUpdate(orderRecord);
|
}
|
|
//插入执法订单记录
|
public void addOrderRecord2(Ticket ticket){
|
OrderRecord orderRecord = new OrderRecord();
|
orderRecord.setAddress(ticket.getAddress());
|
orderRecord.setCarNo(ticket.getCarNo());
|
orderRecord.setCode(ticket.getCode());
|
orderRecord.setMoney(ticket.getMoney());
|
orderRecord.setQueryId(ticket.getId());
|
orderRecord.setType(0);
|
orderRecord.setPayCode(ticket.getPayCode());
|
orderRecordService.saveOrUpdate(orderRecord);
|
}
|
|
|
|
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("打印错误");
|
}
|
}
|
|
public static void main(String[] args) {
|
Path path = Paths.get("E:\\ycCheckBill\\Bank_PSBC_20350421.txt");
|
try {
|
List<String> lines = Files.readAllLines(path);
|
String s = lines.get(0);
|
String[] split = s.split("\\|");
|
|
|
for (String line : lines) {
|
System.out.println(line);
|
}
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
}
|