Browse Source

用户客户统计新增、领取客户修改

anderx 2 years ago
parent
commit
8ab0b20da0

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

@@ -18,5 +18,8 @@ public interface AdminUserCountMapper {
 
     int updateByAidAndDateSelective(AdminUserCount e);
 
-    int updateByaidAndDate(@Param("aid") String aid,@Param("startTime") String startTime, @Param("endTime")String endTime);
+    int updateByaidAndDate(@Param("aid") String aid,@Param("startTime") String startTime,
+                           @Param("endTime")String endTime,@Param("type")Integer type);
+
+    AdminUserCount selectByaidAndDate(@Param("aid") String aid,@Param("startTime") String startTime);
 }

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

@@ -5,6 +5,7 @@ import com.goafanti.app.bo.UserBasicInfo;
 import com.goafanti.common.bo.OutUser;
 import com.goafanti.common.bo.userDaysBo;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.model.AdminUserCount;
 import com.goafanti.common.model.OrganizationContactBook;
 import com.goafanti.common.model.User;
 import com.goafanti.customer.bo.*;
@@ -238,4 +239,8 @@ public interface UserMapper {
 
     List<String> selectBelongByaid(String aid);
 
+    AdminUserCount selectByaidAndDate(@Param("aid") String aid, @Param("startTime") String startTime,
+                                      @Param("endTime")String endTime);
+
+    List<AdminUserCount>selectListByaidAndDate(String  aid);
 }

+ 30 - 3
src/main/java/com/goafanti/common/mapper/AdminUserCountMapper.xml

@@ -24,6 +24,7 @@
     where id = #{id,jdbcType=INTEGER}
   </select>
 
+
   <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
     delete from admin_user_count
     where id = #{id,jdbcType=INTEGER}
