|
@@ -13,6 +13,10 @@ import org.dromara.customer.domain.Salesleads;
|
|
|
import org.dromara.customer.domain.bo.SalesleadsBo;
|
|
import org.dromara.customer.domain.bo.SalesleadsBo;
|
|
|
import org.dromara.customer.domain.bo.TeamMemberBo;
|
|
import org.dromara.customer.domain.bo.TeamMemberBo;
|
|
|
import org.dromara.customer.domain.vo.SalesleadsVo;
|
|
import org.dromara.customer.domain.vo.SalesleadsVo;
|
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
+import org.dromara.system.api.RemoteComStaffService;
|
|
|
|
|
+import org.dromara.system.api.domain.vo.RemoteComStaffVo;
|
|
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.customer.mapper.SalesleadsMapper;
|
|
import org.dromara.customer.mapper.SalesleadsMapper;
|
|
|
import org.dromara.customer.service.IOperationLogService;
|
|
import org.dromara.customer.service.IOperationLogService;
|
|
|
import org.dromara.customer.service.ISalesleadsService;
|
|
import org.dromara.customer.service.ISalesleadsService;
|
|
@@ -23,6 +27,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 销售线索/项目商机 Service 业务层处理
|
|
* 销售线索/项目商机 Service 业务层处理
|
|
@@ -40,6 +46,9 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
private final ITeamMemberService teamMemberService;
|
|
private final ITeamMemberService teamMemberService;
|
|
|
private final IOperationLogService operationLogService;
|
|
private final IOperationLogService operationLogService;
|
|
|
|
|
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private RemoteComStaffService remoteComStaffService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询
|
|
* 查询
|
|
|
*/
|
|
*/
|
|
@@ -47,6 +56,7 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
public SalesleadsVo queryById(Long id) {
|
|
public SalesleadsVo queryById(Long id) {
|
|
|
SalesleadsBo bo = new SalesleadsBo();
|
|
SalesleadsBo bo = new SalesleadsBo();
|
|
|
bo.setId(id);
|
|
bo.setId(id);
|
|
|
|
|
+ applyUserPermission(bo);
|
|
|
List<SalesleadsVo> list = baseMapper.selectSalesleadsList(bo);
|
|
List<SalesleadsVo> list = baseMapper.selectSalesleadsList(bo);
|
|
|
return list.isEmpty() ? null : list.get(0);
|
|
return list.isEmpty() ? null : list.get(0);
|
|
|
}
|
|
}
|
|
@@ -56,6 +66,7 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public TableDataInfo<SalesleadsVo> queryPageList(SalesleadsBo bo, PageQuery pageQuery) {
|
|
public TableDataInfo<SalesleadsVo> queryPageList(SalesleadsBo bo, PageQuery pageQuery) {
|
|
|
|
|
+ applyUserPermission(bo);
|
|
|
IPage<SalesleadsVo> result = baseMapper.selectSalesleadsList(pageQuery.build(), bo);
|
|
IPage<SalesleadsVo> result = baseMapper.selectSalesleadsList(pageQuery.build(), bo);
|
|
|
return TableDataInfo.build(result);
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
}
|
|
@@ -65,6 +76,7 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public List<SalesleadsVo> queryList(SalesleadsBo bo) {
|
|
public List<SalesleadsVo> queryList(SalesleadsBo bo) {
|
|
|
|
|
+ applyUserPermission(bo);
|
|
|
return baseMapper.selectSalesleadsList(bo);
|
|
return baseMapper.selectSalesleadsList(bo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -91,6 +103,10 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
// 新增成功后,将负责人同步到团队成员表
|
|
// 新增成功后,将负责人同步到团队成员表
|
|
|
syncLeaderToTeamMember(add.getId(), add.getLeader(), add.getLeaderName());
|
|
syncLeaderToTeamMember(add.getId(), add.getLeader(), add.getLeaderName());
|
|
|
}
|
|
}
|
|
|
|
|
+ if (add.getId() != null && bo.getProductSupport() != null && !bo.getProductSupport().isEmpty()) {
|
|
|
|
|
+ // 新增成功后,将产品支持同步到团队成员表
|
|
|
|
|
+ syncProductSupportToTeamMember(add.getId(), bo.getProductSupport(), bo.getProductSupportName());
|
|
|
|
|
+ }
|
|
|
// 记录日志
|
|
// 记录日志
|
|
|
operationLogService.recordLog(CustomerConstants.DATA_TYPE_LEADS, String.valueOf(add.getId()), CustomerConstants.ACTION_TYPE_INSERT, null, "创建了销售线索", add.getProjectName());
|
|
operationLogService.recordLog(CustomerConstants.DATA_TYPE_LEADS, String.valueOf(add.getId()), CustomerConstants.ACTION_TYPE_INSERT, null, "创建了销售线索", add.getProjectName());
|
|
|
}
|
|
}
|
|
@@ -131,6 +147,22 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
syncLeaderToTeamMember(bo.getId(), bo.getLeader(), bo.getLeaderName());
|
|
syncLeaderToTeamMember(bo.getId(), bo.getLeader(), bo.getLeaderName());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ if (bo.getProductSupport() != null && !bo.getProductSupport().isEmpty()) {
|
|
|
|
|
+ if (oldData == null || !ObjectUtils.equals(oldData.getProductSupport(), bo.getProductSupport())) {
|
|
|
|
|
+ // 如果旧产品支持存在,则从团队成员中移除
|
|
|
|
|
+ if (oldData != null && oldData.getProductSupport() != null && !oldData.getProductSupport().isEmpty()) {
|
|
|
|
|
+ removeProductSupportFromTeamMember(bo.getId(), oldData.getProductSupport());
|
|
|
|
|
+ }
|
|
|
|
|
+ syncProductSupportToTeamMember(bo.getId(), bo.getProductSupport(), bo.getProductSupportName());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果新产品支持为空,但旧产品支持存在,则从团队中移除
|
|
|
|
|
+ if (oldData != null && oldData.getProductSupport() != null && !oldData.getProductSupport().isEmpty()) {
|
|
|
|
|
+ removeProductSupportFromTeamMember(bo.getId(), oldData.getProductSupport());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return success;
|
|
return success;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -161,6 +193,7 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
update.setId(id);
|
|
update.setId(id);
|
|
|
update.setLeader(bo.getLeader());
|
|
update.setLeader(bo.getLeader());
|
|
|
update.setLeaderName(bo.getLeaderName());
|
|
update.setLeaderName(bo.getLeaderName());
|
|
|
|
|
+ update.setProductSupport(bo.getProductSupport());
|
|
|
update.setIzClue(0); // 认领后转为项目商机
|
|
update.setIzClue(0); // 认领后转为项目商机
|
|
|
update.setProjectType(CustomerConstants.PROJECT_TYPE_OPPORTUNITY);
|
|
update.setProjectType(CustomerConstants.PROJECT_TYPE_OPPORTUNITY);
|
|
|
update.setStatus("0"); // 转为商机后,状态设为跟进中
|
|
update.setStatus("0"); // 转为商机后,状态设为跟进中
|
|
@@ -179,6 +212,21 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
syncLeaderToTeamMember(id, bo.getLeader(), bo.getLeaderName());
|
|
syncLeaderToTeamMember(id, bo.getLeader(), bo.getLeaderName());
|
|
|
|
|
+
|
|
|
|
|
+ // 处理产品支持同步逻辑
|
|
|
|
|
+ if (bo.getProductSupport() != null && !bo.getProductSupport().isEmpty()) {
|
|
|
|
|
+ if (oldData == null || !ObjectUtils.equals(oldData.getProductSupport(), bo.getProductSupport())) {
|
|
|
|
|
+ if (oldData != null && oldData.getProductSupport() != null && !oldData.getProductSupport().isEmpty()) {
|
|
|
|
|
+ removeProductSupportFromTeamMember(id, oldData.getProductSupport());
|
|
|
|
|
+ }
|
|
|
|
|
+ syncProductSupportToTeamMember(id, bo.getProductSupport(), bo.getProductSupportName());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (oldData != null && oldData.getProductSupport() != null && !oldData.getProductSupport().isEmpty()) {
|
|
|
|
|
+ removeProductSupportFromTeamMember(id, oldData.getProductSupport());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 记录日志
|
|
// 记录日志
|
|
|
operationLogService.recordLog(CustomerConstants.DATA_TYPE_LEADS, String.valueOf(id), CustomerConstants.ACTION_TYPE_CLAIM, null, "认领了销售线索", bo.getLeaderName());
|
|
operationLogService.recordLog(CustomerConstants.DATA_TYPE_LEADS, String.valueOf(id), CustomerConstants.ACTION_TYPE_CLAIM, null, "认领了销售线索", bo.getLeaderName());
|
|
|
}
|
|
}
|
|
@@ -247,17 +295,105 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
*/
|
|
*/
|
|
|
private void syncLeaderToTeamMember(Long objectNo, Long leaderId, String leaderName) {
|
|
private void syncLeaderToTeamMember(Long objectNo, Long leaderId, String leaderName) {
|
|
|
if (leaderId == null) return;
|
|
if (leaderId == null) return;
|
|
|
|
|
+ String realName = leaderName;
|
|
|
|
|
+ if (realName == null || realName.isEmpty()) {
|
|
|
|
|
+ Map<Long, String> nameMap = remoteComStaffService.selectStaffNameByIds(Set.of(leaderId));
|
|
|
|
|
+ if (nameMap != null && nameMap.containsKey(leaderId)) {
|
|
|
|
|
+ realName = nameMap.get(leaderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
TeamMemberBo memberBo = new TeamMemberBo();
|
|
TeamMemberBo memberBo = new TeamMemberBo();
|
|
|
memberBo.setDataType(CustomerConstants.DATA_TYPE_LEADS);
|
|
memberBo.setDataType(CustomerConstants.DATA_TYPE_LEADS);
|
|
|
memberBo.setObjectNo(String.valueOf(objectNo));
|
|
memberBo.setObjectNo(String.valueOf(objectNo));
|
|
|
memberBo.setUserNo(leaderId);
|
|
memberBo.setUserNo(leaderId);
|
|
|
- memberBo.setRealName(leaderName);
|
|
|
|
|
|
|
+ memberBo.setRealName(realName);
|
|
|
memberBo.setRoleCode(CustomerConstants.TEAM_ROLE_LEADER); // 业务负责人的字典值
|
|
memberBo.setRoleCode(CustomerConstants.TEAM_ROLE_LEADER); // 业务负责人的字典值
|
|
|
memberBo.setIzManager(1);
|
|
memberBo.setIzManager(1);
|
|
|
memberBo.setUpdateAccredit(1);
|
|
memberBo.setUpdateAccredit(1);
|
|
|
teamMemberService.insertOrUpdateMember(memberBo);
|
|
teamMemberService.insertOrUpdateMember(memberBo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 安全转换 Long
|
|
|
|
|
+ */
|
|
|
|
|
+ private Long tryParseLong(String val) {
|
|
|
|
|
+ if (val == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Long.valueOf(val.trim());
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 从团队成员中安全移除产品支持
|
|
|
|
|
+ */
|
|
|
|
|
+ private void removeProductSupportFromTeamMember(Long objectNo, String productSupport) {
|
|
|
|
|
+ if (productSupport == null || productSupport.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] supportIdStrArray = productSupport.split(",");
|
|
|
|
|
+ for (String idStr : supportIdStrArray) {
|
|
|
|
|
+ Long id = tryParseLong(idStr);
|
|
|
|
|
+ if (id != null) {
|
|
|
|
|
+ teamMemberService.removeMember(CustomerConstants.DATA_TYPE_LEADS, String.valueOf(objectNo), id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 同步产品支持到团队成员表(适配逗号分隔的多值)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void syncProductSupportToTeamMember(Long objectNo, String productSupport, String supportName) {
|
|
|
|
|
+ if (productSupport == null || productSupport.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] supportIdStrArray = productSupport.split(",");
|
|
|
|
|
+ Set<Long> supportIds = new java.util.HashSet<>();
|
|
|
|
|
+ for (String idStr : supportIdStrArray) {
|
|
|
|
|
+ Long id = tryParseLong(idStr);
|
|
|
|
|
+ if (id != null) {
|
|
|
|
|
+ supportIds.add(id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (supportIds.isEmpty()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, String> nameMap = remoteComStaffService.selectStaffNameByIds(supportIds);
|
|
|
|
|
+ String[] supportNameArray = null;
|
|
|
|
|
+ if (supportName != null && !supportName.isEmpty()) {
|
|
|
|
|
+ supportNameArray = supportName.split(",");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+ for (String idStr : supportIdStrArray) {
|
|
|
|
|
+ Long id = tryParseLong(idStr);
|
|
|
|
|
+ if (id != null) {
|
|
|
|
|
+ String realName = nameMap != null ? nameMap.get(id) : null;
|
|
|
|
|
+ if (realName == null || realName.isEmpty()) {
|
|
|
|
|
+ if (supportNameArray != null && index < supportNameArray.length) {
|
|
|
|
|
+ realName = supportNameArray[index].trim();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ realName = supportName;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ TeamMemberBo memberBo = new TeamMemberBo();
|
|
|
|
|
+ memberBo.setDataType(CustomerConstants.DATA_TYPE_LEADS);
|
|
|
|
|
+ memberBo.setObjectNo(String.valueOf(objectNo));
|
|
|
|
|
+ memberBo.setUserNo(id);
|
|
|
|
|
+ memberBo.setRealName(realName);
|
|
|
|
|
+ memberBo.setRoleCode("3");
|
|
|
|
|
+ memberBo.setIzManager(0);
|
|
|
|
|
+ memberBo.setUpdateAccredit(0);
|
|
|
|
|
+ teamMemberService.insertOrUpdateMember(memberBo);
|
|
|
|
|
+ }
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取项目进度名称
|
|
* 获取项目进度名称
|
|
|
*/
|
|
*/
|
|
@@ -272,4 +408,25 @@ public class SalesleadsServiceImpl implements ISalesleadsService {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 应用用户权限:只允许查看自己是负责人或者产品支持的项目
|
|
|
|
|
+ */
|
|
|
|
|
+ private void applyUserPermission(SalesleadsBo bo) {
|
|
|
|
|
+ if (bo == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!LoginHelper.isSuperAdmin()) {
|
|
|
|
|
+ RemoteComStaffVo staffVo = remoteComStaffService.selectStaffByUserId(LoginHelper.getUserId());
|
|
|
|
|
+ if (bo.getParams() == null) {
|
|
|
|
|
+ bo.setParams(new java.util.HashMap<>());
|
|
|
|
|
+ }
|
|
|
|
|
+ bo.getParams().put("restrictToUser", true);
|
|
|
|
|
+ if (staffVo != null && staffVo.getStaffId() != null) {
|
|
|
|
|
+ bo.getParams().put("currentUserId", staffVo.getStaffId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ bo.getParams().put("currentUserId", -1L);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|