Переглянути джерело

新媒体矩阵更新时间EXCEL批量更新

zwq 2 роки тому
батько
коміт
593fcd0aee

+ 63 - 31
nngkxxdp/src/main/java/com/example/nngkxxdp/base/SortArticleHeadlinesExcelListeners.java

@@ -1,52 +1,49 @@
 package com.example.nngkxxdp.base;
 
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
 import com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO;
-import com.example.nngkxxdp.service.SortArticleHeadlinesService;
+import com.example.nngkxxdp.util.Blank;
 import com.example.nngkxxdp.util.WzkpRecordUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
- * 监听数据读取
- *
+ * description: 新媒体矩阵导入监听
  * @author zwq
- * @version 0.0.1
- * @Date 2022/6/23
- * 
- * @Copyright 1998-2021 重庆鸥睿珂数字科技有限公司. All rights reserved.
+ * @date 2022/8/15 11:00
  */
 public class SortArticleHeadlinesExcelListeners extends AnalysisEventListener<SortArticleHeadlinesExcelDTO> {
 
     private static final Logger logger = LoggerFactory.getLogger(WzkpRecordUtil.class);
 
-    private static final int BATCH_COUNT = 200;
+    // 合格的列表
+    private List<SortArticleHeadlinesExcelDTO> rightList = new ArrayList<>();
 
-    private SortArticleHeadlinesService sortArticleHeadlinesService;
-
-    List<SortArticleHeadlinesExcelDTO> list = new ArrayList<>();
-
-    /**
-     * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
-     */
-    public SortArticleHeadlinesExcelListeners(SortArticleHeadlinesService sortArticleHeadlinesService) {
-        this.sortArticleHeadlinesService = sortArticleHeadlinesService;
-    }
+    // 错误的列表
+    private List<SortArticleHeadlinesExcelDTO> errorList = new ArrayList<>();
 
     /**
      * 这个每一条数据解析都会来调用
      */
     @Override
-    public void invoke(SortArticleHeadlinesExcelDTO poolExcelDTO, AnalysisContext analysisContext) {
-        list.add(poolExcelDTO);
-        if (list.size() >= BATCH_COUNT) {
-            saveData();
-            // 存储完成清理 list
-            list.clear();
+    public void invoke(SortArticleHeadlinesExcelDTO excelDTO, AnalysisContext analysisContext) {
+        // 处理空行
+        if (isLineNullValue(excelDTO)) {
+            return;
+        }
+        if (Blank.isEmpty(excelDTO.getOfficialAccount(), excelDTO.getTitle(), excelDTO.getUrl(),
+                excelDTO.getSort(), excelDTO.getCreateTime())) {
+            errorList.add(excelDTO);
+        } else {
+            rightList.add(excelDTO);
         }
     }
 
@@ -57,17 +54,52 @@ public class SortArticleHeadlinesExcelListeners extends AnalysisEventListener<So
      */
     @Override
     public void doAfterAllAnalysed(AnalysisContext analysisContext) {
-        // 这里也要保存数据,确保最后遗留的数据也存储到数据库
-        saveData();
+        logger.info("新媒体矩阵EXCEL数据读取完毕");
     }
 
     /**
-     * 存储数据库
+     * description: 获取合格的列表
+     * @author zwq
+     * @date 2022/8/15 9:33
+     * @return java.util.List<com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO>
      */
-    private void saveData() {
-        logger.info("{}条数据,开始存储数据库!", list.size());
-        sortArticleHeadlinesService.insertBatchByExcel(list);
-        logger.info("存储数据库成功!");
+    public List<SortArticleHeadlinesExcelDTO> getRightList() {
+        return rightList;
+    }
+
+    /**
+     * description: 获取不合格的列表
+     * @author zwq
+     * @date 2022/8/15 9:33
+     * @return java.util.List<com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO>
+     */
+    public List<SortArticleHeadlinesExcelDTO> getErrorList () {
+        return errorList;
+    }
+
+    /**
+     * 判断整行单元格数据是否均为空
+     */
+    private boolean isLineNullValue(SortArticleHeadlinesExcelDTO data) {
+        try {
+            List<Field> fields = Arrays.stream(data.getClass().getDeclaredFields())
+                    .filter(f -> f.isAnnotationPresent(ExcelProperty.class))
+                    .collect(Collectors.toList());
+            List<Boolean> lineNullList = new ArrayList<>(fields.size());
+            for (Field field : fields) {
+                field.setAccessible(true);
+                Object value = field.get(data);
+                if (Blank.isEmpty(value)) {
+                    lineNullList.add(Boolean.TRUE);
+                } else {
+                    lineNullList.add(Boolean.FALSE);
+                }
+            }
+            return lineNullList.stream().allMatch(Boolean.TRUE::equals);
+        } catch (Exception e) {
+            logger.error("读取数据行[{}]解析失败: {}", data, e.getMessage());
+        }
+        return true;
     }
 
 }

+ 97 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/base/WOfaExcelListeners.java

@@ -0,0 +1,97 @@
+package com.example.nngkxxdp.base;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.example.nngkxxdp.entity.WOfaExcelDTO;
+import com.example.nngkxxdp.util.Blank;
+import com.example.nngkxxdp.util.DateUtil;
+import com.example.nngkxxdp.util.WzkpRecordUtil;
+import lombok.SneakyThrows;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * description: 新媒体矩阵更新时间监听
+ * @author zwq
+ * @date 2022/8/15 11:00
+ */
+public class WOfaExcelListeners extends AnalysisEventListener<WOfaExcelDTO> {
+
+    private static final Logger logger = LoggerFactory.getLogger(WzkpRecordUtil.class);
+
+    // 合格的列表
+    private List<WOfaExcelDTO> rightList = new ArrayList<>();
+
+    /**
+     * 这个每一条数据解析都会来调用
+     */
+    @SneakyThrows
+    @Override
+    public void invoke(WOfaExcelDTO excelDTO, AnalysisContext analysisContext) {
+        // 处理空行
+        if (isLineNullValue(excelDTO)) {
+            return;
+        }
+        if (Blank.isEmpty(excelDTO.getWName(), excelDTO.getWType(),
+                excelDTO.getUpdateTime())) {
+            throw new Exception("EXCEL中存在参数为空的数据");
+        } else if (!DateUtil.isValidDate(excelDTO.getUpdateTime(), "yyyy-MM-dd")) {
+            throw new Exception("EXCEL中存在更新时间格式错误的数据");
+        } else {
+            rightList.add(excelDTO);
+        }
+    }
+
+    /**
+     * 所有数据解析完成了 都会来调用
+     *
+     * @param analysisContext
+     */
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+        logger.info("新媒体矩阵更新时间EXCEL数据读取完毕");
+    }
+
+    /**
+     * description: 读取列表
+     * @author zwq
+     * @date 2022/8/15 11:03
+     * @return java.util.List<com.example.nngkxxdp.entity.WOfaExcelDTO>
+     */
+    public List<WOfaExcelDTO> getList() {
+        return rightList;
+    }
+
+    /**
+     * 判断整行单元格数据是否均为空
+     */
+    private boolean isLineNullValue(WOfaExcelDTO data) {
+        try {
+            List<Field> fields = Arrays.stream(data.getClass().getDeclaredFields())
+                    .filter(f -> f.isAnnotationPresent(ExcelProperty.class))
+                    .collect(Collectors.toList());
+            List<Boolean> lineNullList = new ArrayList<>(fields.size());
+            for (Field field : fields) {
+                field.setAccessible(true);
+                Object value = field.get(data);
+                if (Blank.isEmpty(value)) {
+                    lineNullList.add(Boolean.TRUE);
+                } else {
+                    lineNullList.add(Boolean.FALSE);
+                }
+            }
+            return lineNullList.stream().allMatch(Boolean.TRUE::equals);
+        } catch (Exception e) {
+            logger.error("读取数据行[{}]解析失败: {}", data, e.getMessage());
+        }
+        return true;
+    }
+
+}

+ 9 - 12
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/SortArticleHeadlinesController.java

@@ -1,10 +1,6 @@
 package com.example.nngkxxdp.controller;
 
 import com.example.nngkxxdp.entity.SortArticleHeadlinesDO;
-import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.converters.string.StringNumberConverter;
-import com.example.nngkxxdp.base.SortArticleHeadlinesExcelListeners;
-import com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO;
 import com.example.nngkxxdp.service.SortArticleHeadlinesService;
 import com.example.nngkxxdp.util.Blank;
 import com.example.nngkxxdp.util.ConstStr;
@@ -96,19 +92,20 @@ public class SortArticleHeadlinesController {
         return sortArticleHeadlinesService.deleteArticleById(id);
     }
 
+    /**
+     * description: EXCEL批量新增
+     * @author zwq
+     * @date 2022/8/15 8:57
+     * @param file 文件
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
     @PostMapping("/add/batch")
     public Map<String,Object> page(MultipartFile file) {
         if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
             return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
         }
-        try {
-            EasyExcel.read(file.getInputStream(), SortArticleHeadlinesExcelDTO.class, new SortArticleHeadlinesExcelListeners(sortArticleHeadlinesService))
-                    .registerConverter(new StringNumberConverter()).sheet().doRead();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return SendUtil.send(true, ConstStr.RESULT_SUCCESS);
-
+        // 数据全部正确就返回成功,并添加, 数据存在错误就不添加,返回存在错误的数量
+        return sortArticleHeadlinesService.addBatchByExcel(file);
     }
 
 }

+ 82 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/WOfaController.java

@@ -0,0 +1,82 @@
+package com.example.nngkxxdp.controller;
+
+import com.example.nngkxxdp.entity.WOfaDO;
+import com.example.nngkxxdp.service.WOfaService;
+import com.example.nngkxxdp.util.Blank;
+import com.example.nngkxxdp.util.ConstStr;
+import com.example.nngkxxdp.util.DateUtil;
+import com.example.nngkxxdp.util.SendUtil;
+import lombok.AllArgsConstructor;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Map;
+
+/**
+ * description: 新媒体矩阵更新时间
+ * @author zwq
+ * @date 2022/8/12 17:14
+ */
+@RestController
+@RequestMapping("wOfa")
+@AllArgsConstructor
+public class WOfaController {
+
+    private final WOfaService wOfaService;
+
+    /**
+     * description: 分页
+     * @author zwq
+     * @date 2022/8/12 17:15
+     * @param page 分页参数
+     * @param limit 分页参数
+     * @param wName 公众号
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    @GetMapping("/page")
+    public Map<String,Object> page(Integer page, Integer limit, String wName) {
+        if (Blank.isEmpty(page, limit)) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
+        }
+        return wOfaService.page(page, limit, wName);
+    }
+
+    /**
+     * description: 更新时间
+     * @author zwq
+     * @date 2022/8/12 17:16
+     * @param wOfaDO 时间
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    @PostMapping("/update")
+    public Map<String,Object> update(WOfaDO wOfaDO) {
+        if (Blank.isEmpty(wOfaDO)) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
+        }
+        if (Blank.isEmpty(wOfaDO.getId(), wOfaDO.getUpdateTime()) ||
+                !DateUtil.isValidDate(wOfaDO.getUpdateTime(), "yyyy-MM-dd")) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
+        }
+        return wOfaService.updateTime(wOfaDO);
+    }
+
+    /**
+     * description: EXCEL批量更新
+     * @author zwq
+     * @date 2022/8/15 11:15
+     * @param file 文件
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    @PostMapping("/update/batch")
+    public Map<String,Object> page(MultipartFile file) throws Exception {
+        if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) {
+            return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
+        }
+        return wOfaService.updateBatchByExcel(file);
+    }
+
+}

+ 74 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/WOfaDao.java

@@ -0,0 +1,74 @@
+package com.example.nngkxxdp.dao;
+
+import com.example.nngkxxdp.entity.WOfaDO;
+import com.example.nngkxxdp.entity.WOfaExcelDTO;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * description: 新媒体矩阵更新时间
+ * @author zwq
+ * @date 2022/8/12 17:04
+ */
+@Repository
+public interface WOfaDao {
+
+    /**
+     * description: 分页计数
+     * @author zwq
+     * @date 2022/8/12 16:44
+     * @param wName 公众号
+     * @return long 计数
+     */
+    long pageCount(@Param("wName") String wName);
+
+    /**
+     * description: 分页
+     * @author zwq
+     * @date 2022/8/12 16:46
+     * @param startRows 分页参数
+     * @param limit 分页参数
+     * @param wName 公众号
+     * @return java.util.List<com.example.nngkxxdp.entity.WOfa>
+     */
+    List<WOfaDO> pageList(Integer startRows, Integer limit, String wName);
+
+    /**
+     * description: 查询单个
+     * @author zwq
+     * @date 2022/8/12 17:31
+     * @param id 主键
+     * @return com.example.nngkxxdp.entity.WOfaDO
+     */
+    WOfaDO selectOne(@Param("id") Integer id);
+
+    /**
+     * description: 更新时间
+     * @author zwq
+     * @date 2022/8/12 17:06
+     * @param wOfaDO 实体
+     * @return java.lang.Integer
+     */
+    Integer update(WOfaDO wOfaDO);
+
+    /**
+     * description: 更新计数
+     * @author zwq
+     * @date 2022/8/15 13:56
+     * @param entities 列表
+     * @return long
+     */
+    long updateCount(@Param("entities") List<WOfaExcelDTO> entities);
+
+    /**
+     * description: 批量更新时间
+     * @author zwq
+     * @date 2022/8/12 17:07
+     * @param entities 实体列表
+     * @return long
+     */
+    long updateBatchByExcel(@Param("entities") List<WOfaExcelDTO> entities);
+
+}

+ 76 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/WOfaDO.java

@@ -0,0 +1,76 @@
+package com.example.nngkxxdp.entity;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * description: 新媒体矩阵更新时间
+ * @author zwq
+ * @date 2022/8/12 17:01
+ */
+@Data
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+public class WOfaDO implements Serializable {
+
+    private static final long serialVersionUID = 5486048467013889321L;
+
+    /**
+     * id
+     */
+    private Integer id;
+
+
+    /**
+     * 公众号
+     */
+    private String wName;
+
+    /**
+     * 最近更新时间
+     */
+    private String updateTime;
+
+    /**
+     * 平台类型
+     */
+    private String wType;
+
+    /**
+     * 工作人员电话
+     */
+    private String staffPhone;
+
+    /**
+     * 领导电话
+     */
+    private String leadPhone;
+
+    /**
+     * 工作人员名字
+     */
+    private String staffName;
+
+    /**
+     * 领导名字
+     */
+    private String leadName;
+
+    /**
+     * 头像图片路径
+     */
+    private String wxHead;
+
+    /**
+     * 二维码图片路径
+     */
+    private String wxQrCode;
+
+    /**
+     * 微博秀路径
+     */
+    private String weiboXiu;
+
+
+}

+ 45 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/WOfaExcelDTO.java

@@ -0,0 +1,45 @@
+package com.example.nngkxxdp.entity;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * description: 新媒体矩阵更新时间EXCEL传输
+ * @author zwq
+ * @date 2022/8/12 17:01
+ */
+@Data
+public class WOfaExcelDTO implements Serializable {
+
+    private static final long serialVersionUID = 8739218754123649072L;
+
+    /**
+     * id
+     */
+    @ExcelIgnore
+    private Integer id;
+
+
+    /**
+     * 公众号
+     */
+    @ExcelProperty(value = "公众号")
+    private String wName;
+
+    /**
+     * 最近更新时间
+     */
+    @ExcelProperty(value = "更新时间")
+    private String updateTime;
+
+    /**
+     * 平台类型
+     */
+    @ExcelProperty(value = "平台")
+    private String wType;
+
+}

+ 22 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/service/SortArticleHeadlinesService.java

@@ -3,6 +3,7 @@ package com.example.nngkxxdp.service;
 import com.example.nngkxxdp.entity.SortArticleHeadlinesDO;
 
 import com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 import java.util.Map;
@@ -53,13 +54,32 @@ public interface SortArticleHeadlinesService {
      * @return java.util.Map<java.lang.String,java.lang.Object>
      */
     Map<String, Object> deleteArticleById(Integer id);
+
+    /**
+     * description: 批量从EXCEL插入数据
+     * @author zwq
+     * @date 2022/8/15 9:41
+     * @param file 文件
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    Map<String, Object> addBatchByExcel(MultipartFile file);
+
+    /**
+     * description: 获取EXCEL中的列表
+     * @author zwq
+     * @date 2022/8/15 9:23
+     * @param file 文件
+     * @return java.util.Map
+     */
+    Map<String, Object> getExcelList(MultipartFile file);
+
     /**
-     * description: EXCEL批量新增
+     * description: 批量新增
      * @author zwq
      * @date 2022/8/12 11:06
      * @param list 列表
      * @return java.lang.Integer
      */
-    Integer insertBatchByExcel(List<SortArticleHeadlinesExcelDTO> list);
+    Integer insertBatch(List<SortArticleHeadlinesExcelDTO> list);
 
 }

+ 64 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/WOfaService.java

@@ -0,0 +1,64 @@
+package com.example.nngkxxdp.service;
+
+import com.example.nngkxxdp.entity.WOfaDO;
+import com.example.nngkxxdp.entity.WOfaExcelDTO;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * description: 新媒体矩阵更新时间
+ *
+ * @author zwq
+ * @date 2022/8/12 9:34
+ */
+public interface WOfaService {
+
+    /**
+     * description: 分页
+     * @author zwq
+     * @date 2022/8/12 16:57
+     * @param startRows 分页参数
+     * @param limit 分页参数
+     * @param wName 公众号
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    Map<String, Object> page(Integer startRows, Integer limit, String wName);
+
+    /**
+     * description: 更新时间
+     * @author zwq
+     * @date 2022/8/12 16:59
+     * @param wOfaDO 实体
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    Map<String, Object> updateTime(WOfaDO wOfaDO);
+
+    /**
+     * description: 批量更新EXCEL
+     * @author zwq
+     * @date 2022/8/15 11:09
+     * @param file 文件
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    Map<String, Object> updateBatchByExcel(MultipartFile file) throws Exception;
+
+    /**
+     * description: 获取EXCEL列表
+     * @author zwq
+     * @date 2022/8/15 10:51
+     * @param file 文件
+     * @return List<com.example.nngkxxdp.entity.WOfaExcelDTO>
+     */
+    List<WOfaExcelDTO> getExcelList(MultipartFile file);
+
+    /**
+     * description: 批量更新
+     * @author zwq
+     * @date 2022/8/15 10:53
+     * @param list 列表
+     * @return long
+     */
+    long updateBatch(List<WOfaExcelDTO> list) throws Exception;
+}

+ 53 - 3
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/SortArticleHeadlinesServiceImpl.java

@@ -1,5 +1,8 @@
 package com.example.nngkxxdp.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.converters.string.StringNumberConverter;
+import com.example.nngkxxdp.base.SortArticleHeadlinesExcelListeners;
 import com.example.nngkxxdp.dao.SortArticleHeadlinesDao;
 import com.example.nngkxxdp.entity.SortArticleHeadlinesDO;
 import com.example.nngkxxdp.entity.SortArticleHeadlinesExcelDTO;
@@ -10,7 +13,11 @@ import com.example.nngkxxdp.util.SendUtil;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -131,7 +138,51 @@ public class SortArticleHeadlinesServiceImpl implements SortArticleHeadlinesServ
     }
 
     /**
-     * description: EXCEL批量新增
+     * description: 批量从EXCEL插入数据
+     *
+     * @param file 文件
+     * @return java.util.Map<java.lang.String, java.lang.Object>
+     * @author zwq
+     * @date 2022/8/15 9:41
+     */
+    @Override
+    public Map<String, Object> addBatchByExcel(MultipartFile file) {
+        Map excelMap = this.getExcelList(file);
+        if (Blank.isEmpty(excelMap.get("errorList"))) {
+            this.insertBatch((List<SortArticleHeadlinesExcelDTO>)excelMap.get("rightList"));
+            return SendUtil.send(true, ConstStr.RESULT_SUCCESS);
+        } else {
+            return SendUtil.send(false, ((List<SortArticleHeadlinesExcelDTO>)excelMap.get("errorList")).size());
+        }
+    }
+
+    /**
+     * description: 获取EXCEL中的列表
+     *
+     * @param file 文件
+     * @return java.util.Map
+     * @author zwq
+     * @date 2022/8/15 9:23
+     */
+    @Override
+    public Map<String, Object> getExcelList(MultipartFile file) {
+        Map result = new HashMap(2);
+        result.put("rightList", new ArrayList<SortArticleHeadlinesExcelDTO>());
+        result.put("errorList", new ArrayList<SortArticleHeadlinesExcelDTO>());
+        try {
+            SortArticleHeadlinesExcelListeners listeners = new SortArticleHeadlinesExcelListeners();
+            EasyExcel.read(file.getInputStream(), SortArticleHeadlinesExcelDTO.class, listeners)
+                    .registerConverter(new StringNumberConverter()).sheet().doRead();
+            result.replace("rightList", listeners.getRightList());
+            result.replace("errorList", listeners.getErrorList());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    /**
+     * description: 批量新增
      * @author zwq
      * @date 2022/8/12 11:06
      * @param list 列表
@@ -139,12 +190,11 @@ public class SortArticleHeadlinesServiceImpl implements SortArticleHeadlinesServ
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Integer insertBatchByExcel(List<SortArticleHeadlinesExcelDTO> list) {
+    public Integer insertBatch(List<SortArticleHeadlinesExcelDTO> list) {
         if (Blank.isNotEmpty(list)) {
             return sortArticleHeadlinesDao.insertBatchByExcel(list);
         } else {
             return 0;
         }
-
     }
 }

+ 138 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/WOfaServiceImpl.java

@@ -0,0 +1,138 @@
+package com.example.nngkxxdp.service.impl;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.converters.string.StringNumberConverter;
+import com.example.nngkxxdp.base.WOfaExcelListeners;
+import com.example.nngkxxdp.dao.WOfaDao;
+import com.example.nngkxxdp.entity.WOfaDO;
+import com.example.nngkxxdp.entity.WOfaExcelDTO;
+import com.example.nngkxxdp.service.WOfaService;
+import com.example.nngkxxdp.util.Blank;
+import com.example.nngkxxdp.util.ConstStr;
+import com.example.nngkxxdp.util.SendUtil;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * description: 新媒体矩阵更新时间
+ *
+ * @author zwq
+ * @date 2022/8/12 17:12
+ */
+@Service("WOfaService")
+@AllArgsConstructor
+public class WOfaServiceImpl implements WOfaService {
+
+    private final WOfaDao wOfaDao;
+
+    /**
+     * description: 分页
+     * @author zwq
+     * @date 2022/8/12 16:57
+     * @param startRows 分页参数
+     * @param limit 分页参数
+     * @param wName 公众号
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    @Override
+    public Map<String, Object> page(Integer startRows, Integer limit, String wName) {
+        long count = wOfaDao.pageCount(wName);
+        if (count == 0) {
+            return SendUtil.layuiTable(count, null);
+        }
+        startRows = (startRows - 1) * limit;
+        List<WOfaDO> wOfaDOS = wOfaDao.pageList(startRows, limit, wName);
+        if (!wOfaDOS.isEmpty()) {
+            return SendUtil.layuiTable(count, wOfaDOS);
+        }
+        return SendUtil.send(false, ConstStr.RESULT_FAILED);
+    }
+
+    /**
+     * description: 更新时间
+     * @author zwq
+     * @date 2022/8/12 16:59
+     * @param wOfaDO 实体
+     * @return java.util.Map<java.lang.String,java.lang.Object>
+     */
+    @Override
+    public Map<String, Object> updateTime(WOfaDO wOfaDO) {
+        WOfaDO oldWOfa = wOfaDao.selectOne(wOfaDO.getId());
+        // 更新时间
+        oldWOfa.setUpdateTime(wOfaDO.getUpdateTime());
+        if (wOfaDao.update(oldWOfa) <= 0) {
+            return SendUtil.send(false, ConstStr.RESULT_FAILED);
+        }
+        return SendUtil.send(true, ConstStr.RESULT_SUCCESS);
+    }
+
+    /**
+     * description: 批量更新EXCEL
+     *
+     * @param file 文件
+     * @return java.util.Map<java.lang.String, java.lang.Object>
+     * @author zwq
+     * @date 2022/8/15 11:09
+     */
+    @Override
+    public Map<String, Object> updateBatchByExcel(MultipartFile file) throws Exception {
+        List<WOfaExcelDTO> list = this.getExcelList(file);
+        long updateNum = this.updateBatch(list);
+        return SendUtil.send(true, updateNum);
+    }
+
+    /**
+     * description: 获取EXCEL列表
+     *
+     * @param file 文件
+     * @return java.util.List<com.example.nngkxxdp.entity.WOfaExcelDTO>
+     * @author zwq
+     * @date 2022/8/15 10:51
+     */
+    @Override
+    public List<WOfaExcelDTO> getExcelList(MultipartFile file) {
+        List<WOfaExcelDTO> list = new ArrayList<>();
+        try {
+            WOfaExcelListeners listeners = new WOfaExcelListeners();
+            EasyExcel.read(file.getInputStream(), WOfaExcelDTO.class, listeners)
+                    .registerConverter(new StringNumberConverter()).sheet().doRead();
+            list = listeners.getList();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return list;
+    }
+
+    /**
+     * description: 批量更新
+     *
+     * @param list 列表
+     * @return long
+     * @author zwq
+     * @date 2022/8/15 10:53
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public long updateBatch(List<WOfaExcelDTO> list) throws Exception {
+        if (Blank.isNotEmpty(list)) {
+            long count = wOfaDao.updateCount(list);
+            if (count > (long) list.size()) {
+                throw new Exception("请确保数据库中不存在重复数据(校验公众号和平台名)");
+            } else if(count < (long) list.size()) {
+                throw new Exception("存在数据在数据库查询不到,请确保EXCEL中公众号和平台名正确");
+            } else {
+                wOfaDao.updateBatchByExcel(list);
+                return count;
+            }
+        } else {
+            return 0L;
+        }
+    }
+}

+ 29 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/DateUtil.java

@@ -107,6 +107,35 @@ public class DateUtil {
 		return now;
 	}
 
+	/**
+	 * description: 判断字符串是否符合时间格式
+	 * @author zwq
+	 * @date 2022/8/12 17:49
+	 * @param dateStr 时间字符串
+	 * @param formatStr 时间字符串格式
+	 * @return boolean
+	 */
+	public static boolean isValidDate(String dateStr, String formatStr){
+		//判断结果 默认为true
+		boolean judgeresult=true;
+		//1、首先使用SimpleDateFormat初步进行判断,过滤掉注入 yyyy-01-32 或yyyy-00-0x等格式
+		//此处可根据实际需求进行调整,如需判断yyyy/MM/dd格式将参数改掉即可
+		SimpleDateFormat format = new SimpleDateFormat(formatStr);
+		try{
+			//增加强判断条件,否则 诸如2022-02-29也可判断出去
+			format.setLenient(false);
+			Date date =format.parse(dateStr);
+		}catch(Exception e){
+			judgeresult=false;
+		}
+		//由于上述方法只能验证正常的日期格式,像诸如 0001-01-01、11-01-01,10001-01-01等无法校验,此处再添加校验年费是否合法
+		String yearStr=dateStr.split("-")[0];
+		if(yearStr.startsWith("0")||yearStr.length()!=4){
+			judgeresult=false;
+		}
+		return judgeresult;
+	}
+
 	public static void main(String[] args) {
 		System.err.println(getCurrentQuarterStartTime(new Date()));
 	}

+ 3 - 3
nngkxxdp/src/main/resources/mapper/SortArticleHeadlinesDao.xml

@@ -21,8 +21,8 @@
     </update>
 
     <select id="pageCount" resultType="java.lang.Long">
-        select count(*)
-        from sort_article_headlines
+        SELECT count(*)
+        FROM sort_article_headlines
         <where>
             is_deleted = 0
             <if test="officialAccount != null">
@@ -53,7 +53,7 @@
             </if>
         </where>
         ORDER BY create_time DESC
-        limit #{startRows},#{limit}
+        LIMIT #{startRows},#{limit}
     </select>
 
     <insert id="insertBatchByExcel" keyProperty="id" useGeneratedKeys="true">

+ 78 - 0
nngkxxdp/src/main/resources/mapper/WOfaDao.xml

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.nngkxxdp.dao.WOfaDao">
+
+    <select id="pageCount" resultType="java.lang.Long">
+        SELECT count(*)
+        FROM w_ofa
+        <where>
+            <if test="wName != null">
+                AND w_name LIKE CONCAT('%', #{wName}, '%')
+            </if>
+        </where>
+    </select>
+
+    <select id="pageList" resultType="com.example.nngkxxdp.entity.WOfaDO">
+        SELECT
+        id,
+        w_name AS wName,
+        update_time AS updateTime,
+        w_type AS wType
+        FROM w_ofa
+        <where>
+            <if test="wName != null">
+                AND w_name LIKE CONCAT('%', #{wName}, '%')
+            </if>
+        </where>
+        ORDER BY w_type
+        LIMIT #{startRows},#{limit}
+    </select>
+
+    <select id="selectOne" resultType="com.example.nngkxxdp.entity.WOfaDO">
+        SELECT
+        id,
+        w_name AS wName,
+        update_time AS updateTime,
+        w_type AS wType,
+        staff_phone AS staffPhone,
+        lead_phone AS leadPhone,
+        staff_name AS staffName,
+        lead_name AS leadName,
+        wx_head AS wxHead,
+        wx_qr_code AS wxQrCode,
+        weibo_xiu AS weiboXiu
+        FROM w_ofa
+        WHERE
+        id = #{id}
+    </select>
+
+    <update id="update">
+        UPDATE w_ofa
+        SET update_time = #{updateTime}
+        WHERE id = #{id}
+    </update>
+
+    <select id="updateCount" resultType="java.lang.Long">
+        SELECT count(*)
+        FROM w_ofa
+        WHERE
+        <foreach collection="entities" item="entity" separator=" or ">
+            (w_name = #{entity.wName}
+            AND w_type = #{entity.wType})
+        </foreach>
+    </select>
+
+    <update id="updateBatchByExcel">
+        <foreach collection="entities" item="entity" separator=";">
+            UPDATE w_ofa
+            <set >
+                <if test="entity.updateTime != null" >
+                    update_time = #{entity.updateTime},
+                </if>
+            </set>
+            WHERE w_name = #{entity.wName}
+            AND w_type = #{entity.wType}
+        </foreach>
+    </update>
+
+</mapper>