|
|
@@ -77,7 +77,7 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
CustomerContactInfo info = contactInfoMapper.selectOne(new LambdaQueryWrapper<CustomerContactInfo>()
|
|
|
.eq(CustomerContactInfo::getContactId, id));
|
|
|
if (info != null) {
|
|
|
- // 将扩展信息字段合并到 VO 中
|
|
|
+ // 利用 MapstructUtils 自动映射所有扩展字段 (包括职位、年龄等)
|
|
|
MapstructUtils.convert(info, vo);
|
|
|
}
|
|
|
}
|
|
|
@@ -125,6 +125,8 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ // 填充扩展信息
|
|
|
+ fillContactExtInfo(records);
|
|
|
}
|
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
|
@@ -138,7 +140,9 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
@Override
|
|
|
public List<CustomerContactVo> queryList(CustomerContactBo bo) {
|
|
|
LambdaQueryWrapper<CustomerContact> lqw = buildQueryWrapper(bo);
|
|
|
- return baseMapper.selectVoList(lqw);
|
|
|
+ List<CustomerContactVo> list = baseMapper.selectVoList(lqw);
|
|
|
+ fillContactExtInfo(list);
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
private LambdaQueryWrapper<CustomerContact> buildQueryWrapper(CustomerContactBo bo) {
|
|
|
@@ -163,6 +167,18 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getDeptName()), CustomerContact::getDeptName, bo.getDeptName());
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getRoleName()), CustomerContact::getRoleName, bo.getRoleName());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getPlatformCode()), CustomerContact::getPlatformCode, bo.getPlatformCode());
|
|
|
+ // 增加联系人类型查询
|
|
|
+ if (StringUtils.isNotBlank(bo.getType())) {
|
|
|
+ List<CustomerContactInfo> infoList = contactInfoMapper.selectList(new LambdaQueryWrapper<CustomerContactInfo>()
|
|
|
+ .select(CustomerContactInfo::getContactId)
|
|
|
+ .eq(CustomerContactInfo::getType, bo.getType()));
|
|
|
+ if (ObjectUtil.isNotEmpty(infoList)) {
|
|
|
+ List<Long> contactIds = infoList.stream().map(CustomerContactInfo::getContactId).collect(Collectors.toList());
|
|
|
+ lqw.in(CustomerContact::getId, contactIds);
|
|
|
+ } else {
|
|
|
+ lqw.eq(CustomerContact::getId, 0L);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(bo.getCustomerName())) {
|
|
|
CustomerInfoVo customerInfoVo = customerInfoMapper.selectVoOne(new LambdaQueryWrapper<CustomerInfo>().eq(CustomerInfo::getCustomerName, bo.getCustomerName()));
|
|
|
@@ -279,6 +295,8 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
// 保存扩展信息
|
|
|
CustomerContactInfo info = MapstructUtils.convert(bo, CustomerContactInfo.class);
|
|
|
info.setContactId(add.getId());
|
|
|
+ // 按照要求,不插入扩展表的 platform_code
|
|
|
+ info.setPlatformCode(null);
|
|
|
contactInfoMapper.insert(info);
|
|
|
} catch (Exception e) {
|
|
|
log.warn("保存联系人扩展信息失败,可能表 customer_contact_info 尚未创建: {}", e.getMessage());
|
|
|
@@ -319,6 +337,8 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
// 更新或插入扩展信息
|
|
|
CustomerContactInfo info = MapstructUtils.convert(bo, CustomerContactInfo.class);
|
|
|
info.setContactId(bo.getId());
|
|
|
+ // 按照要求,不插入扩展表的 platform_code
|
|
|
+ info.setPlatformCode(null);
|
|
|
CustomerContactInfo exist = contactInfoMapper.selectOne(new LambdaQueryWrapper<CustomerContactInfo>()
|
|
|
.eq(CustomerContactInfo::getContactId, bo.getId()));
|
|
|
if (exist != null) {
|
|
|
@@ -393,13 +413,6 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
* @param isValid 是否进行有效性校验
|
|
|
* @return 是否删除成功
|
|
|
*/
|
|
|
- /**
|
|
|
- * 批量删除联系人
|
|
|
- *
|
|
|
- * @param ids ID 集合
|
|
|
- * @param isValid 是否需要业务校验
|
|
|
- * @return 是否删除成功
|
|
|
- */
|
|
|
@Transactional(rollbackFor = Exception.class) // 1. 开启事务
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
if (ids == null || ids.isEmpty()) {
|
|
|
@@ -445,4 +458,61 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
|
|
|
|
|
|
return rows > 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或编辑扩展联系人信息 (独立方法)
|
|
|
+ *
|
|
|
+ * @param bo 业务对象
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean saveOrUpdateContactExtInfo(CustomerContactBo bo) {
|
|
|
+ if (bo == null || bo.getId() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 1. 将 BO 转换为扩展信息实体
|
|
|
+ CustomerContactInfo info = MapstructUtils.convert(bo, CustomerContactInfo.class);
|
|
|
+ info.setContactId(bo.getId());
|
|
|
+
|
|
|
+ // 2. 按照要求,不插入 platform_code 字段
|
|
|
+ info.setPlatformCode(null);
|
|
|
+
|
|
|
+ // 3. 根据联系人 ID 查询是否已存在扩展记录
|
|
|
+ CustomerContactInfo exist = contactInfoMapper.selectOne(new LambdaQueryWrapper<CustomerContactInfo>()
|
|
|
+ .eq(CustomerContactInfo::getContactId, bo.getId()));
|
|
|
+
|
|
|
+ if (exist != null) {
|
|
|
+ // 已存在则更新
|
|
|
+ info.setId(exist.getId());
|
|
|
+ return contactInfoMapper.updateById(info) > 0;
|
|
|
+ } else {
|
|
|
+ // 不存在则新增
|
|
|
+ return contactInfoMapper.insert(info) > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量填充联系人扩展信息
|
|
|
+ *
|
|
|
+ * @param voList 联系人视图对象列表
|
|
|
+ */
|
|
|
+ public void fillContactExtInfo(List<CustomerContactVo> voList) {
|
|
|
+ if (ObjectUtil.isEmpty(voList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> contactIds = voList.stream().map(CustomerContactVo::getId).collect(Collectors.toList());
|
|
|
+ List<CustomerContactInfo> infos = contactInfoMapper.selectList(new LambdaQueryWrapper<CustomerContactInfo>()
|
|
|
+ .in(CustomerContactInfo::getContactId, contactIds));
|
|
|
+ if (ObjectUtil.isEmpty(infos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, CustomerContactInfo> infoMap = infos.stream().collect(Collectors.toMap(CustomerContactInfo::getContactId, i -> i, (k1, k2) -> k1));
|
|
|
+ voList.forEach(item -> {
|
|
|
+ CustomerContactInfo info = infoMap.get(item.getId());
|
|
|
+ if (info != null) {
|
|
|
+ // 使用 MapstructUtils 自动映射,避免手动赋值遗漏字段
|
|
|
+ MapstructUtils.convert(info, item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|