WeixinPayController.java 48.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
package com.rnt.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.alibaba.fastjson.JSONObject;

import com.jfinal.aop.Clear;
import com.jfinal.aop.Duang;
import com.jfinal.core.Controller;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.weixin.sdk.api.PaymentApi;
import com.jfinal.weixin.sdk.api.PaymentApi.TradeType;
import com.jfinal.weixin.sdk.kit.IpKit;
import com.jfinal.weixin.sdk.kit.PaymentKit;
import com.jfinal.weixin.sdk.utils.HttpUtils;
import com.jfinal.weixin.sdk.utils.JsonUtils;
import com.rnt.commo.enums.DataStatusEnum;
import com.rnt.commo.enums.ErrorType;
import com.rnt.commo.enums.OrderTypeEnum;
import com.rnt.commo.enums.PayOrderEnum;
import com.rnt.commo.enums.SequenceTypeEnum;
import com.rnt.commo.interceptor.BindInterceptor;
import com.rnt.model.zf.CardCoupons;
import com.rnt.model.zf.Order;
import com.rnt.model.zf.ParkCardCoupons;
import com.rnt.model.zf.PayOrder;
import com.rnt.model.zf.PayOrderFlow;
import com.rnt.service.CardOrderService;
import com.rnt.service.IRainQueryService;
import com.rnt.service.OrderService;
import com.rnt.service.ParkCardCouponsService;
import com.rnt.service.ParkLotService;
import com.rnt.service.PersonCardCouponsService;
import com.rnt.utils.CardTypeUtil;
import com.rnt.utils.SequenceUtil;
import com.rnt.utils.TLWXUser;
import com.rnt.vo.BizResult;
import com.rnt.vo.CardBuyVO;
import com.rnt.vo.CardOrderVO;
import com.rnt.vo.OrderVO;
import com.rnt.vo.ParkLotCardVO;
import com.xiaoleilu.hutool.date.DateField;
import com.xiaoleilu.hutool.date.DateUtil;
import org.beetl.sql.core.kit.StringKit;

/**
 * 感谢 *半杯* 童鞋联调支付API
 *
 * @author L.cm
 */
public class WeixinPayController extends Controller {
    private static final Log logger = Log.getLog(WeixinPayController.class);
    //商户相关资料
    //appid
    private static String appid = PropKit.get("appId");
    //商户号
    private static String partner = "1452886602";
    //支付密钥
    private static String paternerKey = "CJ8qjI3isPNbAZghtTcQJB3c5N9PQmlI";
    //推送地址
    private static String notify_url = PropKit.get("app.host") + "/pay/pay_notify";
    //是否允许信用卡支付
    private static Boolean noCredit = PropKit.getBoolean("pay.noCredit");

    CardOrderService cardOrderService = Duang.duang(CardOrderService.class);

    /**
     * 续费订单提交
     */
    public void renewSubmitOrder() {

        BizResult<String> result = new BizResult<>();
        Long cardCouponsId = getParaToLong("custCardId");
        Integer num = getParaToInt("num");

        //订购数量为空
        if (num == null || num == 0) {
            logger.info("停车卡续费 订购数量为空,返回失败!");
            result.setCode(ErrorType.PARAMM_NULL.getCode());
            result.setMsg("订购数量不能为空");
            renderJson(result);
            return;
        }

        if (null == cardCouponsId || cardCouponsId == 0) {
            logger.info("个人卡卷ID为空,重定向上一页面,重新进行业务访问!");
            BizResult<String> bizResult = new BizResult<>();
            String url = PropKit.get("app.host") + "/park/myParkCardView";
            bizResult.setData(url);
            bizResult.setCode(ErrorType.URL_REDIRECT.getCode());
            bizResult.setMsg("业务参数异常,点击确认返回首页请重新尝试访问!");
            renderJson(bizResult);
            return;
        }

        CardCoupons cardCoupons = CardCoupons.dao.findById(cardCouponsId);
        if (null == cardCoupons) {
            logger.info("根据个人卡卷ID查询出的跟人卡卷信息为空,重定向上一页面,重新进行业务访问! cardCouponsId=" + cardCouponsId);
            BizResult<String> bizResult = new BizResult<>();
            String url = PropKit.get("app.host") + "/park/myParkCardView";
            bizResult.setData(url);
            bizResult.setCode(ErrorType.URL_REDIRECT.getCode());
            bizResult.setMsg("业务参数异常,点击确认返回首页请重新尝试访问!");
            renderJson(bizResult);
            return;
        }

        Date startDate = DateUtil.offsetDay(cardCoupons.getExpDate(), 1);
        String startDateStr = DateUtil.format(startDate, "yyyy-MM-dd");
        String endDateStr;
        /** 订单类型:3:月卡订单,2:年卡订单. */
        String orderType;
        if ("YEAR".equals(CardTypeUtil.judgeMonthOrYear(cardCoupons.getCardType() + ""))) {
            //年卡
            Date endDate = DateUtil.offset(startDate, DateField.YEAR, num);
            endDateStr = DateUtil.format(endDate, "yyyy-MM-dd");
            orderType = "2";
        } else {
            //月卡
            Date endDate = DateUtil.offset(startDate, DateField.MONTH, num);
            endDateStr = DateUtil.format(endDate, "yyyy-MM-dd");
            orderType = "3";
        }

        CardBuyVO vo = new CardBuyVO();
        /** 停车场卡券id. */
        vo.setPersonCardId(cardCouponsId+"");
        //购买数量
        vo.setBuyNum(num + "");
        //车牌号.
        vo.setCarNum(cardCoupons.getCarNumber());
        //设置开始时间
        vo.setStartDate(startDateStr);
        //设置结束时间
        vo.setEndDate(endDateStr);
        //设置订单类型
        vo.setOrderType(orderType);
        //设置总金额
        //1、单价乘以数量 2、设置2位小数并设置取舍方法(四舍五入)
        BigDecimal totleMoney = cardCoupons.getCardPrice().multiply(new BigDecimal(num)).setScale(2,
            BigDecimal.ROUND_HALF_UP);
        vo.setTotleMoney(totleMoney.toString());
        //设置客户ID
        vo.setPersonCustId(cardCoupons.getCustId());
        //设置订单明细类型
        /**订单明细类型:1:购卡,2:续费.*/
        vo.setOrderDetailType(2);
        ParkCardCoupons parkCardCoupons = ParkCardCoupons.dao.findById(cardCoupons.getParkCardId());
        vo.setParkLotCardId(parkCardCoupons.getId().toString());
        logger.info("=====开始调用订单保存服务======");
        logger.info("购买信息为:CardBuyVO=" + JSONObject.toJSONString(vo));
        logger.info("停车场卡卷信息为:ParkCardCoupons=" + JSONObject.toJSONString(parkCardCoupons));
        String orderId = cardOrderService.saveOrder(vo, parkCardCoupons);
        logger.info("返回的订单信息为:orderId=" + orderId);
        logger.info("=====开始调用订单保存服务======");

        if (StringKit.isEmpty(orderId)) {
            result.setMsg("业务异常");
            result.setCode(ErrorType.BIZ_ERROR.getCode());

        } else {
            result.setData(orderId);
        }

        renderJson(result);

    }

