Browse Source

释放客户日志

anderx 5 years ago
parent
commit
0dd45681d7

+ 2 - 1
src/main/java/com/goafanti/common/dao/UserLockReleaseMapper.java

@@ -95,7 +95,8 @@ public interface UserLockReleaseMapper {
 			@Param("newStatus")Integer newStatus,@Param("date") Date date);
 	void updateUserTypeLockList(@Param("list")List<String> list, @Param("aid")String aid,@Param("type")Integer type,
 			@Param("newStatus")Integer newStatus,@Param("date") Date date);
-	List<LockingReleaseBo> selectWaitReleaseCustomer(String aid);
+	
+	List<LockingReleaseBo> selectWaitReleaseCustomer(@Param("aid")String aid, @Param("type")Integer type);
 
 	List<LockingReleaseBo> selectWaitReleaseBusiness(String aid);
 

+ 10 - 4
src/main/java/com/goafanti/common/mapper/TOrderNewMapper.xml

@@ -1591,10 +1591,16 @@ left join department d on o.order_dep = d.id   left join t_order_mid a on o.orde
     e.reason,date_format(e.create_time,'%Y-%m-%d') as backDate,a.buyer_id as uid,a.order_dep as orderDep, g.location_province as locationProvince,
     g.location_city as locationCity,g.location_area locationArea,g.postal_address postalAddress,outsource,a.primary_order primaryOrder,a.agreement_url agreementUrl,
     h.name NowFinance,h.contact_mobile NowFinanceMobile,a.additional_order additionalOrder,i.name as oldSalesmanName, i.contact_mobile oldSalesmanMobile
-    from t_order_new a left join `user` b on a.buyer_id=b.id left join admin i on a.old_salesman_id=i.id
-    left join admin c on a.salesman_id=c.id left join department dep on a.order_dep=dep.id left join admin d on a.finance_id=d.id
-    left join admin h on dep.finance_id=h.id left join (select * from t_order_back a where back_status=0) e on a.order_no=e.order_no
-  	left join admin f on e.initiate=f.id left join organization_identity g on a.buyer_id=g.uid
+    from t_order_new a 
+    left join `user` b on a.buyer_id=b.id 
+    left join admin i on a.old_salesman_id=i.id
+    left join admin c on a.salesman_id=c.id 
+    left join department dep on a.order_dep=dep.id 
+    left join admin d on a.finance_id=d.id
+    left join admin h on dep.finance_id=h.id 
+    left join (select * from t_order_back a where back_status=0) e on a.order_no=e.order_no
+  	left join admin f on e.initiate=f.id 
+  	left join organization_identity g on a.buyer_id=g.uid
     where a.order_no = #{orderNo,jdbcType=VARCHAR}
   </select>
   

+ 9 - 6
src/main/java/com/goafanti/common/mapper/UserLockReleaseMapper.xml

@@ -378,17 +378,20 @@
   
   <select id="selectWaitReleaseCustomer" resultType="com.goafanti.customer.bo.LockingReleaseBo">
 	select 
