Przeglądaj źródła

课程导出重粉

yh 1 tydzień temu
rodzic
commit
66f89dd268

+ 25 - 12
fs-admin/src/main/java/com/fs/course/controller/FsUserCourseCategoryController.java

@@ -1,15 +1,20 @@
 package com.fs.course.controller;
 
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.model.LoginUser;
+import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.ServletUtils;
 import com.fs.course.domain.DuplicateFans;
+import com.fs.course.domain.FsUserCourse;
 import com.fs.framework.web.service.TokenService;
+import com.fs.his.domain.FsExportTask;
 import com.fs.his.domain.FsStoreProductCategory;
+import com.fs.his.service.IFsExportTaskService;
 import com.fs.his.vo.FsStoreProductCategoryVO;
 
 import cn.hutool.core.util.ObjectUtil;
@@ -88,25 +93,33 @@ public class FsUserCourseCategoryController extends BaseController
         return util.exportExcel(list, "课堂分类数据");
     }
 
+    @Autowired
+    private IFsExportTaskService exportTaskService;
+
     /**
      * 导出重粉
      */
     @PreAuthorize("@ss.hasPermi('course:userCourseCategory:fansExport')")
-    @Log(title = "课堂分类重粉", businessType = BusinessType.EXPORT)
+    @Log(title = "课程管理导出重粉", businessType = BusinessType.EXPORT)
     @PostMapping("/exportFans")
-    public AjaxResult exportFans(@RequestBody Map<String, List<Integer>> map) {
-
-        List<Integer> ids = map.get("ids");
-
-        List<DuplicateFans> list = fsUserCourseCategoryService.exportFans(ids);
-
-        if (CollectionUtils.isEmpty(list)) {
-            return AjaxResult.error("没有可导出的数据");
+    public AjaxResult exportFans(@RequestBody FsUserCourse param) {
+        Integer exportType1 = exportTaskService.isExportType1(SecurityUtils.getUserId());
+        if (exportType1 > 0) {
+            return AjaxResult.error("你已经有正在导出的任务");
         }
 
-        ExcelUtil<DuplicateFans> util = new ExcelUtil<>(DuplicateFans.class);
-
-        return util.exportExcel(list, "课堂分类重粉数据");
+        FsExportTask task = new FsExportTask();
+        task.setTaskType(12);
+        task.setStatus(0);
+        task.setStartTime(new Date());
+        task.setRemark("课程管理导出重粉");
+        task.setSysType(1);
+        task.setUserId(SecurityUtils.getUserId());
+        exportTaskService.insertFsExportTask(task);
+        param.setTaskId(task.getTaskId());
+
+        fsUserCourseCategoryService.exportFans(param);
+        return new AjaxResult(200, "后台正在导出,请等待...任务ID:" + task.getTaskId(), task.getTaskId());
     }
 
 

+ 7 - 0
fs-service/src/main/java/com/fs/course/domain/FsUserCourse.java

@@ -1,6 +1,7 @@
 package com.fs.course.domain;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fs.common.annotation.Excel;
@@ -157,4 +158,10 @@ public class FsUserCourse extends BaseEntity
      */
     private String configJson;
 
+    //多个课堂名称搜索
+    private List<String> courseNames;
+
+    //任务ID
+    private Long taskId;
+
 }

+ 1 - 1
fs-service/src/main/java/com/fs/course/mapper/FsUserCourseCategoryMapper.java

@@ -103,5 +103,5 @@ public interface FsUserCourseCategoryMapper
     @Select("select cate_id dict_value, cate_name dict_label  from fs_user_course_category WHERE pid = 0 and is_del=0 ")
     List<OptionsVO> selectAllFsUserCourseCategoryPidList();
 
-    List<DuplicateFans> exportFans(@Param("ids") List<Integer> ids);
+    List<DuplicateFans> exportFans(@Param("courseNames") List<String> courseNames);
 }

+ 0 - 28
fs-service/src/main/java/com/fs/course/mapper/FsUserCourseMapper.java

@@ -131,34 +131,6 @@ public interface FsUserCourseMapper
     List<FsUserCourseListUVO> selectFsUserCourseListUVO(@Param("maps") FsUserCourseListUParam param);
 
 
-    @Select({"<script> " +
-            "select c.*,cc.cate_name,ucc.cate_name as sub_cate_name from fs_user_course  c " +
-            " left join fs_user_course_category cc on c.cate_id=cc.cate_id" +
-            " left join fs_user_course_category ucc on  ucc.cate_id = c.sub_cate_id " +
-            "where c.is_del = 0   " +
-            "<if test = ' maps.cateId !=null '> " +
-            "and (cc.cate_id =#{maps.cateId} or cc.pid=#{maps.cateId} )" +
-            "</if>" +
-            "<if test = ' maps.subCateId !=null '> " +
-            "and c.sub_cate_id =#{maps.subCateId}" +
-            "</if>" +
-            "<if test = ' maps.userId !=null '> " +
-            "and c.user_id =#{maps.userId}" +
-            "</if>" +
-            "<if test = ' maps.courseName!=null and maps.courseName != \"\" '> " +
-            "and c.course_name like concat('%', #{maps.courseName}, '%') " +
-            "</if>" +
-            "<if test = ' maps.isPrivate !=null '> " +
-            "and c.is_private = #{maps.isPrivate} " +
-            "</if>" +
-            "<if test = ' maps.isShow !=null '> " +
-            "and c.is_show = #{maps.isShow} " +
-            "</if>" +
-            "<if test ='maps.companyIdsList != null and maps.companyIdsList.length !=0 '> " +
-            " and <foreach collection='maps.companyIdsList'  item='item' index='index'  open='( 1=2 ' separator='' close=')'> or find_in_set(  #{item} , REGEXP_REPLACE ( c.company_ids, '[\"\\\\[\\\\]]', '' ) )  </foreach> " +
-            "</if> " +
-            " order by c.sort, c.course_id  "+
-            "</script>"})
     List<FsUserCourseListPVO> selectFsUserCourseListPVO(@Param("maps") FsUserCourse param);
 
 

+ 2 - 1
fs-service/src/main/java/com/fs/course/service/IFsUserCourseCategoryService.java

@@ -3,6 +3,7 @@ package com.fs.course.service;
 import java.util.List;
 
 import com.fs.course.domain.DuplicateFans;
+import com.fs.course.domain.FsUserCourse;
 import com.fs.course.domain.FsUserCourseCategory;
 import com.fs.his.vo.OptionsVO;
 
@@ -71,5 +72,5 @@ public interface IFsUserCourseCategoryService
 
     List<OptionsVO> selectCateListByPid(Long pid);
 
-    List<DuplicateFans> exportFans(List<Integer> ids);
+    void exportFans(FsUserCourse param);
 }

+ 21 - 2
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseCategoryServiceImpl.java

@@ -1,10 +1,18 @@
 package com.fs.course.service.impl;
 
+import java.util.Date;
 import java.util.List;
+
+import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.course.domain.DuplicateFans;
+import com.fs.course.domain.FsUserCourse;
+import com.fs.his.domain.FsExportTask;
+import com.fs.his.mapper.FsExportTaskMapper;
 import com.fs.his.vo.OptionsVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import com.fs.course.mapper.FsUserCourseCategoryMapper;
 import com.fs.course.domain.FsUserCourseCategory;
