Java怎么实现教材管理系统

发布时间:2021-11-24 11:10:43 作者:柒染
来源:亿速云 阅读:222

这篇文章给大家介绍Java怎么实现教材管理系统,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

一、项目简述

功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用 户包括学生和教师)可以对教材商、教材进行。Excel的导入 导出操作。教师以领取入库的教材,可以退还教材。学生只能在对应的教师那里领取教材,并且可以退还教材、 查询自己已经领取的教材。并且对已领教材付款等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

Java怎么实现教材管理系统

Java怎么实现教材管理系统

Java怎么实现教材管理系统

Java怎么实现教材管理系统

Java怎么实现教材管理系统

查看班级选报信息:

 @Service
public class TopicsServiceImpl implements TopicsService {
 
    @Autowired
    private MyClassMapper classMapper;
 
    @Autowired
    private StudentMapper studentMapper;
 
    @Autowired
    private SubjectselectedMapper subjectselectedMapper;
 
    @Autowired
    private SubjectMapper subjectMapper;
 
    @Autowired
    private HttpServletRequest request;
 
    /**
     * 查看班级选报信息
     */
    @Override
    public List<classinfo> classinfo(Long id) {
        MyClass className = classMapper.selectById(id);//查到班级名字
        List<Student> students = studentMapper.selectByListAll(id);//根据student表里班级id查到用户所在班级的所有人
        List<Subjectselected> projectselectedlist = new ArrayList<>();
        List<Subject> projectlist = new ArrayList<>();
        Subjectselected projectselected = null;
        Subject project = null;
        for (int i = 0; i < students.size(); i++) {
            List<Subjectselected> tprojectselecteds = subjectselectedMapper.selectBystudentid(students.get(i).getId());
            if (tprojectselecteds != null && tprojectselecteds.size() > 0)
                projectselected = tprojectselecteds.get(0);
            if (projectselected != null) {
                projectselectedlist.add(projectselected);
            } else {
                projectselected = new Subjectselected();
                projectselected.setId(0L);
                projectselected.setIdProject(0L);
                projectselected.setIdStudent(0L);
                projectselected.setStuselectFlag(0L);
                projectselectedlist.add(projectselected);
            }
        }
        for (int i = 0; i < projectselectedlist.size(); i++) {
            if (projectselectedlist.get(i).getId() != 0) {
                projectlist.add(subjectMapper.selectById(projectselectedlist.get(i).getIdProject()));
            } else {
                project = new Subject();
                project.setProjectname("无");
                project.setTeachernames("无");
                projectlist.add(project);
            }
        }
        List<classinfo> infolist = new ArrayList<>();
        classinfo info = null;
        for (int i = 0; i < projectlist.size(); i++) {
            info = new classinfo();
            info.setId(students.get(i).getId());
            info.setClassName(className.getClassName());
            info.setName(students.get(i).getName());
            info.setStuNum(students.get(i).getStunum());
            info.setProjectName(projectlist.get(i).getProjectname());
            info.setTeacherNames(projectlist.get(i).getTeachernames());
            info.setStuSelectFlag(projectselectedlist.get(i).getStuselectFlag());
            infolist.add(info);
        }
        return infolist;
    }
 
    /**
     * 查看课题信息
     * 通过classid
     */
    @Override
    public List<topicsinfo> topics(Long id) {
        String specialty = classMapper.selectByspecialty(id);
        List<Subject> projectlist = subjectMapper.selectByAll("%" + specialty + "%");
        List<topicsinfo> topicsinfolist = new ArrayList<>();
        topicsinfo info = null;
        for (int i = 0; i < projectlist.size(); i++) {
            info = new topicsinfo();
            info.setProject_id(projectlist.get(i).getId());
            info.setProjectType(subjectMapper.selectByprojectType(projectlist.get(i).getIdProjecttype().intValue()));
            info.setProjectSource(subjectMapper.selectByprojectSource(projectlist.get(i).getIdProjectsource().intValue()));
            info.setProjectName(projectlist.get(i).getProjectname());
            info.setSelectFlag(projectlist.get(i).getSelectFlag());
            info.setMarchSpecialty(projectlist.get(i).getMarchspecialty());
            info.setTeacherNames(projectlist.get(i).getTeachernames());
            topicsinfolist.add(info);
        }
        return topicsinfolist;
    }
 
