package cn.pluss.platform.klk.service;

import cn.hutool.core.util.ObjectUtil;
import cn.pluss.platform.api.ResultCode;
import cn.pluss.platform.constants.Constant;
import cn.pluss.platform.dto.MemberScanPayDTO;
import cn.pluss.platform.dto.MerChantOrderDTO;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.klk.LakalaConfig;
import cn.pluss.platform.klk.service.impl.LaKalaInterfaceImpl;
import cn.pluss.platform.mapper.MerchantBackLklMapper;
import cn.pluss.platform.mapper.MerchantBaseInfoMapper;
import cn.pluss.platform.merchantOrder.MerchantOrderService;
import cn.pluss.platform.pay.PayService;
import cn.pluss.platform.util.DateUtils;
import cn.pluss.platform.util.ParametersUtil;
import cn.pluss.platform.util.StringUtil;
import cn.pluss.platform.ys.YsConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service("lkLPayService")
@Slf4j
public class LkLPayServiceImpl implements PayService {
    @Resource
    LklPayService lklPayService;

    @Autowired
    MerchantBackLklMapper merchantBackLklMapper;


    @Autowired
    LakalaConfig lakalaConfig;

    @Autowired
    MerchantBaseInfoMapper merchantBaseInfoMapper;

    @Override
    public JSONObject tradePay(MerchantOrder order, MerchantChannelStatus channel, MerchantBaseInfo merchant) {

        String account_type = "WECHAT";
        if (StringUtil.isNotEmpty(order.getScanType()) && "01".equals(order.getScanType())) {
            account_type = "wechatPay".equals(order.getPayTypeCode()) ? "WECHAT" : "aliPay".equals(order.getPayTypeCode()) ? "ALIPAY" : "UQRCODEPAY";
        } else {
            account_type = "wechatPay".equals(order.getPayTypeCode()) ? "WECHAT" : "aliPay".equals(order.getPayTypeCode()) ? "ALIPAY" : "UQRCODEPAY";
        }

        String transType = account_type.equals("WECHAT") ? "71" : account_type.equals("ALIPAY") ? "41" : "51";

        QueryWrapper<MerchantBackLkl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("merchant_code", merchant.getMerchantCode());
        queryWrapper.eq("channel", "5");
        queryWrapper.eq("user_no", LaKalaInterfaceImpl.userNo);

        MerchantBackLkl merchantBackLkl = merchantBackLklMapper.selectOne(queryWrapper);
        MsgException.checkNull(merchantBackLkl, "渠道信息异常");


        String req_time = DateUtils.getSdfTimes();

        Long order_amt = changeY2F(order.getConsumeFee());
        String body = null;
        if (account_type.equals("WECHAT")) {

            if(ObjectUtil.isEmpty(order.getAppletsAppid())){
                order.setAppletsAppid(ParametersUtil.APPLETS_APPID);
            }


            body="{\n" +
                    "\t\"out_org_code\": \""+lakalaConfig.getAppid()+"\",\n" +
                    "\t\"req_data\": {\n" +
                    "\t\t\"acc_busi_fields\": {\n" +
                    "\t\t\t\"user_id\": \""+order.getMercUserId()+"\",\n" +
                    "\t\t\t\"sub_appid\": \""+order.getAppletsAppid()+"\"\n" +
                    "\t\t},\n" +
                    "\t\t\"account_type\": \""+account_type+"\",\n" +
                    "\t\t\"location_info\": {\n" +
                    "\t\t\t\"request_ip\": \""+order.getIp()+"\"\n" +
                    "\t\t},\n" +
                    "\t\t\"merchant_no\": \""+merchantBackLkl.getExternalCustomerNo()+"\",\n" +
                    "\t\t\"notify_url\": \""+lakalaConfig.getCallBackUrl()+"\",\n" +
                    "\t\t\"out_trade_no\": \""+order.getOrderNumber()+"\",\n" +
                    "\t\t\"term_no\": \""+merchantBackLkl.getTermNos()+"\",\n" +
                    "\t\t\"total_amount\": \""+order_amt+"\",\n" +
                    "\t\t\"trans_type\": \""+transType+"\"\n" +
                    "\t},\n" +
                    "\t\"req_time\": \""+req_time+"\",\n" +
                    "\t\"version\": \"3.0\"\n" +
                    "}";

        }

        if (account_type.equals("ALIPAY")) {
            body = "{\n" +
                    "\t\"out_org_code\": \"" + lakalaConfig.getAppid() + "\",\n" +
                    "\t\"req_data\": {\n" +
                    "\t\t\"account_type\": \"" + account_type + "\",\n" +
                    "\t\t\"location_info\": {\n" +
                    "\t\t\t\"request_ip\": \"" + order.getIp() + "\"\n" +
                    "\t\t},\n" +
                    "\t\t\"merchant_no\": \"" + merchantBackLkl.getExternalCustomerNo() + "\",\n" +
                    "\t\t\"notify_url\": \"" + lakalaConfig.getCallBackUrl() + "\",\n" +
                    "\t\t\"out_trade_no\": \"" + order.getOrderNumber() + "\",\n" +
                    "\t\t\"term_no\": \"" + merchantBackLkl.getTermNos() + "\",\n" +
                    "\t\t\"total_amount\": \"" + order_amt + "\",\n" +
                    "\t\t\"trans_type\": \"" + transType + "\"\n" +
                    "\t},\n" +
                    "\t\"req_time\": \"" + req_time + "\",\n" +
                    "\t\"version\": \"3.0\"\n" +
                    "}";
        }


            String response = lklPayService.req(body, "api/v3/labs/trans/preorder");

        JSONObject resp = new JSONObject();
        if (ObjectUtil.isNotEmpty(response)) {
            JSONObject payData = new JSONObject();
            JSONObject object = JSONObject.parseObject(response);

            if (object.containsKey("code") && "BBS00000".equals(object.getString("code"))) {
                if (!(StringUtil.isNotEmpty(order.getScanType()) && "01".equals(order.getScanType()))) {
                    JSONObject acc_resp_fields = object.getJSONObject("resp_data").getJSONObject("acc_resp_fields");
                    if (Constant.PAY_TYPE_ALIPAY.equals(order.getPayTypeCode())) {
                        payData.put("source", acc_resp_fields.getString("code"));
                    } else if (Constant.PAY_TYPE_WECHAT.equals(order.getPayTypeCode())) {

                        payData.put("payAppId", acc_resp_fields.getString("app_id"));
                        payData.put("payTimeStamp", acc_resp_fields.getString("time_stamp"));
                        payData.put("paynonceStr", acc_resp_fields.getString("nonce_str"));
                        payData.put("payPackage", acc_resp_fields.getString("package"));
                        payData.put("paySignType", acc_resp_fields.getString("sign_type"));
                        payData.put("paySign", acc_resp_fields.getString("pay_sign"));
                    } else {
                        payData.put("redirectUrl", acc_resp_fields.containsKey("redirect_url") ? acc_resp_fields.getString("redirect_url") : null);
                    }

                } else {
                    payData.put("payUrl", object.get("code"));
                    payData.put("orderNumber", order.getOrderNumber());
                    payData.put("mercOrderNo", order.getMercOrderNo());
                }
                resp.put("code", ResultCode.SUCCESS.code());
                payData.put("channel", channel.getChannel());
                order.setTransNo((object.getJSONObject("resp_data").containsKey("log_no") && ObjectUtil.isNotEmpty(object.getJSONObject("resp_data").getString("log_no"))) ? object.getString("log_no") : "");
                resp.put("payData", payData);
                return resp;

            } else if (object.containsKey("code") && "BBS16270".equals(object.getString("code"))) {
                resp.put("code", ResultCode.FAIL.code());
                resp.put("msg", object.getString("msg"));
                return resp;
            }
        }


        resp.put("code", ResultCode.FAIL.code());
        resp.put("msg", "失败");
        return resp;

    }

