package com.ycl.jxkg.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.ycl.jxkg.base.Result;
|
import com.ycl.jxkg.domain.entity.EducationResource;
|
import com.ycl.jxkg.domain.entity.Subject;
|
import com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO;
|
import com.ycl.jxkg.domain.vo.student.education.StudentOnlineVO;
|
import com.ycl.jxkg.mapper.EducationResourceMapper;
|
import com.ycl.jxkg.mapper.SubjectMapper;
|
import com.ycl.jxkg.service.EducationResourceService;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* @author:flq
|
* @date:2024/6/18 10:53
|
*/
|
@Service
|
@RequiredArgsConstructor
|
public class EducationResourceServiceImpl implements EducationResourceService {
|
|
private final EducationResourceMapper mapper;
|
private final SubjectMapper subjectMapper;
|
|
@Override
|
public Result add(EducationResourceVO form) {
|
EducationResource educationResource = new EducationResource();
|
BeanUtils.copyProperties(form, educationResource);
|
educationResource.setContentUrl(JSON.toJSONString(form.getContentUrl()));
|
if (!CollectionUtils.isEmpty(form.getAttachment())) {
|
educationResource.setAttachment(JSON.toJSONString(form.getAttachment()));
|
}
|
educationResource.setCreateTime(new Date());
|
educationResource.setUpdateTime(new Date());
|
mapper.add(educationResource);
|
return Result.ok("添加成功");
|
}
|
|
@Override
|
public Result update(EducationResourceVO form) {
|
if (Objects.isNull(form.getId())) {
|
throw new RuntimeException("请选择要修改的数据");
|
}
|
EducationResource educationResource = new EducationResource();
|
BeanUtils.copyProperties(form, educationResource);
|
educationResource.setContentUrl(JSON.toJSONString(form.getContentUrl()));
|
if (!CollectionUtils.isEmpty(form.getAttachment())) {
|
educationResource.setAttachment(JSON.toJSONString(form.getAttachment()));
|
} else {
|
educationResource.setAttachment("");
|
}
|
mapper.update(educationResource);
|
return Result.ok("修改成功");
|
}
|
|
@Override
|
public Result remove(List<Integer> ids) {
|
mapper.remove(ids);
|
return Result.ok("删除成功");
|
}
|
|
@Override
|
public Result page(EducationResourceVO query) {
|
PageInfo<EducationResourceVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() ->
|
mapper.page(query));
|
page.getList().stream().forEach(item -> {
|
item.setContentUrl(JSON.parseObject(item.getContentUrlString(), EducationResourceVO.UploadFile.class));
|
item.setAttachment(JSON.parseArray(item.getAttachmentString(), EducationResourceVO.UploadFile.class));
|
});
|
return Result.ok(page.getList()).put("total", page.getTotal());
|
}
|
|
@Override
|
public Result byType(StudentOnlineVO query) {
|
PageInfo<EducationResourceVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() ->
|
mapper.byType(query));
|
page.getList().stream().forEach(item -> {
|
item.setContentUrl(JSON.parseObject(item.getContentUrlString(), EducationResourceVO.UploadFile.class));
|
item.setAttachment(JSON.parseArray(item.getAttachmentString(), EducationResourceVO.UploadFile.class));
|
});
|
return Result.ok(page.getList()).put("total", page.getTotal());
|
}
|
|
@Override
|
public Result typeList() {
|
List<Subject> subjects = subjectMapper.allSubject();
|
return Result.ok(subjects);
|
}
|
}
|