    /**
     * 课题具体信息
     */
    @Override
    public List<topicsto> topicsinfo(Long project_id) {
        List<Subjectselected> listed = subjectselectedMapper.selectByprojectid(project_id);//中间表
        request.getSession().setAttribute("listsize",listed.size());
 
        List<topicsto> tolist = new ArrayList<>();
        topicsto to = null;
        Student student = null;
        for (int i = 0; i < listed.size(); i++) {
            to = new topicsto();
            student = studentMapper.selectByid(listed.get(i).getIdStudent());
            if(student == null)
                continue;
            to.setStuNum(student.getStunum());
            to.setName(student.getName());
            to.setStuSelectFlag(listed.get(i).getStuselectFlag());
            to.setClassName(classMapper.selectById(student.getIdClass()).getClassName());
            tolist.add(to);
        }
        return tolist;
    }
 
    /**
     * 获取该用户是否选报了课题
     */
 
    public Long state(Student student) {
        Subjectselected project = null;
        List<Subjectselected> tprojectselecteds = subjectselectedMapper.selectBystudentid(student.getId());
        if (tprojectselecteds != null && tprojectselecteds.size() > 0)
            project = tprojectselecteds.get(0);
        if (project == null) {
            return 0L;
        } else
            return project.getStuselectFlag();
    }
 
 
    /**
     * 添加选题
     */
    @Override
    public void insertproject(String project, Long studentid) {
        Long projectid = subjectMapper.selectByprojectid(project);
        int flagid = subjectselectedMapper.insertenroll(projectid, studentid);
    }
 
    /**
     * 删除选题
     */
    @Override
    public int deleteprojectselectedid(Long id) {
        int flag = subjectselectedMapper.deleteBystudentId(id);
        return flag;
    }
 
    /**
     * 查询课题名
     *
     */
    public String selectprojectname(Long id){
        String project_Name = subjectMapper.selectById(id).getProjectname();
        return project_Name;
    }
 
 
    /**
     * 获取该题是否可选
     */
    @Override
    public Long flag(Long project_id) {
        return subjectMapper.selectByselectFlag(project_id);
    }
}

班级信息查询业务:

@Service
public class ClassServiceImpl implements ClassService {
 
    @Autowired
    MyClassMapper myClassMapper;
    @Autowired
    SpecialtyService specialtyService;
    @Autowired
    StudentService studentService;
 
    @Override
    public List getClasses(Integer offset, String getName, Long specialtyid, Long id_institute) {
 
        // 设置分页查询条件
        MyClassExample myClassExample = new MyClassExample();
        //  添加查询条件
        myClassExample = addCondition(myClassExample,offset,id_institute,getName,specialtyid);
 
        if(myClassExample==null)
            return null;
 
        //如果 offset 为 -1 则只查询 id 和 name 列
        if(offset==-1)
        {
            return myClassMapper.selectByExampleSelective(myClassExample,
                    MyClass.Column.id,
                    MyClass.Column.className);
        }else{
            return myClassMapper.selectByExampleSelective(myClassExample);
        }
 
    }
 
    @Override
    public long getClassesCount(Integer offset, String getName, Long specialtyid, Long id_institute) {
        // 设置分页查询条件
        MyClassExample myClassExample = new MyClassExample();
        //        添加查询条件
        myClassExample = addCondition(myClassExample,offset,id_institute,getName,specialtyid);
 
        if(myClassExample==null)
            return 0;
 
        return myClassMapper.countByExample(myClassExample);
 
    }
 
    @Override
    public long delClass(MyClass myClass, Long id_institute) throws MyException {
        checkSpecialtyId(myClass,id_institute);
        return myClassMapper.deleteByPrimaryKey(myClass.getId());
    }
 
    @Override
    public long putClass(MyClass myClass, Long id_institute) throws MyException {
        checkSpecialtyId(myClass,id_institute);
        return myClassMapper.updateByPrimaryKey(myClass);
    }
 
    @Override
    public long postClass(MyClass myClass, Long id_institute) throws MyException {
        checkSpecialtyId(myClass,id_institute);
        long count = getClassesCount(1,myClass.getClassName(),null, id_institute);
        if(count!=0)
            throw new MyException("该班级已存在");
        return myClassMapper.insert(myClass);
    }
 
    @Override
    public long delClassBySpecialty(Long specialtyid) {
        return myClassMapper.deleteByExample(new MyClassExample().createCriteria().andIdSpecialtyEqualTo(specialtyid).example());
    }
 
