package com.vci.web.controller;
|
|
import com.vci.constant.FrameWorkLangCodeConstant;
|
import com.vci.corba.framework.data.FuncOperationInfo;
|
import com.vci.frameworkcore.compatibility.ISmFunctionQueryService;
|
import com.vci.frameworkcore.compatibility.SmHMSysModConfigServiceI;
|
import com.vci.pagemodel.MenuVO;
|
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.BaseResult;
|
import com.vci.starter.web.util.ControllerUtil;
|
import com.vci.starter.web.util.LocalFileUtil;
|
import com.vci.starter.web.util.VciBaseUtil;
|
import com.vci.web.util.Func;
|
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.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.Date;
|
import java.util.LinkedList;
|
import java.util.List;
|
|
/**
|
* 首页系统模块配置控制器
|
* @author ludc
|
* @date 2024/8/19 10:55
|
*/
|
@RestController
|
@RequestMapping("/hmSysModConfigController")
|
@VciUnCheckRight
|
public class HMSysModConfigController {
|
|
/**
|
* 功能查询服务
|
*/
|
@Resource
|
private ISmFunctionQueryService functionQueryService;
|
|
/**
|
* 首页系统配置服务
|
*/
|
@Resource
|
private SmHMSysModConfigServiceI hmSysModConfigService;
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 获取当前模块下的子模块
|
* @param parentId
|
* @param modeType
|
* @return
|
*/
|
@GetMapping("/getSysModelTreeMenuByPID")
|
public BaseResult<List<MenuVO>> getSysModelTreeMenuByPID(String parentId, String modeType) {
|
try {
|
return BaseResult.dataList(functionQueryService.getSysModelTreeMenuByPID(parentId,modeType,true));
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "查询子模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 添加模块
|
* @param menuVO
|
* @return
|
*/
|
@PostMapping("/addModel")
|
public BaseResult addModel(@RequestBody MenuVO menuVO) {
|
try {
|
return BaseResult.success(hmSysModConfigService.addModule(menuVO),"模块增加成功!");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "增加模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 修改模块
|
* @param menuVO
|
* @return
|
*/
|
@PutMapping("/updateModel")
|
public BaseResult updateModel(@RequestBody MenuVO menuVO) {
|
try {
|
return BaseResult.success(hmSysModConfigService.updateModule(menuVO),"模块修改成功");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "修改模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 删除模块
|
* @param menuVO
|
* @return
|
*/
|
@DeleteMapping("/delModule")
|
public BaseResult delModule(@RequestBody MenuVO menuVO) {
|
try {
|
return BaseResult.success(hmSysModConfigService.delModule(menuVO),"模块删除成功");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "删除模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 删除模块下关联的操作类型
|
* @param funcOperationInfo
|
* @return
|
*/
|
@DeleteMapping("/delFuncOperation")
|
public BaseResult delFuncOperation(@RequestBody FuncOperationInfo funcOperationInfo) {
|
try {
|
return BaseResult.success(hmSysModConfigService.delFuncOperation(funcOperationInfo),"模块下操作类型删除成功");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "模块下操作类型删除时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 管理功能模块、业务功能模块下的叶子节点—修改操作别名接口
|
* @param menuVO
|
* @return
|
*/
|
@PutMapping("/updateAlias")
|
public BaseResult updateAlias(@RequestBody MenuVO menuVO) {
|
try {
|
return BaseResult.success(hmSysModConfigService.updateAlias(menuVO),"操作别名修改成功");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "操作别名修改时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 添加操作类型
|
* @param funcOperationInfoList
|
* @return
|
*/
|
@PostMapping("/addOperationType")
|
public BaseResult addOperationType(@RequestBody List<FuncOperationInfo> funcOperationInfoList) {
|
try {
|
return BaseResult.success(hmSysModConfigService.addOperationType(funcOperationInfoList),"操作类型添加成功");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "删除模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 删除非系统模块
|
* @return
|
*/
|
@DeleteMapping("/delNonsysModule")
|
public BaseResult delNonsysModule() {
|
try {
|
return BaseResult.success(hmSysModConfigService.delNonsysModule(),"删除非系统模块成功");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "删除非系统模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 删除业务模块
|
* @return
|
*/
|
@PostMapping("/delBusinessModule")
|
public BaseResult delBusinessModule() {
|
try {
|
return BaseResult.success(hmSysModConfigService.delBusinessModule(),"删除业务模块");
|
}catch (Exception e){
|
e.printStackTrace();
|
String errorMsg = "删除业务模块时出现错误,原因:"+ VciBaseUtil.getExceptionMessage(e);
|
logger.error(errorMsg);
|
throw new VciBaseException(errorMsg);
|
}
|
}
|
|
/**
|
* 导出管理功能模块或操作类型管理模块sql
|
* @return
|
*/
|
@GetMapping("/exportFunctionSql")
|
public void exportFunctionSql(HttpServletResponse response,String exportPath,boolean isFunction) {
|
try {
|
File file = hmSysModConfigService.exportFunctionSql(response,exportPath,isFunction);
|
ControllerUtil.writeFileToResponse(response,file,true);
|
} catch (Exception e) {
|
String msg = "导出sql时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
try {
|
//出错时
|
e.printStackTrace();
|
ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
|
} catch (IOException ioException) {
|
ioException.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 导出模块
|
* @return
|
*/
|
@GetMapping("/exportModule")
|
public void exportModule(HttpServletResponse response) {
|
try {
|
String excelPath = hmSysModConfigService.exportModule(response);
|
ControllerUtil.writeFileToResponse(response,excelPath);
|
} catch (Exception e) {
|
String msg = "导出模块时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
|
try {
|
//出错时
|
e.printStackTrace();
|
ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
|
} catch (IOException ioException) {
|
ioException.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 导入模块
|
* @return
|
*/
|
@PostMapping("/importModule")
|
public BaseResult importModule(@RequestParam("files") List<MultipartFile> files) {
|
LinkedList<File> fileList = new LinkedList<>();
|
try {
|
for (MultipartFile file : files) {
|
String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
|
File file1 = new File(excelFileName);
|
file.transferTo(file1);
|
fileList.add(file1);
|
}
|
if(Func.isNotEmpty(fileList)){
|
return hmSysModConfigService.importModule(fileList);
|
} else {
|
return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"});
|
}
|
}catch (Throwable e) {
|
throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e);
|
}finally {
|
fileList.stream().forEach(file -> file.delete());
|
}
|
}
|
|
}
|