package com.ssm.core.util;

import cn.hutool.core.text.StrBuilder;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.ssm.core.utils.AESUtils;
import com.ssm.core.utils.BeiSenResponse;
import com.ssm.manage.entity.RefundOrderList;
import com.ssm.manage.entity.SmsMessages;
import com.ssm.manage.excelEntity.ExcelCourseMoney;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import javax.xml.transform.Source;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;


public class Http {



//    public static void main(String[] args) throws Exception{
//        HttpClient httpClient = HttpClients.createDefault();
//        HttpPost httpPost = new HttpPost("https://api.4321.sh/sms/send");
//        httpPost.addHeader("Content-Type","application/json");
//        Map<String,Object> map = new HashMap<>();
//        map.put("apikey","N714828db9");
//        map.put("secret","71482cf8d1725360");
//        map.put("sign_id","141506");
//        map.put("mobile","13169783923");
//        map.put("content","短信内容");
//        String json = JSON.toJSONString(map);
//        httpPost.setEntity(new StringEntity(json,"UTF-8"));
//        HttpResponse response = httpClient.execute(httpPost);
//        HttpEntity entity = response.getEntity();
//        String res = EntityUtils.toString(entity);
//        System.out.println(res);
//    }

//    public static void main(String[] args) {
//        //1、创建一个文件对象
//        File excelFile = new File("C:\\Users\\Administrator\\Downloads/订单表.xlsx");
//        //2、判断文件是否存在，不存在则创建一个Excel文件
//        if (!excelFile.exists()) {
//            try {
//                excelFile.createNewFile();//创建一个新的文件
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        //3、指定需要那个class去写。然后写到第一个sheet，名字为模版，然后文件流会自动关闭
//        EasyExcel.write(excelFile, ExcelCourseMoney.class).sheet("订单模版").doWrite(data());
//    }
//
//    public static List<ExcelCourseMoney> data(){
//        //创建一个List集合 LC JZ NT A
//        List ExcelCourseMoney = new ArrayList<>();
//
//        /*
//         *xls版本的Excel最多一次可写0 ...65535行
//         * xlsx 版本的Excel最多一次可写0...1048575行
//         */
//        //超出报异常：java.lang.IllegalArgumentException: Invalid row number (65536) outside allowable range (0..65535)
//        for (int i=0;i<65535;i++){
//            ExcelCourseMoney data = new ExcelCourseMoney();
//            data.setStartTime("20220224"+(i+1));
//            data.setEndTime("商品名称"+i);
//            data.setStoreName("45"+i);
//            data.setOpenning(BigDecimal.ZERO);
//            data.setBalance(BigDecimal.ZERO);
//            data.setCourseMoney(BigDecimal.ZERO);
//            data.setCourseRepay(BigDecimal.ZERO);
//            data.setCashRefund(BigDecimal.ZERO);
//            data.setCoursePromotion(BigDecimal.ZERO);
//            data.setInit(BigDecimal.ZERO);
//            data.setCourseTurnStore(BigDecimal.ZERO);
//            data.setCardChange(BigDecimal.ZERO);
//            data.setCourseRepayMoney(BigDecimal.ZERO);
//            data.setCashMoney(BigDecimal.ZERO);
//            data.setCourseRefundMoney(BigDecimal.ZERO);
//            data.setCourseTurnCharge(BigDecimal.ZERO);
//            data.setCourseTurnStoreMoney(BigDecimal.ZERO);
//            ExcelCourseMoney.add(data);
//        }
//
//        return ExcelCourseMoney;//返回list集合
//    }

