本地暂存逻辑

master
土豆兄弟 4 years ago
parent 7ada37c1eb
commit 4a15b262b0

@ -0,0 +1,92 @@
package me.zhengjie.common;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.io.Serializable;
//属性为 空("" 或者为 NULL 都不序列化则返回的json是没有这个字段的。这样对移动端会更省流量
@JsonSerialize
@Getter // 设置get方法
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor
public class CommonResponse<T> implements Serializable {
// 成功还是失败的状态标识 0,成功 1,失败
private int status;
// 返回信息
private String msg;
// 返回的结果数据
private T data;
/*
*/
private CommonResponse(int status) {
this.status = status;
}
private CommonResponse(int status, T data) { // ps: 当调用T为String类型时候,会默认调用下面的ServerResponse(int status, String msg)类型的构造器
this.status = status;
this.data = data;
}
private CommonResponse(int status, String msg, T data) {
this.status = status;
this.msg = msg;
this.data = data;
}
private CommonResponse(int status, String msg) {
this.status = status;
this.msg = msg;
}
/*
,,
*/
//返回成功码和默认的成功信息
public static <T> CommonResponse<T> createBySuccess() {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc());
}
//返回成功码和成功信息
public static <T> CommonResponse<T> createBySuccessMessage(String msg) {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), msg);
}
//返回成功码和数据
public static <T> CommonResponse<T> createBySuccess(T data) {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), data);
}
//返回成功码和成功信息和数据
public static <T> CommonResponse<T> createBySuccess(String msg, T data) {
return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), msg, data);
}
/*
,,
*/
//返回错误码和错误描述
public static <T> CommonResponse<T> createByError(ResponseCode responseCode){
return new CommonResponse<T>(responseCode.getCode(),responseCode.getDesc());
}
//返回错误码和错误信息(传入)
public static <T> CommonResponse<T> createByErrorMessage(String errorMessage){
return new CommonResponse<T>(ResponseCode.ERROR.getCode(),errorMessage);
}
//返回错误码(传入)和错误信息(传入)
public static <T> CommonResponse<T> createByErrorCodeMessage(int errorCode,String errorMessage){
return new CommonResponse<T>(errorCode,errorMessage);
}
}

@ -0,0 +1,41 @@
package me.zhengjie.common;
/**
* FileName: ResponseCode
* Author: x
* Date: 2019/12/11 20:30
* Description: Response ->
* History:
* <author> <time> <version> <desc>
* x 2019/12/11 v 1.0
*/
public enum ResponseCode {
SUCCESS(0,"SUCCESS"),
ERROR(1,"ERROR"),
// 请求参数校验
ILLEGAL_ARGUMENT(1,"请求参数格式错误"),
EMPTY_ARGUMENT(1,"请求参数为空"),
// 请求结果性的错误
NODATA_ERROR(1,"查询结果为空"),
TASK_BUILD_ERROR(1,"任务建立失败"),
DECRYPT_ERROR(1,"解密错误,请联系我");
private final int code;
private final String desc;
ResponseCode(int code, String desc){
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}

@ -16,19 +16,24 @@
package me.zhengjie.modules.abmessage.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.common.CommonResponse;
import me.zhengjie.common.ResponseCode;
import me.zhengjie.modules.abmessage.domain.AbMessage;
import me.zhengjie.modules.abmessage.rest.vo.AbMessageVO;
import me.zhengjie.modules.abmessage.service.AbMessageService;
import me.zhengjie.modules.abmessage.service.dto.AbMessageDto;
import me.zhengjie.modules.abmessage.service.dto.AbMessageQueryCriteria;
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.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
/**
@ -87,28 +92,17 @@ public class AbMessageController {
}
// ========== 自定义功能 start ==========
@Log("建立ABMessage发送任务")
@ApiOperation("建立ABMessage发送任务")
@Log("ABMessage建立发送任务")
@ApiOperation("ABMessage建立发送任务")
@PreAuthorize("@el.check('abMessage:list')")
@PostMapping
public ResponseEntity<Object> buildTask(@Validated @RequestBody AbMessageVO abMessageVO){
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("ABMessage发送任务")
@ApiOperation("ABMessage发送任务")
@PreAuthorize("@el.check('abMessage:list')")
@PostMapping
public ResponseEntity<Object> sendTask(@Validated @RequestBody AbMessageVO abMessageVO){
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("ABMessage发送任务")
@ApiOperation("ABMessage发送任务")
@PreAuthorize("@el.check('abMessage:list')")
@PostMapping
public ResponseEntity<Object> query(@Validated @RequestBody AbMessageVO abMessageVO){
return new ResponseEntity<>(HttpStatus.OK);
@PostMapping(value = "/buildTask")
public ResponseEntity<Object> buildTask(AbMessageQueryCriteria criteria){
List<AbMessageDto> abMessageDtos = abMessageService.queryAll(criteria);
if (CollectionUtils.isEmpty(abMessageDtos)){
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NODATA_ERROR), HttpStatus.OK);
}
return abMessageService.buildSendTask(abMessageDtos)? new ResponseEntity<>(CommonResponse.createBySuccess(), HttpStatus.OK)
: new ResponseEntity<>(CommonResponse.createByError(ResponseCode.TASK_BUILD_ERROR), HttpStatus.OK);
}
// ========== 自定义功能 end ==========
}

@ -1,11 +1,37 @@
package me.zhengjie.modules.abmessage.rest.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.util.List;
@Data
@Deprecated // 暂时弃用
public class AbMessageVO implements Serializable {
/**
* UID
*/
@Column(name = "uid")
@ApiModelProperty(value = "UID")
private String uid;
/**
* - ,
*/
@Column(name = "act_name")
@ApiModelProperty(value = "报课年级")
private List<Integer> actNames;
/**
* - ,
*/
@Column(name = "act_name")
@ApiModelProperty(value = "所在城市")
private List<Integer> cities;
private Integer device;
}

