|
@@ -3,12 +3,16 @@ package com.etotem.cfc.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.OctopusEffectKeyPerson;
|
|
import com.etotem.cfc.entity.OctopusEffectKeyPerson;
|
|
|
import com.etotem.cfc.entity.OctopusEffectRecord;
|
|
import com.etotem.cfc.entity.OctopusEffectRecord;
|
|
|
import com.etotem.cfc.entity.OctopusKeyPerson;
|
|
import com.etotem.cfc.entity.OctopusKeyPerson;
|
|
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
|
|
+import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.OctopusEffectKeyPersonMapper;
|
|
import com.etotem.cfc.mapper.OctopusEffectKeyPersonMapper;
|
|
|
import com.etotem.cfc.mapper.OctopusEffectRecordMapper;
|
|
import com.etotem.cfc.mapper.OctopusEffectRecordMapper;
|
|
|
import com.etotem.cfc.mapper.OctopusKeyPersonMapper;
|
|
import com.etotem.cfc.mapper.OctopusKeyPersonMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -25,6 +29,12 @@ public class KeyPersonService {
|
|
|
private OctopusKeyPersonMapper keyPersonMapper;
|
|
private OctopusKeyPersonMapper keyPersonMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
private OctopusEffectKeyPersonMapper ekpMapper;
|
|
private OctopusEffectKeyPersonMapper ekpMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private EnergyService energyService;
|
|
|
|
|
|
|
|
// ========== 1. 盘点项目 ==========
|
|
// ========== 1. 盘点项目 ==========
|
|
|
|
|
|
|
@@ -174,6 +184,21 @@ public class KeyPersonService {
|
|
|
ekpMapper.insert(rel);
|
|
ekpMapper.insert(rel);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 行维度能量奖励:每填一条感恩记录 +1,逢5条再额外+1
|
|
|
|
|
+ try {
|
|
|
|
|
+ Long newCount = effectRecordMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<OctopusEffectRecord>().eq(OctopusEffectRecord::getUserId, userId));
|
|
|
|
|
+ int bonus = 1;
|
|
|
|
|
+ if (newCount != null && newCount % 5 == 0) bonus++;
|
|
|
|
|
+ // 查找当前用户的 family_member 记录作为 memberId
|
|
|
|
|
+ List<FamilyMember> members = familyMemberMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<FamilyMember>().eq(FamilyMember::getUserId, userId).last("LIMIT 1"));
|
|
|
|
|
+ if (!members.isEmpty()) {
|
|
|
|
|
+ energyService.awardEnergyByCode(members.get(0).getId(), "action", bonus, "填写感恩记录奖励");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("发放感恩记录能量奖励失败 userId={}: {}", userId, e.getMessage());
|
|
|
|
|
+ }
|
|
|
return Result.success(r);
|
|
return Result.success(r);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -198,6 +223,13 @@ public class KeyPersonService {
|
|
|
.orderByDesc(OctopusKeyPerson::getCreatedAt)
|
|
.orderByDesc(OctopusKeyPerson::getCreatedAt)
|
|
|
);
|
|
);
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
+ Map<Long, String> refNameMap = new HashMap<>();
|
|
|
|
|
+ for (OctopusKeyPerson kp : kps) {
|
|
|
|
|
+ if (kp.getReferrerId() != null) {
|
|
|
|
|
+ OctopusKeyPerson ref = keyPersonMapper.selectById(kp.getReferrerId());
|
|
|
|
|
+ if (ref != null) refNameMap.put(kp.getReferrerId(), ref.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
for (OctopusKeyPerson kp : kps) {
|
|
for (OctopusKeyPerson kp : kps) {
|
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
|
m.put("id", kp.getId());
|
|
m.put("id", kp.getId());
|
|
@@ -206,18 +238,73 @@ public class KeyPersonService {
|
|
|
m.put("department", kp.getDepartment());
|
|
m.put("department", kp.getDepartment());
|
|
|
m.put("title", kp.getTitle());
|
|
m.put("title", kp.getTitle());
|
|
|
m.put("firstMeetScene", kp.getFirstMeetScene());
|
|
m.put("firstMeetScene", kp.getFirstMeetScene());
|
|
|
|
|
+ m.put("firstMeetTime", kp.getFirstMeetTime() != null ? kp.getFirstMeetTime().toString() : "");
|
|
|
m.put("knowWay", kp.getKnowWay());
|
|
m.put("knowWay", kp.getKnowWay());
|
|
|
m.put("contactInfo", kp.getContactInfo());
|
|
m.put("contactInfo", kp.getContactInfo());
|
|
|
|
|
+ m.put("referrerId", kp.getReferrerId());
|
|
|
|
|
+ m.put("referrerName", kp.getReferrerId() != null ? refNameMap.get(kp.getReferrerId()) : "");
|
|
|
|
|
+ m.put("systemUserId", kp.getSystemUserId());
|
|
|
|
|
+ m.put("matched", kp.getSystemUserId() != null);
|
|
|
m.put("createdAt", kp.getCreatedAt() != null ? kp.getCreatedAt().toString() : "");
|
|
m.put("createdAt", kp.getCreatedAt() != null ? kp.getCreatedAt().toString() : "");
|
|
|
list.add(m);
|
|
list.add(m);
|
|
|
}
|
|
}
|
|
|
return Result.success(list);
|
|
return Result.success(list);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Result<OctopusKeyPerson> addKeyPerson(Long userId, String name, String organization,
|
|
|
|
|
|
|
+ /** 通过手机号匹配系统内用户(用于关键人绑定真实用户) */
|
|
|
|
|
+ public Result<Map<String, Object>> matchKeyPersonByPhone(Long userId, String phone) {
|
|
|
|
|
+ if (phone == null || phone.trim().isEmpty()) {
|
|
|
|
|
+ return Result.error("手机号不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ phone = phone.trim();
|
|
|
|
|
+ // 1. 查 users 表
|
|
|
|
|
+ List<User> users = userMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<User>().eq(User::getPhone, phone).last("LIMIT 1")
|
|
|
|
|
+ );
|
|
|
|
|
+ User matchedUser = (users != null && !users.isEmpty()) ? users.get(0) : null;
|
|
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
|
|
+ if (matchedUser != null) {
|
|
|
|
|
+ data.put("userId", matchedUser.getId());
|
|
|
|
|
+ data.put("nickname", matchedUser.getNickname());
|
|
|
|
|
+ data.put("realName", matchedUser.getRealName());
|
|
|
|
|
+ data.put("avatar", matchedUser.getAvatar());
|
|
|
|
|
+ data.put("familyId", matchedUser.getFamilyId());
|
|
|
|
|
+ data.put("phone", matchedUser.getPhone());
|
|
|
|
|
+ // 尝试通过家庭成员表找到 memberId(能力图/能量发放需要)
|
|
|
|
|
+ if (matchedUser.getFamilyId() != null) {
|
|
|
|
|
+ List<FamilyMember> members = familyMemberMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<FamilyMember>()
|
|
|
|
|
+ .eq(FamilyMember::getFamilyId, matchedUser.getFamilyId())
|
|
|
|
|
+ .eq(FamilyMember::getUserId, matchedUser.getId())
|
|
|
|
|
+ .last("LIMIT 1")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (members != null && !members.isEmpty()) {
|
|
|
|
|
+ data.put("memberId", members.get(0).getId());
|
|
|
|
|
+ data.put("memberName", members.get(0).getNickname());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data.put("systemUserId", matchedUser.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ data.put("matched", matchedUser != null);
|
|
|
|
|
+ return Result.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 将关键人与系统用户绑定(持久化匹配状态) */
|
|
|
|
|
+ public Result<OctopusKeyPerson> bindSystemUser(Long userId, Long keyPersonId, Long systemUserId) {
|
|
|
|
|
+ OctopusKeyPerson kp = keyPersonMapper.selectById(keyPersonId);
|
|
|
|
|
+ if (kp == null || !kp.getUserId().equals(userId)) {
|
|
|
|
|
+ return Result.error("关键人不存在或无权操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ kp.setSystemUserId(systemUserId);
|
|
|
|
|
+ keyPersonMapper.updateById(kp);
|
|
|
|
|
+ return Result.success(kp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+public Result<OctopusKeyPerson> addKeyPerson(Long userId, String name, String organization,
|
|
|
String department, String title,
|
|
String department, String title,
|
|
|
- String firstMeetScene, String knowWay,
|
|
|
|
|
- String contactInfo) {
|
|
|
|
|
|
|
+ String firstMeetScene, String firstMeetTime,
|
|
|
|
|
+ String knowWay, String contactInfo,
|
|
|
|
|
+ Long referrerId) {
|
|
|
if (name == null || name.trim().isEmpty()) {
|
|
if (name == null || name.trim().isEmpty()) {
|
|
|
return Result.error("关键人姓名不能为空");
|
|
return Result.error("关键人姓名不能为空");
|
|
|
}
|
|
}
|
|
@@ -228,8 +315,10 @@ public class KeyPersonService {
|
|
|
kp.setDepartment(department != null ? department.trim() : null);
|
|
kp.setDepartment(department != null ? department.trim() : null);
|
|
|
kp.setTitle(title != null ? title.trim() : null);
|
|
kp.setTitle(title != null ? title.trim() : null);
|
|
|
kp.setFirstMeetScene(firstMeetScene != null ? firstMeetScene.trim() : null);
|
|
kp.setFirstMeetScene(firstMeetScene != null ? firstMeetScene.trim() : null);
|
|
|
|
|
+ kp.setFirstMeetTime(firstMeetTime != null ? java.sql.Timestamp.valueOf(firstMeetTime) : null);
|
|
|
kp.setKnowWay(knowWay != null ? knowWay.trim() : null);
|
|
kp.setKnowWay(knowWay != null ? knowWay.trim() : null);
|
|
|
kp.setContactInfo(contactInfo != null ? contactInfo.trim() : null);
|
|
kp.setContactInfo(contactInfo != null ? contactInfo.trim() : null);
|
|
|
|
|
+ kp.setReferrerId(referrerId);
|
|
|
kp.setCreatedAt(new Date());
|
|
kp.setCreatedAt(new Date());
|
|
|
keyPersonMapper.insert(kp);
|
|
keyPersonMapper.insert(kp);
|
|
|
return Result.success(kp);
|
|
return Result.success(kp);
|
|
@@ -292,6 +381,8 @@ public class KeyPersonService {
|
|
|
m.put("contactInfo", kp.getContactInfo());
|
|
m.put("contactInfo", kp.getContactInfo());
|
|
|
m.put("role", roleMap.get(kpId));
|
|
m.put("role", roleMap.get(kpId));
|
|
|
m.put("roleName", roleName(roleMap.get(kpId)));
|
|
m.put("roleName", roleName(roleMap.get(kpId)));
|
|
|
|
|
+ m.put("systemUserId", kp.getSystemUserId());
|
|
|
|
|
+ m.put("matched", kp.getSystemUserId() != null);
|
|
|
m.put("createdAt", kp.getCreatedAt() != null ? kp.getCreatedAt().toString() : "");
|
|
m.put("createdAt", kp.getCreatedAt() != null ? kp.getCreatedAt().toString() : "");
|
|
|
list.add(m);
|
|
list.add(m);
|
|
|
}
|
|
}
|