/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.stereotype.Service
 */
package com.hst.task.service;

import com.hst.common.bo.FwhQytjSqlZxjg;
import com.hst.common.util.HstWxServiceUtil;
import com.hst.framework.constants.WebConstants;
import com.hst.framework.service.BaseService;
import com.hst.framework.util.HstReflectUtil;
import com.hst.task.dao.QytjTaskDaoImp;
import com.hst.task.domain.QytjTaskData;
import com.hst.task.domain.QytjTaskSqlData;
import com.hst.taxService.domain.PublicSQLQueryRequestDomain;
import com.hst.taxService.domain.PublicSQLQueryResponseDomain;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QytjTaskService
implements BaseService {
    @Autowired
    private QytjTaskDaoImp dao;

    public void doExcuteQytjTask() throws Exception {
        Map<String, Object> map = this.dao.queryTaskList();
        List taskList = (List)map.get("taskList");
        List tjxlList = (List)map.get("tjxlList");
        for (QytjTaskData data : taskList) {
            boolean flag = true;
            this.dao.updateFwhQytjRwxxZt(data.getTjrwUuid(), "1", "");
            for (QytjTaskData tjxl : tjxlList) {
                List<QytjTaskSqlData> sqlList = this.dao.querySqlScriptList(tjxl.getTjxlDm());
                for (QytjTaskSqlData sqlData : sqlList) {
                    if ("1".equals(sqlData.getSqlBz())) {
                        PublicSQLQueryRequestDomain requestDomain = new PublicSQLQueryRequestDomain();
                        String sql = sqlData.getSelSql().replaceAll("#DJXH#", data.getDjxh()).replaceAll("#SSSQ_Q#", data.getSssq_q()).replaceAll("#SSSQ_Z#", data.getSssq_z());
                        if ("1".equals(sqlData.getXtbz())) {
                            requestDomain.setCXDB("1");
                        } else if ("2".equals(sqlData.getXtbz())) {
                            requestDomain.setCXDB("3");
                        }
                        requestDomain.setSQL(sql);
                        _logger.debug((Object)("\u4f53\u68c0\u5c0f\u7c7b" + sqlData.getTjxlDm() + "\uff1a\u6267\u884cSQL:" + sql));
                        PublicSQLQueryResponseDomain responseDomain = HstWxServiceUtil.sendMess(WebConstants.TAX_HTTP_PUBLIC_SERVICE_URL, requestDomain, "PRI.publicSqlSelect", PublicSQLQueryResponseDomain.class);
                        _logger.debug((Object)("\u8fd4\u56de\u7ed3\u679c:" + responseDomain.getCode() + "|" + responseDomain.getMess() + responseDomain.getDataList().size()));
                        _logger.debug((Object)("\u8bed\u53e5\u51fa\u9519\uff1a\u4f53\u68c0\u5c0f\u7c7b" + sqlData.getTjxlDm() + "\uff1a\u6267\u884cSQLXH:" + sqlData.getSqlXh() + "\u8fd4\u56de\u7ed3\u679c:" + responseDomain.getCode() + "|" + responseDomain.getMess()));
                        if ("00".equals(responseDomain.getCode())) {
                            FwhQytjSqlZxjg zxjg = new FwhQytjSqlZxjg();
                            zxjg.setTjxlDm(tjxl.getTjxlDm());
                            zxjg.setTjdlDm(tjxl.getTjdlDm());
                            zxjg.setDjxh(data.getDjxh());
                            zxjg.setTjrwUuid(data.getTjrwUuid());
                            zxjg.setSqlXh(sqlData.getSqlXh());
                            int i = 0;
                            while (i < responseDomain.getDataList().size()) {
                                int k = 1;
                                LinkedHashMap<String, String> dataMap = responseDomain.getDataList().get(i);
                                for (Map.Entry<String, String> entry : dataMap.entrySet()) {
                                    String colName = "col" + k;
                                    HstReflectUtil.setFieldValue(zxjg, colName, entry.getValue());
                                    ++k;
                                }
                                ++i;
                            }
                            try {
                                this.dao.insertFwhQytjSqlZxjg(zxjg);
                            }
                            catch (Exception e) {
                                _logger.error((Object)e.getMessage());
                                flag = false;
                                String mess = e.getMessage();
                                if (mess.length() > 1000) {
                                    mess = mess.substring(0, 1000);
                                }
                                this.dao.updateFwhQytjRwxxZt(data.getTjrwUuid(), "9", mess);
                            }
                            continue;
                        }
                        _logger.debug((Object)("\u8bed\u53e5\u51fa\u9519\uff1a\u4f53\u68c0\u5c0f\u7c7b" + sqlData.getTjxlDm() + "\uff1a\u6267\u884cSQLXH:" + sqlData.getSqlXh()));
                        flag = false;
                        this.dao.updateFwhQytjRwxxZt(data.getTjrwUuid(), "9", responseDomain.getMess());
                        continue;
                    }
                    "2".equals(sqlData.getSqlBz());
                }
            }
            try {
                this.dao.doQytjZxjgHxcl(data.getTjrwUuid());
            }
            catch (Exception e) {
                _logger.error((Object)e.getMessage());
                flag = false;
                String mess = e.getMessage();
                if (mess.length() > 1000) {
                    mess = mess.substring(0, 1000);
                }
                this.dao.updateFwhQytjRwxxZt(data.getTjrwUuid(), "9", mess);
            }
            if (!flag) continue;
            this.dao.updateFwhQytjRwxxZt(data.getTjrwUuid(), "2", "");
        }
    }
}
