nickchange
2023-11-29 d4fbea2ac7f7c98ffd83480f8f2535ca92f3baea
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.dsh.course.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.course.entity.CoursePackageScheduling;
import com.dsh.course.entity.CoursePackageStudent;
import com.dsh.course.entity.StudentClassInfo;
import com.dsh.course.entity.TAppUser;
import com.dsh.course.entity.dto.ClassListDto;
import com.dsh.course.feignclient.account.AppUserClient;
import com.dsh.course.feignclient.account.StudentClient;
import com.dsh.course.feignclient.account.model.AppUser;
import com.dsh.course.feignclient.account.model.Student;
import com.dsh.course.mapper.CoursePackageSchedulingMapper;
import com.dsh.course.mapper.CoursePackageStudentMapper;
import com.dsh.course.model.QueryCoursePackageStudentList;
import com.dsh.course.service.CoursePackageSchedulingService;
import com.dsh.course.service.CoursePackageStudentService;
import com.dsh.course.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 学员上课记录 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-06-30
 */
@Service
public class CoursePackageStudentServiceImpl extends ServiceImpl<CoursePackageStudentMapper, CoursePackageStudent> implements CoursePackageStudentService {
 
    @Resource
    private AppUserClient appUserClient;
 
    @Resource
    private StudentClient studentClient;
 
 
    @Autowired
    private CoursePackageSchedulingMapper coursePackageSchedulingService;
 
    /**
     * 获取排课预约数据
     *
     * @param queryCoursePackageStudentList
     * @return
     */
    @Override
    public List<Map<String, Object>> queryCoursePackageStudentList(Page<Map<String, Object>> page, QueryCoursePackageStudentList queryCoursePackageStudentList) {
        List<Integer> userId = null;
        List<Integer> studentId = null;
        if (ToolUtil.isNotEmpty(queryCoursePackageStudentList.getUserName())) {
            List<AppUser> appUsers = appUserClient.queryAppUserListByName(queryCoursePackageStudentList.getUserName());
            if (appUsers.size() > 0) {
                userId = appUsers.stream().map(AppUser::getId).collect(Collectors.toList());
            }
        }
        if (ToolUtil.isNotEmpty(queryCoursePackageStudentList.getStudentName())) {
            List<Student> students = studentClient.queryStudentListByName(queryCoursePackageStudentList.getStudentName());
            if (students.size() > 0) {
                studentId = students.stream().map(Student::getId).collect(Collectors.toList());
            }
        }
 
 
        CoursePackageScheduling coursePackageScheduling = coursePackageSchedulingService.selectById(queryCoursePackageStudentList.getCoursePackageSchedulingId());
        List<CoursePackageScheduling> coursePackageSchedulings = coursePackageSchedulingService.selectList(new QueryWrapper<CoursePackageScheduling>().eq("coursePackageId", coursePackageScheduling.getCoursePackageId()).eq("classDate", coursePackageScheduling.getClassDate()));
 
 
        List<Long> ids = new ArrayList<>();
        for (CoursePackageScheduling packageScheduling : coursePackageSchedulings) {
            ids.add(packageScheduling.getId());
        }
 
        List<Map<String, Object>> list = this.baseMapper.queryCoursePackageStudentList(page, ids, userId, studentId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Integer now = Integer.valueOf(sdf.format(new Date()));
        for (Map<String, Object> map : list) {
            Integer appUserId = Integer.valueOf(map.get("appUserId").toString());
            Integer student_Id = Integer.valueOf(map.get("studentId").toString());
            TAppUser appUser = appUserClient.queryAppUser1(appUserId);
            Student student = studentClient.queryStudentById(student_Id);
            map.put("userName", appUser.getName());
            map.put("phone", student.getPhone());
            map.put("studentName", student.getName());
            map.put("age", null != student.getBirthday() ? now - Integer.valueOf(sdf.format(student.getBirthday())) : "-");
            map.put("sex", student.getSex());
        }
        return list;
    }
 
    @Override
    public StudentClassInfo listAll(Integer tStudentId) {
        return this.baseMapper.listAll(tStudentId);
    }
 
    @Override
    public List<ClassListDto> getClassList(Integer tStudentId) {
        List<ClassListDto> classList = this.baseMapper.getClassList(tStudentId);
        List<ClassListDto> holiList = this.baseMapper.getHoliList(tStudentId);
        classList.addAll(holiList);
 
        return classList;
    }
 
    @Override
    public Date getMaxDate(Integer tStudentId) {
        return this.baseMapper.getMaxDate(tStudentId);
    }
 
    @Override
    public Date getMinDate(Integer tStudentId) {
        return null;
    }
 
    @Override
    public void updateSignInOrNotById(Long id) {
        this.baseMapper.updateSignInOrNotById(id);
    }
}