package com.cnd3b.utility.qywechat.app.drp;

import com.cnd3b.common.data.Row;
import com.cnd3b.common.data.Rows;
import com.cnd3b.common.data.db.DBConnect;
import com.cnd3b.utility.qywechat.base.AppRemote;

import java.util.HashMap;

public class DRP extends AppRemote {

    public static HashMap<String, HashMap<String, Object>> map;

    @Override
    public String switchTextMsg(String Content, String FromUserName, String ToUserName) {
        return createMsg.createTextMsg("账号：" + FromUserName + "返回值：" + Content, FromUserName, ToUserName);
    }

    @Override
    public String switchClickEventMsg(String EventKey, String FromUserName, String ToUserName) {
        StringBuffer returnmsg = new StringBuffer();
        switch (EventKey) {
            case "01": {
                // 基本信息查询
                try {
                    DBConnect connect = new DBConnect();
                    Rows rows = connect.runSqlQuery("select t1.fagentnum,t1.fagentname,t1.fprovince,t1.fcity,t1.fcounty from tagents t1 " +
                            " inner join tagents_users t2 on t1.fagentnum=t2.fagentnum " +
                            " inner join pp_hr t3 on t2.hrid=t3.hrid where t3.fqywechat='" + FromUserName + "'");
                    for (Row row : rows) {
                        returnmsg.append("编号：").append(row.getString("fagentnum")).append("\n");
                        returnmsg.append("企业微信号：").append(FromUserName).append("\n");
                        returnmsg.append("名称：").append(row.getString("fagentname")).append("\n");
                        returnmsg.append("地址：").append(row.getString("fprovince")).append(row.getString("fcity")).append(row.getString("fcounty")).append("\n");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if ("".equals(returnmsg.toString())) {
                    return createMsg.createTextMsg(returnmsg.append("查询不到经销商基本信息，当前企业微信号：").append(FromUserName).toString(), FromUserName, ToUserName);
                } else {
                    return createMsg.createTextMsg(returnmsg.toString(), FromUserName, ToUserName);
                }
            }

            case "02": {
                // 账户信息
                try {
                    DBConnect connect = new DBConnect();
                    Rows rows = connect.runSqlQuery("select t1.fagentnum from tagents_users t1 " +
                            " inner join pp_hr t2 on t1.hrid=t2.hrid where t2.fqywechat='" + FromUserName + "'");
                    for (Row row : rows) {
                        String fagentnum = row.getString("fagentnum");
                        returnmsg.append("经销商编号:").append(fagentnum).append("\n");

                        Rows taccRows = connect.runSqlQuery("select *from taccbal_view where fagentnum='" + fagentnum + "'");
                        for (Row taccrow : taccRows) {
                            returnmsg.append(taccrow.getString("faccclsnum")).append(taccrow.getString("fname")).append("\n");
                            returnmsg.append("账户余额：").append(taccrow.getDouble("fbalance")).append("\n");
                            returnmsg.append("信用额度：").append(taccrow.getDouble("fcreditbal")).append("\n");
                            returnmsg.append("冻结金额：").append(taccrow.getDouble("ffreezamount")).append("\n");
                            returnmsg.append("当前可用余额：").append(taccrow.getDouble("fcanuseamount")).append("\n");
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if ("".equals(returnmsg.toString())) {
                    return createMsg.createTextMsg(returnmsg.append("查询不到账户信息").append(FromUserName).toString(), FromUserName, ToUserName);
                } else {
                    return createMsg.createTextMsg(returnmsg.toString(), FromUserName, ToUserName);
                }
            }
            default:
                return createMsg.createTextMsg("您点击的按钮键值是:" + EventKey, FromUserName, ToUserName);
        }
    }

    @Override
    public String switchImageMsg(String PicUrl, String MediaId, String FromUserName, String ToUserName) {
        return null;
        /*
         * String savefile = Parameter.SaveFile.Image + FromUserName + "_" +
         * Calendar.getInstance().getTimeInMillis() + ".jpg";// 文件保存地址 DownLoad downLoad
         * = new DownLoad(MediaId, savefile); return
         * createMsg.createTextMsg("图片上传成功\n大小：" + downLoad.getfilesize() + "\n网络地址：" +
         * PicUrl, FromUserName, ToUserName);
         */
    }

    @Override
    public String switchVoiceMsg(String MediaId, String Format, String FromUserName, String ToUserName) {
        return null;
        /*
         * String savefile = Parameter.SaveFile.Voice + FromUserName + "_" +
         * Calendar.getInstance().getTimeInMillis() + "." + Format;// 文件保存地址 DownLoad
         * downLoad = new DownLoad(MediaId, savefile); return
         * createMsg.createTextMsg("音频上传成功\n格式：" + Format + "\n大小：" +
         * downLoad.getfilesize(), FromUserName, ToUserName);
         */
    }

    @Override
    public String switchVideoMsg(String MediaId, String ThumbMediaId, String FromUserName, String ToUserName) {
        return null;
        /*
         * String savefile = Parameter.SaveFile.video + FromUserName + "_" +
         * Calendar.getInstance().getTimeInMillis() + ".rm";// 文件保存地址 DownLoad downLoad
         * = new DownLoad(MediaId, savefile); return
         * createMsg.createTextMsg("视频上传成功\n大小：" + downLoad.getfilesize(), FromUserName,
         * ToUserName);
         */
    }

    @Override
    public String switchShortvideoMsg(String MediaId, String ThumbMediaId, String FromUserName, String ToUserName) {
        return null;
        /*
         * String savefile = Parameter.SaveFile.shortvideo + FromUserName + "_" +
         * Calendar.getInstance().getTimeInMillis() + ".rm";// 文件保存地址 DownLoad downLoad
         * = new DownLoad(MediaId, savefile);
         *
         * return createMsg.createTextMsg("小视频上传成功\n大小：" + downLoad.getfilesize(),
         * FromUserName, ToUserName);
         */
    }

    @Override
    public String switchLocationMsg(String Location_X, String Location_Y, String Scale, String Label,
                                    String FromUserName, String ToUserName) {
        return createMsg.createTextMsg("纬度：" + Location_X + "\n经度：" + Location_Y + "\n位置描述：" + Label, FromUserName,
                ToUserName);
    }

    /**
     * 成员关注/取消关注事件
     */
    @Override
    public String switchSubscribeEventMsg(String AgentID, String FromUserName, String ToUserName) {
        return null;
    }

    @Override
    public String switchViewEventMsg(String EventKey, String FromUserName, String ToUserName) {
        return null;
    }

    @Override
    public String switchScancode_pushEventMsg(String EventKey, String ScanType, String ScanResult, String FromUserName,
                                              String ToUserName) {

        String strs[] = ScanResult.split(",");
        return createMsg.createTextMsg("类型：" + ScanType + "\n条码格式：" + strs[0] + "\n条码内容：" + strs[1], FromUserName,
                ToUserName);
    }

    @Override
    public String switchScancode_waitmsgEventMsg(String EventKey, String ScanType, String ScanResult,
                                                 String FromUserName, String ToUserName) {

        if (ScanType.equals("barcode")) {
            String strs[] = ScanResult.split(",");
            return createMsg.createTextMsg("类型：" + ScanType + "\n条码格式：" + strs[0] + "\n条码内容：" + strs[1], FromUserName,
                    ToUserName);
        } else {
            return createMsg.createTextMsg("类型：" + ScanType + "\n条码内容：" + ScanResult, FromUserName, ToUserName);
        }

    }

    @Override
    public String switchEnter_agentEventMsg(String EventKey, String FromUserName, String ToUserName) {
        return null;
        /*
         * Set<String> set = Parameter.entryDrpMap.keySet(); boolean flag = true; long
         * nowtime = System.currentTimeMillis(); if (set.contains(FromUserName)) { long
         * entrytime = Parameter.entryDrpMap.get(FromUserName); if (((nowtime -
         * entrytime) / (1000 * 60)) < 5) { flag = false; } } else {
         * Parameter.entryDrpMap.put(FromUserName, nowtime); } if (flag) { String p2dbconnectstring =
         * "欢迎进入嘉兴博远DRP微信客户端！当前客户端已实现查询信息反馈，文字消息、图文消息群发，DRP系统数据链接，图片、文件、视频、录音等信息的上传、位置的上传及实时记录等功能。"
         * ; return createMsg.createTextMsg("您好，欢迎光临！\n" + p2dbconnectstring, FromUserName, ToUserName);
         * } else { return null; }
         */
    }

    /**
     * 位置事件
     */
    @Override
    public String switchLocationEventMsg(String AgentID, String Latitude, String Longitude, String Precision,
                                         String FromUserName, String ToUserName) {
        return createMsg.createTextMsg("您当前所处的位置是\n纬度：" + Latitude + "\n经度：" + Longitude, FromUserName, ToUserName);

    }
}
