package com.ruoyi.web.controller.system;

import com.alibaba.druid.support.json.JSONUtils;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.security.CryptUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.misc.BASE64Encoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Array;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 *企业工商户Controller
 *
 * @author xu
 * @date 2019-08-22
 */
@Controller
@RequestMapping("/company/tenant")
public class CompanyController extends BaseController
{
    private String prefix ="system/company";

    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IQyCzrxxService qyCzrxxService;
    @Autowired
    private IQyInfoService iQyInfoService;
    @Autowired
    private IQyPersonService iQyPersonService;
    @Autowired
    private IQyDjxxService iQyDjxxService;
    @Autowired
    private IGtgsYwUserService gtgsYwUserService;

    //企业待审核

    @GetMapping("toaudit")
    public String gtgsyw(Model model)
    {
        System.err.println("企业待审核");
        //查询企业申请来源字典
        List<String>qyapply=companyService.selectQyApply();
        model.addAttribute("qyapply",qyapply);
        //待审核的状态为0
        model.addAttribute("state",0);
        return prefix + "/toaudit";
    }

    //企业审核中
    @GetMapping("inreview")
    public String inreview(Model model)
    {
        System.err.println("企业审核中");
        //查询企业申请来源字典
        List<String>qyapply=companyService.selectQyApply();
        model.addAttribute("qyapply",qyapply);
        //审核中状态为1
        model.addAttribute("state",1);
        return prefix + "/toaudit";
    }

    //企业审核通过
    @GetMapping("auditpass")
    public String auditpass(Model model)
    {
        System.err.println("企业审核通过");
        //查询企业申请来源字典
        List<String>qyapply=companyService.selectQyApply();
        model.addAttribute("qyapply",qyapply);
        //企业通过状态为2
        model.addAttribute("state",2);
        return prefix + "/auditpass";
    }


    //企业退回
    @GetMapping("sendback")
    public String sendback(Model model)
    {
        System.err.println("企业审核通过");
        //查询企业申请来源字典
        List<String>qyapply=companyService.selectQyApply();
        model.addAttribute("qyapply",qyapply);
        //企业退回状态为3
        model.addAttribute("state",3);
        return prefix + "/sendback";
    }

    //查找info表(企业申请表)
    @PostMapping("/company/{flg}")
    @ResponseBody
    public TableDataInfo companyList(@PathVariable("flg") String  flg,QyInfo info){

        if(flg.equals("1")){
            //当前登录管理员Id
            Long userId=ShiroUtils.getUserId();
            List<QyInfo>listi=companyService.selectFlgInfoI(flg,userId.toString(),info);
            return getDataTable(listi);
        }
        List<QyInfo> list=companyService.selectFlgInfo(flg ,info);
        return getDataTable(list);
}

    //企业退回
    @GetMapping("kzpage")
    public String kzPage(Model model)
    {
        System.err.println("企业审核通过");
        //查询企业申请来源字典
        List<String>qyapply=companyService.selectQyApply();
        model.addAttribute("qyapply",qyapply);
        //企业退回状态为3
        model.addAttribute("state",3);
        return prefix + "/kezhang";
    }

    //查找info表(企业申请表)
    @PostMapping("/kezhang/{flg}")
    @ResponseBody
    public TableDataInfo keZhangList(@PathVariable("flg") String  flg,QyInfo info){

            //当前登录管理员getLoginName
            String user=ShiroUtils.getSysUser().getLoginName();
            info.setShenhename(user);
            List<QyInfo>listi=companyService.selectFlgInfo(flg,info);
            return getDataTable(listi);
}

    /**
     * 企业审核
     */
    @GetMapping("/qyaudit/{id}")
    public String qyaudit(@PathVariable("id") String id,Model model){
        System.err.println("企业审核 id:"+id);
        //把企业改为审核中状态(1)
        Boolean if1=true;
        model.addAttribute("if1", if1);
        Long userId= ShiroUtils.getUserId();
        companyService.alteraudit(id,userId);
        model.addAttribute("id", id);
        return  prefix + "/qyall";

    }

    /**
     * 企业基本信息页面
     */
    @GetMapping("/qymessage")
    public String qymessage(String id,Model model){


        QyInfo info=companyService.selectIdAll(id);
        //是否军产
        if (info.getIsjc()!=null){
            if(info.getIsjc().equals("0")){
                info.setIsjc("否");
            }else if(info.getIsjc().equals("1")){
                info.setIsjc("是");
            }
        }
        System.err.println("城乡标记:"+info.getQyss());
        //城乡标记.
		if(info.getQyss()!=null){
            if(info.getQyss().equals("请选择")){
                info.setQyss("1");
            }else  if(info.getQyss().equals("城镇")){
                info.setQyss("1");
            }else  if(info.getQyss().equals("农村")){
                info.setQyss("2");
            }
        }

        //住所产权：
        System.err.println("住所产权:"+info.getJycscq());
        if(info.getJycscq()!=null){
            if(info.getJycscq().equals("请选择")){
                info.setJycscq("1");
            }else if(info.getJycscq().equals("自有")){
                info.setJycscq("1");
            }else if(info.getJycscq().equals("租赁")){
                info.setJycscq("2");
            }else if(info.getJycscq().equals("无偿使用")){
                info.setJycscq("3");
            }else if(info.getJycscq().equals("其他")){
                info.setJycscq("4");
            }
        }
            System.err.println("住所产权:"+info.getJycscq());
         //住所性质
            System.err.println("住所性质:"+info.getJycsxz());
        if(info.getJycsxz()!=null){
            if (info.getJycsxz().equals("请选择")){
                info.setJycsxz("1");
            }else if (info.getJycsxz().equals("住宅")){
                info.setJycsxz("1");
            }else if (info.getJycsxz().equals("商用")){
                info.setJycsxz("2");
            }
        }
        //经营期限
        if(info.getQyjyqx().equals("有效年")){
            info.setQyjyqx("1");
        }else if(info.getQyjyqx().equals("有效期")){
            info.setQyjyqx("2");
        }else if(info.getQyjyqx().equals("长期")){
            info.setQyjyqx("3");
        }

        System.err.println("住所性质:"+info.getJycsxz());
        Date date=new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        System.err.println("企业基本信息页面 id:"+info);
        String Createdate=(formatter.format(info.getCreatedate()));
        String time = formatter.format(date);
        model.addAttribute("date", time);
        model.addAttribute("info", info);
        model.addAttribute("Createdate", Createdate);
        return  prefix + "/qymessage";
    }

    /**
     * 企业基本信息表单
     */
    @PostMapping("/qyform/{id}")
    @ResponseBody
    public TableDataInfo getqyform(@PathVariable("id") String  id){
        System.err.println("企业基本信息表单 id:"+id);
        List<QyInfo> list=new ArrayList<>();
        for(QyInfo qy:list){
            System.err.println("企业基本信息表单 qy:"+qy);
        }
        return getDataTable(list);
    }