    public MyClassExample addCondition(MyClassExample myClassExample,Integer offset , Long id_institute , String keyWord , Long id_specialty){
 
        //代表为超管,则可以查询所有;
        if(id_institute==-1)
        {
            return myClassExample.newAndCreateCriteria()
                    .when(StringUtil.stringIsNotNull(keyWord), criteria -> criteria.andClassNameEqualTo(keyWord)) //根据关键字查询
                    .when(id_specialty!=null,criteria -> criteria.andIdSpecialtyEqualTo(id_specialty)) //根据指定教研室查询
                    .example()
                    .when(offset!=-1 && offset != 0,criteria -> criteria.page(offset-1, 10));
        }
 
        //查询出来当前学院的所有专业
        List<Specialty> specialties = specialtyService.getSpecialtys(-1,null,null,id_institute);
 
        //提取 id列 列表
        List<Long> specialtiesIDs = specialties.stream().map(Specialty::getId).collect(Collectors.toList());
 
        if(specialtiesIDs.size()==0||specialtiesIDs==null)
            return null;
 
        return myClassExample.newAndCreateCriteria()
                .when(StringUtil.stringIsNotNull(keyWord),criteria -> criteria.andClassNameEqualTo(keyWord)) //根据关键字查询
                .when(id_specialty!=null,criteria -> criteria.andIdSpecialtyEqualTo(id_specialty)) //根据指定教研室查询
                // 查询的专业只能在当前的学院的教研室下
                .andIdSpecialtyIn(specialtiesIDs)
                .example()
                .when(offset!=-1 && offset != 0,criteria -> criteria.page(offset-1, 10));// 查询第offest-1页数据(每页10条)
 
    }
 
    public void checkSpecialtyId(MyClass myClass ,Long id_institute) throws MyException {
        //如果为超管则不需要检查有没有权力
        if(id_institute==-1)
        {
            return ;
        }
 
        long id_specialty = myClass.getIdSpecialty();
        List<Specialty> specialtyes = specialtyService.getSpecialtys(1,null,null,id_institute);
        //如果被删除的专业是不属于本系教研室则提示没有权限
        for(Specialty specialty :specialtyes)
        {
            if(specialty.getId()==id_specialty)
                return;
        }
        throw new MyException("没有权限操作");
    }
 
}

管理员业务操作:

@Service
public class AdminServiceImpl implements AdminService {
 
    @Autowired
    AdminMapper adminMapper;
 
    @Autowired
    SadminMapper sadminMapper;
 
    @Autowired
    GeneralPurposeMapper mapper;
 
    @Autowired
    PublicService publicService;
 
    //Session 保存时间(秒)
    private final Integer SAVE_TIME = 60*60*24;
 
    //超管 和 子管用一个登录
    @Autowired
    StudentMapper studentMapper;
 
    @Autowired
    SubjectselectedMapper subjectselectedMapper;
 
    @Autowired
    SubjectMapper subjectMapper;
    @Autowired
    ProjectMapper projectMapper;
 
    @Autowired
    ClassMapper classMapper;
 
 
    @Autowired
    SpecialtyMapper specialtyMapper;
 
    @Autowired
    InstituteMapper instituteMapper;
 
    @Autowired
    HttpServletRequest request;
 
    @Autowired
    HttpServletResponse response;
 
    @Override
    public Msg login(String name, String pwd , HttpSession httpSession) {
 
        Sadmin sadmin = selectSadminByName(name);
        if(sadmin!=null){
            //验证密码是否与数据库中的相同
            if(sadmin.getPwd().equals(pwd)){
                User user = new User();
                //-1表示为超管
                user.setId(-1L);
                user.setRole("sadmin");
                user.setUserName(sadmin.getName());
                //生成Token 存到 Cookie
                Cookie cookie = new Cookie("token",TokenUtil.createToken(
                        user
                ));
                //该Cookie无法被js读取
                cookie.setHttpOnly(true);
                cookie.setPath("/");
                response.addCookie(cookie);
                return Msg.success();
            }
            return Msg.error("密码错误");
        }else {
            Admin admin = selectByName(name);
            if(admin == null){
                return Msg.error("账号不存在");
            }else {
                if(admin != null && admin.getPwd().equals(pwd)){
                    User user = new User();
                    user.setId(admin.getId());
                    user.setRole("admin");
                    user.setUserName(admin.getName());
                    Cookie cookie = new Cookie("token",TokenUtil.createToken(
                            user
                    ));
                    cookie.setPath("/");
                    cookie.setHttpOnly(true);
                    response.addCookie(cookie);
                    return Msg.success();//账号密码正确
                }
                return Msg.error("密码错误");
            }
 
        }
 
 
    }
 
 
 
    @Override
    public Admin selectByName(String name) {
        //创建一个 Admin 实例 ,添加条件 为 Name == name
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria().andNameEqualTo(name);
        //根据实例 来查询
        List<Admin> admin = adminMapper.selectByExample(adminExample);
        if( admin==null || admin.size()==0 ) {
            return null;
        }
        return admin.get(0);
    }
 