    @Override
    public JSONObject tradePay(MerChantOrderDTO merchantOrderDTO, MerchantOrder order) {


        QueryWrapper<MerchantBaseInfo> baseQueyWrapper = new QueryWrapper<>();
        baseQueyWrapper.eq("merchantCode", merchantOrderDTO.getMerchantCode());
        MerchantBaseInfo baseInfo = merchantBaseInfoMapper.selectOne(baseQueyWrapper);
        MsgException.checkNull(baseInfo, "商户基本信息错误");


        QueryWrapper<MerchantBackLkl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("merchant_code", merchantOrderDTO.getMerchantCode());
        queryWrapper.eq("channel", "5");
        queryWrapper.eq("user_no", LaKalaInterfaceImpl.userNo);

        MerchantBackLkl merchantBackLkl = merchantBackLklMapper.selectOne(queryWrapper);
        MsgException.checkNull(merchantBackLkl, "进件信息不存在");


        JSONObject obj = new JSONObject(6);

        String req_time = DateUtils.getSdfTimes();
        Long order_amt = changeY2F(order.getConsumeFee());

        String body = "{\n" +
                "\t\"req_data\": {\n" +
                "\t\t\"merchant_no\": \"" + merchantBackLkl.getExternalCustomerNo() + "\",\n" +
                "\t\t\"term_no\": \"" + merchantBackLkl.getTermNos() + "\",\n" +
                "\t\t\"out_trade_no\": \"" + order.getOrderNumber() + "\",\n" +
                "\t\t\"total_amount\": \"" + order_amt + "\",\n" +
                "\t\t\"subject\": \"" + baseInfo.getMccName() + "\",\n" +
                "\t\t\"acc_busi_fields\": {},\n" +
                "\t\t\"notify_url\": \"" + lakalaConfig.getCallBackUrl() + "\",\n" +
                "\t\t\"location_info\": {\n" +
                "\t\t\t\"request_ip\": \"" + order.getIp() + "\"\n" +
                "\t\t},\n" +
                "\t\t\"auth_code\": \"" + merchantOrderDTO.getAuthCode() + "\"\n" +
                "\t},\n" +
                "\t\"out_org_code\": \"" + lakalaConfig.getAppid() + "\",\n" +
                "\t\"version\": \"3.0\",\n" +
                "\t\"req_time\": " + req_time + "\n" +
                "}";


        String response = lklPayService.req(body, "api/v3/labs/trans/micropay");
        if (ObjectUtil.isNotEmpty(response)) {
            JSONObject object = JSON.parseObject(response);
            if (object.containsKey("code") && "BBS10000".equals(object.get("code"))) {
                obj.put("code", ResultCode.TRANSUNKNOW.code());
                obj.put("msg", "用户支付中");
                obj.put("channelOrderNo", object.getJSONObject("resp_data").get("trade_no"));
                obj.put("transNo", object.getJSONObject("resp_data").get("log_no"));
                obj.put("payStatus", "7");
                return obj;
            } else if (object.containsKey("code") && "BBS00000".equals(object.get("code"))) {
                obj.put("code", ResultCode.SUCCESS.code());
                obj.put("msg", "成功");
                obj.put("channelOrderNo", object.getJSONObject("resp_data").get("trade_no"));
                obj.put("transNo", object.getJSONObject("resp_data").get("log_no"));
                obj.put("payStatus", "1");
                obj.put("payTime", DateUtils.convertDate(object.getJSONObject("resp_data").getString("trade_time")));
                return obj;
            } else {
                obj.put("code", ResultCode.FAIL.code());
                obj.put("msg", object.get("msg"));
                return obj;
            }
        }
        obj.put("code", ResultCode.FAIL.code());
        obj.put("msg", "失败");
        return obj;
    }

