|
|
@@ -0,0 +1,76 @@
|
|
|
+package cn.reghao.autodop.dmaster.sys.controller;
|
|
|
+
|
|
|
+import cn.reghao.autodop.common.utils.serializer.JsonConverter;
|
|
|
+import cn.reghao.autodop.dmaster.auth.entity.Role;
|
|
|
+import cn.reghao.autodop.dmaster.auth.repository.RoleRepository;
|
|
|
+import cn.reghao.autodop.dmaster.sys.service.BakService;
|
|
|
+import cn.reghao.autodop.dmaster.sys.service.SysConfig;
|
|
|
+import cn.reghao.autodop.dmaster.utils.UploadDownload;
|
|
|
+import cn.reghao.autodop.dmaster.utils.WebBody;
|
|
|
+import cn.reghao.autodop.dmaster.utils.db.PageList;
|
|
|
+import cn.reghao.autodop.dmaster.utils.db.PageSort;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2021-04-04 21:24:18
|
|
|
+ */
|
|
|
+@Api(tags = "用户页面")
|
|
|
+@RequestMapping("/sys")
|
|
|
+@Controller
|
|
|
+public class SysPageController {
|
|
|
+ private BakService bakService;
|
|
|
+ private UploadDownload uploadDownload;
|
|
|
+ private RoleRepository roleRepository;
|
|
|
+
|
|
|
+ public SysPageController(BakService bakService,
|
|
|
+ UploadDownload uploadDownload,
|
|
|
+ RoleRepository roleRepository) {
|
|
|
+ this.bakService = bakService;
|
|
|
+ this.uploadDownload = uploadDownload;
|
|
|
+ this.roleRepository = roleRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "系统备份还原页面")
|
|
|
+ @GetMapping("/bak")
|
|
|
+ public String sysBakPage(Model model) {
|
|
|
+ PageRequest pageRequest = PageSort.pageRequest();
|
|
|
+ Page<Role> rolePage = roleRepository.findAll(pageRequest);
|
|
|
+ PageList<Role> pageList = PageList.pageList(rolePage);
|
|
|
+
|
|
|
+ model.addAttribute("page", rolePage);
|
|
|
+ model.addAttribute("list", pageList.getList());
|
|
|
+ return "/sys/bak";
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "数据备份")
|
|
|
+ @GetMapping("/bak/export")
|
|
|
+ @ResponseBody
|
|
|
+ public void dataBackup(HttpServletResponse response) throws IOException {
|
|
|
+ String json = bakService.bakSysConfig();
|
|
|
+ ByteArrayInputStream bytesIn = new ByteArrayInputStream(json.getBytes());
|
|
|
+ BufferedInputStream bis = new BufferedInputStream(bytesIn);
|
|
|
+ uploadDownload.download(bis, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "数据还原")
|
|
|
+ @PostMapping("/bak/import")
|
|
|
+ @ResponseBody
|
|
|
+ public String dataRestore(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ String json = new String(bytes, StandardCharsets.UTF_8);
|
|
|
+ SysConfig sysConfig = JsonConverter.jsonToObject(json, SysConfig.class);
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+}
|