`
lw4135
  • 浏览: 44824 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

客户情况统计

    博客分类:
  • Java
阅读更多
/**
	 * 每周客户情况统计 liuwang 说明: 1、客户数=新认识的客户数+约访后回访的客户数+有效的访客数+转介绍客户数
	 * 2、分值数=新认识的客户数*1+约访后回访的客户数*10+有效的访客数*10+转介绍客户数*2 3、面谈数=有效访客数+约访后回访的客户数
	 * 合计中的总数就等于每天的数值之和
	 * 
	 * @Date 2013-12-11
	 * @param params
	 * @return
	 */
	public List getCustomerStaWeekly(Data params) {

		/*
		 * 营业组 营业员 合计 2013-11-15(星期五) 人次 新增 转介绍 邀约 回访 面谈 新增 转介绍 邀约 回访 面谈 客户数
		 */

		// 日期
		String startDate = params.getString("startDate");
		String endDate = params.getString("endDate");
		String staffId = params.getString("staffId");
		String staffGroupId = params.getString("staffGroupId");
		String staffGroupName = params.getString("staffGroupName");
		String staffName = params.getString("staffName");

		String staffDeptId = params.getString("staffDeptId");// 营业部
		String staffDeptName = params.getString("staffDeptName");

		DateTool dateTool = new DateTool();
		if (startDate == null || "".equals(startDate)) {
			startDate = dateTool.getDefaultDates().get(0);
		}
		if (endDate == null || "".equals(endDate)) {
			endDate = dateTool.getDefaultDates().get(1);
		}
		List<String> dates = dateTool.getDates(startDate, endDate);

		StringBuffer sql = new StringBuffer();
		sql.append(" select t0.dept_name,t0.group_name,                                                                    ");
		sql.append("        t0.full_name,                                                                     ");
		for (int j = 1; j <= dates.size(); j++) {
			String customernum = "customernum" + j;// 客户数
			String customerScoresnum = "customeScoresrnum" + j;// 分值数
			String facenum = "facenum" + j;// 面谈数
			String newnum = "newnum" + j;
			String visitnum = "visitnum" + j;
			String activenum = "activenum" + j;
			String referralsnum = "referralsnum" + j;

			String newScorenum = "newScorenum" + j;
			String visitScorenum = "visitScorenum" + j;
			String activeScorenum = "activeScorenum" + j;
			String referralsScorenum = "referralsScorenum" + j;

			// 客户数
			sql.append("isnull(t" + newnum + "." + newnum + ", 0) +");
			sql.append("isnull(t" + visitnum + "." + visitnum + ", 0) +");
			sql.append("isnull(t" + activenum + "." + activenum + ", 0) +");
			sql.append("isnull(t" + referralsnum + "." + referralsnum + ", 0) ");
			sql.append("   as " + customernum + " ,    ");
			// 分值数
			sql.append("isnull(t" + newnum + "." + newnum + ", 0) +");
			sql.append("isnull(10*t" + visitnum + "." + visitnum + ", 0) +");
			sql.append("isnull(10*t" + activenum + "." + activenum + ", 0) +");
			sql.append("isnull(2*t" + referralsnum + "." + referralsnum
					+ ", 0) ");
			sql.append("   as " + customerScoresnum + " ,    ");
			// 面谈数
			sql.append("isnull(t" + visitnum + "." + visitnum + ", 0) +");
			sql.append("isnull(t" + activenum + "." + activenum + ", 0) ");
			sql.append("   as " + facenum + " ,    ");

			sql.append("t" + newnum + "." + newnum + ",");
			sql.append(" t" + newnum + "." + newnum + " as " + newScorenum
					+ "  ,");
			sql.append("t" + visitnum + "." + visitnum + ",");
			sql.append("10*t" + visitnum + "." + visitnum + " as "
					+ visitScorenum + "  ,");
			sql.append("t" + activenum + "." + activenum + ",");
			sql.append("10*t" + activenum + "." + activenum + " as "
					+ activeScorenum + "  ,");
			sql.append("t" + referralsnum + "." + referralsnum + ",");
			sql.append("2*t" + referralsnum + "." + referralsnum + " as "
					+ referralsScorenum + "  ,");
		}

		sql = new StringBuffer(sql.substring(0, sql.length() - 1));
		sql.append("   from (select t00.id        as id,     t01.id as group_id	,	t02.id as dept_id,t02.name as dept_name, ");
		sql.append("                t01.name as group_name,                                              ");
		sql.append("                t00.name as full_name                                                ");
		sql.append("           from (select id, name, sales_group_id,sales_dept_id from org_staff where is_active = 1 and staff_type = 1 ");

		sql.append(" ) t00     ");
		sql.append("           left join (select id, name from org_staff where 1=1 ");

		sql.append(") t01                            ");
		sql.append("             on t00.sales_group_id = t01.id                                         ");

		sql.append(" left join (select id, name from org_staff where 1 = 1) t02  ");
		sql.append("  on t00.sales_dept_id = t02.id  ) t0  ");
		int i = 1;
		for (String date : dates) {
			String newnum = "newnum" + i;
			String visitnum = "visitnum" + i;
			String activenum = "activenum" + i;
			String referralsnum = "referralsnum" + i;

			// // 新认识的客户数+约访后回访的客户数+有效的访客数+转介绍客户数 Scores
			sql.append("   left join (select staff_id, count(*) as " + newnum
					+ "                                     ");
			sql.append("                from crm_situation_survey                                                 ");
			sql.append("               where register_date = '" + date
					+ "'                                         ");
			sql.append("                 and nature like '%新认识的客户%'      ");
			sql.append("               group by staff_id) t" + newnum
					+ "                                                  ");
			sql.append("     on t0.id = t"
					+ newnum
					+ ".staff_id                                                              ");

			sql.append("   left join (select staff_id, count(*) as " + visitnum
					+ "                                     ");
			sql.append("                from crm_situation_survey                                                 ");
			sql.append("               where register_date = '" + date
					+ "'                                         ");
			sql.append("                 and nature like '%约访后回访的客户%'      ");
			sql.append("               group by staff_id) t" + visitnum
					+ "                                                  ");
			sql.append("     on t0.id = t"
					+ visitnum
					+ ".staff_id                                                              ");

			sql.append("   left join (select staff_id, count(*) as "
					+ activenum + "                                     ");
			sql.append("                from crm_situation_survey                                                 ");
			sql.append("               where register_date = '" + date
					+ "'                                         ");
			sql.append("                 and nature like '%有效的访客%'      ");
			sql.append("               group by staff_id) t" + activenum
					+ "                                                  ");
			sql.append("     on t0.id = t"
					+ activenum
					+ ".staff_id                                                              ");

			sql.append("   left join (select staff_id, count(*) as "
					+ referralsnum + "                                     ");
			sql.append("                from crm_situation_survey                                                 ");
			sql.append("               where register_date = '" + date
					+ "'                                         ");
			sql.append("                 and nature like '%转介绍的客户%'      ");
			sql.append("               group by staff_id) t" + referralsnum
					+ "                                                  ");
			sql.append("     on t0.id = t"
					+ referralsnum
					+ ".staff_id                                                              ");
			i++;
		}

		sql.append("    where 1=1                                                           ");

		// 如果name有值,id为空;那么按name取like
		// 如果name为空,不加判断
		// 如果都有;按id。
		boolean nameB = false;
		boolean idB = false;
		if (null != staffName && !"".equals(staffName)
				&& !"undefined".equals(staffName)) {
			nameB = true;
		}
		if (null != staffId && !"".equals(staffId)
				&& !"undefined".equals(staffId)) {
			idB = true;
		}
		if (nameB & idB) {
			sql.append("  and t0.id in(" + staffId
					+ ")                                                 ");// 营销员的范围限定
		} else if (nameB == true && idB == false) {
			if (staffName.indexOf(',') != -1) {// 如果含有逗号包含多个name
				staffName = "'" + staffName + "'";
				staffName = staffName.replaceAll(",", "','");
				sql.append("  and t0.full_name in(" + staffName
						+ ")                                                 ");
			} else {
				sql.append("  and t0.full_name like('%"
						+ staffName
						+ "%')                                                 ");
			}
		}

		// ///营业组范围控制
		// 如果name有值,id为空;那么按name取like
		// 如果name为空,不加判断
		// 如果都有;按id。
		boolean nameGroupB = false;
		boolean idGroupB = false;
		if (null != staffGroupName && !"".equals(staffGroupName)
				&& !"undefined".equals(staffGroupName)) {
			nameGroupB = true;
		}
		if (null != staffGroupId && !"".equals(staffGroupId)
				&& !"undefined".equals(staffGroupId)) {
			idGroupB = true;
		}
		if (nameGroupB & idGroupB) {
			sql.append("  and t0.group_id in(" + staffGroupId
					+ ")                                                 ");// 营销员的范围限定
		} else if (nameGroupB == true && idGroupB == false) {
			if (staffGroupName.indexOf(',') != -1) {// 如果含有逗号包含多个name
				staffGroupName = "'" + staffGroupName + "'";
				staffGroupName = staffGroupName.replaceAll(",", "','");
				sql.append("  and t0.group_name in(" + staffGroupName
						+ ")                                                 ");
			} else {
				sql.append("  and t0.group_name like('%"
						+ staffGroupName
						+ "%')                                                 ");
			}
		}

		// ///营业部范围控制
		// 如果name有值,id为空;那么按name取like
		// 如果name为空,不加判断
		// 如果都有;按id。
		boolean nameDeptB = false;
		boolean idDeptB = false;
		if (null != staffDeptName && !"".equals(staffDeptName)
				&& !"undefined".equals(staffDeptName)) {
			nameDeptB = true;
		}
		if (null != staffDeptId && !"".equals(staffDeptId)
				&& !"undefined".equals(staffDeptId)) {
			idDeptB = true;
		}
		if (nameDeptB & idDeptB) {
			sql.append("  and t0.dept_id in(" + staffDeptId
					+ ")                                                 ");// 营销员的范围限定
		} else if (nameDeptB == true && idDeptB == false) {
			if (staffDeptName.indexOf(',') != -1) {// 如果含有逗号包含多个name
				staffDeptName = "'" + staffDeptName + "'";
				staffDeptName = staffDeptName.replaceAll(",", "','");
				sql.append("  and t0.dept_name in(" + staffDeptName
						+ ")                                                 ");
			} else {
				sql.append("  and t0.dept_name like('%"
						+ staffDeptName
						+ "%')                                                 ");
			}
		}

		// 基于每日的查询结果算出时间段内的合计
		StringBuffer reusltRow = new StringBuffer();
		reusltRow
				.append(" select t.dept_name,t.group_name,    t.full_name,    ");
		String customernumTotal = "";
		String customerScoresnumTotal = "";
		String facenumTotal = "";
		for (int j = 1; j <= dates.size(); j++) {
			customernumTotal = customernumTotal + "customernum" + j + "+";// 客户数
			customerScoresnumTotal = customerScoresnumTotal
					+ "customeScoresrnum" + j + "+";// 分值数
			facenumTotal = facenumTotal + "facenum" + j + "+";// 面谈数
		}
		reusltRow
				.append("    "
						+ customernumTotal.substring(0,
								customernumTotal.length() - 1)
						+ " as customernumTotal , "
						+ customerScoresnumTotal.substring(0,
								customerScoresnumTotal.length() - 1) + " as customerScoresnumTotal ,"
						+ facenumTotal.substring(0, facenumTotal.length() - 1)
						+ " as facenumTotal   , ");

		for (int j = 1; j <= dates.size(); j++) {
			String customernum = "customernum" + j;// 客户数
			String customerScoresnum = "customeScoresrnum" + j;// 分值数
			String facenum = "facenum" + j;// 面谈数
			String newnum = "newnum" + j;
			String visitnum = "visitnum" + j;
			String activenum = "activenum" + j;
			String referralsnum = "referralsnum" + j;

			String newScorenum = "newScorenum" + j;
			String visitScorenum = "visitScorenum" + j;
			String activeScorenum = "activeScorenum" + j;
			String referralsScorenum = "referralsScorenum" + j;

			reusltRow.append(" " + customernum + ", " + customerScoresnum + ","
					+ facenum + "," + newnum+"," +newScorenum +"," +visitnum+"," + visitScorenum+"," +activenum +","
					+ activeScorenum+"," +referralsnum +"," +referralsScorenum +",");
		}
		reusltRow=new StringBuffer(reusltRow.substring(0, reusltRow.length()-1));
		reusltRow.append(" from (");
		reusltRow.append(sql);
		reusltRow.append(")t");
		List<Object[]> result = super.findBySql(reusltRow.toString());
		return result;
	}

	/**
	 * 获取团队长的名字和id
	 * 
	 * @return
	 * @author liuwang
	 * @date 2013-11-29
	 */
	public List<Object[]> getTeamLeader(String name) {

		String sql = "select name,id,code from org_staff where is_active=1 and is_team=1";
		if (null != name && !"".equals(name)) {
			sql = sql + " and name like '%" + name.trim() + "%'";
		}
		List<Object[]> result = super.findBySql(sql);
		return result;
	}

	/**
	 * 获取组长的名字和id
	 * 
	 * @return
	 * @author liuwang
	 * @date 2013-11-29
	 */
	public List<Object[]> getGroupLeader(String name, String teamName) {

		String sql = "select name,id,code from org_staff where is_active=1 and is_group=1";

		if (null != teamName && !"".equals(teamName) && !",".equals(teamName)) {

			if (teamName.indexOf(',') != -1) {// 如果含有逗号包含多个name
				teamName = "'" + teamName + "'";
				teamName = teamName.replaceAll(",", "','");
				sql = sql
						+ " and sales_dept_id in (select  t2.id from org_staff t2 where t2.is_active=1 and t2.is_team=1 and t2.name in("
						+ teamName + ") )";
			} else {
				sql = sql
						+ " and sales_dept_id in (select  t2.id from org_staff t2 where t2.is_active=1 and t2.is_team=1 and t2.name like '%"
						+ teamName.trim() + "%' )";
			}

		}
		if (null != name && !"".equals(name)) {
			sql = sql + " and name like '%" + name.trim() + "%'";
		}
		List<Object[]> result = super.findBySql(sql);
		return result;
	}

	/**
	 * 获取营业员的名字和id
	 * 
	 * @return
	 * @author liuwang
	 * @date 2013-11-29
	 */
	public List<Object[]> getStaff(String name, String teamName,
			String groupName) {

		String sql = "select name,id,code from org_staff where is_active=1 and staff_type=1 ";

		if (null != groupName && !"".equals(groupName)
				&& !",".equals(groupName)) {

			if (groupName.indexOf(',') != -1) {// 如果含有逗号包含多个name
				groupName = "'" + groupName + "'";
				groupName = groupName.replaceAll(",", "','");
				sql = sql
						+ " and sales_group_id in (select  t.id from org_staff t where t.is_active=1 and t.is_group=1 and t.name  in("
						+ groupName + ") )";
			} else {
				sql = sql
						+ " and sales_group_id in (select  t.id from org_staff t where t.is_active=1 and t.is_group=1 and t.name like '%"
						+ groupName.trim() + "%' )";
			}
		}
		if (null != teamName && !"".equals(teamName) && !",".equals(teamName)) {

			if (teamName.indexOf(',') != -1) {// 如果含有逗号包含多个name
				teamName = "'" + teamName + "'";
				teamName = teamName.replaceAll(",", "','");
				sql = sql
						+ " and sales_dept_id in (select  t2.id from org_staff t2 where t2.is_active=1 and t2.is_team=1 and t2.name in("
						+ teamName + ") )";
			} else {
				sql = sql
						+ " and sales_dept_id in (select  t2.id from org_staff t2 where t2.is_active=1 and t2.is_team=1 and t2.name like '%"
						+ teamName.trim() + "%' )";
			}
		}
		if (null != name && !"".equals(name)) {
			sql = sql + " and name like '%" + name.trim() + "%'";
		}
		List<Object[]> result = super.findBySql(sql);
		return result;
	}
分享到:
评论

相关推荐

    周到访客户情况统计表格式.doc

    周到访客户情况统计表格式.doc

    客户跟踪情况统计表.doc

    客户跟踪情况统计表.doc

    进销存管理系统详细说明

    客户情况统计分析 累计购货情况统计分析 各客户销售、利润情况统计分析 客户累计购买某商品情况统计分析  (4) 供应商情况统计分析 累计供货情况统计分析 各供应商供货情况排行榜 供应商累计供应某商品情况分析  ...

    银行客户风险统计报送系统技术方案 .doc

    4.2.2. (对公担保)对公客户担保情况统计表 11 4.2.3. (个人贷款违约)个人贷款违约情况统计表 11 4.2.4. (单一法人客户)单一法人客户基本信息统计表 12 4.2.5. 集团客户、供应链融资基本信息统计表 12 4.2.6. ...

    培训专题-94、阿里巴巴内部培训资料:销售的心态和时间管理.pdf

    老客户情况统计表; 3 更新和完善SALESKITS1 每日CRM 客户翻牌 4 每月月底--下月forecast及目标客户 5 每月签约客户情况总结 6 下月回访客户 7 下月续约客户 时间公式 每天见3个客户节省 30分钟*3= 90分钟 多开发30...

    培训专题-109、阿里巴巴内部培训资料:销售的心态和时间管理.pdf

    老客户情况统计表; 3 更新和完善SALESKITS1 每日CRM 客户翻牌 4 每月月底--下月forecast及目标客户 5 每月签约客户情况总结 6 下月回访客户 7 下月续约客户 时间公式 每天见3个客户节省 30分钟*3= 90分钟 多开发30...

    VIP大客户管理 delphi

    2.1.9 客户经理重要活动及奖罚情况 2-15 2.1.10 客户经理培训记录 2-15 2.1.11 客户经理社会关系 2-16 2.1.12 客户经理工作经历 2-16 2.1.13 竞争对手管理 2-17 2.1.14 竞争对手营销策略管理 2-17 2.1.15 竞争对手...

    销售情况统计

    可以统计销售情况,利用VFP编写。首先把明细销售记录取出来,然后情况客户按月份逐个汇总,生成汇总表。

    PHPStat网站流量统计软件 v3.2

    ,周统计报表 ,月统计报表 ,年统计报表 ,客户端情况统计 ,用户操作系统统计 ,用户浏览器统计 ,屏幕分辨率统计 ,访问者地区统计 ,访问统计分析 ,访问者来路统计 ,搜索引擎统计 ,搜索关键字统计 ,访问者访次统计 ,C段IP...

    JYC统计-超强网站访问统计分析系统

    鼠标点击热点功能实时查看 支持任意时间段 多种查询条件的统计分析展现 准确告诉您页面热点情况 为您提供广告战略决策支持 准确把握每一个访客的访问行为轨迹 了解客户心理 更好的为其提供个性化服务 未知地区...

    PHPStat网站流量统计软件 v3.2 免费版.zip

    ,周统计报表 ,月统计报表 ,年统计报表 ,客户端情况统计 ,用户操作系统统计 ,用户浏览器统计 ,屏幕分辨率统计 ,访问者地区统计 ,访问统计分析 ,访问者来路统计 ,搜索引擎统计 ,搜索关键字统计 ,访问者访次统计 ,C段IP...

    网站访问统计分析介绍

    在国际上,从网络营销管理的角度考虑,网站流量分析是指在获得网站访问量基本数据的情况下,对有关数据进行统计、分析,从中发现用户访问网站的规律,并将这些规律与网络营销策略等相结合,从而发现目前网络营销活动...

    准确快速地统计出源代码中的各种行数

    代码行统计,统计类型多样,统计代码率准确。...网络上也有不少类似统计行数的软件,但到目前为止,我发现“源码统计器1.0版”统计速度是最快的,而且相比较发现更加准确,考虑到了源代码中可能出现的许多特殊情况

    客户关系管理系统(CRM)毕业项目

    并希望系统提供相关报表,以便公司高层随时了解公司客户情况。 客户服务是一个涉及多个部门,存在一定流程的工作。客户服务水平的高低决定着公司的核心竞争力。该客户关系管理系统应提供一个客户服务在线平台,使...

    客户信息查询+数据库

    利用JSP、Servlet技术,编写一个客户信息查询的web程序。要求根据输入的客户登录名和密码,在数据库中查找出该客户的姓名、年龄、地址信息,并根据查找情况给出提示信息。

    超易客户管理软件 v3.53 单机版.zip

    超易客户关系管理软件从客户跟踪、客户销售记录、客户资料管理、客户联系、重要事务提醒、到实际结款以及对客户结款情况统计分析的全方位管理 主要功能点:分为客户分组管理,客户等级设置、联系人管理,商品报价,...

    银行客户信息管理系统

    3、意义:通过对客户信息管理系统对企业的实际需求,实现了客户基本信息的输入、修改、查询等功能,并能够按时间和客户区域对业务情况进行统计,自主设定查询条件,实现对业务数据的综合查询。使银行能够全面地、及...

    源码统计器v1.1

    网络上也有不少类似统计行数的软件,但到目前为止,我发现“源码统计器1.1版”统计速度是最快的,而且相比较发现更加准确,考虑到了源代码中可能出现的许多特殊情况。 软件优点: 1、 准确无误。这当然是任何一...

    PHP客户管理系统源码

    自动化的统计并分析客户信息、销售情况等 ·D. 全面掌握公司业务信息,避免人员离职等导致客户流失 ·E. 通过CRM系统的工作流使公司业务流程自动化 1、将程序放置根目录 2、导入9niuwang.sql 数据库 3、修改数据库...

    PHPStat网站流量统计软件V3.0

    ,周统计报表 ,月统计报表 ,年统计报表 ,客户端情况统计 ,用户操作系统统计 ,用户浏览器统计 ,屏幕分辨率统计 ,访问者地区统计 ,访问统计分析 ,访问者来路统计 ,搜索引擎统计 ,搜索关键字统计 ,访问者访次统计 ,C段IP...

Global site tag (gtag.js) - Google Analytics