package com.engine.htsc.tgpt.web;



import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.lhfxhgtysp.service.impl.LhfxhgtyspServiceImpl;
import com.engine.htsc.tgpt.service.TgptService;
import com.engine.htsc.tgpt.service.impl.TgptServiceImpl;
import weaver.conn.RecordSet;
import weaver.general.Util;

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.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810039
 * @version: 1.0
 * @CreateDate: 2022-08-19
 * @Description: 投关平台
 * @ModifyLog:
 **/
public class TgptAction {

    private TgptService getTgptService(){
        return ServiceUtil.getService(TgptServiceImpl.class);
    }

    /**
     * 获取内部关联人员的接口
     * @param req
     * @param rep
     * @return
     */
    @GET
    @Path("/getGlnbry")
    @Produces({MediaType.APPLICATION_JSON})
    public String getGlnbry(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        HashMap<String, Object> map = new HashMap<>();
        try{

            String xm = req.getParameter("xm");
            Map<String, String> glnbry = getTgptService().getGlnbry(xm);
            map.put("code",200);
            map.put("msg","success");
            map.put("data",glnbry);

        }catch (Exception e){
          map.put("code",500)  ;
          map.put("msg",e.getMessage().toString());
        }


        return JSONObject.toJSONString(map);
    }
    //select base.*,oper.* from workflow_requestbase base left join workflow_currentoperator oper on base.requestid = oper.requestid where oper.iscomplete = 0 and base.deleted = 0 and base.workflowid=64521 and base.requestid = 5577663

    /**
     *
     * @param req
     * @param rep
     * @return
     */
    @GET
    @Path("/getWorkflow")
    @Produces({MediaType.APPLICATION_JSON})
    public String getWorkflow(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        HashMap<String, Object> map = new HashMap<>();
        try{
            String billid = req.getParameter("billid");
            boolean workflow = getTgptService().getWorkflow(billid);
            map.put("code",200);
            map.put("msg","success");
            map.put("data",workflow);
        }catch (Exception e){
            map.put("code",500);
            map.put("msg",e.getMessage().toString());
            map.put("data","");

        }
        return JSONObject.toJSONString(map);

    }

    /**
     * 从第三方接口获取回答次数，和平均回答时间的接口
     */
    @GET
    @Path("/getNumAndTime")
    @Produces({MediaType.APPLICATION_JSON})
    public String getNumAndTime(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        HashMap<String, Object> map = new HashMap<>();
        try{
            Map<String, String> resMap = getTgptService().getNumAndTime();
            map.put("code",200);
            map.put("msg","success");
            map.put("data",resMap);
        }catch (Exception e){
            map.put("code",500);
            map.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(map);

    }

    /**
     * 尽调活动，根据billids获取活动参与人员，删除其日程
     */
    @GET
    @Path("/deleteRc")
    @Produces({MediaType.APPLICATION_JSON})
    public String deleteRc(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        Map<String, Object> apidatas = new HashMap<>();
        try{
            Map<String,Object> param = ParamUtil.request2Map(req);
            String billids = Util.null2String(param.get("billids"));
            apidatas = getTgptService().deleteRc(billids);
            apidatas.put("api_status","true");
        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("api_status","false");
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);

    }

    /**
     * 尽调活动删除，更新沟通数量
     */
    @GET
    @Path("/deleteJdhdAndUpdateGtsl")
    @Produces({MediaType.APPLICATION_JSON})
    public String deleteJdhdAndUpdateGtsl(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        Map<String, Object> apidatas = new HashMap<>();
        try{
            Map<String,Object> param = ParamUtil.request2Map(req);
            String billids = Util.null2String(param.get("billids"));
            apidatas = getTgptService().deleteJdhdAndUpdateGtsl(billids);
            apidatas.put("api_status", "true");

        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("api_status", "false");
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);

    }

    /**
     * 通讯录软删除，更新是否显示字段 sfxs = 1
     */
    @GET
    @Path("/updateYsc")
    @Produces({MediaType.APPLICATION_JSON})
    public String updateYsc(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        Map<String, Object> apidatas = new HashMap<>();
        try{
            Map<String,Object> param = ParamUtil.request2Map(req);
            String billids = Util.null2String(param.get("billids"));
            String tableName = Util.null2String(param.get("tableName"));
            apidatas = getTgptService().updateYsc(billids,tableName);
            apidatas.put("api_status", "true");

        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("api_status", "false");
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);

    }

    /**
     * 根据billid获取分析师的研报明细表数据
     */
    @GET
    @Path("/getYb")
    @Produces({MediaType.APPLICATION_JSON})
    public String getYb(@Context HttpServletRequest req, @Context HttpServletResponse rep){
        Map<String, Object> apidatas = new HashMap<>();
        try{
            Map<String,Object> param = ParamUtil.request2Map(req);
            String billid = Util.null2String(param.get("billid"));
            List<Map<String, String>> dataList = getTgptService().getYb(billid);
            apidatas.put("datas", dataList);
            apidatas.put("api_status", "true");

        }catch (Exception e){
            e.printStackTrace();
            apidatas.put("api_status", "false");
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);

    }


}
