From 8f2b25bdc4ec1c803704d8ca37690462bb1106ea Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 16 五月 2024 16:49:56 +0800 Subject: [PATCH] 学习文件管理端 --- src/main/java/com/mindskip/xzs/service/impl/OnlineStudySeerviceImpl.java | 43 +++++++++++++++++++++++++++++++++++++++---- 1 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/service/impl/OnlineStudySeerviceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/OnlineStudySeerviceImpl.java index 3af5f30..b62c392 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/OnlineStudySeerviceImpl.java +++ b/src/main/java/com/mindskip/xzs/service/impl/OnlineStudySeerviceImpl.java @@ -1,14 +1,25 @@ 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.repository.OnlineStudyMapper; import com.mindskip.xzs.service.OnlineStudyService; +import com.mindskip.xzs.utility.JsonUtil; +import jdk.nashorn.internal.ir.IfNode; 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; +import java.util.stream.Collectors; /** * @author锛歺p @@ -22,13 +33,32 @@ @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("淇敼鎴愬姛"); } @@ -41,7 +71,12 @@ @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()); } } -- Gitblit v1.8.0