    /**
     * 跳转到续费界面
     */
    public void renewView() {
        //获取个人卡卷ID
        Long cardCouponsId = getParaToLong("custCardId");
        //停车场名称
        String parkName = getPara("parkName");

        if (null == cardCouponsId || cardCouponsId == 0) {
            logger.info("个人卡卷ID为空,重定向上一页面,重新进行业务访问!");
            BizResult<String> bizResult = new BizResult<>();
            String url = PropKit.get("app.host") + "/park/myParkCardView";
            bizResult.setData(url);
            bizResult.setCode(ErrorType.URL_REDIRECT.getCode());
            bizResult.setMsg("业务参数异常,请重新进入页面尝试访问!");
            renderJson(bizResult);
            return;
        }

        CardCoupons cardCoupons = CardCoupons.dao.findById(cardCouponsId);
        if (null == cardCoupons) {
            logger.info("根据个人卡卷ID查询出的跟人卡卷信息为空,重定向上一页面,重新进行业务访问! cardCouponsId=" + cardCouponsId);
            BizResult<String> bizResult = new BizResult<>();
            String url = PropKit.get("app.host") + "/park/myParkCardView";
            bizResult.setData(url);
            bizResult.setCode(ErrorType.URL_REDIRECT.getCode());
            bizResult.setMsg("业务参数异常,请重新进入页面尝试访问!");
            renderJson(bizResult);
            return;
        }

        //id
        setAttr("id", cardCouponsId);
        //车牌号
        setAttr("carNo", cardCoupons.getCarNumber());
        //卡类别
        setAttr("cardType", cardCoupons.getCardType());
        //卡类别名称
        setAttr("cardTypeStr", CardTypeUtil.getCardNameByCardType(cardCoupons.getCardType() + ""));
        //到期时间
        setAttr("expDate", cardCoupons.getExpDate());
        //到期时间字符串
        setAttr("expDateStr", DateUtil.format(cardCoupons.getExpDate(), "yyyy-MM-dd"));
        //单价
        setAttr("cardPrice", cardCoupons.getCardPrice());
        //停车场名称
        setAttr("parkName", parkName);

        if ("YEAR".equalsIgnoreCase(CardTypeUtil.judgeMonthOrYear(cardCoupons.getCardType() + ""))) {
            //年卡
            render("yearrenew.html");

        } else if ("MONTH".equalsIgnoreCase(CardTypeUtil.judgeMonthOrYear(cardCoupons.getCardType() + ""))) {
            //月卡
            render("monthrenew.html");

        }

    }

    /**
     * 跳转月卡订单预览页面.<br/>
     */
    public void monthOrderView() {
        //停车场月卡Id
        String id = this.getPara("id");
        this.getRequest().setAttribute("parkLotCardId", id);
        render("monthpay.html");
    }

    /**
     * 跳转月卡订单预览页面.<br/>
     */
    public void yearOrderView() {
        //停车场月卡Id
        String id = this.getPara("id");
        this.getRequest().setAttribute("parkLotCardId", id);
        render("yearpay.html");
    }

