Browse Source

修改跟进接口

anderx 1 year ago
parent
commit
61325b12df

+ 6 - 4
src/main/java/com/goafanti/customer/controller/AdminCustomerApiController.java

@@ -508,10 +508,11 @@ public class AdminCustomerApiController extends BaseApiController{
 	}
 
 	/** 添加拜访记录、客户跟进
-	 * @throws ParseException
-	 * @throws Exception **/
+	 * @param type 0=客户拜访,2=限定项目拜访
+	 * **/
 	@RequestMapping(value = "/addFollow", method = RequestMethod.POST)
-	public Result addFollow(String userBusinessList,String uid,String ocbId,String contactType,String result,String followTime)  throws BusinessException{
+	public Result addFollow(String userBusinessList,String uid,String ocbId,String contactType,
+							String result,String followTime,Integer type)  throws BusinessException{
 		Result res = new Result();
 		if(StringUtils.isBlank(uid) || StringUtils.isBlank(ocbId)){
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
@@ -532,6 +533,7 @@ public class AdminCustomerApiController extends BaseApiController{
 				list.add(userBusiness);
 			}
 		}
+		if (type==null)type=0;
 		FollowBusinessBo fbb = new FollowBusinessBo();
 		fbb.setOcbId(ocbId);
 		fbb.setUid(uid);
@@ -539,7 +541,7 @@ public class AdminCustomerApiController extends BaseApiController{
 		fbb.setResult(result);
 		fbb.setFollowTime(followTime);
 		fbb.setUserBusinessList(list);
-		customerService.addFollow(fbb,null,1);
+		customerService.addFollow(fbb,null,1,0);
 		return res;
 	}
 

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

@@ -174,7 +174,9 @@ public interface CustomerService {
 	 * @param fbb
 	 * @param mainStatus 0辅助跟进 1主要跟进
 	 */
-	int addFollow(FollowBusinessBo fbb,String ufid,Integer mainStatus) throws BusinessException;
+	int addFollow(FollowBusinessBo fbb,String ufid,Integer mainStatus,Integer type) throws BusinessException;
+
+
 
 	/**
 	 * 查询拜访记录详情

+ 103 - 39
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -780,6 +780,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 	}
 
 	@Override
+
 	public List<OrganizationContactBook> findCustomerContacts(String uid) {
 		List<OrganizationContactBook> list = userMapper.findCustomerContacts(uid, null);
 		for (OrganizationContactBook ob : list) {
@@ -791,9 +792,10 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		return list;
 	}
 
-	@Override
+
 	@Transactional
-	public int addFollow(FollowBusinessBo fbb,String ufid,Integer mainStatus) throws BusinessException {
+	@Override
+	public int addFollow(FollowBusinessBo fbb,String ufid,Integer mainStatus,Integer type) throws BusinessException {
 		// 更新跟进记录表
 		Date followTime=DateUtils.StringToDate(fbb.getFollowTime(),AFTConstants.YYYYMMDDHHMMSS);
 		UserFollow userFollow = new UserFollow();
@@ -812,27 +814,92 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		userFollow.setUid(fbb.getUid());
 		int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), null) + 1;
 		userFollow.setFollowCount(followCount);
-		//处理中间表
-		UserMid um =new UserMid();
-		um.setUid(userFollow.getUid());
-		//检查客户,修改小程序打卡,如果负责人和跟进人是同一个,则刷新最后跟进时间
-		User user = userMapper.selectByPrimaryKey(fbb.getUid());
-		if (aid.equals(user.getAid())){
-			um.setLastFollowTime(userFollow.getCreateTime());
-		}
-		um.setFollowNumber(followCount);
-		um.setFollowExplain(userFollow.getResult());
-		um.setFollowDep(userFollow.getFollowDep());
-		um.setLastFollowType(userFollow.getContactType());
-		um.setFollowAname(a.getName());
-		userMidMapper.updateByUid(um);
+		userFollow.setType(0);
+			//处理中间表
+			UserMid um =new UserMid();
+			um.setUid(userFollow.getUid());
+			//检查客户,修改小程序打卡,如果负责人和跟进人是同一个,则刷新最后跟进时间
+			User user = userMapper.selectByPrimaryKey(fbb.getUid());
+			if (aid.equals(user.getAid())){
+				um.setLastFollowTime(userFollow.getCreateTime());
+			}
+			um.setFollowNumber(followCount);
+			um.setFollowExplain(userFollow.getResult());
+			um.setFollowDep(userFollow.getFollowDep());
+			um.setLastFollowType(userFollow.getContactType());
+			um.setFollowAname(a.getName());
+			userMidMapper.updateByUid(um);
+		if (type==0){
+			addUserFllow( fbb, ufid, mainStatus,followTime,followId);
+		}else if (type==1){
+			addRestrictProject(fbb, ufid, mainStatus,followTime,followId);
+		}
 		userFollowMapper.insert(userFollow);
+
+		return 1;
+	}
+
+	private void addRestrictProject(FollowBusinessBo fbb, String ufid, Integer mainStatus, Date followTime, String followId) {
+		List<LockingReleaseBo> businessLockedList = null;
+		String businessName = "";
+		String ufbId = "";
+		UserBusiness userBusiness = null;
+		UserFollowBusiness userFollowBusiness = null;
+		for (BusinessListBo ub : fbb.getUserBusinessList()) {
+			userBusiness = new UserBusiness();
+			userFollowBusiness = new UserFollowBusiness();
+			ufbId = UUID.randomUUID().toString();
+			businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
+			UserBusiness us = userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
+			if (StringUtils.isNotBlank(ub.getBusinessId())) {
+				// 更新业务表
+				userBusiness.setId(ub.getBusinessId());
+				if (us.getFollowSituation() == 5) {// 如果已签合同,则不允许变更
+					if (ub.getCustomerStatus() != us.getCustomerStatus() && ub.getFollowSituation() != 5) {
+						throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
+					}
+				}
+
+				userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
+				userBusiness.setCustomerStatus(ub.getCustomerStatus());
+				userBusiness.setFollowSituation(ub.getFollowSituation());
+				userBusiness.setRemarks(ub.getRemarks());
+				userBusiness.setUid(fbb.getUid());
+				userBusiness.setUpdateTime(followTime);
+				userBusiness.setAid(TokenManager.getAdminId());
+				userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
+				// 更新业务中间表
+				addUserFollowBusiness(userFollowBusiness, ub.getBusinessProjectId(), ub, ufbId, followId);
+			} else {
+				if (userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "") > 0) {
+					throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST, businessName, ""));
+				}
+				String ubId = UUID.randomUUID().toString();
+				// 更新业务表
+				userBusiness.setId(ubId);
+				userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
+				userBusiness.setCreateTime(followTime);
+				userBusiness.setUpdateTime(followTime);
+				userBusiness.setCustomerStatus(ub.getCustomerStatus());
+				userBusiness.setFollowSituation(ub.getFollowSituation());
+				userBusiness.setUid(fbb.getUid());
+				userBusiness.setAid(TokenManager.getAdminId());
+				userBusiness.setRemarks(ub.getRemarks());
+				userBusinessMapper.insert(userBusiness);
+				// 更新业务中间表
+				addUserFollowBusiness(userFollowBusiness, ubId, ub, ufbId, followId);
+			}
+
+		}
+	}
+
+	private void addUserFllow(FollowBusinessBo fbb,String ufid,Integer mainStatus,Date followTime,String followId) {
+		boolean isUserOwner = false;
 		// 检查客户锁定情况
-		if (fbb.getUserBusinessList()!=null&&fbb.getUserBusinessList().size() > 0) {
-			boolean isUserOwner = false;
+		if (fbb.getUserBusinessList()!=null&& !fbb.getUserBusinessList().isEmpty()) {
 			List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(),
 					TokenManager.getAdminId(), null, 0, UserLockReleaseStatus.LOCKED.getCode());
-			if (userLockedList.size() > 0) {
+			if (!userLockedList.isEmpty()) {
 				isUserOwner = true;
 			}
 			boolean isBusinessOwner = false;
@@ -871,6 +938,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 							throw new BusinessException(
 									new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
 					}
+
 //					if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
 //						if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
 //						lockProject(ub);//锁定客户业务
@@ -885,19 +953,12 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 					userBusiness.setAid(TokenManager.getAdminId());
 					userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
 					// 更新业务中间表
-					userFollowBusiness.setBusinessId(ub.getBusinessProjectId());
-					userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
-					userFollowBusiness.setFollowSituation(ub.getFollowSituation());
-					userFollowBusiness.setId(ufbId);
-					userFollowBusiness.setFollowId(followId);
-					userFollowBusiness.setRemarks(ub.getRemarks());
-					userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
-					userFollowBusinessMapper.insert(userFollowBusiness);
+					addUserFollowBusiness(userFollowBusiness, ub.getBusinessProjectId(), ub, ufbId, followId);
 				} else {
 					// 检查业务锁定情况
 					businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
 							1, UserLockReleaseStatus.LOCKED.getCode());
-					if (businessLockedList.size() > 0) {
+					if (!businessLockedList.isEmpty()) {
 						for (LockingReleaseBo bo : businessLockedList) {
 							if (bo.getAid().equals(TokenManager.getAdminId()))
 								isBusinessOwner = true;
@@ -932,23 +993,26 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 					userBusiness.setRemarks(ub.getRemarks());
 					userBusinessMapper.insert(userBusiness);
 					// 更新业务中间表
-					userFollowBusiness.setBusinessId(ubId);
-					userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
-					userFollowBusiness.setFollowSituation(ub.getFollowSituation());
-					userFollowBusiness.setId(ufbId);
-					userFollowBusiness.setFollowId(followId);
-					userFollowBusiness.setRemarks(ub.getRemarks());
-					userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
-					userFollowBusinessMapper.insert(userFollowBusiness);
+					addUserFollowBusiness(userFollowBusiness, ubId, ub, ufbId, followId);
 				}
 
 			}
 		}
 		if (mainStatus==1){
-		followProject(fbb.getUid());
+			followProject(fbb.getUid());
 		}
-		updateADminUserCountFollow(aid,followTime);
-		return 1;
+		updateADminUserCountFollow(TokenManager.getAdminId(),followTime);
+	}
+
+	private void addUserFollowBusiness(UserFollowBusiness userFollowBusiness, String ub, BusinessListBo ub1, String ufbId, String followId) {
+		userFollowBusiness.setBusinessId(ub);
+		userFollowBusiness.setCustomerStatus(ub1.getCustomerStatus());
+		userFollowBusiness.setFollowSituation(ub1.getFollowSituation());
+		userFollowBusiness.setId(ufbId);
+		userFollowBusiness.setFollowId(followId);
+		userFollowBusiness.setRemarks(ub1.getRemarks());
+		userFollowBusiness.setBusinessProjectId(ub1.getBusinessProjectId());
+		userFollowBusinessMapper.insert(userFollowBusiness);
 	}
 
 	private void updateADminUserCountFollow(String aid, Date transferTime) {

+ 1 - 1
src/main/java/com/goafanti/weChat/service/impl/PublicReleaseServiceImpl.java

@@ -1125,7 +1125,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 							fbb.setFollowTime(DateUtils.formatDate(prd.getClockInTime(), AFTConstants.YYYYMMDDHHMMSS));
 							String ufid = UUID.randomUUID().toString();
 							prd.setUfid(ufid);
-							customerService.addFollow(fbb, ufid, prd.getMainStatus());
+							customerService.addFollow(fbb, ufid, prd.getMainStatus(),0);
 							if (clockIn==1){
 								str = "公出人员打卡";
 							}else if (clockIn==2) {