本站消息

  出租广告位,需要合作请联系站长

  今日名言-想象你自己对困难作出的反应,不是逃避或绕开它们,而是面对它们,同它们打交道,以一种进取的和明智的方式同它们奋斗 。——马克斯威尔·马尔兹

  今日名言-用谅解、宽恕的目光和心理看人、待人。人就会觉得葱笼的世界里,春意盎然,到处充满温暖。——蔡文甫


+关注
已关注

分类  

python(8)

java(2)

标签  

python(5)

java(1)

日期归档  

暂无数据

【SaaS云会议系统开发】项目实训——2021.07.06

发布于2021-07-24 21:46     阅读(1426)     评论(0)     点赞(0)     收藏(1)


【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层功能基本实现。其余需要与前端人员进行讨论决定前后端数据传输问题。



所属网站分类: 程序员的那点事

作者:小酷狗

链接:http://www.pythonpdf.com/blog/article/350/d0186ca8521b1c38e092/

来源:编程知识网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

0 0
收藏该文
已收藏

评论内容:(最多支持255个字符)