    public static void main(String[] args) throws Exception {
        System.out.println(new SnowflakeUtil(1023));
        String email = "0000000001@qq.com";
        String substring = email.substring(0, 10);
        System.out.println(substring);
        int parseInt = Integer.parseInt(substring);
        System.out.println(parseInt);
//        Long lojj = 462349002668224512L;
//        LocalDate today = LocalDate.now();
//
//        // 获取昨天的日期
//        LocalDate yesterday = today.minusDays(1);
//        String time = yesterday.toString();
//        String starttime = time+" 00:00:00";
//        String endtime = time+" 23:59:59";
//        // 打印结果
//        System.out.println("今天的日期: " + starttime);
//        System.out.println("昨天的日期: " + endtime);
//        String stfikj = "w0001";
//        String substring1 = stfikj.substring(1);
//
//        String res= "{\n" +
//                "\t\"access_token\": \"X4eTEiMr-8gOE0yuGgrbzDoHLgAPjsbIqNkJ-AxejxHoHml-Iz0oEEe9zvFJ2I60-jfw3j7bc\",\n" +
//                "\t\"token_type\": \"bearer\",\n" +
//                "\t\"expires_in\": 7200,\n" +
//                "\t\"refresh_token\": \"Z0HaROZY-Fi1zWmOarWVfyFoifLWb-V-eKwafhZbw6KBsog-dF6S3iv30LClJ8MCYXh1hhNO9\"\n" +
//                "}";
//        BeiSenResponse beiSenResponse = JSON.parseObject(res,BeiSenResponse.class);
//        System.out.println("beiSenResponse = " + beiSenResponse);
//        String property = System.getProperty("user.dir");
//        System.out.println(property);
//        String ste = "http:ss%s";
//        String rrrr = String.format(ste, "rrrr");
//        System.out.println(rrrr);
//        String errorMessage = SmsMessages.Fields.errorMessage;
//        System.out.println(errorMessage);
//        long timestamp = 1698810670000L;
//        Instant instant = Instant.ofEpochMilli(timestamp);
//        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
//        System.out.println(localDateTime.toString());
//        int cc = 10000;
//        int bb = 10000;
//        System.out.println(cc==bb);
//        String num = "20230919002";
//        int i1 = Integer.parseInt(num.substring(8));
//        System.out.println(i1 + 1);
//        String s2 = JSON.toJSONString("{type: 1,memberId: 415976925485662208,memberName: 温竣翔,mobilePhone: 13751714617,compensation: 0,refundType: ,refundAccount: null,refundReason: ,refundNumber:1,sourceDocNum: 0120230907002,payee: ,refundMoney: 0,courseListRequest: [{mobilePhone:13751714617,memberName:温竣翔,memberId:415976925485662208,courseProjectName:结业门店转卡消耗美容疗程代码,courseCompensation:0,manageStaffName:,refundNumber:1,courseRefundMoney:0,debtMoney:null,kaiKaDate:null,anotherName:null,entities:[],salesmanList:null,courseAccountId:417828171493376000,storeId:369234373443874816,storeName:总店,courseNum:0120230907002,courseProjectId:370516178726032323,courseProjectNum:11000003,courseProjectMoney:0,courseCount:1,courseStandardCount:1,courseStandardMoney:0,courseRestCount:1,courseConsumeCount:1,courseType:2,endTime:null,updateBy:null,updateId:null,updateTime:null,price:0,courseRestPrice:0,courseConsumePrice:0,storeNum:null,courseProjectMoneys:0,courseCounts:1,unrecordedNumber:null,unrecordedAmount:0,promotionDocId:417828057518047232,cancelMoney:0,cancelNum:null,expenditureMoney:null,explainModify:null,salesmens:[],staffLists:[{id:370759919093182464,staffName:周文娟,brandNumber:903,identityCard:null,ratio:100},{ratio:0}]}, {mobilePhone: 13751714617,memberName: 温竣翔,memberId:415976925485662208,courseProjectName: T-健康养生洗,courseCompensation: 0,manageStaffName: ,refundNumber: 10,courseRefundMoney: 980,debtMoney: null,kaiKaDate: null,anotherName: null,entities: [],salesmanList: null,courseAccountId: 417828057672327168,storeId: 369234373443874816,storeName: 总店,courseNum: 0120230907002,courseProjectId: 370516522705096861,courseProjectNum: 30500001,courseProjectMoney: 980,courseCount: 10,courseStandardCount: 10,courseStandardMoney: 980,courseRestCount: 10,courseConsumeCount: 10,courseType: 1,endTime: null,updateBy: null,updateId: null,updateTime: null,price: 98,courseRestPrice: 980,courseConsumePrice: 980,storeNum: null,courseProjectMoneys: 980,courseCounts: 10,unrecordedNumber: null,unrecordedAmount: 0,promotionDocId: 417828057518047232,cancelMoney: 0,cancelNum: null,expenditureMoney: null,explainModify: null,salesmens: [],staffLists: [{staffName: ,brandNumber: ,ratio: 100}]}]}");
//        System.out.println("s2 = " + s2);
//        // \u000d System.out.println("coder Hydra");
//        //\u000d\u0054\u0068\u0072\u0065\u0061\u0064\u002e\u0073\u006c\u0065\u0065\u0070\u0028\u0032\u0030\u0030\u0030\u0029\u003b
//        Float f = 0.01F;
//        Double d = 0.01D;
//        Double a = f.doubleValue();
//        System.out.println(a);
//        System.out.println(BigDecimal.valueOf(f));
//        System.out.println(BigDecimal.valueOf(d));
//        System.out.println(f);//0.01
//        System.out.println(d);//0.01
//        BigDecimal bigDecimal1 = new BigDecimal(f);
//        BigDecimal bigDecimal2 = new BigDecimal(Float.toString(f));
//        BigDecimal bigDecimal3 = new BigDecimal(d);
//        BigDecimal bigDecimal4 = new BigDecimal(Double.toString(d));
//        System.out.println(bigDecimal1);//0.00999999977648258209228515625
//        System.out.println(bigDecimal1.floatValue());//0.01
//        System.out.println(bigDecimal2);//0.01
//        System.out.println(bigDecimal3);//0.01000000000000000020816681711721685132943093776702880859375
//        System.out.println(bigDecimal3.doubleValue());//0.01
//        System.out.println(bigDecimal4);//0.01
//
//        System.out.println(AESUtils.decrypt("7ea529d4b30354d7875b73d41631fd55"));
///**
// * 尊敬的.{}会员：您本次消费.{}次，消费赠送.{}次，剩余.{}次，剩余赠送.{}次。欢迎您再次莅临！本店的联系电话.{}客服热线：18620905828
// */
//
///**
// * 现金消费
// * "尊敬的"+memberName+"会员：您本次消费【"+projectName+"】【" +projectTime+
// * 						"】次。欢迎您再次莅临！客服热线：18620905828";
// */
///**
// * 充值卡消费
// *
// * "尊敬的"+memberName+"会员：您本次消费折后金额"+ (spendMoney.add(giftspendMoney)).setScale(2,BigDecimal.ROUND_HALF_UP) +"元，" +
// * 							"使用赠送金额"+giftspendMoney.setScale(2,BigDecimal.ROUND_HALF_UP)+"元"+
// * 							"，会员卡内余额"+ restMoney.setScale(2,BigDecimal.ROUND_HALF_UP) +"元。赠送卡内余额"+giftRestMoney.setScale(2,BigDecimal.ROUND_HALF_UP)+
// * 							"元。欢迎您再次莅临！客服热线：18620905828";
// */
///**
// * 购买疗程
// * "【"+courseList.getProjectName()+"】次数"+courseList.getNumberTimes()+"次，赠送次数0次。"
// * "尊敬的"+memberName+"会员：您本次购买" + projectName + "欢迎您再次莅临！客服热线：18620905828";
// */
//
///**
// * 充值开卡
// * "尊敬的"+rechargeAccount.getMemberName()+"会员：您本次充值金额为【"+rechargeMoney.setScale(2,BigDecimal.ROUND_HALF_UP)+"】" +
// * 						"元，赠送金额为【"+gifMoney.setScale(2,BigDecimal.ROUND_HALF_UP)+"】元，会员卡余额为【"
// * 						+rechargeAccount.getCardRestMoney().setScale(2,BigDecimal.ROUND_HALF_UP)+"】元" +
// * 						"，赠送余额为【"+rechargeAccount.getCardGiftMoney()+"】元。欢迎您再次莅临！客服热线：18620905828";
// */
//        //
//
//
//
//        String profix = "尊敬的${memberName}会员：您本次消费${numberTime}次，消费赠送${giftTime}次，" +
//                "剩余${remainderTime}次，剩余赠送${remainderGiftTime}次。欢迎您再次莅临！本店的联系电话${storePhone}";
//        String memberName = "陆秀冲";
//        String numberTime = String.valueOf(2);
//        String giftTime = String.valueOf(0);
//        String remainderTime = String.valueOf(8);
//        String remainderGiftTime = String.valueOf(0);
//        String storePhone = "15913619401";
//        Map<String,String> hash = new HashMap<>();
//        hash.put("memberName",memberName);
//        hash.put("numberTime",numberTime);
//        hash.put("giftTime",giftTime);
//        hash.put("remainderTime",remainderTime);
//        hash.put("remainderGiftTime",remainderGiftTime);
//        hash.put("storePhone",storePhone);
//        String s = smsReplace(hash, profix);
//        System.out.println("s = " + s);
//
//        String postfix = "尊敬的${memberName}会员：您本次消费${numberTime}次，" +
//                "剩余${remainderTime}次。欢迎您再次莅临！本店的联系电话${storePhone}客服热线：18620905828";
//        String s1 = smsReplace(hash, postfix);
//        System.out.println("s1 = " + s1);
//
//        //尊敬的陆秀冲会员：您本次消费2次，消费赠送0次，剩余8次，剩余赠送0次。欢迎您再次莅临！本店的联系电话15913619401客服热线：18620905828
//
//        //尊敬的陆秀冲会员：您本次消费2次，剩余8次。欢迎您再次莅临！本店的联系电话15913619401客服热线：18620905828
//
//
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(new Date());
//        calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH)-2);
//        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
//        String format = simpleDateFormat1.format(calendar.getTime());
//        System.out.println(format);
//        Date parse = simpleDateFormat1.parse(format);
//        calendar.setTime(parse);
//        calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DATE));
//        String format1 = simpleDateFormat1.format(calendar.getTime());
//        calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMinimum(Calendar.DATE));
//        String format2 = simpleDateFormat1.format(calendar.getTime());
//        System.out.println(format1+"-------"+format2);
//        format2 = format2 + " 00:00:00";
//        format1 = format1 + " 23:59:59";
//        System.out.println(format1+"-------"+format2);
//
//
//
//        System.out.println(parse);
//        System.out.println(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
//        String date = "202307";
//        int i = Integer.parseInt(date);
//        int x = i-1;
//        String newDate = String.valueOf(x);
//        System.out.println(date);
//        System.out.println(newDate);
//        Date date1 = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////        simpleDateFormat.
//        System.out.println(BigDecimal.valueOf(5));
//        System.out.println(BigDecimal.valueOf(Double.valueOf(5)));
//
////        int i ;
////        while (true){
////            i = 1;
////            i = 2;
////            System.out.println(i);
////            if(i==1){
////                System.out.println(i);
////                break;
////            }
////        }
//        List<Integer> list = new ArrayList<>();
//        list.add(1);
//        list.add(2);
//        list.add(3);
//        list.add(4);
//        list.add(5);
//        boolean b = list.stream().anyMatch(item -> {
//            System.out.println(item);
//            return item > 3;
//        });
//        System.out.println(new BigDecimal(0.1));
//        System.out.println(new BigDecimal("0.1"));
//        System.out.println(AESUtils.decrypt("7ea529d4b30354d7875b73d41631fd55"));
////        System.out.println(new BigDecimal("1").add(null));
//        String docNum = "LCA00120230426001";
//        System.out.println(docNum.length());
//        System.out.println(docNum.substring(docNum.length() - 11, docNum.length() - 3));
//        RefundOrderList refundOrderList = new RefundOrderList();
//        refundOrderList.setStoreNum("A128");
//        System.out.println(refundOrderList.getStoreNum().length());
//        System.out.println(docNum.substring(11+refundOrderList.getStoreNum().length()));
//       int mm = Integer.parseInt(docNum.substring(11+refundOrderList.getStoreNum().length())) + 1;
//        System.out.println(mm);
////        String decrypt = AESUtils.decrypt("19128280160");
////        String encrypt = AESUtils.encrypt("19128280160");
////        System.out.println(encrypt);
//        //LCA001 20230325 001
//        //ZLCA001 20230325 001
//        //LC001 20230325 001
//        //ALC001 202325 001
////        docNum.su
////        ssmCourseService.selectOne()
//        String substring = docNum.substring(docNum.length()-11, docNum.length() - 3);
//        System.out.println(substring);
//        StrBuilder strBuilder = new StrBuilder(substring);
//        StrBuilder insert = strBuilder.insert(6, "-").insert(4, "-");
//        System.out.println(insert);
////        String date = "9430-07-11";
////        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
////        Date parse = simpleDateFormat.parse(date);
////        String format = simpleDateFormat.format(parse);
////        System.out.println(parse);
////        System.out.println(format);
////        Date parse1 = (Date) JSON.parse(date);
////        System.out.println(parse1);
////        int yyyy = 2023;
////        int date = 3;
////        Date date1 = new Date();
////        System.out.println(date1);
////        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
////        String format = simpleDateFormat.format(date1);
////        System.out.println(format);
////        try {
////            Date parse = simpleDateFormat.parse(yyyy+"-0"+date);
////        String date = "2022-06";
////        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
////        try {
////            Date parse = simpleDateFormat.parse(date);
////            System.out.println(parse.before(new Date()));
////        } catch (ParseException e) {
////            e.printStackTrace();
////        }
    }

