package com.zjrs.ggfw.sggfw.bpo.impl;

import com.alibaba.fastjson.JSONObject;
import com.yinhai.bcpcs.exceptions.ClientException;
import org.mohrss.leaf.core.framework.domain.bpo.impl.BPOImpl;
import com.zjrs.ggfw.sggfw.bpo.ExportPdfQueryBPO;
import com.zjrs.ggfw.sggfw.dto.Uca919DTO;
import com.zjrs.ggfw.sggfw.dto.Ucf074DTO;
import com.zjrs.ggfw.sggfw.util.DownloadFile;
import com.zjrs.ggfw.sggfw.util.SggfwConfig;
import com.zjrs.ggfw.sggfw.util.SggfwInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class ExportPdfQueryBPOImpl extends BPOImpl implements ExportPdfQueryBPO {

    @Autowired
    SggfwConfig config;
    @Override
    public void ucf074(Ucf074DTO dto, HttpServletResponse res) throws ClientException, IOException {
        Map<String, Object> p = new HashMap<String, Object>();
        p.put("reportId", "UCF074");//报表ID
        p.put("aaa027", dto.getAaa027());//地市
        p.put("aac002", dto.getAac002());//身份证
        p.put("aac003", dto.getAac003());//姓名
        p.put("seal", "YES");//盖章
        p.put("aae041",dto.getAae041());//起始年度
        p.put("aae042",dto.getAae042());//结束年度
        Map<Object,Object> m=SggfwInterface.qqjk(p,config,"ExportPdfQuery");
        JSONObject jsonObject = JSONObject.parseObject(m.get("data").toString());
        if(jsonObject.get("errorCode").equals("00")){
            if(jsonObject.get("pdfObject")!=null) {
                DownloadFile.download(jsonObject.get("pdfObject").toString(),res);
            }
        }
    }

    @Override
    public void uca919(Uca919DTO dto, HttpServletResponse res) throws ClientException, IOException {
        Map<String, Object> p = new HashMap<String, Object>();
        p.put("reportId", "UCA919_QS");//报表ID
        p.put("aaa027", dto.getAaa027());//地市
        p.put("aac002", dto.getAac002());//身份证
        p.put("aac003", dto.getAac003());//姓名
        p.put("seal", "YES");//盖章
        p.put("aae001",dto.getAae001());//年度
        Map<Object,Object> m=SggfwInterface.qqjk(p,config,"ExportPdfQuery");
        JSONObject jsonObject = JSONObject.parseObject(m.get("data").toString());
        if(jsonObject.get("errorCode").equals("00")){
            if(jsonObject.get("pdfObject")!=null) {
                DownloadFile.download(jsonObject.get("pdfObject").toString(),res);
            }
        }
    }
}
