From 3fc51e7cbdabb7dcd1615c6efac52323f6ca8adb Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期三, 03 七月 2024 18:28:34 +0800 Subject: [PATCH] 代码提交 --- ruoyi-common/src/main/java/com/ruoyi/common/enums/RadioEnum.java | 45 +++ ruoyi-admin/pom.xml | 50 +++ ruoyi-common/src/main/java/com/ruoyi/common/enums/PhotoEnum.java | 45 +++ ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java | 112 ++++++++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java | 224 +++++++++++++--- ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java | 82 ----- ruoyi-common/src/main/java/com/ruoyi/common/enums/VadioEnum.java | 45 +++ ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java | 154 +++++------ smartor/src/main/java/com/smartor/service/impl/CommonTaskServiceImpl.java | 38 +- 9 files changed, 569 insertions(+), 226 deletions(-) diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index c0a1b9c..f425abc 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -130,8 +130,42 @@ <artifactId>nls-sdk-common</artifactId> <version>2.1.6</version> </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>5.2.3</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-scratchpad</artifactId> + <version>5.2.3</version> + </dependency> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.12.0</version> + </dependency> + <dependency> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + <version>1.4.01</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml</artifactId> + <version>5.2.3</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml-schemas</artifactId> + <version>4.1.2</version> + </dependency> + <dependency> + <groupId>org.apache.xmlbeans</groupId> + <artifactId>xmlbeans</artifactId> + <version>3.1.0</version> + </dependency> </dependencies> - <build> <plugins> <plugin> @@ -162,4 +196,18 @@ <finalName>${project.artifactId}</finalName> </build> + <repositories> + <repository> + <id>central</id> + <url>https://repo.maven.apache.org/maven2</url> + </repository> + <repository> + <id>aliyun</id> + <url>https://maven.aliyun.com/repository/public</url> + </repository> + <repository> + <id>jcenter</id> + <url>https://jcenter.bintray.com/</url> + </repository> + </repositories> </project> diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java b/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java index dae2a6a..d5e72b6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java @@ -263,6 +263,118 @@ } /** + * 瀹f暀浠诲姟澶勭悊 + * + * @param commonTaskcallMQ + */ + private void xjHandle(CommonTaskcallMQ commonTaskcallMQ) { + //鍒ゆ柇涓�涓媍ommonTaskcallMQ涓殑stopstate鏄惁涓巌vr_task涓殑涓�鑷达紝涓嶄竴鑷达紝鍒欒鏄庢槸鏆傚仠浜� + ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); + if (ivrTask1.getStopState() != commonTaskcallMQ.getStopState()) { + //灏嗘秷鎭粠闃熷垪涓墧闄� + return; + } + + if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { + //濡備綍浠诲姟鍙戦�佹柟寮忎笉涓虹┖ + String[] split = commonTaskcallMQ.getPreachform().split(","); + System.out.println("split鐨勫�间负锛�" + split); + for (String serviceFrom : split) { + String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom)); + //杩欓噷鍙互鑰冭檻鐢ㄧ瓥鐣ユā寮忎紭鍖栦竴涓嬶紝涓嶇劧澶毦鐪嬩簡 + + //閫氳繃妯℃澘ID鑾峰彇妯℃澘闂 + IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); + ivrTaskTemplateVO.setID(Long.valueOf(commonTaskcallMQ.getTemplateid())); + IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); + + //閫氳繃浠诲姟ID鎷垮埌鎮h�呬俊鎭� + ServiceSubtask ivrTaskcall = new ServiceSubtask(); + ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); + List<ServiceSubtask> ivrTaskcalls = ivrTaskcallMapper.selectServiceSubtaskList(ivrTaskcall); + if (descByCode.equals("鐢佃瘽")) { + for (ServiceSubtask ivrTaskcall1 : ivrTaskcalls) { + ServiceTask ivrTask = ivrTaskMapper.selectServiceTaskByTaskid(ivrTaskcall1.getTaskid()); + if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) { + //濡備綍浠诲姟琚�滄殏鍋溾�濇垨鈥滅粓姝⑩�� + break; + } + + //浠诲姟鍙戦�佽褰曪紙杩欎釜浠g爜搴旇鍐欏湪phoneTask涓紝鍏堝啓鍦ㄨ繖锛屽悗闈㈠啀鏀癸級 + ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); + serviceSubtaskRecord.setTaskid(ivrTaskcall1.getTaskid().toString()); + serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); + serviceSubtaskRecord.setTasktype(ivrTaskcall1.getType()); + serviceSubtaskRecord.setPreachform("3"); + serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); + serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); + + //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽 + executorService.submit(new PhoneTask(ivrTaskcall1, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils)); + } + } else if (descByCode.equals("澶氬獟浣�")) { + //澶氬獟浣� + } else if (descByCode.equals("绾歌川")) { + //绾歌川 + } else if (descByCode.equals("鐭俊")) { + //鐭俊 +// http://localhost:8099/followvisit/particty?param1=3¶m2=348 + //瀵箄rl涓袱涓弬鏁板姞瀵� + RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); + String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); + + + for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) { + String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); + SendMagParam sendMagParam = new SendMagParam(); + sendMagParam.setType("4"); + sendMagParam.setUrl(req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid); + Boolean aBoolean = sendService.sendMsg(sendMagParam); + + //浠诲姟鍙戦�佽褰� + ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); + serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString()); + serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); + serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType()); + serviceSubtaskRecord.setPreachform("4"); + serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); + serviceSubtaskRecord.setResult(aBoolean == true ? "鎴愬姛" : "澶辫触"); + serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); + } + } else if (descByCode.equals("鍏紬鍙�")) { + //鍏紬鍙� + RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); + String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); + for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) { + String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); + SendMagParam sendMagParam = new SendMagParam(); + sendMagParam.setType("5"); + sendMagParam.setUrl(req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName()); + log.info("閾炬帴瀹屾暣璺緞锛歿}", req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName()); + //杩欎釜妯℃澘ID鍏堝啓姝伙紝鍚庨潰鍋氭垚鍙�� + sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4"); + Map map = new HashMap(); + map.put("first", ivrTask1.getTaskName()); + sendMagParam.setContent(JSON.toJSONString(map)); + Boolean aBoolean = sendService.sendMsg(sendMagParam); + + //浠诲姟鍙戦�佽褰� + ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); + serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString()); + serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); + serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType()); + serviceSubtaskRecord.setPreachform("4"); + serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); + serviceSubtaskRecord.setResult(aBoolean == true ? "鎴愬姛" : "澶辫触"); + serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); + } + } + //閫氱煡 MQ 娑堟伅宸茶鎺ユ敹,鍙互ACK(浠庨槦鍒椾腑鍒犻櫎)浜� 锛堣繖涓渶瑕佹牴鎹笟鍔″啀鍘诲鐞咥CK锛� + } + } + } + + /** * 闂嵎浠诲姟澶勭悊 * * @param commonTaskcallMQ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java index cec5006..5268e61 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java @@ -1,9 +1,26 @@ package com.ruoyi.web.controller.common; +import java.io.*; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.lang.model.util.Elements; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import com.ruoyi.common.enums.PhotoEnum; +import com.ruoyi.common.enums.RadioEnum; +import com.ruoyi.common.enums.VadioEnum; +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.converter.PicturesManager; +import org.apache.poi.hwpf.converter.WordToHtmlConverter; +import org.apache.poi.hwpf.usermodel.Picture; +import org.apache.poi.hwpf.usermodel.PictureType; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -20,16 +37,17 @@ import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.framework.config.ServerConfig; +import org.springframework.web.multipart.commons.CommonsMultipartFile; +import org.w3c.dom.Document; /** * 閫氱敤璇锋眰澶勭悊 - * + * * @author ruoyi */ @RestController @RequestMapping("/common") -public class CommonController -{ +public class CommonController { private static final Logger log = LoggerFactory.getLogger(CommonController.class); @Autowired @@ -39,17 +57,14 @@ /** * 閫氱敤涓嬭浇璇锋眰 - * + * * @param fileName 鏂囦欢鍚嶇О - * @param delete 鏄惁鍒犻櫎 + * @param delete 鏄惁鍒犻櫎 */ @GetMapping("/download") - public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) - { - try - { - if (!FileUtils.checkAllowDownload(fileName)) - { + public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { + try { + if (!FileUtils.checkAllowDownload(fileName)) { throw new Exception(StringUtils.format("鏂囦欢鍚嶇О({})闈炴硶锛屼笉鍏佽涓嬭浇銆� ", fileName)); } String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); @@ -58,14 +73,71 @@ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); FileUtils.setAttachmentResponseHeader(response, realFileName); FileUtils.writeBytes(filePath, response.getOutputStream()); - if (delete) - { + if (delete) { FileUtils.deleteFile(filePath); } - } - catch (Exception e) - { + } catch (Exception e) { log.error("涓嬭浇鏂囦欢澶辫触", e); + } + } + + /** + * 鍒嗙被涓婁紶璇锋眰 + */ + @PostMapping("/uploadSort") + public AjaxResult uploadFileSort(MultipartFile file) { + try { + // 涓婁紶鏂囦欢璺緞 + String filePath = RuoYiConfig.getUploadPath(); + String originalFilename = file.getOriginalFilename().split("\\.", 2)[1]; + if (VadioEnum.getDescByCode(originalFilename)) { + filePath = filePath + "/vadio"; + } else if (RadioEnum.getDescByCode(originalFilename)) { + filePath = filePath + "/radio"; + } else if (PhotoEnum.getDescByCode(originalFilename)) { + filePath = filePath + "/photo"; + } else { + filePath = filePath + "/file"; + } + // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О + String fileName = FileUploadUtils.uploadSort(filePath, file); + String url = serverConfig.getUrl() + fileName; + AjaxResult ajax = AjaxResult.success(); + ajax.put("url", url); + ajax.put("fileName", fileName); + ajax.put("newFileName", FileUtils.getName(fileName)); + ajax.put("originalFilename", file.getOriginalFilename()); + return ajax; + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 涓婁紶骞惰浆鎴恏tml璇锋眰 + */ + @PostMapping("/uploadShow") + public AjaxResult uploadFileShow(MultipartFile file) { + try { + // 涓婁紶鏂囦欢璺緞 + String filePath = RuoYiConfig.getUploadPath(); + String originalFilename = file.getOriginalFilename().split("\\.", 2)[1]; + filePath = filePath + "/show/" + file.getOriginalFilename().split("\\.", 2)[0]; + // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О + String fileName = FileUploadUtils.uploadSort(filePath, file); + //灏唚ord杞垚html + convertDocToHtml(filePath + "\\" + file.getOriginalFilename(), filePath + "\\" + file.getOriginalFilename().split("\\.", 2)[0] + ".html", filePath); + updatePicture(filePath + "\\" + file.getOriginalFilename().split("\\.", 2)[0] + ".html"); + + String url = serverConfig.getUrl() + fileName.replaceAll("\\.[^.]*$", ".html"); + AjaxResult ajax = AjaxResult.success(); + ajax.put("url", url); + ajax.put("fileName", fileName); + ajax.put("newFileName", FileUtils.getName(fileName)); + ajax.put("originalFilename", file.getOriginalFilename()); + return ajax; + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); } } @@ -73,10 +145,8 @@ * 閫氱敤涓婁紶璇锋眰锛堝崟涓級 */ @PostMapping("/upload") - public AjaxResult uploadFile(MultipartFile file) throws Exception - { - try - { + public AjaxResult uploadFile(MultipartFile file) { + try { // 涓婁紶鏂囦欢璺緞 String filePath = RuoYiConfig.getUploadPath(); // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О @@ -88,9 +158,7 @@ ajax.put("newFileName", FileUtils.getName(fileName)); ajax.put("originalFilename", file.getOriginalFilename()); return ajax; - } - catch (Exception e) - { + } catch (Exception e) { return AjaxResult.error(e.getMessage()); } } @@ -99,18 +167,15 @@ * 閫氱敤涓婁紶璇锋眰锛堝涓級 */ @PostMapping("/uploads") - public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception - { - try - { + public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception { + try { // 涓婁紶鏂囦欢璺緞 String filePath = RuoYiConfig.getUploadPath(); List<String> urls = new ArrayList<String>(); List<String> fileNames = new ArrayList<String>(); List<String> newFileNames = new ArrayList<String>(); List<String> originalFilenames = new ArrayList<String>(); - for (MultipartFile file : files) - { + for (MultipartFile file : files) { // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О String fileName = FileUploadUtils.upload(filePath, file); String url = serverConfig.getUrl() + fileName; @@ -125,9 +190,7 @@ ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); return ajax; - } - catch (Exception e) - { + } catch (Exception e) { return AjaxResult.error(e.getMessage()); } } @@ -136,13 +199,9 @@ * 鏈湴璧勬簮閫氱敤涓嬭浇 */ @GetMapping("/download/resource") - public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) - throws Exception - { - try - { - if (!FileUtils.checkAllowDownload(resource)) - { + public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) throws Exception { + try { + if (!FileUtils.checkAllowDownload(resource)) { throw new Exception(StringUtils.format("璧勬簮鏂囦欢({})闈炴硶锛屼笉鍏佽涓嬭浇銆� ", resource)); } // 鏈湴璧勬簮璺緞 @@ -154,10 +213,91 @@ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); FileUtils.setAttachmentResponseHeader(response, downloadName); FileUtils.writeBytes(downloadPath, response.getOutputStream()); - } - catch (Exception e) - { + } catch (Exception e) { log.error("涓嬭浇鏂囦欢澶辫触", e); } } + + + private void convertDocToHtml(String docFilePath, String outputHtmlFilePath, String imageDirPath) throws IOException, ParserConfigurationException { + // Load DOC into HWPFDocument + InputStream inputStream = new FileInputStream(docFilePath); + HWPFDocument document = new HWPFDocument(inputStream); + // Prepare HTML output + WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); + // Set PicturesManager to handle image saving + wordToHtmlConverter.setPicturesManager(new PicturesManager() { + @Override + public String savePicture(byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches) { + File imageFile = new File(imageDirPath + "/" + suggestedName); + try (FileOutputStream fos = new FileOutputStream(imageFile)) { + fos.write(content); + } catch (IOException e) { + e.printStackTrace(); + } + return suggestedName; + } + }); + // Convert document to HTML + wordToHtmlConverter.processDocument(document); + // Save images + List<Picture> pics = document.getPicturesTable().getAllPictures(); + if (pics != null) { + for (Picture pic : pics) { + try (FileOutputStream fos = new FileOutputStream(imageDirPath + "/" + pic.suggestFullFileName())) { + fos.write(pic.getContent()); + } + } + } + // Convert to HTML + Document htmlDocument = wordToHtmlConverter.getDocument(); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + org.apache.xml.serialize.OutputFormat format = new org.apache.xml.serialize.OutputFormat(htmlDocument); + org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(outStream, format); + serializer.serialize(htmlDocument); + // Write HTML file + try (OutputStream outputStream = new FileOutputStream(outputHtmlFilePath)) { + outputStream.write(outStream.toByteArray()); + } + } + + private void updatePicture(String htmlFilePath) { + try { + // Load HTML file + File inputFile = new File(htmlFilePath); + org.jsoup.nodes.Document doc = Jsoup.parse(inputFile, "UTF-8"); + + // Select all elements with style attribute and modify their width and height to 90% + org.jsoup.select.Elements elementsWithStyle = doc.select("[style]"); + for (Element element : elementsWithStyle) { + String style = element.attr("style"); + String modifiedStyle = modifyStyle(style); + element.attr("style", modifiedStyle); + } + + // Save the modified HTML to output file + try (FileWriter writer = new FileWriter(htmlFilePath)) { + writer.write(doc.outerHtml()); + } + + System.out.println("Modification completed successfully."); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private String modifyStyle(String style) { + // Define patterns for width and height + Pattern widthPattern = Pattern.compile("width\\s*:\\s*[^;]+"); + Pattern heightPattern = Pattern.compile("height\\s*:\\s*[^;]+"); + + // Replace width and height with 90% + Matcher widthMatcher = widthPattern.matcher(style); + style = widthMatcher.replaceAll("width: 90%"); + + Matcher heightMatcher = heightPattern.matcher(style); + style = heightMatcher.replaceAll("height: 90%"); + + return style; + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java b/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java index c216a11..b9d0b75 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java @@ -1,94 +1,16 @@ package com.ruoyi.web.test; -import com.ruoyi.web.task.PhoneTask; import org.junit.Test; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.beans.factory.annotation.Autowired; - -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import java.security.*; -import java.security.spec.PKCS8EncodedKeySpec; -import java.util.Base64; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; //@SpringBootTest //@RunWith(SpringRunner.class) public class MQTest { - @Autowired - private RabbitTemplate rabbitTemplate; - @Test - public void testSend() { - try { - - // 鐢熸垚RSA瀵嗛挜瀵� - KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); - keyPairGenerator.initialize(2048); - KeyPair keyPair = keyPairGenerator.generateKeyPair(); - - // 鑾峰彇鍏挜鍜岀閽� - PublicKey publicKey = keyPair.getPublic(); - PrivateKey privateKey = keyPair.getPrivate(); - String publicKeyString = Base64.getEncoder().encodeToString(privateKey.getEncoded()); - System.out.println(publicKeyString); - // 鏄庢枃 - String plainText = "Hello, World!"; - - // 鍔犲瘑 - Cipher encryptCipher = Cipher.getInstance("RSA"); - encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey); - byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes()); - - // 灏嗗姞瀵嗗悗鐨勬暟鎹浆鎹负Base64缂栫爜鐨勫瓧绗︿覆 - String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes); - System.out.println("鍔犲瘑鍚庣殑鏁版嵁锛�" + encryptedText); - - // 瑙e瘑 - Cipher decryptCipher = Cipher.getInstance("RSA"); - decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedBytes)); - - // 鏄庢枃 - String decryptedText = new String(decryptedBytes); - System.out.println("瑙e瘑鍚庣殑鏁版嵁锛�" + decryptedText); - } catch (Exception e) { - - } - -// String str = "absdf"; -// String c = Character.toUpperCase(str.charAt(0)) + str.substring(1); -// System.out.println(c); - "鎮ㄥソ锛屾垜鏄禉浜屽尰闄㈠紶鍖荤敓锛屾偍鏄�${name}鍚楋紵杩樻槸瀹跺睘?".replaceAll("$$*variable", "AA"); -// Pattern pattern = Pattern.compile("^(?!.*(濂絴澶ソ)).*$"); -// Matcher matcher = pattern.matcher("鐫$湢涓嶅ソ"); -// System.out.println(matcher.matches()); - // 鍒涘缓鍥哄畾澶у皬鐨勭嚎绋嬫睜 -// ExecutorService executorService = Executors.newFixedThreadPool(10); -// -// executorService.submit(new PhoneTask()); - } @Test public void testSend22() { - try { - byte[] privateKeyBytes = Base64.getDecoder().decode(""); - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes); - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - PrivateKey privateKey = keyFactory.generatePrivate(keySpec); - // 浣跨敤绉侀挜瑙e瘑鏁版嵁 - Cipher decryptCipher = Cipher.getInstance("RSA"); - decryptCipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode("")); - - // 瑙e瘑鍚庣殑鏁版嵁 - String decryptedData = new String(decryptedBytes); - System.out.println("瑙e瘑鍚庣殑鏁版嵁锛�" + decryptedData); - } catch (Exception e) { - } } + + } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/PhotoEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/PhotoEnum.java new file mode 100644 index 0000000..0005c79 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/PhotoEnum.java @@ -0,0 +1,45 @@ +package com.ruoyi.common.enums; + +/** + * 鍙戦�佺被鍨嬫灇涓� + */ +public enum PhotoEnum { + jpg("jpg ", "jpg "), jpeg("jpeg", "jpeg"), png("png", "png"), gif("gif", "gif"), bmp("bmp", "bmp"), tiff("tiff ", "tiff "), tif("tif", "tif"), svg("svg", "svg"); + + + private String code; + private String desc; + + PhotoEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static Boolean getDescByCode(String code) { + PhotoEnum[] organEnums = values(); + for (int i = 0; i < organEnums.length; i++) { + PhotoEnum organEnum = organEnums[i]; + if (organEnum.getCode().equals(code)) { + return true; + } + } + return false; + } + + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/RadioEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/RadioEnum.java new file mode 100644 index 0000000..ece9b59 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/RadioEnum.java @@ -0,0 +1,45 @@ +package com.ruoyi.common.enums; + +/** + * 鍙戦�佺被鍨嬫灇涓� + */ +public enum RadioEnum { + mp3("mp3", "mp3"), wav("wav", "wav"), flac("flac", "flac"), aac("aac", "aac"), ogg("ogg", "ogg"), wma("wma", "wma"); + + + private String code; + private String desc; + + RadioEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static Boolean getDescByCode(String code) { + RadioEnum[] organEnums = values(); + for (int i = 0; i < organEnums.length; i++) { + RadioEnum organEnum = organEnums[i]; + if (organEnum.getCode().equals(code)) { + return true; + } + } + return false; + } + + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/VadioEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/VadioEnum.java new file mode 100644 index 0000000..86fbf88 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/VadioEnum.java @@ -0,0 +1,45 @@ +package com.ruoyi.common.enums; + +/** + * 鍙戦�佺被鍨嬫灇涓� + */ +public enum VadioEnum { + avi("avi", "avi"), mpeg("mpeg", "mpeg"), mp4("mp4", "mp4"), wmv("wmv", "wmv"), flv("flv", "flv"), mov("mov", "mov"), rmvb("rmvb", "rmvb"), mkv("mkv", "mkv"); + + + private String code; + private String desc; + + VadioEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static Boolean getDescByCode(String code) { + VadioEnum[] organEnums = values(); + for (int i = 0; i < organEnums.length; i++) { + VadioEnum organEnum = organEnums[i]; + if (organEnum.getCode().equals(code)) { + return true; + } + } + return false; + } + + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java index d9f2b13..7e5a9ea 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Paths; import java.util.Objects; + import org.apache.commons.io.FilenameUtils; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.config.RuoYiConfig; @@ -20,8 +21,7 @@ * * @author ruoyi */ -public class FileUploadUtils -{ +public class FileUploadUtils { /** * 榛樿澶у皬 50M */ @@ -37,13 +37,11 @@ */ private static String defaultBaseDir = RuoYiConfig.getProfile(); - public static void setDefaultBaseDir(String defaultBaseDir) - { + public static void setDefaultBaseDir(String defaultBaseDir) { FileUploadUtils.defaultBaseDir = defaultBaseDir; } - public static String getDefaultBaseDir() - { + public static String getDefaultBaseDir() { return defaultBaseDir; } @@ -54,14 +52,10 @@ * @return 鏂囦欢鍚嶇О * @throws Exception */ - public static final String upload(MultipartFile file) throws IOException - { - try - { + public static final String upload(MultipartFile file) throws IOException { + try { return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); - } - catch (Exception e) - { + } catch (Exception e) { throw new IOException(e.getMessage(), e); } } @@ -70,18 +64,14 @@ * 鏍规嵁鏂囦欢璺緞涓婁紶 * * @param baseDir 鐩稿搴旂敤鐨勫熀鐩綍 - * @param file 涓婁紶鐨勬枃浠� + * @param file 涓婁紶鐨勬枃浠� * @return 鏂囦欢鍚嶇О * @throws IOException */ - public static final String upload(String baseDir, MultipartFile file) throws IOException - { - try - { + public static final String upload(String baseDir, MultipartFile file) throws IOException { + try { return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); - } - catch (Exception e) - { + } catch (Exception e) { throw new IOException(e.getMessage(), e); } } @@ -89,22 +79,18 @@ /** * 鏂囦欢涓婁紶 * - * @param baseDir 鐩稿搴旂敤鐨勫熀鐩綍 - * @param file 涓婁紶鐨勬枃浠� + * @param baseDir 鐩稿搴旂敤鐨勫熀鐩綍 + * @param file 涓婁紶鐨勬枃浠� * @param allowedExtension 涓婁紶鏂囦欢绫诲瀷 * @return 杩斿洖涓婁紶鎴愬姛鐨勬枃浠跺悕 - * @throws FileSizeLimitExceededException 濡傛灉瓒呭嚭鏈�澶уぇ灏� + * @throws FileSizeLimitExceededException 濡傛灉瓒呭嚭鏈�澶уぇ灏� * @throws FileNameLengthLimitExceededException 鏂囦欢鍚嶅お闀� - * @throws IOException 姣斿璇诲啓鏂囦欢鍑洪敊鏃� - * @throws InvalidExtensionException 鏂囦欢鏍¢獙寮傚父 + * @throws IOException 姣斿璇诲啓鏂囦欢鍑洪敊鏃� + * @throws InvalidExtensionException 鏂囦欢鏍¢獙寮傚父 */ - public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) - throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, - InvalidExtensionException - { + public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension) throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, InvalidExtensionException { int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length(); - if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) - { + if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) { throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); } @@ -118,30 +104,52 @@ } /** - * 缂栫爜鏂囦欢鍚� + * 鏂囦欢涓婁紶 + * + * @param baseDir 鐩稿搴旂敤鐨勫熀鐩綍 + * @param file 涓婁紶鐨勬枃浠� + * @param allowedExtension 涓婁紶鏂囦欢绫诲瀷 + * @return 杩斿洖涓婁紶鎴愬姛鐨勬枃浠跺悕 + * @throws FileSizeLimitExceededException 濡傛灉瓒呭嚭鏈�澶уぇ灏� + * @throws FileNameLengthLimitExceededException 鏂囦欢鍚嶅お闀� + * @throws IOException 姣斿璇诲啓鏂囦欢鍑洪敊鏃� + * @throws InvalidExtensionException 鏂囦欢鏍¢獙寮傚父 */ - public static final String extractFilename(MultipartFile file) - { - return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), - FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); + public static final String uploadSort(String baseDir, MultipartFile file) throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException, InvalidExtensionException { + int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length(); + if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) { + throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); + } + + assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); + + String fileName = file.getOriginalFilename(); + + String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); + file.transferTo(Paths.get(absPath)); + return getPathFileName(baseDir, fileName); } - public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException - { + /** + * 缂栫爜鏂囦欢鍚� + */ + public static final String extractFilename(MultipartFile file) { + return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); + } + + + public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException { File desc = new File(uploadDir + File.separator + fileName); - if (!desc.exists()) - { - if (!desc.getParentFile().exists()) - { + if (!desc.exists()) { + if (!desc.getParentFile().exists()) { desc.getParentFile().mkdirs(); } } return desc; } - public static final String getPathFileName(String uploadDir, String fileName) throws IOException - { + public static final String getPathFileName(String uploadDir, String fileName) throws IOException { int dirLastIndex = RuoYiConfig.getProfile().length() + 1; String currentDir = StringUtils.substring(uploadDir, dirLastIndex); return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; @@ -155,41 +163,24 @@ * @throws FileSizeLimitExceededException 濡傛灉瓒呭嚭鏈�澶уぇ灏� * @throws InvalidExtensionException */ - public static final void assertAllowed(MultipartFile file, String[] allowedExtension) - throws FileSizeLimitExceededException, InvalidExtensionException - { + public static final void assertAllowed(MultipartFile file, String[] allowedExtension) throws FileSizeLimitExceededException, InvalidExtensionException { long size = file.getSize(); - if (size > DEFAULT_MAX_SIZE) - { + if (size > DEFAULT_MAX_SIZE) { throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024); } String fileName = file.getOriginalFilename(); String extension = getExtension(file); - if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) - { - if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) - { - throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension, - fileName); - } - else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) - { - throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension, - fileName); - } - else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) - { - throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, - fileName); - } - else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) - { - throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension, - fileName); - } - else - { + if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) { + if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) { + throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension, fileName); + } else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) { + throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension, fileName); + } else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) { + throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension, fileName); + } else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) { + throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension, fileName); + } else { throw new InvalidExtensionException(allowedExtension, extension, fileName); } } @@ -202,12 +193,9 @@ * @param allowedExtension * @return */ - public static final boolean isAllowedExtension(String extension, String[] allowedExtension) - { - for (String str : allowedExtension) - { - if (str.equalsIgnoreCase(extension)) - { + public static final boolean isAllowedExtension(String extension, String[] allowedExtension) { + for (String str : allowedExtension) { + if (str.equalsIgnoreCase(extension)) { return true; } } @@ -220,11 +208,9 @@ * @param file 琛ㄥ崟鏂囦欢 * @return 鍚庣紑鍚� */ - public static final String getExtension(MultipartFile file) - { + public static final String getExtension(MultipartFile file) { String extension = FilenameUtils.getExtension(file.getOriginalFilename()); - if (StringUtils.isEmpty(extension)) - { + if (StringUtils.isEmpty(extension)) { extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType())); } return extension; diff --git a/smartor/src/main/java/com/smartor/service/impl/CommonTaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/CommonTaskServiceImpl.java index 0067dc4..ca3dcf8 100644 --- a/smartor/src/main/java/com/smartor/service/impl/CommonTaskServiceImpl.java +++ b/smartor/src/main/java/com/smartor/service/impl/CommonTaskServiceImpl.java @@ -36,7 +36,7 @@ private IServiceTaskService ivrTaskService; @Autowired - private ISvyTaskService iSvyTaskService; + private IServiceTaskService iServiceTaskService; @Autowired private RedisCache redisCache; @@ -131,40 +131,40 @@ } public int wjSend(SendTaskVO sendTaskVO) { - SvyTask svyTask = iSvyTaskService.selectSvyTaskByTaskid(sendTaskVO.getTaskId()); + ServiceTask serviceTask1 = iServiceTaskService.selectServiceTaskByTaskid(sendTaskVO.getTaskId()); if (sendTaskVO.getSendState() != null && sendTaskVO.getSendState() == 3 || sendTaskVO.getSendState() != null && sendTaskVO.getSendState() == 4) { //浠诲姟鏆傚仠鎴栫粓姝� - SvyTask serviceTask = new SvyTask(); + ServiceTask serviceTask = new ServiceTask(); serviceTask.setTaskid(sendTaskVO.getTaskId()); - serviceTask.setStopState(svyTask.getStopState() + 1); - serviceTask.setSendState(sendTaskVO.getSendState().toString()); - iSvyTaskService.updateSvyTask(serviceTask); + serviceTask.setStopState(serviceTask1.getStopState() + 1); + serviceTask.setSendState(sendTaskVO.getSendState()); + iServiceTaskService.updateServiceTask(serviceTask); return 0; } //鍒ゆ柇鍙戦�佺姸鎬佹槸鍚︿负绌� if (StringUtils.isEmpty(sendTaskVO.getSendType())) { - sendTaskVO.setSendType(svyTask.getSendType().toString()); + sendTaskVO.setSendType(serviceTask1.getSendType().toString()); } //鍒ゆ柇浠诲姟鏄惁鏄珛鍗冲彂閫� if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("2")) { - String content = sendMQContent(sendTaskVO, svyTask.getTemplateid(), svyTask.getPreachform(), svyTask.getStopState(), null); + String content = sendMQContent(sendTaskVO, serviceTask1.getTemplateid().toString(), serviceTask1.getPreachform(), serviceTask1.getStopState(), null); //绔嬪嵆鍙戦�� redisCache.setCacheObject(content, content, 1, TimeUnit.SECONDS); //灏嗕换鍔$姸鎬佷慨鏀规垚鎵ц涓� - SvyTask serviceTask = new SvyTask(); - serviceTask.setTaskid(svyTask.getTaskid()); - serviceTask.setSendState("2"); - iSvyTaskService.updateSvyTask(serviceTask); + ServiceTask serviceTask = new ServiceTask(); + serviceTask.setTaskid(serviceTask1.getTaskid()); + serviceTask.setSendState(2); + iServiceTaskService.updateServiceTask(serviceTask); } else if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("1") || StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("3")) { //鏃堕棿娈靛彂閫� ObjectMapper objectMapper = new ObjectMapper(); - if (StringUtils.isNotEmpty(svyTask.getSendTimeSlot())) { + if (StringUtils.isNotEmpty(serviceTask1.getSendTimeSlot())) { List<TaskSendTimeVO> taskSendTimeVOList = null; try { - taskSendTimeVOList = objectMapper.readValue(svyTask.getSendTimeSlot(), new TypeReference<List<TaskSendTimeVO>>() { + taskSendTimeVOList = objectMapper.readValue(serviceTask1.getSendTimeSlot(), new TypeReference<List<TaskSendTimeVO>>() { }); } catch (JsonProcessingException e) { log.error("JsonProcessingException鎶ラ敊浜嗭細{}", e.getMessage()); @@ -189,14 +189,14 @@ SendTaskVO sendTaskVO1 = DtoConversionUtils.sourceToTarget(sendTaskVO, SendTaskVO.class); sendTaskVO1.setSendType("1"); - String content = sendMQContent(sendTaskVO1, svyTask.getTemplateid(), svyTask.getPreachform(), svyTask.getStopState(), list); + String content = sendMQContent(sendTaskVO1, serviceTask1.getTemplateid().toString(), serviceTask1.getPreachform(), serviceTask1.getStopState(), list); redisCache.setCacheObject(content, content, milliseconds / 1000, TimeUnit.SECONDS); } //灏嗕换鍔$姸鎬佷慨鏀规垚鎵ц涓� - SvyTask serviceTask = new SvyTask(); - serviceTask.setTaskid(svyTask.getTaskid()); - serviceTask.setSendState("2"); - iSvyTaskService.updateSvyTask(serviceTask); + ServiceTask serviceTask = new ServiceTask(); + serviceTask.setTaskid(serviceTask1.getTaskid()); + serviceTask.setSendState(2); + iServiceTaskService.updateServiceTask(serviceTask); } } return 1; -- Gitblit v1.9.3