package com.engine.htsc.seal.service;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.core.impl.Service;
import com.engine.htsc.seal.entity.PrintLogEntity;
import com.engine.htsc.seal.entity.SealInfoEntity;
import com.htsc.ibpms.api.dto.ai.common.AICommonRequestDto;
import com.htsc.ibpms.api.dto.taskDistributor.*;
import com.htsc.ibpms.api.service.ITaskDistributorService;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.htsc.cus.HTUtil;
import weaver.interfaces.htsc.gwlc.WrokflowToOAUtil;

import java.lang.reflect.Field;
import java.util.*;

public class SealInformationService extends Service {

    /**
     * 创建用印信息
     * @param sealInfo
     * @return
     */
    public Map<String, Object> createSealInfo(SealInfoEntity sealInfo){
        BaseBean bs = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        Map<String, Object> result = new HashMap<>();

        try{
            if(sealInfo!=null){
                String yyxxmodeid = pb.getPropName("UF_YYXX_CUBEUUIUD");
                JSONObject jsonObject_yyxx = pb.getModeInfoByUUID(yyxxmodeid);
                int modeid = Util.getIntValue(jsonObject_yyxx.getString("modeid"));

                String uuid = UUID.randomUUID().toString();
                sealInfo.setModeuuid(uuid);
                sealInfo.setFormmodeid(modeid);
                sealInfo.setModedatacreater(Integer.valueOf(sealInfo.getNgr()));
                sealInfo.setModedatacreatertype(0);
                sealInfo.setModedatacreatedate(TimeUtil.getCurrentDateString());
                sealInfo.setModedatacreatetime(TimeUtil.getOnlyCurrentTimeString());

                bs.writeLog("sealInfo:"+ JSON.toJSONString(sealInfo));

                Class<?> clazz = sealInfo.getClass();
                Field[] fields = clazz.getDeclaredFields();
                String insertFields = " insert into uf_yyxx(";
                String paramsStr  = " values(";
                Object[] values = new Object[fields.length];
                for(int i=0;i<fields.length;i++){
                    fields[i].setAccessible( true );
                    if(i==fields.length-1){
                        insertFields += fields[i].getName()+" )";
                        paramsStr += "? )";
                    }else{
                        insertFields += fields[i].getName()+",";
                        paramsStr += "?,";
                    }
                    try{
                        values[i] = fields[i].get(sealInfo);
                    }catch (Exception e){
                        new BaseBean().writeLog("保存用印信息数据错误："+e);
                    }
                }
                String insertSql = insertFields + paramsStr;
                bs.writeLog("insertSql:"+insertSql);
                boolean res = rs.executeQuery(insertSql,values);
                bs.writeLog("res:"+res);

                if(res){
                    int billid = 0;
                    rs.executeQuery("select id from uf_yyxx where modeuuid='"+uuid+"'" );
                    if (rs.next()) {
                        billid = Util.getIntValue( rs.getString( "id" ) );
                        bs.writeLog("billid:"+billid);
                        ModeRightInfo moderight = new ModeRightInfo();
                        moderight.editModeDataShare(sealInfo.getModedatacreater(),sealInfo.getFormmodeid(),billid);
                    }

                    result.put("billid",billid);
                    result.put("status","1");
                    result.put("message","创建成功");
                }else {
                    result.put("billid","0");
                    result.put("status","-1");
                    result.put("message","创建失败");
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
            result.put("billid","0");
            result.put("status","-2");
            result.put("message","系统错误,请联系系统管理员");
        }
        return result;
    }

    /**
     * 用印变更后更新信息
     * @param sealMap
     */
    public void updateSealInfo(Map<String,String> sealMap){
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();

        String wjmc = sealMap.get("wjmc");
        String gllc = sealMap.get("gllc");
        if(StringUtils.isEmpty(wjmc)||StringUtils.isEmpty(gllc)){
            return;
        }

        String id = sealMap.get("yyxxid");
        if (StringUtils.isEmpty(id)){
            return;
        }

        String yyzt = sealMap.get("yyzt");
        String scwj = StringUtils.isNotEmpty(sealMap.get("scwj"))?sealMap.get("scwj"):"";
        String yyhwj = StringUtils.isNotEmpty(sealMap.get("yyhwj"))?sealMap.get("yyhwj"):"";
        String yqxdyr = StringUtils.isNotEmpty(sealMap.get("yqxdyr"))?sealMap.get("yqxdyr"):"";
        String yyfs = StringUtils.isNotEmpty(sealMap.get("yyfs"))?sealMap.get("yyfs"):"";
        String dzyyfs = StringUtils.isNotEmpty(sealMap.get("dzyyfs"))?sealMap.get("dzyyfs"):"";
        String dsmdy = StringUtils.isNotEmpty(sealMap.get("dsmdy"))?sealMap.get("dsmdy"):"";
        String fwdyfs = StringUtils.isNotEmpty(sealMap.get("fwdyfs"))?sealMap.get("fwdyfs"):"";
        String wlyyfs = StringUtils.isNotEmpty(sealMap.get("wlyyfs"))?sealMap.get("wlyyfs"):"";
        String yyid = StringUtils.isNotEmpty(sealMap.get("yyid"))?sealMap.get("yyid"):"";

        String update_sql = "update uf_yyxx set yqxdyr = '"+yqxdyr+"', yyfs = '"+yyfs+"', dzyyfs = '"+dzyyfs+"', dsmdy = '"+dsmdy+"', " +
                "fwdyfs = '"+fwdyfs+"', wlyyfs = '"+wlyyfs+"', yyid = '"+yyid+"'";
        if(StringUtils.isNotEmpty(yyhwj)){
            update_sql += ", yywj = '"+yyhwj+"'";
        }
        if(StringUtils.isNotEmpty(scwj)){
            update_sql += ", ywj = '"+scwj+"'";
        }

        if("3".equals(yyzt)){//已用印
            update_sql += ", wjzt = '0' where id = '"+id+"'";
            bs.writeLog(update_sql);
            rs.executeUpdate(update_sql);
        }else if("2".equals(yyzt)){//用印中
            update_sql += ", wjzt = '1' where id = '"+id+"'";
            bs.writeLog(update_sql);
            rs.executeUpdate(update_sql);
        }
    }

    /**
     * 获取用印信息
     * @param sql
     * @return
     */
    public Map<String, Object> getSealInfo(String sql){
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();
        Map<String, Object> resultMap = new HashMap<>();

        try{
            ResourceComInfo resourceComInfo = new ResourceComInfo();

            //获取基本信息
            List<Map<String,Object>> sealInfoList = new ArrayList<>();
            bs.writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                Map<String,Object> sealInfoMap = new HashMap<>();
                sealInfoMap.put("yyxxid",Util.null2String(rs.getString("id")));
                sealInfoMap.put("gllc",Util.null2String(rs.getString("gllc")));
                sealInfoMap.put("lcbh",Util.null2String(rs.getString("lcbh")));
                sealInfoMap.put("ngr",Util.null2String(rs.getString("ngr")));
                sealInfoMap.put("yygly",Util.null2String(rs.getString("yygly")));
                sealInfoMap.put("yz",Util.null2String(rs.getString("yz")));
                sealInfoMap.put("yywj",Util.null2String(rs.getString("yywj")));
                sealInfoMap.put("ywj",Util.null2String(rs.getString("ywj")));
                sealInfoMap.put("yqxdyr",Util.null2String(rs.getString("yqxdyr")));
                sealInfoMap.put("yyfs",Util.null2String(rs.getString("yyfs")));
                sealInfoMap.put("dzyyfs",Util.null2String(rs.getString("dzyyfs")));
                sealInfoMap.put("dsmdy",Util.null2String(rs.getString("dsmdy")));
                sealInfoMap.put("fwdyfs",Util.null2String(rs.getString("fwdyfs")));
                sealInfoMap.put("wlyyfs",Util.null2String(rs.getString("wlyyfs")));
                sealInfoMap.put("yyid",Util.null2String(rs.getString("yyid")));
                sealInfoMap.put("wjzt",Util.null2String(rs.getString("wjzt")));
                sealInfoMap.put("sfzw",Util.null2String(rs.getString("sfzw")));
                sealInfoMap.put("lylx",Util.null2String(rs.getString("lylx")));
                sealInfoList.add(sealInfoMap);
            }

            //查询拓展信息
            for(Map<String,Object> sealInfoMap:sealInfoList){
                if(StringUtils.isNotEmpty(sealInfoMap.get("yywj").toString())){
                    sql = "select imagefilename,operatedate,operatetime from DocImageFile where docid = '"+sealInfoMap.get("yywj").toString()+"'";
                    bs.writeLog(sql);
                    rs.executeQuery(sql);
                    if(rs.next()){
                        sealInfoMap.put("yywjName",Util.null2String(rs.getString("imagefilename")));
                        sealInfoMap.put("operatedate",Util.null2String(rs.getString("operatedate")));
                        sealInfoMap.put("operatetime",Util.null2String(rs.getString("operatetime")));
                    }
                }
                if(StringUtils.isNotEmpty(sealInfoMap.get("ywj").toString())){
                    sql = "select imagefilename from DocImageFile where docid = '"+sealInfoMap.get("ywj").toString()+"'";
                    bs.writeLog(sql);
                    rs.executeQuery(sql);
                    if(rs.next()){
                        sealInfoMap.put("ywjName",Util.null2String(rs.getString("imagefilename")));
                    }
                }
                if(StringUtils.isNotEmpty(sealInfoMap.get("ngr").toString())){
                    sealInfoMap.put("ngrName",resourceComInfo.getLastname(sealInfoMap.get("ngr").toString()));

                }
                if(StringUtils.isNotEmpty(sealInfoMap.get("yqxdyr").toString())){
                    List<Map<String,String>> yqxdyrMapList = new ArrayList<>();
                    for(String id:sealInfoMap.get("yqxdyr").toString().split(",")){
                        Map<String,String> userMap = new HashMap<>();
                        userMap.put("id",id);
                        userMap.put("name",resourceComInfo.getLastname(id));
                        yqxdyrMapList.add(userMap);
                    }
                    sealInfoMap.put("yqxdyrList",yqxdyrMapList);
                }
                if(StringUtils.isNotEmpty(sealInfoMap.get("yz").toString())){
                    List<Map<String,String>> yzMapList = new ArrayList<>();
                    for(String id:sealInfoMap.get("yz").toString().split(",")){
                        Map<String,String> yzMap = new HashMap<>();
                        sql = "select yzmc from uf_yinzhang where id = '"+id+"'";
                        bs.writeLog(sql);
                        rs.executeQuery(sql);
                        if(rs.next()){
                            yzMap.put("id",id);
                            yzMap.put("yzmc",Util.null2String(rs.getString("yzmc")));
                        }
                        yzMapList.add(yzMap);
                    }
                    sealInfoMap.put("yzList",yzMapList);
                }
                if(StringUtils.isNotEmpty(sealInfoMap.get("gllc").toString())){
                    sql = "select requestname from workflow_requestbase where requestid = '"+sealInfoMap.get("gllc").toString()+"'";
                    bs.writeLog(sql);
                    rs.executeQuery(sql);
                    while(rs.next()){
                        sealInfoMap.put("gllcName",Util.null2String(rs.getString("requestname")));
                    }
                }
                if(StringUtils.isNotEmpty(sealInfoMap.get("yyid").toString())){
                    String dzyyfs = sealInfoMap.get("dzyyfs").toString();
                    if("1".equals(dzyyfs)){
                        List<String> yyidList = new ArrayList<>();
                        yyidList.add(sealInfoMap.get("yyid").toString());

                        //查询e-seal获得打印份数
                        JSONObject resobject = getPrintInfo(yyidList);
                        String status = Util.null2String(resobject.get("status"));
                        if("200".equals(status)){
                            JSONArray jsonArray = resobject.getJSONArray("data");
                            for(int i=0;i<jsonArray.size();i++){
                                JSONObject date = jsonArray.getJSONObject(i);
                                String documnetId = date.getString("documnetId");
                                if(documnetId.equals(sealInfoMap.get("yyid").toString())){
                                    int totalNum = date.getInteger("totalNum");
                                    int printNum = date.getInteger("printNum");
                                    int allowedNum = totalNum-printNum;
                                    sealInfoMap.put("totalNum",totalNum);
                                    sealInfoMap.put("printNum",printNum);
                                    sealInfoMap.put("allowedNum",allowedNum);
                                    break;
                                }
                            }
                        }

                    }
                }
            }

            //脏数据太多，我累了，毁灭吧
//            //查询e-seal获得打印份数
//            JSONObject resobject = getPrintInfo(yyidList);
//            String status = Util.null2String(resobject.get("status"));
//            if("200".equals(status)){
//                JSONArray jsonArray = resobject.getJSONArray("data");
//                for(int i=0;i<jsonArray.size();i++){
//                    JSONObject date = jsonArray.getJSONObject(i);
//                    String documnetId = date.getString("documnetId");
//                    for(Map<String,Object> sealInfoMap:sealInfoList){
//                        if(StringUtils.isNotEmpty(sealInfoMap.get("yyid").toString())&&documnetId.equals(sealInfoMap.get("yyid").toString())){
//                            sealInfoMap.put("totalNum",date.getString("totalNum"));
//                            sealInfoMap.put("printNum",date.getString("printNum"));
//                            break;
//                        }
//                    }
//                }
//            }
            resultMap.put("sealInfoList",sealInfoList);
        }catch (Exception e){
            e.printStackTrace();
        }

        return resultMap;
    }

    /**
     * 查询用印信息
     * @param docidList
     * @return
     */
    public JSONObject getPrintInfo(List<String> docidList){
        PropBean pb = new PropBean();
        BaseBean bs = new BaseBean();
        HTUtil htUtil = new HTUtil();
        JSONObject resobject=new JSONObject();

        try{
            String appid = Util.null2String(pb.getPropName("AutoSign.appId"));//应用ID
            String secret = Util.null2String(pb.getPropName("AutoSign.secret"));//秘钥

            Map<String,Object> requestMap = new HashMap<>();
            requestMap.put("appId",appid);
            requestMap.put("secret",secret);
            requestMap.put("docIds",docidList);

            String response = htUtil.getPrintInfo(JSONArray.toJSON(requestMap).toString());
            bs.writeLog(response);
            if(StringUtils.isEmpty(response)){
                resobject.put("status","500");
                resobject.put("error","查询用印信息接口返回结果为空");
                return resobject;
            }
            resobject = JSONObject.parseObject(response);
            String status = Util.null2String(resobject.get("status"));//标识200-成功,否则失败
            String message = Util.null2String(resobject.get("message"));
            bs.writeLog("status:"+status);
            bs.writeLog("message:"+message);
        }catch (Exception e){
            e.printStackTrace();
            resobject.put("status","500");
            resobject.put("error","处理异常");
            return resobject;
        }
        bs.writeLog("getPrintInfo-----END-----");
        return resobject;
    }

    /**
     * 获得有权限的打印机信息
     * @return
     */
    public Map<String, Object> getPrinterInfo(String userid) {
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();
        Map<String, Object> resultMap = new HashMap<>();

        try {
            ResourceComInfo resourceComInfo = new ResourceComInfo();
            DepartmentComInfo departInfo = new DepartmentComInfo();
            String deptid = resourceComInfo.getDepartmentID(userid);
            List<Map<String,String>> printerList = new ArrayList<>();
            String sql = "select * from uf_fwdyjsq where ssjg = '"+deptid+"'";
            bs.writeLog(sql);
            rs.executeQuery(sql);
            while(rs.next()){
                Map<String,String> printerMap = new HashMap<>();
                printerMap.put("dyjmc",Util.null2String(rs.getString("dyjmc")));
                printerMap.put("ip",Util.null2String(rs.getString("ip")));
                printerMap.put("lxr",Util.null2String(rs.getString("lxr")));
                printerMap.put("ssjg",Util.null2String(rs.getString("ssjg")));
                printerMap.put("swwz",Util.null2String(rs.getString("swwz")));
                printerMap.put("lxrName",resourceComInfo.getLastname(Util.null2String(rs.getString("lxr"))));
                printerMap.put("ssjgName",departInfo.getDepartmentName(Util.null2String(rs.getString("ssjg"))));
                printerList.add(printerMap);
            }
            resultMap.put("printerInfo",printerList);
        }catch (Exception e){
            e.printStackTrace();
        }

        return resultMap;
    }


    /**
     * 防伪打印件打印
     * @param userid
     * @param printerIp
     * @param printDetail
     * @return
     */
    public Map<String, Object> print(String userid, String printerIp, String printDetail){
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();
        Map<String, Object> resultMap = new HashMap<>();

        try {
            ResourceComInfo resourceComInfo = new ResourceComInfo();
            DepartmentComInfo departInfo = new DepartmentComInfo();

            TaskStartReqDto req = new TaskStartReqDto();
            req.setTaskType("antiFakePrintAssistant");
            req.setSysCode("OA");
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("userName",resourceComInfo.getLastname(userid));
            paramsMap.put("userId",resourceComInfo.getLoginID(userid));
            paramsMap.put("fileSrcSys","OA");

            PrintLogEntity printLog = new PrintLogEntity();
            printLog.setFqr(userid);
            printLog.setFqsj(TimeUtil.getCurrentTimeString());
            printLog.setDyjip(printerIp);

            String sql = "select * from uf_fwdyjsq where ip = '"+printerIp+"'";
            bs.writeLog(sql);
            rs.executeQuery(sql);
            if(rs.next()){
                printLog.setSxdyj(Util.null2String(rs.getString("dyjmc")));
                paramsMap.put("printerName",Util.null2String(rs.getString("dyjmc")));
                paramsMap.put("printerIP",Util.null2String(rs.getString("ip")));
                paramsMap.put("printerOrg",departInfo.getDepartmentName(Util.null2String(rs.getString("ssjg"))));
                paramsMap.put("printerLocation",Util.null2String(rs.getString("swwz")));
            }

            List<PrintFileInfoDto> fileInfoList = new ArrayList<>();
            List<String> docidList = new ArrayList<>();

            JSONArray jsonArray = JSONObject.parseArray(printDetail);
            if(jsonArray.size()>0){
                for(int i=0;i<jsonArray.size();i++){
                    String infoid = jsonArray.getJSONObject(i).getString("infoid");
                    int printNum = jsonArray.getJSONObject(i).getInteger("printNum");
                    String imagefileid = "";
                    String imagefilename = "";
                    String fileid = "";
                    String realfilepath = "";
                    sql = "select t3.imagefileid,t3.imagefilename,t3.fileid,t3.filerealpath,t2.docid from uf_yyxx t1,docimagefile t2,imagefile t3 where t2.docid = t1.yywj and t3.imagefileid = t2.imagefileid and t1.id = '"+infoid+"'";
                    bs.writeLog(sql);
                    rs.executeQuery(sql);
                    if(rs.next()){
                        imagefileid = Util.null2String(rs.getString("imagefileid"));
                        imagefilename = Util.null2String(rs.getString("imagefilename"));
                        fileid = Util.null2String(rs.getString("fileid"));
                        realfilepath = Util.null2String(rs.getString("filerealpath"));
                        docidList.add(Util.null2String(rs.getString("docid")));
                    }
                    if(StringUtils.isEmpty(fileid)){
                        WrokflowToOAUtil wrokflowToOAUtil = new WrokflowToOAUtil();
                        wrokflowToOAUtil.uploadFile2SG(String.valueOf(imagefileid),imagefilename,realfilepath,"0");
                        sql = "select t3.imagefilename,t3.fileid from uf_yyxx t1,docimagefile t2,imagefile t3 where t2.docid = t1.yywj and t3.imagefileid = t2.imagefileid and t1.id = '"+infoid+"'";
                        bs.writeLog(sql);
                        rs.executeQuery(sql);
                        if(rs.next()){
                            imagefilename = Util.null2String(rs.getString("imagefilename"));
                            fileid = Util.null2String(rs.getString("fileid"));
                        }
                    }
                    PrintFileInfoDto fileInfo =  PrintFileInfoDto.builder()
                            .fileUniqueKey(fileid)
                            .fileName(imagefilename)
                            .printNum(printNum)
                            .build();
                    fileInfoList.add(fileInfo);
                }
            }
            paramsMap.put("fileInfoList", fileInfoList);
            req.setParamsMap(paramsMap);
            printLog.setSxwjxx(StringUtils.join(docidList,","));

            HTUtil htUtil = new HTUtil();
            String response = htUtil.doRpaPrint(JSON.toJSONString(req));
            bs.writeLog(response);
            if(StringUtils.isEmpty(response)){
                resultMap.put("status","500");
                resultMap.put("error","调用rpa防伪打印请求接口返回结果为空");
                return resultMap;
            }
            JSONObject resobject = JSONObject.parseObject(response);
            String code = Util.null2String(resobject.get("code"));//标识0-成功,否则失败
            if("0".equals(code)){
                resultMap.put("status","200");
                printLog.setSzygdyjg("打印成功");
            }else {
                String message = Util.null2String(resobject.get("message"));
                resultMap.put("status","500");
                resultMap.put("error",message);
                printLog.setSzygdyjg(message);
            }
            createPrinterlog(printLog);

        }catch (Exception e){
            e.printStackTrace();
        }
        return resultMap;
    }

    /**
     * 创建打印日志
     * @param printlog
     * @return
     */
    public Map<String, Object> createPrinterlog(PrintLogEntity printlog){
        BaseBean bs = new BaseBean();
        PropBean pb = new PropBean();
        RecordSet rs = new RecordSet();
        Map<String, Object> result = new HashMap<>();

        try{
            if(printlog!=null){
                String yyxxmodeid = pb.getPropName("UF_DYRZ_CUBEUUIUD");
                JSONObject jsonObject_dyrz = pb.getModeInfoByUUID(yyxxmodeid);
                int modeid = Util.getIntValue(jsonObject_dyrz.getString("modeid"));

                String uuid = UUID.randomUUID().toString();
                printlog.setModeuuid(uuid);
                printlog.setFormmodeid(modeid);
                printlog.setModedatacreater(Integer.valueOf(printlog.getFqr()));
                printlog.setModedatacreatertype(0);
                printlog.setModedatacreatedate(TimeUtil.getCurrentDateString());
                printlog.setModedatacreatetime(TimeUtil.getOnlyCurrentTimeString());

                bs.writeLog("printlog:"+ JSON.toJSONString(printlog));

                Class<?> clazz = printlog.getClass();
                Field[] fields = clazz.getDeclaredFields();
                String insertFields = " insert into uf_dyrz(";
                String paramsStr  = " values(";
                Object[] values = new Object[fields.length];
                for(int i=0;i<fields.length;i++){
                    fields[i].setAccessible( true );
                    if(i==fields.length-1){
                        insertFields += fields[i].getName()+" )";
                        paramsStr += "? )";
                    }else{
                        insertFields += fields[i].getName()+",";
                        paramsStr += "?,";
                    }
                    try{
                        values[i] = fields[i].get(printlog);
                    }catch (Exception e){
                        new BaseBean().writeLog("保存打印日志错误："+e);
                    }
                }
                String insertSql = insertFields + paramsStr;
                bs.writeLog("insertSql:"+insertSql);
                boolean res = rs.executeQuery(insertSql,values);
                bs.writeLog("res:"+res);

                if(res){
                    int billid = 0;
                    rs.executeQuery("select id from uf_dyrz where modeuuid='"+uuid+"'" );
                    if (rs.next()) {
                        billid = Util.getIntValue( rs.getString( "id" ) );
                        bs.writeLog("billid:"+billid);
                        ModeRightInfo moderight = new ModeRightInfo();
                        moderight.editModeDataShare(printlog.getModedatacreater(),printlog.getFormmodeid(),billid);
                    }

                    result.put("billid",billid);
                    result.put("status","1");
                    result.put("message","创建成功");
                }else {
                    result.put("billid","0");
                    result.put("status","-1");
                    result.put("message","创建失败");
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
            result.put("billid","0");
            result.put("status","-2");
            result.put("message","系统错误,请联系系统管理员");
        }
        return result;
    }
}