    @Override
    public Map<String, Object> refundPay(MerchantOrder order, String mchNo) {

        QueryWrapper<MerchantBaseInfo> baseQueyWrapper = new QueryWrapper<>();
        baseQueyWrapper.eq("merchantCode", mchNo);
        MerchantBaseInfo baseInfo = merchantBaseInfoMapper.selectOne(baseQueyWrapper);
        MsgException.checkNull(baseInfo, "商户基本信息错误");


        QueryWrapper<MerchantBackLkl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("merchant_code", mchNo);
        queryWrapper.eq("channel", "5");
        queryWrapper.eq("user_no", LaKalaInterfaceImpl.userNo);

        MerchantBackLkl merchantBackLkl = merchantBackLklMapper.selectOne(queryWrapper);
        MsgException.checkNull(merchantBackLkl, "商户信息不存在");



        String req_time = DateUtils.getSdfTimes();

        Long order_amt = 0L;
        if(ObjectUtil.isNotEmpty(order.getPayReturnAmount())){
            order_amt=  changeY2F(order.getPayReturnAmount().doubleValue());
        } else if(StringUtil.isNotEmpty(order.getRefundType()) && order.getRefundType() == 2 ){
            order_amt=  changeY2F(order.getRefundAmt().doubleValue());
        } else {
            order_amt=  changeY2F(order.getConsumeFee().doubleValue());
        }


        String refundNo = "LKLR" + StringUtil.getBillno();

        String body="{\n" +
                " \"req_time\":\""+req_time+"\",\n" +
                " \"version\":\"3.0\",\n" +
                " \"out_org_code\":\""+lakalaConfig.getAppid()+"\",\n" +
                " \"req_data\":{\n" +
                "  \"merchant_no\":\""+merchantBackLkl.getExternalCustomerNo()+"\",\n" +
                "  \"term_no\":\""+merchantBackLkl.getTermNos()+"\",\n" +
                "  \"out_trade_no\":\""+refundNo+"\",\n" +
                "  \"refund_amount\":\""+order_amt+"\",\n" +
                "  \"refund_reason\":\"退款\",\n" +
                "  \"origin_out_trade_no\":\""+order.getOrderNumber()+"\",\n" +
                "  \"location_info\":{\n" +
                "   \"request_ip\":\""+order.getIp()+"\",\n" +
                "   \"location\":\"+37.123456789,-121.123456789\"\n" +
                "  }\n" +
                " }\n" +
                "}\n" +
                "\n";

        Map<String, Object> result = new HashMap<>(4);
        result.put("refundNo", refundNo);
        result.put("status", "3");
        result.put("code", ResultCode.FAIL.code());


        String response = lklPayService.req(body, "api/v3/labs/relation/refund");
        if(ObjectUtil.isNotEmpty(response)){
            JSONObject object=JSONObject.parseObject(response);
            if(object.containsKey("code")&&"BBS00000".equals(object.getString("code"))){
                result.put("msg", "退款成功！");
                result.put("data", object.getJSONObject("resp_data"));
                result.put("status", "1");
                result.put("code", ResultCode.SUCCESS.code());
                return result;
            }else {
                result.put("msg", object.getString("msg"));
                return result;
            }
        }

        result.put("msg", "退款失败！");
        return result;
    }