    @Override
    public Sadmin selectSadminByName(String name) {
        SadminExample sadminExample = new SadminExample();
        sadminExample.createCriteria().andNameEqualTo(name);
        List<Sadmin> sadmin = sadminMapper.selectByExample(sadminExample);
        if( sadmin==null|| sadmin.size()==0 )
            return null;
        return sadmin.get(0);
    }
 
    @Override
    public int updatePwdByUserName(String name, String pwd) {
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria().andNameEqualTo(name);
        Admin admin = new Admin();
        admin.setPwd(pwd);
        adminMapper.updateByExampleSelective(admin,adminExample);
 
        return 0;
    }
 
    @Override
    public int updateSadminPwdByUserName(String name, String pwd) {
        SadminExample sadminExample = new SadminExample();
        sadminExample.createCriteria().andNameEqualTo(name);
        Sadmin sadmin = new Sadmin();
        sadmin.setPwd(pwd);
        return sadminMapper.updateByExampleSelective(sadmin, sadminExample);
    }
 
    // 班级的增加
    @Override
    public int add_class(Long specialty_id, String class_name) {
        List<Class> classes = select_class(null, null, null, null, class_name);
        if (classes == null || classes.size() == 0) {
            Class class1 = new Class();
            class1.setClassName(class_name);
            class1.setIdSpecialty(specialty_id);
            return classMapper.insert(class1);
        }
        return 0;
    }
 
    @Override
    public int addAdmin(Admin admin) {
        //添加的时候检测又没用户名重复的
        publicService.CheckIfTheUsernameIsDuplicated(admin.getName());
        return adminMapper.insert(admin);
    }
 
    @Override
    public int delAdmin(Admin admin) {
        return adminMapper.deleteByPrimaryKey(admin.getId());
    }
 
    @Override
    public int updateAdmin(Admin admin) {
        //不更新username
        admin.setName(null);
        return adminMapper.updateByPrimaryKeySelective(admin);
    }
 
    @Override
    public List selectAdmins(Long offset) {
 
 
 
        if(offset!=null && offset==-1){
            return adminMapper.selectByExampleSelective(
                    new AdminExample(),
                    Admin.Column.id
            );
        }
 
        return adminMapper.selectByExample(
                new AdminExample()
        );
    }
 
 
    // 学生的增删改查
    @Override
    public int add_student(String userName, String stuNum, Long id_class, String name, String gender, String pwd){
        Student ss = studentMapper.select_studentbyName(userName, stuNum);
        if (ss == null) {
            StudentWithBLOBs student = new StudentWithBLOBs();
            student.setUsername(userName);
            student.setStunum(stuNum);
            student.setIdClass(id_class);
            student.setName(name);
            student.setGender(gender);
            student.setPwd(pwd);
            return studentMapper.insert(student);
        }
        return 0;
    }
    public int delete_class(Long class_id) {
        return classMapper.deleteByPrimaryKey(class_id);
    }
 
    @Override
    public int update_class(Long class_id, Long specialty_id, String class_name) {
        Class class1 = new Class();
        class1.setId(class_id);
        class1.setIdSpecialty(specialty_id);
        class1.setClassName(class_name);
        return classMapper.updateByPrimaryKeySelective(class1);
    }
 
    @Override
    public List<Project> select_project(Long institute_id, Long section_id, String section_name) {
        return projectMapper.select_project(institute_id, null, null);
    }
 
    @Override
    public List<Static_student> select_studentXT_all(Long section_id, String section_name, Long specialty_id, String specialty_name, Long class_id, String class_name) {
        List<Static_student> static_students = studentMapper.select_studentXT_all(section_id, section_name, specialty_id, specialty_name, class_id, class_name);
        if (static_students != null && static_students.size() > 0) {
            for (int i = 0; i < static_students.size(); i++) {
                List<Subjectselected> projectselecteds = select_Projectselected(static_students.get(i).getId(), null);
                if (projectselecteds != null && projectselecteds.size() > 0) {
                    static_students.get(i).setStuselectFlag("" + projectselecteds.get(0).getStuselectFlag());
                    static_students.get(i).setProjectname(projectselecteds.get(0).getProject_name());
                    static_students.get(i).setTeachernames(projectselecteds.get(0).getProject_teachers());
                } else {
                    static_students.get(i).setProjectname("未选题");
                    static_students.get(i).setTeachernames("");
                }
            }
        }
        return static_students;
    }
 
 
    @Override
    public List<Class> select_class(Long institute_id, Long section_id, Long specialty_id, Long class_id, String class_name) {
        return classMapper.select_class(institute_id, section_id, specialty_id, class_id, class_name);
    }
 
