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

山东大学项目实训weblab(八)组织管理(一)

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

山东大学项目实训weblab(八)组织管理(一)

组织管理(一)
    • 前言
      • 任务目标
      • 我的任务
      • 工作内容
      • 代码

前言

项目仓库

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

任务目标

实现组织的新建,查询,更新功能。

我的任务

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

工作内容

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

代码

实体类
Organization.java

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Organization implements Serializable {
    private Integer id;
    private String name;
    private String code;
    private String courseId;
    private Integer founderId;
    private String founderName;
    private String description;
    private Integer status;
    private Date createTime;
    private Date lastModifyTime;
    private String beginTime;
    private String endTime;

    @Override
    public String toString() {
        return "Organization{" +
                "id=" + id +
                ", name='" + name + ''' +
                ", code=" + code + "'" +
                ", founderid='" + founderId + ''' +
                ", description='" + description + ''' +
                ", status=" + status +
                ", createTime=" + createTime +
                ", lastModifyTime=" + lastModifyTime +
                '}';
    }
}

OrganizationMapper.xml

	
        insert into organization(id,name,code,founder_id,description,status,course_id,founder_name,begin_time,end_time)
        values (#{id}, #{name}, #{code}, #{founderId}, #{description}, #{status}, #{courseId}, #{founderName}, #{beginTime}, #{endTime})
    
    
        update organization set name=#{name} where id=#{id} and status=0
    
    
        update organization set description=#{desc} where id=#{id} and status=0
    
    
        update organization set status=1 where id=#{id}
    
    
        select * from organization
        where code=#{code} and status=0
    
    

OrganizationServiceImpl.java

@Service
public class OrganizationServiceImpl implements OrganizationService {

    @Autowired
    private OrganizationMapper organizationMapper;

    @Override
    public void addOrg(Organization org)
    {
        organizationMapper.addOrganization(org);
    }

    
    @Override
    public String getOrgNameById(int id) {
        Organization org = organizationMapper.getOrgById(id);
        //System.out.println("TTTIS --- --- " + id);
        //System.out.println("OPPPP --- --- " + org.getName());
        return org.getName();
    }

    
    @Override
    public Organization getOrgById(int id) {
        Organization org = organizationMapper.getOrgById(id);
        //System.out.println("TTTIS --- --- " + id);
        //System.out.println("OPPPP --- --- " + org.getName());
        return org;
    }

    
    @Override
    public Organization getOrgByCode(String code) {
        Organization org = organizationMapper.getOrgByCode(code);
        //System.out.println("TTTIS --- --- " + id);
        //System.out.println("OPPPP --- --- " + org.getName());
        return org;
    }

    @Override
    public List getOrgListByFounderId(int founderId) {
        return organizationMapper.getOrgListByFounderId(founderId);
    }

    @Override
    public List getOrgListByUserId(int userId) {
        return  organizationMapper.getOrgListByUserId(userId);
    }


    
    @Override
    public UserList getStuList(int id) {
        List list = organizationMapper.getOrgStuList(id);
        //for(User user : list) {
        //    System.out.println(user);
        //}
        UserList userList = new UserList(list);
        return userList;
    }

    
    @Override
    public void JoinOrg(Integer orgId, Integer userId) {
        organizationMapper.addUserIntoOrgById(orgId, userId);
    }

    
    @Override
    public void QuitOrg(Integer orgId, Integer userId) {
        organizationMapper.deleteUserFromOrgById(orgId, userId);
    }

    
    @Override
    public void removeOrg(int orgId) {
        organizationMapper.deleteOrgById(orgId);
        organizationMapper.deleteMessageFromOrgByOrgId(orgId);
        organizationMapper.deleteLabFromOrgByOrgId(orgId);
    }

    
    @Override
    public void updateOrg(Organization organization) {
        organizationMapper.setOrg(organization);
    }
}

OrganizationController.java

@RestController
@RequestMapping("/organization")
@Slf4j
public class OrgController {



    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private UserService userService;

    
    @PostMapping(value = "/createOrg")
    public ResultEntity createOrg(String name,String desc,String courseId ,String beginTime ,String endTime) throws Exception {
        Integer founderId = UserUtil.getCurrentUser().getId();
        String founderName = userService.getUserById(founderId).getUsername();
        //System.out.println(founderName);
        Organization organization = new Organization(null, name, null, courseId, founderId, founderName, desc, 0, null, null ,beginTime, endTime);
        String str = UserUtil.getVerifyCode(6);
        while(organizationService.getOrgByCode(str)!=null)
        {
            str = UserUtil.getVerifyCode(6);
        }
        int id = Integer.parseInt(UserUtil.getVerifyCode(6));
        while(organizationService.getOrgById(id)!=null)
        {
            id = Integer.parseInt(UserUtil.getVerifyCode(6));
        }
        organization.setId(id);
        organization.setCode(str);
        System.out.println(organization);
        organizationService.addOrg(organization);
        return ResultEntity.success(organization.getId());
    }

    @PostMapping(value = "/createOrgMessage")
    public ResultEntity createOrgMessage(String name,String desc,String courseId ,String beginTime ,String endTime) throws Exception {
        Integer founderId = UserUtil.getCurrentUser().getId();
        String founderName = userService.getUserById(founderId).getUsername();
        //System.out.println(founderName);
        Organization organization = new Organization(null, name, null, courseId, founderId, founderName, desc, 0, null, null ,beginTime, endTime);
        String str = UserUtil.getVerifyCode(6);
        while(organizationService.getOrgByCode(str)!=null)
        {
            str = UserUtil.getVerifyCode(6);
        }
        int id = Integer.parseInt(UserUtil.getVerifyCode(6));
        while(organizationService.getOrgById(id)!=null)
        {
            id = Integer.parseInt(UserUtil.getVerifyCode(6));
        }
        organization.setId(id);
        organization.setCode(str);
        System.out.println(organization);
        organizationService.addOrg(organization);
        return ResultEntity.success(organization);
    }

    
    @PostMapping(value = "/getOrgMessageById")
    public ResultEntity getOrgMessageById(int orgId) {
        Organization org = organizationService.getOrgById(orgId);
        if(org != null)
            return ResultEntity.success(org);
        else
            return ResultEntity.error("Organization not found",null);
    }

    
    @PostMapping(value = "/getOrgMessageByCode")
    public ResultEntity getOrgMessageByCode(String code) {
        Organization org = organizationService.getOrgByCode(code);
        if(org != null)
            return ResultEntity.success(org);
        else
            return ResultEntity.error("Organization not found",null);
    }

    
    @PostMapping(value = "/confirmJoinOrg")
    public ResultEntity ConfirmJoinOrg(int orgId) {
        if(organizationService.getOrgById(orgId)==null)
            return ResultEntity.error("Organization not found",null);
        Integer orgId1 = Integer.valueOf(orgId);
        Integer userId = UserUtil.getCurrentUser().getId();
        //System.out.println("PPPP+++++" + user_id);
        organizationService.JoinOrg(orgId1, userId);
        return ResultEntity.success();
    }

    
    @PostMapping(value = "/confirmQuitOrg")
    public ResultEntity ConfirmQuitOrg(int orgId) {
        if(organizationService.getOrgById(orgId)==null)
            return ResultEntity.error("Organization not found",null);
        //System.out.println("PPPP+++++" + user_id);
        Integer orgId2 = Integer.valueOf(orgId);
        Integer userId = UserUtil.getCurrentUser().getId();
        organizationService.QuitOrg(orgId2, userId);
        return ResultEntity.success();
    }

    
    @PostMapping(value = "/getStuList")
    public ResultEntity getStuList(int orgId) {
        if(organizationService.getOrgById(orgId)==null)
            return ResultEntity.error("Organization not found",null);
        UserList stuList = organizationService.getStuList(orgId);
        System.out.println(stuList);
        return ResultEntity.success(stuList.getUserList());
    }

    
    @PostMapping(value = "/getOrgListByFounderId")
    public ResultEntity getOrgListByFounderId(int founderId) {
        List list = organizationService.getOrgListByFounderId(founderId);
        return ResultEntity.success(list);
    }

    
    @PostMapping(value = "/getOrgListByFounder")
    public ResultEntity getOrgListByFounder() {
        Integer founderId = UserUtil.getCurrentUser().getId();
        List list = organizationService.getOrgListByFounderId(founderId);
        return ResultEntity.success(list);
    }

    
    @PostMapping(value = "/getOrgListByUserId")
    public ResultEntity getOrgList(int userId) {
        List list = organizationService.getOrgListByUserId(userId);
        return ResultEntity.success(list);
    }

    
    @PostMapping(value = "/updateOrg")
    public ResultEntity updateOrg(int id, String name, String desc, String courseId, String beginTime, String endTime) {
        Organization org = organizationService.getOrgById(id);
        if(org==null)
            return ResultEntity.error("Organization not found",null);
        org.setName(name);
        org.setCourseId(courseId);
        org.setDescription(desc);
        org.setBeginTime(beginTime);
        org.setEndTime(endTime);
        organizationService.updateOrg(org);
        return ResultEntity.success(organizationService.getOrgById(id));
    }

    @PostMapping(value = "/deleteOrg")
    public ResultEntity deleteOrg(int id) {
        if(organizationService.getOrgById(id)==null)
            return ResultEntity.error("Organization not found",null);
        organizationService.removeOrg(id);
        return ResultEntity.success();
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/956881.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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