package cn.van.business.util;


import cn.van.business.model.jd.OrderRow;
import cn.van.business.repository.OrderRowRepository;
import com.alibaba.fastjson2.util.DateUtils;
import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.domain.kplunion.OrderService.request.query.OrderRowReq;
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.OrderRowResp;
import com.jd.open.api.sdk.request.kplunion.UnionOpenOrderRowQueryRequest;
import com.jd.open.api.sdk.response.kplunion.UnionOpenOrderRowQueryResponse;
import lombok.Getter;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Leo
 * @version 1.0
 * @create 2024/11/5 17:40
 * @description：
 */
@Component
public class JDUtils {
    /**
     * 密钥配置
     */

    // van论坛
    private static final String LPF_APP_KEY_WZ = "98e21c89ae5610240ec3f5f575f86a59";
    private static final String LPF_SECRET_KEY_WZ = "3dcb6b23a1104639ac433fd07adb6dfb";
    // 导购的
    private static final String LPF_APP_KEY_DG = "faf410cb9587dc80dc7b31e321d7d322";
    private static final String LPF_SECRET_KEY_DG = "a4fb15d7bedd4316b97b4e96e4effc1c";

    private static final String LL_APP_KEY_DG = "9c2011409f0fc906b73432dd3687599d";
    private static final String LL_SECRET_KEY_DG = "3ceddff403e544a8a2eacc727cf05dab";


    /**
     * 实际业务处理
     */
    // 标记是否拉取过小时的订单，空订单会set 一个 tag，避免重复拉取
    private static final String JD_REFRESH_TAG = "jd:refresh:tag:";
    private static final String SERVER_URL = "https://api.jd.com/routerjson";
    //accessToken
    private static final String ACCESS_TOKEN = "";

    private static final Logger logger = LoggerFactory.getLogger(JDUtils.class);

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    private final StringRedisTemplate redisTemplate;
    private final OrderRowRepository orderRowRepository;
    private final WXUtil wxUtil;
    private final OrderUtil orderUtil;

    // 通过构造函数注入所有依赖项，Spring将自动注入这些依赖
    @Autowired  // @Autowired 在构造函数上可以省略，如果类只有一个构造函数
    public JDUtils(StringRedisTemplate redisTemplate, OrderRowRepository orderRowRepository, WXUtil wxUtil, OrderUtil orderUtil) {
        this.redisTemplate = redisTemplate;
        this.orderRowRepository = orderRowRepository;
        this.wxUtil = wxUtil;
        this.orderUtil = orderUtil;
    }

