package com.tiesheng.demo.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.TimeInterval; import cn.hutool.json.JSONUtil; import cn.hutool.log.LogFactory; import cn.hutool.poi.excel.ExcelUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.read.listener.ReadListener; import com.tiesheng.annotation.operation.OperationLog; import com.tiesheng.annotation.token.TokenIgnore; import com.tiesheng.core.service.CoreLogService; import com.tiesheng.core.service.CoreMessageService; import com.tiesheng.core.util.ProcessImportConsumer; import com.tiesheng.database.config.DbBackupConfig; import com.tiesheng.demo.pojos.PoiBean; import com.tiesheng.demo.pojos.TestFile; import com.tiesheng.login.config.token.TsTokenConfig; import com.tiesheng.message.pojos.MessageReqResp; import com.tiesheng.message.pojos.UserChannel; import com.tiesheng.util.config.EncryptConfig; import com.tiesheng.util.config.GlobalConfig; import com.tiesheng.util.config.Ip2regionConfig; import com.tiesheng.util.pojos.ApiResp; import com.tiesheng.util.pojos.FileUploadPath; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.File; import java.util.ArrayList; import java.util.List; /** * @author hao */ @RestController @RequestMapping("/test") public class TestController { @Autowired GlobalConfig globalConfig; @Autowired TsTokenConfig tsTokenConfig; @Autowired Ip2regionConfig ip2regionConfig; @Autowired EncryptConfig encryptConfig; @Autowired CoreMessageService coreMessageService; @Autowired CoreLogService coreLogService; @Autowired DbBackupConfig dbBackupConfig; @RequestMapping("/index") public ApiResp index() { dbBackupConfig.dbBackup(); return ApiResp.respOK("hello world"); } @RequestMapping("/redirect") @TokenIgnore public void redirect(HttpServletResponse response) { ArrayList strings = CollUtil.newArrayList("11111", "22222"); coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer() { @Override public int accept(List list) { LogFactory.get().info("list: " + list.size()); return 0; } @Override public String getFailFile() { LogFactory.get().info("getFailFile: " + strings.size()); return null; } }); LogFactory.get().info("strings: " + strings.size()); // tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true); globalConfig.redirect("mobile", "/test", response); } @GetMapping("/send") @TokenIgnore public ApiResp sendMessage() { MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"), JSONUtil.createObj().putOpt("code", "123456").putOpt("template_code", "SMS_154950909")); return ApiResp.respOK(reqResp); } @RequestMapping("/export") public ApiResp export() { // List list = new ArrayList<>(); // list.add(new TestFile("11111")); // list.add(new TestFile("22222")); // list.add(new TestFile("33333")); // list.add(new TestFile("44444")); // // FileUploadPath fileUploadPath = FileUploadPath.random("xlsx"); // PoiWriteUtil.export(list, TestFile.class, fileUploadPath.getAbsolutePath(), "hahah"); return ApiResp.respOK(""); } @RequestMapping("/uploadPath") @TokenIgnore public ApiResp uploadPath() { FileUploadPath uploadPath = FileUploadPath.file("http://scv6.tmp.kepai365.ltd/upload/2023-01/2b4b6b7b-70d0-4683-859a-f799adc4f04c.xls"); return ApiResp.respOK(uploadPath.getAbsolutePath()); } @RequestMapping("searchIP") @TokenIgnore public ApiResp searchIp() { String search = ip2regionConfig.search("127.0.0.1"); return ApiResp.respOK(search); } @RequestMapping("desensitize") @TokenIgnore public ApiResp> desensitize() { TestFile file = new TestFile("11111"); file.setTest("111111"); TestFile file1 = new TestFile("22222"); file1.setTest("22222"); return ApiResp.respOK(CollUtil.newArrayList(file, file1)); } @RequestMapping("passwd") @TokenIgnore public ApiResp passwd() { String passwdCreate = encryptConfig.passwdCreate("12345Zeng!", ""); LogFactory.get().info(passwdCreate); encryptConfig.passwdVerify("12345Zeng!", passwdCreate); return ApiResp.respOK(""); } @RequestMapping("poi") @TokenIgnore public ApiResp poi() { TimeInterval timeInterval = new TimeInterval(); FileUploadPath file = FileUploadPath.file("/upload/test.xlsx"); EasyExcel.read(new File(file.getAbsolutePath()), PoiBean.class, new ReadListener() { @Override public void invoke(PoiBean poiBean, AnalysisContext analysisContext) { } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { } }).sheet().doRead(); System.out.println("timeInterval: " + timeInterval.interval()); return ApiResp.respOK(""); } @RequestMapping("poiTool") @TokenIgnore public ApiResp poiTool() { TimeInterval timeInterval = new TimeInterval(); FileUploadPath file = FileUploadPath.file("/upload/test.xlsx"); ExcelUtil.getReader(new File(file.getAbsolutePath())).read(); System.out.println("timeInterval: " + timeInterval.interval()); return ApiResp.respOK(""); } }