Browse Source

update

Signed-off-by: anderx <312518615@qq.com>
anderx 5 years ago
parent
commit
64bd0e18d5

+ 3 - 0
src/main/java/com/goafanti/common/dao/UserLockReleaseMapper.java

@@ -117,4 +117,7 @@ public interface UserLockReleaseMapper {
 
 	List<userDaysBo> selectUserDays(@Param("aid")String aid, @Param("x")Integer x, @Param("y")Integer y);
 
+	int updateUserMid(@Param("uid")String uid, @Param("aid")String aid, @Param("followTime")Date followTime, @Param("lockTime")Date lockTime);
+	
+	int insertUserMid(@Param("uid")String uid, @Param("aid")String aid, @Param("followTime")Date followTime, @Param("lockTime")Date lockTime);
 }

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

@@ -444,4 +444,15 @@
 	where datediff(now(),if(t0.lock_time &lt; t1.last_follow_time,t1.last_follow_time,t1.t0.lock_time))> #{x} or datediff(now(),t0.lock_time)> #{y}
   
   </select>
+  
+  
+   <insert id="insertUserMid">
+  insert into user_mid (uid,aid,last_sign_time,last_follow_time,create_time)
+  values (#{uid},#{aid},#{lockTime},#{followTime},now())
+  </insert>
+  <update id="updateUserMid" >
+  update user_mid 
+  set last_sign_time=#{lockTime},last_follow_time=#{followTime}
+  where uid=#{uid} and aid=#{aid}
+  </update> 
 </mapper>

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

@@ -411,36 +411,19 @@
 	</select>
 	
 	<select id="selectPrivateOrganizationCustomerList" resultType="com.goafanti.customer.bo.CustomerListOut">
-			select a.id uid,a.aid,a.identify_name name,a.society_tag societyTag,a.`level`,b.name aName,dg1.name as province,dg2.name as city, a.guidance,
-				dg3.name as area,d.contacts,d.contact_mobile as contactMobile,date_format(t0.last_sign_time,'%Y-%m-%d %H:%i:%S') lastSignTime,
-				date_format(a.transfer_time,'%Y-%m-%d %H:%i:%S') as transferTime,
-			  	date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as createTime,
-				date_format(t1.last_follow_time,'%Y-%m-%d %H:%i:%S') lastFollowTime,
-			  	if(a.transfer_time &lt; t1.last_follow_time,t1.last_follow_time,a.transfer_time) as orderTime
-			from user a left join admin b on  a.aid=b.id 
-			left join organization_identity d on a.id = d.uid left join district_glossory dg1 on d.location_province = dg1.id
-			left join district_glossory dg2 on d.location_city = dg2.id left join district_glossory dg3 on d.location_area = dg3.id
-			<if test="power == 0">
-			left join (select aid,uid,max(lock_time) last_sign_time from user_lock_release where aid= #{aid,jdbcType=VARCHAR} group by uid) t0 on a.id=t0.uid 
-			left join (select uid,aid,max(create_time) last_follow_time from user_follow  where aid= #{aid,jdbcType=VARCHAR} group by uid) t1 on a.id=t1.uid 
-			</if>
-			<if test="power == 1 or power==2">
-			left join (select aid,uid,max(lock_time) last_sign_time from user_lock_release where aid in 
-			<foreach item="item" collection="alist" separator="," open="(" close=")" index="">
-		       #{item}
-		     </foreach> 
-			group by aid,uid) t0 on a.id=t0.uid and a.aid=t0.aid
-			left join (select uid,aid,max(create_time)  last_follow_time from user_follow where aid in 
-			<foreach item="item" collection="alist" separator="," open="(" close=")" index="">
-		       #{item}
-		     </foreach> 
-			 group by aid,uid)t1 on a.id=t1.uid and a.aid=t1.aid
-			</if>
-			<if test="power == 3">
-			left join (select aid,uid,max(lock_time) last_sign_time from user_lock_release group by aid,uid)t0 on a.id=t0.uid
-			left join (select uid,aid,max(create_time)  last_follow_time from user_follow  group by aid,uid)t1 on a.id=t1.uid
-			</if>
-			where a.type= 1 and a.share_type=0  and source !=0
+	select a.id uid,a.aid,a.identify_name name,a.society_tag societyTag,a.`level`,b.name aName,dg1.name as province,dg2.name as city,
+	a.guidance, dg3.name as area,d.contacts,d.contact_mobile as contactMobile,
+	date_format(um.last_sign_time,'%Y-%m-%d %H:%i:%S') lastSignTime,
+	date_format(a.transfer_time,'%Y-%m-%d %H:%i:%S') as transferTime, 
+	date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as createTime,
+	date_format(um.last_follow_time,'%Y-%m-%d %H:%i:%S') lastFollowTime, 
+	if(a.transfer_time &lt; um.last_follow_time,um.last_follow_time,a.transfer_time) as orderTime 
+	from user a left join admin b on a.aid=b.id left join organization_identity d on a.id = d.uid 
+	left join district_glossory dg1 on d.location_province = dg1.id 
+	left join district_glossory dg2 on d.location_city = dg2.id 
+	left join district_glossory dg3 on d.location_area = dg3.id
+	left join user_mid um on um.aid=a.aid and um.uid=a.id
+	where a.type= 1 and a.share_type=0  and a.source in(1,2,3)
 		<if test="power ==0">
 			and a.aid = #{aid,jdbcType=VARCHAR}
 		</if>
@@ -468,7 +451,7 @@
 		<if test="area != null">
 			and d.location_area = #{area,jdbcType=INTEGER}
 		</if>
-		<if test="level != null">
+		 <if test="level != null">
 			and a.level = #{level,jdbcType=INTEGER}
 		</if>
 		<if test="sort != 1">
@@ -482,14 +465,14 @@
 		 </if>
 		 <if test="page_sql != null">
     		${page_sql}
-   		 </if>
+   		 </if> 
 	</select>
 	<select id="selectPrivateOrganizationCustomerCount" resultType="java.lang.Integer">
 			select count(*)
 			from user a left join admin b on  a.aid=b.id 
 			left join organization_identity d on a.id = d.uid left join district_glossory dg1 on d.location_province = dg1.id
 			left join district_glossory dg2 on d.location_city = dg2.id left join district_glossory dg3 on d.location_area = dg3.id
-			where a.type= 1 and a.share_type=0  and source !=0
+			where a.type= 1 and a.share_type=0  and a.source in(1,2,3)
 		<if test="power ==0">
 			and a.aid = #{aid,jdbcType=VARCHAR}
 		</if>
@@ -499,7 +482,6 @@
 		       #{item}
 		     </foreach> 
 		</if>
-		
 		<if test="name != null and name != ''">
 			and a.identify_name like concat('%',#{name},'%')
 		</if>

+ 28 - 0
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -531,6 +531,8 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
 		userFollow.setFollowCount(followCount);
 		userFollowMapper.insert(userFollow);
+		//判断是跟进还是签单
+		int x=0;
 		//检查客户锁定情况
 		if(fbb.getUserBusinessList().size()>0){
 			boolean isUserOwner = false;
@@ -573,6 +575,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 					if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
 						if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
 						lockProject(ub);//锁定客户业务
+						x=1;
 					}		
 					userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
 					userBusiness.setCustomerStatus(ub.getCustomerStatus());
@@ -613,6 +616,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 					if (ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
 						if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
 						lockProject(ub);//锁定客户业务
+						x=1;
 					}
 					String ubId = UUID.randomUUID().toString();
 					//更新业务表
@@ -643,9 +647,32 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 				
 			}
 		}
+		followProject(fbb.getUid(),x);
 		return 1;
 	}
 
+	/**
+	 * 跟进更新用户中间表
+	 * @param ub
+	 */
+	private void followProject(String uid,int x) {
+		Date date =new Date();
+		String aid=TokenManager.getAdminId();
+		if (x==0) {
+			if (userLockReleaseMapper.updateUserMid(uid,aid,date,null)<1) {
+				userLockReleaseMapper.insertUserMid(uid,aid,date,null);
+			}
+		}else {
+			if (userLockReleaseMapper.updateUserMid(uid,aid,date,date)<1) {
+				userLockReleaseMapper.insertUserMid(uid,aid,date,date);
+			}
+		}
+	}
+	
+	/**
+	 * 锁定用户
+	 * @param ub
+	 */
 	private void lockProject(BusinessListBo ub) {
 		UserLockRelease ulr= new UserLockRelease();
 			ulr.setId(UUID.randomUUID().toString());
@@ -664,6 +691,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 			}
 			ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
 			ulr.setUid(ub.getUid());
+			
 			userLockReleaseMapper.insert(ulr);
 		}