    // 专业方向的增删改查
    @Override
    public int add_specialty(Long section_id, String specialty_name) {
        List<Specialty> specialties = select_specialty(null, null, null, specialty_name);
        if (specialties == null || specialties.size() == 0) {
            Specialty specialty = new Specialty();
            specialty.setIdSection(section_id);
            specialty.setSpecialtyName(specialty_name);
            return specialtyMapper.insert(specialty);
        }
        return 0;
    }
 
    @Override
    public int delete_student(Long student_id) {
        return studentMapper.deleteByPrimaryKey(student_id);
    }
 
    @Override
    public int update_student(Long student_id, String userName, String stuNum, Long id_class, String name, String gender, String pwd) {
        Student student = new Student();
        student.setId(student_id);
        student.setUsername(userName);
        student.setStunum(stuNum);
        student.setIdClass(id_class);
        student.setName(name);
        student.setGender(gender);
        student.setPwd(pwd);
        return studentMapper.updateByPrimaryKeySelective((StudentWithBLOBs) student);
    }
 
    @Override
    public List<Static_student> select_student(Long institute_id, Long specialty_id, Long class_id, Long student_id, String name) {
        List<Static_student> static_students = studentMapper.select_Student(institute_id, specialty_id, class_id, student_id, name);
        if (static_students != null) {
            for (int i = 0; i < static_students.size(); i++) {
                Static_student static_student = static_students.get(i);
 
                List<Subjectselected> projectselected = select_Projectselected(static_student.getId(), null);
 
                if (projectselected != null && projectselected.size() != 0) {
                    String s = "";
                    if (projectselected.get(0).getStuselectFlag() == 1) s = "选题待审核";
                    else if (projectselected.get(0).getStuselectFlag() == 2) s = "选题未通过";
                    else s = "选题通过";
                    static_student.setStuselectFlag(s);
                    static_student.setProjectname(projectselected.get(0).getProject_name());
                    static_student.setTeachernames(projectselected.get(0).getProject_teachers());
 
 
                }
            }
            return static_students;
        }
        return null;
    }
 
 
    // 通过学生id 或者 课题id 查 课题的选择 情况
    public List<Subjectselected> select_Projectselected(Long student_id, Long project_id) {
        return subjectselectedMapper.select_Projectselected(student_id, project_id);
    }
 
    public List<Subject> select_ProjectXQ(Long institute_id, Long section_id, String name) {
        List<Subject> projects = subjectMapper.select_ProjectXQ(institute_id, section_id, name);
        if (projects != null) {
            for (int i = 0; i < projects.size(); i++) {
                if (projects.get(i).getSelectFlag() == 0) projects.get(i).setProjectGB("可选");
                else if (projects.get(i).getSelectFlag() == 1) projects.get(i).setProjectGB("不可选");
            }
        }
        return projects;
    }
    public int delete_specialty(Long specialty_id) {
        return specialtyMapper.deleteByPrimaryKey(specialty_id);
    }
 
    @Override
    public int update_specialty(Long specialty_id, Long section_id, String specialty_name) {
        Specialty specialty = new Specialty();
        specialty.setId(specialty_id);
        specialty.setIdSection(section_id);
        specialty.setSpecialtyName(specialty_name);
 
        return specialtyMapper.updateByPrimaryKeySelective(specialty);
    }
 
    @Override
    public List<Specialty> select_specialty(Long institute_id, Long section_id, Long specialty_id, String specialty_name) {
        return specialtyMapper.select_specialty(institute_id, section_id, specialty_id, specialty_name); // 根据学院id 或者 教研室id 查所有专业方向
    }
 
    @Override
    public List<Institute> select_institute(Long institute_id, String institute_name) {
        InstituteExample instituteExample = new InstituteExample();
        InstituteExample.Criteria criteria = instituteExample.createCriteria();
        if (institute_id != null && institute_id != 0) criteria.andIdEqualTo(institute_id);
        if (institute_name != null && institute_name.length() > 0) criteria.andInstituteNameEqualTo(institute_name);
        return instituteMapper.selectByExample(instituteExample);
    }
 
 
 
}

关于Java怎么实现教材管理系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. java实现酒店管理系统
  2. Python自学教材有哪些推荐

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

java

上一篇:C++怎么避免互补性约束

下一篇:Python如何处理图像特效

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》