forked from luyan/epmet-cloud-lingshan
				
			
				 48 changed files with 2276 additions and 0 deletions
			
			
		| @ -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()); | |||
| 
 | |||
|     } | |||
| } | |||
| @ -0,0 +1,97 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,92 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,92 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,92 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -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<String> testTx(@RequestPart("file") MultipartFile file) { | |||
|         ExcelReader excelReader = null; | |||
|         try { | |||
|             InputStream inputStream = null; | |||
|             try { | |||
|                 inputStream = file.getInputStream(); | |||
|             } catch (IOException e) { | |||
|                 return new Result<String>().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<>(); | |||
|     } | |||
| } | |||
| @ -0,0 +1,34 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexDictEntity> { | |||
| 
 | |||
|     int deleteAll(); | |||
| } | |||
| @ -0,0 +1,33 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupEntity> { | |||
| 	 | |||
| } | |||
| @ -0,0 +1,33 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDetailEntity> { | |||
| 	 | |||
| } | |||
| @ -0,0 +1,35 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDetailTemplateEntity> { | |||
| 
 | |||
|     int deleteAll(); | |||
| } | |||
| @ -0,0 +1,34 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupTemplateEntity> { | |||
| 
 | |||
|     int deleteAll(); | |||
| } | |||
| @ -0,0 +1,53 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,60 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,65 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,58 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -0,0 +1,53 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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; | |||
| 
 | |||
| } | |||
| @ -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<IndexModel> { | |||
|     private static final Logger LOGGER = LoggerFactory.getLogger(IndexExcelDataListener.class); | |||
|     /** | |||
|      * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 | |||
|      */ | |||
|     private static volatile boolean isGroup = false; | |||
|     ; | |||
|     AtomicInteger total = new AtomicInteger(0); | |||
|     Map<String, IndexDictEntity> indexDicMap = new HashMap<>(); | |||
|     Map<String, IndexGroupTemplateEntity> indexGroupMap = new HashMap<>(); | |||
|     Map<String, IndexGroupDetailTemplateEntity> indexGroupDetailMap = new HashMap<>(); | |||
|     List<IndexModel> 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<IndexModel> 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()); | |||
|     } | |||
| } | |||
| @ -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; | |||
| } | |||
| @ -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<ParseIndexExcelResult> 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); | |||
|     } | |||
| } | |||
| @ -0,0 +1,34 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexDictEntity> { | |||
| 
 | |||
|     Boolean deleteAndInsertBatch(Collection<IndexDictEntity> values); | |||
| } | |||
| @ -0,0 +1,31 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDetailEntity> { | |||
| 
 | |||
| } | |||
| @ -0,0 +1,34 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDetailTemplateEntity> { | |||
| 
 | |||
|     Boolean deleteAndInsertBatch(Collection<IndexGroupDetailTemplateEntity> values); | |||
| } | |||
| @ -0,0 +1,31 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupEntity> { | |||
| 
 | |||
| } | |||
| @ -0,0 +1,34 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupTemplateEntity> { | |||
| 
 | |||
|     Boolean deleteAndInsertBatch(Collection<IndexGroupTemplateEntity> values); | |||
| } | |||
| @ -0,0 +1,43 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexDictDao, IndexDictEntity> implements IndexDictService { | |||
| 
 | |||
| 
 | |||
|     @Override | |||
|     public Boolean deleteAndInsertBatch(Collection<IndexDictEntity> values) { | |||
|         int n = baseDao.deleteAll(); | |||
|         return this.insertBatch(values,10); | |||
|     } | |||
| } | |||
| @ -0,0 +1,36 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDetailDao, IndexGroupDetailEntity> implements IndexGroupDetailService { | |||
| 
 | |||
| 
 | |||
| } | |||
| @ -0,0 +1,42 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDetailTemplateDao, IndexGroupDetailTemplateEntity> implements IndexGroupDetailTemplateService { | |||
| 
 | |||
|     @Override | |||
|     public Boolean deleteAndInsertBatch(Collection<IndexGroupDetailTemplateEntity> values) { | |||
|         baseDao.deleteAll(); | |||
|         return this.insertBatch(values, 10); | |||
|     } | |||
| } | |||
| @ -0,0 +1,35 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupDao, IndexGroupEntity> implements IndexGroupService { | |||
| 
 | |||
| } | |||
| @ -0,0 +1,43 @@ | |||
| /** | |||
|  * Copyright 2018 人人开源 https://www.renren.io
 | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * 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. | |||
|  * <p> | |||
|  * You should have received a copy of the GNU General Public License | |||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | |||
|  */ | |||
| 
 | |||
