yangdamao 2 éve
szülő
commit
1f927a5281

+ 7 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -264,6 +264,13 @@ public class CommonController extends BaseController {
         return AjaxResult.success(voList);
     }
 
+    @ApiOperation("七大员学员资料批量变更")
+    @PostMapping("common/apply/user/profile")
+    public AjaxResult updateExamUserProfile(MultipartFile file) {
+        iExamApplyService.updateExamUserProfile(file);
+        return AjaxResult.success();
+    }
+
     @ApiOperation("七大员新考结果")
     @PostMapping("common/apply/result")
     public AjaxResult examApplyResult(@RequestBody ExamApplyResultBo bo) {

+ 59 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/file/FileUtils.java

@@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.math.BigInteger;
 import java.net.URLEncoder;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -27,6 +28,7 @@ import java.util.List;
 import java.util.UUID;
 import java.util.stream.Stream;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
 /**
@@ -444,4 +446,61 @@ public class FileUtils extends org.apache.commons.io.FileUtils
         }
     }
 
+
+    /**
+     * 解压
+     *
+     * @param inputStream zip压缩文件
+     * @param descDir 指定的解压目录
+     */
+    public static void unzipWithStream(InputStream inputStream, String descDir) {
+        if (!descDir.endsWith(File.separator)) {
+            descDir = descDir + File.separator;
+        }
+        try (ZipInputStream zipInputStream = new ZipInputStream(inputStream, Charset.forName("GBK"))) {
+            ZipEntry zipEntry;
+            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+                String zipEntryNameStr = zipEntry.getName();
+                String zipEntryName = zipEntryNameStr;
+                if (zipEntryNameStr.contains("/")) {
+                    String str1 = zipEntryNameStr.substring(0, zipEntryNameStr.indexOf("/"));
+                    zipEntryName = zipEntryNameStr.substring(str1.length() + 1);
+                }
+                String outPath = (descDir + zipEntryName).replace("\\\\", "/");
+                File outFile = new File(outPath.substring(0, outPath.lastIndexOf('/')));
+                if (!outFile.exists()) {
+                    outFile.mkdirs();
+                }
+                if (new File(outPath).isDirectory()) {
+                    continue;
+                }
+                writeFile(outPath, zipInputStream);
+                zipInputStream.closeEntry();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new CustomException("压缩包处理异常,异常信息{}"+ e);
+        }
+    }
+
+    //将流写到文件中
+    public static void writeFile(String filePath, ZipInputStream zipInputStream) {
+        File file = new File(filePath);
+        File directory = file.getParentFile();
+        if (!directory.exists()){
+            directory.mkdirs();
+        }
+        try (OutputStream outputStream = new FileOutputStream(filePath)) {
+            byte[] bytes = new byte[4096];
+            int len;
+            while ((len = zipInputStream.read(bytes)) != -1) {
+                outputStream.write(bytes, 0, len);
+            }
+        } catch (IOException ex) {
+            ex.printStackTrace();
+            throw new CustomException("解压文件时,写出到文件出错!");
+        }
+    }
+
+
 }

+ 1 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/config/SecurityConfig.java

@@ -135,6 +135,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/profile/**").anonymous()
                 .antMatchers("/common/jzs/**").anonymous()
                 .antMatchers("/common/rollback/period").anonymous()
+                .antMatchers("/common/apply/user/profile").anonymous()
                 .antMatchers("/common/decompression").anonymous()
                 .antMatchers("/common/merge/file").anonymous()
                 .antMatchers("/common/get/goods").anonymous()

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/mapper/CourseFileMapper.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.zhongzheng.modules.course.domain.CourseFile;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * 文件Mapper接口
  *

+ 4 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/mapper/CourseHandoutsBusinessMapper.java

@@ -1,7 +1,11 @@
 package com.zhongzheng.modules.course.mapper;
 
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.zhongzheng.modules.course.domain.CourseHandoutsBusiness;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 讲义关联业务Mapper接口
@@ -10,5 +14,4 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @date 2021-11-02
  */
 public interface CourseHandoutsBusinessMapper extends BaseMapper<CourseHandoutsBusiness> {
-
 }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/mapper/CourseHandoutsMapper.java

