【SaaS云会议系统开发】我的会议后端编写
1.编写Entity层
根据数据库新建一个实体类MeetingUserRelation
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "meeting_user_relation")
public class MeetingUserRelation {
@Id
@Column(name = "id")
private Integer id;
@Column(name = "meeting_id")
private Integer meetingId;
@Column(name = "user_id")
private Integer userId;
}
2.编写Repositery层
导入jpa相关包,在不同的数据库类中定义方法;
(1)MeetingRepository类
import com.rjxy.Entity.Meeting;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.sql.Timestamp;
import java.util.List;
public interface MeetingRepository extends JpaRepository<Meeting,Integer> {
Meeting findMeetingById(Integer meetingId);
Meeting findMeetingByMeetingNumber(Integer meetingNumber);
Meeting findByMeetingNumberAndStatus(Integer meetingNumber, Integer status);
@Query(value = "select * from meeting as m left join meeting_result_user_relation as r on m.id = r.meeting_id where m.status=?1 and r.user_id=?2 and m.start_time > ?3 and m.end_time < ?4", nativeQuery = true)
List<Meeting> findMeetingByStatusAndUserIdAndStartTimeAndEndTime(Integer Status, Integer userId, Timestamp startTime, Timestamp endTime);
Meeting findMeetingByIdAndStatus(Integer meetingId, int i);
}
(2)MeetingUserRelationRepository类
import com.rjxy.Entity.MeetingUserRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface MeetingUserRelationRepository extends JpaRepository<MeetingUserRelation,Integer>{
List<MeetingUserRelation> findByUserId(Integer userId);
List<MeetingUserRelation> findByMeetingId(Integer meetingId);
void deleteByMeetingId(Integer id);
}
3.编写Service层
MeetingService接口定义;
import com.rjxy.Entity.Meeting;
import com.rjxy.Enum.MeetingStatusEnum;
import com.rjxy.Exception.MeetingNotExistException;
import java.util.List;
public interface MeetingService {
// 根据会议号获取会议
Meeting getMeetingByMeetingNumber(Integer meetingNumber);
// 获取用户的历史会议
List<Meeting> getHistoryMeetingByUserId(Integer userId, Long startTime, Long endTime);
}
MeetingServiceImpl接口实现;
import com.rjxy.Entity.Meeting;
import com.rjxy.Entity.MeetingUserRelation;
import com.rjxy.Enum.MeetingStatusEnum;
import com.rjxy.Exception.MeetingNotExistException;
import com.rjxy.Repository.MeetingRepository;
import com.rjxy.Repository.MeetingUserRelationRepository;
import com.rjxy.Service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@Service
public class MeetingServiceImpl implements MeetingService {
@Autowired
private MeetingRepository meetingRepository;
@Autowired
private MeetingUserRelationRepository meetingUserRelationRepository;
//获得我的会议列表
@Override
public List<Meeting> getMeetingByUserId(Integer userId) {
List<MeetingUserRelation> relations = meetingUserRelationRepository.findByUserId(userId);
List<Meeting> meetings = new ArrayList<>();
for (MeetingUserRelation relation : relations) {
Meeting meeting = meetingRepository.findMeetingByIdAndStatus(relation.getMeetingId(), 1);
if (meeting != null) {
meetings.add(meeting);
}
return meetings;
}
return meetings;
}
4.总结
获取我的会议列表功能的Repo层和Service层功能基本实现。其余需要与前端人员进行讨论决定前后端数据传输问题。