guohongjin
2024-05-01 1901fceb6ddaa56a57f3131191454554c3e77e68
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package cn.stylefeng.guns.modular.business.service.impl;
 
import cn.stylefeng.guns.modular.business.dto.MentalTestMyTestOrderDTO;
import cn.stylefeng.guns.modular.business.dto.MentalTestMyTestRecordTopicDTO;
import cn.stylefeng.guns.modular.business.dto.MentalTestMyTestTopicDTO;
import cn.stylefeng.guns.modular.business.dto.MentalTestRecordPageDTO;
import cn.stylefeng.guns.modular.business.entity.MentalTestRecord;
import cn.stylefeng.guns.modular.business.mapper.MentalTestRecordMapper;
import cn.stylefeng.guns.modular.business.service.IMentalTestRecordService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * <p>
 * 心理测试记录 服务实现类
 * </p>
 *
 * @author goupan
 * @since 2024-01-09
 */
@Service
public class MentalTestRecordServiceImpl extends ServiceImpl<MentalTestRecordMapper, MentalTestRecord> implements IMentalTestRecordService {
 
    @Override
    public List<MentalTestMyTestTopicDTO> myTestTopic(Long userId, Long topicId) {
        return this.baseMapper.myTestTopic(userId, topicId);
    }
    @Override
    public List<MentalTestMyTestRecordTopicDTO> myTestRecordTopicByMentalAppointmentId(Long mentalAppointmentId, List<Long> mentalAppointmentIdList) {
        return this.baseMapper.myTestRecordTopicByMentalAppointmentId(mentalAppointmentId, mentalAppointmentIdList);
    }
 
    @Override
    public List<MentalTestMyTestOrderDTO> myTestOrder(Long userId, Long topicId) {
        return this.baseMapper.myTestOrder(userId, topicId);
    }
 
    @Override
    public Long getConsultWorkerIdByRecord(Long mentalTestRecordId, Long userId) {
        // 咨询性格分析师
        Long consultWorkerId = null;
        if (mentalTestRecordId != null) {
            // 从性格测试结果获取,性格分析师ID
            MentalTestRecord mentalTestRecord = this.getById(mentalTestRecordId);
            consultWorkerId = mentalTestRecord.getConsultWorkerId();
        }
 
        if (consultWorkerId == null && userId != null) {
            // 从其他记录中获取
            consultWorkerId = this.getObj(
                    Wrappers.<MentalTestRecord>lambdaQuery()
                            .select(MentalTestRecord::getConsultWorkerId)
                            .eq(MentalTestRecord::getUserId, userId)
                            .isNotNull(MentalTestRecord::getConsultWorkerId)
                            .last("limit 1"),
                    l -> (Long) l
            );
 
            if (consultWorkerId != null) {
                // 将性格分析师分配入测试记录
                this.update(
                        Wrappers.<MentalTestRecord>lambdaUpdate()
                                .set(MentalTestRecord::getConsultWorkerId, consultWorkerId)
                                .eq(MentalTestRecord::getId, mentalTestRecordId)
                );
            }
        }
        return consultWorkerId;
    }
 
    @Override
    public Page<MentalTestRecordPageDTO> getPage(Page<Object> page, String title, String nickName, String telephone, Integer testType) {
        return this.baseMapper.getPage(page, title, nickName, telephone, testType);
    }
}