-		t0.id,
-		t0.uid,
-		t0.aid,
-		t0.lock_time,
-		t1.last_follow_time
+		t0.id, t0.uid, t0.aid, t0.lock_time lockTime,
+		t1.last_follow_time lastFollowTime
 	from
 		(select id,uid,aid,lock_time from user_lock_release where aid = #{aid} and type = 0 and status = 0)t0
 	left join 
 		(select uid,aid,max(create_time) as last_follow_time from user_follow where aid = #{aid} group by uid)t1
 	on t0.uid = t1.uid 
-	where datediff(now(),if(t0.lock_time &lt; t1.last_follow_time,t1.last_follow_time,t1.t0.lock_time))>30 or datediff(now(),t0.lock_time)>270
+	where 1=1
+	<if test="type==0">
+	 and datediff(now(),if(t0.lock_time &lt; t1.last_follow_time,t1.last_follow_time,t1.t0.lock_time))>30
+	</if>
+	<if test="type==1">
+	 and datediff(now(),t0.lock_time)>270
+	</if>
   </select>
   
   <select id="selectWaitReleaseBusiness"  resultType="com.goafanti.customer.bo.LockingReleaseBo">

+ 12 - 3
src/main/java/com/goafanti/common/task/ReleaseUserTask.java

@@ -102,11 +102,18 @@ public class ReleaseUserTask {
 			List<User> userList = userServiceImpl.selectUserByRoleName("营销员","营销经理");
 			List<LockingReleaseBo> lockUserList = new ArrayList<LockingReleaseBo>();
 			List<LockingReleaseBo> userTmpList = null;
+			List<LockingReleaseBo> userTmpList2 = null;
 			if (userList!=null&&!userList.isEmpty()) {
 				for(User u : userList){
 					if(StringUtils.isNotBlank(u.getId())) {
-						userTmpList = customerServiceImpl.selectWaitReleaseCustomer(u.getId());
-							if(userTmpList!=null&&!userTmpList.isEmpty())lockUserList.addAll(userTmpList);
+						//获取30天释放
+						userTmpList = customerServiceImpl.selectWaitReleaseCustomer(u.getId(),0);
+						//获取270天释放
+						userTmpList2 = customerServiceImpl.selectWaitReleaseCustomer(u.getId(),1);
+						customerServiceImpl.pushReleaseLog(userTmpList,0);
+						customerServiceImpl.pushReleaseLog(userTmpList2,1);
+						if(userTmpList!=null&&!userTmpList.isEmpty())lockUserList.addAll(userTmpList);
+						if(userTmpList2!=null&&!userTmpList2.isEmpty())lockUserList.addAll(userTmpList2);
 						}
 				}
 			}
@@ -115,7 +122,9 @@ public class ReleaseUserTask {
 				  for(int i=0;i<lockUserList.size();i++){
 					  newList.add(lockUserList.get(i));
 					  if(pointsDataLimit == newList.size()||i == lockUserList.size()-1){
-						  if(newList.size()>0) customerServiceImpl.updatePendingReleaseLock(newList);
+						  if(newList.size()>0) {
+							  customerServiceImpl.updatePendingReleaseLock(newList);
+						  }
 						  newList.clear();
 						  Thread.sleep(2000);
 					  }  

+ 14 - 1
src/main/java/com/goafanti/customer/service/CustomerService.java

@@ -454,7 +454,13 @@ public interface CustomerService {
 	 */
 	Pagination<CustomerListOut> listSignPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize);
 	
-	List<LockingReleaseBo> selectWaitReleaseCustomer(String uid);
+	/**
+	 * 查询需要释放的客户
+	 * @param uid 客户Id
+	 * @param type   0 未跟进  1未签单
+	 * @return
+	 */
+	List<LockingReleaseBo> selectWaitReleaseCustomer(String uid, Integer type);
 	
 	List<LockingReleaseBo> selectWaitReleaseBusiness(String uid);
 	
@@ -519,5 +525,12 @@ public interface CustomerService {
 	int pushGuidance(String uid);
 	
 	boolean checkMax(String aid);
+	/**
+	 * 
+	 * @param list 释放客户
+	 * @param type 0 未跟进  1未签单
+	 * @throws InterruptedException 
+	 */
+	void pushReleaseLog(List<LockingReleaseBo> list,Integer type) throws InterruptedException;
 	
 }

+ 89 - 45
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.alibaba.druid.sql.parser.Token;
 import com.goafanti.common.bo.Error;
 import com.goafanti.common.bo.userDaysBo;
 import com.goafanti.common.constant.AFTConstants;
@@ -996,7 +995,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 			user.setInformationMaintainer(TokenManager.getAdminId());
 			user.setSource(2);//客户来源设置为领取
 			user.setTransferTime(now);
-			flag = addUserLock(uid,TokenManager.getAdminId(),0,null,now,false); //指定用户锁定客户
+			flag = addUserLock(uid,TokenManager.getAdminId(),1,null,now,false); //指定用户锁定客户
 			if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_RECEIVE,""));
 			//取消客户领取时把联系人一并转移
 			//organizationContactBookMapper.updateAdmin(uid,TokenManager.getAdminId());
@@ -1010,35 +1009,16 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 				//查询这个客户是否是登陆人的客户
 				if(userMapper.getAidAndUser(uid,TokenManager.getAdminId())<=0)throw new BusinessException(new Error("请勿非法操作!","请勿非法操作!"));
 				flag = updateUserLock(uid,oldAid,UserLockReleaseStatus.LOCKED.getCode(),UserLockReleaseStatus.RELEASE.getCode()); //原用户释放客户
-				if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),0,null,now,isUs); //指定用户锁定客户
+				if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),2,null,now,isUs); //指定用户锁定客户
 				if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL,""));
-				addtransferLog(uid,null,TokenManager.getAdminId(),String.valueOf(params[0]),0,isUs);
 			}else {
 				for (String us : uList) {
 					if(userMapper.getAidAndUser(us,TokenManager.getAdminId())<=0)throw new BusinessException(new Error("请勿非法操作!","请勿非法操作!"));
 				}
 				flag = updateUsersLock(uList,oldAid,UserLockReleaseStatus.LOCKED.getCode(),UserLockReleaseStatus.RELEASE.getCode()); //原用户释放客户
-				if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),0,null,now,isUs); //指定用户锁定客户
+				if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),2,null,now,isUs); //指定用户锁定客户
 				if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL,""));
