diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/ThreadDispatcherConfig.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/ThreadDispatcherConfig.java new file mode 100644 index 0000000000..1b2d32c2cc --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/ThreadDispatcherConfig.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.epmet.commons.tools.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.filter.RequestContextFilter; +import org.springframework.web.servlet.DispatcherServlet; + +import javax.annotation.PostConstruct; + + +/** + * DESC:设置线程继承属性为true,便于子线程获取到父线程的request,两个都设置为了保险 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Configuration +public class ThreadDispatcherConfig { + + @Autowired + RequestContextFilter requestContextFilter; + @Autowired + DispatcherServlet dispatcherServlet; + + @PostConstruct + public void init() { + // 设置线程继承属性为true,便于子线程获取到父线程的request,两个都设置为了保险。 + requestContextFilter.setThreadContextInheritable(true); + dispatcherServlet.setThreadContextInheritable(true); + } +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java index 400e3893e4..77875d5415 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java @@ -171,4 +171,7 @@ public interface Constant { * 被禁用标识 * */ String DISABLE = "disable"; + + String OPITON_SOURCE_REMOTE = "remote"; + String OPITON_SOURCE_LOCAL = "local"; } diff --git a/epmet-gateway/src/main/java/com/epmet/GatewayApplication.java b/epmet-gateway/src/main/java/com/epmet/GatewayApplication.java index a1630c821e..064b59610e 100644 --- a/epmet-gateway/src/main/java/com/epmet/GatewayApplication.java +++ b/epmet-gateway/src/main/java/com/epmet/GatewayApplication.java @@ -10,6 +10,7 @@ package com.epmet; import com.epmet.commons.tools.aspect.ServletExceptionHandler; import com.epmet.commons.tools.config.RedissonConfig; +import com.epmet.commons.tools.config.ThreadDispatcherConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @@ -27,7 +28,7 @@ import org.springframework.context.annotation.FilterType; @EnableDiscoveryClient @EnableFeignClients //@ServletComponentScan -@ComponentScan(basePackages = {"com.epmet.*"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RedissonConfig.class, ServletExceptionHandler.class})) +@ComponentScan(basePackages = {"com.epmet.*"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RedissonConfig.class, ThreadDispatcherConfig.class, ServletExceptionHandler.class})) public class GatewayApplication { public static void main(String[] args) { diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/bean/ResiExportBaseInfoData.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/bean/ResiExportBaseInfoData.java new file mode 100644 index 0000000000..5dc0d0b7c5 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/bean/ResiExportBaseInfoData.java @@ -0,0 +1,27 @@ +package com.epmet.bean; + +import lombok.Data; + +import java.io.Serializable; + +/** + * desc:导出居民信息 基础信息 给其他sheet使用 + */ +@Data +public class ResiExportBaseInfoData implements Serializable { + private static final long serialVersionUID = 1L; + + private String GRID_ID; + private String VILLAGE_ID; + private String BUILD_ID; + private String UNIT_ID; + private String HOME_ID; + private String IS_BDHJ; + private String NAME; + private String MOBILE; + private String GENDER; + private String ID_CARD; + private String BIRTHDAY; + private String CONTACTS; + private String CONTACTS_MOBILE; +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 1350ce159f..303d951526 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -24,6 +24,7 @@ import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.epmet.commons.rocketmq.messages.IcResiUserAddMQMsg; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.Constant; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; @@ -293,6 +294,7 @@ public class IcResiUserController { @RequestMapping(value = "/exportExcel") public void exportExcelByEasyExcel(@RequestHeader String customerId,@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws Exception { //tokenDto.setUserId("9e37adcce6472152e6508a19d3683e02"); + long startM = System.currentTimeMillis(); CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(customerId, tokenDto.getUserId()); String staffOrgPath = null; if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) { @@ -322,7 +324,7 @@ public class IcResiUserController { map.putIfAbsent(tableName,exportItem); String columnName = item.getColumnName().concat(item.getColumnNum() == NumConstant.ZERO ? StrConstant.EPMETY_STR : item.getColumnNum().toString()); exportItem.getItemMap().put(columnName,item); - if (item.getOptionSourceType().equals("remote")&&item.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){ + if (Constant.OPITON_SOURCE_REMOTE.equals(item.getOptionSourceType())&&item.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){ //多个参数 String[] paramArr = item.getOptionSourceValue().split(StrConstant.QUESTION_MARK_TRANSFER)[NumConstant.ONE].split(StrConstant.AND_MARK); Arrays.stream(paramArr).forEach(o->{ @@ -346,7 +348,7 @@ public class IcResiUserController { .collect(Collectors.toList()); List> resiResultList = null; - pageFormDTO.setPageSize(NumConstant.TEN_THOUSAND); + pageFormDTO.setPageSize(NumConstant.ONE_THOUSAND); for (IcResiUserTableEnum tableEnum : resiTableList) { String tableName = tableEnum.getTableName(); pageFormDTO.setPageNo(NumConstant.ONE); @@ -374,6 +376,7 @@ public class IcResiUserController { if (excelWriter != null){ excelWriter.finish(); } + log.info("exportExcelByEasyExcel resi info cost time:{}s",(System.currentTimeMillis()-startM)/NumConstant.ONE_THOUSAND); } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java index 64920cabdc..11a9fd3d4a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java @@ -20,11 +20,9 @@ package com.epmet.service.impl; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.epmet.bean.ResiExportBaseInfoData; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; -import com.epmet.commons.tools.constant.FieldConstant; -import com.epmet.commons.tools.constant.NumConstant; -import com.epmet.commons.tools.constant.ServiceConstant; -import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.constant.*; import com.epmet.commons.tools.dto.form.DictListFormDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.DictListResultDTO; @@ -69,6 +67,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,6 +76,8 @@ import java.math.RoundingMode; import java.sql.Date; import java.sql.Timestamp; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; @@ -114,6 +115,8 @@ public class IcResiUserServiceImpl extends BaseServiceImpl getWrapper(Map params){ String id = (String)params.get(FieldConstant.ID_HUMP); @@ -881,7 +884,7 @@ public class IcResiUserServiceImpl extends BaseServiceImpl> mapListPage = PageHelper.startPage(pageFormDTO.getPageNo(), pageFormDTO.getPageSize(), pageFormDTO.getPageFlag()).doSelectPage(() -> { this.dynamicQuery(pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), baseTableName, pageFormDTO.getConditions(), currentStaffAgencyId, staffOrgPath); }); - mapListPage.getResult().stream().filter(Objects::nonNull).forEach(resiUser -> { + mapListPage.getResult().parallelStream().filter(Objects::nonNull).forEach(resiUser -> { String resiId = null; //获取用户Id if (IcResiUserConstant.IC_RESI_USER.equals(baseTableName)) { @@ -905,28 +908,33 @@ public class IcResiUserServiceImpl extends BaseServiceImpl originalConditionMap = new HashMap<>(); - for (FormItemResult e : formItemMap.getItemMap().values()) { + Map originalConditionMap = new ConcurrentHashMap<>(); + formItemMap.getItemMap().values().parallelStream().forEach(e->{ String columnName = getColumnName(e); Object temp = resiUser.get(columnName); String vauleStr = temp == null ? StrConstant.EPMETY_STR : temp.toString(); originalConditionMap.putIfAbsent(columnName,vauleStr); - if ("remote".equals(e.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) { + if (Constant.OPITON_SOURCE_REMOTE.equals(e.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) { putRemoteValue(formItemMap.getRemoteItemConditionMap().get(e.getItemId()), currentStaffAgencyId, resiUser,originalConditionMap, e, columnName, vauleStr); } else { putOptionValue(resiUser, e, columnName, vauleStr); } + }); - } - if (!IcResiUserConstant.IC_RESI_USER.equals(baseTableName)) { - Map o = redisUtils.hGetAll(RedisKeys.getExportResiBaseInfoKey(resiId)); - if (o != null){ - resiUser.putAll(o); + if (IcResiUserConstant.IC_RESI_USER.equals(baseTableName)) { + //把人放入redis缓存 便于后面的sheet使用基础信息 + ResiExportBaseInfoData infoData = ConvertUtils.mapToEntity(resiUser, ResiExportBaseInfoData.class); + redisTemplate.opsForValue().set(RedisKeys.getExportResiBaseInfoKey(resiId), infoData,RedisUtils.MINUTE_THIRTY_EXPIRE, TimeUnit.SECONDS); + } else { + ResiExportBaseInfoData temp = (ResiExportBaseInfoData) redisTemplate.opsForValue().get(RedisKeys.getExportResiBaseInfoKey(resiId)); + if (temp != null){ + try { + resiUser.putAll(ConvertUtils.entityToMap(temp)); + } catch (Exception e) { + log.error("entityToMap exception,temp:{}",temp); + } } - return; } - //把人放入redis缓存 便于后面的sheet使用基础信息 - redisUtils.hMSet(RedisKeys.getExportResiBaseInfoKey(resiId),resiUser,RedisUtils.MINUTE_THIRTY_EXPIRE); }); remoteOptionCacheMap.clear(); return mapListPage.getResult();