package weaver.interfaces.htsc.itxqlc.action;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.htsc.util.HT_Util;

import java.util.Map;

public class ItxqlcJiraUtil {

    /***
     *
     * @param xqjsrs
     */
    public JSONObject getXqjsrInfo(String xqjsrs){
        JSONObject jsonObject = new JSONObject();
        HT_Util ht_util = new HT_Util();
        RecordSet rs = new RecordSet();
        String[] xqjsr =xqjsrs.split(",");
        for(int i=0;i<xqjsr.length;i++){

            String sql ="  select h.workcode,h.lastname,h.telephone,h.mobile,k.field9 as jobgrade,d.jobtitlecode,d.jobtitlename,\n" +
                    "        k.field0 as workcity,k.field4,k.field5,k.field13,k.field12,\n" +
                    "        l.departmentname,l.departmentcode,p.depttypecode,p.depttypename,\n" +
                    "        p.deptscalelevelcode,p.deptscalelevelname\n" +
                    "   from hrmresource h \n" +
                    "   left join cus_fielddata k on k.id = h.id\n" +
                    "   left join hrmjobtitles d on d.id = h.jobtitle\n" +
                    "   inner join hrmdepartment l on l.id = h.departmentid\n" +
                    "   left join hrmdepartmentdefined p on p.deptid = l.id\n" +
                    "   where k.scopeid=1\n" +
                    "   and h.id="+ xqjsr[i];
            rs.execute(sql);
            if(rs.next()){
                String badge = Util.null2String(rs.getString("workcode"));
                String name = Util.null2String(rs.getString("lastname"));
                String landLine_Telephone = Util.null2String(rs.getString("telephone"));
                String telephone = Util.null2String(rs.getString("mobile"));
                String depabbr = Util.null2String(rs.getString("departmentname"));

                String depclassabbr = Util.null2String(rs.getString("deptscalelevelname"));
                String depclassid = Util.null2String(rs.getString("deptscalelevelcode"));

                String depid = Util.null2String(rs.getString("departmentcode"));

                String deptypeid = Util.null2String(rs.getString("depttypecode"));
                String deptypeabbr = Util.null2String(rs.getString("depttypename"));

                String jobabbr = Util.null2String(rs.getString("jobtitlename"));
                String jobgrade = Util.null2String(rs.getString("jobgrade"));
                String jobid = Util.null2String(rs.getString("jobtitlecode"));

                jsonObject.put("badge",badge);
                jsonObject.put("company","4");
                jsonObject.put("depabbr",depabbr);
                jsonObject.put("depclassabbr",depclassabbr);
                jsonObject.put("depclassid",depclassid);
                jsonObject.put("depid",depid);

                jsonObject.put("deptypeabbr",deptypeabbr);
                jsonObject.put("deptypeid",deptypeid);
                jsonObject.put("gender","");
                jsonObject.put("id","");
                jsonObject.put("isCenter","");
                jsonObject.put("isDelete","");
                jsonObject.put("isKey","");
                jsonObject.put("isManage","");
                jsonObject.put("jobabbr",jobabbr);
                jsonObject.put("jobgrade",jobgrade);
                jsonObject.put("jobid",jobid);
                jsonObject.put("joblevel","");
                jsonObject.put("jyear","");
                jsonObject.put("landLine_Telephone",landLine_Telephone);
                jsonObject.put("lhbadge","");
                jsonObject.put("name",name);

                jsonObject.put("outype","");
                jsonObject.put("password","");
                jsonObject.put("practicebadge",badge);
                jsonObject.put("sortId","0");
                jsonObject.put("usertype","0");
                jsonObject.put("telephone",telephone);
                jsonObject.put("workCity","");
            }

            Map<String,String> szjgMap = ht_util.getszjginfo(xqjsr[i]);
            if(szjgMap !=null){
                String orgid = szjgMap.get("szjgcode");
                String orgname = szjgMap.get("szjgname");
                jsonObject.put("orgid",orgid);
                jsonObject.put("orgname",orgname);
            }
        }
        //company=4 id isCenter isDelete isKey isManage joblevel jyear lhbadge outype password sortId usertype workCity
        return jsonObject;
    }

}