-				addtransferLog(uid,null,TokenManager.getAdminId(),String.valueOf(params[0]),0,isUs);
 			}
-		}else if(AFTConstants.SIGN_USER_TRANSFER_TO_OTHER.equals(operatorType)){
-			if(!isUs) {
-				user.setAid(String.valueOf(params[0]));
-				user.setSource(3);//客户来源设置为转交
-				if (AFTConstants.SIGN_USER_TRANSFER_TO_OTHER==operatorType) {
-					user.setShareType(2);
-				}
-				//查询这个客户是否是登陆人的客户
-				if(userMapper.getAidAndUser(uid,TokenManager.getAdminId())<=0)throw new BusinessException(new Error("请勿非法操作!","请勿非法操作!"));
-				addtransferLog(uid,null,TokenManager.getAdminId(),String.valueOf(params[0]),0,isUs);
-			}else {
-				for (String us : uList) {
-					if(userMapper.getAidAndUser(us,TokenManager.getAdminId())<=0)throw new BusinessException(new Error("请勿非法操作!","请勿非法操作!"));
-				}
-				addtransferLog(uid,null,TokenManager.getAdminId(),String.valueOf(params[0]),0,isUs);
-			}
-			
 		}
 		if (isUs) {
 			if (AFTConstants.SIGN_USER_TRANSFER_TO_OTHER==operatorType) {
@@ -1474,40 +1454,64 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		return userLockReleaseMapper.updateUsersLock(uList,aid,oldStatus,newStatus);
 	}
 	
+	/**
+	 * 
+	 * @param uid
+	 * @param aid
+	 * @param type  0录入  1领取 2转交客户 3转交业务
+	 * @param pid
+	 * @param lockTime
+	 * @param isUs
+	 * @return
+	 */
 	private int addUserLock(String uid,String aid,Integer type,String pid,Date lockTime, boolean isUs){
 		if (!isUs) {
 			UserLockRelease ulr = new UserLockRelease();
+			UserTransferLog utl=new UserTransferLog();
 			ulr.setId(UUID.randomUUID().toString());
-			if (type==0) {
-				ulr.setType(0);
-			}else {
-				ulr.setType(1);
-				ulr.setBusinessProjectId(pid);
-			}
+			ulr.setType(0);
 			ulr.setAid(aid);
 			ulr.setLockTime(lockTime);
 			ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
 			ulr.setUid(uid);
 			userLockReleaseMapper.insert(ulr);
+			utl.setType(type);
+			if(type==0||type==1) utl.setAid(aid);
+			else if(type==2||type==3) {
+				utl.setAid(TokenManager.getAdminId());
+				utl.setTakeAid(aid);
+			}
+			if(type==3)utl.setPid(pid);
+			utl.setCreateTime(lockTime);
+			utl.setUid(uid);
+			userTransferLogMapper.insertSelective(utl);
 		}else {
 			List<String> ulist=Arrays.asList(uid.split(","));
 			List<UserLockRelease> ulrList=new ArrayList<>();
+			List<UserTransferLog> utlList=new ArrayList<>();
 			for (String s : ulist) {
 				UserLockRelease ulr = new UserLockRelease();
+				UserTransferLog utl=new UserTransferLog();
 				ulr.setId(UUID.randomUUID().toString());
-				if (type==0) {
-					ulr.setType(0);
-				}else {
-					ulr.setType(1);
-					ulr.setBusinessProjectId(pid);
-				}
+				ulr.setType(0);
 				ulr.setAid(aid);
 				ulr.setLockTime(lockTime);
 				ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
 				ulr.setUid(s);
 				ulrList.add(ulr);
+				if(type==0||type==1) utl.setAid(aid);
+				else if(type==2||type==3) {
+					utl.setAid(TokenManager.getAdminId());
+					utl.setTakeAid(aid);
+				}
+				if(type==3)utl.setPid(pid);
+				utl.setCreateTime(lockTime);
+				utl.setUid(uid);
+				utl.setType(type);
+				utlList.add(utl);
 			}
 			 userLockReleaseMapper.insertList(ulrList);
+			 userTransferLogMapper.insertList(utlList);
 		}
 		return 1;
 	}
@@ -1516,14 +1520,10 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 	
 	
 	
-	/**
-	 * 查询需要释放客户
-	 * @param uid
-	 * @return
-	 */
+	
 	@Override
-	public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid){
-		return userLockReleaseMapper.selectWaitReleaseCustomer(uid);
+	public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid,Integer type){
+		return userLockReleaseMapper.selectWaitReleaseCustomer(uid,type);
 	}
 	
 	/**
@@ -1672,10 +1672,9 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		LockingReleaseBo l=list.get(0);
 		UserLockRelease ul=new UserLockRelease();
 		ul.setId(l.getId());
-
 		ul.setAid(inputId);
 		userLockReleaseMapper.updateByPrimaryKeySelective(ul);
-		addtransferLog(uid,pid,TokenManager.getAdminId(),inputId,1,false);
+		addtransferLog(uid,pid,TokenManager.getAdminId(),inputId,3,false);
 		List<BusinessListBo> bl=userBusinessMapper.selectBusinessProjectByUAPid(uid, TokenManager.getAdminId(), pid);
 		if (bl.size()==1) {
 			UserBusiness ub=new UserBusiness();
@@ -1724,23 +1723,39 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 	@Override
 	public int pushReleaseUser(String id) {
 		Date date =new Date();
+		String aid=TokenManager.getAdminId();
 		if (!id.contains(",")) {
+			
 			User u=userMapper.selectByPrimaryKey(id);
-			if (!u.getAid().equals(TokenManager.getAdminId())) {
+			if (!u.getAid().equals(aid)) {
 				throw new BuilderException("客户归属错误!");
 			}
+			UserTransferLog utl=new UserTransferLog();
 			u.setTransferTime(date);
 			u.setShareType(1);
 			userMapper.updateByPrimaryKeySelective(u);
+			utl.setAid(aid);
+			utl.setCreateTime(date);
+			utl.setType(6);
+			utl.setUid(id);
+			userTransferLogMapper.insertSelective(utl);
 			userLockReleaseMapper.updateUserTypeLock(u.getId(), TokenManager.getAdminId(), 0, 2,date);
 		}else {
 			List<String> list=Arrays.asList(id.split(","));
+			List<UserTransferLog> ulList=new ArrayList<UserTransferLog>();
 			for (String str : list) {
 				User u=userMapper.selectByPrimaryKey(str);
 				if (!u.getAid().equals(TokenManager.getAdminId())) {
 					throw new BuilderException("客户归属错误!");
 				}
+				UserTransferLog utl=new UserTransferLog();
+				utl.setAid(aid);
+				utl.setCreateTime(date);
+				utl.setType(6);
+				utl.setUid(str);
+				ulList.add(utl);
 			}
+			userTransferLogMapper.insertList(ulList);
 			userMapper.updateList(null, null, null,date,1, list);
 			userLockReleaseMapper.updateUserTypeLockList(list, TokenManager.getAdminId(), 0, 2,date);
 		}
@@ -1780,5 +1795,34 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		return false;
 	}
 
+	@Override
+	public void pushReleaseLog(List<LockingReleaseBo> list,Integer type) throws InterruptedException {
+		Date date=new Date();
+		List<LockingReleaseBo> newList=new ArrayList<LockingReleaseBo>();
+		  if (list!=null&&list.size()>0) {
+			  for(int i=0;i<list.size();i++){
+				  newList.add(list.get(i));
+				  if(50 == newList.size()||i == list.size()-1){
+					  if(newList.size()>0) {
+						  List<UserTransferLog> list3=new ArrayList<UserTransferLog>();
+						  for (LockingReleaseBo lrb : newList) {
+							  UserTransferLog utl=new UserTransferLog();
+							  utl.setAid(lrb.getAid());
+							  utl.setCreateTime(date);
+							  if(type==0)utl.setType(4);
+							  else if(type==1)utl.setType(5);
+							  utl.setUid(lrb.getUid());
+							  list3.add(utl);
+						}
+						  userTransferLogMapper.insertList(list3);
+					  }
+					  newList.clear();
+					  Thread.sleep(2000);
+				  }
+			  }
+		  }
+		
+	}
+
 
 }

+ 2 - 4
src/main/java/com/goafanti/order/service/impl/OrderChangeServiceImpl.java

@@ -665,11 +665,9 @@ public class OrderChangeServiceImpl extends BaseMybatisDao<NewOrderChangeMapper>
 		}else if(nob.getType()==OrderChangeType.TDTK.getCode()) {
 			//先将业务锁关闭
 			List<String> list=tOrderTaskMapper.getLockId(nb.getOrderNo(),o.getSalesmanId(),o.getBuyerId());
-			userLockReleaseMapper.updateReleaseList(list);
+			if(!list.isEmpty())userLockReleaseMapper.updateReleaseList(list);
 			int i=userLockReleaseMapper.selectByUidGetCount(o.getSalesmanId(),o.getBuyerId());
-			if (i<1) {
-				userLockReleaseMapper.updateReleaseUser(o.getOrderNo());
-			}
+			if (i<1) userLockReleaseMapper.updateReleaseUser(o.getOrderNo());
 		}
 		//
 		List<TOrderTaskBo> taskBos=tOrderTaskMapper.selectOrderTask(nb.getOrderNo());