diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java new file mode 100644 index 0000000000..fcefbdf2ca --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/UniqueIdGenerator.java @@ -0,0 +1,81 @@ +package com.epmet.commons.tools.utils; + + +import org.apache.commons.lang3.StringUtils; + +import java.util.Date; +import java.util.Random; +import java.util.concurrent.atomic.AtomicLong; + +/** + * 唯一ID生成器 + */ +public class UniqueIdGenerator { + + private static UniqueValue uniqueValue = new UniqueValue(); + private static String middle; + static { + String threadCode = StringUtils.right(String.valueOf(Math.abs(System.nanoTime()+"".hashCode())), 2); + middle = StringUtils.leftPad(threadCode, 2, "0"); + } + + /** + * 唯一时间值 + */ + private static class UniqueValue { + + private AtomicLong uniqueValue = new AtomicLong(0L); + private volatile String currentTime = DateUtils.format(new Date(), DateUtils.DATE_TIME_NO_SPLIT); + private volatile String lastTime = currentTime; + + /** + * 获取当前时间:yyyyMMddHHmmSS + * 如果到了下一秒,则唯一值从0开始 + * + * @return + */ + public String getCurrentTime() { + currentTime = DateUtils.format(new Date(), DateUtils.DATE_TIME_NO_SPLIT); + if (!currentTime.equals(lastTime)) { + lastTime = currentTime; + Random random = new Random(); + uniqueValue.set(Long.valueOf(random.nextInt(10))); + } + return currentTime; + } + + public String getCurrentValue() { + return StringUtils.leftPad(String.valueOf(uniqueValue.incrementAndGet()), 5, "0"); + } + } + + /** + * 生成一个24位唯一ID + * 15位时间+2位中间值(防止多服务冲突)+2个线程code+5位秒级递增值 + * + * @return + */ + public static String generate() { + StringBuilder builder = new StringBuilder(32); + builder.append(uniqueValue.getCurrentTime()) + .append(middle) + .append(getUniqueThreadCode()) + .append(uniqueValue.getCurrentValue()); + + return builder.toString(); + } + + public static String getUniqueThreadCode() { + String threadCode = StringUtils.left(String.valueOf(Thread.currentThread().hashCode()), 2); + return StringUtils.leftPad(threadCode, 2, "0"); + } + + public static void main(String[] args) throws InterruptedException { + + System.out.println(UniqueIdGenerator.uniqueValue.currentTime); + System.out.println(UniqueIdGenerator.middle); + System.out.println(UniqueIdGenerator.getUniqueThreadCode()); + System.out.println(uniqueValue.getCurrentValue()); + + } +} diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexDictDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexDictDTO.java new file mode 100644 index 0000000000..7ca7e42117 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexDictDTO.java @@ -0,0 +1,97 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.screen; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 评价指标字典 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +public class IndexDictDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + private String id; + + /** + * 指标编码(唯一) + */ + private String indexCode; + + /** + * 指标名 + */ + private String indexName; + + /** + * 指标描述 + */ + private String indexDesc; + + /** + * 父级指标id,如果是一级指标,PID=0 + */ + private String pid; + + /** + * 指标级别(1,2,3,4,5) + */ + private String level; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDTO.java new file mode 100644 index 0000000000..19ee948d15 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDTO.java @@ -0,0 +1,92 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.screen; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +public class IndexGroupDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 指标id + */ + private String indexCode; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + + /** + * 当前指标关联的上一级指标分组,如果没有上一级,则为0 + */ + private String parentIndexGroupId; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDetailDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDetailDTO.java new file mode 100644 index 0000000000..e6335250eb --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDetailDTO.java @@ -0,0 +1,92 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.screen; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +public class IndexGroupDetailDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + private String id; + + /** + * index_group.id + */ + private String indexGroupId; + + /** + * 指标id + */ + private String indexCode; + + /** + * 权重(同一组权重总和=1) + */ + private BigDecimal weight; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDetailTemplateDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDetailTemplateDTO.java new file mode 100644 index 0000000000..e82b7b4588 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/IndexGroupDetailTemplateDTO.java @@ -0,0 +1,92 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto.screen; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +public class IndexGroupDetailTemplateDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + private String id; + + /** + * index_group.id + */ + private String indexGroupId; + + /** + * 指标id + */ + private String indexCode; + + /** + * 权重(同一组权重总和=1) + */ + private BigDecimal weight; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/pom.xml b/epmet-module/data-statistical/data-statistical-server/pom.xml index cf116c4fb7..95c74f75d1 100644 --- a/epmet-module/data-statistical/data-statistical-server/pom.xml +++ b/epmet-module/data-statistical/data-statistical-server/pom.xml @@ -74,6 +74,25 @@ 2.0.0 compile + + + + + org.apache.poi + poi + 3.17 + + + + org.apache.poi + poi-ooxml + 3.17 + + + com.alibaba + easyexcel + 2.2.6 + diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexDictController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexDictController.java new file mode 100644 index 0000000000..217867ea32 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexDictController.java @@ -0,0 +1,68 @@ +package com.epmet.controller; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.read.metadata.ReadSheet; +import com.epmet.commons.tools.utils.Result; +import com.epmet.model.IndexExcelDataListener; +import com.epmet.model.IndexModel; +import com.epmet.service.screen.IndexDictService; +import com.epmet.service.screen.IndexGroupDetailTemplateService; +import com.epmet.service.screen.IndexGroupTemplateService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; + +/** + * @author liujianjun + */ +@RequestMapping("indexdict") +@RestController +@Slf4j +public class IndexDictController { + + @Autowired + private IndexDictService indexDictService; + @Autowired + private IndexGroupTemplateService indexGroupTemplateService; + @Autowired + private IndexGroupDetailTemplateService indexGroupDetailTemplateService; + + /** + * url:http://localhost:8108/data/stats/indexdict/initFromExcel + * desc:从excel初始化指标,分组,权重 + * + * @param file + * @return + */ + @PostMapping("initFromExcel") + public Result testTx(@RequestPart("file") MultipartFile file) { + ExcelReader excelReader = null; + try { + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + return new Result().error("读取文件失败"); + } + excelReader = EasyExcel.read(inputStream).build(); + // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener + ReadSheet readSheet = EasyExcel.readSheet(1).head(IndexModel.class) + .registerReadListener(new IndexExcelDataListener(indexDictService, indexGroupTemplateService, indexGroupDetailTemplateService)) + .build(); + excelReader.read(readSheet); + } finally { + if (excelReader != null) { + excelReader.finish(); + } + } + return new Result<>(); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexDictDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexDictDao.java new file mode 100644 index 0000000000..7aa2ab9733 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexDictDao.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.screen; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.screen.IndexDictEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 评价指标字典 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Mapper +public interface IndexDictDao extends BaseDao { + + int deleteAll(); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDao.java new file mode 100644 index 0000000000..10033b7456 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.screen; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.screen.IndexGroupEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Mapper +public interface IndexGroupDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java new file mode 100644 index 0000000000..1a7dd4a0a8 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.screen; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.screen.IndexGroupDetailEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Mapper +public interface IndexGroupDetailDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailTemplateDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailTemplateDao.java new file mode 100644 index 0000000000..cfe5270615 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupDetailTemplateDao.java @@ -0,0 +1,35 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.screen; + + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.screen.IndexGroupDetailTemplateEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Mapper +public interface IndexGroupDetailTemplateDao extends BaseDao { + + int deleteAll(); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupTemplateDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupTemplateDao.java new file mode 100644 index 0000000000..6f64a61349 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/screen/IndexGroupTemplateDao.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.screen; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.screen.IndexGroupTemplateEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 默认指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Mapper +public interface IndexGroupTemplateDao extends BaseDao { + + int deleteAll(); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexDictEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexDictEntity.java new file mode 100644 index 0000000000..2ea5745dba --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexDictEntity.java @@ -0,0 +1,53 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.screen; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 评价指标字典 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("index_dict") +public class IndexDictEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 指标名 + */ + private String indexName; + + /** + * 指标描述 + */ + private String indexDesc; + + /** + * 指标级别(1,2,3,4,5) + */ + private String level; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupDetailEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupDetailEntity.java new file mode 100644 index 0000000000..e17ba9b2b2 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupDetailEntity.java @@ -0,0 +1,60 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.screen; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("index_group_detail") +public class IndexGroupDetailEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * index_group.id + */ + private String indexGroupId; + + /** + * 指标id + */ + private String indexId; + + /** + * 权重(同一组权重总和=1) + */ + private BigDecimal weight; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupDetailTemplateEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupDetailTemplateEntity.java new file mode 100644 index 0000000000..569cda48d9 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupDetailTemplateEntity.java @@ -0,0 +1,65 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.screen; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("index_group_detail_template") +public class IndexGroupDetailTemplateEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * index_group.id + */ + private String indexGroupId; + + /** + * 指标id + */ + private String indexId; + + /** + * 权重(同一组权重总和=1) + */ + private BigDecimal weight; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + + /** + * 阈值 如果是百分比 则为除以100以后的值 + */ + private BigDecimal threshold; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupEntity.java new file mode 100644 index 0000000000..24df1ef18a --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupEntity.java @@ -0,0 +1,58 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.screen; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("index_group") +public class IndexGroupEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * 指标id + */ + private String indexId; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + + /** + * 当前指标关联的上一级指标分组,如果没有上一级,则为0 + */ + private String parentIndexGroupId; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupTemplateEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupTemplateEntity.java new file mode 100644 index 0000000000..3348ebdeda --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/screen/IndexGroupTemplateEntity.java @@ -0,0 +1,53 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.screen; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("index_group_template") +public class IndexGroupTemplateEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 指标id + */ + private String indexId; + + /** + * 是否启用:启用:enable 禁用:disabled + */ + private String status; + + /** + * 当前指标关联的上一级指标分组,如果没有上一级,则为0 + */ + private String parentIndexGroupId; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java new file mode 100644 index 0000000000..76f0897890 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexExcelDataListener.java @@ -0,0 +1,272 @@ +package com.epmet.model; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.utils.UniqueIdGenerator; +import com.epmet.entity.screen.IndexDictEntity; +import com.epmet.entity.screen.IndexGroupDetailTemplateEntity; +import com.epmet.entity.screen.IndexGroupTemplateEntity; +import com.epmet.service.screen.IndexDictService; +import com.epmet.service.screen.IndexGroupDetailTemplateService; +import com.epmet.service.screen.IndexGroupTemplateService; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +/** + * 读取转换异常 + * + * @author Jiaju Zhuang + */ +public class IndexExcelDataListener extends AnalysisEventListener { + private static final Logger LOGGER = LoggerFactory.getLogger(IndexExcelDataListener.class); + /** + * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 + */ + private static volatile boolean isGroup = false; + ; + AtomicInteger total = new AtomicInteger(0); + Map indexDicMap = new HashMap<>(); + Map indexGroupMap = new HashMap<>(); + Map indexGroupDetailMap = new HashMap<>(); + List indexModelList = new ArrayList<>(); + private String preWheight; + + private Integer wheightSum = 0; + /** + * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。 + */ + private IndexDictService indexDictService; + + private IndexGroupTemplateService indexGroupTemplateService; + + private IndexGroupDetailTemplateService indexGroupDetailTemplateService; + + + /** + * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来 + * + * @param indexDictService + */ + public IndexExcelDataListener(IndexDictService indexDictService, IndexGroupTemplateService indexGroupTemplateService, IndexGroupDetailTemplateService indexGroupDetailTemplateService) { + this.indexDictService = indexDictService; + this.indexGroupTemplateService = indexGroupTemplateService; + this.indexGroupDetailTemplateService = indexGroupDetailTemplateService; + } + + /** + * 这个每一条数据解析都会来调用 + * + * @param data one row value. Is is same as {@link AnalysisContext#readRowHolder()} + * @param context + */ + @Override + public void invoke(IndexModel data, AnalysisContext context) { + if (data == null || data.getIsUsed() == null || data.getIsUsed() != 1) { + return; + } + + //合并单元格的 权重 处理 + String weight = data.getWeight(); + if (StringUtils.isNotBlank(weight)) { + weight = weight.replace("%", ""); + data.setWeight(weight); + preWheight = data.getWeight(); + } else { + data.setWeight(preWheight); + } + LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); + + IndexDictEntity entity = new IndexDictEntity(); + IndexDictEntity entity2 = new IndexDictEntity(); + IndexDictEntity entity3 = new IndexDictEntity(); + IndexDictEntity entity4 = new IndexDictEntity(); + IndexDictEntity entity5 = new IndexDictEntity(); + + indexModelList.add(data); + buildIndexDicEntity(data, entity, entity2, entity3, entity4, entity5); + + buildIndexGroupEntity(); + + total.addAndGet(1); + + + // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM + /*if (isGroup) { + saveData(); + // 存储完成清理 list + list.clear(); + }*/ + } + + private void buildIndexGroupEntity() { + List collect = indexModelList.stream().sorted(Comparator.comparing(IndexModel::getLevel1Index)).collect(Collectors.toList()); + collect.forEach(index -> { + if (index.getLevel1Index().equals("党员相关")) { + IndexDictEntity indexDictEntity = indexDicMap.get(index.getLevel1Index()); + String level1GroupId = UniqueIdGenerator.generate(); + IndexGroupTemplateEntity group1 = indexGroupMap.get(index.getLevel1Index()); + if (group1 == null) { + group1 = new IndexGroupTemplateEntity(); + group1.setIndexId(indexDictEntity.getId()); + group1.setParentIndexGroupId("0"); + group1.setId(level1GroupId); + indexGroupMap.put(index.getLevel1Index(), group1); + } + + String level4Index = index.getLevel4Index(); + indexDictEntity = indexDicMap.get(level4Index); + String level2GroupId = UniqueIdGenerator.generate(); + + IndexGroupTemplateEntity group2 = indexGroupMap.get(level4Index); + IndexGroupDetailTemplateEntity templateEntity = null; + if (group2 == null) { + group2 = new IndexGroupTemplateEntity(); + group2.setIndexId(indexDictEntity.getId()); + group2.setParentIndexGroupId(level1GroupId); + group2.setId(level2GroupId); + indexGroupMap.put(level4Index, group2); + //构建 分组明细 + templateEntity = indexGroupDetailMap.get(level4Index); + if (templateEntity == null) { + buildIndexGroupDetail(indexDictEntity, index, group1.getId(), 2); + } + } + indexDictEntity = indexDicMap.get(index.getLevel5Index()); + + templateEntity = indexGroupDetailMap.get(index.getLevel5Index()); + if (templateEntity == null) { + buildIndexGroupDetail(indexDictEntity, index, group2.getId(), 5); + } + } else { + //todo 测试完去掉 + //if ("街道相关".equals(index.getLevel1Index())) { + IndexDictEntity indexDictEntity = indexDicMap.get(index.getLevel1Index()); + String level1GroupId = UniqueIdGenerator.generate(); + IndexGroupTemplateEntity group1 = indexGroupMap.get(index.getLevel1Index()); + if (group1 == null) { + group1 = new IndexGroupTemplateEntity(); + group1.setIndexId(indexDictEntity.getId()); + group1.setParentIndexGroupId("0"); + group1.setId(level1GroupId); + indexGroupMap.put(index.getLevel1Index(), group1); + } + + String level2Index = index.getLevel2Index(); + indexDictEntity = indexDicMap.get(level2Index); + String level2GroupId = UniqueIdGenerator.generate(); + + IndexGroupTemplateEntity group2 = indexGroupMap.get(level2Index); + IndexGroupDetailTemplateEntity templateEntity = null; + if (group2 == null) { + group2 = new IndexGroupTemplateEntity(); + group2.setIndexId(indexDictEntity.getId()); + group2.setParentIndexGroupId(level1GroupId); + group2.setId(level2GroupId); + indexGroupMap.put(level2Index, group2); + //构建 分组明细 + templateEntity = indexGroupDetailMap.get(level2Index); + if (templateEntity == null) { + buildIndexGroupDetail(indexDictEntity, index, group1.getId(), 2); + } + } + indexDictEntity = indexDicMap.get(index.getLevel5Index()); + + templateEntity = indexGroupDetailMap.get(index.getLevel5Index()); + if (templateEntity == null) { + buildIndexGroupDetail(indexDictEntity, index, group2.getId(), 5); + } + } + //} + }); + LOGGER.info("所有指标分组数据解析完成:{}", JSON.toJSONString(indexGroupMap.values())); + LOGGER.info("所有指标分组明细数据解析完成:{}", JSON.toJSONString(indexGroupDetailMap.values())); + } + + private void buildIndexGroupDetail(IndexDictEntity indexDictEntity, IndexModel index, String groupId, Integer level) { + IndexGroupDetailTemplateEntity templateEntity; + templateEntity = new IndexGroupDetailTemplateEntity(); + templateEntity.setIndexGroupId(groupId); + templateEntity.setIndexId(indexDictEntity.getId()); + + if (level == 5) { + String level5WeightStr = index.getLevel5Weight().replace("%", ""); + templateEntity.setWeight(new BigDecimal(level5WeightStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)); + indexGroupDetailMap.put(index.getLevel5Index(), templateEntity); + } else { + indexGroupDetailMap.put(indexDictEntity.getIndexName(), templateEntity); + templateEntity.setWeight(new BigDecimal(index.getWeight()).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)); + } + templateEntity.setId(UniqueIdGenerator.generate()); + if (StringUtils.isNotBlank(index.getThreshold())) { + String thresholdStr = index.getThreshold().replace("%", ""); + templateEntity.setThreshold(new BigDecimal(thresholdStr).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)); + } + } + + private void buildIndexDicEntity(IndexModel data, IndexDictEntity entity, IndexDictEntity entity2, IndexDictEntity entity3, IndexDictEntity entity4, IndexDictEntity entity5) { + if (!indexDicMap.containsKey(data.getLevel1Index())) { + entity.setId(UniqueIdGenerator.generate()); + entity.setIndexName(data.getLevel1Index()); + entity.setLevel("1"); + indexDicMap.put(data.getLevel1Index(), entity); + } + if (!indexDicMap.containsKey(data.getLevel2Index())) { + entity2.setId(UniqueIdGenerator.generate()); + entity2.setIndexName(data.getLevel2Index()); + entity2.setLevel("2"); + indexDicMap.put(data.getLevel2Index(), entity2); + } + if (!indexDicMap.containsKey(data.getLevel3Index())) { + entity3.setId(UniqueIdGenerator.generate()); + entity3.setIndexName(data.getLevel3Index()); + entity3.setLevel("3"); + indexDicMap.put(data.getLevel3Index(), entity3); + } + if (!indexDicMap.containsKey(data.getLevel4Index())) { + entity4.setId(UniqueIdGenerator.generate()); + entity4.setIndexName(data.getLevel4Index()); + entity4.setLevel("4"); + indexDicMap.put(data.getLevel4Index(), entity4); + } + if (!indexDicMap.containsKey(data.getLevel5Index())) { + entity5.setId(UniqueIdGenerator.generate()); + entity5.setIndexName(data.getLevel5Index()); + entity5.setLevel("5"); + indexDicMap.put(data.getLevel5Index(), entity5); + } + } + + /** + * 所有数据解析完成了 都会来调用 + * + * @param context + */ + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + // 这里也要保存数据,确保最后遗留的数据也存储到数据库 + saveData(); + LOGGER.info("所有数据解析完成!total:{}", total.intValue()); + } + + /** + * 加上存储数据库 + */ + private void saveData() { + LOGGER.info("{}条数据,开始存储数据库!", indexDicMap.size()); + indexDictService.deleteAndInsertBatch(indexDicMap.values()); + + buildIndexGroupEntity(); + + indexGroupTemplateService.deleteAndInsertBatch(indexGroupMap.values()); + indexGroupDetailTemplateService.deleteAndInsertBatch(indexGroupDetailMap.values()); + LOGGER.info("存储数据库成功!指标:{}个,分组:{}个,详情:{}个", indexDicMap.values().size(), indexGroupMap.values().size(), indexGroupDetailMap.values().size()); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java new file mode 100644 index 0000000000..f264a2c39e --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/IndexModel.java @@ -0,0 +1,26 @@ +package com.epmet.model; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +@Data +public class IndexModel { + @ExcelProperty(value = "一级指标") + private String level1Index; + @ExcelProperty(value = "二级指标") + private String level2Index; + @ExcelProperty(value = "三级指标") + private String level3Index; + @ExcelProperty(value = "四级指标") + private String level4Index; + @ExcelProperty(value = "五级指标") + private String level5Index; + @ExcelProperty(value = "是否采用") + private Integer isUsed; + @ExcelProperty(value = "权重") + private String weight; + @ExcelProperty(value = "五级权重") + private String level5Weight; + @ExcelProperty(value = "阈值") + private String threshold; +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/ParseIndexExcelResult.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/ParseIndexExcelResult.java new file mode 100644 index 0000000000..17b4fa0634 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/model/ParseIndexExcelResult.java @@ -0,0 +1,54 @@ +package com.epmet.model; + +import lombok.Data; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +@Data +public class ParseIndexExcelResult implements Serializable { + private String id; + private String groupId; + /** + * 当前指标关联的上一级指标分组,如果没有上一级,则为0 + */ + private String parentIndexGroupId; + /** + * 指标编码(唯一) + */ + private String indexCode; + + /** + * 指标名 + */ + private String indexName; + + /** + * 指标描述 + */ + private String indexDesc; + + /** + * 指标级别(1,2,3,4,5) + */ + private String level; + + private Set children = new HashSet<>(); + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ParseIndexExcelResult that = (ParseIndexExcelResult) o; + return indexCode.equals(that.indexCode) && + indexName.equals(that.indexName) && + level.equals(that.level); + } + + @Override + public int hashCode() { + return Objects.hash(indexCode, indexName, indexDesc, level); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexDictService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexDictService.java new file mode 100644 index 0000000000..9e3b4f83ed --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexDictService.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.screen.IndexDictEntity; + +import java.util.Collection; + +/** + * 评价指标字典 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +public interface IndexDictService extends BaseService { + + Boolean deleteAndInsertBatch(Collection values); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java new file mode 100644 index 0000000000..ea03e298a1 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailService.java @@ -0,0 +1,31 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.screen.IndexGroupDetailEntity; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +public interface IndexGroupDetailService extends BaseService { + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailTemplateService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailTemplateService.java new file mode 100644 index 0000000000..3b0c48f7f9 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupDetailTemplateService.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.screen.IndexGroupDetailTemplateEntity; + +import java.util.Collection; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +public interface IndexGroupDetailTemplateService extends BaseService { + + Boolean deleteAndInsertBatch(Collection values); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupService.java new file mode 100644 index 0000000000..f2ee989bea --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupService.java @@ -0,0 +1,31 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.screen.IndexGroupEntity; + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +public interface IndexGroupService extends BaseService { + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupTemplateService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupTemplateService.java new file mode 100644 index 0000000000..1f23716176 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/IndexGroupTemplateService.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.screen.IndexGroupTemplateEntity; + +import java.util.Collection; + +/** + * 默认指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +public interface IndexGroupTemplateService extends BaseService { + + Boolean deleteAndInsertBatch(Collection values); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexDictServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexDictServiceImpl.java new file mode 100644 index 0000000000..16e4815226 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexDictServiceImpl.java @@ -0,0 +1,43 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen.impl; + +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.screen.IndexDictDao; +import com.epmet.entity.screen.IndexDictEntity; +import com.epmet.service.screen.IndexDictService; +import org.springframework.stereotype.Service; + +import java.util.Collection; + +/** + * 评价指标字典 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Service +public class IndexDictServiceImpl extends BaseServiceImpl implements IndexDictService { + + + @Override + public Boolean deleteAndInsertBatch(Collection values) { + int n = baseDao.deleteAll(); + return this.insertBatch(values,10); + } +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java new file mode 100644 index 0000000000..db9fe1f411 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailServiceImpl.java @@ -0,0 +1,36 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen.impl; + +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.screen.IndexGroupDetailDao; +import com.epmet.entity.screen.IndexGroupDetailEntity; +import com.epmet.service.screen.IndexGroupDetailService; +import org.springframework.stereotype.Service; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Service +public class IndexGroupDetailServiceImpl extends BaseServiceImpl implements IndexGroupDetailService { + + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailTemplateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailTemplateServiceImpl.java new file mode 100644 index 0000000000..081f94ef3c --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupDetailTemplateServiceImpl.java @@ -0,0 +1,42 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen.impl; + +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.screen.IndexGroupDetailTemplateDao; +import com.epmet.entity.screen.IndexGroupDetailTemplateEntity; +import com.epmet.service.screen.IndexGroupDetailTemplateService; +import org.springframework.stereotype.Service; + +import java.util.Collection; + +/** + * 客户指标详情 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Service +public class IndexGroupDetailTemplateServiceImpl extends BaseServiceImpl implements IndexGroupDetailTemplateService { + + @Override + public Boolean deleteAndInsertBatch(Collection values) { + baseDao.deleteAll(); + return this.insertBatch(values, 10); + } +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java new file mode 100644 index 0000000000..5d12ec33d1 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupServiceImpl.java @@ -0,0 +1,35 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen.impl; + +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.screen.IndexGroupDao; +import com.epmet.entity.screen.IndexGroupEntity; +import com.epmet.service.screen.IndexGroupService; +import org.springframework.stereotype.Service; + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Service +public class IndexGroupServiceImpl extends BaseServiceImpl implements IndexGroupService { + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupTemplateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupTemplateServiceImpl.java new file mode 100644 index 0000000000..058cf911eb --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexGroupTemplateServiceImpl.java @@ -0,0 +1,43 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.screen.impl; + +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.screen.IndexGroupTemplateDao; +import com.epmet.entity.screen.IndexGroupTemplateEntity; +import com.epmet.service.screen.IndexGroupTemplateService; +import org.springframework.stereotype.Service; + +import java.util.Collection; + +/** + * 客户指标分组 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-08-19 + */ +@Service +public class IndexGroupTemplateServiceImpl extends BaseServiceImpl implements IndexGroupTemplateService { + + @Override + public Boolean deleteAndInsertBatch(Collection values) { + + baseDao.deleteAll(); + return this.insertBatch(values, 10); + } +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/ExcelListener.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/ExcelListener.java new file mode 100644 index 0000000000..e8ad7cbe66 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/ExcelListener.java @@ -0,0 +1,17 @@ +package com.epmet.util; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import org.apache.poi.ss.formula.functions.T; + +public class ExcelListener extends AnalysisEventListener { + @Override + public void invoke(T t, AnalysisContext analysisContext) { + + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + System.out.println(analysisContext); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/TestFileUtil.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/TestFileUtil.java new file mode 100644 index 0000000000..865e691e80 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/TestFileUtil.java @@ -0,0 +1,35 @@ +package com.epmet.util; + +import java.io.File; +import java.io.InputStream; + +public class TestFileUtil { + + public static InputStream getResourcesFileInputStream(String fileName) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName); + } + + public static String getPath() { + return TestFileUtil.class.getResource("/").getPath(); + } + + public static File createNewFile(String pathName) { + File file = new File(getPath() + pathName); + if (file.exists()) { + file.delete(); + } else { + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + } + return file; + } + + public static File readFile(String pathName) { + return new File(getPath() + pathName); + } + + public static File readUserHomeFile(String pathName) { + return new File(System.getProperty("user.home") + File.separator + pathName); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexDictDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexDictDao.xml new file mode 100644 index 0000000000..a91513e1d5 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexDictDao.xml @@ -0,0 +1,8 @@ + + + + + + delete from index_dict + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDao.xml new file mode 100644 index 0000000000..06f0cf0198 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDao.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml new file mode 100644 index 0000000000..b7854f3338 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailTemplateDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailTemplateDao.xml new file mode 100644 index 0000000000..ddb138771e --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupDetailTemplateDao.xml @@ -0,0 +1,9 @@ + + + + + + + delete from index_group_detail_template + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupTemplateDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupTemplateDao.xml new file mode 100644 index 0000000000..d527876c4d --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/screen/IndexGroupTemplateDao.xml @@ -0,0 +1,8 @@ + + + + + + delete from index_group_template + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/model/DemoData.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/model/DemoData.java new file mode 100644 index 0000000000..234e66cb58 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/model/DemoData.java @@ -0,0 +1,17 @@ +package com.epmet.stats.test.model; + +import lombok.Data; + +import java.util.Date; + +/** + * 基础数据类.这里的排序和excel里面的排序一致 + * + * @author Jiaju Zhuang + **/ +@Data +public class DemoData { + private String string; + private Date date; + private Double doubleData; +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/model/DemoDataListener.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/model/DemoDataListener.java new file mode 100644 index 0000000000..d218327ad1 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/model/DemoDataListener.java @@ -0,0 +1,84 @@ +package com.epmet.stats.test.model; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSON; +import com.epmet.dao.screen.ScreenCustomerAgencyDao; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * 模板的读取类 + * + * @author Jiaju Zhuang + */ +// 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去 +public class DemoDataListener extends AnalysisEventListener { + private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); + /** + * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 + */ + private static final int BATCH_COUNT = 5; + List list = new ArrayList(); + /** + * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。 + */ + private ScreenCustomerAgencyDao demoDAO; + + public DemoDataListener() { + // 这里是demo,所以随便new一个。实际使用如果到了spring,请使用下面的有参构造函数 + demoDAO = null; + } + + /** + * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来 + * + * @param demoDAO + */ + public DemoDataListener(ScreenCustomerAgencyDao demoDAO) { + this.demoDAO = demoDAO; + } + + /** + * 这个每一条数据解析都会来调用 + * + * @param data + * one row value. Is is same as {@link AnalysisContext#readRowHolder()} + * @param context + */ + @Override + public void invoke(DemoData data, AnalysisContext context) { + LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); + list.add(data); + // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM + if (list.size() >= BATCH_COUNT) { + saveData(); + // 存储完成清理 list + list.clear(); + } + } + + /** + * 所有数据解析完成了 都会来调用 + * + * @param context + */ + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + // 这里也要保存数据,确保最后遗留的数据也存储到数据库 + saveData(); + LOGGER.info("所有数据解析完成!"); + } + + /** + * 加上存储数据库 + */ + private void saveData() { + LOGGER.info("{}条数据,开始存储数据库!", list.size()); + //demoDAO.save(list); + LOGGER.info("存储数据库成功!"); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ConverterData.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ConverterData.java new file mode 100644 index 0000000000..9a9be1642d --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ConverterData.java @@ -0,0 +1,30 @@ +package com.epmet.stats.test.read; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; +import com.alibaba.excel.annotation.format.NumberFormat; +import lombok.Data; + +/** + * 基础数据类.这里的排序和excel里面的排序一致 + * + * @author Jiaju Zhuang + **/ +@Data +public class ConverterData { + /** + * 我自定义 转换器,不管数据库传过来什么 。我给他加上“自定义:” + */ + @ExcelProperty(converter = CustomStringStringConverter.class) + private String string; + /** + * 这里用string 去接日期才能格式化。我想接收年月日格式 + */ + @DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒") + private String date; + /** + * 我想接收百分比的数字 + */ + @NumberFormat("#.##%") + private String doubleData; +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ConverterDataListener.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ConverterDataListener.java new file mode 100644 index 0000000000..7c28d41fe8 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ConverterDataListener.java @@ -0,0 +1,48 @@ +package com.epmet.stats.test.read; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSON; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * 模板的读取类 + * + * @author Jiaju Zhuang + */ +public class ConverterDataListener extends AnalysisEventListener { + private static final Logger LOGGER = LoggerFactory.getLogger(ConverterDataListener.class); + /** + * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 + */ + private static final int BATCH_COUNT = 5; + List list = new ArrayList(); + + @Override + public void invoke(ConverterData data, AnalysisContext context) { + LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); + list.add(data); + if (list.size() >= BATCH_COUNT) { + saveData(); + list.clear(); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + saveData(); + LOGGER.info("所有数据解析完成!"); + } + + /** + * 加上存储数据库 + */ + private void saveData() { + LOGGER.info("{}条数据,开始存储数据库!", list.size()); + LOGGER.info("存储数据库成功!"); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/CustomStringStringConverter.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/CustomStringStringConverter.java new file mode 100644 index 0000000000..584e563a77 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/CustomStringStringConverter.java @@ -0,0 +1,59 @@ +package com.epmet.stats.test.read; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +/** + * String and string converter + * + * @author Jiaju Zhuang + */ +public class CustomStringStringConverter implements Converter { + @Override + public Class supportJavaTypeKey() { + return String.class; + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return CellDataTypeEnum.STRING; + } + + /** + * 这里读的时候会调用 + * + * @param cellData + * NotNull + * @param contentProperty + * Nullable + * @param globalConfiguration + * NotNull + * @return + */ + @Override + public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + return "自定义:" + cellData.getStringValue(); + } + + /** + * 这里是写的时候会调用 不用管 + * + * @param value + * NotNull + * @param contentProperty + * Nullable + * @param globalConfiguration + * NotNull + * @return + */ + @Override + public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + return new CellData(value); + } + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoDAO.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoDAO.java new file mode 100644 index 0000000000..bf09288f59 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoDAO.java @@ -0,0 +1,15 @@ +package com.epmet.stats.test.read; + +import java.util.List; + +/** + * 假设这个是你的DAO存储。当然还要这个类让spring管理,当然你不用需要存储,也不需要这个类。 + * + * @author Jiaju Zhuang + **/ +public class DemoDAO { + + public void save(List list) { + // 如果是mybatis,尽量别直接调用多次insert,自己写一个mapper里面新增一个方法batchInsert,所有数据一次性插入 + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoData.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoData.java new file mode 100644 index 0000000000..ceb3dd37ca --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoData.java @@ -0,0 +1,17 @@ +package com.epmet.stats.test.read; + +import lombok.Data; + +import java.util.Date; + +/** + * 基础数据类.这里的排序和excel里面的排序一致 + * + * @author Jiaju Zhuang + **/ +@Data +public class DemoData { + private String string; + private Date date; + private Double doubleData; +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoDataListener.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoDataListener.java new file mode 100644 index 0000000000..539f1903b0 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/DemoDataListener.java @@ -0,0 +1,97 @@ +package com.epmet.stats.test.read; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.fastjson.JSON; +import com.epmet.model.IndexModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 模板的读取类 + * + * @author Jiaju Zhuang + */ +// 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去 +public class DemoDataListener extends AnalysisEventListener { + private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); + /** + * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 + */ + private static final int BATCH_COUNT = 5; + List list = new ArrayList(); + AtomicInteger total = new AtomicInteger(0); + + private String preWheight; + /** + * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。 + */ + private DemoDAO demoDAO; + + public DemoDataListener() { + // 这里是demo,所以随便new一个。实际使用如果到了spring,请使用下面的有参构造函数 + demoDAO = new DemoDAO(); + } + + /** + * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来 + * + * @param demoDAO + */ + public DemoDataListener(DemoDAO demoDAO) { + this.demoDAO = demoDAO; + } + + /** + * 这个每一条数据解析都会来调用 + * + * @param data + * one row value. Is is same as {@link AnalysisContext#readRowHolder()} + * @param context + */ + @Override + public void invoke(IndexModel data, AnalysisContext context) { + if (data == null || data.getIsUsed() == null || data.getIsUsed() != 1){ + return; + } + if ( data.getWeight() != null){ + preWheight = data.getWeight(); + }else{ + data.setWeight(preWheight); + } + LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data)); + list.add(data); + total.addAndGet(1); + // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM + if (list.size() >= BATCH_COUNT) { + saveData(); + // 存储完成清理 list + list.clear(); + } + } + + /** + * 所有数据解析完成了 都会来调用 + * + * @param context + */ + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + // 这里也要保存数据,确保最后遗留的数据也存储到数据库 + saveData(); + LOGGER.info("所有数据解析完成!total:{}",total.intValue()); + } + + /** + * 加上存储数据库 + */ + private void saveData() { + LOGGER.info("{}条数据,开始存储数据库!", list.size()); + //demoDAO.save(list); + LOGGER.info("存储数据库成功!"); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ReadTest.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ReadTest.java new file mode 100644 index 0000000000..85ee1e7806 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/read/ReadTest.java @@ -0,0 +1,70 @@ +package com.epmet.stats.test.read; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.read.metadata.ReadSheet; +import com.epmet.model.IndexModel; +import com.epmet.util.TestFileUtil; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileNotFoundException; + + +/** + * 读的常见写法 + * + * @author Jiaju Zhuang + */ +@Ignore +public class ReadTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(ReadTest.class); + + + + /** + * 读多个或者全部sheet,这里注意一个sheet不能读取多次,多次读取需要重新读取文件 + *

+ * 1. 创建excel对应的实体对象 参照{@link DemoData} + *

+ * 2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener} + *

+ * 3. 直接读即可 + */ + @Test + public void repeatedRead() throws FileNotFoundException { + String fileName = ""; + /* String fileName = TestFileUtil.getPath() + File.separator + "评价指标体系算法需求-备注.xlsx"; + // 读取全部sheet + // 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写 + EasyExcel.read(fileName, IndexModel.class, new DemoDataListener()).doReadAll(); +*/ + // 读取部分sheet + String excelName = "评价指标体系算法需求-备注.xlsx"; + fileName = TestFileUtil.getPath() + File.separator + excelName; + //fileName = this.getClass().getResource(File.separator).getPath().concat(excelName); + ExcelReader excelReader = null; + try { + //ExcelImportUtil.importExcel(null); + + //EasyExcel.read(new FileInputStream(new File(fileName)),IndexModel.class); + excelReader = EasyExcel.read(fileName).build(); + // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener + ReadSheet readSheet1 = + EasyExcel.readSheet(0).head(IndexModel.class).registerReadListener(new DemoDataListener()).build(); + ReadSheet readSheet2 = + EasyExcel.readSheet(1).head(IndexModel.class).registerReadListener(new DemoDataListener()).build(); + // 这里注意 一定要把sheet1 sheet2 一起传进去,不然有个问题就是03版的excel 会读取多次,浪费性能 + excelReader.read(readSheet2); + } finally { + if (excelReader != null) { + // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的 + excelReader.finish(); + } + } + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/util/TestFileUtil.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/util/TestFileUtil.java new file mode 100644 index 0000000000..5035e52046 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/util/TestFileUtil.java @@ -0,0 +1,35 @@ +package com.epmet.stats.test.util; + +import java.io.File; +import java.io.InputStream; + +public class TestFileUtil { + + public static InputStream getResourcesFileInputStream(String fileName) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName); + } + + public static String getPath() { + return TestFileUtil.class.getResource("/").getPath(); + } + + public static File createNewFile(String pathName) { + File file = new File(getPath() + pathName); + if (file.exists()) { + file.delete(); + } else { + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + } + return file; + } + + public static File readFile(String pathName) { + return new File(getPath() + pathName); + } + + public static File readUserHomeFile(String pathName) { + return new File(System.getProperty("user.home") + File.separator + pathName); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/评价指标体系算法需求-备注.xlsx b/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/评价指标体系算法需求-备注.xlsx new file mode 100644 index 0000000000..592e740466 Binary files /dev/null and b/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/评价指标体系算法需求-备注.xlsx differ