parent
23a31c3a51
commit
4bb353699f
23 changed files with 472 additions and 55 deletions
@ -0,0 +1,72 @@ |
||||
package com.teaching.backend.controller.umsAdmin; |
||||
|
||||
import com.teaching.backend.common.CommonResult; |
||||
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; |
||||
import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; |
||||
import com.teaching.backend.service.umsAdmin.UmsStudentManageService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import java.util.Map; |
||||
|
||||
@RestController |
||||
@Api(tags = "学生管理") |
||||
@RequestMapping("/api/studentManage") |
||||
@Slf4j |
||||
public class UmsStudentManageController { |
||||
|
||||
@Autowired |
||||
private UmsStudentManageService umsStudentManageService; |
||||
|
||||
/** |
||||
* 学生管理分页查询 |
||||
* @param umsStudentPageQueryDTO |
||||
* @return |
||||
*/ |
||||
@GetMapping("/page") |
||||
@ApiOperation("学生管理分页查询") |
||||
public CommonResult<Map<String, Object>> page(UmsStudentPageQueryDTO umsStudentPageQueryDTO){ |
||||
Map<String, Object> pageResult = umsStudentManageService.pageQuery(umsStudentPageQueryDTO); |
||||
return CommonResult.success(pageResult); |
||||
} |
||||
|
||||
/** |
||||
* 启用禁用学生账号 |
||||
* @param status |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@PostMapping("/status/{status}") |
||||
@ApiOperation("启用禁用员工账号") |
||||
public CommonResult startOrStop(@PathVariable String status, Long id){ |
||||
umsStudentManageService.startOrStop(status,id); |
||||
return CommonResult.success("修改成功"); |
||||
} |
||||
|
||||
/** |
||||
* 根据id查询学生信息 |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@GetMapping("/{id}") |
||||
@ApiOperation("根据id查询学生信息") |
||||
public CommonResult<UmsStudentManage> getById(@PathVariable Long id){ |
||||
UmsStudentManage umsStudentManage = umsStudentManageService.getByIdStudentAndUser(id); |
||||
return CommonResult.success(umsStudentManage); |
||||
} |
||||
|
||||
/** |
||||
* 编辑学生信息 |
||||
* @param umsStudentManage |
||||
* @return |
||||
*/ |
||||
@PutMapping |
||||
@ApiOperation("编辑学生信息") |
||||
public CommonResult update(@RequestBody UmsStudentManage umsStudentManage){ |
||||
log.info("编辑学生信息: {}",umsStudentManage); |
||||
umsStudentManageService.updateStudentAndUser(umsStudentManage); |
||||
return CommonResult.success("修改成功"); |
||||
} |
||||
} |
@ -1,13 +0,0 @@ |
||||
package com.teaching.backend.controller.umsStudent; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
@RestController |
||||
@Api(tags = "UmsStudentController") |
||||
@RequestMapping("/api/student") |
||||
@Slf4j |
||||
public class UmsStudentController { |
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.teaching.backend.mapper.umsAdmin; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; |
||||
import com.teaching.backend.model.entity.umsAdmin.*; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Mapper |
||||
public interface UmsStudentManageMapper extends BaseMapper<UmsStudentManage> { |
||||
|
||||
UmsStudentManage queryStudent(String userId); |
||||
|
||||
List<UmsStudentManage> pageQueryStudent(UmsStudentPageQuery umsStudentPageQuery); |
||||
|
||||
int pageQueryStudentCount(UmsStudentPageQueryDTO umsStudentPageQueryDTO); |
||||
|
||||
UmsStudentManage getByIdStudentAndUser(Long id); |
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.teaching.backend.model.dto.umsAdmin; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
public class UmsStudentPageQueryDTO implements Serializable { |
||||
|
||||
//学生姓名
|
||||
private String name; |
||||
|
||||
//学号
|
||||
private String number; |
||||
|
||||
//页码
|
||||
private int page; |
||||
|
||||
//每页显示记录数
|
||||
private int pageSize; |
||||
|
||||
//学号
|
||||
private String userId; |
||||
|
||||
} |
@ -0,0 +1,84 @@ |
||||
package com.teaching.backend.model.entity.umsAdmin; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDate; |
||||
import java.time.LocalDateTime; |
||||
|
||||
/** |
||||
* <p> |
||||
* |
||||
* </p> |
||||
* |
||||
* @author zjh |
||||
* @since 2024-06-12 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
public class UmsStudentManage implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
//用户名
|
||||
private String username; |
||||
|
||||
//密码
|
||||
private String password; |
||||
|
||||
//昵称
|
||||
private String nickName; |
||||
|
||||
//头像
|
||||
private String icon; |
||||
|
||||
//注册时间
|
||||
private LocalDateTime createTime; |
||||
|
||||
//账号状态
|
||||
private Integer status; |
||||
|
||||
//姓名
|
||||
private String name; |
||||
|
||||
//性别
|
||||
private String sex; |
||||
|
||||
//民族
|
||||
private String nationality; |
||||
|
||||
//学号
|
||||
private String number; |
||||
|
||||
//生日
|
||||
private LocalDateTime birthday; |
||||
|
||||
//手机号
|
||||
private String phone; |
||||
|
||||
//院系
|
||||
private String faculty; |
||||
|
||||
//专业
|
||||
private String major; |
||||
|
||||
//入学年份
|
||||
private LocalDate yearAge; |
||||
|
||||
//班级
|
||||
private String className; |
||||
|
||||
//user_id
|
||||
private Integer userId; |
||||
|
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.teaching.backend.model.entity.umsAdmin; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
public class UmsStudentPageQuery implements Serializable { |
||||
|
||||
//学生姓名
|
||||
private String name; |
||||
|
||||
//学号
|
||||
private String number; |
||||
|
||||
//每页显示记录数
|
||||
private int pageSize; |
||||
|
||||
//偏移量
|
||||
private int offset; |
||||
} |
@ -0,0 +1,94 @@ |
||||
package com.teaching.backend.service.impl.umsAdmin; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.teaching.backend.exception.BusinessException; |
||||
import com.teaching.backend.mapper.umsAdmin.*; |
||||
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; |
||||
import com.teaching.backend.model.entity.umsAdmin.*; |
||||
import com.teaching.backend.service.impl.courses.CoursesServiceImpl; |
||||
import com.teaching.backend.service.umsAdmin.UmsStudentManageService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.LinkedHashSet; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class UmsStudentManageServiceImpl extends ServiceImpl<UmsStudentManageMapper, UmsStudentManage> implements UmsStudentManageService { |
||||
|
||||
@Autowired |
||||
private UmsStudentManageMapper umsStudentManageMapper; |
||||
@Autowired |
||||
private UmsStudentMapper umsStudentMapper; |
||||
@Autowired |
||||
private UmsUserMapper umsUserMapper; |
||||
@Autowired |
||||
private CoursesServiceImpl coursesService; |
||||
|
||||
|
||||
@Override |
||||
public Map<String, Object> pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { |
||||
|
||||
LinkedHashSet<UmsStudentManage> umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); |
||||
|
||||
//总记录数
|
||||
int totalCount = umsStudentManages.size(); |
||||
|
||||
//总页数
|
||||
int totalPages = (int) Math.ceil((double) totalCount / umsStudentPageQueryDTO.getPageSize()); |
||||
|
||||
List<UmsStudentManage> umsStudentManageList = umsStudentManages.stream() |
||||
.skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) |
||||
.limit(umsStudentPageQueryDTO.getPageSize()) |
||||
.collect(Collectors.toList()); |
||||
|
||||
Map<String, Object> result = new HashMap<>(); |
||||
result.put("Records", umsStudentManageList); |
||||
result.put("totalCount", totalCount); |
||||
result.put("totalPages", totalPages); |
||||
result.put("currentPage", umsStudentPageQueryDTO.getPage()); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public UmsStudentManage getByIdStudentAndUser(Long id) { |
||||
UmsStudentManage studentAndUser = umsStudentManageMapper.getByIdStudentAndUser(id); |
||||
return studentAndUser; |
||||
} |
||||
|
||||
@Override |
||||
public void updateStudentAndUser(UmsStudentManage umsStudentManage) { |
||||
UmsStudent umsStudent = new UmsStudent(); |
||||
BeanUtils.copyProperties(umsStudentManage,umsStudent); |
||||
boolean studentInfo = umsStudentMapper.updateStudentInfo(umsStudent); |
||||
if (studentInfo == false){ |
||||
throw new BusinessException(400,"修改失败"); |
||||
} |
||||
UmsUser umsUser = new UmsUser(); |
||||
BeanUtils.copyProperties(umsStudentManage, umsUser); |
||||
umsUser.setId(Long.valueOf(umsStudentManage.getUserId())); |
||||
boolean userInformation = umsUserMapper.updateUserInformation(umsUser); |
||||
if (userInformation == false){ |
||||
throw new BusinessException(400,"修改失败"); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void startOrStop(String status, Long id) { |
||||
UmsUser umsUser = new UmsUser(); |
||||
umsUser.setStatus(status); |
||||
umsUser.setId(id); |
||||
boolean updateUserInformation = umsUserMapper.updateUserInformation(umsUser); |
||||
if (updateUserInformation == false){ |
||||
throw new BusinessException(400,"账号状态修改失败"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.teaching.backend.service.umsAdmin; |
||||
|
||||
|
||||
import cn.hutool.db.PageResult; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; |
||||
import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public interface UmsStudentManageService extends IService<UmsStudentManage> { |
||||
|
||||
|
||||
Map<String, Object> pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO); |
||||
|
||||
UmsStudentManage getByIdStudentAndUser(Long id); |
||||
|
||||
void updateStudentAndUser(UmsStudentManage umsStudentManage); |
||||
|
||||
void startOrStop(String status, Long id); |
||||
} |
@ -1,5 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.teaching.backend.mapper.umsAdmin.UmsPermissionMapper"> |
||||
|
||||
</mapper> |
@ -0,0 +1,46 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.teaching.backend.mapper.umsAdmin.UmsStudentManageMapper"> |
||||
|
||||
<select id="queryStudent" resultType="com.teaching.backend.model.entity.umsAdmin.UmsStudentManage"> |
||||
select * |
||||
from ums_student us |
||||
INNER JOIN ums_user uu ON us.user_id = uu.id |
||||
WHERE us.user_id = #{userId} |
||||
</select> |
||||
<select id="pageQueryStudent" resultType="com.teaching.backend.model.entity.umsAdmin.UmsStudentManage"> |
||||
select * |
||||
from ums_student us |
||||
INNER JOIN ums_user uu ON us.user_id = uu.id |
||||
<where> |
||||
<if test="name != null and name != ''"> |
||||
and name like concat('%',#{name},'%') |
||||
</if> |
||||
<if test="number != null and number != ''"> |
||||
and number like concat('%',#{number},'%') |
||||
</if> |
||||
</where> |
||||
LIMIT #{pageSize} OFFSET #{offset}; |
||||
</select> |
||||
<select id="pageQueryStudentCount" resultType="java.lang.Integer"> |
||||
SELECT COUNT(*) |
||||
FROM ums_student us |
||||
INNER JOIN ums_user uu ON us.user_id = uu.id |
||||
<where> |
||||
<if test="name != null and name != ''"> |
||||
AND us.name LIKE CONCAT('%', #{name}, '%') |
||||
</if> |
||||
<if test="number != null and number != ''"> |
||||
AND us.number LIKE CONCAT('%', #{number}, '%') |
||||
</if> |
||||
</where> |
||||
</select> |
||||
<select id="getByIdStudentAndUser" resultType="com.teaching.backend.model.entity.umsAdmin.UmsStudentManage" |
||||
parameterType="java.lang.Long"> |
||||
select * |
||||
from ums_student us |
||||
INNER JOIN ums_user uu ON us.user_id = uu.id |
||||
WHERE us.id = #{id} |
||||
</select> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue