Sfoglia il codice sorgente

1、直播敏感词导入功能

yys 4 settimane fa
parent
commit
1d0f7b929d

+ 20 - 0
fs-admin/src/main/java/com/fs/live/controller/LiveSensitiveWordsController.java

@@ -6,11 +6,13 @@ import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.his.domain.FsChineseMedicine;
 import com.fs.live.domain.LiveSensitiveWords;
 import com.fs.live.service.ILiveSensitiveWordsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -95,4 +97,22 @@ public class LiveSensitiveWordsController extends BaseController
     {
         return toAjax(liveSensitiveWordsService.deleteLiveSensitiveWordsByWordIds(wordIds));
     }
+
+    @GetMapping("/importTemplate")
+    public AjaxResult importTemplate()
+    {
+        ExcelUtil<LiveSensitiveWords> util = new ExcelUtil<>(LiveSensitiveWords.class);
+        return util.importTemplateExcel("导入模板");
+    }
+
+
+    @Log(title = "导入", businessType = BusinessType.IMPORT)
+    @PostMapping("/importData")
+    public AjaxResult importData(MultipartFile file) throws Exception
+    {
+        ExcelUtil<LiveSensitiveWords> util = new ExcelUtil<>(LiveSensitiveWords.class);
+        List<LiveSensitiveWords> list = util.importExcel(file.getInputStream());
+        String message = liveSensitiveWordsService.importData(list);
+        return AjaxResult.success(message);
+    }
 }

+ 9 - 0
fs-service/src/main/java/com/fs/live/service/ILiveSensitiveWordsService.java

@@ -1,6 +1,7 @@
 package com.fs.live.service;
 
 
+import com.fs.his.domain.FsChineseMedicine;
 import com.fs.live.domain.LiveSensitiveWords;
 
 import java.util.List;
@@ -64,4 +65,12 @@ public interface ILiveSensitiveWordsService {
      * 查询所有敏感词
      */
     List<String> selectAllWords();
+
+    /**
+     * 导入直播敏感词
+     *
+     * @param list
+     * @return
+     */
+        String importData(List<LiveSensitiveWords> list);
 }

+ 44 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveSensitiveWordsServiceImpl.java

@@ -1,6 +1,9 @@
 package com.fs.live.service.impl;
 
 
+import com.fs.common.exception.ServiceException;
+import com.fs.common.utils.DateUtils;
+import com.fs.his.domain.FsInquiryDisease;
 import com.fs.live.domain.LiveSensitiveWords;
 import com.fs.live.mapper.LiveSensitiveWordsMapper;
 import com.fs.live.service.ILiveSensitiveWordsService;
@@ -102,4 +105,45 @@ public class LiveSensitiveWordsServiceImpl implements ILiveSensitiveWordsService
     public List<String> selectAllWords() {
         return baseMapper.selectAllWords();
     }
+
+    @Override
+    public String importData(List<LiveSensitiveWords> list) {
+        if (com.fs.common.utils.StringUtils.isNull(list) || list.size() == 0)
+        {
+            throw new ServiceException("导入数据不能为空!");
+        }
+        int successNum = 0;
+        int failureNum = 0;
+        StringBuilder successMsg = new StringBuilder();
+        StringBuilder failureMsg = new StringBuilder();
+        for (LiveSensitiveWords vo : list)
+        {
+            try
+            {
+                vo.setCreateTime(DateUtils.getNowDate());
+                int i = baseMapper.insertLiveSensitiveWords(vo);
+
+                successNum++;
+                successMsg.append("<br/>" + successNum + "、名称 " + vo.getWord() + " 导入成功");
+
+            }
+            catch (Exception e)
+            {
+
+                failureNum++;
+                String msg = "<br/>" + failureNum + "、名称 " +vo.getWord() + " 导入失败:";
+                failureMsg.append(msg + e.getMessage());
+            }
+        }
+        if (failureNum > 0)
+        {
+            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
+            throw new ServiceException(failureMsg.toString());
+        }
+        else
+        {
+            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+        }
+        return successMsg.toString();
+    }
 }