更新了部分代码

master
土豆兄弟 4 years ago
parent 38b7eb8a37
commit 5d0685e83e

1
.gitignore vendored

@ -4,3 +4,4 @@
*/target/*
*/*.iml
.github/
/log/

@ -62,7 +62,7 @@ public class SendBigDataTask {
/**
* ,
*/
public static final String BASE_URL_CHAR_NUMBER = "123456";
public static final String BASE_URL_CHAR_NUMBER = "1234567";
/**
* url
@ -135,8 +135,11 @@ public class SendBigDataTask {
}
// 过滤的集合
Set<String> filterCollect = collect.stream().map(Tag::getUid).filter(fileLines::contains).collect(Collectors.toSet());
if (CollectionUtil.isNotEmpty(filterCollect)){
log.info("================== [Filter collect is ready, collect size is {} ] ================================",filterCollect.size());
collect = collect.stream().filter(one -> !filterCollect.contains(one.getUid())).collect(Collectors.toList());
}
}
// 乱序
// Collections.shuffle(collect);
// 对需要发送的字段进行发送
@ -148,10 +151,20 @@ public class SendBigDataTask {
Long sendTotal = atomicLong.get();
// 之前要进行校验
Long dbCount = buildRecordDto.getSendTotal();
// 这个数字会不准确和最开始的记录可能有冲突,这边加一个统计校验
Long sendCountFromDB = tagService.countSendSum(Long.valueOf(id), FINISH_SEND_TAG);
if (dbCount == null){
dbCount = 0L;
}
if (sendCountFromDB == null){
sendCountFromDB = 0L;
}
if (!Objects.equals((sendTotal + dbCount), sendCountFromDB)){
// 设置一个容错校验
buildRecordDto.setSendTotal(sendCountFromDB);
}else{
buildRecordDto.setSendTotal(sendTotal + dbCount);
}
BeanUtil.copyProperties(buildRecordDto, buildRecord);
buildRecordService.update(buildRecord);
}catch (Exception e){

@ -42,6 +42,29 @@ public class MailTaskController {
}
// 构建一次性链接
String result = mailTaskService.buildOnceLinkForInputFile(files);
return getOnceLinktResponseEntity(result);
}
/**
* ,
*
* @param filePath
* @return
*/
@Log("生成文件一次性链接")
@PostMapping("link/nofile")
@ApiOperation("生成一次性链接")
@AnonymousAccess // fixme 需要测试完成后进行去除和使用上面的权限注解
public ResponseEntity<Object> buildRequestNoFile(@RequestParam(value = "filePath") String filePath){
if (StringUtils.isBlank(filePath)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.EMPTY_ARGUMENT), HttpStatus.OK);
}
// 生成一次性链接, 返回生成的一次性链接地址
String result = mailTaskService.buildOnceLinkFromServer(filePath);
return getOnceLinktResponseEntity(result);
}
private ResponseEntity<Object> getOnceLinktResponseEntity(String result) {
OnceLinkMsgJsonContent content = new OnceLinkMsgJsonContent();
if (StringUtils.isNotBlank(result)) {
// 进行json相关的转换
@ -49,10 +72,10 @@ public class MailTaskController {
} else {
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_MATCH_ARGUMENT_SET), HttpStatus.OK);
}
return new ResponseEntity<>(CommonResponse.createBySuccess(content), HttpStatus.OK);
}
/**
* ,
*/

@ -23,4 +23,13 @@ public interface MailTaskService {
* @param rand
*/
void downloadFilesByRandCode(String rand, HttpServletResponse response, HttpServletRequest request);
/**
* ,
*
* @param filePath
* @return
*/
String buildOnceLinkFromServer(String filePath);
}

@ -30,6 +30,7 @@ import java.nio.charset.Charset;
import java.nio.file.FileSystem;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
@Service
@RequiredArgsConstructor
@ -178,4 +179,26 @@ public class MailTaskServiceImpl implements MailTaskService {
}
// return Boolean.FALSE;
}
@Override
public String buildOnceLinkFromServer(String filePath) {
// 任务记录
TempFileRecord tempFileRecord = new TempFileRecord();
// 保存当次任务生成的所有日志地址,然后保存在一次,用逗号分隔
tempFileRecord.setFilePaths(filePath);
// 默认保存7天
tempFileRecord.setDays(7);
// 生成验证码
String verificationCode = RandomUtil.randomString(11);
tempFileRecord.setVerificationCode(verificationCode);
// 文件标记 - 生成但是未读
tempFileRecord.setFileStatus(FINISH_BUILD_FILE_STATUS_CODE);
TempFileRecordDto tempFileRecordDto = tempFileRecordService.create(tempFileRecord);
if (tempFileRecordDto == null){
log.error(" ====== [make verificationCode fail. please check .tempFileRecord is {} ] ======", tempFileRecord.toString());
return "";
}
return remoteFileServerAddress + "?" + "rand=" + verificationCode;
}
}

@ -25,4 +25,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2020-09-22
**/
public interface TagRepository extends JpaRepository<Tag, Long>, JpaSpecificationExecutor<Tag> {
Long countByTaskIdAndPushStatus(Long taskId, Integer pushStatus);
}

@ -116,4 +116,13 @@ public interface TagService {
* @param rectangle
*/
Integer queryAndBatchInsertData(Integer taskId,List<Integer> cityCode, List<Integer> stuGrade, Rectangle rectangle);
/**
* /
*
* @param taskId
* @param pushStatus
* @return
*/
Long countSendSum(Long taskId, Integer pushStatus);
}

@ -210,4 +210,9 @@ public class TagServiceImpl implements TagService {
return nativeQuery.executeUpdate();
}
@Override
public Long countSendSum(Long taskId, Integer pushStatus) {
return tagRepository.countByTaskIdAndPushStatus(taskId, pushStatus);
}
}

@ -56,7 +56,7 @@ public class SendRecordTask {
/**
* ,
*/
public static final String BASE_URL_CHAR_NUMBER = "12345";
public static final String BASE_URL_CHAR_NUMBER = "1234567";
/**
* url

@ -5,7 +5,7 @@ spring:
freemarker:
check-template-location: false
profiles:
active: dev
active: test
jackson:
time-zone: GMT+8
data:

@ -77,7 +77,7 @@
<root level="INFO">
<!-- TODO prod 环境去掉std -->
<appender-ref ref="stdAppender"/>
<!--<appender-ref ref="fileAppender"/>-->
<!--<appender-ref ref="stdAppender"/>-->
<appender-ref ref="fileAppender"/>
</root>
</configuration>

@ -298,4 +298,14 @@ public class SpringJPATest {
Integer aLong = tagService.updateAllPushStatus(pushIds, taskId);
System.out.println(aLong);
}
/**
*
*/
@Test
public void testCount(){
Long taskId = 26L;
System.out.println(tagService.countSendSum(taskId, 1));
}
}

@ -12,10 +12,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -128,4 +125,14 @@ public class TempTest {
return "";
}
}
@Test
public void testLongComp(){
Long a = 2L;
Long b = 2L;
if (Objects.equals(a, b)){
System.out.println("yes");
}
}
}

Loading…
Cancel
Save