添加学生管理的添加学生和删除学生接口

master
mzh820631607 4 years ago
parent a3141cca39
commit 5585f78693
  1. 6
      src/main/java/com/yipin/liuwanr/controller/StudentController.java
  2. 139
      src/main/java/com/yipin/liuwanr/controller/UserInfoController.java
  3. 30
      src/main/java/com/yipin/liuwanr/entity/OrganizationRelationship.java
  4. 14
      src/main/java/com/yipin/liuwanr/helper/QueryStudentUtils.java
  5. 7
      src/main/java/com/yipin/liuwanr/mapper/OrganizationRelationshipMapper.java
  6. 30
      src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java
  7. 118
      src/main/java/com/yipin/liuwanr/service/UserInfoService.java
  8. 91
      src/test/java/com/yipin/liuwanr/service/StudentServiceTest.java

@ -135,7 +135,7 @@ public class StudentController {
resp.setErrmessage("学校id为空,查询失败!");
}else{
HashMap<String, Object> ret = studentService.queryStudentByProfessionalIds(professionalId, pageNo, pageSize, schoolId);
QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue");
QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue");
}
return resp;
}
@ -156,7 +156,7 @@ public class StudentController {
resp.setErrmessage("学校id为空,查询失败!");
}else {
HashMap<String, Object> ret = studentService.queryStudentByGradeIds(gradeId, pageNo, pageSize, schoolId);
QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue");
QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue");
}
return resp;
}
@ -177,7 +177,7 @@ public class StudentController {
resp.setErrmessage("学校id为空,查询失败!");
}else {
HashMap<String, Object> ret = studentService.queryStudentByClassIds(classId, pageNo, pageSize, schoolId);
QueryStudentUtils.queryStudentByIds(resp, ret, "retcode", "retvalue");
QueryStudentUtils.statusInformationEntity(resp, ret, "retcode", "retvalue");
}
return resp;
}

@ -1,11 +1,13 @@
package com.yipin.liuwanr.controller;
import com.yipin.liuwanr.entity.*;
import com.yipin.liuwanr.helper.QueryStudentUtils;
import com.yipin.liuwanr.helper.RedisHelper;
import com.yipin.liuwanr.service.StaffService;
import com.yipin.liuwanr.service.StudentService;
import com.yipin.liuwanr.service.UserInfoService;
import com.yipin.liuwanr.vo.UserInfoVO;
import jdk.nashorn.internal.ir.IfNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@ -13,6 +15,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -32,6 +35,129 @@ public class UserInfoController {
@Autowired
RedisHelper redisHelper;
/**
* 接收参数
* UserInfo:account,userName,roleId,uniqueIdentificationAccount,phone,email
* OrganizationRelationship:workNumber,professionalClassId,gradeId,classId
*/
@PostMapping("/addStudent")
Response addUserInfo(@RequestBody UserInfoVO vo) {
Response response = new Response();
// Student student = vo.getStudent();
UserInfo userInfo = vo.getUserInfo();
OrganizationRelationship organizationRelationship = vo.getOrganizationRelationship();
String account = userInfo.getAccount();
String userName = userInfo.getUserName();
Integer roleId = userInfo.getRoleId();
String uniqueIdentificationAccount = userInfo.getUniqueIdentificationAccount();
String phone = userInfo.getPhone();
String email = userInfo.getEmail();
String workNumber = organizationRelationship.getWorkNumber();
Integer professionalId = organizationRelationship.getProfessionalId();
Integer gradeId = organizationRelationship.getGradeId();
Integer classId = organizationRelationship.getClassId();
// UserM user = vo.getUser();
if (account==null||userName==null||roleId!=4||uniqueIdentificationAccount==null||workNumber==null||professionalId<=0||gradeId<=0||classId<=0) {
response.setStatus(300);
response.setErrmessage("Parameter Invalid");
} else {
HashMap<String, Object> ret = userInfoService.addUserInfo(userInfo);
int status = (int) ret.get("retcode");
if (200 == status) {
response.setStatus(status);
response.setMessage(ret.get("retvalue"));
HashMap<String, Object> ret1 = userInfoService.addOrganizationRelationship(organizationRelationship);
int status1 = (int)ret.get("retcode");
if (status1 == 200){
response.setStatus(status1);
response.setMessage(ret1.get("retvalue"));
}else {
response.setStatus(status1);
response.setErrmessage(ret1.get("retvalue").toString());
throw new RuntimeException();
}
} else {
response.setStatus(status);
response.setErrmessage(ret.get("retvalue").toString());
throw new RuntimeException();
}
}
return response;
}
/**
* 查询学生信息
* @param schoolId
* @param professionalIds
* @param searchContent
* @param gradeIds
* @param classIds
* @param pageNo
* @param pageSize
* @return
*/
@GetMapping("/queryStudent")
Response queryStudent(@RequestParam Integer schoolId, Integer[] professionalIds, String searchContent, Integer[] gradeIds, Integer[] classIds, Integer pageNo, Integer pageSize) {
Response response = new Response();
UserInfo userInfo = new UserInfo();
OrganizationRelationship ship = new OrganizationRelationship();
HashMap<Object, Object> ids = new HashMap<>(8);
if (schoolId == null) {
response.setStatus(300);
response.setErrmessage("学校信息为空");
} else {
if (searchContent != null && searchContent != "") {
userInfo.setSearchContent(searchContent);
}
if (professionalIds.length > 0) {
// List<Integer> professionalList = Arrays.asList(professionalId);
for (Integer professionalId:professionalIds){
ship.setProfessionalId(professionalId);
}
}
if (gradeIds.length > 0) {
// List<Integer> gradeList = Arrays.asList(gradeIds);
for (Integer gradeId:gradeIds){
ship.setGradeId(gradeId);
}
}
if (classIds.length > 0) {
// List<Integer> classList = Arrays.asList(classIds);
for (Integer classId:classIds){
ship.setClassId(classId);
}
}
userInfo.setSchoolId(schoolId);
// HashMap map = userInfoService.queryStudent(userInfo,ship,pageNo,pageSize);
// QueryStudentUtils.statusInformationController(response,map, "retcode", "retvalue");
}
return response;
}
/**
* 批量删除学生
*
* @param ids 用户id
* @return
*/
@GetMapping("/deleteStudent")
Response deleteStudent(Integer[] ids) {
Response response = new Response();
if (ids.length > 0) {
userInfoService.deleteStudent(ids);
response.setStatus(200);
} else {
response.setStatus(500);
response.setErrmessage("学生id不能为空");
}
return response;
}
/**
* 添加用户
*/
@ -140,7 +266,8 @@ public class UserInfoController {
}
//月份
if (month != null) {
userInfo.setMonth(month);;
userInfo.setMonth(month);
;
}
//创建时间
if (creationTime != null && creationTime != "") {
@ -319,8 +446,7 @@ public class UserInfoController {
} else if (roleId == null) {
resp.setStatus(300);
resp.setErrmessage("用户角色id为空,登录失败!");
}
else{
} else {
userInfo.setRoleId(roleId);
userInfo.setUserId(userId);
userInfo.setSchoolId(schoolId);
@ -490,6 +616,7 @@ public class UserInfoController {
}
return resp;
}
/**
* 用户模块查询客户
*/
@ -543,8 +670,7 @@ public class UserInfoController {
} else if (roleId == null) {
resp.setStatus(300);
resp.setErrmessage("角色id为空!");
}
else {
} else {
HashMap<String, Object> ret = userInfoService.queryWorkNumberIsExist(workNumber, roleId, schoolId);
int status = (int) ret.get("retcode");
if (200 == status) {
@ -598,8 +724,7 @@ public class UserInfoController {
} else if (userId == null) {
resp.setStatus(300);
resp.setErrmessage("用户id为空!");
}
else{
} else {
HashMap<String, Object> ret = userInfoService.deletePlatform(platformId, userId);
int status = (int) ret.get("retcode");
if (200 == status) {

@ -33,6 +33,10 @@ public class OrganizationRelationship {
private String professionalName;
//年级ID
private Integer gradeId;
private String professionalIds;
private String gradeIds;
private String classIds;
//年级名称
private String gradeName;
//班级ID
@ -42,6 +46,32 @@ public class OrganizationRelationship {
//客户ID
private Integer customerId;
public String getProfessionalIds() {
return professionalIds;
}
public void setProfessionalIds(String professionalIds) {
this.professionalIds = professionalIds;
}
public String getGradeIds() {
return gradeIds;
}
public void setGradeIds(String gradeIds) {
this.gradeIds = gradeIds;
}
public String getClassIds() {
return classIds;
}
public void setClassIds(String classIds) {
this.classIds = classIds;
}
public String getOneDepartmentIds() {
return oneDepartmentIds;
}

@ -13,7 +13,8 @@ public class QueryStudentUtils {
* @param retcode
* @param retvalue
*/
public static void queryStudentByIds(Response resp,HashMap<String, Object> hashMap,String retcode,String retvalue){
//com.yipin.liuwanr.entity.Response
public static void statusInformationEntity(Response resp,HashMap<String, Object> hashMap,String retcode,String retvalue){
int status = (int)hashMap.get(retcode);
if (status==200){
@ -23,6 +24,17 @@ public class QueryStudentUtils {
resp.setStatus(status);
resp.setMessage(hashMap.get(retvalue.toString()));
}
}
//com.yipin.liuwanr.controller.Response
public static void statusInformationController(com.yipin.liuwanr.controller.Response resp, HashMap<String, Object> hashMap, String retcode, String retvalue){
int status = (int)hashMap.get(retcode);
if (status==200){
resp.setStatus(status);
resp.setMessage(hashMap.get(retvalue));
}else{
resp.setStatus(status);
resp.setMessage(hashMap.get(retvalue.toString()));
}
}
}

@ -3,6 +3,7 @@ package com.yipin.liuwanr.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yipin.liuwanr.entity.OrganizationRelationship;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@ -11,6 +12,12 @@ import java.util.List;
@Mapper
public interface OrganizationRelationshipMapper{
@Insert({"<script>" +
"INSERT INTO hr_organization_relationship(roleId,workNumber,professionalId,gradeId,classId,isdel)",
"VALUES(#{roleId},#{workNumber},#{professionalId},#{gradeId},#{classId},0)",
"</script>"})
Integer insertOrganizationRelationship(OrganizationRelationship organizationRelationship);
@Select("select organizationRelationshipId,schoolName,professionalName,gradeName,className,workNumber,roleId " +
"from hr_organization_relationship where userId=#{userId} ")
List<OrganizationRelationship> getByuserId(Integer userId);

@ -1,5 +1,6 @@
package com.yipin.liuwanr.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yipin.liuwanr.entity.*;
import com.yipin.liuwanr.vo.UserInfoVO;
import com.yipin.liuwanr.vo.UserVO;
@ -10,6 +11,35 @@ import java.util.List;
public interface UserInfoMapper{
@Insert("INSERT INTO hr_user_info(userName,uniqueIdentificationAccount,documentType,IDNumber,provinceId,cityId,countries,dateBirth,educationDegree,schoolId,phone,weChatID,email,account,password,creationTime,logInNumber,sex,userAvatars,isdel)"
+ " VALUES(#{userName},#{uniqueIdentificationAccount},#{documentType},#{IDNumber},#{provinceId},#{cityId},#{countries},#{dateBirth},#{educationDegree},#{schoolId},#{phone},#{weChatID},#{email},#{account},#{password},now(),#{logInNumber},#{sex},#{userAvatars},0)")
Integer insertUserInfo(UserInfo userInfo);
/**
* 批量查询学生信息
* @param
* @return
*/
@Select({ "<script>" ,
"SELECT u.logInNumber,u.userName,u.lastLoginTime,o.roleId, o.gradeId, o.classId, o.professionalId FROM hr_user_info u,hr_organization_relationship o WHERE o.roleId = 4 AND u.schoolId = #{schoolId} AND u.isdel = 0",
"<if test='searchContent!=null'>AND (u.userName like CONCAT('%',#{searchContent},'%') or u.userId like CONCAT('%',#{searchContent},'%'))</if>",
// "<if test='professionalIds.size()>0'> OR o.professionalId IN <foreach collection='professionalIds' item='professionalId' open='(' separator=',' close=')'>#{professionalId}</foreach></if>" ,
// "<if test='gradeIds.size()>0'>OR o.gradeId IN <foreach collection='gradeIds' item='gradeId' open='(' separator=',' close=')'>#{gradeId}</foreach></if>" ,
// "<if test='classIds.size()>0'>OR o.classId IN <foreach collection='classIds' item='classId' open='(' separator=',' close=')'>#{classId}</foreach></if>" ,
"<if test='professionalId>0'> OR o.professionalId = #{professionalId}</if>" ,
"<if test='gradeId>0'>OR o.gradeId = #{gradeId}</if>" ,
"<if test='classId>0'>OR o.classId = #{classId}</if>" ,
"ORDER BY o.professionalId desc,o.gradeId desc,o.classId desc",
"</script>"})
// List queryStudent(UserInfo userInfo,OrganizationRelationship organizationRelationship);
List queryStudent(String searchContent,Integer schoolId,Integer gradeId,Integer classId,Integer professionalId);
@Update({"<script>" +
"UPDATE hr_user_info SET isdel=1 WHERE userId IN " +
"<foreach collection='list' item='userId' index='index' separator=',' open='(' close=')'>#{userId}</foreach>" +
"</script>"})
Integer updateStudentInfo(List list);
@Update({ "<script>",
"UPDATE lw_user SET",
"<when test='mobile!=null'>", "mobile=#{mobile},", "</when>",

@ -1,12 +1,14 @@
package com.yipin.liuwanr.service;
import com.aliyun.oss.OSSClient;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yipin.liuwanr.AliyunOssConfig;
import com.yipin.liuwanr.entity.*;
import com.yipin.liuwanr.helper.OssConfigUtil;
import com.yipin.liuwanr.helper.RandomUtil;
import com.yipin.liuwanr.mapper.OrganizationRelationshipMapper;
import com.yipin.liuwanr.mapper.StaffMapper;
import com.yipin.liuwanr.mapper.StudentMapper;
import com.yipin.liuwanr.mapper.UserInfoMapper;
@ -19,6 +21,7 @@ import org.springframework.web.multipart.MultipartFile;
import redis.clients.jedis.JedisCluster;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -28,6 +31,9 @@ import java.util.List;
public class UserInfoService {
private static Logger logger = Logger.getLogger(UserInfoService.class);
private final static String RETCODE = "retcode";
private final static String RETVALUE = "retvalue";
@Autowired
private StaffMapper staffMapper;
@ -41,6 +47,118 @@ public class UserInfoService {
private AliyunOssConfig config;
@Autowired
private BeanFactory beanFactory;
@Autowired
private OrganizationRelationshipMapper organizationRelationshipMapper;
/**
* 批量删除学生信息
*/
@Transactional
public HashMap<String,Object> deleteStudent(Integer[] ids){
HashMap<String, Object> resp = new HashMap<String, Object>();
// UpdateWrapper<UserInfo> updateWrapper = new UpdateWrapper<UserInfo>();
// UserInfo userInfo = new UserInfo();
// for (Integer id:ids){
// userInfo.setUserId(id);
// }
// //修改学生状态信息码为1
// updateWrapper.eq("isdel",1);
// int update = userInfoMapper.update(userInfo, updateWrapper);
ArrayList<Object> list = new ArrayList<>();
for (Integer id : ids){
list.add(id);
}
int update = userInfoMapper.updateStudentInfo(list);
if (update>0){
resp.put(RETCODE,200);
}else{
resp.put(RETCODE,500);
resp.put(RETVALUE,"student/delete Invalid");
}
return resp;
}
/**
* 添加学生信息
*/
public HashMap<String,Object> addUserInfo(UserInfo userInfo){
HashMap<String, Object> resp = new HashMap<>();
try {
userInfo.setPassword("hanran999");
int insert = userInfoMapper.insertUserInfo(userInfo);
if (insert>0){
resp.put(RETCODE,200);
}else{
resp.put(RETCODE,400);
resp.put(RETVALUE,"student/insert Invalid");
}
}catch (RuntimeException e){
logger.error(e);
resp.put(RETCODE,500);
resp.put(RETVALUE,"student/insert Invalid");
}
return resp;
}
public HashMap<String,Object> addOrganizationRelationship(OrganizationRelationship ship){
HashMap<String, Object> resp = new HashMap<>();
try {
// userInfoMapper.insert(userInfo);
// int insert = organizationRelationshipMapper.insert(ship);
int insert = organizationRelationshipMapper.insertOrganizationRelationship(ship);
if (insert>0){
resp.put(RETCODE,200);
}else{
resp.put(RETCODE,400);
resp.put(RETVALUE,"student/insert Invalid");
}
}catch (RuntimeException e){
resp.put(RETCODE,500);
resp.put(RETVALUE,"student/insert Invalid");
}
return resp;
}
/**
* 批量查询学生信息
*/
@Transactional
public HashMap<String,Object> queryStudent(UserInfo userInfo,OrganizationRelationship ship,Integer pageNo,Integer pageSize){
HashMap<String, Object> resp = new HashMap<String, Object>();
// UserInfo user = new UserInfo();
// OrganizationRelationship organizationRelationship = new OrganizationRelationship();
String searchContent = userInfo.getSearchContent();
Integer schoolId = userInfo.getSchoolId();
Integer gradeId = ship.getGradeId();
Integer classId = ship.getClassId();
Integer professionalId = ship.getProfessionalId();
try {
if(pageNo!=null&&pageSize!=null) {
PageHelper.startPage(pageNo, pageSize);
List list = userInfoMapper.queryStudent(searchContent, schoolId, gradeId, classId, professionalId);
PageInfo info=new PageInfo(list);
int total1 = (int) info.getTotal();
int totalPages;
totalPages = total1 / pageSize;
if (total1 % pageSize != 0){
totalPages ++;
}
long total = total1;
resp.put("retvalue", new PageResult(total, list,totalPages));
resp.put("retcode", 200);
}else {
List<UserInfo> list = userInfoMapper.queryStudent(searchContent,schoolId,gradeId,classId,professionalId);
resp.put("retvalue", list);
resp.put("retcode", 200);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "查询用户失败!");
return resp;
}
return resp;
}
public HashMap<String, Object> login(String id, String password){
HashMap<String, Object> resp = new HashMap<String, Object>();

@ -0,0 +1,91 @@
package com.yipin.liuwanr.service;
import com.yipin.liuwanr.entity.OrganizationRelationship;
import com.yipin.liuwanr.entity.UserInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
@SpringBootTest
@RunWith(SpringRunner.class)
public class StudentServiceTest {
@Autowired
private UserInfoService userInfoService;
/**
* 新增学生
*/
@Test
public void addStudent(){
UserInfo userInfo = new UserInfo();
OrganizationRelationship ship = new OrganizationRelationship();
userInfo.setAccount("");
userInfo.setUniqueIdentificationAccount("huoran999");
userInfo.setSchoolId(1);
userInfo.setUserName("michonne");
userInfo.setRoleId(4);
userInfo.setPassword("123456");
ship.setProfessionalId(1);
ship.setGradeId(1);
ship.setClassId(1);
ship.setWorkNumber("888");
HashMap<String, Object> map = userInfoService.addUserInfo(userInfo);
userInfoService.addOrganizationRelationship(ship);
for (String s : map.keySet()) {
System.out.println("key:" + s + "," + "value:" + map.get(s));
}
HashMap<String, Object> map1 = userInfoService.addOrganizationRelationship(ship);
for (String ss : map1.keySet()) {
System.out.println("key:" + ss + "," + "value:" + map.get(ss));
}
}
/**
* 查询学生信息
*/
@Test
public void queryStudent(){
UserInfo userInfo = new UserInfo();
OrganizationRelationship organizationRelationship = new OrganizationRelationship();
userInfo.setSchoolId(1);
userInfo.setSearchContent("1");
Integer[] a = {1,2};
Integer[] b = {1,2};
Integer[] c = {1,2};
for (Integer aa: a){
organizationRelationship.setProfessionalId(aa);
}
for (Integer bb:b){
organizationRelationship.setGradeId(bb);
}
for (Integer cc:c){
organizationRelationship.setClassId(cc);
}
Integer pageNo = 1;
Integer pageSize = 3;
HashMap<String, Object> map = userInfoService.queryStudent(userInfo, organizationRelationship, pageNo, pageSize);
for (String s : map.keySet()) {
System.out.println("key:" + s + "," + "value:" + map.get(s));
}
}
/**
* 测试删除学生信息
*/
@Test
public void deleteStudent(){
Integer[] userInfo = new Integer[]{13,14,15};
HashMap<String, Object> map = userInfoService.deleteStudent(userInfo);
for (String s : map.keySet()) {
System.out.println("key:" + s + "," + "value:" + map.get(s));
}
}
}
Loading…
Cancel
Save