| | |
| | | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.mzl.flower.config.OssProperties; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void saveSmsTask(SmsTaskDTO smsTaskDTO) { |
| | | public void saveSmsTask(SmsTaskDTO smsTaskDTO) throws IOException { |
| | | //校验 |
| | | if (StringUtils.isEmpty(smsTaskDTO.getName())) { |
| | | throw new ValidationException("短信名称不能为空"); |
| | |
| | | String userIdInfos = userIds.stream().map(Object::toString) // 确保每个元素都转换为字符串 |
| | | .collect(Collectors.joining(";")); // 使用换行符连接字符串 |
| | | smsTaskDO.setUserIds(userIdInfos); |
| | | smsTaskDTO.setNum((long) userIds.size()); |
| | | } |
| | | } |
| | | smsTaskDO.setStatus(Constants.SMS_TASK_STATUS.wait_publish.name()); |
| | |
| | | smsTaskMapper.insert(smsTaskDO); |
| | | } |
| | | |
| | | private void dealImportExcel(SmsTaskDTO smsTaskDTO) { |
| | | private void dealImportExcel(SmsTaskDTO smsTaskDTO) throws IOException { |
| | | String fileUrlMessage = ""; |
| | | // 创建ObjectMapper实例 |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | JsonNode rootNode = objectMapper.readTree(smsTaskDTO.getFileUrl()); |
| | | if (rootNode.isArray()) { |
| | | JsonNode firstElement = rootNode.get(0); |
| | | if (firstElement.has("url")) { |
| | | fileUrlMessage = firstElement.get("url").asText(); |
| | | } else { |
| | | throw new ValidationException("URL字段不存在"); |
| | | } |
| | | } else { |
| | | throw new ValidationException("JSON数组为空或不是数组"); |
| | | } |
| | | |
| | | String endPoint = ossProperties.getEndpoint(); |
| | | String accessKeyId = ossProperties.getKeyid(); |
| | | String accessKeySecret = ossProperties.getKeysecret(); |
| | |
| | | try { |
| | | // 下载Excel文件到本地临时文件 |
| | | File tempFile = File.createTempFile("temp", ".xlsx"); |
| | | String fileUrl = smsTaskDTO.getFileUrl(); |
| | | String fileUrl = fileUrlMessage; |
| | | String objectKey = fileUrl.replaceFirst("^https?://[^/]+/", ""); // 去掉协议部分 |
| | | ossClient.getObject(new GetObjectRequest(bucketName, objectKey), tempFile); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updateSmsTask(SmsTaskDTO smsTaskDTO) { |
| | | public void updateSmsTask(SmsTaskDTO smsTaskDTO) throws IOException { |
| | | SmsTaskDO smsTaskDO = smsTaskMapper.selectById(smsTaskDTO.getId()); |
| | | if (!smsTaskDO.getStatus().equals(Constants.SMS_TASK_STATUS.wait_publish.name())) { |
| | | throw new ValidationException("非待发布的任务不可编辑"); |
| | |
| | | String userIdInfos = userIds.stream().map(Object::toString) // 确保每个元素都转换为字符串 |
| | | .collect(Collectors.joining(";")); // 使用换行符连接字符串 |
| | | smsTaskDO.setUserIds(userIdInfos); |
| | | smsTaskDTO.setNum((long) userIds.size()); |
| | | } |
| | | } |
| | | BeanUtils.copyProperties(smsTaskDTO, smsTaskDO,"userIds"); |