    /**
     * 将 响应参数转化为 OrderRow，并返回
     */
    private static OrderRow createOrderRow(OrderRowResp orderRowResp) {
        OrderRow orderRow = new OrderRow();
        orderRow.setOrderId(orderRowResp.getOrderId());
        orderRow.setSkuId(orderRowResp.getSkuId());
        orderRow.setSkuName(orderRowResp.getSkuName());
        orderRow.setItemId(orderRowResp.getItemId());
        orderRow.setSkuNum(orderRowResp.getSkuNum());
        orderRow.setPrice(orderRowResp.getPrice());
        orderRow.setActualCosPrice(orderRowResp.getActualCosPrice());
        orderRow.setActualFee(orderRowResp.getActualFee());
        orderRow.setEstimateCosPrice(orderRowResp.getEstimateCosPrice());
        orderRow.setEstimateFee(orderRowResp.getEstimateFee());
        orderRow.setSubSideRate(orderRowResp.getSubSideRate());
        orderRow.setSubsidyRate(orderRowResp.getSubsidyRate());
        orderRow.setCommissionRate(orderRowResp.getCommissionRate());
        orderRow.setFinalRate(orderRowResp.getFinalRate());

        orderRow.setOrderTime(DateUtils.parseDate(orderRowResp.getOrderTime()));
        orderRow.setFinishTime(DateUtils.parseDate(orderRowResp.getFinishTime()));
        orderRow.setOrderTag(orderRowResp.getOrderTag());
        orderRow.setOrderEmt(orderRowResp.getOrderEmt());
        orderRow.setUnionId(orderRowResp.getUnionId());
        orderRow.setUnionRole(orderRowResp.getUnionRole());
        orderRow.setUnionAlias(orderRowResp.getUnionAlias());
        orderRow.setUnionTag(orderRowResp.getUnionTag());
        orderRow.setTraceType(orderRowResp.getTraceType());
        orderRow.setValidCode(orderRowResp.getValidCode());
        orderRow.setPayMonth(orderRowResp.getPayMonth());
        orderRow.setSiteId(orderRowResp.getSiteId());
        orderRow.setParentId(orderRowResp.getParentId());
        //GoodsInfo goodsInfo = orderRowResp.getGoodsInfo();
        //GoodsInfoVO goodsInfoVO = new GoodsInfoVO();
        //goodsInfoVO.setShopId(String.valueOf(goodsInfo.getShopId()));
        //goodsInfoVO.setShopName(goodsInfo.getShopName());
        //goodsInfoVO.setOwner(goodsInfo.getOwner());
        //goodsInfoVO.setProductId(String.valueOf(goodsInfo.getProductId()));
        //goodsInfoVO.setImageUrl(goodsInfo.getImageUrl());
        //orderRow.setGoodsInfo(goodsInfoVO);
        orderRow.setCallerItemId(orderRowResp.getCallerItemId());
        orderRow.setPid(orderRowResp.getPid());
        orderRow.setCid1(orderRowResp.getCid1());
        orderRow.setCid2(orderRowResp.getCid2());
        orderRow.setCid3(orderRowResp.getCid3());
        orderRow.setChannelId(orderRowResp.getChannelId());
        orderRow.setProPriceAmount(orderRowResp.getProPriceAmount());
        orderRow.setSkuFrozenNum(orderRowResp.getSkuFrozenNum());
        orderRow.setSkuReturnNum(orderRowResp.getSkuReturnNum());
        orderRow.setSkuTag(orderRowResp.getSkuTag());
        orderRow.setPositionId(orderRowResp.getPositionId());
        orderRow.setPopId(orderRowResp.getPopId());
        orderRow.setRid(orderRowResp.getRid());
        orderRow.setPlus(orderRowResp.getPlus());
        orderRow.setCpActId(orderRowResp.getCpActId());
        orderRow.setGiftCouponKey(orderRowResp.getGiftCouponKey());

        orderRow.setModifyTime(new Date());
        orderRow.setSign(orderRowResp.getSign());
        orderRow.setBalanceExt(orderRowResp.getBalanceExt());
        orderRow.setExpressStatus(orderRowResp.getExpressStatus());
        orderRow.setExt1(orderRowResp.getExt1());
        orderRow.setSubUnionId(orderRowResp.getSubUnionId());
        orderRow.setGiftCouponOcsAmount(orderRowResp.getGiftCouponOcsAmount());
        orderRow.setTraceType(orderRowResp.getTraceType());
        orderRow.setExpressStatus(orderRowResp.getExpressStatus());
        orderRow.setTraceType(orderRowResp.getTraceType());
        orderRow.setId(orderRowResp.getId());
        orderRow.setValidCode(orderRowResp.getValidCode());
        orderRow.setExpressStatus(orderRowResp.getExpressStatus());
        orderRow.setTraceType(orderRowResp.getTraceType());
        return orderRow;
    }

    private static List<OrderRow> filterOrdersByDate(List<OrderRow> orderRows, int daysBack) {
        LocalDate now = LocalDate.now();

        return orderRows.stream().filter(order -> {
            // 将 Date 转换为 LocalDate
            LocalDate orderDate = order.getOrderTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

            // 计算是否在给定的天数内
            return !orderDate.isBefore(now.minusDays(daysBack)) && !orderDate.isAfter(now);
        }).collect(Collectors.toList());
    }

