|  | @@ -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.StudentCourseHomework;
 | 
	
		
			
				|  |  | +import com.ym.mec.education.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.ym.mec.education.enums.ReturnCodeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.education.mapper.StudentCourseHomeworkMapper;
 | 
	
		
			
				|  |  | +import com.ym.mec.education.req.HomeWorkReq;
 | 
	
		
			
				|  |  | +import com.ym.mec.education.resp.HomeWrokResp;
 | 
	
		
			
				|  |  |  import com.ym.mec.education.service.IStudentCourseHomeworkService;
 | 
	
		
			
				|  |  | -import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.ym.mec.education.service.ISysUserService;
 | 
	
		
			
				|  |  | +import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  | +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.List;
 | 
	
		
			
				|  |  | +import java.util.Optional;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * <p>
 | 
	
	
		
			
				|  | @@ -17,4 +35,56 @@ import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  @Service("IStudentCourseHomeworkService")
 | 
	
		
			
				|  |  |  public class StudentCourseHomeworkServiceImpl extends ServiceImpl<StudentCourseHomeworkMapper, StudentCourseHomework> implements IStudentCourseHomeworkService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ISysUserService sysUserService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public PageResponse workList(HomeWorkReq 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);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<Integer> userIds = null;
 | 
	
		
			
				|  |  | +        if(!CollectionUtils.isEmpty(userList)){
 | 
	
		
			
				|  |  | +            userIds = userList.stream().map(SysUser::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        IPage ipage = new Page(req.getPageNo() == null ? 1: req.getPageNo(),req.getPageSize() == null ? 10:req.getPageSize());
 | 
	
		
			
				|  |  | +        QueryWrapper<StudentCourseHomework> queryWrapper = new QueryWrapper<>();
 | 
	
		
			
				|  |  | +        if(userIds != null && !userIds.isEmpty()){
 | 
	
		
			
				|  |  | +            queryWrapper.in("user_id_",userIds);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        IPage<StudentCourseHomework> homeworkIPage =  this.page(ipage,queryWrapper);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<StudentCourseHomework> courseHomeworkList = homeworkIPage.getRecords();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<HomeWrokResp> homeWrokRespList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        if(!CollectionUtils.isEmpty(courseHomeworkList)){
 | 
	
		
			
				|  |  | +            List<SysUser> finalUserList = userList;
 | 
	
		
			
				|  |  | +            courseHomeworkList.forEach(e ->{
 | 
	
		
			
				|  |  | +                HomeWrokResp homeWrokResp = new HomeWrokResp();
 | 
	
		
			
				|  |  | +                BeanUtils.copyProperties(e,homeWrokResp);
 | 
	
		
			
				|  |  | +                Optional<SysUser> optional = finalUserList.stream().filter(u -> u.getId().equals(e.getUserId())).findFirst();
 | 
	
		
			
				|  |  | +                if(optional.isPresent()){
 | 
	
		
			
				|  |  | +                    homeWrokResp.setAvatar(optional.get().getAvatar());
 | 
	
		
			
				|  |  | +                    homeWrokResp.setName(optional.get().getRealName());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                homeWrokRespList.add(homeWrokResp);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        response.setReturnCode(ReturnCodeEnum.CODE_200.getCode());
 | 
	
		
			
				|  |  | +        response.setMessage(ReturnCodeEnum.CODE_200.getValue());
 | 
	
		
			
				|  |  | +        response.setRecords(homeWrokRespList);
 | 
	
		
			
				|  |  | +        response.setTotal(Math.toIntExact(homeworkIPage.getTotal()));
 | 
	
		
			
				|  |  | +        return response;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |