| | |
| | | package com.example.controller; |
| | | |
| | | import com.example.utils.DictionaryUtil; |
| | | import com.example.utils.DictionaryUtilNew; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.io.*; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Company: 西安路泰科技有限公司 |
| | |
| | | private static final String LOG_PATH = "src/main/resources/log.log"; |
| | | @Autowired |
| | | private DictionaryUtil dictionaryUtil; |
| | | @Autowired |
| | | private DictionaryUtilNew dictionaryUtilNew; |
| | | |
| | | /** |
| | | * 全部字典同步 |
| | | * @return |
| | | */ |
| | | @GetMapping("exec") |
| | | public String exce(){ |
| | | // 将文件内容设置为空 |
| | |
| | | fileWriter.close(); |
| | | } catch (IOException ignored) {} |
| | | new Thread(()->{ |
| | | try { |
| | | dictionaryUtil.exec1(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // dictionaryUtil.exec1(); |
| | | dictionaryUtilNew.exec1(); |
| | | }).start(); |
| | | return "已提交执行"; |
| | | } |
| | | |
| | | /** |
| | | * 显示日志 |
| | | * @return |
| | | */ |
| | | @GetMapping("/show") |
| | | public String showLog() { |
| | | StringBuilder logContent = new StringBuilder(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 清除日志 |
| | | * @return |
| | | */ |
| | | @GetMapping("/clear") |
| | | public String cleanLog() { |
| | | try { |
| | |
| | | return "Failed to clear log content."; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 手动同步 |
| | | * @param methods 同步的字典名 |
| | | * @param type 是否在同步前清除日志 默认否 |
| | | * @return |
| | | */ |
| | | @PostMapping("exec") |
| | | public String execPost(@RequestParam("methods")List<String > methods,@RequestParam(value = "type",required = false,defaultValue = "false")Boolean type){ |
| | | if (type){ |
| | | FileWriter fileWriter = null; |
| | | try { |
| | | fileWriter = new FileWriter(LOG_PATH); |
| | | fileWriter.write(""); |
| | | fileWriter.close(); |
| | | } catch (IOException ignored) {} |
| | | } |
| | | new Thread(()->{ |
| | | // dictionaryUtil.exec1(); |
| | | dictionaryUtilNew.execMethods(methods); |
| | | }).start(); |
| | | return "已提交执行"; |
| | | } |
| | | } |