/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.google.common.reflect.TypeToken
 *  com.google.gson.Gson
 *  org.apache.commons.lang.StringUtils
 *  org.springframework.stereotype.Service
 */
package com.hst.taxService.service.imp;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.hst.common.domain.TaxCommonReturnDomain;
import com.hst.common.service.imp.BaseBusinessServiceImp;
import com.hst.common.util.HstWxServiceUtil;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.dao.BaseDao;
import com.hst.task.domain.zhdtmq.QhjGetYwflAppDomain;
import com.hst.task.domain.zhdtmq.QhjGetYwflDomain;
import com.hst.task.domain.zhdtmq.QhjGetYwflReturnDomain;
import com.hst.task.domain.zhdtmq.YyqhGetKyysjrsAppDomain;
import com.hst.task.domain.zhdtmq.YyqhGetKyysjrsDomain;
import com.hst.task.domain.zhdtmq.YyqhGetKyysjrsReturnDomain;
import com.hst.task.domain.zhdtmq.YyqhSaveAppDomain;
import com.hst.task.domain.zhdtmq.YyqhSaveReturnDomain;
import com.hst.task.domain.zhdtmq.YyqhZfAppDomain;
import com.hst.taxService.dao.imp.TaxYybsAppDaoImp;
import com.hst.taxService.domain.dsyyqh.BookScheduleDto;
import com.hst.taxService.domain.dsyyqh.BookTicketDto;
import com.hst.taxService.domain.dsyyqh.BookTimeSlicesDto;
import com.hst.taxService.domain.dsyyqh.BookableItemsDto;
import com.hst.taxService.domain.dsyyqh.DsYyqhBaseResponse;
import com.hst.taxService.service.TaxDsYyqhCommonAppService;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class TaxDsYyqhCommonServiceImp
extends BaseBusinessServiceImp
implements TaxDsYyqhCommonAppService {
    private BaseDao dao;

    @Override
    public TaxCommonReturnDomain yyqhGetYwfl(QhjGetYwflAppDomain appDomain) throws Exception {
        QhjGetYwflReturnDomain returnDomain = new QhjGetYwflReturnDomain();
        returnDomain.setCode("00");
        if (WebConstants.YYQH_DS_BSDT.containsKey(appDomain.getBsdtdjxh())) {
            String path = "/openintf/booking/getBookableItemsByArea.json";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("areaId", WebConstants.YYQH_DS_BSDT.get(appDomain.getBsdtdjxh()));
            Map<String, String> res = HstWxServiceUtil.sendMessForBasicAuth(String.valueOf(WebConstants.DS_YYQH_URL) + path, params, "utf-8", WebConstants.DS_YYQH_USERNAME, WebConstants.DS_YYQH_PASSWORD);
            if ("00".equals(res.get("code"))) {
                ArrayList<QhjGetYwflDomain> dataList;
                Type objectType;
                Gson gson = new Gson();
                String json = res.get("mess");
                DsYyqhBaseResponse response = (DsYyqhBaseResponse)gson.fromJson(json, objectType = new TypeToken<DsYyqhBaseResponse<List<BookableItemsDto>>>(){}.getType());
                if ("0".equals(response.getCode())) {
                    dataList = new ArrayList<QhjGetYwflDomain>();
                    for (BookableItemsDto dto : (List)response.getData()) {
                        QhjGetYwflDomain data = new QhjGetYwflDomain();
                        data.setYwflbm(dto.getTicketItemId());
                        data.setYwflmc(dto.getTicketItemName());
                        dataList.add(data);
                    }
                } else {
                    returnDomain.setCode("01");
                    returnDomain.setMess(response.getMessage());
                    return returnDomain;
                }
                returnDomain.setDataList(dataList);
                returnDomain.setCode("00");
                return returnDomain;
            }
            returnDomain.setCode("01");
            returnDomain.setMess(res.get("mess"));
            return returnDomain;
        }
        return returnDomain;
    }

    @Override
    public TaxCommonReturnDomain yyqhGetYysj(YyqhGetKyysjrsAppDomain appDomain) throws Exception {
        YyqhGetKyysjrsReturnDomain returnDomain = new YyqhGetKyysjrsReturnDomain();
        returnDomain.setCode("00");
        if (WebConstants.YYQH_DS_BSDT.containsKey(appDomain.getBsdtdjxh())) {
            String yysjPath = "/openintf/booking/getBookTimeSlicesByArea.json";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("areaId", WebConstants.YYQH_DS_BSDT.get(appDomain.getBsdtdjxh()));
            Map<String, String> res = HstWxServiceUtil.sendMessForBasicAuth(String.valueOf(WebConstants.DS_YYQH_URL) + yysjPath, params, "utf-8", WebConstants.DS_YYQH_USERNAME, WebConstants.DS_YYQH_PASSWORD);
            if ("00".equals(res.get("code"))) {
                ArrayList<YyqhGetKyysjrsDomain> dataList;
                Type objectType;
                Gson gson = new Gson();
                String json = res.get("mess");
                DsYyqhBaseResponse response = (DsYyqhBaseResponse)gson.fromJson(json, objectType = new TypeToken<DsYyqhBaseResponse<List<BookTimeSlicesDto>>>(){}.getType());
                if ("0".equals(response.getCode())) {
                    dataList = new ArrayList<YyqhGetKyysjrsDomain>();
                    for (BookTimeSlicesDto dto : (List)response.getData()) {
                        if (!"0".equals(dto.getDisabled())) continue;
                        YyqhGetKyysjrsDomain data = new YyqhGetKyysjrsDomain();
                        data.setYysj_q(String.valueOf(appDomain.getRq()) + " " + dto.getStartTime().substring(11, 19));
                        data.setYysj_z(String.valueOf(appDomain.getRq()) + " " + dto.getEndTime().substring(11, 19));
                        data.setTimeSliceId(dto.getId());
                        dataList.add(data);
                    }
                    String yyjhPath = "/openintf/booking/getBookScheduleByAreaAndTicketItem.json";
                    if (StringUtils.isBlank((String)appDomain.getYwflbm())) {
                        returnDomain.setCode("01");
                        returnDomain.setMess("\u539f\u5730\u7a0e\u5927\u5385\u9700\u8981\u4f20ywflbm");
                        return returnDomain;
                    }
                    params.put("ticketItemId", appDomain.getYwflbm());
                    params.put("beginDate", String.valueOf(appDomain.getRq()) + " 00:00:00");
                    params.put("endDate", String.valueOf(appDomain.getRq()) + " 23:59:00");
                    Map<String, String> yyjhRes = HstWxServiceUtil.sendMessForBasicAuth(String.valueOf(WebConstants.DS_YYQH_URL) + yyjhPath, params, "utf-8", WebConstants.DS_YYQH_USERNAME, WebConstants.DS_YYQH_PASSWORD);
                    if ("00".equals(yyjhRes.get("code"))) {
                        Type yyjhType;
                        String yyjhJson = yyjhRes.get("mess");
                        DsYyqhBaseResponse yyjhResponse = (DsYyqhBaseResponse)gson.fromJson(yyjhJson, yyjhType = new TypeToken<DsYyqhBaseResponse<List<BookScheduleDto>>>(){}.getType());
                        if (!"0".equals(yyjhResponse.getCode())) {
                            returnDomain.setCode("01");
                            returnDomain.setMess(yyjhResponse.getMessage());
                            return returnDomain;
                        }
                        for (YyqhGetKyysjrsDomain data : dataList) {
                            if (yyjhResponse.getData() == null) {
                                data.setKyysl("0");
                                continue;
                            }
                            for (BookScheduleDto jhDto : (List)yyjhResponse.getData()) {
                                if (!data.getTimeSliceId().equals(jhDto.getTimeSliceId())) continue;
                                data.setSchDateIdx(jhDto.getSchDateIdx());
                                data.setKyysl(jhDto.getAmount());
                            }
                        }
                    }
                } else {
                    returnDomain.setCode("01");
                    returnDomain.setMess(response.getMessage());
                    return returnDomain;
                }
                returnDomain.setDataList(dataList);
                returnDomain.setCode("00");
                return returnDomain;
            }
            returnDomain.setCode("01");
            returnDomain.setMess(res.get("mess"));
            return returnDomain;
        }
        return returnDomain;
    }

    @Override
    public TaxCommonReturnDomain yyqhSave(YyqhSaveAppDomain appDomain) throws Exception {
        YyqhSaveReturnDomain returnDomain = new YyqhSaveReturnDomain();
        if (WebConstants.YYQH_DS_BSDT.containsKey(appDomain.getBsdtdjXh())) {
            Type objectType;
            if (StringUtils.isBlank((String)appDomain.getSchDateIdx())) {
                returnDomain.setCode("01");
                returnDomain.setMess("\u539f\u5730\u7a0e\u5927\u5385\u9700\u8981\u4f20schDateId");
                return returnDomain;
            }
            if (StringUtils.isBlank((String)appDomain.getTimeSliceId())) {
                returnDomain.setCode("01");
                returnDomain.setMess("\u539f\u5730\u7a0e\u5927\u5385\u9700\u8981\u4f20timeSliceId");
                return returnDomain;
            }
            String yysjPath = "/openintf/booking/add.json";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("areaId", WebConstants.YYQH_DS_BSDT.get(appDomain.getBsdtdjXh()));
            params.put("ticketItemId", appDomain.getYwflbm());
            params.put("schDateIdx", appDomain.getSchDateIdx());
            params.put("timeSliceId", appDomain.getTimeSliceId());
            params.put("nsrbm", appDomain.getSfzhm());
            Map<String, String> res = HstWxServiceUtil.sendMessForBasicAuth(String.valueOf(WebConstants.DS_YYQH_URL) + yysjPath, params, "utf-8", WebConstants.DS_YYQH_USERNAME, WebConstants.DS_YYQH_PASSWORD);
            if (!"00".equals(res.get("code"))) {
                returnDomain.setCode("01");
                returnDomain.setMess(res.get("mess"));
                return returnDomain;
            }
            Gson gson = new Gson();
            String json = res.get("mess");
            DsYyqhBaseResponse response = (DsYyqhBaseResponse)gson.fromJson(json, objectType = new TypeToken<DsYyqhBaseResponse<BookTicketDto>>(){}.getType());
            if (!"0".equals(response.getCode())) {
                returnDomain.setCode("01");
                returnDomain.setMess(response.getMessage());
                return returnDomain;
            }
            String hqyzm = ((BookTicketDto)response.getData()).getBookPwd();
            returnDomain = (YyqhSaveReturnDomain)((TaxYybsAppDaoImp)this.getDao("taxYybsAppDaoImp")).yyqhSaveDs(appDomain, hqyzm, ((BookTicketDto)response.getData()).getSessionId());
        }
        return returnDomain;
    }

    @Override
    public TaxCommonReturnDomain yyqhDel(YyqhZfAppDomain appDomain) throws Exception {
        TaxCommonReturnDomain returnDomain = new TaxCommonReturnDomain();
        HashMap<String, String> res = ((TaxYybsAppDaoImp)this.getDao("taxYybsAppDaoImp")).yyqhDelDs(appDomain);
        if (res.containsKey("dsYyqhId") && StringUtils.isNotBlank((String)res.get("dsYyqhId"))) {
            String path = "/openintf/booking/cancelBooking.json";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("bookSessionId", res.get("dsYyqhId"));
            params.put("nsrbm", appDomain.getSfzhm());
            HstWxServiceUtil.sendMessForBasicAuth(String.valueOf(WebConstants.DS_YYQH_URL) + path, params, "utf-8", WebConstants.DS_YYQH_USERNAME, WebConstants.DS_YYQH_PASSWORD);
        }
        returnDomain.setCode(res.get("code"));
        returnDomain.setMess(res.get("mess"));
        return returnDomain;
    }

    public BaseDao getDao(String daoName) {
        this.dao = (BaseDao)WebConstants.WEB_APP_CONTEXT.getBean(daoName);
        return this.dao;
    }
}