@@ -40,4 +40,6 @@ public interface CourseHandoutsMapper extends BaseMapper<CourseHandouts> {
     @InterceptorIgnore(tenantLine = "true")
     void removeHandoutsFile(@Param("handoutsId") Long handoutsId,@Param("tenantId") Long tenantId);
 
+    @InterceptorIgnore(tenantLine = "true")
+    List<CourseHandouts> getHandoutsListByTenant(@Param("encoder") String encoder,@Param("handoutsName") String handoutsName,@Param("tenantId") Long tenantId);
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/ICourseHandoutsService.java

@@ -60,4 +60,7 @@ public interface ICourseHandoutsService extends IService<CourseHandouts> {
     List<Long> getGoodsIds(Long handoutsId, Long tenantId);
 
 	void removeHandouts(Long handoutsId, Long tenantId);
+
+	List<CourseHandouts> getHandoutsListByTenant(String encoder, String handoutsName, Long tenantId);
+
 }

+ 0 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseFileServiceImpl.java

@@ -167,5 +167,4 @@ public class CourseFileServiceImpl extends ServiceImpl<CourseFileMapper, CourseF
     public void deleteByTenant(Long handoutsId, Long newTenantId) {
         baseMapper.deleteByTenant(handoutsId, newTenantId);
     }
-
 }

+ 5 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseHandoutsServiceImpl.java

@@ -337,5 +337,10 @@ public class CourseHandoutsServiceImpl extends ServiceImpl<CourseHandoutsMapper,
         baseMapper.removeHandoutsFile(handoutsId, tenantId);
     }
 
+    @Override
+    public List<CourseHandouts> getHandoutsListByTenant(String encoder, String handoutsName, Long tenantId) {
+        return baseMapper.getHandoutsListByTenant(encoder, handoutsName, tenantId);
+    }
+
 
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/service/IExamApplyService.java

@@ -7,6 +7,7 @@ import com.zhongzheng.modules.exam.vo.*;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zhongzheng.modules.goods.domain.Goods;
 import com.zhongzheng.modules.goods.vo.GoodsVo;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.Collection;
 import java.util.List;
@@ -95,4 +96,6 @@ public interface IExamApplyService extends IService<ExamApply> {
 	boolean saveOrUpBeforeKnow(ExamBeforeKnowBo bo);
 
     List<Long> getApplyGoodsId(Long applyId, String majorName);
+
+    void updateExamUserProfile(MultipartFile file);
 }

+ 13 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/service/impl/ExamApplyServiceImpl.java

@@ -998,6 +998,19 @@ public class ExamApplyServiceImpl extends ServiceImpl<ExamApplyMapper, ExamApply
         return baseMapper.getApplyGoodsId(applyId, majorName);
     }
 
+    @Override
+    public void updateExamUserProfile(MultipartFile file) {
+        String zhiyuan = System.getProperty("user.dir");
+        String path = zhiyuan+"/zhongzheng-admin/src/main/resources/kaoshi";
+        try {
+            FileUtils.unzipWithStream(file.getInputStream(),path);
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new CustomException("文件解压错误");
+        }
+
+    }
+
 
     private void userStudyRecord(String userPath, List<UserSubscribe> list) {
         Map<Long, List<UserSubscribe>> map = list.stream().collect(Collectors.groupingBy(UserSubscribe::getUserId));

+ 12 - 5
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/service/impl/GoodsServiceImpl.java

@@ -4902,12 +4902,19 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
             if (ObjectUtils.isNull(goodsTwo)){
                 continue;
             }
-           List<Long> goodsIds = iCourseHandoutsService.getGoodsIds(goodsTwo.getHandoutsId(),tenantId);
-            if (goodsIds.stream().allMatch(x -> x.equals(goodsTwo.getGoodsId()))){
-                //删除讲义
-                iCourseHandoutsService.removeHandouts(goodsTwo.getHandoutsId(),tenantId);
-            }
+//           List<Long> goodsIds = iCourseHandoutsService.getGoodsIds(goodsTwo.getHandoutsId(),tenantId);
+//            if (goodsIds.stream().allMatch(x -> x.equals(goodsTwo.getGoodsId()))){
+//                //删除讲义
+//                iCourseHandoutsService.removeHandouts(goodsTwo.getHandoutsId(),tenantId);
+//            }
+            //如果存在先删除掉之前的讲义
+            List<CourseHandouts> handoutsList = iCourseHandoutsService.getHandoutsListByTenant(handouts.getEncoder(),handouts.getHandoutsName(),tenantId);
 
+            if (CollectionUtils.isNotEmpty(handoutsList)){
+                handoutsList.forEach(item -> {
+                    iCourseHandoutsService.removeHandouts(item.getHandoutsId(),tenantId);
+                });
+            }
             //新增
             handouts.setHandoutsId(null);
             handouts.setTenantId(tenantId);

+ 4 - 0
zhongzheng-system/src/main/resources/mapper/modules/course/CourseHandoutsMapper.xml

@@ -143,4 +143,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         DELETE FROM course_file WHERE handouts_id = #{handoutsId} AND tenant_id = #{tenantId}
     </delete>
 
+    <select id="getHandoutsListByTenant" parameterType="map" resultType="com.zhongzheng.modules.course.domain.CourseHandouts" >
+        SELECT * FROM `course_handouts` WHERE encoder = #{encoder} AND handouts_name = #{handoutsName} AND tenant_id = #{tenantId}
+    </select>
+
 </mapper>