    @Override
    public JSONObject tradeQuery(MerchantOrder order, String mchId) {

        QueryWrapper<MerchantBaseInfo> baseQueyWrapper = new QueryWrapper<>();
        baseQueyWrapper.eq("merchantCode", order.getMerchantCode());
        MerchantBaseInfo baseInfo = merchantBaseInfoMapper.selectOne(baseQueyWrapper);
        MsgException.checkNull(baseInfo, "商户基本信息错误");


        QueryWrapper<MerchantBackLkl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("merchant_code", order.getMerchantCode());
        queryWrapper.eq("channel", "5");
        queryWrapper.eq("user_no", LaKalaInterfaceImpl.userNo);

        MerchantBackLkl merchantBackLkl = merchantBackLklMapper.selectOne(queryWrapper);
        MsgException.checkNull(merchantBackLkl, "商户信息不存在");
        String req_time = DateUtils.getSdfTimes();
        Long order_amt = changeY2F(order.getConsumeFee());

        String body = "{\n" +
                "\"req_time\":\"" + req_time + "\",\n" +
                "\"version\":\"3.0\",\n" +
                "\"out_org_code\":\"" + lakalaConfig.getAppid() + "\",\n" +
                "\"req_data\":{\n" +
                "\"merchant_no\":\"" + merchantBackLkl.getExternalCustomerNo() + "\",\n" +
                "\"term_no\":\"" + merchantBackLkl.getTermNos() + "\",\n" +
                "\"out_trade_no\":\"" + order.getOrderNumber() + "\"\n" +
                "}\n" +
                "}\n";

        JSONObject result = new JSONObject();
        String response = lklPayService.req(body, "api/v3/labs/query/tradequery");
        if (ObjectUtil.isNotEmpty(response)) {
            JSONObject object = JSONObject.parseObject(response);
            if (object.containsKey("code") && "BBS00000".equals(object.getString("code"))) {

                JSONObject resp_data=object.getJSONObject("resp_data");
                String status=resp_data.getString("trade_state");
                switch (status){
                    case "INIT":
                        result.put("payStatus", "10");
                        break;
                    case "CREATE":
                        result.put("payStatus", "3");
                        break;
                    case "SUCCESS":
                        result.put("payStatus", "1");
                        break;
                    case "DEAL":
                        result.put("payStatus", "11");
                        break;
                    case "UNKNOWN":
                        result.put("payStatus", "12");
                        break;
                    case "CLOSE":
                        result.put("payStatus", "9");
                        break;
                    case "PART_REFUND":
                        result.put("payStatus", "13");
                        break;
                    case "REFUND":
                        result.put("payStatus", "14");
                        break;
                }
                result.put("channelOrderNo", resp_data.get("trade_no"));
                result.put("payTime", ObjectUtil.isNotEmpty(resp_data.getString("trade_time"))?DateUtils.parse(resp_data.getString("trade_time"), "yyyyMMddHHmmss"):new Date());
                result.put("transNo", resp_data.get("log_no"));
                result.put("code", ResultCode.SUCCESS.code());

                result.put("msg", "查询成功！");
                result.put("buyerId", resp_data.get("user_id1"));
                return result;
            } else {
                result.put("code", ResultCode.FAIL.code());
                result.put("msg", object.getString("msg"));
                return result;
            }
        }
        log.error("==============>【拉卡拉】交易订单查询失败<==================");
        result.put("code", ResultCode.FAIL.code());
        result.put("msg", "订单查询异常");
        return result;
    }