@@ -174,9 +175,35 @@
   <update id="updateByaidAndDate" >
     update admin_user_count a,(select aid,dates,count(*)counts
         from (select aid,DATE_FORMAT(a.transfer_time , '%Y-%m-%d') dates
-        from user a where status =0 and source in(1,2,3) and share_type=0 and new_channel=0 and aid=  #{aid}
-        and create_time BETWEEN #{startTime} and  #{endTime})x group by aid,dates)b
-    set a.private_count =b.counts
+        from user a where status =0 and source in(1,2,3)
+        <if test="type==0 or type==3">
+          and share_type=0 and new_channel=0
+        </if>
+        <if test="type==1 or type==4">
+          and share_type=0 and new_channel=1
+        </if>
+        <if test="type==5 or type==6">
+          and share_type=2
+        </if>
+        and aid=  #{aid}
+        and transfer_time BETWEEN #{startTime} and  #{endTime})x group by aid,dates)b
+    set
+    <if test="type==0 or type==3">
+        a.private_count =b.counts
+    </if>
+    <if test="type==1 or type==4">
+      a.channel_count =b.counts
+    </if>
+    <if test="type==5 or type==6">
+      a.sign_count =b.counts
+    </if>
     where a.aid=b.aid and a.date_time=b.dates
   </update>
+
+  <select id="selectByaidAndDate"  resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+    from admin_user_count
+    where aid= #{aid} and date_time=#{startTime}
+  </select>
 </mapper>

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

@@ -2344,4 +2344,24 @@ inner join(
 		where aid= #{aid} and share_type in (0,2)
 	</select>
 
+	<select id="selectByaidAndDate" resultType="com.goafanti.common.model.AdminUserCount">
+		SELECT aid,dateTime,sum(privateCount)privateCount,sum(channelCount)channelCount,sum(signCount)signCount
+		from ( select aid,DATE_FORMAT(a.transfer_time , '%Y-%m-%d') dateTime,
+					  if(share_type=0 and new_channel=0,1,0) privateCount,
+					  if(share_type=0 and new_channel=1,1,0)channelCount, if(share_type=2,1,0)signCount
+			   from user a where status =0 and source in(1,2,3) and aid= #{aid}
+				and transfer_time  BETWEEN #{startTime} and #{endTime}
+		    )x group by aid,dateTime
+	</select>
+	<select id="selectListByaidAndDate" resultType="com.goafanti.common.model.AdminUserCount">
+		SELECT aid,dateTime,sum(privateCount)privateCount,sum(channelCount)channelCount,sum(signCount)signCount
+		from ( select aid,DATE_FORMAT(a.transfer_time , '%Y-%m-%d') dateTime,
+		if(share_type=0 and new_channel=0,1,0) privateCount,
+		if(share_type=0 and new_channel=1,1,0)channelCount, if(share_type=2,1,0)signCount
+		from user a where status =0 and source in(1,2,3) and aid= #{aid}
+		<if test="startTime!=null or endTime !=null">
+			and transfer_time  BETWEEN #{startTime} and #{endTime}
+		</if>
+		)x group by aid,dateTime
+	</select>
 </mapper>

+ 31 - 3
src/main/java/com/goafanti/common/utils/AsyncUtils.java

@@ -56,12 +56,40 @@ public class AsyncUtils {
 	private TOrderMidMapper tOrderMidMapper;
 	@Autowired
 	private RoleMapper roleMapper;
+@Autowired
+	private UserMapper userMapper;
+@Autowired
+	private AdminUserCountMapper adminUserCountMapper;
+
+    public  void updateAdminUserCount(String aid, String transferId) {
+		List<AdminUserCount> list1 = userMapper.selectListByaidAndDate(aid);
+		List<AdminUserCount> list2 = userMapper.selectListByaidAndDate(transferId);
+		pushAdminUserCount(list1);
+		pushAdminUserCount(list2);
+	}
 
+	private void pushAdminUserCount(List<AdminUserCount> list) {
+		for (AdminUserCount e : list) {
+			String startTime=DateUtils.formatDate(e.getDateTime(),AFTConstants.YYYYMMDD);
+			AdminUserCount selectAUC = adminUserCountMapper.selectByaidAndDate(e.getAid(), startTime);
+			AdminUserCount newAUC=new AdminUserCount();
+			newAUC.setId(e.getId());
+			if (selectAUC==null){
+				adminUserCountMapper.insertSelective(e);
+			}else {
+				if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
+				if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
+				if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
+				newAUC.setPrivateCount(selectAUC.getPrivateCount());
+				newAUC.setChannelCount(selectAUC.getChannelCount());
+				newAUC.setSignCount(selectAUC.getSignCount());
+				adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
+			}
+		}
+	}
 
 
-
-
-	public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException {
+    public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException {
 		SendEmailUtil.getInstance().patentSend(bo);
 	}
 

+ 93 - 14
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -451,23 +451,42 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		}
 		addUserLock(uid, TokenManager.getAdminId(), now, uList);
 		addUserTransferLog(uid, TokenManager.getAdminId(), null,0, null, now, uList);
-		updateAdminUserCountAddPrivate(user);
+
+		updateAdminUserCount(user.getAid(),user.getTransferTime());
 		return 1;
 	}
 
-	private void updateAdminUserCountAddPrivate(User user) {
-		String startTime=DateUtils.formatDate(user.getTransferTime(),AFTConstants.YYYYMMDD);
+	/**
+	 *
+	 * @param  aid    管理员编号
+	 * @param  transferTime  客户转换时间
+	 */
+	private void updateAdminUserCount(String aid ,Date transferTime) {
+		String startTime=DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
 		String endTime=startTime+" 23:59:59";
-		//
-		Integer i = adminUserCountMapper.updateByaidAndDate(user.getAid(), startTime, endTime);
-		if (i==null||i==0){
-			AdminUserCount adminUserCount=new AdminUserCount();
-			adminUserCount.setDateTime(user.getTransferTime());
-			adminUserCount.setPrivateCount(1);
-			adminUserCount.setAid(user.getAid());
-			adminUserCountMapper.insertSelective(adminUserCount);
-		}
+		AdminUserCount adminUserCount = adminUserCountMapper.selectByaidAndDate(aid, startTime);
+		if (adminUserCount==null){
+			AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
+			adminUserCountMapper.insertSelective(selectAUC);
+		}else {
+			AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
+			AdminUserCount newAUC=new AdminUserCount();
+			newAUC.setId(adminUserCount.getId());
+			if (selectAUC==null){
+				newAUC.setPrivateCount(0);
+				newAUC.setChannelCount(0);
+				newAUC.setSignCount(0);
+			}else {
+				if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
+				if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
+				if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
+				newAUC.setPrivateCount(selectAUC.getPrivateCount());
+				newAUC.setChannelCount(selectAUC.getChannelCount());
+				newAUC.setSignCount(selectAUC.getSignCount());
+			}
 
+			adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
+		}
 	}
 
 	private void checkUserName(InputAddCustomer in) {
@@ -1251,6 +1270,9 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		user.setId(uid);
 		user.setTransferTime(now);
 		int flag = 0;
+		//记录旧数据值,与新数据值 将旧数据与新数据都需要更新
+		List<User> useList=new ArrayList<>();
+		List<User> newList=new ArrayList<>();
 		//领取
 		if (AFTConstants.USER_RECEIVE.equals(operatorType)) {
 			user.setAid(TokenManager.getAdminId());
@@ -1265,6 +1287,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		} else if (AFTConstants.USER_TRANSFER_TO_OTHER.equals(operatorType)
 				|| AFTConstants.SIGN_USER_TRANSFER_TO_OTHER .equals(operatorType)
 				|| AFTConstants.CHANNEL_USER_TRANSFER_TO_OTHER .equals(operatorType)) {
+
 			if (!isUs) {
 				user.setAid(aid);
 				if (data==1||data==3){
@@ -1287,6 +1310,14 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 						throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL, ""));
 				}
 				updateUserMid(aid,uid,0,null);
+				//单客户转交,需要将客户原来得数据修改,需要将新数据刷新
+				User use = userMapper.selectByPrimaryKey(uid);
+				useList.add(use);
+				User newUser=new User();
+				newUser.setAid(aid);
+				newUser.setTransferTime(now);
+				newUser.setShareType(use.getShareType());
+				newList.add(newUser);
 			} else {
 				for (String us : uList) {
 					if (userMapper.getAidAndUser(us, TokenManager.getAdminId()) <= 0){
@@ -1298,6 +1329,14 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 					if (data==2||data==3){
 						updateOrderHandOver(uid,aid,oldAid);
 					}
+					//单客户转交,需要将客户原来得数据修改,需要将新数据刷新
+					User use = userMapper.selectByPrimaryKey(uid);
+					useList.add(use);
+					User newUser=new User();
+					newUser.setAid(aid);
+					newUser.setTransferTime(now);
+					newUser.setShareType(use.getShareType());
+					newList.add(newUser);
 				}
 				if (AFTConstants.USER_TRANSFER_TO_OTHER == operatorType) {
 					flag = updateUsersLock(uList, oldAid, UserLockReleaseStatus.LOCKED.getCode(),
@@ -1328,11 +1367,33 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		}
 		//处理用户客户统计
 		if (AFTConstants.USER_RECEIVE.equals(operatorType)){
-			updateAdminUserCountAddPrivate(user);
+			updateAdminUserCount(user.getAid(),user.getTransferTime());
+		}
+		if (AFTConstants.USER_TRANSFER_TO_OTHER.equals(operatorType)
+				|| AFTConstants.SIGN_USER_TRANSFER_TO_OTHER .equals(operatorType)
+				|| AFTConstants.CHANNEL_USER_TRANSFER_TO_OTHER .equals(operatorType)) {
+			updateAdminUserCountTransfer(useList,newList);
 		}
 		return errors;
 	}
 
+	/**
+	 *
+	 * @param useList
+	 * @param newList
+	 */
+	private void updateAdminUserCountTransfer(List<User> useList, List<User> newList) {
+		for (User u : useList) {
+
+			updateAdminUserCount(u.getAid(),u.getTransferTime());
+		}
+		for (User u : newList) {
+
+			updateAdminUserCount(u.getAid(),u.getTransferTime());
+		}
+
+	}
+
 	@Override
 	public void transferUser(List<String> uList, String aid, String uid) {
 		if(uList.isEmpty())uList.add(uid);
@@ -1432,6 +1493,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 	@Override
 	public int pushReceiveAsChannel(String uid) {
 		Date date = new Date();
+		User use=userMapper.selectByPrimaryKey(uid);
 		User u =new User();
 		String aid=TokenManager.getAdminId();
 		u.setId(uid);
@@ -1445,7 +1507,9 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		addUserLock(uid,aid, date, null); // 指定用户锁定客户
 		updateUserMid(aid,uid,0,null);
 		addUserTransferLog(uid, aid,null, 15, null, date, null);
-		return userMapper.updateByPrimaryKeySelective(u);
+		userMapper.updateByPrimaryKeySelective(u);
+		updateAdminUserCount(use.getAid(),use.getTransferTime());
+		return 1;
 	}
 
 	@Override
@@ -2287,9 +2351,13 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 			utl.setUid(id);
 			userTransferLogMapper.insertSelective(utl);
 			userLockReleaseMapper.updateUserTypeLock(u.getId(), TokenManager.getAdminId(), 0, 2, date);
+			//用户客户统计移除时修改
+			updateAdminUserCount(u.getAid(),u.getTransferTime());
+
 		} else {
 			List<String> list = Arrays.asList(id.split(","));
 			List<UserTransferLog> ulList = new ArrayList<UserTransferLog>();
+			List<User> userList=new ArrayList<>();
 			for (String str : list) {
 				User u = userMapper.selectByPrimaryKey(str);
 				if (!u.getAid().equals(TokenManager.getAdminId())) {
@@ -2301,14 +2369,25 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 				utl.setType(6);
 				utl.setUid(str);
 				ulList.add(utl);
+				userList.add(u);
 			}
+
 			userTransferLogMapper.insertList(ulList);
 			userMapper.updateList(null, null, null, date, 1, list,null);
 			userLockReleaseMapper.updateUserTypeLockList(list, TokenManager.getAdminId(), 0, 2, date);
+			//批量移除客户,需要单独处理客户每天得计算。
+			updateAdminUserAllCount(userList);
 		}
 		return 1;
 	}
 
+	private void updateAdminUserAllCount(List<User> userList) {
+		for (User user : userList) {
+			updateAdminUserCount(user.getAid(),user.getTransferTime());
+		}
+	}
+
+
 	@Override
 	public List<userDaysBo> selectReleaseUserDays(String id) {
 		//渠道

+ 3 - 0
src/main/java/com/goafanti/permission/service/impl/NewRoleServiceImpl.java

@@ -194,6 +194,7 @@ public class NewRoleServiceImpl extends BaseMybatisDao<RoleMapper> implements Ne
 				//所有客户转交给接受者
 				transferUserUpdateExamine(aid,transferId);
 				userMapper.updateDimissionTransfer(aid,transferId);
+				asyncUtils.updateAdminUserCount(aid,transferId);
 			}else if (s==roleResources.QDYW.getCode()) {
 				userTransferLogMapper.insertUserLockLog(aid,transferId,date);
 				patentNewMapper.updateAdmin(aid,transferId);
@@ -216,6 +217,8 @@ public class NewRoleServiceImpl extends BaseMybatisDao<RoleMapper> implements Ne
 		return 1;
 	}
 
+
+
 	/**
 	 *
 	 * @param aid 离职id

+ 1 - 1
src/main/resources/props/config_local.properties

@@ -52,7 +52,7 @@ yxjl_max=100
 amb.maxLvl=6
 
 avatar.host=//static.jishutao.com
-static.host=//static.jishutao.com/1.2.81
+static.host=//static.jishutao.com/1.2.82
 rd.static.host=//static.jishutao.com/RD/1.0.00
 #avatar.host=//172.16.0.255:3000
 #static.host=//172.16.0.255:3000/1.2.62