package com.engine.htsc.duban.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.collaboration.service.TaskLogService;
import com.engine.htsc.duban.service.DubanService;
import com.engine.htsc.duban.service.impl.DubanServiceImpl;
import com.engine.integration.gconst.IntegrationConstant;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.formmode.virtualform.VirtualFormHandler;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.GlobatTools.Smstools;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.workflow.workflow.WorkflowBillComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class DubanAction {


    public DubanService getService(){
        return ServiceUtil.getService(DubanServiceImpl.class);
    }

    /**
     *
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/createTask")
    @Produces({MediaType.TEXT_PLAIN})
    public String createTask(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.checkUser(request, response);
            if (user == null) {
                apidatas.put("msg", "登录信息超时");
                apidatas.put("errorCode", "002");
                apidatas.put("api_status", false);
                apidatas.put(IntegrationConstant.INTEGRATION_RESULT_STATUS, IntegrationConstant.INTEGRATION_RESULT_STATUS_FALSE);
            }else{
                Map<String,Object> param = ParamUtil.request2Map(request);
                apidatas = getService().createTask(param,user);
                apidatas.put("api_status", true);
            }
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @GET
    @Path("/createSubTask")
    @Produces({MediaType.TEXT_PLAIN})
    public String createSubTask(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.checkUser(request, response);
            if (user == null) {
                apidatas.put("msg", "登录信息超时");
                apidatas.put("errorCode", "002");
                apidatas.put("api_status", false);
                apidatas.put(IntegrationConstant.INTEGRATION_RESULT_STATUS, IntegrationConstant.INTEGRATION_RESULT_STATUS_FALSE);
            }else{
                Map<String,Object> param = ParamUtil.request2Map(request);
                apidatas = getService().createSubTask(param,user);
                apidatas.put("api_status", true);
            }
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @GET
    @Path("/doSave")
    @Produces({MediaType.TEXT_PLAIN})
    public String doSave(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String,Object> map = new HashMap<>();
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        try{
            WorkflowBillComInfo workflowBillComInfo = new WorkflowBillComInfo();
            Integer billid = Util.getIntValue(request.getParameter("billid"));
            String formId = Util.null2String(request.getParameter("formId"));
            String JSONStr = Util.null2String(request.getParameter("JSONStr"));
            //1.获取表名
            String tableName = VirtualFormHandler.getRealFromName(Util.null2String(workflowBillComInfo.getTablename(formId)));
            bb.writeLog("当前表名--"+tableName);
            //2.解析表单数据
            JSONObject dataObject = JSONObject.parseObject(JSONStr);
            bb.writeLog("JSONStr=="+dataObject);
            //2.1 获取真实对应数据
            List<String> list = new ArrayList<>();
            if (dataObject != null && !dataObject.isEmpty()){
                for (Object str : dataObject.keySet()){
                    //2.2 截取field12345
                    String field = str.toString();
                    String id = field.substring(5);
                    rs.executeQuery("select fieldname from workflow_billfield where id = ?",new Object[]{id});
                    if (rs.next()){
                        String fieldname = Util.null2String(rs.getString("fieldname"));
                        String value = fieldname +" = '"+ dataObject.get(str)+"'";
                        list.add(value);
                    }
                }
                String datas = StringUtils.join(list, ",");
                bb.writeLog("拼接更新数据=="+datas);
                String updateFormSql = "update "+tableName+" set "+datas+" where id = ?";
                bb.writeLog("更新语句=="+updateFormSql);
                rs.executeUpdate(updateFormSql,billid);
            }
            map.put("status",1);
            map.put("msg","success");
        }catch (Exception e){
            map.put("status",-1);
            map.put("msg","fail");
            e.printStackTrace();

        }
        return JSON.toJSONString(map);
    }


    @POST
    @Path("/doPostModifyLog")
    @Produces({MediaType.TEXT_PLAIN})
    public String TaskToUser(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(request, response);
            String billid = Util.null2String(request.getParameter("billid"));
            String title= Util.null2String(request.getParameter("title"));
            String context  = Util.null2String(request.getParameter("context"));
            String sjlx= Util.null2String(request.getParameter("sjlx"));
            String jllx= Util.null2String(request.getParameter("jllx"));
            if("".equals(sjlx)){
                sjlx="0";
            }
            if("".equals(billid)||"".equals(title)||"".equals(context)){
                apidatas.put("status", false);
                apidatas.put("errormsg", "传递参数为空");
            }

            TaskLogService taskLogService = new TaskLogService();
            taskLogService.createTaskLog(user,billid,"",jllx,sjlx,context,title);
            apidatas.put("status", "true");
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("status", false);
            apidatas.put("errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @POST
    @Path("/doPostTaskSmsToUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String TaskSmsToUser(@Context HttpServletRequest request, @Context HttpServletResponse response){
        PropBean propBean = new PropBean();
        Smstools smstools=new Smstools();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            String billid = Util.null2String(request.getParameter("billid"));
            String smsuser = Util.null2String(request.getParameter("smsuser"));
            String bt= Util.null2String(request.getParameter("bt"));
            String context  = Util.null2String(request.getParameter("context"));
            if(billid ==""|| smsuser==""|| bt==""){
                apidatas.put("status", false);
                apidatas.put("errormsg", "传递参数为空");
            }
            int smstypeid = Integer.parseInt(Util.null2String(propBean.getPropName("uf_ry_sms")));
            Set<String> setuseridvalue = new HashSet(Arrays.asList(smsuser.split(",")));
            if(setuseridvalue.size()>0){

                String url = propBean.getPropName("dbrw_mobile_url");
                String link = url+"&billid="+billid;

                boolean flag = smstools.sendMessage(smstypeid,setuseridvalue,bt,context,link,link);
                if(!flag){
                    apidatas.put("errmsg","消息发送失败");
                    apidatas.put("status", "false");
                }
            }
            apidatas.put("status", "true");
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("status", false);
            apidatas.put("errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @GET
    @Path("/feedbackList")
    @Produces({MediaType.TEXT_PLAIN})
    public String feedbackList(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.checkUser(request, response);
            if (user == null) {
                apidatas.put("msg", "登录信息超时");
                apidatas.put("errorCode", "002");
                apidatas.put("api_status", false);
                apidatas.put(IntegrationConstant.INTEGRATION_RESULT_STATUS, IntegrationConstant.INTEGRATION_RESULT_STATUS_FALSE);
            }else{
                Map<String,Object> param = ParamUtil.request2Map(request);
                apidatas = getService().getDataList(param,user);
                apidatas.put("api_status", true);
            }
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/reloadzUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String reloadzUser(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            String xzbillid = Util.null2String(request.getParameter("billid"));
            if( xzbillid =="" || Util.getIntValue(xzbillid)<0){
                apidatas.put("flag", "false");
                return  JSON.toJSONString(apidatas);
            }

            RecordSet rs = new RecordSet();
            BaseBean beanBean = new BaseBean();
            beanBean.writeLog("开始做协作任务人员同步！！！！");
            String jbr="";
            String tzydr="";
            String distinctjbr="";
            String distincttzydr="";
            String sqlvalue=" select wm_concat_old(jbr) as jbr,wm_concat_old(gzr) as gzr from uf_rw  where dbsy='"+xzbillid+"'";
            beanBean.writeLog("协作查询所有jbr和gzr的sql："+sqlvalue);
            rs.execute(sqlvalue);
            if(rs.next()){
                jbr = Util.null2String(rs.getString("jbr")) ;
                tzydr = Util.null2String(rs.getString("gzr"));
            }
            distinctjbr = disinctry(jbr.split(","));
            distincttzydr = disinctry(tzydr.split(","));
            String sqlupdatevalue = "update uf_xzsx set jbr=?,tzydr=? where id='"+xzbillid+"'";
            beanBean.writeLog("协作跟新语句："+sqlupdatevalue+" jbr:"+distinctjbr+"tzydr:"+distincttzydr);
            rs.executeUpdate(sqlupdatevalue, distinctjbr,distincttzydr);
            apidatas.put("flag", "true");
        }catch (Exception e) {
            apidatas.put("flag", "false");
            apidatas.put("error", e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    public String disinctry(String[] array){

        if(array == null || array.length<0 ){
            return "";
        }
        String ryvalue="";
        List<String> listarray= Arrays.asList(array);
        List list=(List) listarray.stream().distinct().collect(Collectors.toList());
        ryvalue=String.join(",", list);
        return ryvalue;
    }

    @GET
    @Path("/reportlist")
    @Produces({MediaType.TEXT_PLAIN})
    public String ReportList(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();

        try{
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().getreportList(param,user);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @GET
    @Path("/dynamicslist")
    @Produces({MediaType.TEXT_PLAIN})
    public String dynamicsList(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().getdynamicsList(param,user);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/TaskShareUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String TaskShareUser(@Context HttpServletRequest request, @Context HttpServletResponse response){
        PropBean propBean = new PropBean();
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        ModeRightInfo mode=new ModeRightInfo();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        SimpleDateFormat sd= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String datetime = sd.format(new Date());
        String rwbillid="";
        try{
            User user = HrmUserVarify.getUser(request, response);

            String modedatacreater = "" ;
            String sql = " select modedatacreater from uf_xzsx where id="+rwbillid ;
            rs.execute(sql);
            if(rs.next()){
                modedatacreater = Util.null2String(rs.getString("modedatacreater"));
            }

            rwbillid = Util.null2String(request.getParameter("billid"));
            String bgxr = Util.null2String(request.getParameter("bgxr"));
            if(rwbillid==""||bgxr==""){
                apidatas.put("status", false);
                apidatas.put("errormsg", "传递参数为空");
            }
            String sqlvalue="";
            String userarray= JAVATools.disinctrlist(bgxr.split(","));
            bb.writeLog("userarray:"+userarray);
            String[] userlist = userarray.split(",");
            for (int i=0;i<userlist.length;i++) {
                if(!"".equals(userlist[i])) {
                    bb.writeLog("userlist:"+userlist[i]);
                    try {
                        String usernewid=JAVATools.getmainhrmid(userlist[i]);
                        sqlvalue = "insert into uf_rw_dt2(mainid,czr,bgxr,gxsj) values(?,?,?,?)";
                        rs.executeQuery(sqlvalue, new Object[]{rwbillid, user.getUID(), usernewid, datetime});

                    }catch (Exception exo){
                    }
                }
            }

            JSONObject jsonObject= propBean.getModeInfoByUUID(propBean.getPropName("UF_RW_CUBEUUID"));
            int nodeid = Integer.parseInt(jsonObject.get("modeid").toString());
            mode.rebuildModeDataShareByEdit(Util.getIntValue(modedatacreater),nodeid,Integer.parseInt(rwbillid));

            apidatas.put("status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("status", false);
            apidatas.put("errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/CooperationShareUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String CooperationShareUser(@Context HttpServletRequest request, @Context HttpServletResponse response){
        PropBean propBean = new PropBean();
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        ModeRightInfo mode = new ModeRightInfo();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        SimpleDateFormat sd= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String datetime=sd.format(new Date());
        try{
            User user = HrmUserVarify.getUser(request, response);

            String rwbillid = Util.null2String(request.getParameter("billid"));
            String bgxr = Util.null2String(request.getParameter("bgxr"));
            if(rwbillid =="" || bgxr==""){
                apidatas.put("status", false);
                apidatas.put("errormsg", "传递参数为空");
            }

            String modedatacreater = "" ;
            List<String> tzydrList = new ArrayList<>();
            String sql = " select modedatacreater,tzydr from uf_xzsx where id="+rwbillid ;
            rs.execute(sql);
            if(rs.next()){
                modedatacreater = Util.null2String(rs.getString("modedatacreater"));
                String tzydr = Util.null2String(rs.getString("tzydr"));
                if(org.apache.commons.lang.StringUtils.isNotEmpty(tzydr)){
                    tzydrList.addAll(Arrays.asList(tzydr.split(",")));
                }
            }

            String userarray = JAVATools.disinctrlist(bgxr.split(","));
            bb.writeLog("userarray:"+userarray);
            String[] userlist = userarray.split(",");
            for (int i=0;i<userlist.length;i++)
            {
                bb.writeLog("userlist:"+userlist[i]);
                if(!"".equals(userlist[i])) {
                    try {
                        String usernewid=JAVATools.getmainhrmid(userlist[i]);

                        //共享人添加到参与人，去重
                        boolean flag = false;
                        for(String tzydrid:tzydrList){
                            String tzydrmainid = JAVATools.getmainhrmid(tzydrid);
                            if(usernewid.equals(tzydrmainid)){
                                flag = true;
                                break;
                            }
                        }
                        if(!flag){
                            tzydrList.add(userlist[i]);
                        }

                        String sqlvalue = "insert into uf_xzsx_dt1(mainid,czr,bgxr,gxsj) values(?,?,?,?)";
                        rs.executeQuery(sqlvalue, new Object[]{rwbillid, user.getUID(), usernewid, datetime});
                    }catch (Exception ex){
                        bb.writeLog("e:"+ex);
                    }
                }
            }

            String newtzydr = String.join(",",tzydrList);
            String tzydzzhyc = "" ;
            if(!"".equals(newtzydr)){
                tzydzzhyc= JAVATools.GetZctogid(newtzydr);
            }
            String updateSql = "update uf_xzsx set tzydr = '"+newtzydr+"', tzydzzhyc = '"+tzydzzhyc+"'  where id = '"+rwbillid+"'";
            rs.executeUpdate(updateSql);

            JSONObject jsonObject = propBean.getModeInfoByUUID(propBean.getPropName("UF_DBSX_CUBEUUIUD"));
            int modeid =  Integer.parseInt(jsonObject.get("modeid").toString());
            mode.rebuildModeDataShareByEdit(Util.getIntValue(modedatacreater),modeid,Integer.parseInt(rwbillid));
            //mode.rebuildModeDataShareByEdit();
            apidatas.put("status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("status", false);
            apidatas.put("errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @GET
    @Path("/taskDelete")
    @Produces({MediaType.TEXT_PLAIN})
    public String taskDelete(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            BaseBean bs = new BaseBean();
            RecordSet rs = new RecordSet();
            String taskid = Util.null2String(request.getParameter("taskid"));
            //0正常 1搁置
            try {
                if(!"".equals(taskid))
                {
                    String rwzt = "" ;
                    String sql = " select rwzt from uf_rw where id = "+taskid ;
                    bs.writeLog("sql:"+sql);
                    rs.execute(sql);
                    if(rs.next()){
                        rwzt = Util.null2String(rs.getString("rwzt"));
                    }
                    bs.writeLog("rwzt:"+rwzt);
                    if("0".equals(rwzt))
                    {
                        sql = " delete from uf_rw where id="+taskid;
                        boolean bool = rs.execute(sql);
                        if(bool)
                        {
                            apidatas.put("api_status", true);
                            apidatas.put("status","1");
                            apidatas.put("message","任务已删除!");
                        }else{
                            apidatas.put("api_status", false);
                            apidatas.put("status","-6");
                            apidatas.put("message","任务删除失败!");
                        }
                    }else{
                        apidatas.put("api_status", false);
                        apidatas.put("status","-5");
                        apidatas.put("message","任务状态不是草稿，无法删除!");
                    }
                }
            }catch (Exception e){
                apidatas.put("api_status", false);
                apidatas.put("status","-2");
                apidatas.put("message","系统错误,请联系系统管理员");
                bs.writeLog(e);
            }
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @GET
    @Path("/dbxzDelete")
    @Produces({MediaType.TEXT_PLAIN})
    public String dbxzDelete(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().dbxzDelete(param,user);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @GET
    @Path("/doGetDbComplete")
    @Produces({MediaType.TEXT_PLAIN})
    public String doGetDbComplete(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().doGetDbComplete(param,user);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @GET
    @Path("/doGetTopButton")
    @Produces({MediaType.TEXT_PLAIN})
    public String doGetTopButton(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(request, response);
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().doGetTopButton(param,user);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @GET
    @Path("/dubanDelete")
    @Produces({MediaType.TEXT_PLAIN})
    public String dubanDelete(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            BaseBean bs = new BaseBean();
            RecordSet rs = new RecordSet();
            String billid = Util.null2String(request.getParameter("billid"));
            //0正常 1搁置
            try {
                if(!"".equals(billid))
                {
                    String xzzt = "" ;
                    String sql = " select xzzt from uf_xzsx where id = "+billid ;
                    bs.writeLog("sql:"+sql);
                    rs.execute(sql);
                    if(rs.next()){
                        xzzt = Util.null2String(rs.getString("xzzt"));
                    }
                    bs.writeLog("xzzt:"+xzzt);
                    if("0".equals(xzzt))
                    {
                        sql = " delete from uf_xzsx where id="+billid;
                        boolean bool = rs.execute(sql);
                        if(bool)
                        {
                            apidatas.put("api_status", true);
                            apidatas.put("status","1");
                            apidatas.put("message","督办删除成功");
                        }else{
                            apidatas.put("api_status", false);
                            apidatas.put("status","-6");
                            apidatas.put("message","督办删除失败");
                        }
                    }else{
                        apidatas.put("api_status", false);
                        apidatas.put("status","-5");
                        apidatas.put("message","督办不是草稿状态,无法删除");
                    }
                }
            }catch (Exception e){
                apidatas.put("api_status", false);
                apidatas.put("status","-2");
                apidatas.put("message","系统错误,请联系系统管理员");
                bs.writeLog(e);
            }
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }
}
