|
|
|
@ -2,6 +2,8 @@ package cn.estsh.i3plus.core.apiservice.controller.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLocaleResourceService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
@ -11,6 +13,7 @@ import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLocaleResource;
|
|
|
|
|
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;
|
|
|
|
@ -22,9 +25,26 @@ import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.DataInputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -51,6 +71,9 @@ public class SysLocaleResourceController extends CoreBaseController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISystemInitService systemInitService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增语言资源
|
|
|
|
|
* @param sysLocaleResource 语言资源
|
|
|
|
@ -265,4 +288,81 @@ public class SysLocaleResourceController extends CoreBaseController {
|
|
|
|
|
redisRes.putHashMap(CommonConstWords.REDIS_PREFIX_CACHE_LANGUAGE + ":" + sysLocaleResource.getResourceKey(), resource, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/import")
|
|
|
|
|
@ApiOperation(value = "导入系统资源")
|
|
|
|
|
public ResultBean importSysLocaleResource(@RequestParam("file") MultipartFile file){
|
|
|
|
|
try {
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
|
List<SysLocaleResource> sysLocaleResourceList = excelTool.importData(file.getOriginalFilename(), file.getInputStream(),
|
|
|
|
|
SysLocaleResource.class);
|
|
|
|
|
|
|
|
|
|
// 初始化数据
|
|
|
|
|
for (SysLocaleResource sysOrderNoRule : sysLocaleResourceList) {
|
|
|
|
|
sysOrderNoRule.setIsSystem(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
ConvertBean.modelInitialize(sysOrderNoRule, AuthUtil.getSessionUser());
|
|
|
|
|
}
|
|
|
|
|
sysLocaleResourceService.insertInitSysLocaleResourceList(sysLocaleResourceList);
|
|
|
|
|
|
|
|
|
|
// 重新加载资源
|
|
|
|
|
systemInitService.putAndLoadSysLocaleLanguage();
|
|
|
|
|
return ResultBean.success("导入成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/export")
|
|
|
|
|
@ApiOperation(value = "导入系统资源")
|
|
|
|
|
public ResultBean exportSysLocaleResource(HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
startMultiService();
|
|
|
|
|
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
|
|
|
|
|
String fileName = "locale_" + System.currentTimeMillis() + ".xls";
|
|
|
|
|
List<SysLocaleResource> list = sysLocaleResourceService.listSysLocaleResource();
|
|
|
|
|
|
|
|
|
|
File file = new File(fileName);
|
|
|
|
|
file.createNewFile();
|
|
|
|
|
File excle = excelTool.exportData(file, list, SysLocaleResource.class, new String[]{
|
|
|
|
|
"resourceType", "languageCode", "languageNameRdd", "resourceKey", "resourceValue", "softType"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
InputStream targetStream = new DataInputStream(new FileInputStream(excle));
|
|
|
|
|
response.setContentType("application/force-download"); // 设置强制下载不打开
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件名
|
|
|
|
|
response.addHeader("Content-type", "application/octet-stream"); // 设置文件名
|
|
|
|
|
|
|
|
|
|
BufferedInputStream bis = null;
|
|
|
|
|
try {
|
|
|
|
|
bis = new BufferedInputStream(targetStream);
|
|
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
int i = bis.read(buffer);
|
|
|
|
|
while (i != -1) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
file.delete(); // 删除临时文件
|
|
|
|
|
return ResultBean.success("下载").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|