package io.dataease.controller.sys; import io.dataease.base.domain.SystemParameter; import io.dataease.commons.constants.ParamConstants; import io.dataease.controller.sys.response.BasicInfo; import io.dataease.controller.sys.response.MailInfo; import io.dataease.dto.SystemParameterDTO; import io.dataease.listener.DatasetCheckListener; import io.dataease.listener.util.CacheUtils; import io.dataease.service.FileService; import io.dataease.service.system.EmailService; import io.dataease.service.system.SystemParameterService; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import javax.annotation.Resource; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @ApiIgnore @RestController @RequestMapping(value = "/system") public class SystemParameterController { @Resource private SystemParameterService systemParameterService; @Resource private FileService fileService; @Resource private EmailService emailService; @RequiresPermissions("sysparam:read") @GetMapping("/mail/info") public MailInfo mailInfo() { return emailService.mailInfo(); } @RequiresPermissions("sysparam:read") @GetMapping("/basic/info") public BasicInfo basicInfo() { return systemParameterService.basicInfo(); } @GetMapping("/requestTimeOut") public Integer RequestTimeOut() { BasicInfo basicInfo = systemParameterService.basicInfo(); return StringUtils.isNotBlank(basicInfo.getFrontTimeOut()) ? Integer.parseInt(basicInfo.getFrontTimeOut()) : 10; } @RequiresPermissions("sysparam:read") @PostMapping("/edit/email") public void editMail(@RequestBody List systemParameter) { emailService.editMail(systemParameter); } @RequiresPermissions("sysparam:read") @PostMapping("/edit/basic") public void editBasic(@RequestBody List systemParameter) { systemParameterService.editBasic(systemParameter); } @PostMapping("/testConnection") public void testConnection(@RequestBody HashMap hashMap) { emailService.testConnection(hashMap); } @GetMapping("/version") public String getVersion() { return systemParameterService.getVersion(); } @RequiresPermissions("sysparam:read") @GetMapping("/base/info") public List getBaseInfo() { return systemParameterService.getSystemParameterInfo(ParamConstants.Classify.BASE.getValue()); } @GetMapping("/ui/info") public List getDisplayInfo() { return systemParameterService.getSystemParameterInfo(ParamConstants.Classify.UI.getValue()); } @GetMapping(value = "/ui/image/{imageId}", produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE}) public ResponseEntity image(@PathVariable("imageId") String imageId) { byte[] bytes = fileService.loadFileAsBytes(imageId); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<>(bytes, headers, HttpStatus.OK); } @PostMapping(value = "/save/ui", consumes = {"multipart/form-data"}) public void saveUIInfo(@RequestPart("request") Map> systemParameterMap, @RequestPart(value = "files", required = false) List bodyFiles) throws IOException { systemParameterService.saveUIInfo(systemParameterMap, bodyFiles); } @PostMapping(value = "/checkCustomDs") public boolean checkCustomDs() { try { Object cache = CacheUtils.get(DatasetCheckListener.CACHE_NAME, DatasetCheckListener.CACHE_KEY); return cache != null && (boolean) cache; } catch (Exception e) { return false; } } }