<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.*" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.math.RoundingMode" %>
<%@ page import="com.api.develop.service.growup.GrowUpListService" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    BaseBean bb = new BaseBean();
    String begindate = "" ;
    String enddate = "" ;
    int year = 0 ;
    String active = bb.getPropValue("developProp","active");

    User user = null;
    String type = Util.null2String(request.getParameter("type"));
    if("0".equals(type)){
        begindate = Util.null2String(request.getParameter("begindate"));
        enddate =  Util.null2String(request.getParameter("enddate"));
        year = Util.getIntValue(request.getParameter("year"));
        int userid = Util.getIntValue(request.getParameter("userid"));
        user = new User(userid);
    }else{
        begindate = TimeUtil.getFirstDayOfTheYear();
        enddate = TimeUtil.getCurrentDateString();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        year = calendar.get(Calendar.YEAR);
        user = HrmUserVarify.getUser(request , response) ;
    }
    RecordSet rs = new RecordSet();
    int userid = user.getUID();
    String field291 = "";
    String fieldid = "field69";
    try {
        String sql = " select field69 from cus_fielddata where id= ? and len(field69) > 0 " ;
        rs.executeQuery(sql,new Object[]{userid});
        while (rs.next()){
            String value =  Util.null2String(rs.getString("field69"));
            if(StringUtils.isNotEmpty(value)){
                field291 = value;
            }
        }
    }catch (Exception e){

    }

    if(StringUtils.isEmpty(field291))
    {
        String posttype = Util.null2String(request.getParameter("posttype"));
        field291 = posttype;
    }

    String posttype = "" ;
    bb.writeLog("field291:"+field291);
    bb.writeLog("begindate:"+begindate);
    bb.writeLog("enddate:"+enddate);
    bb.writeLog("year:"+year);

    List<Map<String,String>> list = new ArrayList<Map<String,String>>();
    if(StringUtils.isNotEmpty(field291)){

        if("PROD".equals(active))
        {
            if("1".equals(field291)){

                list = getSalesPerson(user,begindate,enddate,year);
                posttype = "0" ;
            }else if("2".equals(field291)){

                list = getProjectPerson(user,begindate,enddate,year);
                posttype = "1" ;
            }else if("3".equals(field291)){

                list = getDevPerson(userid,begindate,enddate);
                posttype = "2" ;
            }else{
                list = getOtherPerson(userid,begindate,enddate);
                posttype = "3" ;
            }

        }else{
            if("0".equals(field291)){

                list = getSalesPerson(user,begindate,enddate,year);
                posttype = field291 ;
            }else if("1".equals(field291)){

                list = getProjectPerson(user,begindate,enddate,year);
                posttype = field291 ;
            }else if("2".equals(field291)){

                list = getDevPerson(userid,begindate,enddate);
                posttype = field291 ;
            }else{

                list = getOtherPerson(userid,begindate,enddate);
                posttype = "3" ;
            }
        }
    }else{
        list = getOtherPerson(userid,begindate,enddate);
        posttype = "3" ;
    }

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("data",list);
    jsonObject.put("posttype",posttype);
    jsonObject.put("userid",user.getUID());
    jsonObject.put("lastname",user.getLastname());
%>
<%=jsonObject.toString()  %>

