韦忠喜提交

master
weizhongxi 3 years ago
parent a6f8f02314
commit dc44d17446

@ -19,6 +19,7 @@ public enum ResponseCode {
// 通用请求参数校验
ILLEGAL_ARGUMENT(1,"请求参数格式错误"),
EMPTY_ARGUMENT(1,"请求参数为空"),
NO_SMS_BAD(1,"短信内容有问题"),
NO_MATCH_ARGUMENT_SET(1,"不能满足要求的参数设置"),
NO_FILE_INPUT(1,"没有文件输入"),
// 特殊需要进行前端返回说明的参数定义

@ -100,6 +100,8 @@ public class BuildRecord implements Serializable {
@ApiModelProperty(value = "活动任务ID")
private Long taskBuildId;
public void copy(BuildRecord source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}

@ -40,6 +40,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@ -57,6 +59,12 @@ public class BuildRecordController {
private final BuildRecordService buildRecordService;
private final String word1 = "日";
private final String word2 = "你妹";
private final String word3 = "操";
@Autowired
private ProduceBigDataTask produceBigDataTask;
@Autowired
@ -165,6 +173,13 @@ public class BuildRecordController {
){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
//判断内容是否含有不良词
if (!StringUtils.isBlank(buildRecordSendVO.getRemoteRecord().getSmsContent())){
if (buildRecordSendVO.getRemoteRecord().getSmsContent().contains(word1) || buildRecordSendVO.getRemoteRecord().getSmsContent().contains(word2)
||buildRecordSendVO.getRemoteRecord().getSmsContent().contains(word3)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_SMS_BAD), HttpStatus.OK);
}
}
SendBigDataDTO sendBigDataDTO = new SendBigDataDTO();
BeanUtil.copyProperties(buildRecordSendVO, sendBigDataDTO);
// 调用发送课包任务,开始发送
@ -218,4 +233,19 @@ public class BuildRecordController {
// ========================= 自定义的大数据平台相关的接口 start =========================
// @Log("上传并加密任务")
// @ApiOperation("上传并加密任务")
// @AnonymousAccess
// @PostMapping("/aa")
//// @ResponseBody
// public ResponseEntity<Object> aa(Long taskBuildId,String addressTag,String sendName,String onlyName,String smsContent){
// BuildRecord buildRecord = new BuildRecord();
// buildRecord.setId(94);
// buildRecord.setSmsContent("哈哈哈哈111");
// buildRecord.setLinkUrl("https://fanyi.youdao.com/");
// buildRecordService.update(buildRecord);
//// buildRecordService.updateSmsContent(smsContent,94);
// return new ResponseEntity<>(CommonResponse.createBySuccess(), HttpStatus.OK);
// }
}

@ -3,6 +3,7 @@ package me.zhengjie.modules.buildrecord.task;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
@ -13,9 +14,13 @@ import me.zhengjie.modules.buildrecord.domain.BuildRecord;
import me.zhengjie.modules.buildrecord.service.BuildRecordService;
import me.zhengjie.modules.buildrecord.service.dto.BuildRecordDto;
import me.zhengjie.modules.buildrecord.task.dto.SendBigDataDTO;
import me.zhengjie.modules.buildrecord.task.model.SendSmsContenJsonContent;
import me.zhengjie.modules.remoterec.domain.RemoteRecord;
import me.zhengjie.modules.remoterec.service.RemoteRecordService;
import me.zhengjie.modules.remoterec.service.dto.RemoteRecordDto;
import me.zhengjie.modules.smscontent.domain.TbSendSmsContent;
import me.zhengjie.modules.smscontent.service.TbSendSmsContentService;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentDto;
import me.zhengjie.modules.tag.domain.Tag;
import me.zhengjie.modules.tag.service.TagService;
import me.zhengjie.modules.tag.service.dto.TagDto;
@ -23,10 +28,7 @@ import me.zhengjie.modules.tag.service.dto.TagQueryCriteria;
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordDto;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordQueryCriteria;
import me.zhengjie.utils.ConvertUtil;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.HttpUtil;
import me.zhengjie.utils.StringUtils;
import me.zhengjie.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
@ -39,6 +41,7 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
@ -83,6 +86,12 @@ public class SendBigDataTask {
@Value(value = "${req.db.host}")
private String host;
/**
*
*/
@Value(value = "${inter.address}")
private String sendtAddress;
@Autowired
private BuildRecordService buildRecordService;
@ -93,6 +102,9 @@ public class SendBigDataTask {
@Autowired
private RemoteRecordService remoteRecordService;
@Autowired
private TbSendSmsContentService tbSendSmsContentService;
@Async(value = "SendBigDataTaskExecutor")
public void doRunTask(BuildRecord resource, RemoteRecord remoteRecord, SendBigDataDTO sendBigDataDTO){
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
@ -128,6 +140,9 @@ public class SendBigDataTask {
if (remoteRecord.getId() != null){
RemoteRecordDto remoteRecordDto = remoteRecordService.findById(remoteRecord.getId());
// //添加部分
// remoteRecordDto.setLocalSavePath(remoteRecordDto.getLocalSavePath()+"bak");
waitSendSuccessRemoteRec(remoteRecordDto);
// 远程文件存储形式的源
remoteCollect = getRemoteRecFromLocal(remoteRecordDto);
@ -137,7 +152,35 @@ public class SendBigDataTask {
AtomicLong atomicLong = batchSendRemote(remoteCollect, sendBigDataDTO, resource);
finishSendThenUpdateRemoteRec(remoteRecord, atomicLong);
}
//给文件上传系统发送短信内容
if (remoteRecord.getId() != null){
log.info("========== [SaveToFileTask|runTask ========== SmsContent"+remoteRecord.getSmsContent()+" LinkUrl:"+remoteRecord.getLinkUrl());
if (remoteRecord.getSmsContent() != null && remoteRecord.getLinkUrl() != null){
//将短信内容和url放入数据库中
remoteRecordService.update(remoteRecord);
RemoteRecordDto remoteRecordDto = remoteRecordService.findById(remoteRecord.getId());
TbSendSmsContent tbSendSmsContent = new TbSendSmsContent();
tbSendSmsContent.setSmsContent(remoteRecord.getSmsContent());
tbSendSmsContent.setSendStatus(0);
tbSendSmsContent.setTaskName(sendBigDataDTO.getSendName());
Date date = new Date();
Timestamp nousedate = new Timestamp(date.getTime());
tbSendSmsContent.setPushTime(nousedate);
tbSendSmsContent.setGmtCreate(nousedate);
tbSendSmsContent.setGmtModified(nousedate);
tbSendSmsContent.setLinkUrl(remoteRecord.getLinkUrl());
// String username = SecurityUtils.getCurrentUsername();
tbSendSmsContent.setOperation(remoteRecordDto.getOperation());
TbSendSmsContentDto tbSendSmsContentDto = tbSendSmsContentService.create(tbSendSmsContent);
tbSendSmsContentDto.setTaskName(sendBigDataDTO.getSendName());
if (tbSendSmsContentDto != null ){
sendSmsContent(remoteRecord,tbSendSmsContentDto);
}
}
}
// 乱序 乱序的逻辑写在SQL语句中
// Collections.shuffle(collect);
}
@ -415,5 +458,61 @@ public class SendBigDataTask {
// 返回拼接结果
return builder.toString();
}
//发给文件系统短信内容
private void sendSmsContent(RemoteRecord resource,TbSendSmsContentDto tbSendSmsContentDto){
// 组装成JSON
SendSmsContenJsonContent sendSmsContenJsonContent = new SendSmsContenJsonContent();
sendSmsContenJsonContent.setTaskName(tbSendSmsContentDto.getTaskName());
sendSmsContenJsonContent.setSmsContent(resource.getSmsContent());
sendSmsContenJsonContent.setLinkUrl(resource.getLinkUrl());
sendSmsContenJsonContent.setOperator(tbSendSmsContentDto.getOperation());
String readSendJsonStr = JSON.toJSONString(sendSmsContenJsonContent);
log.info("SendBigDataTask|sendSmsContent ready send json is : {}", readSendJsonStr);
int count = 0;
while (count < 3) {
// 调用HTTP请求发送数据
HttpResponse httpResponse = sendPostReq(readSendJsonStr);
log.info("========== [SaveToFileTask|sendSmsContent request success, response is {} ] ==========", httpResponse.body()+" " +httpResponse.isOk());
if (httpResponse.isOk() && httpResponse.body().contains("SUCCESS")) {
log.info("========== [SaveToFileTask|sendSmsContent request success, response is {} ] ==========", httpResponse.body());
break;
} else {
count++;
try {
// 重新发送前休眠3秒
Thread.sleep(3_0000);
} catch (InterruptedException e) {
log.error("SendBigDataTask|sendSmsContent sleep ERROR. message is", e.getMessage(), e);
}
log.error("========== [SendBigDataTask|sendSmsContent request fail, response is {} ] ==========", httpResponse.body());
}
}
TbSendSmsContent tbSendSmsContent = new TbSendSmsContent();
tbSendSmsContent.setId(tbSendSmsContentDto.getId());
if (count >= 3) {
log.error("========== [SendBigDataTask|sendSmsContent update send status fail, url is {} ] ==========" );
} else {
//发送成功!!
tbSendSmsContent.setSendStatus(1);
}
tbSendSmsContentService.update(tbSendSmsContent);
}
/**
* HTTPPost
*
* @param json body
* @return
*/
private HttpResponse sendPostReq(String json) {
HttpResponse httpResponse = HttpRequest
.post(sendtAddress)
.header("Content-Type", "application/json;charset=utf-8")
.body(json)
.execute();
return httpResponse;
}
}

@ -77,6 +77,14 @@ public class RemoteRecord implements Serializable {
@ApiModelProperty(value = "成功上传数量")
private Long successSendCount;
@Column(name = "sms_content")
@ApiModelProperty(value = "短信内容")
private String smsContent;
@Column(name = "link_url")
@ApiModelProperty(value = "短信链接")
private String linkUrl;
public void copy(RemoteRecord source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}

@ -95,6 +95,10 @@ public class DownloadSFTPFileTask {
if (StringUtils.isNotBlank(sftpFilePath)){
remoteFileToKLocal = sftpToDownloadFile(sftpFilePath, resources);
}
// //添加的部分
// remoteFileToKLocal = resources.getLocalSavePath()+"bak";
// log.info("remoteFileToKLocal============"+remoteFileToKLocal);
// 取回成功/失败,更新记录状态
RemoteRecord remoteRecord = new RemoteRecord();

@ -0,0 +1,79 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author weizhongxi
* @date 2021-04-16
**/
@Entity
@Data
@Table(name="tb_send_sms_content")
public class TbSendSmsContent implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@ApiModelProperty(value = "id")
private Long id;
@Column(name = "gmt_create")
@ApiModelProperty(value = "创建时间")
private Timestamp gmtCreate;
@Column(name = "gmt_modified")
@ApiModelProperty(value = "修改时间")
private Timestamp gmtModified;
@Column(name = "operation")
@ApiModelProperty(value = "操作人")
private String operation;
@Column(name = "task_name")
@ApiModelProperty(value = "任务名称")
private String taskName;
@Column(name = "sms_content")
@ApiModelProperty(value = "短信内容")
private String smsContent;
@Column(name = "send_status")
@ApiModelProperty(value = "推送状态")
private Integer sendStatus;
@Column(name = "push_time")
@ApiModelProperty(value = "推送时间")
private Timestamp pushTime;
@Column(name = "link_url")
@ApiModelProperty(value = "推送时间")
private String linkUrl;
public void copy(TbSendSmsContent source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

@ -0,0 +1,28 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.repository;
import me.zhengjie.modules.smscontent.domain.TbSendSmsContent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @website https://el-admin.vip
* @author weizhongxi
* @date 2021-04-16
**/
public interface TbSendSmsContentRepository extends JpaRepository<TbSendSmsContent, Long>, JpaSpecificationExecutor<TbSendSmsContent> {
}

@ -0,0 +1,87 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.smscontent.domain.TbSendSmsContent;
import me.zhengjie.modules.smscontent.service.TbSendSmsContentService;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://el-admin.vip
* @author weizhongxi
* @date 2021-04-16
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "发送短信内容管理")
@RequestMapping("/api/tbSendSmsContent")
public class TbSendSmsContentController {
private final TbSendSmsContentService tbSendSmsContentService;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('tbSendSmsContent:list')")
public void download(HttpServletResponse response, TbSendSmsContentQueryCriteria criteria) throws IOException {
tbSendSmsContentService.download(tbSendSmsContentService.queryAll(criteria), response);
}
@GetMapping
@Log("查询发送短信内容")
@ApiOperation("查询发送短信内容")
@PreAuthorize("@el.check('tbSendSmsContent:list')")
public ResponseEntity<Object> query(TbSendSmsContentQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(tbSendSmsContentService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增发送短信内容")
@ApiOperation("新增发送短信内容")
@PreAuthorize("@el.check('tbSendSmsContent:add')")
public ResponseEntity<Object> create(@Validated @RequestBody TbSendSmsContent resources){
return new ResponseEntity<>(tbSendSmsContentService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改发送短信内容")
@ApiOperation("修改发送短信内容")
@PreAuthorize("@el.check('tbSendSmsContent:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody TbSendSmsContent resources){
tbSendSmsContentService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除发送短信内容")
@ApiOperation("删除发送短信内容")
@PreAuthorize("@el.check('tbSendSmsContent:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
tbSendSmsContentService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

@ -0,0 +1,83 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.service;
import me.zhengjie.modules.smscontent.domain.TbSendSmsContent;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentDto;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://el-admin.vip
* @description
* @author weizhongxi
* @date 2021-04-16
**/
public interface TbSendSmsContentService {
/**
*
* @param criteria
* @param pageable
* @return Map<String,Object>
*/
Map<String,Object> queryAll(TbSendSmsContentQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<TbSendSmsContentDto>
*/
List<TbSendSmsContentDto> queryAll(TbSendSmsContentQueryCriteria criteria);
/**
* ID
* @param id ID
* @return TbSendSmsContentDto
*/
TbSendSmsContentDto findById(Long id);
/**
*
* @param resources /
* @return TbSendSmsContentDto
*/
TbSendSmsContentDto create(TbSendSmsContent resources);
/**
*
* @param resources /
*/
void update(TbSendSmsContent resources);
/**
*
* @param ids /
*/
void deleteAll(Long[] ids);
/**
*
* @param all
* @param response /
* @throws IOException /
*/
void download(List<TbSendSmsContentDto> all, HttpServletResponse response) throws IOException;
}

@ -0,0 +1,53 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author weizhongxi
* @date 2021-04-16
**/
@Data
public class TbSendSmsContentDto implements Serializable {
private Long id;
/** 创建时间 */
private Timestamp gmtCreate;
/** 修改时间 */
private Timestamp gmtModified;
/** 操作人 */
private String operation;
/** 任务名称 */
private String taskName;
/** 短信内容 */
private String smsContent;
/** 推送状态 */
private Integer sendStatus;
/** 推送时间 */
private Timestamp pushTime;
}

@ -0,0 +1,47 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.util.List;
import me.zhengjie.annotation.Query;
/**
* @website https://el-admin.vip
* @author weizhongxi
* @date 2021-04-16
**/
@Data
public class TbSendSmsContentQueryCriteria{
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
private String operation;
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
private String taskName;
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
private String smsContent;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;
}

@ -0,0 +1,110 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.service.impl;
import me.zhengjie.modules.smscontent.domain.TbSendSmsContent;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.smscontent.repository.TbSendSmsContentRepository;
import me.zhengjie.modules.smscontent.service.TbSendSmsContentService;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentDto;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentQueryCriteria;
import me.zhengjie.modules.smscontent.service.mapstruct.TbSendSmsContentMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/**
* @website https://el-admin.vip
* @description
* @author weizhongxi
* @date 2021-04-16
**/
@Service
@RequiredArgsConstructor
public class TbSendSmsContentServiceImpl implements TbSendSmsContentService {
private final TbSendSmsContentRepository tbSendSmsContentRepository;
private final TbSendSmsContentMapper tbSendSmsContentMapper;
@Override
public Map<String,Object> queryAll(TbSendSmsContentQueryCriteria criteria, Pageable pageable){
Page<TbSendSmsContent> page = tbSendSmsContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbSendSmsContentMapper::toDto));
}
@Override
public List<TbSendSmsContentDto> queryAll(TbSendSmsContentQueryCriteria criteria){
return tbSendSmsContentMapper.toDto(tbSendSmsContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
@Transactional
public TbSendSmsContentDto findById(Long id) {
TbSendSmsContent tbSendSmsContent = tbSendSmsContentRepository.findById(id).orElseGet(TbSendSmsContent::new);
ValidationUtil.isNull(tbSendSmsContent.getId(),"TbSendSmsContent","id",id);
return tbSendSmsContentMapper.toDto(tbSendSmsContent);
}
@Override
@Transactional(rollbackFor = Exception.class)
public TbSendSmsContentDto create(TbSendSmsContent resources) {
return tbSendSmsContentMapper.toDto(tbSendSmsContentRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbSendSmsContent resources) {
TbSendSmsContent tbSendSmsContent = tbSendSmsContentRepository.findById(resources.getId()).orElseGet(TbSendSmsContent::new);
ValidationUtil.isNull( tbSendSmsContent.getId(),"TbSendSmsContent","id",resources.getId());
tbSendSmsContent.copy(resources);
tbSendSmsContentRepository.save(tbSendSmsContent);
}
@Override
public void deleteAll(Long[] ids) {
for (Long id : ids) {
tbSendSmsContentRepository.deleteById(id);
}
}
@Override
public void download(List<TbSendSmsContentDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (TbSendSmsContentDto tbSendSmsContent : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("创建时间", tbSendSmsContent.getGmtCreate());
map.put("修改时间", tbSendSmsContent.getGmtModified());
map.put("操作人", tbSendSmsContent.getOperation());
map.put("任务名称", tbSendSmsContent.getTaskName());
map.put("短信内容", tbSendSmsContent.getSmsContent());
map.put("推送状态", tbSendSmsContent.getSendStatus());
map.put("推送时间", tbSendSmsContent.getPushTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

@ -0,0 +1,32 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.zhengjie.modules.smscontent.service.mapstruct;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.smscontent.domain.TbSendSmsContent;
import me.zhengjie.modules.smscontent.service.dto.TbSendSmsContentDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://el-admin.vip
* @author weizhongxi
* @date 2021-04-16
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TbSendSmsContentMapper extends BaseMapper<TbSendSmsContentDto, TbSendSmsContent> {
}

@ -62,3 +62,6 @@ rsa:
# sm.ms 图床的 token
smms:
token: 1oOP3ykFDI0K6ifmtvU7c8Y1eTWZSlyl
# 发送短信内容给文件上传接口一些参数
inter:
address: http://47.110.11.213:8000/api/tbTemplate/getSmsInfo

Loading…
Cancel
Save