    /**
     * 跳转订单支付页面.<br/>
     */
    public void orderPayView() {
        //订单id
        String parkOrderId = this.getPara("parkOrderId");
        PayOrder payOrder = new PayOrder();
        String payOrderId = SequenceUtil.getNextOrderId(SequenceTypeEnum.ORDER_PAY_WXGZH.value());
        payOrder.setPayOrderId(payOrderId);
        payOrder.setPaySrcType(Integer.valueOf(PayOrderEnum.PAY_RESOURCE_TYPE_SERVICE.getValue()));
        payOrder.setRltOrderId(parkOrderId);
        payOrder.setPayOrderTitle(PayOrderEnum.PAY_ORDER_TYPE_PAY.getValue());
        payOrder.setPayType(Integer.valueOf(PayOrderEnum.PAY_TYPE_WXGZH.getValue()));
        payOrder.setPayOrderState(Integer.valueOf(PayOrderEnum.PAY_ORDER_STATE_WAIT_PAY.getValue()));
        payOrder.setPayorderStateTime(new Date());
        payOrder.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
        payOrder.setCreateDate(new Date());
        payOrder.setModfiyDate(new Date());
        logger.info("支付单save请求数据为: payOrder=" + JSONObject.toJSONString(payOrder));
        Boolean flag = payOrder.save();
        logger.info("支付单save 响应为: flag=" + flag);

        this.getRequest().setAttribute("parkOrderId", parkOrderId);
        setAttr("payOrderId", payOrderId);
        render("pay.html");
    }

    /**
     * 跳转错误页面.<br/>
     */
    @Clear
    public void errorView() {
        render("syserror.html");
    }

    /**
     * 查询待支付订单信息.<br/>
     */
    public void queryOrderForNotPay() {
        String orderId = this.getPara("parkOrderId");
        BizResult<CardOrderVO> result = new BizResult<CardOrderVO>();
        if (StringKit.isNotBlank(orderId)) {
            CardOrderVO cardOrderVO = cardOrderService.queryNotPayCardOrder(orderId);
            if (cardOrderVO != null) {
                result.setData(cardOrderVO);
            } else {
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }
        } else {
            result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
        }
        this.renderJson(result);
    }

