| | |
| | | package com.mindskip.xzs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | import com.mindskip.xzs.domain.OnlineStudy; |
| | | import com.mindskip.xzs.domain.question.QuestionObject; |
| | | import com.mindskip.xzs.domain.vo.OnlineStudyVO; |
| | | import com.mindskip.xzs.domain.vo.StudentOnlineVO; |
| | | import com.mindskip.xzs.domain.vo.StudyTypeVO; |
| | | import com.mindskip.xzs.repository.OnlineStudyMapper; |
| | | import com.mindskip.xzs.repository.StudyTypeMapper; |
| | | import com.mindskip.xzs.service.OnlineStudyService; |
| | | 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:xp |
| | |
| | | public class OnlineStudySeerviceImpl implements OnlineStudyService { |
| | | |
| | | private final OnlineStudyMapper mapper; |
| | | private final StudyTypeMapper studyTypeMapper; |
| | | |
| | | @Override |
| | | public RestResponse add(OnlineStudyVO form) { |
| | | mapper.add(form); |
| | | OnlineStudy onlineStudy = new OnlineStudy(); |
| | | BeanUtils.copyProperties(form, onlineStudy); |
| | | onlineStudy.setContentUrl(JSON.toJSONString(form.getContentUrl())); |
| | | if (! CollectionUtils.isEmpty(form.getAttachment())) { |
| | | onlineStudy.setAttachment(JSON.toJSONString(form.getAttachment())); |
| | | } |
| | | onlineStudy.setCreateTime(new Date()); |
| | | onlineStudy.setUpdateTime(new Date()); |
| | | mapper.add(onlineStudy); |
| | | return RestResponse.ok("添加成功"); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse update(OnlineStudyVO form) { |
| | | mapper.update(form); |
| | | if (Objects.isNull(form.getId())) { |
| | | throw new RuntimeException("请选择要修改的数据"); |
| | | } |
| | | OnlineStudy onlineStudy = new OnlineStudy(); |
| | | BeanUtils.copyProperties(form, onlineStudy); |
| | | onlineStudy.setContentUrl(JSON.toJSONString(form.getContentUrl())); |
| | | if (! CollectionUtils.isEmpty(form.getAttachment())) { |
| | | onlineStudy.setAttachment(JSON.toJSONString(form.getAttachment())); |
| | | } else { |
| | | onlineStudy.setAttachment(""); |
| | | } |
| | | mapper.update(onlineStudy); |
| | | return RestResponse.ok("修改成功"); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public RestResponse page(OnlineStudyVO query) { |
| | | PageHelper.startPage(query.getPageNum(), query.getPageSize()); |
| | | List<OnlineStudyVO> data = mapper.page(query); |
| | | return RestResponse.ok(data); |
| | | PageInfo<OnlineStudyVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() -> |
| | | mapper.page(query)); |
| | | page.getList().stream().forEach(item -> { |
| | | item.setContentUrl(JSON.parseObject(item.getContentUrlString(), OnlineStudyVO.UploadFile.class)); |
| | | item.setAttachment(JSON.parseArray(item.getAttachmentString(), OnlineStudyVO.UploadFile.class)); |
| | | }); |
| | | return RestResponse.ok(page.getList()).put("total", page.getTotal()); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse byType(StudentOnlineVO query) { |
| | | PageInfo<OnlineStudyVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() -> |
| | | mapper.byType(query)); |
| | | page.getList().stream().forEach(item -> { |
| | | item.setContentUrl(JSON.parseObject(item.getContentUrlString(), OnlineStudyVO.UploadFile.class)); |
| | | item.setAttachment(JSON.parseArray(item.getAttachmentString(), OnlineStudyVO.UploadFile.class)); |
| | | }); |
| | | return RestResponse.ok(page.getList()).put("total", page.getTotal()); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse typeList() { |
| | | List<StudyTypeVO> list = studyTypeMapper.list(); |
| | | return RestResponse.ok(list); |
| | | } |
| | | } |