Browse Source

部门统计优化

anderx 3 years ago
parent
commit
4f2fff4801

+ 27 - 4
src/main/java/com/goafanti/admin/service/impl/AdminServiceImpl.java

@@ -46,6 +46,8 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 	@Autowired
 	private UserBusinessMapper	userBusinessMapper;
 	@Autowired
+	private UserMapper	userMapper;
+	@Autowired
 	private DepartmentMapper departmentMapper;
 	@Autowired
 	private DepartmentService departmentService;
@@ -383,7 +385,6 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 			if(TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
 				List<String> myShiroDep = departmentService.selectMyDeps();
 				if (!myShiroDep.contains(depId))throw new BusinessException("无权查看此部门信息");
-
 			}
 			depIds =departmentService.selectSubordinateDeps(depId);
 			Department department = new Department();
@@ -393,7 +394,7 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 		}
 		List<AdminCustomerBo> list =null;
 		//原sql计算
-		list=departmentMapper.AlldepCount(depIds,startTime,  endTime);
+//		list=departmentMapper.AlldepCount(depIds,startTime,  endTime);
 		//新java计算
 		list=AllDepCount(depIds,startTime,endTime);
 		for (AdminCustomerBo ad : list) {
@@ -416,8 +417,30 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 	}
 
 	private List<AdminCustomerBo> AllDepCount(List<Department> depIds, String startTime, String endTime) {
-
-		return null;
+		List<AdminCustomerBo> admins = adminMapper.selectByDeps(depIds);
+		List<AdminCustomerBo> users = 	userMapper.selectNoChannelByaids(admins,startTime,endTime);
+		List<AdminCustomerBo> users2 = 	userMapper.selectChannelByaids(admins,startTime,endTime);
+		for (AdminCustomerBo admin : admins) {
+			for (AdminCustomerBo user : users) {
+					if (admin.getAid().equals(user.getAid())){
+						admin.setUserCount(user.getUserCount());
+						admin.setChannelCount(user.getChannelCount());
+						admin.setSignCount(user.getSignCount());
+						admin.setNewCount(user.getNewCount());
+						admin.setChannelNewCount(user.getChannelNewCount());
+						admin.setReceiveCount(user.getReceiveCount());
+						break;
+					}
+			}
+			for (AdminCustomerBo user : users2) {
+				if (admin.getAid().equals(user.getAid())){
+					admin.setCompleteCount(user.getCompleteCount());
+					admin.setChannelCompleteCount(user.getChannelCompleteCount());
+					break;
+				}
+			}
+		}
+		return admins;
 	}
 
 	//迭代获取所有部门与部门员工并计算出部门数量

+ 4 - 0
src/main/java/com/goafanti/common/dao/AdminMapper.java

@@ -1,8 +1,10 @@
 package com.goafanti.common.dao;
 
 import com.goafanti.admin.bo.AdminContacts;
+import com.goafanti.admin.bo.AdminCustomerBo;
 import com.goafanti.admin.bo.AdminListBo;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.model.Department;
 import com.goafanti.common.model.Role;
 import org.apache.ibatis.annotations.Param;
 
@@ -161,4 +163,6 @@ public interface AdminMapper {
     int selectByAmbIdCount(String id);
 
     List<Admin> selectAdminByRoleType(@Param("roleType") String roleType);
+
+    List<AdminCustomerBo > selectByDeps(@Param("depIds") List<Department> depIds);
 }

+ 4 - 1
src/main/java/com/goafanti/common/dao/UserMapper.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import com.goafanti.admin.bo.AdminCustomerBo;
 import com.goafanti.customer.bo.*;
 import org.apache.ibatis.annotations.Param;
 
@@ -19,7 +20,6 @@ import com.goafanti.user.bo.UserDownLoadBo;
 import com.goafanti.user.bo.UserInterestBo;
 import com.goafanti.user.bo.UserPageHomeBo;
 import com.goafanti.user.bo.UserPartnerDetailBo;
-import com.goafanti.common.model.UserExample;
 import com.goafanti.report.bo.CountMarketingStatisticsBo;
 import com.goafanti.report.bo.marketingESBo;
 import com.goafanti.report.bo.userDataListBo;
@@ -238,4 +238,7 @@ public interface UserMapper {
 
 
     List<OutChannelListBo> channelUserList(Map<String, Object> params);
+
+    List<AdminCustomerBo> selectNoChannelByaids(@Param("admins")List<AdminCustomerBo> admins,@Param("startTime") String startTime,@Param("endTime") String endTime);
+    List<AdminCustomerBo> selectChannelByaids(@Param("admins")List<AdminCustomerBo> admins,@Param("startTime") String startTime,@Param("endTime") String endTime);
 }

+ 11 - 0
src/main/java/com/goafanti/common/mapper/AdminMapper.xml

@@ -1154,4 +1154,15 @@
       and c.role_type  in (#{roleType})
     </if>
   </select>
+    <select id="selectByDeps" resultType="com.goafanti.admin.bo.AdminCustomerBo">
+      SELECT a.id aid,a.name aName,a.department_id depId,d.name depName
+      from admin a left join department d on a.department_id = d.id
+      where a.status =0 and a.`type` =1
+      <if test="depIds!= null">
+        and a.department_id in
+        <foreach close=")" collection="depIds" item="deps" open="(" separator=",">
+          #{deps.id}
+        </foreach>
+      </if>
+    </select>
 </mapper>

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

@@ -2300,4 +2300,38 @@ inner join(
 			and a.transfer_time between #{startDate} and #{endDate}
 		</if>
 	</select>
+
+
+	<select id="selectNoChannelByaids" resultType="com.goafanti.admin.bo.AdminCustomerBo">
+		select aid,sum(if( share_type=0 and channel=0,1,0))userCount,
+		sum(if(share_type=3 and channel=1,1,0))channelCount, sum(if( share_type=2 ,1,0))signCount,
+		sum(if(share_type=0 and source =1 and channel=0,1,0))newCount, sum(if(share_type=0 and source =1 and channel=1,1,0))channelNewCount,
+		sum(if(share_type=0 and source =2 and channel=0,1,0))receiveCount from `user` where `type` =1 and new_channel=0
+		<if test="startTime != null and endTime != null">
+			and  transfer_time  between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
+		</if>
+		<if test="admins!= null">
+			and aid in
+			<foreach close=")" collection="admins" item="ad" open="(" separator=",">
+				#{ad.aid}
+			</foreach>
+		</if>
+		group by aid
+	</select>
+
+	<select id="selectChannelByaids" resultType="com.goafanti.admin.bo.AdminCustomerBo">
+		select a.aid,sum(if(c.channel=0,1,0))completeCount, sum(if(c.channel=1,1,0))channelCompleteCount
+		from public_release a left join public_release_details b on a.id=b.prid left join `user` c on b.uid=c.id
+		where b.clock_in =1
+		<if test="startTime != null and endTime != null">
+			and  c.transfer_time  between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
+		</if>
+		<if test="admins!= null">
+			and a.aid in
+			<foreach close=")" collection="admins" item="ad" open="(" separator=",">
+				#{ad.aid}
+			</foreach>
+		</if>
+		group by a.aid
+	</select>
 </mapper>