    /**
     * 查询选择购买得卡信息
     */
    public void queryParkLotCardForChoose() {
        BizResult<ParkLotCardVO> result = new BizResult<ParkLotCardVO>();
        ParkCardCouponsService parkCardCouponsService = Duang.duang(ParkCardCouponsService.class);
        ParkLotService parkLotService = Duang.duang(ParkLotService.class);
        List<ParkCardCoupons> list = new ArrayList<ParkCardCoupons>();
        try {
            Long parkLotCardId = this.getParaToLong("parkLotCardId");
            //1.查询卡
            ParkCardCoupons parkCardCoupons = parkCardCouponsService.queryParkCardCouponsById(parkLotCardId);
            if (parkCardCoupons != null && StringKit.isNotBlank(parkCardCoupons.getParkId())) {
                list.add(parkCardCoupons);
                //.查询停车场信息
                result = parkLotService.queryParkLotForpklNo(parkCardCoupons.getParkId());
            } else {
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }
            if (result.getData() != null) {
                result.getData().setParkCardCouponsList(list);
            } else {
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.renderJson(result);
    }

    /**
     * 生成订单信息.<br/>
     */
    public void createOrderInfo() {
        BizResult<String> result = new BizResult<String>();
        ParkCardCouponsService parkCardCouponsService = Duang.duang(ParkCardCouponsService.class);
        PersonCardCouponsService personCardCouponsService = Duang.duang(PersonCardCouponsService.class);
        Map<String, String[]> map = this.getParaMap();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            /**获取请求参数.*/
            CardBuyVO cardBuyVO = this.getRequestParam(map);
            cardBuyVO.setPersonCustId(TLWXUser.getCustId());
            cardBuyVO.setOrderDetailType(OrderTypeEnum.ORDER_DETAIL_TYPE_BUY_CARD.value());
            if (StringKit.isNotBlank(cardBuyVO.getBuyNum()) && StringKit.isNotBlank(cardBuyVO.getStartDate())
                && StringKit.isNotBlank(cardBuyVO.getParkLotCardId())) {
                //1.查询卡
                ParkCardCoupons parkCardCoupons = parkCardCouponsService.queryParkCardCouponsById(
                    StringKit.isNotBlank(cardBuyVO.getParkLotCardId()) ? Long.valueOf(cardBuyVO.getParkLotCardId())
                        : 0L);
                //计算总金额
                logger.info("前端金额=" + cardBuyVO.getTotleMoney());
                cardBuyVO.setTotleMoney(
                    (parkCardCoupons.getGoodsAmount().longValue() * Integer.parseInt(cardBuyVO.getBuyNum())) + "");
                logger.info("计算金额=" + cardBuyVO.getTotleMoney());
                if ("3".equals(cardBuyVO.getOrderType())) {
                    //计算结束月份
                    Date date = format.parse(cardBuyVO.getStartDate());
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(date);
                    calendar.add(Calendar.MONTH, Integer.parseInt(cardBuyVO.getBuyNum()));
                    Date resultDate = calendar.getTime();
                    logger.info("前端结束时间=" + cardBuyVO.getEndDate());
                    cardBuyVO.setEndDate(format.format(resultDate));
                    logger.info("--计算结束时间=" + cardBuyVO.getEndDate());
                } else {
                    //计算结束年
                    Date date = format.parse(cardBuyVO.getStartDate());
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(date);
                    calendar.add(Calendar.YEAR, Integer.parseInt(cardBuyVO.getBuyNum()));
                    Date resultDate = calendar.getTime();
                    logger.info("前端结束时间=" + cardBuyVO.getEndDate());
                    cardBuyVO.setEndDate(format.format(resultDate));
                    logger.info("--计算结束时间=" + cardBuyVO.getEndDate());
                }
                /**创建个人卡信息.*/
                 String personCardId = personCardCouponsService.savePersonCard(cardBuyVO, parkCardCoupons);
                 cardBuyVO.setPersonCardId(personCardId);
                //2.创建订单
                /**插入停车订单.*/
                String orderId = cardOrderService.saveOrder(cardBuyVO, parkCardCoupons);
                if (StringKit.isNotBlank(orderId)) {
                	result.setData(orderId);
                } else {
                    result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
                }

            } else {
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        this.renderJson(result);
    }

    /**
     * 获取RequestParam.<br/>
     *
     * @param map
     * @return
     */
    private CardBuyVO getRequestParam(Map<String, String[]> map) {
        CardBuyVO cardBuyVO = new CardBuyVO();
        try {
            if (map != null && map.size() > 0) {
                Set<Entry<String, String[]>> set = map.entrySet();
                for (Iterator<Entry<String, String[]>> iter = set.iterator(); iter.hasNext(); ) {
                    Entry<String, String[]> entry = iter.next();
                    System.out.println(entry.getKey() + "" + entry.getValue()[0]);
                    switch (entry.getKey()) {
                        case "parkLotCardId":
                            cardBuyVO.setParkLotCardId(entry.getValue()[0]);
                            break;
                        case "orderType":
                            cardBuyVO.setOrderType(entry.getValue()[0]);
                            break;
                        case "buyNum":
                            cardBuyVO.setBuyNum(entry.getValue()[0]);
                            break;
                        case "startDate":
                            cardBuyVO.setStartDate(entry.getValue()[0]);
                            break;
                        case "endDate":
                            cardBuyVO.setEndDate(entry.getValue()[0]);
                            break;
                        case "carNum":
                            cardBuyVO.setCarNum(entry.getValue()[0]);
                            break;
                        case "totleMoney":
                            cardBuyVO.setTotleMoney(entry.getValue()[0]);
                            break;

                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cardBuyVO;
    }

    /**
     * 公众号支付js-sdk 获取js支付参数
     */
    public void getJSPayParam() {

        BizResult<String> bizResult = new BizResult<>();
        String orderId = getPara("orderId");
        String openId = getPara("openId");
        String payOrderId = getPara("payOrderId");
        logger.info("开始获取公众号支付JS支付参数: orderId=" + orderId + "; openId=" + openId+"; payOrderId="+payOrderId);
        //订单ID
        if (StringKit.isEmpty(orderId)) {
            bizResult.setCode(ErrorType.PARAMM_NULL.getCode());
            bizResult.setMsg("订单ID不能为空");
            renderJson(bizResult);
            return;
        }

        if(StringKit.isEmpty(payOrderId)){
            bizResult.setCode(ErrorType.PARAMM_NULL.getCode());
            bizResult.setMsg("支付单ID不能为空");
            renderJson(bizResult);
            return;
        }

        PayOrder payOrder = PayOrder.dao.findFirst("select * from td_b_pay_order t where t.pay_order_id = ?",payOrderId);

        if(null == payOrder){
            bizResult.setCode(ErrorType.PARAMM_NULL.getCode());
            bizResult.setMsg("支付单不存在");
            renderJson(bizResult);
            return;
        }


        // 判断支付单状态 支付单状态:0-待支付 1-成功 2-失败(作废)
        if (null == payOrder.getPayOrderState() || 0 != payOrder.getPayOrderState()) {
            logger.info("支付单状态不正确,支付单状态为: orderState=" + payOrder.getPayOrderState());
            bizResult.setCode(ErrorType.PARAMM_NULL.getCode());
            bizResult.setMsg("支付单状态不正确");
            renderJson(bizResult);
            return;
        }


        Order order = Order.dao.findFirst("select * from td_b_order t where t.order_id = ?", orderId);
        if (null == order) {
            bizResult.setCode(ErrorType.PARAMM_NULL.getCode());
            bizResult.setMsg("订单不存在");
            renderJson(bizResult);
            return;
        }
        // 判断订单状态 订单状态:1:待核算、2:待支付、3:已支付、4:已完成、5 逃逸、6 停车场收费
        if (null == order.getOrderState() || 2 != order.getOrderState()) {
            logger.info("订单状态不正确,订单状态为: orderState=" + order.getOrderState());
            bizResult.setCode(ErrorType.PARAMM_NULL.getCode());
            bizResult.setMsg("订单状态不正确");
            renderJson(bizResult);
            return;
        }
        //获取待支付金额,将元转换为分
        BigDecimal payFee = order.getOrderNotPayFee();
        Map<String, String> params = new HashMap<String, String>();
        //封装参数
        params.put("appid", appid);
        params.put("mch_id", partner);
        params.put("body", "任你停公众号订单支付");
        params.put("out_trade_no", payOrderId);
        //支付金额
        params.put("total_fee", payFee.longValue()+"");

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }

        params.put("spbill_create_ip", ip);
        params.put("trade_type", TradeType.JSAPI.name());
        params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
        params.put("notify_url", notify_url);
        params.put("openid", openId);
        //是否支持信用卡支付
        if (!noCredit) {
            //不支持信用卡
            params.put("limit_pay", "no_credit");
        }

        String sign = PaymentKit.createSign(params, paternerKey);
        params.put("sign", sign);
        logger.info("调用微信支付统一下单接口请求入参为:params=" + JSONObject.toJSONString(params));
        String xmlResult = PaymentApi.pushOrder(params);
        logger.info("调用微信支付统一下单接口返回结果为:xmlResult=" + xmlResult);
        Map<String, String> result = PaymentKit.xmlToMap(xmlResult);
        String return_code = result.get("return_code");
        String return_msg = result.get("return_msg");
        if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
            bizResult.setData("return_code=" + return_code + "; return_msg=" + return_msg);
            bizResult.setCode(ErrorType.BIZ_ERROR.getCode());
            bizResult.setMsg("调用微信支付异常,请稍后重试!");
            renderJson(bizResult);
            return;
        }
        String result_code = result.get("result_code");
        if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
            bizResult.setData("result_code=" + result_code + "; return_msg=" + return_msg);
            bizResult.setCode(ErrorType.BIZ_ERROR.getCode());
            bizResult.setMsg("调用微信支付异常,请稍后重试!");
            renderJson(bizResult);
            return;
        }
        // 以下字段在return_code 和result_code都为SUCCESS的时候有返回
        String prepay_id = result.get("prepay_id");
        Map<String, String> packageParams = new HashMap<String, String>();
        packageParams.put("appId", appid);
        packageParams.put("timeStamp", System.currentTimeMillis() / 1000 + "");
        packageParams.put("nonceStr", System.currentTimeMillis() + "");
        packageParams.put("package", "prepay_id=" + prepay_id);
        packageParams.put("signType", "MD5");
        logger.info("生成签名钱的字符串为: params="+packageParams.toString());
        String packageSign = PaymentKit.createSign(packageParams, paternerKey);
        logger.info("获取到的密钥为: paternerKey="+paternerKey);
        packageParams.put("paySign", packageSign);
        //生成js 支付调用串
        String paySign = JsonUtils.toJson(packageParams);
        logger.info("生成H5 调用支付串为:paySign=" + paySign);
        bizResult.setCode(ErrorType.BIZ_SUCCESS.getCode());
        bizResult.setData(paySign);
        renderJson(bizResult);
    }


    /**
     * 公众号支付js-sdk
     */
    public void index_default() {
        // openId,采用 网页授权获取 access_token API:SnsAccessTokenApi获取
        String openId = "";

        // 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1

        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
        params.put("mch_id", partner);
        params.put("body", "JFinal2.0极速开发");
        params.put("out_trade_no", "977773682111");
        params.put("total_fee", "1");

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }

        params.put("spbill_create_ip", ip);
        params.put("trade_type", TradeType.JSAPI.name());
        params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
        params.put("notify_url", notify_url);
        params.put("openid", openId);

        String sign = PaymentKit.createSign(params, paternerKey);
        params.put("sign", sign);
        String xmlResult = PaymentApi.pushOrder(params);

        System.out.println(xmlResult);
        Map<String, String> result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get("return_code");
        String return_msg = result.get("return_msg");
        if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
            renderText(return_msg);
            return;
        }
        String result_code = result.get("result_code");
        if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
            renderText(return_msg);
            return;
        }
        // 以下字段在return_code 和result_code都为SUCCESS的时候有返回
        String prepay_id = result.get("prepay_id");

        Map<String, String> packageParams = new HashMap<String, String>();
        packageParams.put("appId", appid);
        packageParams.put("timeStamp", System.currentTimeMillis() / 1000 + "");
        packageParams.put("nonceStr", System.currentTimeMillis() + "");
        packageParams.put("package", "prepay_id=" + prepay_id);
        packageParams.put("signType", "MD5");
        String packageSign = PaymentKit.createSign(packageParams, paternerKey);

        packageParams.put("paySign", packageSign);

        String jsonStr = JsonUtils.toJson(packageParams);
        setAttr("json", jsonStr);
        System.out.println(jsonStr);
        render("/jsp/pay.jsp");
    }

    /**
     * 支付成功通知
     */
    @Clear
    public void pay_notify() {
        // 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
        String xmlMsg = HttpKit.readData(getRequest());
        logger.info("接收到异步支付通知:xmlMsg=" + xmlMsg);
        Map<String, String> params = PaymentKit.xmlToMap(xmlMsg);

        String result_code = params.get("result_code");
        // 总金额
        String totalFee = params.get("total_fee");
        // 商户订单号  支付单号
        String payOrderId = params.get("out_trade_no");
        // 微信支付订单号
        String transId = params.get("transaction_id");
        // 支付完成时间,格式为yyyyMMddHHmmss
        String timeEnd = params.get("time_end");

        //支付流水保存
        PayOrderFlow payOrderFlow = new PayOrderFlow();
        payOrderFlow.setPayOrderFlowId(SequenceUtil.getNextOrderId(SequenceTypeEnum.ORDER_PAY_FLOW_WXGZH.value()));
        payOrderFlow.setPayOrderId(payOrderId);
        payOrderFlow.setTradeNo(transId);
        //传回的金额以 分 为单位,转换为double,然后转换为 BigDecimal类型
        payOrderFlow.setBuyerPayAmount(new BigDecimal(new Double(totalFee) / 100));
        //付款时间
        payOrderFlow.setGmtPayment(new Date());
        //处理环节
        payOrderFlow.setProcLink(2);
        //处理时间
        payOrderFlow.setProcTime(new Date());
        //支付类型
        payOrderFlow.setPayType(Integer.valueOf(PayOrderEnum.PAY_TYPE_WXGZH.getValue()));
        //支付流水类型
        payOrderFlow.setPayFlowType(Integer.valueOf(PayOrderEnum.PAY_FLOW_TYPE_ASYN.getValue()));
        //创建人
        payOrderFlow.setCreateEmpid("-1");
        //创建时间
        payOrderFlow.setCreateDate(new Date());
        //修改人
        payOrderFlow.setModfiyEmpid("-1");
        //修改时间
        payOrderFlow.setModfiyDate(new Date());

        boolean flag = false;

        // 注意重复通知的情况,同一订单号可能收到多次通知,请注意一定先判断订单状态
        // 避免已经成功、关闭、退款的订单被再次更新
        Map<String, String> xml = new HashMap<String, String>();
        if (PaymentKit.verifyNotify(params, paternerKey)) {
            if (("SUCCESS").equals(result_code)) {
                //用户标识
                String openId = params.get("openid");
                payOrderFlow.setBuyerLogonId(openId);
                //更新订单信息
                OrderService orderService = Duang.duang(OrderService.class, new Tx());
                logger.info("微信支付异步通知订单更新 payOrder=" + payOrderId);
                flag = orderService.payOrderSuccess(payOrderId, transId);
                logger.info("微信支付异步通知订单更新结果为 flag=" + flag);
                xml.put("return_code", "SUCCESS");
                xml.put("return_msg", "OK");

            } else {
                String err_code = params.get("err_code");
                String err_code_des = params.get("err_code_des");
                logger.info("微信支付异步通知业务异常:err_code=" + err_code + "; err_code_des=" + err_code_des);
                xml.put("return_code", "FAIL");
                xml.put("return_msg", "业务失败");
            }
        } else {
            logger.info("微信支付异步通知验证签名失败,返回FAIL");
            xml.put("return_code", "FAIL");
            xml.put("return_msg", "签名失败!");
            flag = false;
        }
        if (flag) {
            payOrderFlow.setProcResult(1);
        } else {
            payOrderFlow.setProcResult(2);
        }
        payOrderFlow.save();

        renderText(PaymentKit.toXml(xml));
        return;
    }

    /**
     * @author Javen
     * 2016年5月14日
     * PC扫码支付获取二维码(模式一)
     */
    public String getCodeUrl(String productId) {
        String url = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";

        String timeStamp = Long.toString(System.currentTimeMillis() / 1000);
        String nonceStr = Long.toString(System.currentTimeMillis());
        Map<String, String> packageParams = new HashMap<String, String>();
        packageParams.put("appid", appid);
        packageParams.put("mch_id", partner);
        packageParams.put("product_id", productId);
        packageParams.put("time_stamp", timeStamp);
        packageParams.put("nonce_str", nonceStr);
        String packageSign = PaymentKit.createSign(packageParams, paternerKey);

        return String.format(url, packageSign, appid, partner, productId, timeStamp, nonceStr);
    }

    public void test() {
        String product_id = "001";
        renderText(getCodeUrl(product_id));
    }

    /**
     * @author Javen
     * 2016年5月14日
     * PC扫码支付回调(模式一)
     */
    public void wxpay() {
        String result = HttpKit.readData(getRequest());
        System.out.println("回调结果=" + result);
        /**
         * 获取返回的信息内容中各个参数的值
         */
        Map<String, String> map = PaymentKit.xmlToMap(result);
        for (String key : map.keySet()) {
            System.out.println("key= " + key + " and value= " + map.get(key));
        }

        String appid = map.get("appid");
        String openid = map.get("openid");
        String mch_id = map.get("mch_id");
        String is_subscribe = map.get("is_subscribe");
        String nonce_str = map.get("nonce_str");
        String product_id = map.get("product_id");
        String sign = map.get("sign");
        Map<String, String> packageParams = new HashMap<String, String>();
        packageParams.put("appid", appid);
        packageParams.put("openid", openid);
        packageParams.put("mch_id", mch_id);
        packageParams.put("is_subscribe", is_subscribe);
        packageParams.put("nonce_str", nonce_str);
        packageParams.put("product_id", product_id);

        String packageSign = PaymentKit.createSign(packageParams, paternerKey);
        if (sign.equals(packageSign)) {
            // 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1

            Map<String, String> params = new HashMap<String, String>();
            params.put("appid", appid);
            params.put("mch_id", mch_id);
            params.put("body", "测试扫码支付");
            String out_trade_no = Long.toString(System.currentTimeMillis());
            params.put("out_trade_no", out_trade_no);
            int price = ((int)(Float.valueOf(10) * 100));
            params.put("total_fee", price + "");
            params.put("attach", out_trade_no);

            String ip = IpKit.getRealIp(getRequest());
            if (StrKit.isBlank(ip)) {
                ip = "127.0.0.1";
            }

            params.put("spbill_create_ip", ip);
            params.put("trade_type", TradeType.NATIVE.name());
            params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
            params.put("notify_url", notify_url);
            params.put("openid", openid);

            String paysign = PaymentKit.createSign(params, paternerKey);
            params.put("sign", paysign);

            String xmlResult = PaymentApi.pushOrder(params);

            System.out.println("prepay_xml>>>" + xmlResult);
            Map<String, String> payResult = PaymentKit.xmlToMap(xmlResult);

            String return_code = payResult.get("return_code");
            String return_msg = payResult.get("return_msg");

            if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
                System.out.println("return_code>>>" + return_msg);
                return;
            }
            if (StrKit.isBlank(return_msg) || !"OK".equals(return_msg)) {
                System.out.println("return_msg>>>>" + return_msg);
                return;
            }
            // 以下字段在return_code 和result_code都为SUCCESS的时候有返回
            String prepay_id = payResult.get("prepay_id");

            Map<String, String> prepayParams = new HashMap<String, String>();
            prepayParams.put("return_code", "SUCCESS");
            prepayParams.put("appId", appid);
            prepayParams.put("mch_id", mch_id);
            prepayParams.put("nonceStr", System.currentTimeMillis() + "");
            prepayParams.put("prepay_id", prepay_id);
            prepayParams.put("result_code", "SUCCESS");
            String prepaySign = PaymentKit.createSign(prepayParams, paternerKey);
            prepayParams.put("sign", prepaySign);
            String xml = PaymentKit.toXml(prepayParams);

            System.out.println(xml);

            renderText(xml);
        }
    }

