<%@ page import="weaver.general.*" %>
<%@ page import="weaver.conn.RecordSet"%>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="com.cloudstore.dev.api.bean.MessageBean" %>
<%@ page import="com.cloudstore.dev.api.bean.MessageType" %>
<%@ page import="com.cloudstore.dev.api.util.Util_Message" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<jsp:useBean id="ResourceComInfo" class="weaver.hrm.resource.ResourceComInfo" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    JSONObject jsonObject = new JSONObject();
    boolean flag = true;
    int smstypeid = Util.getIntValue(request.getParameter("replaytypeid"),505);
//    User user = HrmUserVarify.getUser(request , response) ;
//    int userid = user.getUID();

    String fsr = request.getParameter("fsr");
    String jsr = request.getParameter("jsr");
    String hfnr = request.getParameter("hfnr");
    out.println("fsr:"+fsr);
    out.println("jsr:"+jsr);
    out.println("hfnr"+hfnr);

    try{
        if(StringUtils.isNotBlank(fsr) && StringUtils.isNotBlank(jsr)){
            String jsrname = ResourceComInfo.getLastname(jsr);
            out.println("jsrname"+jsrname);
            flag = sendMessage(smstypeid,fsr,hfnr,jsrname);
        }else{
            flag = false;
        }
    }catch (Exception e){
        flag = false;
    }
    out.println("flag"+flag);

    jsonObject.put("result",flag);

%>
<%=jsonObject.toString()  %>


<%!

    /***
     *
     * @param
     * @param
     * @return
     */
    private boolean sendMessage(int smstypeid,String jsr,String hfnr,String fsrname) {

        String linkUrl = "";
        String linkMobileUrl = "";
        String title = " ";
        String content = fsrname+"给你回复:"+hfnr;

        Set<String> userSet = new HashSet<String>();
        userSet.add(jsr);
        return sendMessage(smstypeid,userSet,title,content,linkUrl,linkMobileUrl);
    }


    /***
     *
     * @param smstypeid
     * @param sendIdSet
     * @param title
     * @param context
     * @param linkPcUrl
     * @param linkMobileUrl
     * @return
     */
    public boolean sendMessage(int smstypeid, Set<String> sendIdSet, String title, String context, String linkPcUrl, String linkMobileUrl)
    {
        BaseBean bs = new BaseBean();
        RecordSet rs = new RecordSet();
        boolean flag = false;
        String sumcount="";
        String sql=" select count(*) as sumcount from ecology_message_type  where id='"+smstypeid+"'";
        rs.execute(sql);
        if(rs.next()){
            sumcount=Util.null2String(rs.getString("sumcount"));
        }
        if("0".equals(sumcount)){
            return flag;
        }

        MessageType messageType = MessageType.newInstance(smstypeid); // 消息来源（见文档第四点补充 必填）
        try {
            MessageBean messageBean = Util_Message.createMessage(messageType, sendIdSet, title, context, linkPcUrl, linkMobileUrl);
            messageBean.setCreater(1);// 创建人id
            messageBean.setDetailTitle("");
            flag = Util_Message.store(messageBean);

        } catch (IOException e) {
            flag = false;
            e.printStackTrace();
            bs.writeLog("send message error:",e);
        }
        return flag;
    }

%>



