diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ThreadLocalConstant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ThreadLocalConstant.java index 6a2b304cfa..9061c2e8d3 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ThreadLocalConstant.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ThreadLocalConstant.java @@ -1,5 +1,7 @@ package com.epmet.commons.tools.constant; +import java.util.Map; + /** * ThreadLocal常亮 */ @@ -19,4 +21,9 @@ public class ThreadLocalConstant { * 用于本次的获取请求参数 */ public static final ThreadLocal requestParam = new ThreadLocal(); + + /** + * 可被子线程继承的,追加的request headers + */ + public static final InheritableThreadLocal> inheritableAdditionalHeaders = new InheritableThreadLocal<>(); } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java index 7fb9822290..f687696494 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/EpmetBaseRequestInterceptor.java @@ -1,5 +1,6 @@ package com.epmet.commons.tools.feign; +import com.epmet.commons.tools.constant.ThreadLocalConstant; import feign.RequestInterceptor; import feign.RequestTemplate; import org.springframework.web.context.request.RequestAttributes; @@ -8,17 +9,38 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; public class EpmetBaseRequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { - RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); - if (requestAttributes == null) { - return; + // 自定义追加的request header,可被子线程继承拷贝 + Map inheritableAdditionalHeaders = ThreadLocalConstant.inheritableAdditionalHeaders.get(); + Map requestHeaders = getHeadersFromRequest(); + + if (requestHeaders != null && requestHeaders.size() > 0) { + for (Map.Entry kv : requestHeaders.entrySet()) { + template.header(kv.getKey(), kv.getValue()); + } + } + + if (inheritableAdditionalHeaders != null && inheritableAdditionalHeaders.size() > 0) { + for (Map.Entry kv : inheritableAdditionalHeaders.entrySet()) { + template.header(kv.getKey(), kv.getValue()); + } } + } + + /** + * 从header里面获取headers + */ + public HashMap getHeadersFromRequest() { + HashMap headers = new HashMap<>(); + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Enumeration headerNames = request.getHeaderNames(); if (headerNames != null) { @@ -27,9 +49,11 @@ public class EpmetBaseRequestInterceptor implements RequestInterceptor { Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = values.nextElement(); - template.header(name, value); + headers.put(name, value); } } } + + return headers; } } \ No newline at end of file diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java index 8a9bc6ad80..c7da43dc5b 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java @@ -1,5 +1,6 @@ package com.epmet.commons.tools.feign; +import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.RenException; @@ -13,6 +14,8 @@ import org.slf4j.LoggerFactory; */ public interface ResultDataResolver { + Logger logger = LoggerFactory.getLogger(ResultDataResolver.class); + /** * @Description 获取Result种的data,如果失败(返回result为null或者result.success为false),那么返回null * @return data数据 @@ -20,7 +23,6 @@ public interface ResultDataResolver { * @date 2021.06.07 22:45 */ default R getResultDataOrReturnNull(Result result, String targetServiceName) { - Logger logger = LoggerFactory.getLogger(ResultDataResolver.class); if (result == null) { logger.error("调用{}服务发生错误,返回Result为null", targetServiceName); return null; @@ -56,6 +58,8 @@ public interface ResultDataResolver { }*/ if (!result.success()) { + String j = JSON.toJSONString(result); + logger.info("远程调用出错,返回结果:{}", j); // 如果不通过参数指定code,则默认使用8000服务器开小差 Integer finalErrorCode = errorCode == null ? EpmetErrorCode.SERVER_ERROR.getCode() : errorCode; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/GlobalFilter.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/GlobalFilter.java index fe3dc8a3e9..4aa7beab20 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/GlobalFilter.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/GlobalFilter.java @@ -25,6 +25,7 @@ public class GlobalFilter implements Filter { ThreadLocalConstant.sqlFilter.remove(); ThreadLocalConstant.requirePermissionTl.remove(); ThreadLocalConstant.requestParam.remove(); + ThreadLocalConstant.inheritableAdditionalHeaders.remove(); } } } \ No newline at end of file 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 392984aede..bb7bb20420 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 @@ -27,6 +27,7 @@ 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.constant.ThreadLocalConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionDataResultDTO; import com.epmet.commons.tools.enums.IcFormCodeEnum; @@ -34,6 +35,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.feign.EpmetBaseRequestInterceptor; import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.RedisKeys; @@ -58,6 +60,7 @@ import com.epmet.feign.OperCustomizeOpenFeignClient; import com.epmet.feign.OssFeignClient; import com.epmet.service.IcResiUserImportService; import com.epmet.service.IcResiUserService; +import feign.RequestInterceptor; import jodd.io.FileUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; @@ -71,7 +74,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; @@ -88,6 +90,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; @@ -130,6 +133,8 @@ public class IcResiUserController implements ResultDataResolver { private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; @Autowired private LoginUserUtil loginUserUtil; + @Autowired + private RequestInterceptor requestInterceptor; /** * 模板枚举 @@ -359,6 +364,7 @@ public class IcResiUserController implements ResultDataResolver { //表数据写入 //通过枚举获取相关表并按照sheetNo排序 List resiTableList = Arrays.stream(IcResiUserTableEnum.values()) + .filter((v) -> v.getSheetNo() != null) .sorted(Comparator.comparing(IcResiUserTableEnum::getSheetNo)) .collect(Collectors.toList()); List> resiResultList = null; @@ -465,26 +471,14 @@ public class IcResiUserController implements ResultDataResolver { throw new RenException("上传失败"); } - HttpServletRequest request = ((StandardMultipartHttpServletRequest)multipartRequest).getRequest(); + HashMap headers = ((EpmetBaseRequestInterceptor) requestInterceptor).getHeadersFromRequest(); - HashMap headers = getHeadersFromRequest(request); + ThreadLocalConstant.inheritableAdditionalHeaders.set(headers); // 三.异步执行导入 - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { - // 睡眠2秒钟,等待主线程先结束,主线程会清空request对象的headers,等他执行了清空之后,我们这边再手动setHeader进去 - Thread.sleep(2000l); - System.out.println("请求头:" + headers); - } catch (InterruptedException e) { - String errorMsg = ExceptionUtils.getErrorStackTrace(e); - log.error("【上传居民信息】失败,睡眠2s发生中断:{}", errorMsg); - return; - } - - try { - setHeaders2Request(request, headers); - List formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); } catch (Throwable e) { @@ -502,56 +496,29 @@ public class IcResiUserController implements ResultDataResolver { log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); } - // 清理request对象 - RequestContextHolder.resetRequestAttributes(); + // 清理tl对象 + ThreadLocalConstant.inheritableAdditionalHeaders.remove(); } - }); + }).start(); return new Result(); } - private HashMap getHeadersFromRequest(HttpServletRequest request) { - HashMap headers = new HashMap<>(); - Enumeration headerNames = request.getHeaderNames(); - if (headerNames != null) { - while (headerNames.hasMoreElements()) { - String name = headerNames.nextElement(); - Enumeration values = request.getHeaders(name); - while (values.hasMoreElements()) { - String value = values.nextElement(); - headers.put(name, value); - } - } - } - return headers; - } - - private void setHeaders2Request(HttpServletRequest request, HashMap headers) { - for (Map.Entry kv : headers.entrySet()) { - setParam2Header(request, kv.getKey(), kv.getValue()); - } - } - - private void setParam2Header(HttpServletRequest requestFacade, String key, String value){ - Class requestFacadeClass = requestFacade.getClass(); - try { - Field requestField = requestFacadeClass.getDeclaredField("request"); - requestField.setAccessible(true); - Object requestObject = requestField.get(requestFacade); - - Field coyoteRequestField = requestObject.getClass().getDeclaredField("coyoteRequest"); - coyoteRequestField.setAccessible(true); - Object coyoteRequestObject = coyoteRequestField.get(requestObject); - - Field headers = coyoteRequestObject.getClass().getDeclaredField("headers"); - headers.setAccessible(true); - MimeHeaders o2 = (MimeHeaders)headers.get(coyoteRequestObject); - o2.addValue(key).setString(value); - } catch (Exception e) { - e.printStackTrace(); - log.error("为子线程设置请求头出错"); - } - } +// private HashMap getHeadersFromRequest(HttpServletRequest request) { +// HashMap headers = new HashMap<>(); +// Enumeration headerNames = request.getHeaderNames(); +// if (headerNames != null) { +// while (headerNames.hasMoreElements()) { +// String name = headerNames.nextElement(); +// Enumeration values = request.getHeaders(name); +// while (values.hasMoreElements()) { +// String value = values.nextElement(); +// headers.put(name, value); +// } +// } +// } +// return headers; +// } @PostMapping("test") public Result>> test(@LoginUser TokenDto tokenDto, @RequestBody DynamicQueryFormDTO formDTO) { diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java index 5bb46b6369..0490c50c5c 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java @@ -89,7 +89,7 @@ public enum IcResiUserTableEnum { return tableComment; } - public int getSheetNo() { + public Integer getSheetNo() { return sheetNo; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiImportDynamicExcelListener.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiImportDynamicExcelListener.java index 427e70f0a3..b390d10a39 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiImportDynamicExcelListener.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiImportDynamicExcelListener.java @@ -122,12 +122,18 @@ public class IcResiImportDynamicExcelListener extends AnalysisEventListener> headers = icResiUserImportService.mergeMultiLevelHeadLabels(headList); + icResiUserImportService.printLog("invokeHeadMap_1_" + isPrimary); + // 清洗表头数据,通过items剔除,并且得到options abandonedHeaders = icResiUserImportService.removeAndGetOptionsFromHeaders(headers, formItemList); + icResiUserImportService.printLog("invokeHeadMap_2_" + isPrimary); + // 交换表头信息,以label连起来的string作为key,列号的列表作为value HashMap> combinedHeaders = icResiUserImportService.exchangeKeyAndValueOfHeaders(headers); + icResiUserImportService.printLog("invokeHeadMap_3_" + isPrimary); + // 得到客户配置item数据。<"兴趣爱好:兴趣特长", item对象> Map customizedLabelCompbinedItemsMap = formItemList.stream().collect( Collectors.toMap(formItem -> { @@ -141,7 +147,11 @@ public class IcResiImportDynamicExcelListener extends AnalysisEventListener formItem) ); + icResiUserImportService.printLog("invokeHeadMap_4_" + isPrimary); + itemIdAndColumnWrapper = icResiUserImportService.convertExcelHeaders2DBColumnWrappers(customizedLabelCompbinedItemsMap, combinedHeaders); + + icResiUserImportService.printLog("invokeHeadMap_5_" + isPrimary); } /** @@ -172,6 +182,7 @@ public class IcResiImportDynamicExcelListener extends AnalysisEventListener>> itemIdAndOptionsCache = CacheBuilder.newBuilder().maximumSize(500).build(); - - @Autowired - private LoginUserUtil loginUserUtil; - @Autowired private EpmetUserOpenFeignClient epmetUserOpenFeignClient; @@ -217,19 +213,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res @Override public void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath) { - String loginUserId = loginUserUtil.getLoginUserId(); - String loginUserApp = loginUserUtil.getLoginUserApp(); - String loginUserClient = loginUserUtil.getLoginUserClient(); + String app = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); + String client = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CLIENT); + String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); - LoginUserDetailsFormDTO userForm = new LoginUserDetailsFormDTO(); - userForm.setApp(loginUserApp); - userForm.setClient(loginUserClient); - userForm.setUserId(loginUserId); + String currUserAgencyId = userService.getLoginUserDetails(app, client, loginUserId).getAgencyId(); - String currUserAgencyId = userService.getLoginUserDetails( - loginUserUtil.getLoginUserApp(), - loginUserUtil.getLoginUserClient(), - loginUserUtil.getLoginUserId()).getAgencyId(); + log.info("importIcResiInfoFromExcel:: currUserAgencyId:{}", currUserAgencyId); CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(currUserAgencyId), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null, null); String customerId = agencyInfo.getCustomerId(); @@ -238,6 +228,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res initImportThreadLocal(customerId); // 上传主表信息 + log.info("======开始导入基础信息======="); importIcResiBaseInfoFromExcel(formItemList,excelPathName, IcResiUserTableEnum.IC_RESI_USER.getSheetNo(), IcResiUserTableEnum.IC_RESI_USER.getHeadRowNo(), currUserAgencyId, agencyInfo.getPids(), loginUserId, IcResiUserTableEnum.IC_RESI_USER.getTableName(), customerId); @@ -249,6 +240,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } try { + log.info("======开始导入附加表:{}=======", sheet.getTableComment()); importIcResiExtraInfoFromExcel(formItemList, excelPathName, sheet, currUserAgencyId, loginUserId, customerId); } catch (Exception e) { String errorMsg = ExceptionUtils.getErrorStackTrace(e); @@ -324,7 +316,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res */ private void initImportThreadLocal(String customerId) { // 生成importTag,用于标记唯一一次导入操作,导入完成之后,用来删除redis里面临时的key - String operatorId = loginUserUtil.getLoginUserId(); + String operatorId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); String importTag = operatorId + System.currentTimeMillis(); // 错误信息 @@ -364,6 +356,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private void importIcResiBaseInfoFromExcel(List formItemList, String excelPathName, int sheetNo, int headRowNumber, String currUserAgencyId, String currUserAgencyPids, String currentUserId, String tableName, String customerId) { + String loginUserApp = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); + String loginUserClient = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CLIENT); + String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + String loginUserCustomerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase()); + + log.info("importIcResiBaseInfoFromExcel:: userId:{}, app:{}, client:{}, customerId:{}", loginUserId, loginUserApp, loginUserClient, loginUserCustomerId); + IcResiImportDynamicExcelListener readListener = new IcResiImportDynamicExcelListener(this, customerId, currentUserId, currUserAgencyId, currUserAgencyPids, true, tableName, formItemList, headRowNumber); EasyExcel.read(new File(excelPathName)).registerReadListener(readListener).headRowNumber(headRowNumber).sheet(sheetNo).doRead(); @@ -416,6 +415,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String currUserAgencyId, Map checkBoxOptionColumnIdxAndLabel, String currUserAgencyPids, String currentUserId, String tableName) { + String loginUserApp = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); + String loginUserClient = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CLIENT); + String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + String loginUserCustomerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + + log.info("persistIcResiBaseInfo:: userId:{}, app:{}, client:{}, customerId:{}", loginUserId, loginUserApp, loginUserClient, loginUserCustomerId); + // 遍历每一行,将行内容转化为 for (Map row : dataRows) { @@ -471,7 +477,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res columnAndValues.put("AGENCY_ID", currUserAgencyId); columnAndValues.put("PIDS", currUserAgencyPids); - columnAndValues.put("CUSTOMER_ID", loginUserUtil.getLoginUserCustomerId()); + columnAndValues.put("CUSTOMER_ID", loginUserCustomerId); columnAndValues.put("UPDATED_BY", currentUserId); @@ -541,6 +547,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res LinkedHashMap columnAndValues = new LinkedHashMap<>(); + String loginUserApp = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); + String loginUserClient = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CLIENT); + String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + String loginUserCustomerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase()); + + log.info("persistIcResiExtraInfo:: userId:{}, app:{}, client:{}, customerId:{}", loginUserId, loginUserApp, loginUserClient, loginUserCustomerId); + // 遍历每一行,将行内容转化为 for (Map row : dataRows) { @@ -567,7 +580,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String icResiId = existResiInfoMap.get("ID"); columnAndValues.put("IC_RESI_USER", icResiId); - columnAndValues.put("CUSTOMER_ID", loginUserUtil.getLoginUserCustomerId()); + columnAndValues.put("CUSTOMER_ID", loginUserCustomerId); columnAndValues.put("UPDATED_BY", currentUserId); // 移除excel中存在,但是数据库表中不存在的无效列,方式sql语法错误 @@ -991,6 +1004,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res List options = null; + log.info("optionsUrl:{}, currUserAgencyId:{}", pureUri, currUserAgencyId); + switch (pureUri) { case "/epmetuser/icresidemanddict/demandoption": options = getResultDataOrThrowsException(epmetUserOpenFeignClient.getDemandOptions(), ServiceConstant.EPMET_USER_SERVER, @@ -1267,7 +1282,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res Date now = new Date(); - CustomerStaffInfoCacheResult operator = CustomerStaffRedis.getStaffInfo(loginUserUtil.getLoginUserCustomerId(), loginUserUtil.getLoginUserId()); + String customerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase()); + String userId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + + CustomerStaffInfoCacheResult operator = CustomerStaffRedis.getStaffInfo(customerId, userId); for (Map.Entry entry : categoryChangedResis.entrySet()) { String resiId = entry.getKey(); @@ -1296,7 +1314,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } // 生成changeRecord并存入 - IcUserChangeRecordEntity changeRecord = fillChangeRecord(loginUserUtil.getLoginUserCustomerId(), resiId, resiInfoMap.get("NAME"), null, loginUserUtil.getLoginUserId(), + IcUserChangeRecordEntity changeRecord = fillChangeRecord(customerId, resiId, resiInfoMap.get("NAME"), null, userId, operator.getRealName() , descBefore, descAfter, "category", "类别", "", now); icUserChangeRecordDao.insert(changeRecord); @@ -1316,7 +1334,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String unitId = newData.getUnitId(); String homeId = newData.getHomeId(); - IcUserChangeDetailedEntity newDetail = fillChangeDetail(loginUserUtil.getLoginUserCustomerId(), resiId, changeRecord.getId(), agencyId, + IcUserChangeDetailedEntity newDetail = fillChangeDetail(customerId, resiId, changeRecord.getId(), agencyId, gridId, villageId, buildId, unitId, homeId, "category", "类别", columnEntry.getKey(), 1, resiInfoMap.get("PIDS")); @@ -1361,7 +1379,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res Set newResiKeys = redisUtils.keys(RedisKeys.icResiImportTypeKey(newlyOrChangedResi.get().getImportTag(), "add").concat("*")); - CustomerStaffInfoCacheResult operator = CustomerStaffRedis.getStaffInfo(loginUserUtil.getLoginUserCustomerId(), loginUserUtil.getLoginUserId()); + String customerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase()); + String userId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + + CustomerStaffInfoCacheResult operator = CustomerStaffRedis.getStaffInfo(customerId, userId); for (String resiKey : newResiKeys) { Map newResiInfoMap = redisUtils.hGetAll(resiKey); @@ -1370,14 +1391,14 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res IcResiUserEntity resiInfo = icResiUserDao.selectById(newResiInfoObj.getResiId()); // 插入changeRecord - IcUserChangeRecordEntity changeRecord = fillChangeRecord(loginUserUtil.getLoginUserCustomerId(), newResiInfoObj.getResiId(), resiInfo.getName(), null, - loginUserUtil.getLoginUserId(), operator.getRealName(), "-", "-", + IcUserChangeRecordEntity changeRecord = fillChangeRecord(customerId, newResiInfoObj.getResiId(), resiInfo.getName(), null, + userId, operator.getRealName(), "-", "-", "add", "新增", "", now); icUserChangeRecordDao.insert(changeRecord); // 插入changeDetail for (Map.Entry mainTableColumn : newResiInfoObj.getCategories().entrySet()) { - IcUserChangeDetailedEntity changedetail = fillChangeDetail(loginUserUtil.getLoginUserCustomerId(), newResiInfoObj.getResiId(), changeRecord.getId(), newResiInfoObj.getAgencyId(), + IcUserChangeDetailedEntity changedetail = fillChangeDetail(customerId, newResiInfoObj.getResiId(), changeRecord.getId(), newResiInfoObj.getAgencyId(), newResiInfoObj.getGridId(), newResiInfoObj.getVillageId(), newResiInfoObj.getBuildId(), newResiInfoObj.getUnitId(), newResiInfoObj.getHomeId(), "add", "新增", mainTableColumn.getKey(), 1, resiInfo.getPids()); @@ -1396,8 +1417,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res */ public void saveTransferedResiRecord(Map transferedResis) { Date now = new Date(); - String customerId = loginUserUtil.getLoginUserCustomerId(); - CustomerStaffInfoCacheResult operator = CustomerStaffRedis.getStaffInfo(customerId, loginUserUtil.getLoginUserId()); + String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + String loginUserCustomerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase()); + CustomerStaffInfoCacheResult operator = CustomerStaffRedis.getStaffInfo(loginUserCustomerId, loginUserId); for (Map.Entry resi : transferedResis.entrySet()) { @@ -1430,7 +1452,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String newHomeId = newData.getHomeId(); IcResiUserOrgMsgFormDTO oldOrgFormDTO = new IcResiUserOrgMsgFormDTO(); - oldOrgFormDTO.setCustomerId(customerId); + oldOrgFormDTO.setCustomerId(loginUserCustomerId); oldOrgFormDTO.setAgencyId(oldAgencyId); oldOrgFormDTO.setGridId(oldGridId); oldOrgFormDTO.setNeighborHoodId(oldvillageId); @@ -1440,7 +1462,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res Result oldOrgInfoRst = govOrgOpenFeignClient.icResiUserOrgMsg(oldOrgFormDTO); IcResiUserOrgMsgFormDTO newOrgInfo = new IcResiUserOrgMsgFormDTO(); - newOrgInfo.setCustomerId(customerId); + newOrgInfo.setCustomerId(loginUserCustomerId); newOrgInfo.setAgencyId(newAgencyId); newOrgInfo.setGridId(newGridId); newOrgInfo.setNeighborHoodId(newvillageId); @@ -1510,13 +1532,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } // 保存 transferRecord - IcUserTransferRecordEntity transferRecord = fillTransferRecord(resiId, resiName, operator, customerId, - oldAgencyId, oldGridId, oldvillageId, oldBuildId, oldUnitId, oldHomeId, customerId, + IcUserTransferRecordEntity transferRecord = fillTransferRecord(resiId, resiName, operator, loginUserCustomerId, + oldAgencyId, oldGridId, oldvillageId, oldBuildId, oldUnitId, oldHomeId, loginUserCustomerId, newAgencyId, newGridId, newvillageId, newBuildId, newUnitId, newHomeId, oldOrg, newOrg); icUserTransferRecordDao.insert(transferRecord); // 保存 调动changeRecord - IcUserChangeRecordEntity transferChangeRecord = fillChangeRecord(customerId, resiId, resiName, transferRecord.getId(), operator.getStaffId(), + IcUserChangeRecordEntity transferChangeRecord = fillChangeRecord(loginUserCustomerId, resiId, resiName, transferRecord.getId(), operator.getStaffId(), operator.getRealName(), sbBefore.toString(), sbAfter.toString(), "transfer", "调动", "", now); icUserChangeRecordDao.insert(transferChangeRecord); @@ -1550,7 +1572,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String categoryDescAfter = sbAfter.toString(); if (!StringUtils.isAllBlank(categoryDescBefore, categoryDescAfter)) { - IcUserChangeRecordEntity categoryChangeRecord = fillChangeRecord(customerId, resiId, resiName, transferRecord.getId(), operator.getStaffId(), + IcUserChangeRecordEntity categoryChangeRecord = fillChangeRecord(loginUserCustomerId, resiId, resiName, transferRecord.getId(), operator.getStaffId(), operator.getRealName(), categoryDescBefore, categoryDescAfter , "category", "类别", "", now); icUserChangeRecordDao.insert(categoryChangeRecord); } @@ -1563,7 +1585,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res // 之前是这个类型,那这个类型需要-1 String oldValue = oldCategories.getValue(); if ("1".equals(oldValue)) { - IcUserChangeDetailedEntity changeDetail = fillChangeDetail(customerId, resiId, transferChangeRecord.getId(), oldAgencyId, + IcUserChangeDetailedEntity changeDetail = fillChangeDetail(loginUserCustomerId, resiId, transferChangeRecord.getId(), oldAgencyId, oldGridId, oldvillageId, oldBuildId, oldUnitId, oldHomeId, transferChangeRecord.getType(), transferChangeRecord.getTypeName(), key, -1, pids); icUserChangeDetailedDao.insert(changeDetail); @@ -1577,7 +1599,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res // 现在是这个类型,这个类型要+1 if ("1".equals(newValue)) { - IcUserChangeDetailedEntity changeDetail = fillChangeDetail(customerId, resiId, transferChangeRecord.getId(), newAgencyId, + IcUserChangeDetailedEntity changeDetail = fillChangeDetail(loginUserCustomerId, resiId, transferChangeRecord.getId(), newAgencyId, newGridId, newvillageId, newBuildId, newUnitId, newHomeId, transferChangeRecord.getType(), transferChangeRecord.getTypeName(), key, 1, pids); icUserChangeDetailedDao.insert(changeDetail); @@ -1808,4 +1830,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res importTaskId, processStatus, operatorId, resultDesc, resultDescPath); } } + + public void printLog(String positionPrefix) { + String app = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.APP); + String client = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CLIENT); + String loginUserId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.USER_ID.toLowerCase()); + String loginUserCustomerId = ThreadLocalConstant.inheritableAdditionalHeaders.get().get(AppClientConstant.CUSTOMER_ID.toLowerCase()); + + log.info("{}:: userId:{}, app:{}, client:{}, customerId:{}", positionPrefix, loginUserId, app, client, loginUserCustomerId); + } }