<%!
    /***
     * 销售显示6个，签约合同金额、年度指标、指标完成率、合同收款、客户数量、商机数量；
     */
    public List<Map<String,String>> getSalesPerson(User user, String begindate, String enddate,int currentYear){

        List<Map<String,String>> list = new ArrayList<Map<String,String>>();

        Map<String,String> map = null;
        int userid = user.getUID();
        double qyhtje = 0.0;
        try{
            qyhtje = getSignContract(user,currentYear,begindate,enddate);
        }catch (Exception e){

        }

        String unit = "" ;
        String xsqyht = "" ;
        if(qyhtje < 10000){
            unit = "万元";
            xsqyht = qyhtje+"";
        }else{
            unit = "亿元";
            BigDecimal bd = new BigDecimal(qyhtje/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            xsqyht = bd.toString();
        }
        map = new HashMap<String,String>();
        map.put("name","qyhtje");
        map.put("value",xsqyht);
        map.put("title","签约合同金额");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);


        double ndzb = 0.0;
        try{
            ndzb = getSalesTarget(userid,currentYear);
        }catch (Exception e){

        }

        unit = "";
        String xsndzb = "" ;
        if(ndzb < 10000){
            unit = "万元";
            xsndzb = ndzb+"";
        }else{
            unit = "亿元";
            BigDecimal bd = new BigDecimal(ndzb/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            xsndzb = bd.toString();
        }
        map = new HashMap<String,String>();
        map.put("name","ndzb");
        map.put("value",xsndzb);
        map.put("title","年度指标");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);

        String zbwcl = "";
        try{
            BigDecimal bd = new BigDecimal((qyhtje/(ndzb*1.00)*100));
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            zbwcl = bd.toString()+"%";
        }catch (Exception e){

        }
        unit = "%";
        map = new HashMap<String,String>();
        map.put("name","zbwcl");
        map.put("value",zbwcl);
        map.put("title","指标完成率");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);

        double htsk = 0;
        try {
            htsk = getContractCollection(user,currentYear,begindate,enddate);
        }catch (Exception e){

        }
        unit = "" ;
        String xshtsk = "" ;
        if(htsk < 10000){
            unit = "万元";
            xshtsk = htsk+"";
        }else{
            unit = "亿元";
            BigDecimal bd = new BigDecimal(htsk/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            xshtsk = bd.toString();
        }
        map = new HashMap<String,String>();
        map.put("name","htsk");
        map.put("value",xshtsk);
        map.put("title","合同收款");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);

        int khsl = 0 ;
        try{
            khsl = getCustomerCount(user,currentYear,begindate,enddate);
        }catch (Exception e){

        }
        map = new HashMap<String,String>();
        map.put("name","khsl");
        map.put("value",khsl+"");
        map.put("title","客户数量");
        map.put("unit","");
        map.put("url","");
        list.add(map);

        int sjsl = 0 ;
        try{
            sjsl = getConnectionsCount(user,currentYear,begindate,enddate);
        }catch (Exception e){

        }
        map = new HashMap<String,String>();
        map.put("name","sjsl");
        map.put("value",sjsl+"");
        map.put("title","商机数量");
        map.put("unit","");
        map.put("url","");
        list.add(map);

        return list;
    }

    /***
     * 项目显示6个，内容：验收指标、验收金额、指标达成率、收款金额、验收项目个数、平均项目周期；
     */
    public List<Map<String,String>> getProjectPerson(User user,String begindate, String enddate,int year){

        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        int userid = user.getUID();

        Map<String,String> map = null ;
        double yszb = 0.0;
        try {
            yszb = getAcceptanceIndex(userid,year);
        }catch (Exception e){
        }

        if(yszb > 0){
            BigDecimal bd = new BigDecimal(yszb/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            yszb = bd.doubleValue();
        }
        String unit = "" ;
        String xmyszb = "" ;
        if(yszb < 10000){
            unit = "万元";
            xmyszb = yszb+"";
        }else{
            unit = "亿元";
            BigDecimal bd = new BigDecimal(yszb/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            xmyszb = bd.toString();
        }

        map = new HashMap<String,String>();
        map.put("name","yszb");
        map.put("value",xmyszb);
        map.put("title","验收指标");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);

        double ysje = 0.0 ;
        try {
            ysje = getAcceptanceAmount(user,year,begindate,enddate);
        }catch (Exception e){
        }
        unit = "" ;
        String xmysje = "" ;
        if(ysje < 10000){
            unit = "万元";
            xmysje = ysje+"";
        }else{
            unit = "亿元";
            BigDecimal bd = new BigDecimal(ysje/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            xmysje = bd.toString();
        }
        map = new HashMap<String,String>();
        map.put("name","ysje");
        map.put("value",xmysje+"");
        map.put("title","验收金额");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);

        String zbdcl = "0.0" ;
        try{
            BigDecimal bd = new BigDecimal((ysje/(yszb*1.00))*100.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            zbdcl = bd.toString()+"%";
        }catch (Exception e){

        }
        map = new HashMap<String,String>();
        map.put("name","zbdcl");
        map.put("value",zbdcl);
        map.put("title","指标达成率");
        map.put("unit","%");
        map.put("url","");
        list.add(map);


        double skje = 0.0 ;
        try{
            skje = getPaymentsAmount(user,year,begindate,enddate);
        }catch (Exception e){

        }
        unit = "" ;
        String xmskje = "" ;
        if(skje < 10000){
            unit = "万元";
            xmskje = skje+"";
        }else{
            unit = "亿元";
            BigDecimal bd = new BigDecimal(skje/10000.00);
            bd = bd.setScale(2, RoundingMode.HALF_UP);
            xmskje = bd.toString();
        }
        map = new HashMap<String,String>();
        map.put("name","skje");
        map.put("value",xmskje+"");
        map.put("title","收款金额");
        map.put("unit",unit);
        map.put("url","");
        list.add(map);

        int ysxmgs = 0;
        double pjxmzq = 0.0;
        try{
            Map<String,Object> xmMap = getProjectCheckCountAndAveragePeriod(userid,year,begindate,enddate);
            ysxmgs = Util.getIntValue(Util.null2String(xmMap.get("ysxmgs")),0);
            pjxmzq = Util.getDoubleValue(Util.null2String(xmMap.get("pjxmzq")),0.0);
        }catch (Exception e){

        }
        map = new HashMap<String,String>();
        map.put("name","ysxmgs");
        map.put("value",ysxmgs+"");
        map.put("title","验收项目个数");
        map.put("unit","");
        map.put("url","");
        list.add(map);

        map = new HashMap<String,String>();
        map.put("name","ysxmgs");
        map.put("value",pjxmzq+"");
        map.put("title","平均项目周期");
        map.put("unit","");
        map.put("url","");
        list.add(map);
        return list;
    }

    /***
     * 技术显示4个，内容：问题处理数量、开发人天、协作沟通数、处理流程数；
     */
    public List<Map<String,String>> getDevPerson(int userid, String begindate, String enddate){

        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        Map<String,String> map = null;
        int wtclgs = 0;
        try{
            wtclgs = getProblemHandlCount(userid,begindate,enddate);
        }catch (Exception e){

        }
        map = new HashMap<String,String>();
        map.put("name","wtclgs");
        map.put("value",wtclgs+"");
        map.put("title","问题处理数量");
        map.put("unit","");
        map.put("url","/spa/workflow/static/index.html#/main/workflow/listDone");
        list.add(map);


        double kfrt = 0.0 ;
        try{
            kfrt = getDevelopDaysCount(userid,begindate,enddate);
        }catch (Exception e){
        }
        map = new HashMap<String,String>();
        map.put("name","kfrt");
        map.put("value",kfrt+"");
        map.put("title","开发人天");
        map.put("unit","");
        map.put("url","/spa/workflow/static/index.html#/main/workflow/listDone");
        list.add(map);

        int xzgtsl = 0;
        try{
            xzgtsl = getCoworkReplayCount(userid,begindate,enddate);
        }catch (Exception e){
        }
        map = new HashMap<String,String>();
        map.put("name","xzgtsl");
        map.put("value",xzgtsl+"");
        map.put("title","协作沟通数");
        map.put("unit","");
        map.put("url","/spa/cowork/static/index.html#/main/cowork/mine");
        list.add(map);

        int cllcsl = 0;
        try{
            cllcsl = getWorkflowDealCount(userid,begindate,enddate);
        }catch (Exception e){

        }

        map = new HashMap<String,String>();
        map.put("name","cllcsl");
        map.put("value",cllcsl+"");
        map.put("title","处理流程数");
        map.put("unit","");
        map.put("url","/spa/workflow/static/index.html#/main/workflow/listDone");
        list.add(map);

        return list;
    }

    /***
     * 其他：处理流程数、文档贡献度、微博填写数、沟通协作数
     *
     */
    public List<Map<String,String>> getOtherPerson(int userid, String begindate, String enddate){
        List<Map<String,String>> list = new ArrayList<Map<String,String>>();
        Map<String,String> map = null;
        int cllcsl = 0;
        try{
            cllcsl = getWorkflowDealCount(userid,begindate,enddate);
        }catch (Exception e){
        }
        map = new HashMap<String,String>();
        map.put("name","cllcsl");
        map.put("value",cllcsl+"");
        map.put("title","处理流程数");
        map.put("unit","");
        map.put("url","/spa/workflow/static/index.html#/main/workflow/listDone");
        list.add(map);


        int wdgxd = 0;
        try{
            wdgxd = getDocCreateCount(userid,begindate,enddate);
        }catch (Exception e){
        }
        map = new HashMap<String,String>();
        map.put("name","wdgxd");
        map.put("value",wdgxd+"");
        map.put("title","文档贡献度");
        map.put("unit","");
        map.put("url","/spa/document/static/index.html#/main/document/add");
        list.add(map);

        int wbtxs = 0;
        try {
            wbtxs = getBlogWriteCount(userid,begindate,enddate);
        }catch (Exception e){
        }
        map = new HashMap<String,String>();
        map.put("name","wbtxs");
        map.put("value",wbtxs+"");
        map.put("title","微博填写数");
        map.put("unit","");
        map.put("url","/spa/blog/static/index.html#/main/blog/myBlog");
        list.add(map);

        int xzgts = 0;
        try {
            xzgts = getCoworkReplayCount(userid,begindate,enddate);
        }catch (Exception e){
        }
        map = new HashMap<String,String>();
        map.put("name","xzgts");
        map.put("value",xzgts+"");
        map.put("title","沟通协作数");
        map.put("unit","");
        map.put("url","/spa/cowork/static/index.html#/main/cowork/mine");
        list.add(map);
        return list;
    }

    /////##########################销售人员##################################//
    /***
     * 签约合同金额
     * @param user
     * @param year
     * @param startDate
     * @param endDate
     * @return
     */
    public double getSignContract(User user,int year,String startDate,String endDate){
        BaseBean bb = new BaseBean();
        bb.writeLog("getSignContract:");

        double _total = 0.0;//总数
        int userid = user.getUID();
        GrowUpListService service = new GrowUpListService();
        //https://www.e-cology.com.cn/api/develop/growup/getData?season=&month=&week=&day=&
        // year=2022&isDecimal=1&grouptype=&datatype=&type=performances&hrmid=5796
        try {
            Map<String,Object> params = new HashMap<String,Object>();
            params.put("year",year);
            params.put("hrmid",userid);
            params.put("type","contractamount");
            params.put("isDecimal","1");
            params.put("fromdate",startDate);
            params.put("todate",endDate);

            Map<String,Object> apidatas = service.getContractAmount(user, params);
            bb.writeLog(JSONObject.toJSONString(apidatas));

            if(apidatas.containsKey("status") && apidatas.containsKey("num")){
                String status = Util.null2String(apidatas.get("status"));
                if("1".equals(status)){
                    _total = Util.getDoubleValue(Util.null2String(apidatas.get("num")));
                }
            }

            bb.writeLog("_total:"+_total);
        }catch (Exception e) {
            bb.writeLog("getSignContract-e:"+e);
        }
        return _total;

    }


    /**
     * 销售验收指标
     * @param userid
     * @param year
     * @return
     */
    public double getSalesTarget(int userid,int year){

        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getSalesTarget:");

        double sales_target = 0.0;
        String formtable = getUfPropValue("salesindextable");

        try{
            if(StringUtils.isEmpty(formtable)){
                formtable = "formtable_main_2055";
            }

            String lastname = "" ;
            String sql = " select lastname from hrmresource where id = ?" ;
            rs.executeQuery(sql,new Object[]{userid});
            if(rs.next()){
                lastname = Util.null2String(rs.getString("lastname"));
            }

            if(StringUtils.isNotEmpty(lastname)){
                String mainid = "" ;
                sql = " select id from "+formtable+" where sbnd='"+year+"' ";
                rs.execute(sql);
                if(rs.next()){
                    mainid = Util.null2String(rs.getString("id"));
                }
                if(StringUtils.isNotEmpty(mainid)){
                    sql = " select yxyswy from "+formtable+"_dt1 where mainid="+mainid+" and xmfzr='"+lastname+"'" ;
                    bb.writeLog("sql:"+sql);
                    rs.execute(sql);
                    if(rs.next()){
                        sales_target = Util.getDoubleValue(Util.null2String(rs.getString("yxyswy")));
                    }
                }
            }
        }catch (Exception e){
            bb.writeLog("getSalesTarget-e:"+e);
        }
        return sales_target;
    }



    /***
     *  合同收款金额
     * @param user
     * @param year
     * @param startDate
     * @param endDate
     * @return
     */
    public double getContractCollection(User user,int year,String startDate,String endDate){
        BaseBean bb = new BaseBean();
        bb.writeLog("getContractCollection:");
        double _total = 0.0;//总数
        int userid = user.getUID();
        GrowUpListService service = new GrowUpListService();
        //https://www.e-cology.com.cn/api/develop/growup/getData?season=&month=&week=&day=&
        // year=2022&isDecimal=1&grouptype=&datatype=&type=performances&hrmid=5796
        try {
            Map<String,Object> params = new HashMap<String,Object>();
            params.put("year",year);
            params.put("hrmid",userid);
            params.put("type","validpayments");
            params.put("isDecimal","1");
            params.put("fromdate",startDate);
            params.put("todate",endDate);

            Map<String,Object> apidatas = service.getValidPayments(user, params);
            bb.writeLog(JSONObject.toJSONString(apidatas));

            if(apidatas.containsKey("status") && apidatas.containsKey("num")){
                String status = Util.null2String(apidatas.get("status"));
                if("1".equals(status)){
                    _total = Util.getDoubleValue(Util.null2String(apidatas.get("num")));
                }
            }
            bb.writeLog("_total:"+_total);
        }catch (Exception e) {
            bb.writeLog("getContractCollection-e:"+e);
        }
        return _total;
    }

    /***
     * 客户总和
     * @param user
     * @param year
     * @param startDate
     * @param endDate
     * @return
     */
    public int getCustomerCount(User user,int year,String startDate,String endDate){
        BaseBean bb = new BaseBean();
        bb.writeLog("getCustomerCount:");
        int _total = 0;//总数
        int userid = user.getUID();
        GrowUpListService service = new GrowUpListService();
        //https://www.e-cology.com.cn/api/develop/growup/getData?season=&month=&week=&day=&
        // year=2022&isDecimal=1&grouptype=&datatype=&type=performances&hrmid=5796

        try {
            Map<String,Object> params = new HashMap<String,Object>();
            params.put("year",year);
            params.put("hrmid",userid);
            params.put("type","customernum");
            params.put("isDecimal","1");
            params.put("fromdate",startDate);
            params.put("todate",endDate);

            Map<String,Object> apidatas = service.getCustomerNum(user, params);
            bb.writeLog(JSONObject.toJSONString(apidatas));

            if(apidatas.containsKey("status") && apidatas.containsKey("num")){
                String status = Util.null2String(apidatas.get("status"));
                if("1".equals(status)){
                    _total = Util.getIntValue(Util.null2String(apidatas.get("num")));
                }
            }
            bb.writeLog("_total:"+_total);

        }catch (Exception e) {
            bb.writeLog("getCustomerCount-e:"+e);
        }
        return _total;
    }


    /***
     *  商机总和
     * @param user
     * @param year
     * @param startDate
     * @param endDate
     * @return
     */
    public int getConnectionsCount(User user,int year,String startDate,String endDate){
        BaseBean bb = new BaseBean();
        bb.writeLog("getConnectionsCount:");

        int _total = 0;//总数
        int userid = user.getUID();
        GrowUpListService service = new GrowUpListService();
        //https://www.e-cology.com.cn/api/develop/growup/getData?season=&month=&week=&day=&
        // year=2022&isDecimal=1&grouptype=&datatype=&type=performances&hrmid=5796

        try {
            Map<String,Object> params = new HashMap<String,Object>();
            params.put("year",year);
            params.put("hrmid",userid);
            params.put("type","sellchancenum");
            params.put("isDecimal","1");
            params.put("fromdate",startDate);
            params.put("todate",endDate);

            Map<String,Object> apidatas = service.getSellchanceNum(user, params);
            bb.writeLog(JSONObject.toJSONString(apidatas));

            if(apidatas.containsKey("status") && apidatas.containsKey("num")){
                String status = Util.null2String(apidatas.get("status"));
                if("1".equals(status)){
                    _total = Util.getIntValue(Util.null2String(apidatas.get("num")));
                }
            }
            bb.writeLog("_total:"+_total);
        }catch (Exception e) {
            bb.writeLog("getConnectionsCount-e:"+e);
        }
        return _total;
    }


    /////##########################销售人员##################################//

    /////##########################项目人员##################################//
    /**
     * 验收指标
     * @param cyear
     * @param hrmid
     * @return
     */
    public double getAcceptanceIndex(int hrmid,int cyear){
        double yszb = 0.0 ;
        BaseBean bb = new BaseBean();
        bb.writeLog("getAcceptanceIndex");
        RecordSet rs = new RecordSet();
        StringBuffer sqlWhere = new StringBuffer();
        sqlWhere.append(" and t1.hsyjnf like '"+cyear+"%'");
        sqlWhere.append(" and (exists(select 1 from getallchilds("+hrmid+") h where (t1.xmjl = h.id or t1.tdfzr = h.id )))");
        String tablename = "" ;
        String sql = " select bm from uf_cm_right_detail where sign='xmzb' ";
        bb.writeLog("sql:"+sql);
        rs.executeQuery(sql);
        if(rs.next()){
            tablename = Util.null2String(rs.getString("bm"));
        }
        if(StringUtils.isNotEmpty(tablename)){
            sql =" select sum(yszb) as yszb from "+tablename + " t1 where 1=1 "+sqlWhere.toString();
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql);
            if(rs.next()){
                yszb = Util.getDoubleValue(Util.null2String(rs.getString("yszb")));
            }
        }
        bb.writeLog("yszb:"+yszb);
        return yszb;
    }

    /***
     * 项目验收金额
     * @param user
     * @param year
     * @param startDate
     * @param endDate
     * @return
     */
    public double getAcceptanceAmount(User user,int year,String startDate,String endDate){
        BaseBean bb = new BaseBean();
        bb.writeLog("getAcceptanceAmount");
        double _total = 0;//总数
        int userid = user.getUID();
        GrowUpListService service = new GrowUpListService();
        //https://www.e-cology.com.cn/api/develop/growup/getData?season=&month=&week=&day=&
        // year=2022&isDecimal=1&grouptype=&datatype=&type=performances&hrmid=5796
        try {
            Map<String,Object> params = new HashMap<String,Object>();
            params.put("year",year);
            params.put("hrmid",userid);
            params.put("type","projacceptance");
            params.put("isDecimal","1");
            params.put("fromdate",startDate);
            params.put("todate",endDate);

            Map<String,Object> apidatas = service.getProjacceptance(user, params);
            bb.writeLog(JSONObject.toJSONString(apidatas));

            if(apidatas.containsKey("status") && apidatas.containsKey("num")){
                String status = Util.null2String(apidatas.get("status"));
                if("1".equals(status)){
                    _total = Util.getDoubleValue(Util.null2String(apidatas.get("num")));
                }
            }
            bb.writeLog("_total:"+_total);
        }catch (Exception e) {
            bb.writeLog("getCustomerCount-e:"+e);
        }
        return _total;
    }

    /***
     *  项目收款金额
     * @param user
     * @param year
     * @param startDate
     * @param endDate
     * @return
     */
    public double getPaymentsAmount(User user,int year,String startDate,String endDate){
        BaseBean bb = new BaseBean();
        bb.writeLog("getPaymentsAmount");

        double _total = 0;//总数
        int userid = user.getUID();
        GrowUpListService service = new GrowUpListService();
        //https://www.e-cology.com.cn/api/develop/growup/getData?season=&month=&week=&day=&
        // year=2022&isDecimal=1&grouptype=&datatype=&type=performances&hrmid=5796
        try {
            Map<String,Object> params = new HashMap<String,Object>();
            params.put("year",year);
            params.put("hrmid",userid);
            params.put("type","projpayments");
            params.put("isDecimal","1");
            params.put("fromdate",startDate);
            params.put("todate",endDate);

            Map<String,Object> apidatas = service.getProjpayments(user, params);
            bb.writeLog(JSONObject.toJSONString(apidatas));

            if(apidatas.containsKey("status") && apidatas.containsKey("num")){
                String status = Util.null2String(apidatas.get("status"));
                if("1".equals(status)){
                    _total = Util.getDoubleValue(Util.null2String(apidatas.get("num")));
                }
            }

            bb.writeLog("_total:"+_total);
        }catch (Exception e) {
            bb.writeLog("getCustomerCount-e:"+e);
        }
        return _total;
    }


    /***
     *  项目验收个数，项目验收平均周期
     * @param userid
     * @param startdate
     * @param enddate
     * @return
     */
    public Map<String,Object> getProjectCheckCountAndAveragePeriod(int userid,int year,String startdate,String enddate)
    {
        BaseBean bb = new BaseBean();
        bb.writeLog("getProjectCheckCountAndAveragePeriod:");
        RecordSet rs = new RecordSet();
        /******************完成收款****************/
        int ysxmgs = 0 ;
        double pjxmzq = 0.0 ;
        Map<String,Object> map = new HashMap<String,Object>();
        try{

//            String userids = userid+"";
//            String sql =" with tem_table(hrm_id,last_name,manager_id,curlevel) as \n" +
//                        " (select id,lastname,managerid,1 as level " +
//                        "         from HrmResource " +
//                        "         where id=" + userid +
//                        "  union all\n" +
//                        "  select a.id,a.lastname,a.managerid,b.curlevel+1 " +
//                        "         from HrmResource a " +
//                        "         inner join tem_table b on (a.managerid = b.hrm_id) \n" +
//                        " )\n" +
//                        " select * from tem_table" ;
//            rs.execute(sql);
//            while (rs.next()){
//                String hrmid = Util.null2String(rs.getString("hrm_id"));
//                userids += userids == "" ? hrmid : ","+hrmid ;
//            }

            String userWhere = " and (t3t.hrmid in("+userid+") or t3t.qyjl in("+userid+") or t3t.dqzj in("+userid+") or t3t.qyzj in("+userid+")) " ;

            String sql = " select sum(datediff(Day,cbi.planstartdate,cbi.gdrq))/count(1) as pjxmzq,count(1) as ysxmgs  " +
                    " from proj_CardBaseInfo cbi " +
                    " left join lf_prjhrminfo t3t on t3t.hrmid = cbi.projmanager " +
                    " where cbi.gdrq >= '"+startdate+"' AND cbi.gdrq <= '"+enddate+"' " +
                    " and cbi.gdrq IS NOT NULL AND cbi.gdrq <> '' " +
                    " and cbi.planstartdate is not null and cbi.planstartdate <> '' " +
                    " and cbi.isYanshou=1 "+userWhere;

            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql);
            if(rs.next()){
                pjxmzq = Util.getDoubleValue(Util.null2String(rs.getString("pjxmzq")));
                ysxmgs = Util.getIntValue(Util.null2String(rs.getString("ysxmgs")));
            }
        }catch (Exception e){

        }

        bb.writeLog("pjxmzq:"+pjxmzq);
        bb.writeLog("ysxmgs:"+ysxmgs);

        map.put("ysxmgs",ysxmgs);
        map.put("pjxmzq",pjxmzq);
        return map;
    }


    /////##########################项目人员##################################//


    /////##########################技术人员##################################//
    /***
     * 问题处理数量
     * @param userid
     * @param begindate
     * @param enddate
     * @return
     */
    public int getProblemHandlCount(int userid,String begindate,String enddate){
        int problem_handl = 0;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getProblemHandlCount");

//        String khwezcjjlc_billform = getUfPropValue("khwezcjjlc.billformid");  //83
//        if(StringUtils.isEmpty(khwezcjjlc_billform)){
//            khwezcjjlc_billform = "83";
//        }
        try{
//            String sql =" select sum(case when (t.tzhxgs is null or len(t.tzhxgs)=0) then case when convert(varchar(1000),t.gzlgs) is null then 0 else isnull(cast(t.gzlgs as decimal(10,2)),0) end else isnull(cast(t.tzhxgs as decimal(10,2) ),0) end) as gzlgs " +
//                        " from workflow_form t\n" +
//                        " inner join workflow_requestbase h on t.requestid = h.requestid\n" +
//                        " where t.billformid=? \n" +
//                        " convert(varchar(1000),t.gzlgs) <> '-' \n" +
//                        " and charindex(','+convert(varchar(1000),t.mutiresource)+',',',"+userid+",')>0 \n" +
//                        " and h.createdate >= ? and h.createdate<=? \n" +
//                        " and h.currentnodetype=3";

            String sql =" select count(1) as gzlgs " +
                    " from workflow_form t\n" +
                    " inner join workflow_requestbase h on t.requestid = h.requestid\n" +
                    " where h.workflowid = 232  \n" +
                    " and charindex(','+convert(varchar(1000),t.mutiresource)+',',',"+userid+",')>0 \n" +
                    " and h.createdate >= ? and h.createdate<=? \n" +
                    " and h.currentnodeid <> 1023 " +
                    " and h.currentnodetype = 3";

            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{begindate,enddate});
            if(rs.next()){
                problem_handl = rs.getInt(1);
            }
            bb.writeLog("problem_handl:"+problem_handl);
        }catch (Exception e){
            bb.writeLog("getProblemHandlCount-e:"+e);
        }
        return problem_handl;
    }


    /***
     * 开发人天
     * @param userid
     * @param begindate
     * @param enddate
     * @return
     */
    public int getDevelopDaysCount(int userid,String begindate,String enddate){
        int develop_day = 0;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getDevelopDaysCount");
        try{
            String sql =" select isnull(sum(cast(desc1 as decimal(6,2))),0) as desc1 from workflow_form t\n" +
                    " inner join workflow_requestbase h on t.requestid = h.requestid\n" +
                    " where h.workflowid = 2582 \n" +
                    " and len(t.desc1) >0" +
                    " and charindex(','+convert(varchar(1000),t.multiresource5)+',',',"+userid+",')>0\n" +
                    " and h.createdate >= ? and h.createdate<=?\n" +
                    " and h.currentnodetype =3 ";

            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{begindate,enddate});
            if(rs.next()){
                develop_day = rs.getInt(1);
            }
            bb.writeLog("develop_day:"+develop_day);
        }catch (Exception e){
            bb.writeLog("getDevelopDaysCount-e:"+e);
        }
        return develop_day;
    }


    /***
     *处理流程数
     * @param userid
     * @param begindate
     * @param enddate
     * @return
     */
    public int getWorkflowDealCount(int userid,String begindate,String enddate){
        int wf_deal = 0;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getWorkflowDealCount");
        try{
            String sql = " select count(requestid) as amount from workflow_requestLog where operator=? and operatedate>=? and operatedate<=? ";
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{userid,begindate,enddate});
            if(rs.next()){
                wf_deal = rs.getInt(1);
            }
            bb.writeLog("wf_deal:"+wf_deal);
        }catch (Exception e){
            bb.writeLog("getWorkflowDealCount-e:"+e);
        }
        return wf_deal;
    }

    /////##########################技术人员##################################//

    /***
     *  沟通协作数
     * @param userid
     * @param begindate
     * @param enddate
     * @return
     */
    public int getCoworkReplayCount(int userid,String begindate,String enddate){
        int cwork_replay = 0;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getCoworkReplayCount");
        try {
            String sql = "select count(coworkid) as amount from cowork_discuss where discussant=? and createdate>=? and createdate<=?";
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{userid,begindate,enddate});
            if(rs.next()){
                cwork_replay = rs.getInt(1);
            }
            bb.writeLog("cwork_replay:"+cwork_replay);
        }catch (Exception e){
            bb.writeLog("getCoworkReplayCount-e:"+e);
        }

        return cwork_replay;
    }

    /***
     * 微博填写数
     * @param userid
     * @param begindate
     * @param enddate
     * @return
     */
    public int getBlogWriteCount(int userid,String begindate,String enddate){
        int blog_write = 0;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getBlogWriteCount");
        try{
            String sql = "select count(*) as count from blog_discuss where userid=? and createdate>=? and createdate<=? ";
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql,new Object[]{userid,begindate,enddate});
            if(rs.next()){
                blog_write = rs.getInt(1);
            }
            bb.writeLog("blog_write:"+blog_write);
        }catch (Exception e){
            bb.writeLog("getBlogWriteCount-e:"+e);
        }
        return blog_write;
    }


    /***
     *文档贡献度
     * @param userid
     * @param begindate
     * @param enddate
     * @return
     */
    public int getDocCreateCount(int userid,String begindate,String enddate){
        int doc_create = 0;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("getDocCreateCount");
        try{
            String sql = " select count(*) as count from docdetaillog where  operatetype = 1 and exists(select 1 from docdetail where id = docid) AND operateuserid  = ? and operatedate>=? and operatedate<=?";
            bb.writeLog("sql:"+sql);
            rs.executeQuery(sql, new Object[]{userid, begindate, enddate});
            if(rs.next()){
                doc_create = rs.getInt(1);
            }
            bb.writeLog("doc_create:"+doc_create);
        }catch (Exception e){
            e.printStackTrace();
            bb.writeLog("getDocCreateCount-e:"+e);
        }
        return doc_create;
    }

    /***
     *
     * @param pkey
     * @return
     */
    public String getUfPropValue(String pkey){
        if(StringUtils.isEmpty(pkey)){
            return "";
        }
        String value = "" ;
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        String active = bb.getPropValue("developProp","active");
        String sql = " select devvalue,prodvalue from uf_hr_prop where pkey = ?" ;
        rs.executeQuery(sql,new Object[]{pkey});
        if(rs.next()){
            value = Util.null2String(rs.getString(active+"value"));
        }
        return value;
    }
%>



