@ -5,6 +5,7 @@ import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysLocaleResourceService ;
import cn.estsh.i3plus.platform.common.convert.ConvertBean ;
import cn.estsh.i3plus.platform.common.exception.BaseImppException ;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum ;
import cn.estsh.i3plus.platform.common.tool.ExcelTool ;
import cn.estsh.i3plus.platform.common.tool.StringTool ;
import cn.estsh.i3plus.platform.common.util.CommonConstWords ;
@ -20,7 +21,6 @@ import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil ;
import cn.estsh.impp.framework.boot.exception.ImppBusiException ;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder ;
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum ;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient ;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSFile ;
import cn.estsh.impp.framework.boot.util.ImppRedis ;
@ -39,6 +39,7 @@ import javax.annotation.Resource;
import javax.persistence.EntityManager ;
import javax.servlet.http.HttpServletResponse ;
import java.io.* ;
import java.nio.charset.StandardCharsets ;
import java.util.* ;
/ * *
@ -61,7 +62,7 @@ public class SysLocaleResourceController extends CoreBaseController {
private ISysLocaleResourceService sysLocaleResourceService ;
@Autowired
private ISystemInitService systemInitService ; ;
private ISystemInitService systemInitService ;
@Autowired
private ISysFileService sysFileService ;
@ -91,6 +92,12 @@ public class SysLocaleResourceController extends CoreBaseController {
//新增初始化
sysLocaleResource . setIsSystem ( CommonEnumUtil . TRUE_OR_FALSE . FALSE . getValue ( ) ) ;
// 系统功能key添加指定前缀, 避免与其他资源重复
if ( sysLocaleResource . getResourceType ( ) . equals ( CommonEnumUtil . SYS_LOCALE_RESOURCE_TYPE . MENU . getValue ( ) )
& & sysLocaleResource . getResourceKey ( ) . indexOf ( CommonConstWords . RESOURCE_PREFIX_MENU ) ! = 0 ) {
sysLocaleResource . setResourceKey ( CommonConstWords . RESOURCE_PREFIX_MENU + sysLocaleResource . getResourceKey ( ) ) ;
}
sysLocaleResourceService . insertSysLocaleResource ( sysLocaleResource ) ;
// 更新缓存信息
@ -110,7 +117,7 @@ public class SysLocaleResourceController extends CoreBaseController {
* /
@PutMapping ( value = "/update" )
@ApiOperation ( value = "修改语言资源" , notes = "修改语言资源" )
public ResultBean updateSysLocaleResource ( SysLocaleResource sysLocaleResource ) {
public ResultBean updateSysLocaleResource ( SysLocaleResource sysLocaleResource ) {
try {
//条件验证
ValidatorBean . beginValid ( sysLocaleResource )
@ -220,8 +227,6 @@ public class SysLocaleResourceController extends CoreBaseController {
sysLocaleResourceService . deleteSysLocaleResourceByIds ( StringTool . getArrayLong ( idsStr ) ) ;
// 重新加载资源
systemInitService . putAndLoadSysLocaleLanguage ( ) ;
return ResultBean . success ( "操作成功" ) . setCode ( ResourceEnumUtil . MESSAGE . SUCCESS . getCode ( ) ) ;
} catch ( ImppBusiException busExcep ) {
return ResultBean . fail ( busExcep ) ;
@ -239,22 +244,26 @@ public class SysLocaleResourceController extends CoreBaseController {
@ApiOperation ( value = "批量添加系统资源" )
public ResultBean insertSysLocaleResourceList ( @RequestBody List < SysLocaleResource > sysLocaleResourcesList ) {
try {
if ( sysLocaleResourcesList . size( ) = = 0 ) {
if ( sysLocaleResourcesList . isEmpty( ) ) {
throw ImppExceptionBuilder . newInstance ( )
. setSystemID ( CommonEnumUtil . SOFT_TYPE . CORE . getCode ( ) )
. setErrorCode ( ImppExceptionEnum . VARIFY_EXCEPTION . getCode ( ) )
. setErrorDetail ( "请选择 需要删除的 资源。")
. setErrorDetail ( "请选择 输入需要添加 资源。")
. build ( ) ;
}
for ( SysLocaleResource sysLocaleResource : sysLocaleResourcesList ) {
// 系统功能key添加指定前缀, 避免与其他资源重复
if ( sysLocaleResource . getResourceType ( ) . equals ( CommonEnumUtil . SYS_LOCALE_RESOURCE_TYPE . MENU . getValue ( ) )
& & sysLocaleResource . getResourceKey ( ) . indexOf ( CommonConstWords . RESOURCE_PREFIX_MENU ) ! = 0 ) {
sysLocaleResource . setResourceKey ( CommonConstWords . RESOURCE_PREFIX_MENU + sysLocaleResource . getResourceKey ( ) ) ;
}
ConvertBean . modelInitialize ( sysLocaleResource , AuthUtil . getSessionUser ( ) ) ;
}
sysLocaleResourceService . insertSysLocaleResourceList ( sysLocaleResourcesList ) ;
// 重新加载资源
systemInitService . putAndLoadSysLocaleLanguage ( ) ;
return ResultBean . success ( "操作成功" ) . setCode ( ResourceEnumUtil . MESSAGE . SUCCESS . getCode ( ) ) ;
} catch ( ImppBusiException busExcep ) {
return ResultBean . fail ( busExcep ) ;
@ -268,27 +277,11 @@ public class SysLocaleResourceController extends CoreBaseController {
* @param sysLocaleResource 系 统 资 源 消 息
* @param isDelete 是 否 删 除
* /
private void updateResourceCache ( SysLocaleResource sysLocaleResource , boolean isDelete ) {
private void updateResourceCache ( SysLocaleResource sysLocaleResource , boolean isDelete ) {
// 判断是否为删除资源
if ( isDelete ) {
Map < Object , Object > langMap = redisRes . getHashMap ( CommonConstWords . REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource . getLanguageCode ( ) ) ;
if ( langMap ! = null & & langMap . size ( ) ! = 0 ) {
langMap . remove ( sysLocaleResource . getResourceKey ( ) ) ;
redisRes . putHashMap ( CommonConstWords . REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource . getLanguageCode ( ) , langMap ) ;
}
redisRes . deleteKey ( CommonConstWords . REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource . getResourceKey ( ) ) ;
} else {
Map < Object , Object > langMap = redisRes . getHashMap ( CommonConstWords . REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource . getLanguageCode ( ) ) ;
if ( langMap ! = null & & langMap . size ( ) ! = 0 ) {
langMap . put ( sysLocaleResource . getResourceKey ( ) , sysLocaleResource . getResourceValue ( ) ) ;
redisRes . putHashMap ( CommonConstWords . REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource . getLanguageCode ( ) , langMap ) ;
}
// 更新web资源
HashMap < String , String > resource = new HashMap < String , String > ( ) ;
resource . put ( sysLocaleResource . getLanguageCode ( ) , sysLocaleResource . getResourceValue ( ) ) ;
redisRes . putHashMap ( CommonConstWords . REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource . getResourceKey ( ) , resource , 0 ) ;
}
// 更新后台资源
}
@PostMapping ( value = "/import" )
@ -304,6 +297,11 @@ public class SysLocaleResourceController extends CoreBaseController {
String resourceKey ;
String userName = AuthUtil . getSessionUser ( ) . getUserName ( ) ;
for ( SysLocaleResource localeResource : sysLocaleResourceList ) {
// 系统功能key添加指定前缀, 避免与其他资源重复
if ( localeResource . getResourceType ( ) . equals ( CommonEnumUtil . SYS_LOCALE_RESOURCE_TYPE . MENU . getValue ( ) )
& & localeResource . getResourceKey ( ) . indexOf ( CommonConstWords . RESOURCE_PREFIX_MENU ) ! = 0 ) {
localeResource . setResourceKey ( CommonConstWords . RESOURCE_PREFIX_MENU + localeResource . getResourceKey ( ) ) ;
}
localeResource . setIsSystem ( CommonEnumUtil . TRUE_OR_FALSE . TRUE . getValue ( ) ) ;
ConvertBean . serviceModelInitialize ( localeResource , userName ) ;
@ -326,11 +324,9 @@ public class SysLocaleResourceController extends CoreBaseController {
}
// 重新加载资源
// systemInitService.putAndLoadSysLocaleLanguage();
systemInitService . putAndLoadSysLocaleLanguage ( ) ;
return ResultBean . success ( "导入成功" ) . setCode ( ResourceEnumUtil . MESSAGE . SUCCESS . getCode ( ) ) ;
} catch ( ImppBusiException busExcep ) {
return ResultBean . fail ( busExcep ) ;
} catch ( BaseImppException busExcep ) {
} catch ( BaseImppException busExcep ) {
return ResultBean . fail ( busExcep ) ;
} catch ( Exception e ) {
return ImppExceptionBuilder . newInstance ( ) . buildExceptionResult ( e ) ;
@ -340,7 +336,6 @@ public class SysLocaleResourceController extends CoreBaseController {
@PostMapping ( value = "/export" )
@ApiOperation ( value = "导出系统资源" )
public ResultBean exportSysLocaleResource ( HttpServletResponse response ) {
try {
startMultiService ( ) ;
ExcelTool excelTool = new ExcelTool ( entityManager , redisRes ) ;
@ -348,7 +343,13 @@ public class SysLocaleResourceController extends CoreBaseController {
List < SysLocaleResource > list = sysLocaleResourceService . listSysLocaleResource ( ) ;
File file = new File ( fileName ) ;
file . createNewFile ( ) ;
if ( file . createNewFile ( ) ) {
throw ImppExceptionBuilder . newInstance ( )
. setSystemID ( CommonEnumUtil . SOFT_TYPE . CORE . getCode ( ) )
. setErrorCode ( ImppExceptionEnum . IO_EXCEPTION_FILE . getCode ( ) )
. setErrorDetail ( "临时文件创建失败!" )
. build ( ) ;
}
File excle = excelTool . exportData ( file , list , SysLocaleResource . class , new String [ ] {
"resourceType" , "languageCode" , "languageNameRdd" , "resourceKey" , "resourceValue" , "softType"
} ) ;
@ -359,16 +360,17 @@ public class SysLocaleResourceController extends CoreBaseController {
fileName = java . net . URLEncoder . encode ( fileName , "UTF-8" ) ;
} else {
// 非IE浏览器的处理:
fileName = new String ( fileName . getBytes ( "UTF-8" ) , "ISO-8859-1" ) ;
fileName = new String ( fileName . getBytes ( StandardCharsets . UTF_8 ) , StandardCharsets . ISO_8859_1 ) ;
}
InputStream targetStream = new DataInputStream ( new FileInputStream ( excle ) ) ;
response . setContentType ( "application/force-download" ) ; // 设置强制下载不打开
response . addHeader ( "Content-Disposition" , "attachment;fileName=" + fileName ) ; // 设置文件名
response . addHeader ( "Content-type" , FileContentTypeTool . getContentType ( ".xls" ) ) ; // 设置文件名
BufferedInputStream bis = null ;
InputStream targetStream = null ;
try {
targetStream = new DataInputStream ( new FileInputStream ( excle ) ) ;
bis = new BufferedInputStream ( targetStream ) ;
OutputStream os = response . getOutputStream ( ) ;
byte [ ] buffer = new byte [ 1024 ] ;
@ -377,19 +379,18 @@ public class SysLocaleResourceController extends CoreBaseController {
os . write ( buffer , 0 , i ) ;
i = bis . read ( buffer ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
} finally {
if ( bis ! = null ) {
try {
bis . close ( ) ;
targetStream . close ( ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
bis . close ( ) ;
}
if ( targetStream ! = null ) {
targetStream . close ( ) ;
}
}
// 删除临时文件
if ( ! file . delete ( ) ) {
LOGGER . warn ( "临时文件清理失败" ) ;
}
file . delete ( ) ; // 删除临时文件
return ResultBean . success ( "下载" ) . setCode ( ResourceEnumUtil . MESSAGE . SUCCESS . getCode ( ) ) ;
} catch ( ImppBusiException busExcep ) {
return ResultBean . fail ( busExcep ) ;
@ -422,6 +423,11 @@ public class SysLocaleResourceController extends CoreBaseController {
String resourceKey ;
String userName = AuthUtil . getSessionUser ( ) . getUserName ( ) ;
for ( SysLocaleResource localeResource : sysLocaleResourceList ) {
// 系统功能key添加指定前缀, 避免与其他资源重复
if ( localeResource . getResourceType ( ) . equals ( CommonEnumUtil . SYS_LOCALE_RESOURCE_TYPE . MENU . getValue ( ) )
& & localeResource . getResourceKey ( ) . indexOf ( CommonConstWords . RESOURCE_PREFIX_MENU ) ! = 0 ) {
localeResource . setResourceKey ( CommonConstWords . RESOURCE_PREFIX_MENU + localeResource . getResourceKey ( ) ) ;
}
// 初始化
localeResource . setId ( getResourceKey ( localeResource . getResourceKey ( ) , localeResource . getLanguageCode ( ) ) ) ;
localeResource . setIsSystem ( CommonEnumUtil . TRUE_OR_FALSE . TRUE . getValue ( ) ) ;
@ -439,7 +445,6 @@ public class SysLocaleResourceController extends CoreBaseController {
// 分批导入
int size = 1000 ;
int i = 0 ;
for ( List < SysLocaleResource > resourceList : ListUtils . partition ( importDataList , size ) ) {
new Thread ( ) {
@Override
@ -452,10 +457,7 @@ public class SysLocaleResourceController extends CoreBaseController {
} . start ( ) ;
}
// LOGGER.info("数据缓存更新完毕,总耗时:{}",System.currentTimeMillis()-startTime);
return ResultBean . success ( "数据导入中..." ) . setCode ( ResourceEnumUtil . MESSAGE . SUCCESS . getCode ( ) ) ;
} catch ( ImppBusiException busExcep ) {
return ResultBean . fail ( busExcep ) ;
} catch ( BaseImppException busExcep ) {
return ResultBean . fail ( busExcep ) ;
} catch ( Exception e ) {