package com.yc.ship.module.resource.service.resource;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.framework.mybatis.core.util.MyBatisUtils;
import com.yc.ship.module.resource.controller.admin.resource.vo.ResourceAccessRespVO;
import com.yc.ship.module.resource.controller.admin.resource.vo.ResourcePageReqVO;
import com.yc.ship.module.resource.controller.admin.resource.vo.ResourceSaveReqVO;
import com.yc.ship.module.resource.dal.dataobject.resource.ResourceDO;
import com.yc.ship.module.resource.dal.dataobject.supplier.ProductSupplierDO;
import com.yc.ship.module.resource.dal.mysql.resource.ResourceMapper;
import com.yc.ship.module.resource.dal.mysql.supplier.ProductSupplierMapper;
import com.yc.ship.module.resource.dal.redis.RedisKeyConstants;
import com.yc.ship.module.resource.enums.ErrorCodeConstants;
import com.yc.ship.module.resource.service.resource.util.DesUtil;
import com.yc.ship.module.resource.service.resource.util.EncryptUtils;
import com.yc.ship.module.resource.service.resource.util.MD5Utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.logging.log4j.util.Base64Util;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.*;

import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;


/**
 * 产品资源 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
@Slf4j
@CacheConfig(cacheNames = "resource")
public class ResourceServiceImpl implements ResourceService {

    @Resource
    private ResourceMapper resourceMapper;

    @Resource
    private ProductSupplierMapper productSupplierMapper;

    String PLAT_SERVICE = "platSupplierTradeService";
    String STANDARD_SERVICE = "standardSupplierTradeService";
    String ZSHL_SERVICE = "zshlSupplierTradeService";
    String ZWY_SERVICE = "zwySupplierTradeService";
    String ETERNAL_SERVICE = "eternalSupplierTradeService";
    String CRUISE_SERVICE = "cruiseSupplierTradeService";
    String SANXIAJY_SERVICE = "sanxiaJySupplierTradeService";

    @Override
    public Long createResource(ResourceSaveReqVO createReqVO) {
        // 插入
        ResourceDO resource = BeanUtils.toBean(createReqVO, ResourceDO.class);
        Long id= IdWorker.getId(resource);
        resource.setId(id);
        resource.setDeleted(false);
        resourceMapper.insert(resource);
        // 返回
        return resource.getId();
    }

    @Override
    public void updateResource(ResourceSaveReqVO updateReqVO) {
        // 校验存在
        validateResourceExists(updateReqVO.getId());
        // 更新
        ResourceDO updateObj = BeanUtils.toBean(updateReqVO, ResourceDO.class);
        resourceMapper.updateById(updateObj);
    }

    @Override
    public void deleteResource(Long id) {
        // 校验存在
        validateResourceExists(id);
        // 删除
        resourceMapper.deleteById(id);
    }

    private void validateResourceExists(Long id) {
        if (resourceMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.RESOURCE_NOT_EXISTS);
        }
    }

    @Override
    public ResourceDO getResource(Long id) {
        return resourceMapper.selectById(id);
    }

    @Override
    public PageResult<ResourceDO> getResourcePage(ResourcePageReqVO pageReqVO) {
        IPage<ProductSupplierDO> iPage = MyBatisUtils.buildPage(pageReqVO);
        IPage<ResourceDO> page = resourceMapper.queryPage(iPage,pageReqVO);

//        return resourceMapper.selectPage(pageReqVO);
        return new PageResult<>(page.getRecords(),page.getTotal());
    }

    @Override
    public List<ResourceDO> getSimpleResourceList() {
        return resourceMapper.getSimpleResourceList();
    }

    @Override
    public List<ResourceDO> getResourceByCategoryId(Long categoryId) {
        return resourceMapper.getResourceByCategoryId(categoryId);
    }

    /***
     *&#064;Description 获取第三方直连资源列表(jfg、船舶物资)
     *@author qsl
     *@date 2025/8/15 10:08
      *@param supplierId
     *@return 
     */
    @Override
    @Cacheable(cacheNames = RedisKeyConstants.ACCESS_PRODUCT_LIST+"#60", key = "#supplierId")
    public List<ResourceAccessRespVO> getProductListByAccessList(String supplierId) {
        List<ResourceAccessRespVO> list = new ArrayList<>();
        ProductSupplierDO supplierDO = productSupplierMapper.selectById(supplierId);
        if(supplierDO!=null && supplierDO.getIsSystemDirect()==1){
            if(ZSHL_SERVICE.equals(supplierDO.getDirectServer())){
                //jfg票务
                return loadZshlProductList(supplierDO);
            }else if(CRUISE_SERVICE.equals(supplierDO.getDirectServer())){
                //船舶物资
                return loadCruiseProductList(supplierDO);
            }else if(ZWY_SERVICE.equals(supplierDO.getDirectServer())){
                //自我游
                return loadZwyProductList(supplierDO);
            }
        }
        return list;
    }

    public List<ResourceAccessRespVO> loadZshlProductList(ProductSupplierDO supplierDO){
        List<ResourceAccessRespVO> list = new ArrayList<>();
        try {
            //jfg票务
            String method = "getProductInfo";
            String createOrderUrl = supplierDO.getDirectOrderUrl() + method;
            String userId = supplierDO.getDirectAccount();
            String userKey = supplierDO.getDirectParam();
            Long timestamp = System.currentTimeMillis() / 1000;

            JSONObject rep_head = new JSONObject();
            rep_head.put("user_id", userId);
            rep_head.put("method", method);
            rep_head.put("timestamp", timestamp);

            JSONObject rep_body = new JSONObject();
            rep_body.put("sceneryNo", "");

            String bodyStr = DesUtil.encrypt(rep_body.toString(), userKey);
            String signStr = userId + method + timestamp + bodyStr + userKey;
            log.error("jfg供应商产品查询开始,signStr:{}", signStr);
            String sign = MD5Utils.getMD5(signStr.getBytes("UTF-8"));
            rep_head.put("sign", sign);

            JSONObject req = new JSONObject();
            req.put("requestHead", rep_head);
            req.put("requestBody", bodyStr);
            Map<String, String> headMap = new HashMap<>();
            headMap.put("Content-type", "application/x-www-form-urlencoded");

            log.info("jfg供应商产品查询开始,请求地址:{},请求参数:{}", createOrderUrl, req.toString());
            String res = HttpUtil.createPost(createOrderUrl).contentType("application/json")
                    .body(Base64Util.encode(req.toString()))
                    .headerMap(headMap, false)
                    .timeout(15000)
                    .execute().body();
            log.info("jfg供应商产品查询完成,响应参数:{}", res);
            // base64解密
            String json = new String(Base64.decodeBase64(res.getBytes("UTF-8")));
            log.info("jfg供应商退票完成,响应response参数:{}", json);
            JSONObject jsonObj = JSONUtil.parseObj(json);
            JSONObject responseHead = jsonObj.getJSONObject("responseHead");
            if (StringUtils.equals("1000", responseHead.getStr("res_code"))) {
                String response = jsonObj.getStr("responseBody");
                String body = "";
                try {
                    body = DesUtil.decrypt(response, userKey);
                } catch (Exception e) {
                    log.info(e.toString());
                }
                log.info("jfg供应商退票请求完成,响应body参数:{}", body);
                JSONObject responseBody = JSONUtil.parseObj(body);
                JSONArray jsonArray = responseBody.getJSONArray("productList");
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    ResourceAccessRespVO resourceAccessRespVO = new ResourceAccessRespVO();
                    resourceAccessRespVO.setId(jsonObject.getStr("productId"));
                    resourceAccessRespVO.setName(jsonObject.getStr("productName"));
                    resourceAccessRespVO.setPrice(jsonObject.getStr("price"));
                    list.add(resourceAccessRespVO);
                }
                return list;
            } else {
                return list;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }


    public static String getToken(String appId,String url,String appSecretKey){
        Map<String, String> param =  new TreeMap<>();
        param.put("appId",appId);
        String reqUrl = url+"/v1/api/account/getToken";
        param.put("timestamp", DateUtil.now());
        String sign = MD5Utils.getSign(param, appSecretKey);
        param.put("encrypt",sign);
        System.out.println("url:"+reqUrl);
        System.out.println("param:"+JSONUtil.toJsonStr(param));
        String postJson = HttpUtil.createPost(reqUrl).contentType("application/json")
                .body(JSONUtil.toJsonStr(param))
                .headerMap(null,false)
                .timeout(100000)
                .execute().body();
        System.out.println("postJson:"+postJson);
        JSONObject data = JSONUtil.parseObj(postJson);
        if(data.get("code").equals("00000")){
            JSONObject res = data.getJSONObject("data");
            return res.getStr("auth");
        }
        return null;
    }

    /**
     * 获取商品
     * {
     *   "state": 1,
     *   "msg": "获取产品列表成功",
     *   "data": {
     *     "startIndex": 0,
     *     "resultNum": 10,
     *     "size": 5,
     *     "sizeAll": 5,
     *     "page": 0,
     *     "pageCount": 1,
     *     "results": [
     *       {
     *         "productNo": 80144579,
     *         "productName": "金卉庄园日场门票双人票 标准价 双人票",
     *         "treeId": 0,
     *         "ticketTypeName": "普通票",
     *         "peopleNum": 1,
     *         "childrenNum": 0,
     *         "oldmanNum": 0,
     *         "img": "http://qnimg.zowoyoo.com/img/15463/1575702105826.jpg",
     *         "imgs": "",
     *         "isOnlinepay": 1,
     *         "isSingle": 0,
     *         "isConfirm": 0,
     *         "startDate": "2025-04-09",
     *         "isPackage": 0,
     *         "viewId": "view_1671974",
     *         "viewName": "金卉庄园",
     *         "viewAddress": "湖北省孝感市孝南区",
     *         "cityName": "孝感",
     *         "cityId": "1004209",
     *         "viewLongitude": "113.956656",
     *         "viewLatitude": "31.014034",
     *         "ticketCount": 119,
     *         "attentCount": 0,
     *         "settlementPrice": 87.12,
     *         "salePrice": 99.0,
     *         "marketPrice": 0.0,
     *         "isExpress": 0,
     *         "expressPrice": 0.0,
     *         "distributionDesc": "",
     *         "isFree": 0,
     *         "startMinute": 0,
     *         "payMinute": 60,
     *         "startTime": "17:00",
     *         "startDay": 0,
     *         "startMaxDay": 0,
     *         "startNum": 1,
     *         "maxNum": 99,
     *         "limitType": 0,
     *         "cancelDay": 0,
     *         "validityType": 5,
     *         "validityCon": "2025-12-28,2025-12-31",
     *         "orderDesc": "",
     *         "businessHours": "",
     *         "peoples": "成人",
     *         "priceStartDate": "2025-12-30",
     *         "priceEndDate": "2025-12-31",
     *         "orderPolicy": "可当天预订，必须17时之前下单，要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。",
     *         "content": "",
     *         "custField": "link_man,link_phone,",
     *         "custFieldEx": "",
     *         "creditTypeSet": "",
     *         "state": 0,
     *         "ticketcodeType": 0,
     *         "isTimeslot": 0,
     *         "isChangeask": 0,
     *         "isTop": 0,
     *         "isPrint": 1,
     *         "prodDesc": null,
     *         "goodsunit": null,
     *         "saleStartDate": null,
     *         "saleEndDate": null,
     *         "appointment": null,
     *         "posterImg": null,
     *         "chargeInclude": "金卉庄园日场门票双人票&lt;br/&gt;2份景区门票+四季花海+萌宠观赏+无动力乐园+孔雀放飞表演",
     *         "chargeNoInclude": "",
     *         "refundNote": "订单未核销时可随时申请退订&lt;br/&gt;产品不支持部分退&lt;br/&gt;*如需改期，请申请退订后重新预订。",
     *         "userNote": "无需取票，凭电子凭证直接验证使用;使用地址：金卉庄园风景区;使用时间：08:30~17:00",
     *         "importantNote": "",
     *         "isConds": 0,
     *         "pubVers": "",
     *         "verifyType": 0,
     *         "verifyIntype": 0,
     *         "yyLink": null,
     *         "groupInfoIds": null,
     *         "views": [
     *           "view_1671974"
     *         ],
     *         "themes": [],
     *         "conds": [],
     *         "cancelRules": [],
     *         "purchaseLimit": {
     *           "limitTimeType": 0,
     *           "limitPhoneDay": -1,
     *           "limitPhoneNum": 0,
     *           "limitPhoneGoods": 0,
     *           "limitCardDay": -1,
     *           "limitCardNum": 0,
     *           "limitCardGoods": 0
     *         },
     *         "packageProducts": [],
     *         "specs": [],
     *         "isMusku": 0,
     *         "muskus": null,
     *         "lang": null
     *       },
     *       {
     *         "productNo": 80144741,
     *         "productName": "金卉庄园日场门票成人票 标准价 成人票",
     *         "treeId": 0,
     *         "ticketTypeName": "普通票",
     *         "peopleNum": 1,
     *         "childrenNum": 0,
     *         "oldmanNum": 0,
     *         "img": "http://qnimg.zowoyoo.com/img/15463/1575702105826.jpg",
     *         "imgs": "",
     *         "isOnlinepay": 1,
     *         "isSingle": 0,
     *         "isConfirm": 0,
     *         "startDate": "2025-04-09",
     *         "isPackage": 0,
     *         "viewId": "view_1671974",
     *         "viewName": "金卉庄园",
     *         "viewAddress": "湖北省孝感市孝南区",
     *         "cityName": "孝感",
     *         "cityId": "1004209",
     *         "viewLongitude": "113.956656",
     *         "viewLatitude": "31.014034",
     *         "ticketCount": 56,
     *         "attentCount": 0,
     *         "settlementPrice": 59.84,
     *         "salePrice": 68.0,
     *         "marketPrice": 0.0,
     *         "isExpress": 0,
     *         "expressPrice": 0.0,
     *         "distributionDesc": "",
     *         "isFree": 0,
     *         "startMinute": 0,
     *         "payMinute": 60,
     *         "startTime": "21:00",
     *         "startDay": 0,
     *         "startMaxDay": 0,
     *         "startNum": 1,
     *         "maxNum": 99,
     *         "limitType": 0,
     *         "cancelDay": 0,
     *         "validityType": 5,
     *         "validityCon": "2025-12-28,2025-12-31",
     *         "orderDesc": "<p>每份成人票赠送1张“哥德堡鬼船”项目票，注明：60岁以上老人，心脏病高血压癫痫等人群不可游玩鬼船</p>",
     *         "businessHours": "",
     *         "peoples": "成人",
     *         "priceStartDate": "2025-12-30",
     *         "priceEndDate": "2025-12-31",
     *         "orderPolicy": "可当天预订，必须21时之前下单，要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。",
     *         "content": "",
     *         "custField": "link_man,link_phone,",
     *         "custFieldEx": "",
     *         "creditTypeSet": "",
     *         "state": 0,
     *         "ticketcodeType": 0,
     *         "isTimeslot": 0,
     *         "isChangeask": 0,
     *         "isTop": 0,
     *         "isPrint": 1,
     *         "prodDesc": null,
     *         "goodsunit": null,
     *         "saleStartDate": null,
     *         "saleEndDate": null,
     *         "appointment": null,
     *         "posterImg": null,
     *         "chargeInclude": "金卉庄园日场门票成人票&lt;br/&gt;四季花海+萌宠观赏+无动力乐园",
     *         "chargeNoInclude": "",
     *         "refundNote": "订单未核销时可随时申请退订&lt;br/&gt;产品不支持部分退&lt;br/&gt;*如需改期，请申请退订后重新预订。",
     *         "userNote": "无需取票，凭电子凭证直接验证使用;使用地址：金卉庄园风景区;使用时间：08:30~17:00;08:30~21:00(2月10日-2月25日)",
     *         "importantNote": "",
     *         "isConds": 0,
     *         "pubVers": "",
     *         "verifyType": 0,
     *         "verifyIntype": 0,
     *         "yyLink": null,
     *         "groupInfoIds": null,
     *         "views": [
     *           "view_1671974"
     *         ],
     *         "themes": [],
     *         "conds": [],
     *         "cancelRules": [],
     *         "purchaseLimit": {
     *           "limitTimeType": 0,
     *           "limitPhoneDay": -1,
     *           "limitPhoneNum": 0,
     *           "limitPhoneGoods": 0,
     *           "limitCardDay": -1,
     *           "limitCardNum": 0,
     *           "limitCardGoods": 0
     *         },
     *         "packageProducts": [],
     *         "specs": [],
     *         "isMusku": 0,
     *         "muskus": null,
     *         "lang": null
     *       },
     *       {
     *         "productNo": 80144498,
     *         "productName": "金卉庄园日场门票优待票(老人/儿童) 标准价 优待票(老人/儿童)",
     *         "treeId": 0,
     *         "ticketTypeName": "普通票",
     *         "peopleNum": 1,
     *         "childrenNum": 0,
     *         "oldmanNum": 0,
     *         "img": "http://qnimg.zowoyoo.com/img/15463/1575702105826.jpg",
     *         "imgs": "",
     *         "isOnlinepay": 1,
     *         "isSingle": 0,
     *         "isConfirm": 0,
     *         "startDate": "2025-04-09",
     *         "isPackage": 0,
     *         "viewId": "view_1671974",
     *         "viewName": "金卉庄园",
     *         "viewAddress": "湖北省孝感市孝南区",
     *         "cityName": "孝感",
     *         "cityId": "1004209",
     *         "viewLongitude": "113.956656",
     *         "viewLatitude": "31.014034",
     *         "ticketCount": 1792,
     *         "attentCount": 0,
     *         "settlementPrice": 30.8,
     *         "salePrice": 35.0,
     *         "marketPrice": 0.0,
     *         "isExpress": 0,
     *         "expressPrice": 0.0,
     *         "distributionDesc": "",
     *         "isFree": 0,
     *         "startMinute": 0,
     *         "payMinute": 60,
     *         "startTime": "23:59",
     *         "startDay": 0,
     *         "startMaxDay": 0,
     *         "startNum": 1,
     *         "maxNum": 99,
     *         "limitType": 0,
     *         "cancelDay": 0,
     *         "validityType": 5,
     *         "validityCon": "2025-12-28,2025-12-31",
     *         "orderDesc": "",
     *         "businessHours": "",
     *         "peoples": "优惠人群",
     *         "priceStartDate": "2025-12-30",
     *         "priceEndDate": "2025-12-31",
     *         "orderPolicy": "可当天预订，必须23时59分之前下单，要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。",
     *         "content": "",
     *         "custField": "link_man,link_phone,",
     *         "custFieldEx": "",
     *         "creditTypeSet": "",
     *         "state": 0,
     *         "ticketcodeType": 0,
     *         "isTimeslot": 0,
     *         "isChangeask": 0,
     *         "isTop": 0,
     *         "isPrint": 1,
     *         "prodDesc": null,
     *         "goodsunit": null,
     *         "saleStartDate": null,
     *         "saleEndDate": null,
     *         "appointment": null,
     *         "posterImg": null,
     *         "chargeInclude": "金卉庄园日场门票优待票<br/>四季花海+无动力乐园+萌宠观赏",
     *         "chargeNoInclude": "",
     *         "refundNote": "订单未核销时可随时申请退订<br/>产品不支持部分退<br/>*如需改期，请申请退订后重新预订。",
     *         "userNote": "无需取票，凭电子凭证直接验证使用;使用地址：金卉庄园风景区;使用时间：08:30~23:59",
     *         "importantNote": "",
     *         "isConds": 0,
     *         "pubVers": "",
     *         "verifyType": 0,
     *         "verifyIntype": 0,
     *         "yyLink": null,
     *         "groupInfoIds": null,
     *         "views": [
     *           "view_1671974"
     *         ],
     *         "themes": [],
     *         "conds": [],
     *         "cancelRules": [],
     *         "purchaseLimit": {
     *           "limitTimeType": 0,
     *           "limitPhoneDay": -1,
     *           "limitPhoneNum": 0,
     *           "limitPhoneGoods": 0,
     *           "limitCardDay": -1,
     *           "limitCardNum": 0,
     *           "limitCardGoods": 0
     *         },
     *         "packageProducts": [],
     *         "specs": [],
     *         "isMusku": 0,
     *         "muskus": null,
     *         "lang": null
     *       },
     *       {
     *         "productNo": 81205934,
     *         "productName": "【三峡大瀑布】 仅当日可售-成人大门票",
     *         "treeId": 0,
     *         "ticketTypeName": "普通票",
     *         "peopleNum": 1,
     *         "childrenNum": 0,
     *         "oldmanNum": 0,
     *         "img": "http://qnimg.zowoyoo.com/img/15463/1629699310416.png",
     *         "imgs": "",
     *         "isOnlinepay": 1,
     *         "isSingle": 1,
     *         "isConfirm": 0,
     *         "startDate": "2025-04-09",
     *         "isPackage": 0,
     *         "viewId": "sxdpb",
     *         "viewName": "三峡大瀑布",
     *         "viewAddress": "湖北-宜昌黄花乡黄花场村 ",
     *         "cityName": "宜昌",
     *         "cityId": "1004205",
     *         "viewLongitude": "111.330536",
     *         "viewLatitude": "30.930432",
     *         "ticketCount": 11,
     *         "attentCount": 0,
     *         "settlementPrice": 112.0,
     *         "salePrice": 115.0,
     *         "marketPrice": 115.0,
     *         "isExpress": 0,
     *         "expressPrice": 0.0,
     *         "distributionDesc": "",
     *         "isFree": 0,
     *         "startMinute": 0,
     *         "payMinute": 60,
     *         "startTime": "16:30",
     *         "startDay": 0,
     *         "startMaxDay": 0,
     *         "startNum": 1,
     *         "maxNum": 99,
     *         "limitType": 0,
     *         "cancelDay": 0,
     *         "validityType": 0,
     *         "validityCon": "",
     *         "orderDesc": "",
     *         "businessHours": "",
     *         "peoples": "成人",
     *         "priceStartDate": "2025-03-08",
     *         "priceEndDate": "2025-12-31",
     *         "orderPolicy": "可当天预订，必须16时30分之前下单，要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。",
     *         "content": "",
     *         "custField": "link_man,link_phone,link_single_phone,link_credit_no,",
     *         "custFieldEx": "",
     *         "creditTypeSet": "0,3,13",
     *         "state": 0,
     *         "ticketcodeType": 0,
     *         "isTimeslot": 0,
     *         "isChangeask": 1,
     *         "isTop": 0,
     *         "isPrint": 1,
     *         "prodDesc": null,
     *         "goodsunit": null,
     *         "saleStartDate": null,
     *         "saleEndDate": null,
     *         "appointment": null,
     *         "posterImg": null,
     *         "chargeInclude": "大瀑布门票&lt;br/&gt;产品包含&lt;br/&gt;· 费用包含: 三峡大瀑布景点门票",
     *         "chargeNoInclude": "",
     *         "refundNote": "订单未核销时可随时申请退订&lt;br/&gt;*如需改期，请申请退订后重新预订。",
     *         "userNote": "无需取票，凭有效证件+电子凭证直接验证使用;使用地址：三峡大瀑布售票处;使用时间：08:30~16:30;补充说明：为保证充足的游玩时间，建议尽早取票游玩",
     *         "importantNote": "",
     *         "isConds": 0,
     *         "pubVers": "",
     *         "verifyType": 1,
     *         "verifyIntype": 0,
     *         "yyLink": null,
     *         "groupInfoIds": null,
     *         "views": [
     *           "sxdpb"
     *         ],
     *         "themes": [],
     *         "conds": [],
     *         "cancelRules": [],
     *         "purchaseLimit": {
     *           "limitTimeType": 0,
     *           "limitPhoneDay": -1,
     *           "limitPhoneNum": 0,
     *           "limitPhoneGoods": 0,
     *           "limitCardDay": -1,
     *           "limitCardNum": 0,
     *           "limitCardGoods": 0
     *         },
     *         "packageProducts": [],
     *         "specs": [],
     *         "isMusku": 0,
     *         "muskus": null,
     *         "lang": null
     *       },
     *       {
     *         "productNo": 81153894,
     *         "productName": "【三峡大瀑布】成人门票-非当日可售",
     *         "treeId": 0,
     *         "ticketTypeName": "普通票",
     *         "peopleNum": 1,
     *         "childrenNum": 0,
     *         "oldmanNum": 0,
     *         "img": "http://qnimg.zowoyoo.com/img/15463/1629699310416.png",
     *         "imgs": "",
     *         "isOnlinepay": 1,
     *         "isSingle": 1,
     *         "isConfirm": 0,
     *         "startDate": "2025-04-10",
     *         "isPackage": 0,
     *         "viewId": "sxdpb",
     *         "viewName": "三峡大瀑布",
     *         "viewAddress": "湖北-宜昌黄花乡黄花场村 ",
     *         "cityName": "宜昌",
     *         "cityId": "1004205",
     *         "viewLongitude": "111.330536",
     *         "viewLatitude": "30.930432",
     *         "ticketCount": 989,
     *         "attentCount": 0,
     *         "settlementPrice": 90.0,
     *         "salePrice": 105.0,
     *         "marketPrice": 115.0,
     *         "isExpress": 0,
     *         "expressPrice": 0.0,
     *         "distributionDesc": "",
     *         "isFree": 0,
     *         "startMinute": 0,
     *         "payMinute": 60,
     *         "startTime": "23:59",
     *         "startDay": 1,
     *         "startMaxDay": 0,
     *         "startNum": 1,
     *         "maxNum": 99,
     *         "limitType": 0,
     *         "cancelDay": 0,
     *         "validityType": 0,
     *         "validityCon": "",
     *         "orderDesc": "",
     *         "businessHours": "",
     *         "peoples": "成人",
     *         "priceStartDate": "2025-03-08",
     *         "priceEndDate": "2025-12-31",
     *         "orderPolicy": "需提前1天预订，必须23时59分之前下单，要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。",
     *         "content": "",
     *         "custField": "link_man,link_phone,link_single_phone,link_credit_no,",
     *         "custFieldEx": "",
     *         "creditTypeSet": "0,3,13",
     *         "state": 0,
     *         "ticketcodeType": 0,
     *         "isTimeslot": 0,
     *         "isChangeask": 1,
     *         "isTop": 0,
     *         "isPrint": 1,
     *         "prodDesc": null,
     *         "goodsunit": null,
     *         "saleStartDate": null,
     *         "saleEndDate": null,
     *         "appointment": null,
     *         "posterImg": null,
     *         "chargeInclude": "大瀑布门票&lt;br/&gt;产品包含&lt;br/&gt;· 费用包含: 三峡大瀑布景点门票",
     *         "chargeNoInclude": "",
     *         "refundNote": "订单未核销时可随时申请退订&lt;br/&gt;*如需改期，请申请退订后重新预订。",
     *         "userNote": "无需取票，凭有效证件+电子凭证直接验证使用;使用地址：三峡大瀑布售票处;使用时间：08:30~16:30;补充说明：为保证充足的游玩时间，建议尽早取票游玩",
     *         "importantNote": "",
     *         "isConds": 0,
     *         "pubVers": "",
     *         "verifyType": 1,
     *         "verifyIntype": 0,
     *         "yyLink": null,
     *         "groupInfoIds": null,
     *         "views": [
     *           "sxdpb"
     *         ],
     *         "themes": [],
     *         "conds": [],
     *         "cancelRules": [],
     *         "purchaseLimit": {
     *           "limitTimeType": 0,
     *           "limitPhoneDay": -1,
     *           "limitPhoneNum": 0,
     *           "limitPhoneGoods": 0,
     *           "limitCardDay": -1,
     *           "limitCardNum": 0,
     *           "limitCardGoods": 0
     *         },
     *         "packageProducts": [],
     *         "specs": [],
     *         "isMusku": 0,
     *         "muskus": null,
     *         "lang": null
     *       }
     *     ]
     *   }
     * }
     */
    public static String getZwyPresaleGoodsku(String url,String userId,String appSecretKey){
        String reqUrl = url+"/api/thirdPaty/prod/list";
        Map<String,Object> params=new TreeMap<>();
        params.put("apikey",appSecretKey);
        params.put("custId",userId);
        params.put("resultNum",20);
        System.out.println("params:"+JSONUtil.toJsonStr(params));
        String postJson = HttpUtil.createPost(reqUrl).contentType("application/json")
                .body(JSONUtil.toJsonStr(params))
                .headerMap(null,false)
                .timeout(100000)
                .execute().body();
        System.out.println("返回参数:"+postJson);
        return postJson;
    }

    /**
     * 获取商品
     * postJson:{"code":"00000","message":"00000","timestamp":1723448236220,"traceId":"",
     * "data":{"auth":"3f53d638-307b-408f-8a93-52835a6948ce","appId":"AVb8uYC6cPTMW",
     * "appSecretKey":"rkmhd4e7fmxv3t79gtpfzn1jvspazzy4ryoscyc0ptxtroxwzdopivsvz48a32ig","authorization":null,
     * "expireTime":"2025-08-15 15:37:16","authFailureDate":null,"claims":null,"createTime":"2025-08-12 15:37:16"}}
     */
    public static String getPresaleGoodsku(String url,String appSecretKey,String auth){
        Map<String, String> header = new HashMap<>();
        String reqUrl = url+"/v1/open/goodsku/getPresaleGoodsku";
        header.put("Auth",auth);
        Map<String,Object> params=new TreeMap<>();
        params.put("presaleDate",DateUtil.today());
        params.put("SecretKey",appSecretKey);
        String jsonStr = EncryptUtils.mapIterator(params);
        String md5 = null;
        try {
            md5 = EncryptUtils.getMd5(jsonStr);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        params.put("mac",md5);
        System.out.println("params:"+JSONUtil.toJsonStr(params));
        String postJson = HttpUtil.createPost(reqUrl).contentType("application/json")
                .body(JSONUtil.toJsonStr(params))
                .headerMap(header,false)
                .timeout(100000)
                .execute().body();
        System.out.println("返回参数:"+postJson);
        return postJson;
    }
    public List<ResourceAccessRespVO> loadCruiseProductList(ProductSupplierDO supplierDO){
        List<ResourceAccessRespVO> list = new ArrayList<>();
        try {
            //船舶物资
            String url = supplierDO.getDirectOrderUrl();
            String userId = supplierDO.getDirectAccount();
            String userKey = supplierDO.getDirectParam();
            //获取token
            String auth = getToken(userId,url,userKey);
            //获取产品
            //{"code":"00000","message":"00000","timestamp":1723449837912,"traceId":"","data":[{"id":"1","goodId":"0lam9agq4-004c1o0cqt-25g2-001","goodName":"多人套餐","goodSkuId":"0lplx985t-004c1o0cqt-1djb-001","goodSkuName":"多人套餐","presaleDate":"2025-08-12","presalNumber":10,"price":216.0000,"saleNumber":0},{"id":"2","goodId":"0lam9agq4-004c1o0cqt-25g2-001","goodName":"双人套餐","goodSkuId":"0ldlca2rb-004c1o0cqt-2g78-001","goodSkuName":"双人套餐","presaleDate":"2025-08-12","presalNumber":10,"price":198.0000,"saleNumber":0}]}
            String json =  getPresaleGoodsku(url,userKey,auth);
            JSONObject jsonObj = JSONUtil.parseObj(json);
            if (StringUtils.equals("00000", jsonObj.getStr("code"))) {
                JSONArray dataList = jsonObj.getJSONArray("data");
                for (int i = 0; i < dataList.size(); i++) {
                    JSONObject jsonObject = dataList.getJSONObject(i);
                    ResourceAccessRespVO resourceAccessRespVO = new ResourceAccessRespVO();
                    resourceAccessRespVO.setId(jsonObject.getStr("goodSkuId"));
                    resourceAccessRespVO.setName(jsonObject.getStr("goodName"));
                    resourceAccessRespVO.setPrice(jsonObject.getStr("price"));
                    list.add(resourceAccessRespVO);
                }
                return list;
            } else {
                return list;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    public List<ResourceAccessRespVO> loadZwyProductList(ProductSupplierDO supplierDO){
        List<ResourceAccessRespVO> list = new ArrayList<>();
        try {
            //自我游
            String url = supplierDO.getDirectOrderUrl();
            String userId = supplierDO.getDirectAccount();
            String userKey = supplierDO.getDirectParam();
            //获取产品
            String json =  getZwyPresaleGoodsku(url,userId,userKey);
            JSONObject jsonObj = JSONUtil.parseObj(json);
            if (StringUtils.equals("1", jsonObj.getStr("state"))) {
                JSONArray dataList = jsonObj.getJSONObject("data").getJSONArray("results");
                for (int i = 0; i < dataList.size(); i++) {
                    JSONObject jsonObject = dataList.getJSONObject(i);
                    ResourceAccessRespVO resourceAccessRespVO = new ResourceAccessRespVO();
                    resourceAccessRespVO.setId(jsonObject.getStr("productNo"));
                    resourceAccessRespVO.setName(jsonObject.getStr("productName"));
                    resourceAccessRespVO.setPrice(jsonObject.getStr("settlementPrice"));
                    list.add(resourceAccessRespVO);
                }
                return list;
            } else {
                return list;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

}