    @Override
    public JSONObject refundQuery(MerchantRefundOrder refundOrder) {

        QueryWrapper<MerchantBackLkl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("merchant_code", refundOrder.getMerchantCode());
        queryWrapper.eq("channel", "5");
        queryWrapper.eq("user_no", LaKalaInterfaceImpl.userNo);

        MerchantBackLkl merchantBackLkl = merchantBackLklMapper.selectOne(queryWrapper);
        MsgException.checkNull(merchantBackLkl, "商户信息不存在");

        String req_time = DateUtils.getSdfTimes();

        String body="{\n" +
                " \"req_time\":\""+req_time+"\",\n" +
                " \"version\":\"3.0\",\n" +
                " \"out_org_code\":\""+lakalaConfig.getAppid()+"\",\n" +
                " \"req_data\":{\n" +
                "  \"merchant_no\":\""+merchantBackLkl.getExternalCustomerNo()+"\",\n" +
                "  \"term_no\":\""+merchantBackLkl.getTermNos()+"\",\n" +
                "  \"out_refund_order_no\":\""+refundOrder.getRefundNo()+"\"\n" +
                " }\n" +
                "}\n" +
                "\n";

        JSONObject result = new JSONObject();
        String response = lklPayService.req(body, "api/v3/labs/query/idmrefundquery");
        if (ObjectUtil.isNotEmpty(response)) {
            JSONObject object = JSONObject.parseObject(response);
            if (object.containsKey("code") && "BBS00000".equals(object.getString("code"))) {
                result.put("refundTime", object.getString("trade_time"));
                result.put("code", ResultCode.SUCCESS.code());
                result.put("status", "1");
                result.put("msg", "查询成功！");
                return result;
            } else {
                result.put("code", ResultCode.FAIL.code());
                result.put("msg", object.getString("msg"));
                return result;
            }
        }
        log.error("==============>【拉卡拉】交易订单查询失败<==================");
        result.put("code", ResultCode.FAIL.code());
        result.put("msg", "退款订单查询异常");
        return result;
    }

    @Override
    public Map<String, Object> closeOrder(String orderNumber, String channelNo) {
        return null;
    }