    /**
     * 刷卡支付
     * 文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=5_1
     */
    public void micropay() {
        String url = "https://api.mch.weixin.qq.com/pay/micropay";

        String total_fee = "1";
        String auth_code = getPara("auth_code");//测试时直接手动输入刷卡页面上的18位数字

        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
        params.put("mch_id", partner);
        params.put("device_info", "javen205");//终端设备号
        params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
        params.put("body", "刷卡支付测试");
        //		params.put("detail", "json字符串");//非必须
        params.put("attach", "javen205");//附加参数非必须
        String out_trade_no = System.currentTimeMillis() + "";
        params.put("out_trade_no", out_trade_no);
        params.put("total_fee", total_fee);

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }

        params.put("spbill_create_ip", ip);
        params.put("auth_code", auth_code);

        String sign = PaymentKit.createSign(params, paternerKey);
        params.put("sign", sign);

        String xmlResult = HttpUtils.post(url, PaymentKit.toXml(params));
        //同步返回结果
        System.out.println("xmlResult:" + xmlResult);

        Map<String, String> result = PaymentKit.xmlToMap(xmlResult);
        String return_code = result.get("return_code");
        if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
            //通讯失败
            String err_code = result.get("err_code");
            //用户支付中,需要输入密码
            if (err_code.equals("USERPAYING")) {
                //等待5秒后调用【查询订单API】https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_2

            }
            renderText("通讯失败>>" + xmlResult);
            return;
        }

        String result_code = result.get("result_code");
        if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
            //支付失败
            renderText("支付失败>>" + xmlResult);
            return;
        }

        //支付成功 返回参会入库 业务逻辑处理

        renderText(xmlResult);
    }

    /**
     * PC支付模式二,PC支付不需要openid
     */
    public void pcModeTwo() {
        // 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
        params.put("mch_id", partner);
        params.put("body", "JFinal2.2极速开发");

        // 商品ID trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
        params.put("product_id", "1");
        // 商户订单号 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
        params.put("out_trade_no", "97777368222");
        params.put("total_fee", "1");

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }

        params.put("spbill_create_ip", ip);
        params.put("trade_type", TradeType.NATIVE.name());
        params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
        params.put("notify_url", notify_url);

        String sign = PaymentKit.createSign(params, paternerKey);
        params.put("sign", sign);
        String xmlResult = PaymentApi.pushOrder(params);

        System.out.println(xmlResult);
        Map<String, String> result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get("return_code");
        String return_msg = result.get("return_msg");
        if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
            renderText(return_msg);
            return;
        }
        String result_code = result.get("result_code");
        if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
            renderText(return_msg);
            return;
        }
        // 以下字段在return_code 和result_code都为SUCCESS的时候有返回
        String prepay_id = result.get("prepay_id");
        // trade_type为NATIVE是有返回,可将该参数值生成二维码展示出来进行扫码支付
        String code_url = result.get("code_url");

        setAttr("code_url", code_url);
        render("/jsp/pc_pay.jsp");
    }

    /**
     * wap支付第一版本
     */
    public void wap1() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
        params.put("mch_id", partner);
        params.put("body", "JFinal2.0极速开发");
        params.put("out_trade_no", "977773682111");
        params.put("total_fee", "1");

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }

        params.put("spbill_create_ip", ip);
        params.put("trade_type", TradeType.WAP.name());
        params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
        params.put("notify_url", notify_url);

        String sign = PaymentKit.createSign(params, paternerKey);
        params.put("sign", sign);
        String xmlResult = PaymentApi.pushOrder(params);

        System.out.println(xmlResult);
        Map<String, String> result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get("return_code");
        String return_msg = result.get("return_msg");
        if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
            renderText(return_msg);
            return;
        }
        String result_code = result.get("result_code");
        if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
            renderText(return_msg);
            return;
        }
        // 以下字段在return_code 和result_code都为SUCCESS的时候有返回
        String prepayId = result.get("prepay_id");
        String url = PaymentApi.getDeepLink(appid, prepayId, paternerKey);

        // 微信那边的开发建议用a标签打开该链接
        setAttr("url", url);
    }

    /**
     * wap支付第二版
     */
    public void wap2() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
        params.put("mch_id", partner);
        params.put("body", "JFinal2.0极速开发");
        params.put("out_trade_no", "977773682111");
        params.put("total_fee", "1");

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = "127.0.0.1";
        }

        params.put("spbill_create_ip", ip);
        params.put("trade_type", TradeType.MWEB.name());
        params.put("nonce_str", System.currentTimeMillis() / 1000 + "");
        params.put("notify_url", notify_url);

        String sign = PaymentKit.createSign(params, paternerKey);
        params.put("sign", sign);
        String xmlResult = PaymentApi.pushOrder(params);

        System.out.println(xmlResult);
        Map<String, String> result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get("return_code");
        String return_msg = result.get("return_msg");
        if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
            renderText(return_msg);
            return;
        }
        String result_code = result.get("result_code");
        if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
            renderText(return_msg);
            return;
        }
        // 以下字段在return_code 和result_code都为SUCCESS的时候有返回
        String url = result.get("mweb_url");

        // 微信那边的开发建议用a标签打开该链接
        setAttr("url", url);
    }

    /*************************************输入车牌查询支付单支付功能*******************************************************/

    /**
     * 支付页面-入口.<br/>
     */
    public void selectCarView(){
        setAttr("openId",TLWXUser.getOpenId());
        setAttr("custId",TLWXUser.getCustId());
    	this.render("select.html");
    }

    /**
     * 查看支付单错误.<br/>
     */
    @Clear(BindInterceptor.class)
    public void queryOrderCheckErrorView(){
    	String carNum = this.getPara("carNum");
    	this.setAttr("carNum", carNum);
    	this.render("checkerror.html");
    }

    /**
     * 查询历史支付车牌号.<br/>
     * 步骤:根据个人cust_id 查询历史订单中最近的3个车牌号.<br/>
     */
    public void queryHistoryCarNum(){
        BizResult<List<String>> result = new BizResult<List<String>>();
        OrderService orderService = Duang.duang(OrderService.class);
        List<String>  list = new ArrayList<String>();
        String custId = this.getPara("personCustId");
        try{
            if(StringKit.isNotBlank(custId)){
                list = orderService.queryHistoryCarNum(custId);
            }else{
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }
        }catch (Exception e) {
            e.printStackTrace();
        }

        result.setData(list);


        this.renderJson(result);
    }

    /**
     * 根据车牌号查询待支付的停车订单.<br/>
     */
    public void queryOrderInfoView(){
        String carNum = this.getPara("carNum");
        this.getRequest().setAttribute("carNum", carNum);
        this.render("check.html");
    }
    /**
     * 检查输入的车牌号是否存订单(带核算/待支付/已完成).<br/>
     */
    public void parkOrderForNotPayExist(){
        BizResult<Order> result = new BizResult<>();
        String carNum = this.getPara("carNum");
        logger.info("开始校验输入车牌是否存在待核算订单..入参="+carNum);
        String rs ="";
        OrderVO OrderVO = new OrderVO();
        try{
            if(StringKit.isNotBlank(carNum)){
                OrderService orderService = Duang.duang(OrderService.class);
                IRainQueryService iRainQueryService = Duang.duang(IRainQueryService.class);
                /**查询待核算支付单信息.*/
                Order order = orderService.findOrderByCarNum(carNum);
                if(order != null && StringKit.isNotBlank(order.getOrderId())){
                    result.setData(order);
                    /**调用艾润查询费用接口.*/
                    rs = iRainQueryService.billQuery(carNum, order.getParkId());
                }else{
                    result.setErrorMessage(ErrorType.NO_PARKING_MSG, "无停车记录");
                }
            }else{
                logger.info("入参为空!");
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }
            if(StringKit.isNotBlank(rs)){
                if("NO_PARK_RECORD".equals(JSONObject.parseObject(rs).get("code"))){
                    result.setErrorMessage(ErrorType.NO_PARKING_MSG, "无停车记录");
                    this.renderJson(result);
                    return ;
                }
            }else{
                result.setErrorMessage(ErrorType.NO_PARKING_MSG, "无停车记录");
                this.renderJson(result);
                return ;
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        logger.info("结束校验输入车牌是否存在待核算订单..响应="+JSONObject.toJSONString(result));
        this.renderJson(result);

    }
    /**
     * 查询待支付的停车订单.<br/>
     * 步骤二:
     * 1.查询待支付的订单
     * 1.调用艾润接口查询费用.<br/>
     * 3.更新订单费用.<br/>
     * 4.更新订单明细费用.<br/>
     * 5.插入订单流水表.
     */
    public void  queryParkOrderForNotPay(){
        logger.info("开始查询待支付的停车订单WeixinPayController.queryParkOrderForNotPay()方法.");
        BizResult<OrderVO> result = new BizResult<OrderVO>();
        String carNum = this.getPara("carNum");
        OrderService orderService = Duang.duang(OrderService.class);
        OrderVO orderVO = new OrderVO();
        try{
            orderVO = orderService.queryParkOrderForNotPay(carNum);
            if(orderVO != null && StringKit.isNotBlank(orderVO.getOrderId())){
                /**根据停车场编码查询通知艾润停车场编码.*/
                result.setData(orderVO);
            }else{
                result.setErrorMessage(ErrorType.SYSTEM_ERROR, "业务错误");
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        this.renderJson(result);
    }


    public void paySuccessView(){
        String money = getPara("payMoney");
        setAttr("payMoney",money);
        render("paysuccess.html");
    }

    public static void main(String[] args) {
        Date date = new Date();
        System.out.println("now date :" + DateUtil.format(date, "yyyy-MM-dd"));
        Date newDate = DateUtil.offset(date, DateField.YEAR, 10);
        System.out.println("offset year date :" + DateUtil.format(newDate, "yyyy-MM-dd"));
        newDate = DateUtil.offset(date, DateField.MONTH, 10);
        System.out.println("offset month date :" + DateUtil.format(newDate, "yyyy-MM-dd"));
    }




}