@ -80,4 +80,12 @@ public interface AbMessageService {
* @throws IOException /
*/
void download(List<AbMessageDto> all, HttpServletResponse response) throws IOException;
/**
*
*
* @param abMessageDtos
* @return
*/
boolean buildSendTask(List<AbMessageDto> abMessageDtos);
}

@ -31,13 +31,12 @@ public class AbMessageQueryCriteria{
/** 精确 */
@Query
private String uid;
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
private String actName;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;
private List<Timestamp> startTime;
/** BETWEEN */
@Query(type = Query.Type.IN)
private List<Integer> clientType;

@ -109,4 +109,12 @@ public class AbMessageServiceImpl implements AbMessageService {
}
FileUtil.downloadExcel(list, response);
}
@Override
public boolean buildSendTask(List<AbMessageDto> abMessageDtos) {
// 记录待发送的相关信息
return false;
}
}

@ -0,0 +1,51 @@
package me.zhengjie.modules.form.rest.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
@Data
public class FormMessageVO implements Serializable {
/**
* UID
*/
@ApiModelProperty(value = "UID")
private String uid;
/**
*
*/
@ApiModelProperty(value = "业务名称")
private String actName;
/**
* - ,
*/
@ApiModelProperty(value = "报课年级")
private List<Integer> stuGrades;
/**
* - ,
*/
@ApiModelProperty(value = "所在城市")
private List<Integer> cities;
/**
* - ,1-,0-
*/
@ApiModelProperty(value = "听课设备有无")
private Integer device;
/**
* -
*/
@ApiModelProperty(value = "业务开始时间")
private Timestamp startTime;
}

@ -0,0 +1,36 @@
package me.zhengjie.task;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
/**
*
*/
@Component
@Slf4j
public class ProduceLocalFileTask {
/**
* ,
*
* @return
*/
@Async(value = "ProduceLocalFileTaskExecutor")
public void doRunTask(List<T> list){
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start running, task name is {} ] ======", "ProduceLocalFileTask");
runTask(list);
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "ProduceLocalFileTask", (endMilliSecond - satrtMilliSecond));
}
private void runTask(List<T> list) {
}
}

@ -0,0 +1,37 @@
package me.zhengjie.task;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
/**
*
*/
@Component
@Slf4j
public class SendRecordTask {
/**
* ,
*
* @return
*/
@Async(value = "SendRecordTaskExecutor")
public void doRunTask(List<T> list){
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start running, task name is {} ] ======", "SendRecordTask");
runTask(list);
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "SendRecordTask", (endMilliSecond - satrtMilliSecond));
}
private void runTask(List<T> list) {
}
}
Loading…
Cancel
Save