|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysMenuService;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.util.ExcelUtil;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
@ -12,17 +14,22 @@ import cn.estsh.i3plus.pojo.platform.bean.SysMenu;
|
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
|
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.util.ResultBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
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.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : 系统功能对外接口
|
|
|
|
@ -271,4 +278,118 @@ public class SysMenuController extends CoreBaseController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件上传
|
|
|
|
|
* @param multipart 文件
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/upload")
|
|
|
|
|
@ApiOperation(value = "文件上传", notes = "文件上传")
|
|
|
|
|
public ResultBean singleFileUpload(@RequestParam("file") MultipartFile multipart) {
|
|
|
|
|
try {
|
|
|
|
|
startMultiService();
|
|
|
|
|
|
|
|
|
|
if(multipart.isEmpty()){
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("请选择需要上传的文件。")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
System.out.println("hhh");
|
|
|
|
|
List<SysMenu> list = ExcelUtil.importData("permission.xls",multipart.getInputStream(), SysMenu.class);
|
|
|
|
|
|
|
|
|
|
Map<String,SysMenu> map = new HashMap<>();
|
|
|
|
|
list.forEach(menu -> {
|
|
|
|
|
ValidatorBean.checkNotNull(menu.getMenuCode(), "功能代码不能为空");
|
|
|
|
|
ValidatorBean.checkNotNull(menu.getParentId(), "父级功能ID不能为空");
|
|
|
|
|
|
|
|
|
|
menu.setId(Long.parseLong(menu.getMenuCode()));
|
|
|
|
|
if (!map.containsKey(menu.getMenuCode())) {
|
|
|
|
|
map.put(menu.getMenuCode(),menu);
|
|
|
|
|
} else {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("功能代码【" + menu.getMenuCode() + "】重复")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.forEach(menu -> {
|
|
|
|
|
if(menu.getParentId().longValue() != -1){
|
|
|
|
|
SysMenu mu = map.get(menu.getParentId().toString());
|
|
|
|
|
ValidatorBean.checkNotNull(mu, "【"+menu.getParentId()+"】不存在的父节点信息");
|
|
|
|
|
menu.setParentNameRdd(mu.getName());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("上传成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
|
|
|
|
|
.setResultList(sysMenuService.refreshSysMenu(list));
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件下载
|
|
|
|
|
*
|
|
|
|
|
* @param response response
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/download/excel")
|
|
|
|
|
@ApiOperation(value = "权限文件下载", notes = "权限文件下载")
|
|
|
|
|
public ResultBean singleDownload(HttpServletResponse response) {
|
|
|
|
|
try {
|
|
|
|
|
startMultiService();
|
|
|
|
|
String fileName = "menu_" + System.currentTimeMillis() + ".xls";
|
|
|
|
|
List<SysMenu> list = sysMenuService.findSysMenuAll();
|
|
|
|
|
|
|
|
|
|
File file = new File(fileName);
|
|
|
|
|
file.createNewFile();
|
|
|
|
|
File excle = ExcelUtil.exportData(file, list, SysMenu.class, new String[]{
|
|
|
|
|
"menuCode", "name","parentId","menuType","menuStatus","parentNameRdd","menuUrl","menuClassPath","menuGrade","menuSort"
|
|
|
|
|
,"menuCss","menuIcon","menuDescription"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success("下载").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
}catch(ImppBusiException busExcep){
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|