| 
					
				 | 
			
			
				@@ -1,11 +1,39 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.gubersail.admin.corp.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gubersail.admin.corp.mapper.CorpsDescMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gubersail.admin.corp.service.ICorpsDescService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.gubersail.dealer.admin.api.corps.entity.PjCorpsDesc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gubersail.admin.goods.service.IBrandDescService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gubersail.dealer.admin.api.corps.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gubersail.dealer.admin.api.corps.vo.CorpsDescVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gubersail.dealer.admin.api.excel.CorpsDescImportExcel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gubersail.dealer.admin.api.goods.entity.PjBrandDesc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.AllArgsConstructor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.core.secure.utils.AuthUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.core.secure.utils.SecureUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.core.tool.api.R; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.core.tool.utils.BeanUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.core.tool.utils.ObjectUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.system.entity.Dept; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.system.feign.ISysClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.system.user.entity.User; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.system.user.entity.UserInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.system.user.enums.UserEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springblade.system.user.feign.IUserClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.interceptor.TransactionAspectSupport; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -16,8 +44,900 @@ import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, PjCorpsDesc> implements ICorpsDescService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final CorpsAttnServiceImpl corpsAttnService;//客户联系人 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final CorpsAddrServiceImpl corpsAddrService;//客户地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final CorpsFilesServiceImpl corpsFilesService;//客户附件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final CorpsTypeDescServiceImpl corpsTypeDescService;//客户类别对应表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final CorpsTypeServiceImpl corpsTypeService;//客户类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final IUserClient userClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final ISysClient sysClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	private final IBrandDescService brandDescService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	public PjCorpsDesc getCorpsDescById(Long attnId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return baseMapper.selectById(attnId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 获取客户详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public CorpsDescVO getMessageByID(PjCorpsDesc corpsDesc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		CorpsDescVO corpsDescVO = new CorpsDescVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PjCorpsDesc desc = baseMapper.selectById(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (desc != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			BeanUtil.copyProperties(desc, corpsDescVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获取客户联系人 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDescVO.setCorpsAttnList(corpsAttnService.list(new QueryWrapper<PjCorpsAttn>().eq("pid", corpsDesc.getId()).eq("is_deleted", 0))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获取客户地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDescVO.setCorpsAddrList(corpsAddrService.list(new QueryWrapper<PjCorpsAddr>().eq("pid", corpsDesc.getId()).eq("is_deleted", 0))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获取客户附件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDescVO.setCorpsFilesList(corpsFilesService.list(new QueryWrapper<PjCorpsFiles>().eq("pid", corpsDesc.getId()).eq("is_deleted", 0))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (org.springframework.util.StringUtils.hasText(desc.getResourceWarehouse())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setResourceWarehouseList(JSONArray.parseArray(desc.getResourceWarehouse(), Long.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获取客户类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<String> longs = corpsTypeDescService.selectTypeId(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDescVO.setCorpsTypeId(String.join(",", longs)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsType> corpsTypeList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!longs.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeList = corpsTypeService.list(new LambdaQueryWrapper<PjCorpsType>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.eq(PjCorpsType::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.eq(PjCorpsType::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.in(PjCorpsType::getId, longs)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			StringBuilder corpsTypeName = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(longs)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (String id : longs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsTypeList.stream().filter(e -> id.equals(e.getId() + "")).findFirst() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						.ifPresent(corpsType -> corpsTypeName.append(corpsType.getCname()).append(",")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				String corpsName = corpsTypeName.substring(0, corpsTypeName.length() - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setCorpsTypeName(corpsName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return corpsDescVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 自定义分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public IPage<CorpsDescVO> selectCorpsDescPage(IPage<CorpsDescVO> page, CorpsDescVO corpsDesc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//获取客户子类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (StringUtils.isNotBlank(corpsDesc.getCorpsTypeId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Long corpsTypeId = Long.parseLong(corpsDesc.getCorpsTypeId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Long> corpsTypeIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsTypeService.selectChildById(corpsTypeId, corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsTypeIdList.add(corpsTypeId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTypeList(corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else if (StringUtils.isNotBlank(corpsDesc.getCorpsTypeName())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			LambdaQueryWrapper<PjCorpsType> lambdaQueryWrapper = new LambdaQueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			lambdaQueryWrapper.eq(PjCorpsType::getCname, corpsDesc.getCorpsTypeName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			lambdaQueryWrapper.eq(PjCorpsType::getIsDeleted, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			lambdaQueryWrapper.eq(PjCorpsType::getTenantId, SecureUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsType> corpsTypeList = corpsTypeService.list(lambdaQueryWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (CollectionUtils.isNotEmpty(corpsTypeList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<Long> corpsTypeIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeList.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsTypeService.selectChildById(item.getId(), corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsTypeIdList.add(item.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setTypeList(corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setIsDeleted(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setStrTenantId(Arrays.asList(AuthUtil.getDeptId().split(","))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (!AuthUtil.getUserRole().contains("admin") && !AuthUtil.getUserRole().contains("老板") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			&& !AuthUtil.getUserRole().contains("销售总览")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (AuthUtil.getUserRole().contains("业务员")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setSalesmanId(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setSalesCompanyId(Long.parseLong(AuthUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		IPage<CorpsDescVO> page1 = page.setRecords(baseMapper.selectCorpsDescPage(page, corpsDesc)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return page1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 新增或修改 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public R submit(CorpsDescVO corpsDescVO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PjCorpsDesc corpsDesc = new PjCorpsDesc(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		BeanUtil.copyProperties(corpsDescVO, corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Long userId = SecureUtil.getUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Date date = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (ObjectUtils.isNotNull(corpsDesc.getBrandId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjBrandDesc> pjBrandDescList = brandDescService.list(new LambdaQueryWrapper<PjBrandDesc>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getType, "PP") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getEnableOrNot, 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.apply("find_in_set(id,'" + corpsDesc.getBrandId() + "')")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!pjBrandDescList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setBrandName(pjBrandDescList.stream().map(PjBrandDesc::getCname).collect(Collectors.joining(","))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsDesc> pjCorpsDesc = baseMapper.selectList(new LambdaQueryWrapper<PjCorpsDesc>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getSalesCompanyId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getCname, corpsDesc.getCname())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (!org.springframework.util.CollectionUtils.isEmpty(corpsDescVO.getResourceWarehouseList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setResourceWarehouse(JSONArray.toJSONString(corpsDescVO.getResourceWarehouseList())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (corpsDesc.getId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!pjCorpsDesc.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("客户" + corpsDesc.getCname() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTenantId(SecureUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateDept(Long.valueOf(SecureUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setSalesCompanyId(Long.valueOf(AuthUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setSalesCompanyName(sysClient.getDept(Long.valueOf(AuthUtil.getDeptId())).getData().getFullName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setEnableOrNot(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Long> ids = pjCorpsDesc.stream().map(PjCorpsDesc::getId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!pjCorpsDesc.isEmpty() && !ids.contains(corpsDesc.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("客户" + corpsDesc.getCname() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTenantId(SecureUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setUpdateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateDept(Long.valueOf(SecureUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setUpdateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			/*List<PjOrder> orderList = orderMapper.selectList(new LambdaQueryWrapper<PjOrder>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjOrder::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjOrder::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjOrder::getCustomerId, corpsDesc.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!orderList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<PjOrder> orders = orderList.stream().filter(item -> !corpsDesc.getCname().equals(item.getCustomerName())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (PjOrder item : orders) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setCustomerName(corpsDesc.getCname()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateUserName(AuthUtil.getUserName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					orderMapper.updateById(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjShip> shipList = shipMapper.selectList(new LambdaQueryWrapper<PjShip>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjShip::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjShip::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjShip::getCustomerId, corpsDesc.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!shipList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<PjShip> ships = shipList.stream().filter(item -> !corpsDesc.getCname().equals(item.getCustomerName())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (PjShip item : ships) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setCustomerName(corpsDesc.getCname()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateUserName(AuthUtil.getUserName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					shipMapper.updateById(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjSettlement> settlementList = settlementMapper.selectList(new LambdaQueryWrapper<PjSettlement>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjSettlement::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjSettlement::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjSettlement::getCorpId, corpsDesc.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!settlementList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<PjSettlement> settlements = settlementList.stream().filter(item -> !corpsDesc.getCname().equals(item.getCorpName())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (PjSettlement item : settlements) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setCorpName(corpsDesc.getCname()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.setUpdateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					settlementMapper.updateById(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		this.saveOrUpdate(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Long pId = corpsDesc.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String tenantId = corpsDesc.getTenantId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户联系人信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		R saveOrUpdateAttn = this.saveOrUpdateAttn(corpsDescVO, userId, pId, tenantId, date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (saveOrUpdateAttn.getCode() != 200) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return saveOrUpdateAttn; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户地址信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		this.saveOrUpdateAddr(corpsDescVO, userId, pId, tenantId, date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户文件信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		this.saveOrUpdateFiles(corpsDescVO, userId, pId, tenantId, date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户与类别对应关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		this.saveOrUpdateTypeDesc(corpsDescVO, userId, pId, date, tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return R.data(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 导入客户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public R importUser(List<CorpsDescImportExcel> data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (CollectionUtils.isEmpty(data)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new SecurityException("导入数据不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Boolean> countList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<String> typeList = data.stream().map(CorpsDescImportExcel::getType).filter(Objects::nonNull).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String type = String.join(",", typeList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsType> pjCorpsTypeList = corpsTypeService.list(new LambdaQueryWrapper<PjCorpsType>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsType::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsType::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsType::getSalesCompanyId, Long.parseLong(AuthUtil.getDeptId())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.apply("find_in_set(cname,'" + type + "')") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (typeList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new RuntimeException("分类不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (pjCorpsTypeList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new RuntimeException("分类不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (pjCorpsTypeList.size() < typeList.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new RuntimeException("导入中的数据,分类字段不存在或者未填分类字段"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<User> user = userClient.getUserByRole(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (user.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new RuntimeException("未查到业务员信息"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//获得所属公司 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Long salesCompanyId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String salesCompanyName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String appletsId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		R<Dept> dept = sysClient.getDept(Long.valueOf(AuthUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (ObjectUtil.isNotEmpty(dept)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			salesCompanyId = dept.getData().getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			salesCompanyName = dept.getData().getFullName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			appletsId = dept.getData().getAppletsId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new SecurityException("数据异常请联系管理员"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String brandName = data.stream().map(CorpsDescImportExcel::getBrandName).filter(Objects::nonNull).distinct().collect(Collectors.joining(",")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjBrandDesc> pjBrandDescList = brandDescService.list(new LambdaQueryWrapper<PjBrandDesc>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjBrandDesc::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjBrandDesc::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.apply("find_in_set(cname,'" + brandName + "')")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		R<String> r = sysClient.getRoleIds(AuthUtil.getTenantId(), "客户"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<String> cname = data.stream().map(CorpsDescImportExcel::getCname).filter(Objects::nonNull).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (cname.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new RuntimeException("客户名称不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		LambdaQueryWrapper<PjCorpsDesc> queryWrapper = new LambdaQueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		queryWrapper.in(PjCorpsDesc::getCname, cname); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		queryWrapper.like(PjCorpsDesc::getCorpType, "KH"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		queryWrapper.eq(PjCorpsDesc::getIsDeleted, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsDesc> selectList = baseMapper.selectList(queryWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		for (CorpsDescImportExcel e : data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsType corpsType = pjCorpsTypeList.stream().filter(item -> item.getCname().equals(e.getType())).findFirst().orElse(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (corpsType == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				countList.add(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			countList.add(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsDesc corpsDesc = new PjCorpsDesc(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCname(e.getCname()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTel(e.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setPriceSystem(e.getPriceSystem()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setAccountPeriod(e.getAccountPeriod()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获得业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (StringUtils.isNotBlank(e.getSalesmanName())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				User user1 = user.stream().filter(item -> item.getRealName().equals(e.getSalesmanName())).findFirst().orElse(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (user1 == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					throw new SecurityException("请输入正确的业务员"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setSalesmanId(user1.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setSalesmanName(user1.getRealName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setSalesCompanyId(salesCompanyId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setSalesCompanyName(salesCompanyName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreditLimit(e.getCreditLimit()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setUseCreditLimit(e.getUseCreditLimit()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCorpType("KH"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(e.getBrandName())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<String> list = Arrays.asList(e.getBrandName().split(",")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (!pjBrandDescList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					List<PjBrandDesc> pjBrandDescs = pjBrandDescList.stream().filter(item -> list.contains(item.getCname())).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (!pjBrandDescs.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						corpsDesc.setBrandName(pjBrandDescList.stream().map(PjBrandDesc::getCname).distinct().collect(Collectors.joining(","))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						StringBuilder brandIds = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						for (PjBrandDesc item : pjBrandDescList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							brandIds.append(item.getId()).append(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						if (ObjectUtils.isNotNull(brandIds.toString())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							corpsDesc.setBrandId(brandIds.substring(0, brandIds.length() - 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						corpsDesc.setBrandName(pjBrandDescList.stream().map(PjBrandDesc::getCname).distinct().collect(Collectors.joining(","))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//名称相等视为重复数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsDesc selectOne = selectList.stream().filter(i-> i.getCname().equals(corpsDesc.getCname())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.findFirst().orElse(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (selectOne == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setCheckStatus("通过"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				baseMapper.insert(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				PjCorpsTypeDesc middle = new PjCorpsTypeDesc(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				middle.setCorpId(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				middle.setCorpTypeId(corpsType.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				middle.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				middle.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				middle.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				middle.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeDescService.save(middle); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (ObjectUtils.isNotNull(corpsDesc.getTel())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					User userData = userClient.loginByAccount("", corpsDesc.getTel(), "4", AuthUtil.getTenantId(), appletsId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (ObjectUtils.isNull(userData)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						//用户不存在,注册用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						User saveUser = new User(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setAppletsId(appletsId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setAccount(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setName(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setRealName(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setUserType(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setPhone(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setDeptId(AuthUtil.getDeptId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						//获取注册用户类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							saveUser.setRoleId(r.getData()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							saveUser.setRoleId(""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						saveUser.setPassword("123456"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						R<Boolean> result = userClient.saveUser(saveUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						if (!result.isSuccess()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							throw new RuntimeException(result.getMsg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						R<UserInfo> resu = userClient.userInfo(AuthUtil.getTenantId(), corpsDesc.getTel(), UserEnum.WECHAT.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						if (resu.isSuccess()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							userData = resu.getData().getUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							throw new RuntimeException("创建用户失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					//保存客户联系人信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					PjCorpsAttn corpsAttn = new PjCorpsAttn(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (ObjectUtils.isNotNull(userData)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						long count = corpsAttnService.count(new LambdaQueryWrapper<PjCorpsAttn>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							.eq(PjCorpsAttn::getUserId, userData.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							.eq(PjCorpsAttn::getTel, corpsDesc.getTel()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							.eq(PjCorpsAttn::getIsDeleted, 0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+							throw new RuntimeException("手机号已存在,提交失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						corpsAttn.setUserId(userData.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setCname(e.getContacts()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setTel(e.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setPid(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setSalesCompanyId(salesCompanyId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setSalesCompanyName(salesCompanyName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttnService.save(corpsAttn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					//保存客户地址信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					PjCorpsAddr corpsAddr = new PjCorpsAddr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setContacts(e.getContacts()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setTel(e.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setBelongtoarea(e.getAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setDetailedAddress(e.getAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setPid(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddr.setDefaultAddres("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAddrService.save(corpsAddr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setId(selectOne.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setUpdateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				baseMapper.updateById(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Boolean> booleanList = countList.stream().filter(e -> e).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (data.size() > booleanList.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return R.fail("导入中的数据,分类字段不存在或者未填分类字段"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else if (data.size() == booleanList.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return R.success("导入成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new SecurityException("导入失败,请仔细检查导入数据"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		/*} catch (Exception exception) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new SecurityException("请检查导入数据" + exception.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 自定义分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public List<CorpsDescVO> selectCorpsDescAll(CorpsDescVO corpsDesc) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//获取客户子类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (StringUtils.isNotBlank(corpsDesc.getCorpsTypeId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Long corpsTypeId = Long.parseLong(corpsDesc.getCorpsTypeId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Long> corpsTypeIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsTypeService.selectChildById(corpsTypeId, corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsTypeIdList.add(corpsTypeId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTypeList(corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else if (StringUtils.isNotBlank(corpsDesc.getCorpsTypeName())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			LambdaQueryWrapper<PjCorpsType> lambdaQueryWrapper = new LambdaQueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			lambdaQueryWrapper.eq(PjCorpsType::getCname, corpsDesc.getCorpsTypeName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			lambdaQueryWrapper.eq(PjCorpsType::getIsDeleted, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			lambdaQueryWrapper.eq(PjCorpsType::getTenantId, SecureUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsType> corpsTypeList = corpsTypeService.list(lambdaQueryWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (CollectionUtils.isNotEmpty(corpsTypeList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<Long> corpsTypeIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeList.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsTypeService.selectChildById(item.getId(), corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsTypeIdList.add(item.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setTypeList(corpsTypeIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setIsDeleted(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setCorpType("KH"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<CorpsDescVO> list = baseMapper.selectCorpsDescPage(null, corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public R saveCorpsDescApp(CorpsDescVO corpsDescVO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PjCorpsDesc corpsDesc = new PjCorpsDesc(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		BeanUtil.copyProperties(corpsDescVO, corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Long userId = SecureUtil.getUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Long deptId = Long.valueOf(AuthUtil.getDeptId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Date date = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (ObjectUtils.isNotNull(corpsDesc.getBrandId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjBrandDesc> pjBrandDescList = brandDescService.list(new LambdaQueryWrapper<PjBrandDesc>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getType, "PP") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjBrandDesc::getEnableOrNot, 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.apply("find_in_set(id,'" + corpsDesc.getBrandId() + "')")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!pjBrandDescList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setBrandName(pjBrandDescList.stream().map(PjBrandDesc::getCname).collect(Collectors.joining(","))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		R<Dept> resDept = sysClient.getDept(Long.parseLong(AuthUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (!resDept.isSuccess() || ObjectUtils.isNull(resDept.getData())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new RuntimeException("未找到小程序id"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		String deptName = resDept.getData().getFullName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsDesc.setCorpType("KH"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (StringUtils.isBlank(corpsDesc.getCname())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return R.data(200, "error", "客户名称不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		User user = userClient.loginByAccount("", corpsDesc.getTel(), "4", AuthUtil.getTenantId(), resDept.getData().getAppletsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (ObjectUtils.isNull(user)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//用户不存在,注册用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			User saveUser = new User(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setAppletsId(resDept.getData().getAppletsId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setAccount(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setName(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setRealName(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setUserType(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setPhone(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setDeptId(AuthUtil.getDeptId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获取注册用户类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			R<String> r = sysClient.getRoleIds(AuthUtil.getTenantId(), "客户"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				saveUser.setRoleId(r.getData()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				saveUser.setRoleId(""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			saveUser.setPassword("123456"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			R<Boolean> result = userClient.saveUser(saveUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!result.isSuccess()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException(result.getMsg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			R<UserInfo> resu = userClient.userInfo(AuthUtil.getTenantId(), corpsDesc.getTel(), UserEnum.WECHAT.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (resu.isSuccess()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				user = resu.getData().getUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("创建用户失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsDesc> pjCorpsDesc = baseMapper.selectList(new LambdaQueryWrapper<PjCorpsDesc>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getCname, corpsDesc.getCname())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsDesc> corpsDescTel = baseMapper.selectList(new LambdaQueryWrapper<PjCorpsDesc>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.eq(PjCorpsDesc::getTel, corpsDesc.getTel())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (null == corpsDesc.getId()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!pjCorpsDesc.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("客户" + corpsDesc.getCname() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!corpsDescTel.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("客户" + corpsDesc.getTel() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setTenantId(SecureUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateDept(Long.valueOf(SecureUtil.getDeptId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setPriceSystem("售价1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setSalesCompanyId(deptId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setSalesCompanyName(deptName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			baseMapper.insert(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Long pId = corpsDesc.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			String tenantId = corpsDesc.getTenantId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//保存客户联系人信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsAttn corpsAttn = new PjCorpsAttn(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(user)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				long count = corpsAttnService.count(new LambdaQueryWrapper<PjCorpsAttn>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.eq(PjCorpsAttn::getUserId, user.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.eq(PjCorpsAttn::getTel, corpsDesc.getTel()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.eq(PjCorpsAttn::getIsDeleted, 0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					throw new RuntimeException("手机号已存在,提交失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn.setUserId(user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsAttn> corpsAttnList = corpsAttnService.list(new LambdaQueryWrapper<PjCorpsAttn>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTel, corpsDesc.getTel()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getIsDeleted, 0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!corpsAttnList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				PjCorpsDesc pjCorpsDesc1 = baseMapper.selectById(corpsAttnList.get(0).getPid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (pjCorpsDesc1 != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					throw new RuntimeException("该手机号:" + corpsDesc.getTel() + "已经在客户:" + pjCorpsDesc1.getCname() + "注册,请修改客户名称"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					throw new RuntimeException("该手机号未查到客户信息"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setCname(corpsDescVO.getAttn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setTel(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setPid(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setSalesCompanyId(deptId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttn.setSalesCompanyName(deptName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAttnService.save(corpsAttn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//保存客户地址信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsAddr corpsAddr = new PjCorpsAddr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setContacts(corpsDescVO.getAttn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setTel(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setBelongtoarea(corpsDescVO.getAddr()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setDetailedAddress(corpsDescVO.getDetails()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setPid(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddr.setDefaultAddres("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddrService.save(corpsAddr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//保存客户与类别对应关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			this.saveOrUpdateTypeDesc(corpsDescVO, userId, pId, date, tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Long> ids = pjCorpsDesc.stream().map(PjCorpsDesc::getId).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!pjCorpsDesc.isEmpty() && !ids.contains(corpsDesc.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("客户" + corpsDesc.getCname() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Long> idList = corpsDescTel.stream().map(PjCorpsDesc::getId).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (!corpsDescTel.isEmpty() && !idList.contains(corpsDesc.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("客户" + corpsDesc.getTel() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.setUpdateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			baseMapper.updateById(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsAttn> corpsAttnList = corpsAttnService.list(new LambdaQueryWrapper<PjCorpsAttn>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTel, corpsDesc.getTel())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsAttn corpsAttn = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getPid, corpsDesc.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTel, corpsDesc.getTel())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(corpsAttn)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<Long> idLists = corpsAttnList.stream().map(PjCorpsAttn::getId).distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (!corpsAttnList.isEmpty() && !idLists.contains(corpsAttn.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					throw new RuntimeException("客户" + corpsDesc.getTel() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (ObjectUtils.isNotNull(user)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setUserId(user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn.setCname(corpsDescVO.getAttn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn.setTel(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn.setSalesCompanyId(deptId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn.setSalesCompanyName(deptName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttnService.updateById(corpsAttn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (!corpsAttnList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					throw new RuntimeException("客户" + corpsDesc.getTel() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				//保存客户联系人信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				PjCorpsAttn corpsAttn1 = new PjCorpsAttn(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (ObjectUtils.isNotNull(user)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn1.setUserId(user.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setCname(corpsDescVO.getAttn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setTel(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setPid(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setSalesCompanyId(deptId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn1.setSalesCompanyName(deptName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttnService.save(corpsAttn1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsAddr corpsAddr = corpsAddrService.getOne(new LambdaQueryWrapper<PjCorpsAddr>().eq(PjCorpsAddr::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAddr::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAddr::getPid, corpsDesc.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAddr::getTel, corpsDesc.getTel())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(corpsAddr)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr.setContacts(corpsDescVO.getAttn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr.setTel(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr.setBelongtoarea(corpsDescVO.getAddr()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr.setDetailedAddress(corpsDescVO.getDetails()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr.setSalesCompanyId(deptId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr.setSalesCompanyName(deptName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddrService.updateById(corpsAddr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				//保存客户地址信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				PjCorpsAddr corpsAddr1 = new PjCorpsAddr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setContacts(corpsDescVO.getAttn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setTel(corpsDesc.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setBelongtoarea(corpsDescVO.getAddr()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setDetailedAddress(corpsDescVO.getDetails()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setPid(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setTenantId(AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setCreateUser(AuthUtil.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setSalesCompanyId(deptId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setSalesCompanyName(deptName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddr1.setDefaultAddres("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAddrService.save(corpsAddr1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//保存客户与类别对应关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		this.saveOrUpdateTypeDesc(corpsDescVO, userId, corpsDesc.getId(), date, AuthUtil.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return R.data(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public R appDetailsV1(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		CorpsDescVO corpsDescVO = new CorpsDescVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PjCorpsDesc corpsDesc = baseMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		BeanUtil.copyProperties(corpsDesc, corpsDescVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (ObjectUtils.isNotNull(corpsDesc)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsAddr corpsAddr = corpsAddrService.getOne(new LambdaQueryWrapper<PjCorpsAddr>().eq(PjCorpsAddr::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAddr::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAddr::getPid, corpsDesc.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAddr::getDefaultAddres, "1")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(corpsAddr)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setAddr(corpsAddr.getBelongtoarea()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setDetails(corpsAddr.getDetailedAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsAttn pjCorpsAttn = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getPid, corpsDesc.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTel, corpsDesc.getTel())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(pjCorpsAttn)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setAttn(pjCorpsAttn.getCname()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDesc.setTel(pjCorpsAttn.getTel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsAttn> attnList = corpsAttnService.list(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getPid, corpsDesc.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDescVO.setNumber(new BigDecimal(attnList.size())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//获取客户类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<String> longs = corpsTypeDescService.selectTypeId(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDescVO.setCorpsTypeId(String.join(",", longs)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			StringBuilder corpsTypeName = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (ObjectUtils.isNotNull(longs)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (String item : longs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					String name = corpsTypeService.getById(Long.parseLong(item)) == null ? "" : corpsTypeService.getById(Long.parseLong(item)).getCname(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsTypeName.append(name).append(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				String corpsName = corpsTypeName.substring(0, corpsTypeName.length() - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setCorpsTypeName(corpsName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsDescVO.setCorpsTypeName(""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return R.data(corpsDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 保存客户联系人信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 客户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param userId    登录人id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param pId       客户详情表id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param tenantId  租户id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param date      创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public R saveOrUpdateAttn(CorpsDescVO corpsDesc, Long userId, Long pId, String tenantId, Date date) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (CollectionUtils.isNotEmpty(corpsDesc.getCorpsAttnList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			String tel = corpsDesc.getCorpsAttnList().stream().map(PjCorpsAttn::getTel).filter(Objects::nonNull) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.distinct().collect(Collectors.joining(",")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<PjCorpsAttn> pjCorpsAttnList = corpsAttnService.list(new LambdaQueryWrapper<PjCorpsAttn>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getIsDeleted, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				.apply("find_in_set(tel,'" + tel + "')")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (PjCorpsAttn corpsAttn : corpsDesc.getCorpsAttnList()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsAttn.setPid(pId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<PjCorpsAttn> pjCorpsAttns = pjCorpsAttnList.stream().filter(e -> e.getTel().equals(corpsAttn.getTel())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					.collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (corpsAttn.getId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (!pjCorpsAttns.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						throw new RuntimeException("手机号:" + corpsAttn.getTel() + "已存在,请勿重复添加"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttnService.save(corpsAttn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					List<Long> ids = pjCorpsAttns.stream().map(PjCorpsAttn::getId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (!pjCorpsAttns.isEmpty() && !ids.contains(corpsAttn.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						throw new RuntimeException("手机号" + corpsAttn.getTel() + "已存在,请勿重复添加!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setUpdateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttn.setUpdateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					corpsAttnService.updateById(corpsAttn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return R.success("success"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 保存客户文件信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 客户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param userId    登录人id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param pId       客户详情表id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param tenantId  租户id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param date      创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public void saveOrUpdateFiles(CorpsDescVO corpsDesc, Long userId, Long pId, String tenantId, Date date) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (CollectionUtils.isNotEmpty(corpsDesc.getCorpsFilesList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.getCorpsFilesList().forEach(files -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				files.setPid(pId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				files.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (files.getId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					files.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					files.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					files.setUpdateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					files.setUpdateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsFilesService.saveOrUpdateBatch(corpsDesc.getCorpsFilesList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 保存客户地址信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 客户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param userId    登录人id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param pId       客户详情表id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param tenantId  租户id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param date      创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public void saveOrUpdateAddr(CorpsDescVO corpsDesc, Long userId, Long pId, String tenantId, Date date) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (CollectionUtils.isNotEmpty(corpsDesc.getCorpsAddrList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			long count = corpsDesc.getCorpsAddrList().stream().filter(e -> "1".equals(e.getDefaultAddres())).count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (count != 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				throw new RuntimeException("默认地址唯一"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsDesc.getCorpsAddrList().forEach(addr -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				addr.setPid(pId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				addr.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (addr.getId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					addr.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					addr.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					addr.setUpdateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					addr.setUpdateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsAddrService.saveOrUpdateBatch(corpsDesc.getCorpsAddrList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 保护客户与类别对应信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param corpsDesc 客户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param userId    登录人id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param pId       客户详情表id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @param date      创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public void saveOrUpdateTypeDesc(CorpsDescVO corpsDesc, Long userId, Long pId, Date date, String tenantId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (StringUtils.isBlank(corpsDesc.getCorpsTypeId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<String> list = Arrays.asList(corpsDesc.getCorpsTypeId().split(",")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (!list.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		corpsTypeDescService.remove(new QueryWrapper<PjCorpsTypeDesc>().eq("corp_id", corpsDesc.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsTypeDesc> typeDescList = corpsTypeDescService.list(new QueryWrapper<PjCorpsTypeDesc>().eq("corp_id", pId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			.in("corp_type_id", list)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<PjCorpsTypeDesc> typeDescListNew = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		list.forEach(item -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (typeDescList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			PjCorpsTypeDesc typeDesc = typeDescList.stream().filter(e -> item.equals(e.getCorpTypeId() + "")).findFirst().orElse(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if (typeDesc != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				typeDesc.setCorpTypeId(Long.valueOf(item)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				typeDesc.setCorpId(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				typeDesc.setUpdateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				typeDesc.setUpdateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				typeDescListNew.add(typeDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				PjCorpsTypeDesc corpsTypeDesc = new PjCorpsTypeDesc(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeDesc.setCorpId(corpsDesc.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeDesc.setCorpTypeId(Long.valueOf(item)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeDesc.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeDesc.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				corpsTypeDesc.setTenantId(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				typeDescListNew.add(corpsTypeDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (!typeDescListNew.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			corpsTypeDescService.saveOrUpdateBatch(typeDescListNew); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |