xiatian 2 năm trước cách đây
mục cha
commit
4342241932

+ 19 - 0
src/main/java/cn/com/qmth/mps/bean/CourseInfo.java

@@ -0,0 +1,19 @@
+package cn.com.qmth.mps.bean;
+
+public class CourseInfo {
+	private String code;
+	private String name;
+	public String getCode() {
+		return code;
+	}
+	public void setCode(String code) {
+		this.code = code;
+	}
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+}

+ 7 - 1
src/main/java/cn/com/qmth/mps/controller/UserController.java

@@ -63,11 +63,17 @@ public class UserController extends BaseController {
 		return userService.page(query,getAccessUser());
 	}
 
-	@ApiOperation(value = "获取信息")
+	@ApiOperation(value = "获取指定用户信息")
 	@RequestMapping(value = "info", method = RequestMethod.POST)
 	public UserVo info(@RequestParam Long id) {
 		return userService.info(id);
 	}
+	
+	@ApiOperation(value = "获取当前用户信息")
+	@RequestMapping(value = "my/info", method = RequestMethod.POST)
+	public UserVo myInfo() {
+		return userService.myInfo(getAccessUser());
+	}
 
 	@ApiOperation(value = "启用/禁用")
 	@RequestMapping(value = "toggle", method = RequestMethod.POST)

+ 2 - 1
src/main/java/cn/com/qmth/mps/dao/UserCourseRelationDao.java

@@ -6,10 +6,11 @@ import org.apache.ibatis.annotations.Param;
 
 import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
 
+import cn.com.qmth.mps.bean.CourseInfo;
 import cn.com.qmth.mps.entity.UserCourseRelationEntity;
 
 public interface UserCourseRelationDao extends MppBaseMapper<UserCourseRelationEntity> {
 
-	List<String> getCourseCodes(@Param("userId")Long userId);
+	List<CourseInfo> getCourses(@Param("userId")Long userId);
 
 }

+ 2 - 1
src/main/java/cn/com/qmth/mps/service/UserCourseRelationService.java

@@ -4,6 +4,7 @@ import java.util.List;
 
 import com.github.jeffreyning.mybatisplus.service.IMppService;
 
+import cn.com.qmth.mps.bean.CourseInfo;
 import cn.com.qmth.mps.entity.UserCourseRelationEntity;
 
 public interface UserCourseRelationService  extends IMppService<UserCourseRelationEntity> {
@@ -12,6 +13,6 @@ public interface UserCourseRelationService  extends IMppService<UserCourseRelati
 
 	void removeCourse(Long id);
 
-	List<String> getCourseCodes(Long id);
+	List<CourseInfo> getCourses(Long userId);
 
 }

+ 2 - 0
src/main/java/cn/com/qmth/mps/service/UserService.java

@@ -31,5 +31,7 @@ public interface UserService  extends IService<UserEntity> {
 
 	void resetPass(Long userId, String passwd, User accessUser);
 
+	UserVo myInfo(User accessUser);
+
 
 }

+ 3 - 2
src/main/java/cn/com/qmth/mps/service/impl/UserCourseRelationServiceImpl.java

@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
 import com.qmth.boot.core.exception.StatusException;
 
+import cn.com.qmth.mps.bean.CourseInfo;
 import cn.com.qmth.mps.dao.UserCourseRelationDao;
 import cn.com.qmth.mps.entity.CourseEntity;
 import cn.com.qmth.mps.entity.UserCourseRelationEntity;
@@ -52,8 +53,8 @@ public class UserCourseRelationServiceImpl extends
 	}
 
 	@Override
-	public List<String> getCourseCodes(Long userId) {
-		return this.baseMapper.getCourseCodes(userId);
+	public List<CourseInfo> getCourses(Long userId) {
+		return this.baseMapper.getCourses(userId);
 	}
 
 

+ 29 - 1
src/main/java/cn/com/qmth/mps/service/impl/UserServiceImpl.java

@@ -7,6 +7,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -30,6 +31,7 @@ import com.qmth.boot.tools.excel.ExcelReader;
 import com.qmth.boot.tools.excel.enums.ExcelType;
 import com.qmth.boot.tools.excel.model.DataMap;
 
+import cn.com.qmth.mps.bean.CourseInfo;
 import cn.com.qmth.mps.bean.User;
 import cn.com.qmth.mps.dao.UserDao;
 import cn.com.qmth.mps.entity.UserEntity;
@@ -256,7 +258,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 		vo.setSchoolId(ue.getSchoolId());
 		vo.setSchoolName(schoolService.getById(ue.getSchoolId()).getName());
 		if (vo.getRoleId().equals(Role.SECTION_LEADER.getId())) {
-			vo.setCourseCodes(userCourseRelationService.getCourseCodes(vo.getId()));
+			List<CourseInfo> cs=userCourseRelationService.getCourses(vo.getId());
+			vo.setCourseCodes(cs.stream().map(m->m.getCode()).collect(Collectors.toList()));
 		}
 		return vo;
 	}
@@ -309,4 +312,29 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 		lw.eq(UserEntity::getId, userId);
 		this.update(wrapper);
 	}
+
+	@Override
+	public UserVo myInfo(User user) {
+		UserEntity ue = this.getById(user.getId());
+		if (ue == null) {
+			throw new StatusException("未找到用户信息");
+		}
+		UserVo vo = new UserVo();
+		vo.setEnable(ue.getEnable());
+		vo.setId(ue.getId());
+		vo.setRoleId(ue.getRoleId());
+		vo.setLoginName(ue.getLoginName());
+		vo.setName(ue.getName());
+		vo.setSchoolId(ue.getSchoolId());
+		vo.setSchoolName(schoolService.getById(ue.getSchoolId()).getName());
+		if (vo.getRoleId().equals(Role.SECTION_LEADER.getId())) {
+			List<CourseInfo> cs=userCourseRelationService.getCourses(vo.getId());
+			if(CollectionUtils.isNotEmpty(cs)) {
+				vo.setCourseCodes(cs.stream().map(m->m.getCode()).collect(Collectors.toList()));
+				vo.setCourseNames(cs.stream().map(m->m.getCode()+"-"+m.getName()).collect(Collectors.toList()));
+			}
+		}
+		return vo;
+	}
+	
 }

+ 8 - 0
src/main/java/cn/com/qmth/mps/vo/user/UserVo.java

@@ -26,6 +26,8 @@ public class UserVo extends BaseEntity{
 	private Long roleId;
 	@ApiModelProperty("科目代码集合")
 	private List<String> courseCodes;
+	@ApiModelProperty("科目名称集合")
+	private List<String> courseNames;
 	public Long getId() {
 		return id;
 	}
@@ -74,5 +76,11 @@ public class UserVo extends BaseEntity{
 	public void setCourseCodes(List<String> courseCodes) {
 		this.courseCodes = courseCodes;
 	}
+	public List<String> getCourseNames() {
+		return courseNames;
+	}
+	public void setCourseNames(List<String> courseNames) {
+		this.courseNames = courseNames;
+	}
 	
 }

+ 2 - 2
src/main/resources/mapper/UserCourseRelationMapper.xml

@@ -2,8 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.qmth.mps.dao.UserCourseRelationDao">
 
-	<select id="getCourseCodes" resultType="string">
-		select s.code from mps_user_course_relation
+	<select id="getCourses" resultType="cn.com.qmth.mps.bean.CourseInfo">
+		select s.name,s.code from mps_user_course_relation
 		t
 		left join
 		mps_course s on