studentMeetingService.js
7.3 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
var studentMeeting = require('../model/studentMeetingModel');
var userModel = require('../model/userModel');
var status = require('../util/resTemplate');
var saitMd5 = require('../util/saltMD5');
var sequelize = require('../config');
var tokenUtil = require('../util/tokenUtil');
var meetingModel = require('../model/meetingModel');
var co = require('co');
function studentMeetingService(){
}
studentMeetingService.prototype.addStudentMeeting = async(body)=>{
try {
var t = await sequelize.transaction({ autocommit: true })
let user = await userModel.findOne({where:{id:body.studentId}});
if(!user){
t.rollback();
return {code:300,msg:'用户不存在'}
}
let oldSutudentMeeting = await studentMeeting.findOne({where:{studentId:body.studentId,meetingId:body.meetingId}});
if(oldSutudentMeeting){
t.rollback();
console
var error = {code:300,msg:''}
if(body.status == 7){
error.msg = '您已收藏这堂课'
}else{
error.msg = '您已预约这堂课'
}
return error
}
let Meeting = await meetingModel.findOne({where:{id:body.meetingId}});
if(!Meeting){
t.rollback();
return {code:300,msg:'课堂不存在'}
}
let sm = await studentMeeting.create(body,{transaction: t});
// let MeetingBack = await meetingModel.update(
// {reservationNumber:Meeting.reservationNumber+1},
// {where:{id:body.meetingId}},
// {transaction: t});
t.commit();
return sm;
} catch (error) {
t.rollback();
throw error;
}
}
studentMeetingService.prototype.getStudentMeetingCount = async(meetingId) =>{
try {
let sm = await studentMeeting.count({where:{meetingId:meetingId}})
return sm;
} catch (error) {
console.log(error)
throw error;
}
}
studentMeetingService.prototype.queryStudentMeeting = async(teacherName,page=1,pageno=8)=>{
try {
let querySql = `SELECT
3u.*, 3meet.meeting_name,
3meet.create_user teacherName
FROM
3m_student_meeting 3sm
LEFT JOIN 3m_user 3u ON 3u.id = 3sm.student_id
LEFT JOIN 3m_meeting 3meet ON 3meet.id = 3sm.meeting_id
WHERE
3meet.create_user = '` +teacherName+"'";;
querySql += ' ORDER BY 3sm.create_time DESC LIMIT '+(page-1)*pageno+' , ' +pageno
let sm = await sequelize.query(querySql);
return sm[0];
} catch (error) {
console.log(error)
throw error;
}
}
studentMeetingService.prototype.getStudentMeetingBySite = async(siteId,page=1,pageno=8)=>{
try {
let querySql = `SELECT
3u.*, 3meet.meeting_name,
3meet.meeting_status meetingStatus,
3meet.id meetingId,
3meet.create_user teacherName,
3meet.meeting_number meetingNumber,
3meet.begin_time meetingBeginTime,
3meet.end_time meetingEndTime,
3sm. STATUS studentMeetingStatus,
3u2.user_name checkUserName,
3sm.check_time check_time,
3sm.id studentMeetingId,
(SELECT
3m_attachment.path
FROM
3m_user
LEFT JOIN 3m_attachment ON 3m_attachment.business_id = 3m_user.id
WHERE
3m_user.login_name = 3meet.create_user) teacherPhoto,
(
SELECT
path
FROM
3m_attachment
WHERE
3m_attachment.business_id = 3meet.id and 3m_attachment.category = 1
) meetingPhoto
FROM
3m_student_meeting 3sm
LEFT JOIN 3m_user 3u ON 3u.id = 3sm.student_id
LEFT JOIN 3m_user 3u2 ON 3u2.id = 3sm.check_user_id
LEFT JOIN 3m_meeting 3meet ON 3meet.id = 3sm.meeting_id
WHERE
3sm.site_id = '` +siteId+"'";;
querySql += ' AND 3sm.status != 5 ORDER BY 3sm.create_time DESC LIMIT '+(page-1)*pageno+' , ' +pageno
let count = await studentMeeting.count({where:{siteId:siteId,status:{$ne: 5}}})
let sm = await sequelize.query(querySql);
return {studentMeeting:sm[0],count:count,page:page,pageno:pageno};
//return sm[0];
} catch (error) {
throw error;
}
}
studentMeetingService.prototype.updateStudentMeetingBySite = async(id,data) =>{
try {
let studentMeetingS = await studentMeeting.update(data,{where:{id:id}});
return studentMeetingS;
} catch (error) {
throw error;
}
}
studentMeetingService.prototype.delStudentMeetingBySite = async(id,siteId) =>{
try {
console.log(siteId)
let s = await studentMeeting.find({where:{meetingId:id,siteId:siteId}});
if(!s){
throw new Error('数据不存在')
}
let studentMeetingS = await studentMeeting.destroy({where:{meetingId:id,siteId:siteId}});
return studentMeetingS;
} catch (error) {
throw error;
}
}
studentMeetingService.prototype.getStudentMeetingByStudentId = async(id,page=1,pageno=8,body) =>{
try {
let querySql = `SELECT
3u.*, 3meet.meeting_name,
3meet.meeting_status meetingStatus,
3meet.id meetingId,
3meet.create_user teacherName,
3meet.meeting_number meetingNumber,
3meet.begin_time meetingBeginTime,
3meet.end_time meetingEndTime,
3sm. STATUS studentMeetingStatus,
3u2.user_name checkUserName,
3sm.check_time check_time,
3sm.id studentMeetingId,
(SELECT
3m_attachment.path
FROM
3m_user
LEFT JOIN 3m_attachment ON 3m_attachment.business_id = 3m_user.id
WHERE
3m_user.login_name = 3meet.create_user) teacherPhoto,
(
SELECT
path
FROM
3m_attachment
WHERE
3m_attachment.business_id = 3meet.id and 3m_attachment.category = 1
) meetingPhoto
FROM
3m_student_meeting 3sm
LEFT JOIN 3m_user 3u ON 3u.id = 3sm.student_id
LEFT JOIN 3m_user 3u2 ON 3u2.id = 3sm.check_user_id
LEFT JOIN 3m_meeting 3meet ON 3meet.id = 3sm.meeting_id
WHERE
3sm.student_id = '` +id+"'";;
if(body.status){
querySql += ' and 3sm.status = ' + body.status
}
querySql += ' AND 3sm.status != 5 ORDER BY 3sm.create_time DESC LIMIT '+(page-1)*pageno+' , ' +pageno
let sm = await sequelize.query(querySql);
return sm[0];
} catch (error) {
throw error
}
}
studentMeetingService.prototype.isAppointment = async(body)=>{
try {
let Appointment = await studentMeeting.findAll({where:body});
return Appointment;
} catch (error) {
throw error;
}
}
module.exports = new studentMeetingService();