    @Override
    public Map<String, Object> getWxOpenId(MemberScanPayDTO memberScanPayDTO, MerchantChannelStatus channel) throws Exception {
        return null;
    }

    @Override
    public Map<String, Object> getUnionInfo(String userAuthCode, String paymentApp, String merchantId) throws Exception {
        Map<String, Object> result = new HashMap<>();
        String req_time = DateUtils.getSdfTimes();

        QueryWrapper<MerchantBackLkl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("merchant_code", merchantId);
        queryWrapper.eq("channel", "5");
        MerchantBackLkl merchantBackLkl = merchantBackLklMapper.selectOne(queryWrapper);
        MsgException.checkNull(merchantBackLkl, "商户基本信息不完整");

        String body = "{\n" +
                "\"ver\":\"1.0.0\",\n" +
                "\"timestamp\":\"" + System.currentTimeMillis() + "\",\n" +
                "\"reqId\":\"" + req_time + "\",\n" +
                "\"reqData\":{\n" +
                "\"mercId\":\"" + merchantBackLkl.getExternalCustomerNo() + "\",\n" +
                "\"termNo\":\"" + merchantBackLkl.getTermNos() + "\",\n" +
                "\"authCode\":\"" + userAuthCode + "\",\n" +
                "\"tradeCode\":\"030304\"\n" +
                "}\n" +
                "}\n";
        String response = lklPayService.req(body, "api/v2/saas/query/wx_openid_query");
        if (ObjectUtil.isNotEmpty(response)) {
            JSONObject object = JSONObject.parseObject(response);
            if (object.containsKey("retCode") && "BBS00000".equals(object.getString("retCode"))) {

                JSONObject reqData = new JSONObject(2);
                reqData.put("data", object.getJSONObject("respData").getString("openId"));
                reqData.put("userAuthCode", userAuthCode);
                reqData.put("appUpIdentifier", paymentApp);
                result.put("data", reqData);
                result.put("code", "1");
                result.put("msg", "获取成功");
            }
        }
        result.put("code","0");
        result.put("msg", "获取失败");
        return result;
    }


    @Setter(onMethod_ = {@Autowired, @Lazy})
    private MerchantOrderService merchantOrderService;

    @Override
    public Object payNotifyCallBack(Map<String, String> params) {

        Map<String, String> result = new HashMap<>(2);
        result.put("code", "fail");
        result.put("msg", "失败");

        String trade_no = params.get("trade_no");
        String ordNo = params.get("out_trade_no");

        String acc_trade_no = params.get("acc_trade_no");

        String payTime = params.get("trade_time");

        String bizCode = params.get("trade_status");

        String buyerId = params.get("user_id1");
        if ("SUCCESS".equals(bizCode)) {
            QueryWrapper<MerchantOrder> queryWrapper = new QueryWrapper<MerchantOrder>().eq("orderNumber", ordNo);

            MerchantOrder order = merchantOrderService.getOne(queryWrapper);
            if (order == null) {
                log.error("====================>【拉卡拉】支付成功回调订单号查询，查询的订单为空：订单号：{}<====================", ordNo);
                return YsConfig.RESULT_SUCCESS_CODE;
            }
            Date payDate = DateUtils.parse(payTime, "yyyyMMddHHmmss");
            order.setTransDt(payDate);
            order.setTransNo(trade_no);
            order.setThirdTransNo(acc_trade_no);
            merchantOrderService.updateOrderAndCreateProfit(order);
            result.put("code", "success");
            result.put("msg", "成功");
            return result;

        }


        return null;
    }

    @Override
    public String tradePayWap(MerchantOrder order, MerchantChannelStatus channel) {
        return null;
    }

    @Override
    public JSONObject getUnionAccountUrl(JSONObject reqData) {
        return null;
    }

    @Override
    public JSONObject jftPay(JftReceiptOrder order, JftMercBaseInfo jftMerc, JftMercPaymentChannel jftChannel) {
        return null;
    }



    private static long changeY2F(double price) {
        DecimalFormat df = new DecimalFormat("#.00");
        price = Double.valueOf(df.format(price));
        long money = (long)(price * 100);
        return money;
    }

    public static void main(String[] args){
        System.out.println(changeY2F(3d));
    }
}
