Browse Source

拜访记录统计报表接口开发

anderx 7 years ago
parent
commit
63b17a8b7b

+ 6 - 0
src/main/java/com/goafanti/common/dao/UserMapper.java

@@ -1,5 +1,6 @@
 package com.goafanti.common.dao;
 
+import java.util.Date;
 import java.util.List;
 
 import org.apache.ibatis.annotations.Param;
@@ -20,6 +21,7 @@ import com.goafanti.customer.bo.CustomerPersonalDetailBo;
 import com.goafanti.customer.bo.CustomerSimpleBo;
 import com.goafanti.customer.bo.FollowBusinessBo;
 import com.goafanti.customer.bo.LockingReleaseBo;
+import com.goafanti.report.bo.marketingESBo;
 
 public interface UserMapper {
 	/**
@@ -227,4 +229,8 @@ public interface UserMapper {
 	List<User> selectUserByRoleName(@Param("roleName")String roleName);
 	
 	void updateReleaseLock(List<LockingReleaseBo> list);
+
+	marketingESBo marketingStatistics(@Param("id")String id, @Param("dailyStart")String dailyStart, @Param("dailyEnd")String dailyEnd);
+
+	marketingESBo marketingDepStatistics(@Param("id")String id, @Param("dailyStart")String dailyStart, @Param("dailyEnd")String dailyEnd);
 }

+ 48 - 13
src/main/java/com/goafanti/common/mapper/DailySalesReportMapper.xml

@@ -167,17 +167,18 @@
   </select>
   
    <select id="findmarketingStatisticsListByPage" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
-  	select a.id ,a.name,a.department_id,d.name,d.manager_id,f.name,c.role_name,ifnull(e.privateCustomersCount,0)as privateCustomersCount
-			from admin a left join user_role b
-			on a.id=b.uid left join role c
-			on b.rid=c.id left join department_management d
-			on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
-			on a.id=e.aid left join admin f
-			on d.manager_id=f.id
-			where 1=1
-			and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
-	<if test="position != null">
-		and a.department_id = #{departmentId,jdbcType=VARCHAR}
+		select a.id ,a.name,a.department_id as departmentId,d.name as departmentName,d.manager_id,f.name as departmentManagerName,
+				c.role_name as roleName,ifnull(e.privateCustomersCount,0)as privateCustomersCount,a.create_time as entryTime
+		from admin a left join user_role b
+		on a.id=b.uid left join role c
+		on b.rid=c.id left join department_management d
+		on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
+		on a.id=e.aid left join admin f
+		on d.manager_id=f.id
+		where 1=1
+		and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
+	<if test="id != null">
+		and a.department_id = #{id,jdbcType=VARCHAR}
 	</if>
 	order by a.create_time desc
 	<if test="page_sql!=null">
@@ -195,9 +196,43 @@
 			on d.manager_id=f.id
 			where 1=1
 			and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
-	<if test="position != null">
-		and a.department_id = #{departmentId,jdbcType=VARCHAR}
+	<if test="id != null">
+		and a.department_id = #{id,jdbcType=VARCHAR}
 	</if>
   </select>
   
+  
+  <select id="findmarketingDepStatisticsListByPage" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
+		select a.id as departmentId,a.name as departmentName
+	from department_management a left join admin b
+	on a.id=b.department_id left join user_role c
+	on b.id =c.uid left join role d
+	on c.rid =d.id 
+	where 1=1
+	and (d.role_name='营销员' or d.role_name='营销经理'or d.role_name='营销管理员')
+	<if test="id != null">
+		and a.id = #{id,jdbcType=VARCHAR}
+	</if>
+	group by a.id
+	order by a.create_time desc
+	<if test="page_sql!=null">
+			${page_sql}
+	</if>
+  </select>
+  
+  <select id="findmarketingDepStatisticsCount" parameterType="String" resultType="java.lang.Integer">
+  	select count(0)
+	from (select a.id,a.name
+	from department_management a left join admin b
+	on a.id=b.department_id left join user_role c
+	on b.id =c.uid left join role d
+	on c.rid =d.id 
+	where 1=1
+	and (d.role_name='营销员' or d.role_name='营销经理'or d.role_name='营销管理员')
+	<if test="id != null">
+		and a.id = #{id,jdbcType=VARCHAR}
+	</if>
+	group by a.id)x
+	</select>
+  
 </mapper>

+ 33 - 0
src/main/java/com/goafanti/common/mapper/UserMapperExt.xml

@@ -1598,4 +1598,37 @@
 			#{item.uid}
 		</foreach>
     </update>
+    
+    <select id="marketingStatistics" parameterType="java.lang.String" resultType="com.goafanti.report.bo.marketingESBo">
+   	 		select
+			aid,
+			count(0) as yearFollowNo,
+			ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo, 
+			ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
+			from user_follow where 1=1
+			and aid = #{id,jdbcType=VARCHAR}
+			and create_time &gt; #{dailyStart,jdbcType=VARCHAR}
+			and create_time &lt; #{dailyEnd,jdbcType=VARCHAR}
+			GROUP BY aid
+	</select>
+	<select id="marketingDepStatistics" parameterType="java.lang.String" resultType="com.goafanti.report.bo.marketingESBo">
+	   	 					select
+		b.department_id,
+		count( 0 ) as yearFollowNo,
+		ifnull(
+			sum( case when a.contact_type = 0 then 1 else 0 end ),
+			0
+		) as yearVisitNo,
+		ifnull(
+			sum( case when a.contact_type = 1 then 1 else 0 end ),
+			0
+		) as yearTelNo
+	from user_follow a left join admin b on a.aid =b.id
+	where
+		1 = 1
+		and b.department_id = #{id,jdbcType=VARCHAR}
+		and a.create_time &gt; #{dailyStart,jdbcType=VARCHAR}
+		and a.create_time &lt; #{dailyEnd,jdbcType=VARCHAR}
+		GROUP BY b.department_id
+	</select>
 </mapper>

+ 12 - 0
src/main/java/com/goafanti/report/bo/marketingESBo.java

@@ -52,72 +52,84 @@ public class marketingESBo {
 			this.privateCustomersCount = privateCustomersCount;
 		}
 		public String getDailyVisitNo() {
+			if (null==dailyVisitNo)	return "0";
 			return dailyVisitNo;
 		}
 		public void setDailyVisitNo(String dailyVisitNo) {
 			this.dailyVisitNo = dailyVisitNo;
 		}
 		public String getDailyTelNo() {
+			if (null==dailyTelNo)	return "0";
 			return dailyTelNo;
 		}
 		public void setDailyTelNo(String dailyTelNo) {
 			this.dailyTelNo = dailyTelNo;
 		}
 		public String getDailyFollowNo() {
+			if (null==dailyFollowNo)	return "0";
 			return dailyFollowNo;
 		}
 		public void setDailyFollowNo(String dailyFollowNo) {
 			this.dailyFollowNo = dailyFollowNo;
 		}
 		public String getWeeklyVisitNo() {
+			if (null==weeklyVisitNo)	return "0";
 			return weeklyVisitNo;
 		}
 		public void setWeeklyVisitNo(String weeklyVisitNo) {
 			this.weeklyVisitNo = weeklyVisitNo;
 		}
 		public String getWeeklyTelNo() {
+			if (null==weeklyTelNo)	return "0";
 			return weeklyTelNo;
 		}
 		public void setWeeklyTelNo(String weeklyTelNo) {
 			this.weeklyTelNo = weeklyTelNo;
 		}
 		public String getWeeklyFollowNo() {
+			if (null==weeklyFollowNo)	return "0";
 			return weeklyFollowNo;
 		}
 		public void setWeeklyFollowNo(String weeklyFollowNo) {
 			this.weeklyFollowNo = weeklyFollowNo;
 		}
 		public String getMonthVisitNo() {
+			if (null==monthVisitNo)	return "0";
 			return monthVisitNo;
 		}
 		public void setMonthVisitNo(String monthVisitNo) {
 			this.monthVisitNo = monthVisitNo;
 		}
 		public String getMonthTelNo() {
+			if (null==monthTelNo)	return "0";
 			return monthTelNo;
 		}
 		public void setMonthTelNo(String monthTelNo) {
 			this.monthTelNo = monthTelNo;
 		}
 		public String getMonthFollowNo() {
+			if (null==monthFollowNo)	return "0";
 			return monthFollowNo;
 		}
 		public void setMonthFollowNo(String monthFollowNo) {
 			this.monthFollowNo = monthFollowNo;
 		}
 		public String getYearVisitNo() {
+			if (null==yearVisitNo)	return "0";
 			return yearVisitNo;
 		}
 		public void setYearVisitNo(String yearVisitNo) {
 			this.yearVisitNo = yearVisitNo;
 		}
 		public String getYearTelNo() {
+			if (null==yearTelNo)	return "0";
 			return yearTelNo;
 		}
 		public void setYearTelNo(String yearTelNo) {
 			this.yearTelNo = yearTelNo;
 		}
 		public String getYearFollowNo() {
+			if (null==yearFollowNo)	return "0";
 			return yearFollowNo;
 		}
 		public void setYearFollowNo(String yearFollowNo) {

+ 7 - 6
src/main/java/com/goafanti/report/controller/ReportApiController.java

@@ -112,15 +112,16 @@ public class ReportApiController extends BaseApiController {
 	@RequestMapping(value = "/sales/marketingStatistics", method = RequestMethod.GET)
 	public Result marketingStatistics(String depId,Integer type,Integer pNo,Integer pSize) {
 		Result res=new Result();
-		if (StringUtils.isBlank(depId)) {
-			 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到部门", "部门"));
-	            return res;
-		}
+		
 		if (null==type||type>1) {
-			 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到部门", "部门"));
+			 res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "参数错误", "参数"));
 	            return res;
 		}
-		return res.data(reportService.marketingStatistics(depId, type,pNo,pSize));
+		if (Integer.valueOf(type)==0) {
+			return res.data(reportService.marketingStatistics(depId,pNo,pSize));
+		}else {
+			return res.data(reportService.marketingDepStatistics(depId,pNo,pSize));
+		}
 	}
 
 }

+ 116 - 13
src/main/java/com/goafanti/report/service/SalesReportServiceImpl.java

@@ -1,6 +1,7 @@
 package com.goafanti.report.service;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.HashMap;
@@ -10,13 +11,13 @@ import java.util.Optional;
 import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
-
-import com.goafanti.achievement.bo.AchievementListBo;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.DailySalesReportMapper;
+import com.goafanti.common.dao.UserMapper;
 import com.goafanti.common.error.BusinessException;
 import com.goafanti.common.model.DailySalesReport;
 import com.goafanti.core.mybatis.BaseMybatisDao;
@@ -34,6 +35,8 @@ public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMappe
 
 	@Autowired
 	DailySalesReportMapper salesReportMapper;
+	@Autowired
+	UserMapper userMapper;
 
 	public int insertDailyReports(Date startTime, Date endTime) {
 		List<DailySalesReport> list = salesReportMapper.selectAdmins();
@@ -247,7 +250,7 @@ public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMappe
 	}
 
 	@SuppressWarnings("unchecked")
-	public Pagination<marketingESBo> marketingStatistics(String depId, Integer type,Integer pNo,Integer pSize) {
+	public Pagination<marketingESBo> marketingStatistics(String depId,Integer pNo,Integer pSize) {
 		if (pNo == null || pNo < 0) {
 			pNo = 1;
 		}
@@ -259,24 +262,124 @@ public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMappe
 		if (StringUtils.isNotBlank(depId)) {
 			params.put("depId", depId);
 		}
-		if (null!=type) {
-			params.put("type", type);
-		}
-
 		Pagination<marketingESBo> p=(Pagination<marketingESBo>) findPage("findmarketingStatisticsListByPage",
 				"findmarketingStatisticsCount",params,
 				pNo, pSize);
 		List<marketingESBo> list=(List<marketingESBo>) p.getList();
+		List<marketingESBo> l=new ArrayList<>();
 		
-		if (type==0) {
+			ReportDate rd = new ReportDate(new Date());
+			
 			for (marketingESBo m : list) {
-				ReportDate rd = new ReportDate(new Date());
-				//salesReportMapper.get(m.getId(),rd.getDailyStart(), rd.getDailyStart());
+				marketingESBo day=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getDailyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getDailyEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (day!=null&&StringUtils.isBlank(day.getYearFollowNo())) {
+					m.setDailyFollowNo(day.getYearFollowNo());
+				}
+				if (day!=null&&StringUtils.isBlank(day.getYearTelNo())) {
+					m.setDailyTelNo(day.getYearTelNo());
+				}
+				if (day!=null&&StringUtils.isBlank(day.getYearVisitNo())) {
+					m.setDailyVisitNo(day.getYearVisitNo());
+				}
+				marketingESBo weekly=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getWeeklyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getWeeklyEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (weekly!=null&&StringUtils.isNotBlank(weekly.getYearFollowNo())) {
+					m.setWeeklyFollowNo(weekly.getYearFollowNo());
+				}
+				if (weekly!=null&&StringUtils.isNotBlank(weekly.getYearTelNo())) {
+					m.setWeeklyTelNo(weekly.getYearTelNo());
+				}
+				if (weekly!=null&&StringUtils.isNotBlank(weekly.getYearVisitNo())) {
+					m.setWeeklyVisitNo(weekly.getYearVisitNo());
+				}
+				marketingESBo month=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getMonthStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getMonthEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (month!=null&&StringUtils.isNotBlank(month.getYearFollowNo())) {
+					m.setMonthFollowNo(month.getYearFollowNo());
+				}
+				if (month!=null&&StringUtils.isNotBlank(month.getYearTelNo())) {
+					m.setMonthTelNo(month.getYearTelNo());
+				}
+				if (month!=null&&StringUtils.isNotBlank(month.getYearVisitNo())) {
+					m.setMonthVisitNo(month.getYearVisitNo());
+				}
+				marketingESBo year=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getYearStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getYearEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (year!=null&&StringUtils.isNotBlank(year.getYearFollowNo())) {
+					m.setYearFollowNo(year.getYearFollowNo());
+				}
+				if (year!=null&&StringUtils.isNotBlank(year.getYearTelNo())) {
+					m.setYearTelNo(year.getYearTelNo());
+				}
+				if (year!=null&&StringUtils.isNotBlank(year.getYearVisitNo())) {
+					m.setYearVisitNo(year.getYearVisitNo());
+				}
+				l.add(m);
 			}
-			
-		}else {
-			
+			p.setList(l);	
+		return p;
+	}
+
+	@SuppressWarnings("unchecked")
+	public Pagination<marketingESBo> marketingDepStatistics(String depId, Integer pNo, Integer pSize) {
+		if (pNo == null || pNo < 0) {
+			pNo = 1;
+		}
+
+		if (pSize == null || pSize < 0 || pSize > 10) {
+			pSize = 10;
+		}
+		Map<String, Object> params=new HashMap<>();
+		if (StringUtils.isNotBlank(depId)) {
+			params.put("depId", depId);
 		}
+		Pagination<marketingESBo> p=(Pagination<marketingESBo>) findPage("findmarketingDepStatisticsListByPage","findmarketingDepStatisticsCount",params,pNo, pSize);
+		List<marketingESBo> list=(List<marketingESBo>) p.getList();
+		List<marketingESBo> l=new ArrayList<>();
+		ReportDate rd = new ReportDate(new Date());
+			for (marketingESBo m : list) {
+				marketingESBo day=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getDailyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getDailyEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (day!=null&&StringUtils.isNotBlank(day.getYearFollowNo())) {
+					m.setDailyFollowNo(day.getYearFollowNo());
+					System.out.println(day.getYearFollowNo());
+					System.out.println(m.getDailyFollowNo());
+				}
+				if (day!=null&&StringUtils.isNotBlank(day.getYearTelNo())) {
+					m.setDailyTelNo(day.getYearTelNo());
+				}
+				if (day!=null&&StringUtils.isNotBlank(day.getYearVisitNo())) {
+					m.setDailyVisitNo(day.getYearVisitNo());
+				}
+				marketingESBo weekly=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getWeeklyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getWeeklyEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (weekly!=null&&StringUtils.isNotBlank(weekly.getYearFollowNo())) {
+					m.setWeeklyFollowNo(weekly.getYearFollowNo());
+				}
+				if (weekly!=null&&StringUtils.isNotBlank(weekly.getYearTelNo())) {
+					m.setWeeklyTelNo(weekly.getYearTelNo());
+				}
+				if (weekly!=null&&StringUtils.isNotBlank(weekly.getYearVisitNo())) {
+					m.setWeeklyVisitNo(weekly.getYearVisitNo());
+				}
+				marketingESBo month=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getMonthStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getMonthEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (month!=null&&StringUtils.isNotBlank(month.getYearFollowNo())) {
+					m.setMonthFollowNo(month.getYearFollowNo());
+				}
+				if (month!=null&&StringUtils.isNotBlank(month.getYearTelNo())) {
+					m.setMonthTelNo(month.getYearTelNo());
+				}
+				if (month!=null&&StringUtils.isNotBlank(month.getYearVisitNo())) {
+					m.setMonthVisitNo(month.getYearVisitNo());
+				}
+				marketingESBo year=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getYearStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getYearEnd(), AFTConstants.YYYYMMDDHHMMSS));
+				if (year!=null&&StringUtils.isNotBlank(year.getYearFollowNo())) {
+					m.setYearFollowNo(year.getYearFollowNo());
+				}
+				if (year!=null&&StringUtils.isNotBlank(year.getYearTelNo())) {
+					m.setYearTelNo(year.getYearTelNo());
+				}
+				if (year!=null&&StringUtils.isNotBlank(year.getYearVisitNo())) {
+					m.setYearVisitNo(year.getYearVisitNo());
+				}
+				l.add(m);
+			}
+			p.setList(l);	
 		return p;
 	}