chengpeng vor 5 Jahren
Ursprung
Commit
961a19d30b

+ 56 - 0
mec-education/src/main/java/com/ym/mec/education/controller/TeacherController.java

@@ -0,0 +1,56 @@
+package com.ym.mec.education.controller;
+
+import com.ym.mec.education.base.BaseResponse;
+import com.ym.mec.education.base.PageResponse;
+import com.ym.mec.education.req.HomeWorkReq;
+import com.ym.mec.education.req.TeacherReq;
+import com.ym.mec.education.service.ITeacherService;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import net.bytebuddy.asm.Advice;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author : chengp
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月29日 9:54
+ */
+
+@RestController
+@RequestMapping("api/teacher")
+@Api(tags = "老师列表")
+@Slf4j
+public class TeacherController {
+
+    @Autowired
+    private ITeacherService teacherService;
+
+    /**
+     * 服务降级处理
+     *
+     * @return
+     */
+    private BaseResponse defaultFallback() {
+        BaseResponse response = new BaseResponse();
+        response.setReturnCode(500);
+        response.setMessage("太拥挤了, 请稍后再试!");
+        return response;
+    }
+
+
+    /**
+     *
+     * @param req
+     * @return
+     */
+    @PostMapping(value = "/workList")
+    public PageResponse workList(@RequestBody TeacherReq req) {
+
+        return teacherService.teacherList(req);
+    }
+}

+ 17 - 0
mec-education/src/main/java/com/ym/mec/education/req/TeacherReq.java

@@ -0,0 +1,17 @@
+package com.ym.mec.education.req;
+
+import com.ym.mec.education.base.BaseQuery;
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月29日 10:02
+ */
+@Data
+@ToString
+public class TeacherReq extends BaseQuery {
+
+    private String name;
+}

+ 24 - 0
mec-education/src/main/java/com/ym/mec/education/resp/TeacherResp.java

@@ -0,0 +1,24 @@
+package com.ym.mec.education.resp;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.util.List;
+
+/**
+ * @version V1.0
+ * @Description: TODO
+ * @date Date : 2019年09月29日 13:45
+ */
+@Data
+@ToString
+public class TeacherResp {
+
+    private String userId;
+
+    private String name;
+
+    private List<String> subjectName;
+
+    private List<String> className;
+}

+ 3 - 0
mec-education/src/main/java/com/ym/mec/education/service/ITeacherService.java

@@ -1,7 +1,9 @@
 package com.ym.mec.education.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.ym.mec.education.base.PageResponse;
 import com.ym.mec.education.entity.Teacher;
+import com.ym.mec.education.req.TeacherReq;
 
 /**
  * <p>
@@ -13,4 +15,5 @@ import com.ym.mec.education.entity.Teacher;
  */
 public interface ITeacherService extends IService<Teacher> {
 
+    PageResponse teacherList(TeacherReq req);
 }

+ 64 - 0
mec-education/src/main/java/com/ym/mec/education/service/impl/TeacherServiceImpl.java

@@ -1,10 +1,28 @@
 package com.ym.mec.education.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ym.mec.education.base.PageResponse;
+import com.ym.mec.education.entity.Subject;
+import com.ym.mec.education.entity.SysUser;
 import com.ym.mec.education.entity.Teacher;
 import com.ym.mec.education.mapper.TeacherMapper;
+import com.ym.mec.education.req.TeacherReq;
+import com.ym.mec.education.resp.TeacherResp;
+import com.ym.mec.education.service.ISubjectService;
+import com.ym.mec.education.service.ISysUserService;
 import com.ym.mec.education.service.ITeacherService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -17,4 +35,50 @@ import org.springframework.stereotype.Service;
 @Service("ITeacherService")
 public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {
 
+    @Autowired
+    private ISysUserService sysUserService;
+
+    @Autowired
+    private ISubjectService subjectService;
+
+    @Override
+    public PageResponse teacherList(TeacherReq req) {
+        PageResponse response = new PageResponse();
+        QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
+        List<SysUser> userList = null;
+        if(req != null && StringUtils.isEmpty(req.getName())){
+            userQueryWrapper.like("real_name_",req.getName());
+            userList = sysUserService.list(userQueryWrapper);
+        }
+        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
+        List<Integer> userIds = null;
+        if(!CollectionUtils.isEmpty(userList)){
+            userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList());
+            queryWrapper.in("id_",userIds);
+        }
+
+
+        IPage<Teacher> page = new Page(req.getPageNo() == null ? 1 : req.getPageNo(),req.getPageSize() == null ? 10 : req.getPageSize());
+        IPage<Teacher> teacherIPage = this.page(page,queryWrapper);
+
+        List<Teacher> teacherList = teacherIPage.getRecords();
+        List<TeacherResp> teacherRespList = new ArrayList<>();
+        if(!CollectionUtils.isEmpty(teacherList)){
+            teacherList.forEach(e ->{
+                TeacherResp teacherResp = new TeacherResp();
+                String ids[] = e.getSubjectId().split(",");
+                List<String> stringB = Arrays.asList(ids);
+                QueryWrapper<Subject> queryWrapperSub = new QueryWrapper<>();
+                queryWrapperSub.in("id_", stringB);
+                List<Subject> subjectList = subjectService.list(queryWrapperSub);
+                if (!CollectionUtils.isEmpty(subjectList)) {
+                    List<String> subName = subjectList.stream().map(Subject::getName).collect(Collectors.toList());
+                }
+
+            });
+
+        }
+
+        return null;
+    }
 }