    /**
     * 党建信息页面
     */
    @GetMapping("/partymessage")
    public String partymessage(String id,Model model){
        Boolean if1=true;
        model.addAttribute("if1", if1);
        System.err.println("党建信息页面 id:"+id);
        QyInfo info=companyService.selectIdAll(id);
        QyDjxx jdxx=companyService.selectQyjdxx(info.getBsid());
		//书记标志
        if(jdxx.getSjflg()==null ||!jdxx.getSjflg().equals("1")||!jdxx.getSjflg().equals("0")){
            jdxx.setSjflg("0");
        }
        //组织标记
        if(jdxx.getZzflg()==null ||!jdxx.getZzflg().equals("1")||!jdxx.getZzflg().equals("0")){
            jdxx.setZzflg("0");
        }
        //党组织建制
        if(jdxx.getZzjz()!=null){
            if(jdxx.getZzjz().equals("请选择")){
                jdxx.setZzjz("1");
            }else if(jdxx.getZzjz().equals("党委")){
                jdxx.setZzjz("2");
            }else if(jdxx.getZzjz().equals("党总支")){
                jdxx.setZzjz("3");
            }else if(jdxx.getZzjz().equals("党支部")){
                jdxx.setZzjz("4");
            }else if(jdxx.getZzjz().equals("未成立")){
                jdxx.setZzjz("5");
            }
        }
        if(jdxx.getZjfs()!=null){
            if(jdxx.getZjfs().equals("请选择")){
                jdxx.setZjfs("1");
            }else if(jdxx.getZjfs().equals("单独组建")){
                jdxx.setZjfs("2");
            }else if(jdxx.getZjfs().equals("联合组建")){
                jdxx.setZjfs("3");
            }else if(jdxx.getZjfs().equals("其他")){
                jdxx.setZjfs("4");
            }
        }
        System.err.println("党建信息:"+jdxx);
        model.addAttribute("jdxx", jdxx);
        return  prefix + "/partymessage";
    }

    /**
     * 股东(出资人)页面
     */
    @GetMapping("/shareholder")
    public String shareholder(String id,Model model){
        QyInfo info=companyService.selectIdAll(id);
        model.addAttribute("info", info);
        System.err.println("股东(出资人)页面 id:"+id);
        model.addAttribute("id", id);
        return  prefix + "/shareholder";
    }

    /**
     * 股东(出资人)表单
     */
    @PostMapping("/shareholderform/{id}")
    @ResponseBody
    public TableDataInfo shareholderform(@PathVariable("id") String  id){
        System.err.println("股东(出资人)表单 id:"+id);
        QyInfo info=companyService.selectIdAll(id);
        List<QyCzrxx> czrxx=companyService.selectCzrxx(info.getBsid());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        for (QyCzrxx czr:czrxx) {
            if(StringUtils.isEmpty(czr.getRzQx())) {
                String time = formatter.format(czr.getRenjiaoqxtime());
                czr.setYzjg(time);
            }
        }
        return getDataTable(czrxx);

    }
    /**
     * 法定代表人、董事、监事、经理页面
     */
    @GetMapping("/director")
    public String director(String id,Model model){

        System.err.println("法定代表人页面 id:"+id);
        QyInfo info=companyService.selectIdAll(id);
        model.addAttribute("info", info);
        model.addAttribute("id", id);
        return  prefix + "/director";
    }

    /**
     * 法定代表人、董事、监事、经理表单
     */
    @PostMapping("/directorform/{id}")
    @ResponseBody
    public TableDataInfo directorform(@PathVariable("id") String  id){
        System.err.println("法定代表人表单 id:"+id);
        QyInfo info=companyService.selectIdAll(id);
        List<QyPerson> person =companyService.selectidPerson(info.getBsid());
      /*  if(!person.isEmpty()){
            for(QyPerson qy :person){
                if(qy.getRentype().equals("法定代表人")||qy.getRentype().equals("董事")||
                        qy.getRentype().equals("监事")||qy.getRentype().equals("经理")){
                    listPerson.add(qy);
                }
            }
        }*/

        return getDataTable(person);
    }
    /**
     * 财务负责人页面
     */
    @GetMapping("/finance")
    public String finance(String id,Model model){


        System.err.println("财务负责人页面 id:"+id);
        QyInfo info=companyService.selectIdAll(id);
        //查询财务负责人
        QyPerson person=companyService.selectFinance(info.getBsid());
        model.addAttribute("info", info);
        model.addAttribute("person", person);
        return  prefix + "/finance";
    }

    /**
     * 不予受理页面
     */

    @GetMapping("/sendback/{id}")
    public String send(@PathVariable("id")String id,Model model)
    {
        System.err.println("退回:"+id);

        //查询企业退回便捷语
        model.addAttribute("easy", companyService.selectqyeasy());
        model.addAttribute("id", id);
        return prefix+"/back.html";
    }



    /**
     * 保存不予受理
     * @param id 不予受理的id
     * @param returnReason 不予受理原因
     * @return
     */
    @PostMapping( "/send/{id}")
    @ResponseBody
    public AjaxResult returnSend(@PathVariable("id") String id , String returnReason)
    {
        System.err.println("企业退回:"+id);
        System.err.println("String returnReason:"+ returnReason);
        //当前登录管理员的id
        Long userId= ShiroUtils.getUserId();
		int i=companyService.updateSend(id,userId,returnReason);

        return toAjax(i);

    }

    /**
     * 添加企业便捷语
     * @param add
     * @return
     */
    @PostMapping("/addeasy")
    @ResponseBody
    public AjaxResult addeasy( String add)
    {
        System.err.println("添加企业便捷语add:"+add);
        int i =companyService.insertQyeasy(add);
        return toAjax(1);
    }

    /**
     * 审核通过
     * @param id 审核通过id
     * @param model
     * @param xycode 社会信用代码
     * @return 审核通过页面
     */

    @GetMapping( "/pass/{id}")
    public String auditpass(@PathVariable("id")String id,Model model,String xycode)
    {
        System.err.println("企业通过:"+id);
        //注册日期(默认当前时间)
        Date date =new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        model.addAttribute("date",dateString);
        model.addAttribute("id", id);
        return prefix+"/pass.html";
    }


    /**
     * 审核通过保存
     * @param id 审核通过的id
     * @param xycode 信用代码
     * @param book 书文号
     * @param reg 注册号
     * @return
     */
    @PostMapping( "/pass/{id}")
    @ResponseBody
    public AjaxResult pass(@PathVariable("id") String id ,String xycode,String book,String reg ,String regdate,HttpServletRequest request)
    {

        String url=Global.getConfig("ruoyi.gsdz")+":8005/gtdj/licence.do?method=toTowDimCode&appNo=&uniScid="+xycode+"&certTypeId=41";
        String QRcode=  getImg(url);
        /* String QRcode=QRcode(xycode);*/
        System.err.println("企业QRcode:"+QRcode);
        Long userId= ShiroUtils.getUserId();
        //保存通过审核
        int i=companyService.updateAuditPass(id,xycode,book,reg,regdate,QRcode,userId,request);
        return toAjax(i);

    }