| 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<IndexGroupTemplateDao, IndexGroupTemplateEntity> implements IndexGroupTemplateService { | |||
| 
 | |||
|     @Override | |||
|     public Boolean deleteAndInsertBatch(Collection<IndexGroupTemplateEntity> values) { | |||
| 
 | |||
|         baseDao.deleteAll(); | |||
|         return this.insertBatch(values, 10); | |||
|     } | |||
| } | |||
| @ -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<T> { | |||
|     @Override | |||
|     public void invoke(T t, AnalysisContext analysisContext) { | |||
| 
 | |||
|     } | |||
| 
 | |||
|     @Override | |||
|     public void doAfterAllAnalysed(AnalysisContext analysisContext) { | |||
|         System.out.println(analysisContext); | |||
|     } | |||
| } | |||
| @ -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); | |||
|     } | |||
| } | |||
| @ -0,0 +1,8 @@ | |||
| <?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.epmet.dao.screen.IndexDictDao"> | |||
|     <delete id="deleteAll"> | |||
|         delete from index_dict | |||
|     </delete> | |||
| </mapper> | |||
| @ -0,0 +1,7 @@ | |||
| <?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.epmet.dao.screen.IndexGroupDao"> | |||
| 
 | |||
| 
 | |||
| </mapper> | |||
| @ -0,0 +1,6 @@ | |||
| <?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.epmet.dao.screen.IndexGroupDetailDao"> | |||
| 
 | |||
| </mapper> | |||
| @ -0,0 +1,9 @@ | |||
| <?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.epmet.dao.screen.IndexGroupDetailTemplateDao"> | |||
| 
 | |||
|     <delete id="deleteAll"> | |||
|         delete from index_group_detail_template | |||
|     </delete> | |||
| </mapper> | |||
| @ -0,0 +1,8 @@ | |||
| <?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.epmet.dao.screen.IndexGroupTemplateDao"> | |||
|     <delete id="deleteAll"> | |||
|         delete from index_group_template | |||
|     </delete> | |||
| </mapper> | |||
| @ -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; | |||
| } | |||
| @ -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<DemoData> { | |||
|     private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); | |||
|     /** | |||
|      * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 | |||
|      */ | |||
|     private static final int BATCH_COUNT = 5; | |||
|     List<DemoData> list = new ArrayList<DemoData>(); | |||
|     /** | |||
|      * 假设这个是一个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("存储数据库成功!"); | |||
|     } | |||
| } | |||
| @ -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; | |||
| } | |||
| @ -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<ConverterData> { | |||
|     private static final Logger LOGGER = LoggerFactory.getLogger(ConverterDataListener.class); | |||
|     /** | |||
|      * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 | |||
|      */ | |||
|     private static final int BATCH_COUNT = 5; | |||
|     List<ConverterData> list = new ArrayList<ConverterData>(); | |||
| 
 | |||
|     @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("存储数据库成功!"); | |||
|     } | |||
| } | |||
| @ -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<String> { | |||
|     @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); | |||
|     } | |||
| 
 | |||
| } | |||
| @ -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<DemoData> list) { | |||
|         // 如果是mybatis,尽量别直接调用多次insert,自己写一个mapper里面新增一个方法batchInsert,所有数据一次性插入
 | |||
|     } | |||
| } | |||
| @ -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; | |||
| } | |||
| @ -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<IndexModel> { | |||
|     private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); | |||
|     /** | |||
|      * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 | |||
|      */ | |||
|     private static final int BATCH_COUNT = 5; | |||
|     List<IndexModel> list = new ArrayList<IndexModel>(); | |||
|     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("存储数据库成功!"); | |||
|     } | |||
| } | |||
| @ -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不能读取多次,多次读取需要重新读取文件 | |||
|      * <p> | |||
|      * 1. 创建excel对应的实体对象 参照{@link DemoData} | |||
|      * <p> | |||
|      * 2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener} | |||
|      * <p> | |||
|      * 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(); | |||
|             } | |||
|         } | |||
|     } | |||
| } | |||
| @ -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); | |||
|     } | |||
| } | |||
								
									Binary file not shown.
								
							
						
					
					Loading…
					
					
				
		Reference in new issue