@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.epmet.bean.ResiImportCategoryData ;
import com.epmet.bean.ResiImportResiCategoryChangedCache ;
import com.epmet.bean.ResiImportChangedData ;
import com.epmet.commons.tools.constant.AppClientConstant ;
import com.epmet.commons.tools.constant.ServiceConstant ;
import com.epmet.commons.tools.constant.StrConstant ;
import com.epmet.commons.tools.constant.ThreadLocalConstant ;
@ -23,7 +24,6 @@ import com.epmet.commons.tools.feign.ResultDataResolver;
import com.epmet.commons.tools.redis.RedisKeys ;
import com.epmet.commons.tools.redis.RedisUtils ;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis ;
import com.epmet.commons.tools.security.user.LoginUserUtil ;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.Result ;
import com.epmet.constants.ImportTaskConstants ;
@ -103,10 +103,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
* /
Cache < String , Map < String , Map < String , String > > > 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 < FormItemResult > 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 < FormItemResult > 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,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
String currUserAgencyId , Map < Integer , String > checkBoxOptionColumnIdxAndLabel ,
String currUserAgencyPids , String currentUserId , String tableName ) {
this . printLog ( "persistIcResiBaseInfo" ) ;
// 遍历每一行,将行内容转化为
for ( Map < Integer , String > row : dataRows ) {
@ -471,7 +472,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" , ThreadLocalConstant . inheritableAdditionalHeaders . get ( ) . get ( AppClientConstant . CUSTOMER_ID . toLowerCase ( ) ) ) ;
columnAndValues . put ( "UPDATED_BY" , currentUserId ) ;
@ -541,6 +542,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
LinkedHashMap < String , String > 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 < Integer , String > row : dataRows ) {
@ -567,7 +575,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
String icResiId = existResiInfoMap . get ( "ID" ) ;
columnAndValues . put ( "IC_RESI_USER" , icResiId ) ;
columnAndValues . put ( "CUSTOMER_ID" , loginUserUtil . getLoginUser CustomerId ( ) ) ;
columnAndValues . put ( "CUSTOMER_ID" , loginUserCustomerId ) ;
columnAndValues . put ( "UPDATED_BY" , currentUserId ) ;
// 移除excel中存在,但是数据库表中不存在的无效列,方式sql语法错误
@ -991,6 +999,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
List < OptionResultDTO > options = null ;
log . info ( "optionsUrl:{}, currUserAgencyId:{}" , pureUri , currUserAgencyId ) ;
this . printLog ( "listRemoteOptions" ) ;
switch ( pureUri ) {
case "/epmetuser/icresidemanddict/demandoption" :
options = getResultDataOrThrowsException ( epmetUserOpenFeignClient . getDemandOptions ( ) , ServiceConstant . EPMET_USER_SERVER ,
@ -1030,6 +1040,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
nform . setAgencyId ( currUserAgencyId ) ;
}
nform . setGridId ( gridId ) ;
this . printLog ( "listRemoteOptions#neighborhoodoption" ) ;
log . info ( "neighborhoodoption:{},{}" , currUserAgencyId , gridId ) ;
options = getResultDataOrThrowsException ( govOrgOpenFeignClient . getNeighborHoodOptions ( nform ) , ServiceConstant . GOV_ORG_SERVER , EpmetErrorCode . SERVER_ERROR . getCode ( ) , null , null ) ;
break ;
case "/sys/dict/data/education" :
@ -1267,7 +1281,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 < String , ResiImportChangedData > entry : categoryChangedResis . entrySet ( ) ) {
String resiId = entry . getKey ( ) ;
@ -1296,7 +1313,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
}
// 生成changeRecord并存入
IcUserChangeRecordEntity changeRecord = fillChangeRecord ( loginUserUtil . getLoginUserC ustomerId( ) , resiId , resiInfoMap . get ( "NAME" ) , null , loginUserUtil . getLoginUserId ( ) ,
IcUserChangeRecordEntity changeRecord = fillChangeRecord ( c ustomerId, resiId , resiInfoMap . get ( "NAME" ) , null , userId ,
operator . getRealName ( ) , descBefore , descAfter , "category" , "类别" , "" , now ) ;
icUserChangeRecordDao . insert ( changeRecord ) ;
@ -1316,7 +1333,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
String unitId = newData . getUnitId ( ) ;
String homeId = newData . getHomeId ( ) ;
IcUserChangeDetailedEntity newDetail = fillChangeDetail ( loginUserUtil . getLoginUserC ustomerId( ) , resiId , changeRecord . getId ( ) , agencyId ,
IcUserChangeDetailedEntity newDetail = fillChangeDetail ( c ustomerId, resiId , changeRecord . getId ( ) , agencyId ,
gridId , villageId , buildId , unitId ,
homeId , "category" , "类别" , columnEntry . getKey ( ) , 1 , resiInfoMap . get ( "PIDS" ) ) ;
@ -1361,7 +1378,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
Set < String > 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 < String , Object > newResiInfoMap = redisUtils . hGetAll ( resiKey ) ;
@ -1370,14 +1390,14 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
IcResiUserEntity resiInfo = icResiUserDao . selectById ( newResiInfoObj . getResiId ( ) ) ;
// 插入changeRecord
IcUserChangeRecordEntity changeRecord = fillChangeRecord ( loginUserUtil . getLoginUserC ustomerId( ) , newResiInfoObj . getResiId ( ) , resiInfo . getName ( ) , null ,
loginUserUtil . getLoginUserId ( ) , operator . getRealName ( ) , "-" , "-" ,
IcUserChangeRecordEntity changeRecord = fillChangeRecord ( c ustomerId, newResiInfoObj . getResiId ( ) , resiInfo . getName ( ) , null ,
userId , operator . getRealName ( ) , "-" , "-" ,
"add" , "新增" , "" , now ) ;
icUserChangeRecordDao . insert ( changeRecord ) ;
// 插入changeDetail
for ( Map . Entry < String , String > mainTableColumn : newResiInfoObj . getCategories ( ) . entrySet ( ) ) {
IcUserChangeDetailedEntity changedetail = fillChangeDetail ( loginUserUtil . getLoginUserC ustomerId( ) , newResiInfoObj . getResiId ( ) , changeRecord . getId ( ) , newResiInfoObj . getAgencyId ( ) ,
IcUserChangeDetailedEntity changedetail = fillChangeDetail ( c ustomerId, newResiInfoObj . getResiId ( ) , changeRecord . getId ( ) , newResiInfoObj . getAgencyId ( ) ,
newResiInfoObj . getGridId ( ) , newResiInfoObj . getVillageId ( ) , newResiInfoObj . getBuildId ( ) , newResiInfoObj . getUnitId ( ) ,
newResiInfoObj . getHomeId ( ) , "add" , "新增" , mainTableColumn . getKey ( ) , 1 , resiInfo . getPids ( ) ) ;
@ -1396,8 +1416,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
* /
public void saveTransferedResiRecord ( Map < String , ResiImportChangedData > 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 < String , ResiImportChangedData > resi : transferedResis . entrySet ( ) ) {
@ -1430,7 +1451,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
String newHomeId = newData . getHomeId ( ) ;
IcResiUserOrgMsgFormDTO oldOrgFormDTO = new IcResiUserOrgMsgFormDTO ( ) ;
oldOrgFormDTO . setCustomerId ( c ustomerId) ;
oldOrgFormDTO . setCustomerId ( loginUserC ustomerId) ;
oldOrgFormDTO . setAgencyId ( oldAgencyId ) ;
oldOrgFormDTO . setGridId ( oldGridId ) ;
oldOrgFormDTO . setNeighborHoodId ( oldvillageId ) ;
@ -1440,7 +1461,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
Result < IcResiUserOrgMsgResultDTO > oldOrgInfoRst = govOrgOpenFeignClient . icResiUserOrgMsg ( oldOrgFormDTO ) ;
IcResiUserOrgMsgFormDTO newOrgInfo = new IcResiUserOrgMsgFormDTO ( ) ;
newOrgInfo . setCustomerId ( c ustomerId) ;
newOrgInfo . setCustomerId ( loginUserC ustomerId) ;
newOrgInfo . setAgencyId ( newAgencyId ) ;
newOrgInfo . setGridId ( newGridId ) ;
newOrgInfo . setNeighborHoodId ( newvillageId ) ;
@ -1510,13 +1531,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
}
// 保存 transferRecord
IcUserTransferRecordEntity transferRecord = fillTransferRecord ( resiId , resiName , operator , c ustomerId,
oldAgencyId , oldGridId , oldvillageId , oldBuildId , oldUnitId , oldHomeId , c ustomerId,
IcUserTransferRecordEntity transferRecord = fillTransferRecord ( resiId , resiName , operator , loginUserC ustomerId,
oldAgencyId , oldGridId , oldvillageId , oldBuildId , oldUnitId , oldHomeId , loginUserC ustomerId,
newAgencyId , newGridId , newvillageId , newBuildId , newUnitId , newHomeId , oldOrg , newOrg ) ;
icUserTransferRecordDao . insert ( transferRecord ) ;
// 保存 调动changeRecord
IcUserChangeRecordEntity transferChangeRecord = fillChangeRecord ( c ustomerId, resiId , resiName , transferRecord . getId ( ) , operator . getStaffId ( ) ,
IcUserChangeRecordEntity transferChangeRecord = fillChangeRecord ( loginUserC ustomerId, resiId , resiName , transferRecord . getId ( ) , operator . getStaffId ( ) ,
operator . getRealName ( ) , sbBefore . toString ( ) , sbAfter . toString ( ) , "transfer" , "调动" , "" , now ) ;
icUserChangeRecordDao . insert ( transferChangeRecord ) ;
@ -1550,7 +1571,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
String categoryDescAfter = sbAfter . toString ( ) ;
if ( ! StringUtils . isAllBlank ( categoryDescBefore , categoryDescAfter ) ) {
IcUserChangeRecordEntity categoryChangeRecord = fillChangeRecord ( c ustomerId, resiId , resiName , transferRecord . getId ( ) , operator . getStaffId ( ) ,
IcUserChangeRecordEntity categoryChangeRecord = fillChangeRecord ( loginUserC ustomerId, resiId , resiName , transferRecord . getId ( ) , operator . getStaffId ( ) ,
operator . getRealName ( ) , categoryDescBefore , categoryDescAfter , "category" , "类别" , "" , now ) ;
icUserChangeRecordDao . insert ( categoryChangeRecord ) ;
}
@ -1563,7 +1584,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
// 之前是这个类型,那这个类型需要-1
String oldValue = oldCategories . getValue ( ) ;
if ( "1" . equals ( oldValue ) ) {
IcUserChangeDetailedEntity changeDetail = fillChangeDetail ( c ustomerId, resiId , transferChangeRecord . getId ( ) , oldAgencyId ,
IcUserChangeDetailedEntity changeDetail = fillChangeDetail ( loginUserC ustomerId, resiId , transferChangeRecord . getId ( ) , oldAgencyId ,
oldGridId , oldvillageId , oldBuildId , oldUnitId ,
oldHomeId , transferChangeRecord . getType ( ) , transferChangeRecord . getTypeName ( ) , key , - 1 , pids ) ;
icUserChangeDetailedDao . insert ( changeDetail ) ;
@ -1577,7 +1598,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res
// 现在是这个类型,这个类型要+1
if ( "1" . equals ( newValue ) ) {
IcUserChangeDetailedEntity changeDetail = fillChangeDetail ( c ustomerId, resiId , transferChangeRecord . getId ( ) , newAgencyId ,
IcUserChangeDetailedEntity changeDetail = fillChangeDetail ( loginUserC ustomerId, resiId , transferChangeRecord . getId ( ) , newAgencyId ,
newGridId , newvillageId , newBuildId , newUnitId ,
newHomeId , transferChangeRecord . getType ( ) , transferChangeRecord . getTypeName ( ) , key , 1 , pids ) ;
icUserChangeDetailedDao . insert ( changeDetail ) ;
@ -1808,4 +1829,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 ) ;
}
}