src/main/java/com/mindskip/xzs/base/RestResponse.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/configuration/spring/mvc/WebMvcConfiguration.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/controller/common/UploadController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/domain/OnlineStudy.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/domain/vo/OnlineStudyVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/repository/OnlineStudyMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/service/impl/OnlineStudySeerviceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mindskip/xzs/utility/Constants.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/OnlineStudyMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/StudyTypeMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/mindskip/xzs/base/RestResponse.java
@@ -97,4 +97,10 @@ public RestResponse() { } @Override public RestResponse put(String key, Object value) { super.put(key, value); return this; } } src/main/java/com/mindskip/xzs/configuration/spring/mvc/WebMvcConfiguration.java
@@ -6,7 +6,11 @@ import com.mindskip.xzs.utility.Constants; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.*; import java.io.File; @@ -57,14 +61,27 @@ super.addInterceptors(registry); } @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowCredentials(true) .allowedMethods("*") .allowedOrigins("*") .allowedHeaders("*"); super.addCorsMappings(registry); /** * 跨域配置 */ @Bean public CorsFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); // 设置访问源地址 config.addAllowedOrigin("*"); // 设置访问源请求头 config.addAllowedHeader("*"); // 设置访问源请求方法 config.addAllowedMethod("*"); // 有效期 1800秒 config.setMaxAge(1800L); // 添加映射路径,拦截一切请求 UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); // 返回新的CorsFilter return new CorsFilter(source); } } src/main/java/com/mindskip/xzs/controller/common/UploadController.java
@@ -11,6 +11,8 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.UUID; /** * @author:xp @@ -36,8 +38,8 @@ } try { // 获取文件名 String fileName = StringUtils.cleanPath(file.getOriginalFilename()); String originalFileName = StringUtils.cleanPath(file.getOriginalFilename()); String randomName = UUID.randomUUID().toString().replace("-", "") + originalFileName.substring(originalFileName.lastIndexOf(".")); // 指定文件存储路径 String uploadDir = ruoYiConfig.getUrl(); // 修改为您希望存储的目录 // 如果目录不存在,则创建目录 @@ -46,11 +48,14 @@ dir.mkdirs(); } // 构建目标文件的路径 String filePath = uploadDir + "/" + fileName; String filePath = uploadDir + "/" + randomName; // 将文件保存到目标位置 file.transferTo(new File(filePath)); // 返回成功响应 return RestResponse.ok("文件上传成功"); HashMap hashMap = new HashMap(2); hashMap.put("name", originalFileName); hashMap.put("url", randomName); return RestResponse.ok(hashMap); } catch (IOException e) { e.printStackTrace(); // 返回失败响应 src/main/java/com/mindskip/xzs/domain/OnlineStudy.java
@@ -22,7 +22,7 @@ private String contentUrl; /** 所属分类 */ private String belongType; private Integer belongType; /** 主题 */ private String subject; src/main/java/com/mindskip/xzs/domain/vo/OnlineStudyVO.java
@@ -3,7 +3,9 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.Date; import java.util.List; /** * @author:xp @@ -23,19 +25,36 @@ private String contentType; /** 文件地址 */ @NotBlank(message = "请上传文件") private String contentUrl; @NotNull(message = "请上传文件") private UploadFile contentUrl; private String contentUrlString; /** 所属分类 */ @NotBlank(message = "请选择分类") private String belongType; @NotNull(message = "请选择分类") private Integer belongType; private String typeName; /** 主题 */ @NotBlank(message = "请输入主题") private String subject; /** 附件 */ private List<UploadFile> attachment; private String attachmentString; private Date createTime; private Date updateTime; @Data public static class UploadFile { /** 地址 */ private String url; /** 文件原始名 */ private String name; } } src/main/java/com/mindskip/xzs/repository/OnlineStudyMapper.java
@@ -14,9 +14,9 @@ @Mapper public interface OnlineStudyMapper { void add(@Param("form") OnlineStudyVO form); void add(@Param("form") OnlineStudy form); void update(@Param("form") OnlineStudyVO form); void update(@Param("form") OnlineStudy form); void remove(@Param("ids") List<Integer> ids); 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:xp @@ -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()); } } src/main/java/com/mindskip/xzs/utility/Constants.java
@@ -132,7 +132,7 @@ /** * 资源映射路径 前缀 */ public static final String RESOURCE_PREFIX = "/files"; public static final String RESOURCE_PREFIX = "/api/files"; /** * RMI 远程方法调用 src/main/resources/mapper/OnlineStudyMapper.xml
@@ -6,13 +6,25 @@ <select id="page" resultType="com.mindskip.xzs.domain.vo.OnlineStudyVO"> SELECT id,content_type, content_url, belong_type, subject, create_time, update_time, attachment tos.id, tos.content_type, tos.content_url as contentUrlString, tos.belong_type, tos.subject, tos.create_time, tos.update_time, tos.attachment as attachmentString, tst.type_name FROM t_online_study t_online_study tos INNER JOIN t_study_type tst ON tst.id = tos.belong_type <where> AND deleted = 0 AND tos.deleted = 0 <if test="query.subject != null and query.subject != ''"> AND subject like concat('%', #{query.subject}, '%') AND tos.subject like concat('%', #{query.subject}, '%') </if> <if test="query.belongType != null"> AND tst.id = #{query.belongType} </if> </where> ORDER BY @@ -31,14 +43,13 @@ <set> <if test="form.contentType != null and form.contentType != ''">content_type = #{form.contentType},</if> <if test="form.contentUrl != null and form.contentUrl != ''">content_url = #{form.contentUrl},</if> <if test="form.belong_type != null and form.belong_type != ''">belong_type = #{form.belongType},</if> <if test="form.belongType != null and form.belongType != ''">belong_type = #{form.belongType},</if> <if test="form.belongType != null">belong_type = #{form.belongType},</if> <if test="form.subject != null and form.subject != ''">subject = #{form.subject},</if> <if test="form.updateTime != null">update_time = #{form.updateTime},</if> <if test="form.attachment != null and form.attachment != ''">attachment = #{form.attachment},</if> attachment = #{form.attachment} </set> WHERE id = #{vo.id} id = #{form.id} </update> <update id="remove"> src/main/resources/mapper/StudyTypeMapper.xml
@@ -39,6 +39,8 @@ t_study_type WHERE deleted = 0 ORDER BY order_num ASC </select> </mapper>