    private static String smsReplace(Map<String, String> hash, String postfix) {
        String replace = postfix.replace("${memberName}", hash.get("memberName"));
        String replace1 = replace.replace("${courseName}", hash.get("courseName"));
        String replace2 = replace1.replace("${courseNumberTime}", hash.get("courseNumberTime"));
        String replace3 = replace2.replace("${courseGiftNumberTime}", hash.get("courseGiftNumberTime"));
        String replace4 = replace3.replace("${courseReaminderTime}", hash.get("courseReaminderTime"));
        String replace5 = replace4.replace("${courseReaminderGiftTime}", hash.get("courseReaminderGiftTime"));
        String replace6 = replace5.replace("${rechargeMoney}", hash.get("rechargeMoney"));
        String replace7 = replace6.replace("${rechargeGiftMoney}", hash.get("rechargeGiftMoney"));
        String replace8 = replace7.replace("${rechargeRestMoney}", hash.get("rechargeRestMoney"));
        String replace9 = replace8.replace("${rechargeGiftRestMoney}", hash.get("rechargeGiftMoney"));
        String replace10 = replace9.replace("${projectName}", hash.get("projectName"));
        String replace11 = replace10.replace("${projectTime}", hash.get("projectTime"));
        String replace12 = replace11.replace("${rechargeCashMoney}", hash.get("rechargeCashMoney"));
        String replace13 = replace12.replace("${rechargeSpendGeneralMoney}", hash.get("rechargeSpendGeneralMoney"));
        String replace14 = replace13.replace("${rechargeSpendGiftMoney}", hash.get("rechargeSpendGiftMoney"));
        String replace15 = replace14.replace("${courseCashTime}", hash.get("courseCashTime"));
        String replace16 = replace15.replace("${courseGiftCashTime}", hash.get("courseGiftCashTime"));
        String replace17 = replace16.replace("${storePhone}", hash.get("storePhone"));
        String replace18 = replace17.replace("${customerPhone}", hash.get("customerPhone"));
        return replace18;
    }

}
