mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
feat: UserPersonaAssignment service(upsert/manual/reset)
Task 3: 读写映射 Service - UserPersonaAssignmentService 接口(getByUserId/upsertAuto/setManual/resetAuto) - UserPersonaAssignmentServiceImpl(LambdaQueryWrapper + saveOrUpdate) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3df8cd7b8d
commit
2fb2ddef4c
2 changed files with 87 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
||||||
|
package xiaozhi.modules.agent.service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import xiaozhi.modules.agent.entity.UserPersonaAssignmentEntity;
|
||||||
|
|
||||||
|
public interface UserPersonaAssignmentService extends IService<UserPersonaAssignmentEntity> {
|
||||||
|
|
||||||
|
UserPersonaAssignmentEntity getByUserId(Long userId);
|
||||||
|
|
||||||
|
/** 自动匹配写入(manual=0) */
|
||||||
|
void upsertAuto(Long userId, String agentId, BigDecimal score, String reason);
|
||||||
|
|
||||||
|
/** 家长手动切换(manual=1,立即生效) */
|
||||||
|
void setManual(Long userId, String agentId);
|
||||||
|
|
||||||
|
/** 恢复自动匹配(manual=0) */
|
||||||
|
void resetAuto(Long userId);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package xiaozhi.modules.agent.service.impl;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
import xiaozhi.modules.agent.dao.UserPersonaAssignmentDao;
|
||||||
|
import xiaozhi.modules.agent.entity.UserPersonaAssignmentEntity;
|
||||||
|
import xiaozhi.modules.agent.service.UserPersonaAssignmentService;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserPersonaAssignmentServiceImpl
|
||||||
|
extends ServiceImpl<UserPersonaAssignmentDao, UserPersonaAssignmentEntity>
|
||||||
|
implements UserPersonaAssignmentService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserPersonaAssignmentEntity getByUserId(Long userId) {
|
||||||
|
if (userId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.getOne(new LambdaQueryWrapper<UserPersonaAssignmentEntity>()
|
||||||
|
.eq(UserPersonaAssignmentEntity::getUserId, userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void upsertAuto(Long userId, String agentId, BigDecimal score, String reason) {
|
||||||
|
UserPersonaAssignmentEntity e = getByUserId(userId);
|
||||||
|
if (e == null) {
|
||||||
|
e = new UserPersonaAssignmentEntity();
|
||||||
|
e.setUserId(userId);
|
||||||
|
}
|
||||||
|
e.setAgentId(agentId);
|
||||||
|
e.setScore(score);
|
||||||
|
e.setReason(reason);
|
||||||
|
e.setManual(0);
|
||||||
|
e.setMatchedAt(new Date());
|
||||||
|
this.saveOrUpdate(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setManual(Long userId, String agentId) {
|
||||||
|
UserPersonaAssignmentEntity e = getByUserId(userId);
|
||||||
|
if (e == null) {
|
||||||
|
e = new UserPersonaAssignmentEntity();
|
||||||
|
e.setUserId(userId);
|
||||||
|
}
|
||||||
|
e.setAgentId(agentId);
|
||||||
|
e.setManual(1);
|
||||||
|
e.setReason("manual");
|
||||||
|
e.setMatchedAt(new Date());
|
||||||
|
this.saveOrUpdate(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetAuto(Long userId) {
|
||||||
|
UserPersonaAssignmentEntity e = getByUserId(userId);
|
||||||
|
if (e != null) {
|
||||||
|
e.setManual(0);
|
||||||
|
this.updateById(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue