瀏覽代碼

Merge remote-tracking branch 'origin/master'

yuhongqi 2 周之前
父節點
當前提交
be766a54fe

+ 35 - 0
fs-admin/src/main/java/com/fs/course/controller/FsUserCourseCategoryController.java

@@ -5,6 +5,7 @@ import java.util.List;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.model.LoginUser;
 import com.fs.common.utils.ServletUtils;
+import com.fs.course.dto.FsCourseCategoryImportDTO;
 import com.fs.framework.web.service.TokenService;
 import com.fs.his.domain.FsStoreProductCategory;
 import com.fs.his.vo.FsStoreProductCategoryVO;
@@ -33,6 +34,7 @@ import com.fs.course.domain.FsUserCourseCategory;
 import com.fs.course.service.IFsUserCourseCategoryService;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 课堂分类Controller
@@ -174,4 +176,37 @@ public class FsUserCourseCategoryController extends BaseController
         List<OptionsVO> list = fsUserCourseCategoryService.selectCateListByPid(pid);
         return R.ok().put("data", list);
     }
+
+    // 下载模板
+    @GetMapping("/importTemplate")
+    public AjaxResult importTemplate() {
+        ExcelUtil<FsCourseCategoryImportDTO> util = new ExcelUtil<>(FsCourseCategoryImportDTO.class);
+        return util.importTemplateExcel("课堂分类导入模板");
+    }
+
+    @Log(title = "导入", businessType = BusinessType.IMPORT)
+    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:importData')")
+    @PostMapping("/importData")
+    public AjaxResult importData(MultipartFile file) throws Exception {
+        ExcelUtil<FsCourseCategoryImportDTO> util = new ExcelUtil<>(FsCourseCategoryImportDTO.class);
+        List<FsCourseCategoryImportDTO> list = util.importExcel(file.getInputStream());
+
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        Long userId = loginUser.getUser().getUserId();
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+        if (ObjectUtil.isEmpty(config.getIsBound()) || !config.getIsBound()){
+            userId = null;
+        }
+
+        return AjaxResult.success(fsUserCourseCategoryService.importData(list, userId));
+    }
+
+    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:exportFail')")
+    @Log(title = "课堂分类", businessType = BusinessType.EXPORT)
+    @PostMapping("/exportFail")
+    public AjaxResult exportFail(@RequestBody List<FsCourseCategoryImportDTO> list) {
+        ExcelUtil<FsCourseCategoryImportDTO> util = new ExcelUtil<>(FsCourseCategoryImportDTO.class);
+        return util.exportExcel(list, "课堂分类错误数据");
+    }
 }

+ 14 - 0
fs-service/src/main/java/com/fs/course/dto/FsCourseCategoryImportDTO.java

@@ -0,0 +1,14 @@
+package com.fs.course.dto;
+
+import com.fs.common.annotation.Excel;
+import lombok.Data;
+
+@Data
+public class FsCourseCategoryImportDTO {
+
+    @Excel(name = "父分类")
+    private String rootCate;
+
+    @Excel(name = "子分类")
+    private String subCate;
+}

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

@@ -101,4 +101,16 @@ 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();
+
+    /**
+     * 根据名称和上级ID查询分类
+     */
+    @Select("select * from fs_user_course_category where cate_name = #{name} and pid = #{parentId} and is_del = 0")
+    FsUserCourseCategory selectFsUserCourseCategoryByNameAndParentId(@Param("name") String name, @Param("parentId") Long parentId);
+
+    /**
+     * 获取序号
+     */
+    @Select("select ifnull(max(sort), 0) + 1 from fs_user_course_category where pid = #{parentId}")
+    Long getSortByParentId(@Param("parentId") Long parentId);
 }

+ 8 - 0
fs-service/src/main/java/com/fs/course/service/IFsUserCourseCategoryService.java

@@ -1,7 +1,10 @@
 package com.fs.course.service;
 
 import java.util.List;
+import java.util.Map;
+
 import com.fs.course.domain.FsUserCourseCategory;
+import com.fs.course.dto.FsCourseCategoryImportDTO;
 import com.fs.his.vo.OptionsVO;
 
 /**
@@ -68,4 +71,9 @@ public interface IFsUserCourseCategoryService
     List<OptionsVO> selectFsUserCourseCategoryPidList(Long userId);
 
     List<OptionsVO> selectCateListByPid(Long pid);
+
+    /**
+     * 课堂分类导入
+     */
+    Map<String, Object> importData(List<FsCourseCategoryImportDTO> list, Long userId);
 }

+ 89 - 1
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseCategoryServiceImpl.java

@@ -1,8 +1,14 @@
 package com.fs.course.service.impl;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.StringUtils;
+import com.fs.course.dto.FsCourseCategoryImportDTO;
 import com.fs.his.vo.OptionsVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.fs.course.mapper.FsUserCourseCategoryMapper;
@@ -15,6 +21,7 @@ import com.fs.course.service.IFsUserCourseCategoryService;
  * @author fs
  * @date 2024-05-15
  */
+@Slf4j
 @Service
 public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategoryService
 {
@@ -118,4 +125,85 @@ public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategorySer
     public List<OptionsVO> selectCateListByPid(Long pid) {
         return fsUserCourseCategoryMapper.selectCateListByPid(pid);
     }
+
+    /**
+     * 课堂分类导入
+     */
+    @Override
+    public Map<String, Object> importData(List<FsCourseCategoryImportDTO> list, Long userId) {
+        int suCnt = 0;
+        int filCnt = 0;
+        List<FsCourseCategoryImportDTO> failedList = new ArrayList<>();
+
+        if (list == null || list.isEmpty()) {
+            throw new CustomException("导入数据不能为空");
+        }
+
+        Map<String, List<FsCourseCategoryImportDTO>> rootMap = list.stream()
+                .filter(dto -> StringUtils.isNotBlank(dto.getRootCate()))
+                .collect(Collectors.groupingBy(FsCourseCategoryImportDTO::getRootCate));
+        for (Map.Entry<String, List<FsCourseCategoryImportDTO>> entry : rootMap.entrySet()) {
+            if (StringUtils.isBlank(entry.getKey())) {
+                failedList.addAll(entry.getValue());
+                filCnt += entry.getValue().size();
+                continue;
+            }
+
+            String rootCate = entry.getKey().trim();
+            FsUserCourseCategory root = fsUserCourseCategoryMapper.selectFsUserCourseCategoryByNameAndParentId(rootCate, 0L);
+            if (Objects.isNull(root)) {
+                root = new FsUserCourseCategory();
+                root.setPid(0L);
+                root.setCateName(rootCate);
+                root.setSort(fsUserCourseCategoryMapper.getSortByParentId(0L));
+                root.setIsShow(1);
+                root.setCreateTime(new Date());
+                root.setIsDel(0);
+                root.setUserId(userId);
+                fsUserCourseCategoryMapper.insertFsUserCourseCategory(root);
+            }
+
+            Long parentId = root.getCateId();
+            long curSort = fsUserCourseCategoryMapper.getSortByParentId(root.getCateId());
+            List<FsCourseCategoryImportDTO> subList = entry.getValue();
+            for (FsCourseCategoryImportDTO child : subList) {
+                try {
+                    if (StringUtils.isBlank(child.getSubCate())) {
+                        failedList.add(child);
+                        filCnt++;
+                        continue;
+                    }
+
+                    String cateName = child.getSubCate().trim();
+                    FsUserCourseCategory sub = fsUserCourseCategoryMapper.selectFsUserCourseCategoryByNameAndParentId(cateName, parentId);
+                    if (Objects.nonNull(sub)) {
+                        failedList.add(child);
+                        filCnt++;
+                        continue;
+                    }
+
+                    sub = new FsUserCourseCategory();
+                    sub.setPid(parentId);
+                    sub.setCateName(cateName);
+                    sub.setSort(curSort++);
+                    sub.setIsShow(1);
+                    sub.setCreateTime(new Date());
+                    sub.setIsDel(0);
+                    sub.setUserId(userId);
+                    fsUserCourseCategoryMapper.insertFsUserCourseCategory(sub);
+
+                    suCnt++;
+                } catch (Exception e) {
+                    filCnt++;
+                    log.error("导入子分类失败: {}", child, e);
+                }
+            }
+        }
+
+        String message = "导入完成!成功" + suCnt + "条,失败" + filCnt + "条。";
+        Map<String, Object> resp = new HashMap<>();
+        resp.put("message", message);
+        resp.put("failList", failedList);
+        return resp;
+    }
 }

+ 1 - 2
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreProductScrmMapper.java

@@ -76,8 +76,7 @@ public interface FsStoreProductScrmMapper
      */
     public int deleteFsStoreProductByIds(Long[] productIds);
     @Select({"<script> " +
-            "select p.*,fspavs.bar_code as barCode2,pc.cate_name, fs.store_name from fs_store_product_scrm p left join fs_store_product_category_scrm pc on p.cate_id=pc.cate_id  " +
-            "left join  fs_store_product_attr_value_scrm as fspavs on fspavs.product_id=p.product_id "+
+            "select p.*,pc.cate_name, fs.store_name from fs_store_product_scrm p left join fs_store_product_category_scrm pc on p.cate_id=pc.cate_id  " +
             "left join fs_store fs on fs.store_id = p.store_id " +
             "where 1=1 and p.is_del = 0" +
             "<if test = 'maps.productName != null and  maps.productName !=\"\"    '> " +

+ 0 - 2
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreProductListVO.java

@@ -115,6 +115,4 @@ public class FsStoreProductListVO  implements Serializable
 
     private String storeId;
     private String storeName;
-    //fs_store_product_attr_value_scrm表里面的条码 原字段没数据
-    private String barCode2;
 }