    private static Stream<OrderRow> getStreamForWeiGui(List<OrderRow> todayOrders) {
        return todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 13 || orderRow.getValidCode() == 25 || orderRow.getValidCode() == 26 || orderRow.getValidCode() == 27 || orderRow.getValidCode() == 28 || orderRow.getValidCode() == 29);
    }

    /**
     * 实时刷新最近10分钟的订单
     */
    @Scheduled(cron = "0 * * * * ?") // 每分钟执行一次
    public void fetchLatestOrder() throws Exception {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime lastMinute = now.minusMinutes(10).withSecond(0).withNano(0);

        UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(lastMinute, true, 1, true);  // 真实代表实时订单
        if (response != null) {

            int code = response.getQueryResult().getCode();
            if (code == 200) {
                if (response.getQueryResult().getCode() == 200) {
                    OrderRowResp[] orderRowResps = response.getQueryResult().getData();
                    if (orderRowResps == null) {
                        return;
                    }
                    for (OrderRowResp orderRowResp : orderRowResps) {
                        // 固化到数据库
                        OrderRow orderRow = createOrderRow(orderRowResp);
                        // 订单号不存在就保存，存在就更新订单状态
                        orderRowRepository.save(orderRow);
                    }
                }
            }
        }

    }

    /**
     * 扫描订单发送到微信
     * 每分钟的30秒执行一次
     */
    @Scheduled(cron = "*/10 * * * * ?")
    public void sendOrderToWx() {
        //long start = System.currentTimeMillis();
        int[] validCodes = {-1};
        // 只要三个月的,更多的也刷新不出来的
        Date threeMonthsAgo = Date.from(LocalDateTime.now().minusMonths(3).atZone(ZoneId.systemDefault()).toInstant());
        List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInAndOrderTimeGreaterThanOrderByOrderTimeDesc(validCodes, threeMonthsAgo);

        for (OrderRow orderRow : orderRows) {

            orderUtil.orderToWx(orderRow, true);

        }

        //logger.info("扫描订单发送到微信耗时：{} ms, 订单数：{} ", System.currentTimeMillis() - start, orderRows.size());

    }

    /**
     * 一天拉取三次 30天到60天前的订单
     */
    @Scheduled(cron = "0 0 */4 * * ?")
    public void fetchHistoricalOrders3090() {

        fetchHistoricalOrders3090Do();
    }

    private int fetchHistoricalOrders3090Do() {

        int count = 0;
        LocalDateTime now = LocalDateTime.now();
        //logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());

        LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS).minusMonths(1);
        LocalDateTime startDate = lastHour.minusMonths(3).truncatedTo(ChronoUnit.HOURS);

        while (!startDate.isEqual(lastHour)) {
            Integer pageIndex = 1;
            boolean hasMore = true;

            while (hasMore) {
                try {
                    // 30-60 天 ，非实时，非分钟
                    UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex, false);
                    if (response != null && response.getQueryResult() != null) {
                        if (response.getQueryResult().getCode() == 200) {
                            OrderRowResp[] orderRowResps = response.getQueryResult().getData();
                            if (orderRowResps != null) {
                                for (OrderRowResp orderRowResp : orderRowResps) {
                                    if (orderRowResp != null) { // Check each orderRowResp is not null
                                        OrderRow orderRow = createOrderRow(orderRowResp);
                                        if (orderRow != null) { // Ensure orderRow is not null after creation
                                            orderRowRepository.save(orderRow);
                                            count++;
                                        }
                                    }
                                }
                            }
                            hasMore = Boolean.TRUE.equals(response.getQueryResult().getHasMore());
                        } else {
                            hasMore = false;
                        }
                    } else {
                        hasMore = false;
                    }
                } catch (Exception e) {
                    hasMore = false; // Optionally break out of the while loop if required
                }
                if (hasMore) pageIndex++;
            }
            startDate = startDate.plusHours(1);
        }
        return count;
    }

    /**
     * 一天拉取6次 14天到30天前的订单
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void fetchHistoricalOrders1430() {
        fetchHistoricalOrders1430Do();
    }

    private int fetchHistoricalOrders1430Do() {
        int count = 0;
        LocalDateTime now = LocalDateTime.now();
        //logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());

        LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS).minusDays(14);
        LocalDateTime startDate = lastHour.minusMonths(1).truncatedTo(ChronoUnit.HOURS);

        while (!startDate.isEqual(lastHour)) {
            Integer pageIndex = 1;
            boolean hasMore = true;

            while (hasMore) {
                try {
                    // 14 - 30 天 ，非实时，非分钟
                    UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex, false);
                    if (response != null && response.getQueryResult() != null) {
                        if (response.getQueryResult().getCode() == 200) {
                            OrderRowResp[] orderRowResps = response.getQueryResult().getData();
                            if (orderRowResps != null) {
                                for (OrderRowResp orderRowResp : orderRowResps) {
                                    if (orderRowResp != null) { // Check each orderRowResp is not null
                                        OrderRow orderRow = createOrderRow(orderRowResp);
                                        if (orderRow != null) { // Ensure orderRow is not null after creation
                                            orderRowRepository.save(orderRow);
                                            count++;
                                        }
                                    }
                                }
                            }
                            hasMore = Boolean.TRUE.equals(response.getQueryResult().getHasMore());
                        } else {
                            hasMore = false;
                        }
                    } else {
                        hasMore = false;
                    }
                } catch (Exception e) {
                    hasMore = false; // Optionally break out of the while loop if required
                }
                if (hasMore) pageIndex++;
            }
            startDate = startDate.plusHours(1);
        }
        return count;
    }

    /**
     * 每10分钟拉取07-14天的订单
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void fetchHistoricalOrders0714() {

        fetchHistoricalOrders0714Do();
    }

    private int fetchHistoricalOrders0714Do() {
        int count = 0;
        LocalDateTime now = LocalDateTime.now();
        //logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());
        LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS).minusDays(7);
        LocalDateTime startDate = lastHour.minusDays(14).truncatedTo(ChronoUnit.HOURS);

        while (!startDate.isEqual(lastHour)) {
            Integer pageIndex = 1;
            boolean hasMore = true;

            while (hasMore) {
                try {
                    // 7 - 14 天 ，非实时，非分钟
                    UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex, false);
                    if (response != null && response.getQueryResult() != null) {
                        if (response.getQueryResult().getCode() == 200) {
                            OrderRowResp[] orderRowResps = response.getQueryResult().getData();
                            if (orderRowResps != null) {
                                for (OrderRowResp orderRowResp : orderRowResps) {
                                    if (orderRowResp != null) { // Check each orderRowResp is not null
                                        OrderRow orderRow = createOrderRow(orderRowResp);
                                        if (orderRow != null) { // Ensure orderRow is not null after creation
                                            orderRowRepository.save(orderRow);
                                            count++;
                                        }
                                    }
                                }
                            }
                            hasMore = Boolean.TRUE.equals(response.getQueryResult().getHasMore());
                        } else {
                            hasMore = false;
                        }
                    } else {
                        hasMore = false;
                    }
                } catch (Exception e) {
                    hasMore = false; // Optionally break out of the while loop if required
                }
                if (hasMore) pageIndex++;
            }
            startDate = startDate.plusHours(1);
        }
        return count;
    }

    @Scheduled(cron = "0 0 * * * ?")
    public void fetchHistoricalOrders0007() {
        fetchHistoricalOrders0007Do();
    }

    private int fetchHistoricalOrders0007Do() {

        int count = 0;
        LocalDateTime now = LocalDateTime.now();
        //logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());
        LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS);
        LocalDateTime startDate = lastHour.minusDays(7).truncatedTo(ChronoUnit.HOURS);

        while (!startDate.isEqual(lastHour)) {
            Integer pageIndex = 1;
            boolean hasMore = true;

            while (hasMore) {
                try {
                    // 0 - 7 天 ，非实时，非分钟
                    UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex, false);
                    if (response != null && response.getQueryResult() != null) {
                        if (response.getQueryResult().getCode() == 200) {
                            OrderRowResp[] orderRowResps = response.getQueryResult().getData();
                            if (orderRowResps != null) {
                                for (OrderRowResp orderRowResp : orderRowResps) {
                                    if (orderRowResp != null) { // Check each orderRowResp is not null
                                        OrderRow orderRow = createOrderRow(orderRowResp);
                                        if (orderRow != null) { // Ensure orderRow is not null after creation
                                            orderRowRepository.save(orderRow);
                                            count++;
                                        }
                                    }
                                }
                            }
                            hasMore = Boolean.TRUE.equals(response.getQueryResult().getHasMore());
                        } else {
                            hasMore = false;
                        }
                    } else {
                        hasMore = false;
                    }
                } catch (Exception e) {
                    hasMore = false; // Optionally break out of the while loop if required
                }
                if (hasMore) pageIndex++;
            }
            startDate = startDate.plusHours(1);
        }
        return count;
    }

    /**
     * 根据指定的日期时间拉取订单
     *
     * @param startTime 开始时间
     *                  isRealTime 是否是实时订单 是的话不会判断是否拉取过
     *                  page 分页页码
     *                  isMinutes 是否是分钟级订单 分钟的每次加10分钟，小时每小时加1小时
     */
    public synchronized UnionOpenOrderRowQueryResponse fetchOrdersForDateTime(LocalDateTime startTime, boolean isRealTime, Integer page, boolean isMinutes) {

        LocalDateTime endTime = isMinutes ? startTime.plusMinutes(30) : startTime.plusHours(1);
        String hourMinuteTag = isRealTime ? "minute" : "hour";
        String timeTag = JD_REFRESH_TAG + startTime.format(DATE_TIME_FORMATTER);

        HashOperations<String, String, String> hashOps = redisTemplate.opsForHash();

        // 检查这个小时或分钟是否已经被处理过
        if (hashOps.hasKey(timeTag, hourMinuteTag)) {
            if (!isMinutes) {
                return null;
            }
        }

        // 调用 API 以拉取订单
        try {
            UnionOpenOrderRowQueryResponse unionOpenOrderRowQueryResponse = getUnionOpenOrderRowQueryResponse(startTime, endTime, page);
            // 历史的订单才进行标记为已拉取,小时分钟的都进行拉取并且标记
            if (!isRealTime) {
                // 只有没有订单的才进行标记为已拉取
                if (unionOpenOrderRowQueryResponse != null && unionOpenOrderRowQueryResponse.getQueryResult() != null && unionOpenOrderRowQueryResponse.getQueryResult().getData() == null) {
                    hashOps.put(timeTag, hourMinuteTag, "done");
                }

            }
            // 打印方法调用和开始结束时间

            //logger.info("拉取订单---> ,类型 {} , 开始时间：{} --- 结束时间：{}", hourMinuteTag, startTime.format(DATE_TIME_FORMATTER), endTime.format(DATE_TIME_FORMATTER));
            return unionOpenOrderRowQueryResponse;
        } catch (Exception e) {
            return null;
        }


    }

    /**
     * 接收京粉指令指令
     */
    public void sendOrderToWxByOrderJD(String order) {
        int[] param = {-1};
        List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(param);
        /**
         * 菜单：
         * 今日统计
         * 昨日统计
         * 最近七天统计
         * 最近一个月统计
         * 今天订单
         * 昨天订单
         * */
        StringBuilder content = new StringBuilder();
        switch (order) {
            case "菜单":
                content.append("菜单：京+命令 \n 如： 京今日统计\r");
                content.append("今日统计\r");
                content.append("昨天统计\r");
                content.append("七日统计\r");
                content.append("一个月统计\r");
                content.append("两个月统计\r");
                content.append("三个月统计\r");
                content.append("总统计\r");
                content.append("这个月统计\r");
                content.append("上个月统计\r");
                content.append("今日订单\r");
                content.append("昨日订单\r");
                content.append("刷新7天\r");
                content.append("刷新3090\r");
                content.append("刷新1430\r");
                content.append("刷新0714\r");

                content.append("\n");
                content.append(":::高级菜单:::\r");
                content.append("菜单：京+高级+命令 \n 如： 京高级违规30\r");
                content.append("京高级违规+整数\r");
                content.append("京高级+订单号\r\"");
                content.append("京高级SKU+sku\\r\"");
                break;
            case "今日统计": {
                List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
                // 订单总数，已付款，已取消，佣金总计
                content.append("今日统计：\n");
                content.append("订单总数：").append(todayOrders.size()).append("\r");
                content.append("已付款：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(todayOrders).count()).append("\r");
                content.append("已付款佣金：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(todayOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());

                break;
            }
            case "已付款": {
                List<OrderRow> yfkOrders = orderRows.stream().filter(orderRow -> orderRow.getValidCode() == 16).collect(Collectors.toList());
                content.append("已付款：\n");
                content.append("订单总数：").append(yfkOrders.size()).append("\r");
                content.append("佣金总数：").append(yfkOrders.stream().mapToDouble(OrderRow::getEstimateFee).sum());
                for (OrderRow orderRow : yfkOrders) {
                    orderUtil.orderToWx(orderRow, false);
                }
                break;
            }
            case "昨日统计": {
                List<OrderRow> yesterdayOrders = filterOrdersByDate(orderRows, 1);
                List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
                yesterdayOrders.removeAll(todayOrders);
                content.append("昨日统计：\n");
                content.append("订单总数：").append(yesterdayOrders.size()).append("\r");
                content.append("已付款：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(yesterdayOrders).count()).append("\r");
                content.append("已付款佣金：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(yesterdayOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "三日统计": {
                List<OrderRow> last3DaysOrders = filterOrdersByDate(orderRows, 3);
                content.append("三日统计：\n");
                content.append("订单总数：").append(last3DaysOrders.size()).append("\r");
                content.append("已付款：").append(last3DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(last3DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(last3DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(last3DaysOrders).count()).append("\r");
                content.append("已付款佣金：").append(last3DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(last3DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(last3DaysOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "七日统计": {
                List<OrderRow> last7DaysOrders = filterOrdersByDate(orderRows, 7);
                content.append("七日统计：\n");
                content.append("订单总数：").append(last7DaysOrders.size()).append("\r");
                content.append("已付款：").append(last7DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(last7DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(last7DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(last7DaysOrders).count()).append("\r");
                content.append("已付款佣金：").append(last7DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(last7DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(last7DaysOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "一个月统计": {
                List<OrderRow> last30DaysOrders = filterOrdersByDate(orderRows, 30);
                content.append("一个月统计：\n");
                content.append("订单总数：").append(last30DaysOrders.size()).append("\r");
                content.append("已付款：").append(last30DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(last30DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(last30DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(last30DaysOrders).count()).append("\r");
                content.append("已付款佣金：").append(last30DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(last30DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(last30DaysOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "两个月统计": {
                List<OrderRow> last60DaysOrders = filterOrdersByDate(orderRows, 60);
                content.append("两个月统计：\n");
                content.append("订单总数：").append(last60DaysOrders.size()).append("\r");
                content.append("已付款：").append(last60DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(last60DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(last60DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(last60DaysOrders).count()).append("\r");
                content.append("已付款佣金：").append(last60DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(last60DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(last60DaysOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "三个月统计": {
                List<OrderRow> last90DaysOrders = filterOrdersByDate(orderRows, 90);
                content.append("订单总数：").append(last90DaysOrders.size()).append("\r");
                content.append("已付款：").append(last90DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(last90DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(last90DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(last90DaysOrders).count()).append("\r");
                content.append("已付款佣金：").append(last90DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(last90DaysOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(last90DaysOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "这个月统计": {
                // 计算出距离1号有几天
                int days = LocalDate.now().getDayOfMonth();
                List<OrderRow> thisMonthOrders = filterOrdersByDate(orderRows, days);

                content.append("本月统计：\n");
                content.append("订单总数：").append(thisMonthOrders.size()).append("\r");
                content.append("已付款：").append(thisMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(thisMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(thisMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(thisMonthOrders).count()).append("\r");
                content.append("已付款佣金：").append(thisMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(thisMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(thisMonthOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }
            case "上个月统计": {
                LocalDate lastMonth = LocalDate.now().minusMonths(1);
                int days = LocalDate.now().getDayOfMonth();

                List<OrderRow> lastMonthOrders = filterOrdersByDate(orderRows, lastMonth.lengthOfMonth() + days);
                List<OrderRow> thisMonthOrders = filterOrdersByDate(orderRows, days);
                lastMonthOrders = lastMonthOrders.stream().filter(orderRow -> !thisMonthOrders.contains(orderRow)).collect(Collectors.toList());

                content.append("上个月统计：\n");
                content.append("订单总数：").append(lastMonthOrders.size()).append("\r");
                content.append("已付款：").append(lastMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(lastMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(lastMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(lastMonthOrders).count()).append("\r");
                content.append("已付款佣金：").append(lastMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(lastMonthOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(lastMonthOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;

            }
            //总统计

            case "总统计": {
                content.append("总统计：\n");
                content.append("订单总数：").append(orderRows.size()).append("\r");
                content.append("已付款：").append(orderRows.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(orderRows.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(orderRows.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(orderRows).count()).append("\r");
                content.append("已付款佣金：").append(orderRows.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(orderRows.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(orderRows).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                break;
            }


            case "今日订单": {
                List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
                // 订单总数，已付款，已取消，佣金总计
                content.append("今日统计：\n");
                content.append("订单总数：").append(todayOrders.size()).append("\r");
                content.append("已付款：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(todayOrders).count()).append("\r");
                content.append("已付款佣金：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(todayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(todayOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());

                for (OrderRow orderRow : todayOrders) {
                    orderUtil.orderToWx(orderRow, false);
                }

                break;
            }
            case "昨日订单": {
                List<OrderRow> yesterdayOrders = filterOrdersByDate(orderRows, 1);
                List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
                yesterdayOrders.removeAll(todayOrders);
                content.append("昨日统计：\n");
                content.append("订单总数：").append(yesterdayOrders.size()).append("\r");
                content.append("已付款：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).count()).append("\r");
                content.append("已取消：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() != 16 && orderRow.getValidCode() != 17).count()).append("\r");
                content.append("已完成：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).count()).append("\r");
                content.append("违规：").append(getStreamForWeiGui(yesterdayOrders).count()).append("\r");
                content.append("已付款佣金：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum()).append("\r");
                content.append("已完成佣金：").append(yesterdayOrders.stream().filter(orderRow -> orderRow.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum());
                content.append("\r" + "违规佣金：").append(getStreamForWeiGui(yesterdayOrders).mapToDouble(orderRow -> orderRow.getEstimateCosPrice() * orderRow.getCommissionRate() * 0.01).sum());
                for (OrderRow orderRow : yesterdayOrders) {
                    orderUtil.orderToWx(orderRow, false);
                }
                break;
            }
            case "刷新7天": {
                long start = System.currentTimeMillis();
                int count = 0;
                LocalDateTime startDate = LocalDateTime.now().minusDays(3).withMinute(0).withSecond(0).withNano(0);
                LocalDateTime lastHour = LocalDateTime.now().minusHours(1).withMinute(0).withSecond(0).withNano(0);
                while (!startDate.isEqual(lastHour)) {
                    startDate = startDate.plusHours(1);
                    UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, 1, false);
                    if (response != null) {

                        int code = response.getQueryResult().getCode();
                        if (code == 200) {
                            if (response.getQueryResult().getCode() == 200) {
                                OrderRowResp[] orderRowResps = response.getQueryResult().getData();
                                if (orderRowResps == null) {
                                    continue;
                                }
                                for (OrderRowResp orderRowResp : orderRowResps) {
                                    // 固化到数据库
                                    OrderRow orderRow = createOrderRow(orderRowResp);
                                    // 订单号不存在就保存，存在就更新订单状态
                                    orderRowRepository.save(orderRow);
                                    count++;
                                }
                            }
                        }
                    }
                }
                content.append("刷新三天成功,耗时").append((System.currentTimeMillis() - start) / 1000).append("秒\r").append("刷新订单数：").append(count);
                break;

            }
            case "刷新3090": {
                long start = System.currentTimeMillis();
                int count = fetchHistoricalOrders3090Do();
                long time = System.currentTimeMillis() - start;
                content.append("订单行：").append(count).append(",耗时: ").append(time).append("ms,  ").append((time) / 1000).append(" s\r");
                break;

            }
            case "刷新1430": {
                long start = System.currentTimeMillis();
                int count = fetchHistoricalOrders1430Do();
                long time = System.currentTimeMillis() - start;
                content.append("订单行：").append(count).append(",耗时: ").append(time).append("ms,  ").append((time) / 1000).append(" s\r");

                break;
            }
            case "刷新0714": {
                long start = System.currentTimeMillis();
                int count = fetchHistoricalOrders0714Do();
                long time = System.currentTimeMillis() - start;
                content.append("订单行：").append(count).append(",耗时: ").append(time).append("ms,  ").append((time) / 1000).append(" s\r");
                break;
            }

            default:
                sendOrderToWxByOrderJDAdvanced(order);
        }
        if (content.length() > 0) {
            wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid);
        }

    }

    /**
     * 接收京粉指令指令
     * 高级菜单
     */
    public void sendOrderToWxByOrderJDAdvanced(String order) {
        int[] parm = {-1};
        List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);

        StringBuilder content = new StringBuilder();
        if (order.startsWith("高级")) {
            order = order.replace("高级", "");
            if (order.startsWith("违规")) {
                String days = order.replace("违规", "");
                Integer daysInt = 365;
                if (Util.isNotEmpty(days)) {
                    daysInt = Integer.parseInt(days);
                }
                List<OrderRow> filterOrdersByDays = filterOrdersByDate(orderRows, daysInt);

                content.append("违规排行：");
                content.append(daysInt).append("天").append("\r\n");


                Map<String, Long> skuIdViolationCountMap = filterOrdersByDays.stream().filter(orderRow -> orderRow.getValidCode() == 27 || orderRow.getValidCode() == 28).filter(orderRow -> orderRow.getSkuName() != null).collect(Collectors.groupingBy(OrderRow::getSkuName, Collectors.counting()));

                Map<String, List<OrderInfo>> orderInfoMap = filterOrdersByDays.stream().filter(orderRow -> orderRow.getValidCode() == 27 || orderRow.getValidCode() == 28).filter(orderRow -> orderRow.getSkuName() != null).map(orderRow -> {
                    OrderInfo info = new OrderInfo();
                    info.setSkuName(orderRow.getSkuName());
                    info.setOrderId(orderRow.getOrderId());
                    info.setOrderDate(orderRow.getOrderTime());
                    return info;
                }).collect(Collectors.groupingBy(OrderInfo::getSkuName));

                List<Map.Entry<String, Long>> sortedViolationCounts = skuIdViolationCountMap.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());

                Integer num = 0;
                for (Map.Entry<String, Long> entry : sortedViolationCounts) {
                    num++;
                    String skuName = entry.getKey();
                    Long count = entry.getValue();
                    content.append("\n").append(num).append(",商品：").append(skuName).append("\r\r").append(" 违规次数：").append(count).append("\r");
                    List<OrderInfo> infos = orderInfoMap.get(skuName);
                    if (infos != null) {
                        for (OrderInfo info : infos) {
                            content.append("\n 订单：").append(info.getOrderId()).append("\r 下单：").append(info.getOrderDate()).append("\r");
                        }
                    }
                }
            }
            // 订单状态查询
            if (order.startsWith("3") || order.startsWith("2")) {
                List<OrderRow> orderRowList = orderRowRepository.findByOrderId(Long.parseLong(order));
                if (!orderRowList.isEmpty()) {
                    OrderRow orderRow = orderRowList.get(0);
                    content.append(orderUtil.getFormattedOrderInfo(orderRow, orderRow.getValidCode()));
                } else {
                    content.append("订单不存在");
                }
            }
            if (order.startsWith("SKU")) {
                order = order.replace("SKU", "");
                String[] split = order.split("\r\n");
                content.append("电脑端").append("\r\n");
                for (String s : split) {
                    content.append("https://item.jd.com/").append(s).append(".html").append("\r\n");
                }
                wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid);
                content = new StringBuilder();
                content.append("手机端").append("\r\n");
                for (String s : split) {
                    content.append("https://item.m.jd.com/product/").append(s).append(".html").append("\r\n");
                }
                wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid);
                content = new StringBuilder();


            }
            // 转链
            if (order.startsWith("转链")) {
                order = order.replace("转链", "");
                String[] split = order.split("\r\n");
                for (String s : split) {
                    content.append("https://item.jd.com/").append(s).append(".html").append("\r\n");
                }
            }
        } else {
            try {
                sendOrderToWxByOrderJD("菜单");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        if (content.length() > 0) {
            wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content.toString(), 1, WXUtil.super_admin_wxid);
        }
    }
    //public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(){
    //    JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, APP_KEY, SECRET_KEY);
    //
    //    UnionOpenGoodsBigfieldQueryRequest request=new UnionOpenGoodsBigfieldQueryRequest();
    //    BigFieldGoodsReq goodsReq=new BigFieldGoodsReq();
    //    goodsReq.setSkuIds();
    //    request.setGoodsReq(goodsReq);
    //    request.setVersion("1.0");
    //    UnionOpenGoodsBigfieldQueryResponse response= null;
    //    try {
    //        response = client.execute(request);
    //    } catch (Exception e) {
    //        throw new RuntimeException(e);
    //    }
    //    return response;
    //}


    /**
     * 获取订单列表
     *
     * @param start 开始时间
     * @param end   结束时间
     * @return
     * @throws Exception
     */
    public UnionOpenOrderRowQueryResponse getUnionOpenOrderRowQueryResponse(LocalDateTime start, LocalDateTime end, Integer pageIndex) throws Exception {
        String startTime = start.format(DATE_TIME_FORMATTER);
        String endTime = end.format(DATE_TIME_FORMATTER);
        // 模拟 API 调用
        //System.out.println("调用API - 从 " + startTime
        //        + " 到 " + endTime);
        // 实际的 API 调用逻辑应在这里进行
        JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_SECRET_KEY_WZ);
        UnionOpenOrderRowQueryRequest request = new UnionOpenOrderRowQueryRequest();
        OrderRowReq orderReq = new OrderRowReq();
        orderReq.setPageIndex(pageIndex);
        orderReq.setPageSize(200);
        orderReq.setStartTime(startTime);
        orderReq.setEndTime(endTime);
        orderReq.setType(1);


        request.setOrderReq(orderReq);
        request.setVersion("1.0");
        request.setSignmethod("md5");
        // 时间戳，格式为yyyy-MM-dd HH:mm:ss，时区为GMT+8。API服务端允许客户端请求最大时间误差为10分钟
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        request.setTimestamp(simpleDateFormat.format(date));


        return client.execute(request);
    }

    /**
     * 接口描述：通过商品链接、领券链接、活动链接获取普通推广链接或优惠券二合一推广链接
     */
    //String transfer(String url) throws Exception {
    //    JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, APP_KEY_DG, SECRET_KEY_DG);
    //    UnionOpenPromotionBysubunionidGetRequest getRequest = new UnionOpenPromotionBysubunionidGetRequest();
    //    getRequest.setVersion("1.0");
    //    getRequest.setSignmethod("md5");
    //
    //    PromotionCodeReq promotionCodeReq = new PromotionCodeReq();
    //    promotionCodeReq.setMaterialId(url);
    //    promotionCodeReq.setSiteId("4101191512");
    //    promotionCodeReq.setSceneId(2);
    //    promotionCodeReq.setCommand(1);
    //    promotionCodeReq.setProType(5);
    //
    //
    //    getRequest.setPromotionCodeReq(promotionCodeReq);
    //    client.execute(getRequest);
    //
    //    String jsonString = JSON.toJSONString(response);
    //    System.out.println(jsonString);
    //
    //    System.out.println(request.getAppJsonParams());
    //    System.out.println(request.getPromotionCodeReq());
    //
    //    System.out.println("--------");
    //    System.out.println(response.getGetResult().getCode());
    //    System.out.println(response.getGetResult().getMessage());
    //    System.out.println(response.getGetResult().getData().getClickURL());
    //    System.out.println(response.getGetResult().getData().getJCommand());
    //    return response.getGetResult().getData().getClickURL();
    //}

    @Setter
    @Getter
    public static class OrderInfo {
        private String skuName;
        private Long count;
        private Long orderId;
        private Date orderDate;
    }
}
