|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|