栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

山东大学项目实训weblab(十二)作业管理

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

山东大学项目实训weblab(十二)作业管理

作业管理
    • 前言
      • 任务目标
      • 我的任务
      • 工作内容
      • 代码

前言

项目仓库

本项目是为开发一套容器化的开发、运行、测试环境,用以支持Web开发、程序设计等课程的实验教学。

任务目标

实现通知的新建,查询,更新功能。

我的任务

Mapper层编写sql,操作数据库,建立通知的Service和controller层,编写通知的新建,查询,更新接口。

工作内容

建立Lab表,设计对应操作API

代码

实体类
Lab.java

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Lab {
    private Integer id;
    private Integer organizationId;
    private Integer founderId;
    private String name;
    private String description;
    private String beginTime;
    private String endTime;
    private Integer status;
    private Date createTime;
    private Date lastModifyTime;
}

LabMapper.xml


    
        
        
        
        
        
        
        
    
    
        
        
        
        
        
        
    
    
        
        
        
        
        
        
        
        
        
        
        
        
    
    
        insert into lab(id, organization_id, founder_id, name, description, status, begin_time, end_time)
        values (#{id}, #{organizationId}, #{founderId}, #{name}, #{description}, #{status}, #{beginTime}, #{endTime})
    
    
        update lab set id = #{id}, organization_id = #{organizationId}, founder_id = #{founderId}, name = #{name}, description = #{description}, begin_time = #{beginTime}, end_time = #{endTime}
        where id=#{id} and status=0
    
    
        select * from lab
        where organization_id=#{orgId} and status=0
    
    
        select p1.id ,p1.weblab_user_id ,p1.gitlab_user_id ,p1.name ,p1.description ,p1.url, u1.real_name, u1.grade, u1.banji, u1.student_id, u1.head_img, u1.signature
        from lab_project l1,project p1,userInfo u1
        where p1.weblab_user_id=u1.user_id and l1.project_id=p1.id and l1.lab_id=#{labId} and p1.status=0 and u1.status=0
    


    
        insert into lab_project(lab_id, project_id)
        values (#{labId}, #{projectId})
    
    
        delete from lab_project
        where lab_id=#{labId}
    
    
        delete from lab_project
        where project_id=#{projectId} and lab_id=#{labId}
    

LabServiceImpl.java

@Service
public class LabServiceImpl implements LabService {

    @Autowired
    LabMapper labMapper;

    @Override
    public void createLab(Lab lab) {
        labMapper.addLab(lab);
    }

    @Override
    public Lab getLabById(int id) {
        return labMapper.getLabById(id);
    }

    @Override
    public void removeLab(int id) {
        labMapper.deleteLab(id);
        labMapper.deleteProjectFromLabByLabId(id);
    }

    @Override
    public void updateLab(Lab lab) {
        labMapper.setLab(lab);
    }

    @Override
    public List getProjectList(int labId) {
        List list = labMapper.getProjectList(labId);
        return list;
    }

    @Override
    public List getOrgLabList(int orgId) {
        List list = labMapper.getOrgLabList(orgId);
        return list;
    }

    @Override
    public List getUserProjectList(int userId, int labId) {
        List list = labMapper.getUserProjectList(userId, labId);
        return list;
    }

    @Override
    public void addProjectIntoLab(int labId, int projectId) {
        labMapper.addProjectIntoLab(labId, projectId);
    }

}

LabController.java

@RestController
@RequestMapping("/lab")
@Slf4j
public class LabController {

    @Autowired
    private LabService labService;

    @Autowired
    private OrganizationService organizationService;


    
    @PostMapping(value = "/createLab")
    public ResultEntity createLab(int organizationId, String name, String desc, String beginTime, String endTime) throws Exception {
        if(organizationService.getOrgById(organizationId)==null)
            return ResultEntity.error("Organization not found",null);
        Integer founderId = UserUtil.getCurrentUser().getId();
        Lab lab = new Lab(null, organizationId, founderId, name ,desc, beginTime, endTime, 0, null, null);
        lab.setId(Integer.parseInt(UserUtil.getVerifyCode(6)));
        labService.createLab(lab);
        return ResultEntity.success(lab);
    }

    
    @PostMapping(value = "/updateLab")
    public ResultEntity updateLab(int id, String name, String desc, String beginTime, String endTime) {
        if(labService.getLabById(id)==null)
            return ResultEntity.error("Lab not found",null);
        Lab lab = labService.getLabById(id);
        if(organizationService.getOrgById(lab.getOrganizationId())==null)
            return ResultEntity.error("Organization not found",null);
        lab.setName(name);
        lab.setDescription(desc);
        lab.setBeginTime(beginTime);
        lab.setEndTime(endTime);
        labService.updateLab(lab);
        return ResultEntity.success(lab);
    }

    
    @PostMapping(value = "/getLabById")
    public ResultEntity getLabById(int id) {
        Lab lab = labService.getLabById(id);
        if(lab==null)
            return ResultEntity.error("Lab not found",null);
        if(organizationService.getOrgById(lab.getOrganizationId())==null)
            return ResultEntity.error("Organization not found",null);
        return ResultEntity.success(lab);
    }

    
    @PostMapping(value = "/getProjectList")
    public ResultEntity getProjectList(int labId) {
        if(labService.getLabById(labId)==null)
            return ResultEntity.error("Lab not found",null);
        if(organizationService.getOrgById(labService.getLabById(labId).getOrganizationId())==null)
            return ResultEntity.error("Organization not found",null);
        List list = labService.getProjectList(labId);
        return ResultEntity.success(list);
    }

    
    @PostMapping(value = "/getUserProjectList")
    public ResultEntity getUserProjectList(int userId, int labId) {
        if(labService.getLabById(labId)==null)
            return ResultEntity.error("Lab not found",null);
        if(organizationService.getOrgById(labService.getLabById(labId).getOrganizationId())==null)
            return ResultEntity.error("Organization not found",null);
        List list = labService.getUserProjectList(userId,labId);
        return ResultEntity.success(list);
    }



    
    @PostMapping(value = "/getOrgLabList")
    public ResultEntity getOrgLabList(int orgId) {
        if(organizationService.getOrgById(orgId)==null)
            return ResultEntity.error("Organization not found",null);
        List list = labService.getOrgLabList(orgId);
        return ResultEntity.success(list);
    }

    
    @PostMapping(value = "/deleteLab")
    public ResultEntity deleteLab(int id) {
        if(labService.getLabById(id)==null)
            return ResultEntity.error("Lab not found",null);
        if(organizationService.getOrgById(labService.getLabById(id).getOrganizationId())==null)
            return ResultEntity.error("Organization not found",null);
        labService.removeLab(id);
        return ResultEntity.success();
    }

    @PostMapping(value = "/addProjectIntoLab")
    public ResultEntity addProjectIntoLab(int labId, int projectId) {
        if(labService.getLabById(labId)==null)
            return ResultEntity.error("Lab not found",null);
        if(organizationService.getOrgById(labService.getLabById(labId).getOrganizationId())==null)
            return ResultEntity.error("Organization not found",null);
        labService.addProjectIntoLab(labId, projectId);
        return ResultEntity.success();
    }

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/967145.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号