发布于2021-07-24 21:46 阅读(1426) 评论(0) 点赞(0) 收藏(1)
根据数据库新建一个实体类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;
}
导入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);
}
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;
}
获取我的会议列表功能的Repo层和Service层功能基本实现。其余需要与前端人员进行讨论决定前后端数据传输问题。
作者:小酷狗
链接:http://www.pythonpdf.com/blog/article/350/d0186ca8521b1c38e092/
来源:编程知识网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!