From 5e5592f2fd5998eb5094948f4dbf3e27a2181a80 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Wed, 14 Oct 2020 13:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7=E6=9D=83?= =?UTF-8?q?=E9=87=8D=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/controller/IndexDictController.java | 14 +++++----- .../screen/IndexGroupDetailDao.java | 3 +++ .../epmet/model/IndexExcelDataListener.java | 27 +++++++++++++++++-- .../screen/IndexGroupDetailService.java | 12 +++++++++ .../impl/IndexGroupDetailServiceImpl.java | 19 +++++++++++++ .../screen/IndexGroupDetailDao.xml | 9 +++++++ 6 files changed, 75 insertions(+), 9 deletions(-) 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 index 03deff604d..6a24b3e98b 100644 --- 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 @@ -8,10 +8,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.dto.screen.form.InitCustomerIndexForm; import com.epmet.model.IndexExcelDataListener; import com.epmet.model.IndexModel; -import com.epmet.service.evaluationindex.screen.IndexDictService; -import com.epmet.service.evaluationindex.screen.IndexGroupDetailTemplateService; -import com.epmet.service.evaluationindex.screen.IndexGroupService; -import com.epmet.service.evaluationindex.screen.IndexGroupTemplateService; +import com.epmet.service.evaluationindex.screen.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -37,7 +34,8 @@ public class IndexDictController { private IndexGroupService indexGroupService; @Autowired private IndexGroupDetailTemplateService indexGroupDetailTemplateService; - + @Autowired + private IndexGroupDetailService indexGroupDetailService; /** * url:http://localhost:8108/data/stats/indexdict/initFromExcel * desc:从excel初始化指标,分组,权重 @@ -46,7 +44,7 @@ public class IndexDictController { * @return */ @PostMapping("initFromExcel") - public Result testTx(@RequestPart("file") MultipartFile file) { + public Result testTx(@RequestPart("file") MultipartFile file,@RequestParam("customerId") String customerId) { ExcelReader excelReader = null; try { InputStream inputStream = null; @@ -58,7 +56,9 @@ public class IndexDictController { excelReader = EasyExcel.read(inputStream).build(); // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener ReadSheet readSheet = EasyExcel.readSheet(1).head(IndexModel.class) - .registerReadListener(new IndexExcelDataListener(indexDictService, indexGroupTemplateService, indexGroupDetailTemplateService)) + .registerReadListener(new IndexExcelDataListener(indexDictService, indexGroupTemplateService, indexGroupDetailTemplateService, + customerId, + indexGroupDetailService)) .build(); excelReader.read(readSheet); } finally { diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/IndexGroupDetailDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/IndexGroupDetailDao.java index b173b94bd6..2c6d867a08 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/IndexGroupDetailDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/IndexGroupDetailDao.java @@ -22,6 +22,7 @@ import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.List; /** @@ -47,4 +48,6 @@ public interface IndexGroupDetailDao extends BaseDao { * @return */ List selectSelfSubIndex(@Param("customerId") String customerId, @Param("allIndexCodePath") String allIndexCodePath); + + int updateWeight(@Param("indexCode") String indexCode, @Param("customerId") String customerId, @Param("weight") BigDecimal weight); } \ No newline at end of file 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 index 23a305e8f9..9870714357 100644 --- 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 @@ -9,6 +9,7 @@ import com.epmet.entity.evaluationindex.screen.IndexDictEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailTemplateEntity; import com.epmet.entity.evaluationindex.screen.IndexGroupTemplateEntity; import com.epmet.service.evaluationindex.screen.IndexDictService; +import com.epmet.service.evaluationindex.screen.IndexGroupDetailService; import com.epmet.service.evaluationindex.screen.IndexGroupDetailTemplateService; import com.epmet.service.evaluationindex.screen.IndexGroupTemplateService; import com.epmet.support.normalizing.Correlation; @@ -51,16 +52,25 @@ public class IndexExcelDataListener extends AnalysisEventListener { private IndexGroupDetailTemplateService indexGroupDetailTemplateService; + private IndexGroupDetailService indexGroupDetailService; + /** + * 客户id不为空时,需要修改index_group_detail + */ + private String customerId; /** * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来 * * @param indexDictService */ - public IndexExcelDataListener(IndexDictService indexDictService, IndexGroupTemplateService indexGroupTemplateService, IndexGroupDetailTemplateService indexGroupDetailTemplateService) { + public IndexExcelDataListener(IndexDictService indexDictService, IndexGroupTemplateService indexGroupTemplateService, IndexGroupDetailTemplateService indexGroupDetailTemplateService, + String customerId, + IndexGroupDetailService indexGroupDetailService) { this.indexDictService = indexDictService; this.indexGroupTemplateService = indexGroupTemplateService; this.indexGroupDetailTemplateService = indexGroupDetailTemplateService; + this.customerId=customerId; + this.indexGroupDetailService=indexGroupDetailService; } /** @@ -329,10 +339,16 @@ public class IndexExcelDataListener extends AnalysisEventListener { @Override public void doAfterAllAnalysed(AnalysisContext context) { // 这里也要保存数据,确保最后遗留的数据也存储到数据库 - saveData(); + if(StringUtils.isNotBlank(customerId)){ + //修改客户权重信息 + updateCustomerGroupDetail(); + }else{ + saveData(); + } LOGGER.info("所有数据解析完成!total:{}", total.intValue()); } + /** * 加上存储数据库 */ @@ -346,4 +362,11 @@ public class IndexExcelDataListener extends AnalysisEventListener { indexGroupDetailTemplateService.deleteAndInsertBatch(indexGroupDetailMap.values()); LOGGER.info("存储数据库成功!指标:{}个,分组:{}个,详情:{}个", indexDicMap.values().size(), indexGroupMap.values().size(), indexGroupDetailMap.values().size()); } + + /** + * 修改客户权重信息 + */ + private void updateCustomerGroupDetail() { + indexGroupDetailService.updateCustomerIndexGroupDetail(indexGroupDetailMap.values(),customerId); + } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/IndexGroupDetailService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/IndexGroupDetailService.java index eb77f2cf63..9e903481f4 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/IndexGroupDetailService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/IndexGroupDetailService.java @@ -19,8 +19,10 @@ package com.epmet.service.evaluationindex.screen; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; +import com.epmet.entity.evaluationindex.screen.IndexGroupDetailTemplateEntity; import java.math.BigDecimal; +import java.util.Collection; import java.util.List; /** @@ -46,4 +48,14 @@ public interface IndexGroupDetailService extends BaseService values, String customerId); } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupDetailServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupDetailServiceImpl.java index 26fb5b8cc2..0b807c0f7c 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupDetailServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/IndexGroupDetailServiceImpl.java @@ -25,6 +25,7 @@ import com.epmet.commons.tools.exception.RenException; import com.epmet.constant.DataSourceConstant; import com.epmet.dao.evaluationindex.screen.IndexGroupDetailDao; import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity; +import com.epmet.entity.evaluationindex.screen.IndexGroupDetailTemplateEntity; import com.epmet.redis.IndexCalRedis; import com.epmet.service.evaluationindex.screen.IndexGroupDetailService; import lombok.extern.slf4j.Slf4j; @@ -33,6 +34,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -79,4 +81,21 @@ public class IndexGroupDetailServiceImpl extends BaseServiceImpl values, String customerId) { + int updatedNum=0; + for(IndexGroupDetailTemplateEntity entity:values){ + updatedNum+=baseDao.updateWeight(entity.getIndexCode(),customerId,entity.getWeight()); + } + log.info("修改客户权重信息,影响行数="+updatedNum); + } + } \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/IndexGroupDetailDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/IndexGroupDetailDao.xml index 52ef05f966..6624f1b58a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/IndexGroupDetailDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/IndexGroupDetailDao.xml @@ -31,4 +31,13 @@ CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and STATUS = 'enable' and DEL_FLAG = '0' and ALL_PARENT_INDEX_CODE like concat(#{allIndexCodePath,jdbcType=VARCHAR},'%') + + + UPDATE index_group_detail + SET WEIGHT =#{weight} + WHERE + DEL_FLAG = '0' + AND CUSTOMER_ID = #{customerId} + AND INDEX_CODE = #{indexCode} + \ No newline at end of file