@@ -21,6 +29,8 @@ public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategorySer
 {
     @Autowired
     private FsUserCourseCategoryMapper fsUserCourseCategoryMapper;
+    @Autowired
+    private FsExportTaskMapper fsExportTaskMapper;
 
     /**
      * 查询课堂分类
@@ -120,8 +130,17 @@ public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategorySer
         return fsUserCourseCategoryMapper.selectCateListByPid(pid);
     }
 
+    @Async
     @Override
-    public List<DuplicateFans> exportFans(List<Integer> ids) {
-        return fsUserCourseCategoryMapper.exportFans(ids);
+    public void exportFans(FsUserCourse param) {
+        List<String> courseNames = param.getCourseNames();
+        List<DuplicateFans> list = fsUserCourseCategoryMapper.exportFans(courseNames);
+        ExcelUtil<DuplicateFans> util = new ExcelUtil<>(DuplicateFans.class);
+        AjaxResult result = util.exportExcel(list, "重粉导出");
+        FsExportTask task = fsExportTaskMapper.selectFsExportTaskByTaskId(param.getTaskId());
+        task.setFinishTime(new Date());
+        task.setStatus(1);
+        task.setFileUrl(result.get("msg").toString());
+        fsExportTaskMapper.updateFsExportTask(task);
     }
 }

+ 28 - 26
fs-service/src/main/resources/mapper/course/FsUserCourseCategoryMapper.xml

@@ -47,33 +47,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="exportFans" resultType="com.fs.course.domain.DuplicateFans">
         SELECT
-        'wx6ee517a8d8743f88' AS app_id,
-        fu.union_id,
-        fu.mp_open_id
-        FROM fs_user fu
+            'wx6ee517a8d8743f88' app_id,
+            fu.union_id,
+            fu.mp_open_id
+        FROM
+            fs_user fu
         WHERE
-        fu.union_id IS NOT NULL
-        AND fu.mp_open_id IS NOT NULL
-        AND fu.user_id IN (
-        SELECT fswl.user_id
-        FROM fs_course_watch_log fswl
-        INNER JOIN fs_user_course fuc
-        ON fuc.course_id = fswl.course_id
-        WHERE
-        fswl.user_id IS NOT NULL
-        AND fswl.user_id &gt; 0
-        <if test="ids != null and ids.size() > 0">
-            AND fuc.cate_id IN
-            <foreach collection="ids"
-                     item="id"
-                     open="("
-                     separator=","
-                     close=")">
-                #{id}
-            </foreach>
-        </if>
-        GROUP BY fswl.user_id
-        )
+            fu.union_id IS NOT NULL
+          AND fu.mp_open_id IS NOT NULL
+          AND fu.user_id IN (
+            SELECT
+                fswl.user_id
+            FROM
+                fs_course_watch_log fswl
+                    LEFT JOIN fs_user_course fuc ON fuc.course_id = fswl.course_id
+            WHERE
+                fswl.user_id IS NOT NULL
+              AND fswl.user_id > 0
+              <if test="courseNames != null and courseNames.size() > 0">
+                  AND (
+                  <foreach collection="courseNames"
+                           item="item"
+                           separator=" OR ">
+                      fuc.course_name LIKE CONCAT('%', #{item}, '%')
+                  </foreach>
+                  )
+              </if>
+            GROUP BY
+                fswl.user_id
+        );
     </select>
 
 

+ 63 - 0
fs-service/src/main/resources/mapper/course/FsUserCourseMapper.xml

@@ -170,6 +170,69 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </select>
 
+    <select id="selectFsUserCourseListPVO" resultType="com.fs.course.vo.FsUserCourseListPVO">
+        SELECT
+        c.*,
+        cc.cate_name,
+        ucc.cate_name AS sub_cate_name
+        FROM fs_user_course c
+        LEFT JOIN fs_user_course_category cc
+        ON c.cate_id = cc.cate_id
+        LEFT JOIN fs_user_course_category ucc
+        ON ucc.cate_id = c.sub_cate_id
+        WHERE c.is_del = 0
+
+        <if test="maps.cateId != null">
+            AND (
+            cc.cate_id = #{maps.cateId}
+            OR cc.pid = #{maps.cateId}
+            )
+        </if>
+
+        <if test="maps.subCateId != null">
+            AND c.sub_cate_id = #{maps.subCateId}
+        </if>
+
+        <if test="maps.userId != null">
+            AND c.user_id = #{maps.userId}
+        </if>
+
+        <if test="maps.courseName != null and maps.courseName != ''">
+            AND c.course_name LIKE CONCAT('%', #{maps.courseName}, '%')
+        </if>
+
+        <if test="maps.isPrivate != null">
+            AND c.is_private = #{maps.isPrivate}
+        </if>
+
+        <if test="maps.isShow != null">
+            AND c.is_show = #{maps.isShow}
+        </if>
+
+        <if test="maps.companyIdsList != null and maps.companyIdsList.size() > 0">
+            AND (
+            <foreach collection="maps.companyIdsList"
+                     item="item"
+                     separator=" OR ">
+                FIND_IN_SET(
+                #{item},
+                REGEXP_REPLACE(c.company_ids, '[\"\\[\\]]', '')
+                )
+            </foreach>
+            )
+        </if>
+
+        <if test="maps.courseNames != null and maps.courseNames.size() > 0">
+            AND (
+            <foreach collection="maps.courseNames"
+                     item="item"
+                     separator=" OR ">
+                c.course_name LIKE CONCAT('%', #{item}, '%')
+            </foreach>
+            )
+        </if>
+        ORDER BY c.sort, c.course_id
+    </select>
 
     <insert id="insertFsUserCourse" parameterType="FsUserCourse" useGeneratedKeys="true" keyProperty="courseId">
         insert into fs_user_course