    private static String strNetImageToBase64;
    public static String getImg(String urlgs){
        final ByteArrayOutputStream data = new ByteArrayOutputStream();
        try {
            // 创建URL
            URL url = new URL(urlgs);
            final byte[] by = new byte[1024];
            // 创建链接
            final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(5000);

            try {
                InputStream is = conn.getInputStream();
                // 将内容读取内存中
                System.err.println(111);
                int len = -1;
                while ((len = is.read(by)) != -1) {
                    data.write(by, 0, len);
                }
                System.err.println(222);
                // 对字节数组Base64编码
                BASE64Encoder encoder = new BASE64Encoder();
                strNetImageToBase64 = encoder.encode(data.toByteArray());
                System.out.println("网络图片转换Base64:" + strNetImageToBase64);
                // 关闭流
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  strNetImageToBase64;

    }

    /**
     *    @PostMapping("/edit")
     */

    @PostMapping("/kezhang")
    @ResponseBody
    public AjaxResult kezhang(QyInfo info) {
        int i=companyService.updateQymessage(info);
        return toAjax(i);
    };
    /**
     * 修改保存企业基本信息
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult Qymessage(QyInfo info) {
        System.err.println("info:"+info);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String time = formatter.format(info.getQyclrq());
        String jz=formatter.format(info.getQyyyqz());
        System.err.println("注册日期:"+time);
        System.err.println("截止日期:"+jz);
        //注册日期
        //info.setShuwenhao(time);
        //经营期限
//        info.setZhucehao(jz);
        info.setFlg(info.getQyjyqx());
        //是否军产
        if(info.getIsjc().equals("是")){
            info.setIsjc("1");
        }else if(info.getIsjc().equals("否")){
            info.setIsjc("0");
        }
        //城乡标记
        if(info.getQyss().equals("1")){
            info.setQyss("城镇");
        }else   if(info.getQyss().equals("2")){
            info.setQyss("农村");
        }
        //经营期限
        if(info.getQyjyqx().equals("1")){
            info.setQyjyqx("有效年");
        }else if(info.getQyjyqx().equals("2")){
            info.setQyjyqx("有效期");
        }else if(info.getQyjyqx().equals("3")){
            info.setQyjyqx("长期");
        }
        //住所产权
        if(info.getJycscq().equals("1")){
            info.setJycscq("自有");
        }else  if(info.getJycscq().equals("2")){
            info.setJycscq("租赁");
        }else  if(info.getJycscq().equals("3")){
            info.setJycscq("无偿使用");
        }else  if(info.getJycscq().equals("4")){
            info.setJycscq("其他");
        }

        //住所性质
        if(info.getJycsxz().equals("1")){
            info.setJycsxz("住宅");
        }else  if(info.getJycsxz().equals("2")){
            info.setJycsxz("商用");
        }
        //修改打印状态

            //保存更新企业基本信息
        int i=companyService.updateQymessage(info);
        return toAjax(i);
    }

    /**
     * 修改保存党建信息
     */
    @PostMapping("/partyedit")
    @ResponseBody
    public AjaxResult partymessage(QyDjxx djxx) {
        System.err.println("编辑保存党建信息");
        System.err.println("djxx:"+djxx);
        if(djxx.getIsdangjian().equals("1")){
            //有党建组织
            System.err.println("有党建组织");
            if(djxx.getZzjz()!=null){
                //党组织建制
                if(djxx.getZzjz().equals("1")){
                    djxx.setZzjz("请选择");
                }else if(djxx.getZzjz().equals("2")){
                    djxx.setZzjz("党委");
                }else if(djxx.getZzjz().equals("3")){
                    djxx.setZzjz("党总支");
                }else if(djxx.getZzjz().equals("4")){
                    djxx.setZzjz("党支部");
                }else if(djxx.getZzjz().equals("5")){
                    djxx.setZzjz("未成立");
                }
            }
            if(djxx.getZjfs()!=null){
                //党组织建制方式
                if(djxx.getZjfs().equals("1")){
                    djxx.setZjfs("请选择");
                }else if(djxx.getZjfs().equals("2")){
                    djxx.setZjfs("单独组建");
                }else if(djxx.getZjfs().equals("3")){
                    djxx.setZjfs("联合组建");
                }else if(djxx.getZjfs().equals("4")){
                    djxx.setZjfs("其他");
                }
            }
            //修改有党建组织党建信息
            int i =companyService.updateQyjdzzAll(djxx);
            return toAjax(i);
        }else{
            //没有党建组织
            System.err.println("没有党建组织");
            //修改没有党建组织党建信息
            int i =companyService.updateQyjdzz(djxx);

            return toAjax(i);
        }

    }

    /**
     * 修改保存财务负责人
     */
    @PostMapping("/financeedit")
    @ResponseBody
    public AjaxResult financeedit(QyPerson person) {
        System.err.println("编辑保存财务负责人");
        System.err.println("姓名:"+person.getRenname());
        System.err.println("手机号:"+person.getRenphone());
        System.err.println("证件号:"+person.getRencardno());
        System.err.println("bsid:"+person.getBsid());
        //修改保存财务负责人
        int i=companyService.updateFinance(person);
        return toAjax(i);

    }

    /**
     * 股东（出资人）查看页面
     */

    @GetMapping( "/shareck/{id}")
    public String download (@PathVariable("id")String id,Model model)
    {
        System.err.println("股东（出资人）查看:"+id);
        //股东人详细信息
        QyCzrxx czrxx=companyService.selectCzrxxById(id);
        model.addAttribute("czrxx", czrxx);
        model.addAttribute("id", id);
        model.addAttribute("change",false);
        return prefix+"/shareck.html";
    }
    /**
     * 股东（出资人）编辑页面
     */

    @GetMapping( "/sharebj/{id}")
    public String sharebj (@PathVariable("id")String id,Model model)
    {
        System.err.println("股东（出资人）查看:"+id);
        //股东人详细信息
        QyCzrxx czrxx=companyService.selectCzrxxById(id);
        model.addAttribute("czrxx", czrxx);
        model.addAttribute("id", id);
        model.addAttribute("change",true);
        return prefix+"/shareck.html";
    }


    /**
     * 修改保存股东详细信息
     */
    @PostMapping("/shareedit")
    @ResponseBody
    public AjaxResult shareedit( QyCzrxx czrxx) {
        //保存更新股东详细信息
       int i= qyCzrxxService.updateQyCzrxx(czrxx);
        return toAjax(i);
    }

    /**
     * 法定法定代表人、董事、监事、经理 查看页面
     */

    @GetMapping( "/directorck/{id}")
    public String directorck (@PathVariable("id")String id,Model model)
    {
        System.err.println("法定法定代表人、董事、监事、经理 查看:"+id);
        //法定法定代表人、董事、监事、经理详细信息
        QyPerson person =companyService.selectQyPersonById(id);
		//是否为法人
        String fr="否";
        if(person.getRentype()!=null){
            if(person.getRentype().equals("法定代表人")){
                fr="是";
            }
        }
        if(person.getRentype()!=null){
            if(person.getRentype().equals("请选择")){
                person.setRentype("1");
            }else if(person.getRentype().equals("法定代表人")){
                person.setRentype("2");
            }else if(person.getRentype().equals("董事")){
                person.setRentype("3");
            }else if(person.getRentype().equals("监事")){
                person.setRentype("4");
            }else if(person.getRentype().equals("经理")){
                person.setRentype("5");
            }else if(person.getRentype().equals("委托代理人")){
                person.setRentype("6");
            }else if(person.getRentype().equals("联络员")){
                person.setRentype("7");
            }
        }
        model.addAttribute("person", person);
        model.addAttribute("id", id);
        model.addAttribute("change",false);
        return prefix+"/directorck.html";
    }

    /**
     * 股东（出资人）编辑页面
     */

    @GetMapping( "/directorbj1/{id}")
    public String directorbj (@PathVariable("id")String id,Model model)
    {
        System.err.println("法定法定代表人、董事、监事、经理 编辑:"+id);
        //法定法定代表人、董事、监事、经理详细信息
        QyPerson person =companyService.selectQyPersonById(id);
		  //是否为法人
        String fr="否";
        if(person.getRentype()!=null){
            if(person.getRentype().equals("法定代表人")){
                fr="是";
            }
        }
        if(person.getRentype()!=null){
            if(person.getRentype().equals("请选择")){
                person.setRentype("1");
            }else if(person.getRentype().equals("法定代表人")){
                person.setRentype("2");
            }else if(person.getRentype().equals("董事")){
                person.setRentype("3");
            }else if(person.getRentype().equals("监事")){
                person.setRentype("4");
            }else if(person.getRentype().equals("经理")){
                person.setRentype("5");
            }else if(person.getRentype().equals("委托代理人")){
                person.setRentype("6");
            }else if(person.getRentype().equals("联络员")){
                person.setRentype("7");
            }
        }
        model.addAttribute("person", person);
        model.addAttribute("id", id);
        model.addAttribute("change",true);
        return prefix+"/directorck.html";
    }


    /**
     * 修改保存法定法定代表人、董事、监事、经理详细信息
     */
    @PostMapping("/directorbc")
    @ResponseBody
    public AjaxResult directorbc( QyPerson person) {
        System.err.println("名字:"+person.getRenname());
        System.err.println("性别:"+person.getRensex());
        System.err.println("身份证件号码:"+person.getRencardno());
        System.err.println("手机号:"+person.getRenphone());
        if(person.getRentype()!=null){
            if(person.getRentype().equals("1")){
                person.setRentype("请选择");
            }else if(person.getRentype().equals("2")){
                person.setRentype("法定代表人");
            }else if(person.getRentype().equals("3")){
                person.setRentype("董事");
            }else if(person.getRentype().equals("4")){
                person.setRentype("监事");
            }else if(person.getRentype().equals("5")){
                person.setRentype("经理");
            }else if(person.getRentype().equals("6")){
                person.setRentype("委托代理人");
            }else if(person.getRentype().equals("7")){
                person.setRentype("联络员");
            }
            System.err.println("职务:"+person.getRentype());
        }
        //修改保存法定法定代表人、董事、监事、经理详细信息
        int i=companyService.updateQyPerson(person);
        return toAjax(i);
    }

	 /**
     * 下载档案 页面
     */

    @GetMapping( "/download/{id}")
    public String downloadword (@PathVariable("id")String id,Model model)
    {
        String pageName ="/download.html";
        System.err.println("企业下载:"+id);
        model.addAttribute("id", id);
        QyInfo qy = companyService.selectIdAll(id);
        model.addAttribute("gtgsyw",qy);
        if(qy.getQylx().equals("有限责任公司（自然人投资或控股）")){
            pageName ="/download2.html";
        }
        if(qy.getQylx().equals("有限责任公司(自然人投资或控股)")){
            pageName ="/download2.html";
        }
        if(qy.getQylx().equals("个人独资企业")){
            pageName ="/download3.html";
        }
        return prefix + pageName;
    }


     /**
     * 下载doc
     * @param id
     * @param down
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @GetMapping("/test/toWord")
    public ModelAndView toWord(@RequestParam("id") String id , String down, HttpServletRequest request, HttpServletResponse response) throws IOException{
        System.err.println("企业id:"+id);
        System.err.println("企业down:"+down);
        File file = companyService.createDoc(id,down);
        QyInfo qy = companyService.selectIdAll(id);
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("UTF-8");
        java.io.BufferedInputStream bis = null;
        java.io.BufferedOutputStream bos = null;
        try {
            long fileLength = file.length();
            response.setContentType("application/msword");
            if(down.equals("1")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"章程——一人有限责任公司参考文本（执行董事、监事）.doc", "utf-8"));
            }else if (down.equals("2")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"一人有限责任公司股东决定参考文本（执行董事、监事）.doc", "utf-8"));
            }else if (down.equals("3")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"章程——有限责任公司参考文本（执行董事、监事）.doc", "utf-8"));
            }else if (down.equals("4")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"首次股东会决议参考文本（执行董事、监事）.doc", "utf-8"));
            }else if (down.equals("6")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"登记（备案）申请书.doc", "utf-8"));
            }else if (down.equals("7")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+".住所（经营场所）信息申报表.doc", "utf-8"));
            }else if (down.equals("8")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"个人独资企业申请书.doc", "utf-8"));
            }else if (down.equals("9")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"个人独资企业设立(变更)登记审核表.doc", "utf-8"));
            }else if (down.equals("10")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"经营场所使用证明.doc", "utf-8"));
            }else if (down.equals("11")){
                response.setHeader("Content-disposition", "attachment; filename="+
                         URLEncoder.encode(qy.getQyname()+"市场主体住所（经营场所）使用承诺书.doc", "utf-8"));
            }
            response.setHeader("Content-Length", String.valueOf(fileLength));
            bis = new BufferedInputStream(new FileInputStream(file));
            bos = new BufferedOutputStream(response.getOutputStream());
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(bis != null) {
                bis.close();
            }
            if(bos != null) {
                bos.close();
            }
      }
        System.err.println("下载完成");
        return null;
    }

 /**
 * 企业数据同步
 */
    @GetMapping("/qyDataSysc")
    @ResponseBody
    public AjaxResult qyDataSysc(Long  id) throws UnsupportedEncodingException {

        String qhdm=Global.getConfig("ruoyi.qhdm");   //区划代码
        String csdm=Global.getConfig("ruoyi.sjqhdm");   //城市代码+
        String date= DateUtils.datePath();
        QyInfo info=iQyInfoService.selectQyInfoById(id);
        //传入名字 获取需要字段

        QyDjxx djxx=iQyDjxxService.selectQyDjxxByBsid(info.getBsid());
        List<QyCzrxx> czrxx=qyCzrxxService.selectQyCzrxxByBsid(info.getBsid());
        // 当前登录用户
        SysUser user = ShiroUtils.getSysUser();
        GtgsYwUser gtgsYwUser=gtgsYwUserService.selectGtgsYwUserByRemark(user.getRemark());
        if(gtgsYwUser==null){
            return error("该账户未绑定工商户籍系统账号");
        }
        List<QyPerson> persons=iQyPersonService.selectQyPersonBybsid(info.getBsid());

//        //j加密
//        CryptUtil crypt = CryptUtil.getInstance();
        Map map =new HashMap();
        String wtr="";
        //联络员
        String lly="";
        String llysfz="";
        String llysjh="";
        String cwfzr="";
        String cwfzrsfz="";
        String cwfzrsjh="";
        String person="";
        int i=1;
        String s="";
        String NameCard="";
        Map<String,String> t = new HashMap<>();
        for (QyPerson p:persons) {
            String type="";
            if(p.getRentype().equals("委托代理人")){
                t.put("agentName",URLEncoder.encode(p.getRenname(), "utf-8"));
                t.put("agentCertNo",URLEncoder.encode(p.getRencardno(), "utf-8"));
                wtr=p.getRenname();
            }
            if(p.getRentype().equals("联络员")){
                t.put("contactName",URLEncoder.encode(p.getRenname(), "utf-8"));
                t.put("contactCertNo",URLEncoder.encode(p.getRencardno(), "utf-8"));
                lly=p.getRenname();
                llysfz=p.getRencardno();
                llysjh=p.getRenmoblie();
            }
            if(p.getRentype().equals("财务负责人")){
                t.put("finicialName",URLEncoder.encode(p.getRenname(), "utf-8"));
                t.put("finicialCertNo",URLEncoder.encode(p.getRencardno(), "utf-8"));
                cwfzr=p.getRenname();
                cwfzrsfz=p.getRencardno();
                cwfzrsjh=p.getRenmoblie();
            }
          if(p.getRentype().equals("董事")||p.getRentype().equals("监事")||p.getRentype().equals("经理")){
              String gdshidGb="";
              String isfr="";
              if(p.getRentype().equals("董事")){
                  gdshidGb="432A";
                  person="&personDS=";

                  t.put("memberName_1",URLEncoder.encode(p.getRenname(), "utf-8"));
                  t.put("memberCertNo_1",URLEncoder.encode(p.getRencardno(), "utf-8"));
              }else  if(p.getRentype().equals("监事")){
                  gdshidGb="408A";
                  person="&personJS=";

                  t.put("memberName_2",URLEncoder.encode(p.getRenname(), "utf-8"));
                  t.put("memberCertNo_2",URLEncoder.encode(p.getRencardno(), "utf-8"));
              }else if (p.getRentype().equals("经理")){
                  person="&personJL=";
                  gdshidGb="436A";

                  t.put("memberName_3",URLEncoder.encode(p.getRenname(), "utf-8"));
                  t.put("memberCertNo_3",URLEncoder.encode(p.getRencardno(), "utf-8"));
              }else if (p.getRentype().equals("法定代表人")){
                  isfr="on";
                  person="&personFR=";
                  gdshidGb="431A";

                  t.put("legelName",URLEncoder.encode(p.getRenname(), "utf-8"));
                  t.put("legelCertNo",URLEncoder.encode(p.getRencardno(), "utf-8"));
              }
              String sex="";
              int sex1 = Integer.parseInt(StringUtils.substring(p.getRencardno(),17,18));
              if(sex1%2!=0){
                  sex="1";
              }else {
                  sex="2";
              }
              Map<String,String> m = new HashMap<>();
              m.put("biaoSiName","");
              m.put("subObjId","10");
              m.put("memberType",isfr);
              m.put("memberType","9");
              m.put("etpsMemberBoTempId","");
              m.put("etpsMemberBoId","");
              m.put("appNo","");
              m.put("personName",URLEncoder.encode(p.getRenname(), "utf-8"));
              m.put("popMemberChecked","");
              m.put("sexId",sex);
              m.put("cetfTypeGb","1");
              m.put("cetfId",URLEncoder.encode(p.getRencardno() ,"utf-8"));
              m.put("nationalityId","156");
              m.put("nationalityIdText","");
              m.put("birthdate","");
              m.put("generateId","02");
              m.put("nationId","01");
              m.put("nationIdText","");
              m.put("memberTelephone","");
              m.put("fjMobile","");
              m.put("email","");
              m.put("accreditName","");
              m.put("accreditId","");
              m.put("hdshIdGb",URLEncoder.encode(gdshidGb ,"utf-8"));
              m.put("hdshId","");
              m.put("officeTermType","1");
              m.put("fjTermYear","");
              m.put("startDate","");
              m.put("endDate","");
              m.put("entityProvinceId","");
              m.put("provinceText","");
              m.put("staffSign","");
              m.put("memberAddress","");
              s += person+JSONUtils.toJSONString(m);

          }
        }

        for (QyCzrxx czr:czrxx) {
            t.put("investorName_"+i,URLEncoder.encode(czr.getCzrname(), "utf-8"));
            t.put("investorCertNo_"+i,URLEncoder.encode(czr.getCzrcardno(), "utf-8"));
            i++;
        }
        t.put("appNo","");
        t.put("etpsNm",URLEncoder.encode(info.getQyname(),"utf-8"));
        t.put("etpsType","1151");
        t.put("appTypeId","02");
        t.put("regOrgan","130105");
        t.put("investorCount","0");
        t.put("memberCount","1");
        t.put("clearCount","0");
        t.put("sessionUuid","null");
        t.put("validHasSpecial","");
        t.put("branchEtpsName",URLEncoder.encode(info.getQyname(),"utf-8"));
        t.put("branchEtpsTypeGb","1151");
        t.put("ignoreReason","");
        NameCard="&person="+JSONUtils.toJSONString(t);

        String userDetail="&authId="+ gtgsYwUser.getAuthid()+"&loginDeptId="+gtgsYwUser.getDetpid()+"&loginUserId="+gtgsYwUser.getUserid()+NameCard;
        String pydata= HttpUtils.sendPost(Global.getConfig("ruoyi.pyip")+"/companyGetData","qyname="+URLEncoder.encode(info.getQyname(),"utf-8")+userDetail);


        String qylx="";
        if(info.getQylx().equals("有限责任公司（自然人投资或控股）")){
            qylx="1130";
        }else  if(info.getQylx().equals("有限责任公司（自然人独资）")){
            qylx="1151";
        }

        String jyqx="";
        String tradeYears="";
        String tradeStartDate="";
        String tradeEndDate="";
        if(info.getQyjyqx().equals("有效年")){
            jyqx="1";
            tradeYears= String.valueOf(info.getQynx());
        }else if(info.getQyjyqx().equals("有效期")){
            jyqx="2";
            tradeStartDate=DateUtils.dateTime(info.getQyclrq());
            tradeEndDate=DateUtils.dateTime(info.getQyyyqz());
        }else if(info.getQyjyqx().equals("长期")){
            jyqx="3";
        }
        String qyss="";
        if(info.getQyss().equals("城镇")){
            qyss="1";
        }else{
            qyss="2";
        }
        String jycscq="";
        if(info.getJycscq().equals("租赁")){
            jycscq="01";
        }else if(info.getJycscq().equals("自由")){
            jycscq="02";
        }else if(info.getJycscq().equals("无偿使用")){
            jycscq="03";
        }else if(info.getJycscq().equals("其他")){
            jycscq="04";
        }
String isdj="";
        if(djxx.getIsdangjian().equals("0")){
isdj="2";
        }else {
            isdj="1";
        }
        Map pym= (Map) JSONUtils.parse(pydata);
        System.err.println("pym:"+pym);
        System.err.println(String.valueOf(pym.get("code")).equals("500"));
        if(String.valueOf(pym.get("code")).equals("500")){
            return AjaxResult.error("同步异常:"+pym.get("massage"));
        }
       String[] etpsAppendixBoIds =  pym.get("etpsAppendixBoIds").toString().split(",");
       System.err.println(etpsAppendixBoIds.length);
       String []arr= new String[6];
       if(etpsAppendixBoIds.length<=1){
            arr[0]="";
            arr[1]="";
            arr[2]="";
            arr[3]="";
            arr[4]="";
            arr[5]="";
        }else {
           arr=etpsAppendixBoIds;
       }
        String[]  arr1=  pym.get("investorTempIds").toString().split(",");
        String[] arr3=  new String[2];
        String[] licenceIds=  pym.get("licenceIds").toString().split(",");
        if(licenceIds.length==0){
            arr3[0]="";
            arr3[1]="";
        }else {
            arr3=licenceIds;
        }
       System.err.println(pym.get("licenceIds").toString().split(",").length);

        String arr2="";
        if(arr1.length>1){
             arr2 ="&ifInitiator=0&investorTempId="+arr1[1]+"&nationality_check_investor_"+arr1[1]+"=156&nationId_check_investor_"+arr1[1]+"=01&investor_type_"+arr1[1]+"=0101&domzeCptlTotal=0.000000";
        }

        //   股东信息添加
        String gd="";
        int g1=1;
        String ts = String.valueOf(System.currentTimeMillis());
        for (QyCzrxx czr:czrxx) {
            Map<String,String> m = new HashMap<>();
            m.put("cptlCrncyId","002");
            m.put("investorTempId","");
            m.put("entityTypeId","0101");
            m.put("fjSeqNo", String.valueOf(g1+1));//股东序号
            m.put("entityName",URLEncoder.encode(czr.getCzrname(),"utf-8"));
            m.put("popInvestorChecked",URLEncoder.encode(czr.getCzrname(),"utf-8")+";"+czr.getCzrcardno());
            m.put("entityTypeGb","1");
            m.put("cetfType","");
            m.put("cetfId",czr.getCzrcardno());
            m.put("sexId",czr.getCzrxb().equals("男")?"1":"2");
            m.put("birthdate","");
            m.put("nationId","01");
            m.put("entityProvinceId","");
            m.put("province1","");
            m.put("provinceText","");
            m.put("investCrncyId","002");
            m.put("fjStages","");
            m.put("infoDate","");
            m.put("investTotal","");
            m.put("fjVerifyOrgan","");
            m.put("investTotalDollar","");
            m.put("resolutionDate","");
            m.put("resolutionCptl","");
            m.put("fjDelayDate","");
            m.put("fjStagesId_1_"+ts,String.valueOf(g1));
            m.put("infoDateId_1_"+ts,URLEncoder.encode(String.valueOf(DateUtils.dateMonth(czr.getShijiaoqxtime())),"utf-8"));
            m.put("fjVerifyOrganId_1_"+ts,"");
            m.put("fjDelayDateId_1_"+ts,"");
            m.put("infoInvtTypeGbId_1_"+ts,"1");
            m.put("infoInvtTypeId_1_"+ts,"");
            m.put("cptl_1_"+ts,czr.getRenjiaoje());
            m.put("cptlDollar_1_"+ts,czr.getRenjiaoje());
            m.put("resolutionDate_1_"+ts,"");
            m.put("resolutionCptl_1_"+ts,"");
            m.put("invtInfoId_1_"+ts,"");
            m.put("invtInfoTempId","1_"+ts);
            m.put("invtInfoDeleteFlag_1_"+ts,"0");
            gd+="&personGD"+g1+"="+JSONUtils.toJSONString(m);
            g1++;
        }
        if(gd==""){
            gd="&personGD1=&personGD2=&personGD3=";
        }
        gd+="&GdNumber="+czrxx.size();
        System.err.println("股东:---------------- "+gd);
        String str="";
      //为窗口待办打开提交人员信息的 str
       /* str="appNo="+pym.get("appNo")+"&etpsId=&flowId=001001&actnId=0039&modifyAppActv=&appTypeId=02&subObjId=10&appCaseType=&applyOrgan="+URLEncoder.encode(qhdm,"utf-8")+"&ifTempSave=true&currentStatus=0032&sessionUuid="+pym.get("sessionUuid")+
                "&gddServiceJson=&gddOldName=&regOrgan="+URLEncoder.encode(qhdm,"utf-8")+"&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[0]+"&appendixId=0&appendixName="+URLEncoder.encode("《公司登记（备案）申请书》","utf-8")+
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=0&etpsAppendixBoId="+arr[1]+"&appendixId=1&appendixName="+URLEncoder.encode("公司章程（有限责任公司由全体股东签署，股份有限公司由全体发起人签署）","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[2]+"&appendixId=2&appendixName="+URLEncoder.encode("股东、发起人的主体资格证明或自然人身份证明","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[3]+"&appendixId=3&appendixName="+URLEncoder.encode("法定代表人、董事、监事和经理的任职文件","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[4]+"&appendixId=4&appendixName="+URLEncoder.encode("住所使用证明","utf-8")+"&receiveDate="+URLEncoder.encode(date,"utf-8")+
                "&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=0&etpsAppendixBoId="+arr[5]+"&appendixId=5&appendixName="+URLEncoder.encode("法律、行政法规和国务院决定规定设立公司必须报经批准的或公司申请登记的经营范围中有法律、行政法规和国务院决定规定必须在登记前报经批准的项目，提交有关批准文件或者许可证件的复印件","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&nameTrad=&tradPiny=&nameExtra=&etpsName="+URLEncoder.encode(info.getQyname(),"utf-8")+"&etpsNameId=&nameAppNo="+pym.get("nameAppNo")+"&nmId="+
                "&directAcceptClick=&webStatusId=&grpName=&isPCom=&groupName=&groupNameTemp=&cerNoQuery=&agentbiaoSiNameChecked="+URLEncoder.encode(wtr+";"+info.getWtrcardno(),"utf-8")+
                "&agentbiaoSiName=&organId="+URLEncoder.encode(qhdm,"utf-8")+"&deptId=&flowId=001001"
                + "&actnId=0039&userId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getUserid()),"utf-8")+"&staffName="
                +URLEncoder.encode(gtgsYwUser.getName(),"utf-8")
                +"&applicantName="+URLEncoder.encode(wtr,"utf-8")+
                "&cerTypeGb=1&cerNo="+URLEncoder.encode(info.getWtrcardno(),"utf-8")+"&agentTelephone=&fjProxyQQ=&appDate="+URLEncoder.encode(DateUtils.dateTime(info.getCreatedate()),"utf-8")+"&=&=" +
                "&validContactName="+URLEncoder.encode(lly+";"+llysfz,"utf-8")+"&contactName=&persnName="+URLEncoder.encode(lly,"utf-8")+"&contactAddress=&contactCetfType=1&contactCetfId="+URLEncoder.encode(llysfz,"utf-8")+"&contactTelephone=&contactMobile="+URLEncoder.encode(llysjh,"utf-8")+
                "&contactMail=&contactPostcode=&etpsTypeGb="+URLEncoder.encode(qylx,"utf-8")+"&isPrivate=1&fjEtpsSort1=2&fjEtpsSort=2&fjCityFlag="+URLEncoder.encode(qyss,"utf-8") +
                "&toEdit=1&areaId="+URLEncoder.encode(csdm,"utf-8")+"&fjCounty="+URLEncoder.encode(qhdm,"utf-8")+"&districtExtraSelect=&districtExtra=&fjStreet=&fjNeigbor=&road=&address="+URLEncoder.encode(info.getQyjycs(),"utf-8")+"&areaOrganId1="+URLEncoder.encode(csdm,"utf-8") +
                "&areaOrganId="+qhdm+"&roomRight="+jycscq+"&mailAddr="+URLEncoder.encode("无","utf-8")+"&postcode=050000&telephone="+URLEncoder.encode(info.getQylxdh(),"utf-8")+"&establishType=01&leaderPersonName="+URLEncoder.encode(info.getFrname(),"utf-8")+
                "&cptlTotal="+URLEncoder.encode(info.getQyzczj(),"utf-8")+".000000&cptlCrncyId=002&cptlRmb="+URLEncoder.encode(info.getQyzczj(),"utf-8")+ "&tradeTermType="+URLEncoder.encode(jyqx,"utf-8")+"&tradeYears="+URLEncoder.encode(tradeYears,"utf-8")+"&tradeStartDate="+URLEncoder.encode(tradeStartDate,"utf-8")+"&tradeEndDate="+URLEncoder.encode(tradeEndDate,"utf-8")+
                "&empNum="+URLEncoder.encode(info.getQycyrs(),"utf-8")+ "&unemploymentNum=&offJobNumb=&licenceId="+arr3[0]+"&licenceSeqNo=&licenceNo=" +
                "&licenceTypeId=01&licenceDataType=1&licenceNumb=1&licenceId="+arr3[1]+"&licenceSeqNo=&licenceNo=&licenceTypeId=07&licenceDataType=2&licenceNumb=1&isProvideDzyyzz=1&licCardCnt=1&fjFileNo="+pym.get("fjFileNo")+
                "&delIds=&fjMergerSplit=&industryCode111="+pym.get("industryCode111")+"&industryPhy="+pym.get("industryCode111")+"&industryCode1="+pym.get("industryCode111")+"&industryCode=&industryCode2=&industryCode3="+
                "&foodTrdTypeId=&trdScope="+URLEncoder.encode(info.getQyjyfw(),"utf-8")+"&dzhyAppNo=&estPartyFlag="+URLEncoder.encode(djxx.getIsdangjian(),"utf-8")+"&estPartyTime=&insId=&orgId=&partyNum=&permitInfoTemp=&etType0=" +
                "&ifInitiator=0&investorTempId="+arr1[0]+"&nationality_check_investor_"+arr1[0]+"=156&nationId_check_investor_"+arr1[0]+"=01&investor_type_"+arr1[0]+"=0101&domzeCptlTotal=0.000000"+ arr2 +
                "&domzeCptlDollar=&domzeCptlPercent=" +
                "&frgnCptl=&investorFrgnCptlDollar=&frgnCptlPercent=&domzeActlTotal=&domzeActllDollar=&domzeActlPercent=&frgnActl=&frgnActlDollar=&frgnActlPercent=&actlDollar=&ifCollege=&checkInvestmentOverdue=&isFddbr=" +
                "&leaderPersonName1=&leaderPersonNameSpanId1=&yieDistrict1="+URLEncoder.encode(csdm,"utf-8")+"&etpsSzhyInfo.yieDistrict="+URLEncoder.encode(qhdm,"utf-8")+"&etpsSzhyInfo.proLoc="+URLEncoder.encode("河北省石家庄市"+ Global.getCityName() ,"utf-8")+"&etpsSzhyInfo.finaName="+URLEncoder.encode(cwfzr ,"utf-8")+
                "&FinalNameChecked="+URLEncoder.encode(cwfzr+";"+cwfzrsfz,"utf-8")+"&etpsSzhyInfo.finaTel="+URLEncoder.encode(cwfzrsjh,"utf-8")+"&etpsSzhyInfo.finaCetfType=1&etpsSzhyInfo.finaCetfId="+URLEncoder.encode(cwfzrsfz,"utf-8")+"&etpsSzhyInfo.finaMobile=" +
                "&etpsSzhyInfo.finaMail=&organId="+URLEncoder.encode(qhdm,"utf-8")+"&deptId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getDetpid()),"utf-8")+ "&staffName="+URLEncoder.encode(gtgsYwUser.getName(),"utf-8")+"&userId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getUserid()),"utf-8")+"&subscriptionDate="+URLEncoder.encode(String.valueOf(pym.get("subscriptionDate")),"utf-8")+
                "&staffName="+URLEncoder.encode(gtgsYwUser.getName(),"utf-8")+"&organId="+URLEncoder.encode(qhdm,"utf-8") + "&userId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getUserid()),"utf-8")+"&deptId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getDetpid()),"utf-8")+ "&subscriptionDate="+URLEncoder.encode(String.valueOf(pym.get("subscriptionDate")),"utf-8")+"&resultTemp=" +
                "&needCheckTemp=&statusId=&actnId=0039&resultId=&netPlanDate=&acceptNotice=01&textOpnn=&flowType=03&tokenDate="+URLEncoder.encode(String.valueOf(pym.get("tokenDate")),"utf-8")+"&submitMode="+s;
       */

        //为预核名称 打开提交人员信息的 str
       str="appNo="+pym.get("appNo")+"&etpsId=&flowId=001001&actnId=0039&modifyAppActv=&appTypeId=02&subObjId=10&appCaseType=&applyOrgan="+URLEncoder.encode(qhdm,"utf-8")+"&ifTempSave=true&currentStatus=0032&sessionUuid="+pym.get("sessionUuid")+
                "&gddServiceJson=&gddOldName=&regOrgan="+URLEncoder.encode(qhdm,"utf-8")+"&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[0]+"&appendixId=0&appendixName="+URLEncoder.encode("《公司登记（备案）申请书》","utf-8")+
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=0&etpsAppendixBoId="+arr[1]+"&appendixId=1&appendixName="+URLEncoder.encode("公司章程（有限责任公司由全体股东签署，股份有限公司由全体发起人签署）","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[2]+"&appendixId=2&appendixName="+URLEncoder.encode("股东、发起人的主体资格证明或自然人身份证明","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[3]+"&appendixId=3&appendixName="+URLEncoder.encode("法定代表人、董事、监事和经理的任职文件","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=1&etpsAppendixBoId="+arr[4]+"&appendixId=4&appendixName="+URLEncoder.encode("住所使用证明","utf-8")+"&receiveDate="+URLEncoder.encode(date,"utf-8")+
                "&needApply=0&description=&etpsAppendixDeleteFlag=0&etpsAppendixHandinSwitch=on&etpsAppendixHandin=0&etpsAppendixBoId="+arr[5]+"&appendixId=5&appendixName="+URLEncoder.encode("法律、行政法规和国务院决定规定设立公司必须报经批准的或公司申请登记的经营范围中有法律、行政法规和国务院决定规定必须在登记前报经批准的项目，提交有关批准文件或者许可证件的复印件","utf-8") +
                "&receiveDate="+URLEncoder.encode(date,"utf-8")+"&needApply=0&description=&etpsAppendixDeleteFlag=0&nameTrad=&tradPiny=&nameExtra=&etpsName="+URLEncoder.encode(info.getQyname(),"utf-8")+"&etpsNameId=&nameAppNo="+pym.get("nameAppNo")+"&nmId="+
                "&directAcceptClick=&webStatusId=&grpName=&isPCom=&groupName=&groupNameTemp=&cerNoQuery=&agentbiaoSiNameChecked="+URLEncoder.encode(wtr+";"+info.getWtrcardno(),"utf-8")+
                "&agentbiaoSiName=&organId="+URLEncoder.encode(qhdm,"utf-8")+"&deptId=&flowId=001001"
                + "&actnId=0039&userId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getUserid()),"utf-8")+"&staffName="
                +URLEncoder.encode(gtgsYwUser.getName(),"utf-8")
                +"&applicantName="+URLEncoder.encode(wtr,"utf-8")+
                "&cerTypeGb=1&cerNo="+URLEncoder.encode(info.getWtrcardno(),"utf-8")+"&agentTelephone=&fjProxyQQ=&appDate="+URLEncoder.encode(DateUtils.dateTime(info.getCreatedate()),"utf-8")+"&=&=" +
                "&validContactName="+URLEncoder.encode(lly+";"+llysfz,"utf-8")+"&contactName=&persnName="+URLEncoder.encode(lly,"utf-8")+"&contactAddress=&contactCetfType=1&contactCetfId="+URLEncoder.encode(llysfz,"utf-8")+"&contactTelephone=&contactMobile="+URLEncoder.encode(llysjh,"utf-8")+
                "&contactMail=&contactPostcode=&etpsTypeGb="+URLEncoder.encode(qylx,"utf-8")+"&isPrivate=1&fjEtpsSort1=2&fjEtpsSort=2&fjCityFlag="+URLEncoder.encode(qyss,"utf-8") +
                "&toEdit=1&areaId="+URLEncoder.encode(csdm,"utf-8")+"&fjCounty="+URLEncoder.encode(qhdm,"utf-8")+"&districtExtraSelect=&districtExtra=&fjStreet=&fjNeigbor=&road=&address="+URLEncoder.encode(info.getQyjycs(),"utf-8")+"&areaOrganId1="+URLEncoder.encode(csdm,"utf-8") +
                "&areaOrganId="+qhdm+"&roomRight="+jycscq+"&mailAddr="+URLEncoder.encode("无","utf-8")+"&postcode=050000&telephone="+URLEncoder.encode(info.getQylxdh(),"utf-8")+"&establishType=01&leaderPersonName="+URLEncoder.encode(info.getFrname(),"utf-8")+
                "&cptlTotal="+URLEncoder.encode(info.getQyzczj(),"utf-8")+".000000&cptlCrncyId=002&cptlRmb="+URLEncoder.encode(info.getQyzczj(),"utf-8")+ "&tradeTermType="+URLEncoder.encode(jyqx,"utf-8")+"&tradeYears="+URLEncoder.encode(tradeYears,"utf-8")+"&tradeStartDate="+URLEncoder.encode(tradeStartDate,"utf-8")+"&tradeEndDate="+URLEncoder.encode(tradeEndDate,"utf-8")+
                "&empNum="+URLEncoder.encode(info.getQycyrs(),"utf-8")+ "&unemploymentNum=&offJobNumb=&licenceId="+arr3[0]+"&licenceSeqNo=&licenceNo=" +
                "&licenceTypeId=01&licenceDataType=1&licenceNumb=1&licenceId="+arr3[1]+"&licenceSeqNo=&licenceNo=&licenceTypeId=07&licenceDataType=2&licenceNumb=1&isProvideDzyyzz=1&licCardCnt=1&fjFileNo="+pym.get("fjFileNo")+
                "&delIds=&fjMergerSplit=&industryCode111="+pym.get("industryCode111")+"&industryPhy="+pym.get("industryCode111")+"&industryCode1="+pym.get("industryCode111")+"&industryCode=&industryCode2=&industryCode3="+
                "&foodTrdTypeId=&trdScope="+URLEncoder.encode(info.getQyjyfw(),"utf-8")+"&dzhyAppNo=&estPartyFlag="+URLEncoder.encode(djxx.getIsdangjian(),"utf-8")+"&estPartyTime=&insId=&orgId=&partyNum=&permitInfoTemp=&etType0=" +
                "&ifInitiator=0&investorTempId="+arr1[0]+"&nationality_check_investor_"+arr1[0]+"=156&nationId_check_investor_"+arr1[0]+"=01&investor_type_"+arr1[0]+"=0101&domzeCptlTotal=0.000000"+ arr2 +
                "&domzeCptlDollar=&domzeCptlPercent=" +
                "&frgnCptl=&investorFrgnCptlDollar=&frgnCptlPercent=&domzeActlTotal=&domzeActllDollar=&domzeActlPercent=&frgnActl=&frgnActlDollar=&frgnActlPercent=&actlDollar=&ifCollege=&checkInvestmentOverdue=&isFddbr=" +
                "&leaderPersonName1=&leaderPersonNameSpanId1=&yieDistrict1="+URLEncoder.encode(csdm,"utf-8")+"&etpsSzhyInfo.yieDistrict="+URLEncoder.encode(qhdm,"utf-8")+"&etpsSzhyInfo.proLoc="+URLEncoder.encode("河北省"+Global.getSuperCity()+ Global.getCityName() ,"utf-8")+"&etpsSzhyInfo.finaName="+URLEncoder.encode(cwfzr ,"utf-8")+
                "&FinalNameChecked="+URLEncoder.encode(cwfzr+";"+cwfzrsfz,"utf-8")+"&etpsSzhyInfo.finaTel="+URLEncoder.encode(cwfzrsjh,"utf-8")+"&etpsSzhyInfo.finaCetfType=1&etpsSzhyInfo.finaCetfId="+URLEncoder.encode(cwfzrsfz,"utf-8")+"&etpsSzhyInfo.finaMobile=" +
                "&etpsSzhyInfo.finaMail=&organId="+URLEncoder.encode(qhdm,"utf-8")+"&deptId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getDetpid()),"utf-8")+ "&staffName="+URLEncoder.encode(gtgsYwUser.getName(),"utf-8")+"&userId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getUserid()),"utf-8")+"&subscriptionDate="+URLEncoder.encode(String.valueOf(pym.get("subscriptionDate")),"utf-8")+
                "&staffName="+URLEncoder.encode(gtgsYwUser.getName(),"utf-8")+"&organId="+URLEncoder.encode(qhdm,"utf-8") + "&userId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getUserid()),"utf-8")+"&deptId="+URLEncoder.encode(String.valueOf(gtgsYwUser.getDetpid()),"utf-8")+ "&subscriptionDate="+URLEncoder.encode(String.valueOf(pym.get("subscriptionDate")),"utf-8")+"&resultTemp=" +
                "&needCheckTemp=&statusId=&actnId=0039&resultId=&netPlanDate=&acceptNotice=01&textOpnn=&flowType=03&tokenDate="+URLEncoder.encode(String.valueOf(pym.get("tokenDate")),"utf-8")+"&submitMode="+s+gd;
        String s1="";
        try {
            s1= HttpUtils.sendPost(Global.getConfig("ruoyi.pyip")+"/companyAdd",str);
        }catch (RuntimeException e){
            System.err.println("同步请求异常:"+e);
            return AjaxResult.error("同步异常");
        }finally {
            return AjaxResult.success(s1);
        }


    }


}
