设置三级表单 定时任务提交
parent
a9cc324795
commit
f3c554b3c6
@ -0,0 +1,160 @@
|
||||
package me.zhengjie.to;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* 通用返回对象
|
||||
*/
|
||||
public class ResponseResult<T> {
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* 普通成功返回
|
||||
*
|
||||
* @param data 获取的数据
|
||||
*/
|
||||
public ResponseResult<T> success(Object data) {
|
||||
this.code = HttpStatus.OK.value();
|
||||
this.message = "操作成功";
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 操作成功返回
|
||||
*
|
||||
*/
|
||||
public static <T> ResponseResult<T> successfulOperation() {
|
||||
return new ResponseResult<T>().success("操作成功");
|
||||
}
|
||||
|
||||
|
||||
public ResponseResult<T> fail(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通失败提示信息
|
||||
*/
|
||||
public ResponseResult<T> failed() {
|
||||
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
this.message = "操作失败";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统错误提示
|
||||
*/
|
||||
public ResponseResult<T> error(String message) {
|
||||
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 参数验证失败使用
|
||||
*
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public ResponseResult<T> validateFailed(String message) {
|
||||
this.code = HttpStatus.NOT_FOUND.value();
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未登录时使用
|
||||
*
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public ResponseResult<T> unauthorized(String message) {
|
||||
this.code = HttpStatus.UNAUTHORIZED.value();
|
||||
this.message = "暂未登录或token已经过期";
|
||||
this.data = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未授权时使用
|
||||
*
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public ResponseResult<T> forbidden(String message) {
|
||||
this.code = HttpStatus.FORBIDDEN.value();
|
||||
this.message = message;
|
||||
this.data = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponseResult<T> forbidden() {
|
||||
this.code = HttpStatus.NOT_IMPLEMENTED.value();
|
||||
this.message = "请先登录";
|
||||
this.data = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未授权时使用
|
||||
*
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public ResponseResult<T> forbidden(int code,String message) {
|
||||
this.code = code;
|
||||
this.message = "没有相关权限";
|
||||
this.data = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 参数验证失败使用
|
||||
* @param result 错误信息
|
||||
*/
|
||||
public ResponseResult<T> validateFailed(BindingResult result) {
|
||||
validateFailed(result.getFieldError().getDefaultMessage());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package me.zhengjie.modules.buildrecord.rest.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2021/4/28
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChangeBuildRecordVo {
|
||||
|
||||
@NotNull(message = "修改id")
|
||||
private Integer id;
|
||||
|
||||
@NotNull(message = "下标位置不能为空")
|
||||
private Integer reSubscript;
|
||||
|
||||
@NotNull(message = "修改父类id不能为空")
|
||||
private Integer changeParentId;
|
||||
|
||||
@NotNull(message = "原始父类id")
|
||||
private Integer originalParentId;
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.buildtask.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description /
|
||||
* @author Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="tb_build_task")
|
||||
public class BuildTask implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "gmt_create")
|
||||
@ApiModelProperty(value = "gmtCreate")
|
||||
private Timestamp gmtCreate;
|
||||
|
||||
@Column(name = "gmt_modified")
|
||||
@ApiModelProperty(value = "gmtModified")
|
||||
private Timestamp gmtModified;
|
||||
|
||||
@Column(name = "build_id")
|
||||
@ApiModelProperty(value = "发送id")
|
||||
private Integer buildId;
|
||||
|
||||
@Column(name = "send_time")
|
||||
@ApiModelProperty(value = "发送时间")
|
||||
private Timestamp sendTime;
|
||||
|
||||
@Column(name = "is_send")
|
||||
@ApiModelProperty(value = "发送状态 1成功 0失败")
|
||||
private Integer isSend;
|
||||
|
||||
public void copy(BuildTask source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.buildtask.repository;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import me.zhengjie.modules.buildtask.domain.BuildTask;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @website https://el-admin.vip
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
public interface BuildTaskRepository extends JpaRepository<BuildTask, Integer>, JpaSpecificationExecutor<BuildTask> {
|
||||
|
||||
/**
|
||||
* 日期发送id查询
|
||||
* @param recordId
|
||||
* @param now
|
||||
* @return
|
||||
*/
|
||||
@Query(value =
|
||||
"select t.* from tb_build_task t where t.build_id = ?1 and TO_DAYS(t.gmt_create)=TO_DAYS(?2)",
|
||||
nativeQuery = true)
|
||||
BuildTask findBuildByRecordIdAndDate(Integer recordId, LocalTime now);
|
||||
|
||||
|
||||
/**
|
||||
* 修改发送状态
|
||||
* @param buildTaskId
|
||||
* @return
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "update BuildTask set isSend = 1 where id = ?1")
|
||||
int updateSendStatusById(Integer buildTaskId);
|
||||
|
||||
/**
|
||||
* 查询前一日未发送数据
|
||||
* @param offsetDay
|
||||
* @return
|
||||
*/
|
||||
@Query(value =
|
||||
"select t.* from tb_build_task t where is_send = 0 and TO_DAYS(t.gmt_create)=TO_DAYS(?1) ",
|
||||
nativeQuery = true)
|
||||
List<BuildTask> findBuildTaskByTime(String offsetDay);
|
||||
|
||||
|
||||
/**
|
||||
* 时间段查询发送任务
|
||||
* @param beginOfDay
|
||||
* @param endOfDay
|
||||
* @return
|
||||
*/
|
||||
@Query("select t from BuildTask t where t.isSend = 0 and t.gmtCreate between ?1 and ?2")
|
||||
List<BuildTask> findBuildTaskByTime(DateTime beginOfDay, DateTime endOfDay);
|
||||
}
|
@ -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.buildtask.rest;
|
||||
|
||||
import me.zhengjie.annotation.Log;
|
||||
import me.zhengjie.modules.buildtask.domain.BuildTask;
|
||||
import me.zhengjie.modules.buildtask.service.BuildTaskService;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskQueryCriteria;
|
||||
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 Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "buildTask管理")
|
||||
@RequestMapping("/api/buildTask")
|
||||
public class BuildTaskController {
|
||||
|
||||
private final BuildTaskService buildTaskService;
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('buildTask:list')")
|
||||
public void download(HttpServletResponse response, BuildTaskQueryCriteria criteria) throws IOException {
|
||||
buildTaskService.download(buildTaskService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询buildTask")
|
||||
@ApiOperation("查询buildTask")
|
||||
@PreAuthorize("@el.check('buildTask:list')")
|
||||
public ResponseEntity<Object> query(BuildTaskQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(buildTaskService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增buildTask")
|
||||
@ApiOperation("新增buildTask")
|
||||
@PreAuthorize("@el.check('buildTask:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody BuildTask resources){
|
||||
return new ResponseEntity<>(buildTaskService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改buildTask")
|
||||
@ApiOperation("修改buildTask")
|
||||
@PreAuthorize("@el.check('buildTask:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody BuildTask resources){
|
||||
buildTaskService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除buildTask")
|
||||
@ApiOperation("删除buildTask")
|
||||
@PreAuthorize("@el.check('buildTask:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody Integer[] ids) {
|
||||
buildTaskService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.buildtask.service;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import me.zhengjie.modules.buildtask.domain.BuildTask;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskDto;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description 服务接口
|
||||
* @author Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
public interface BuildTaskService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(BuildTaskQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<BuildTaskDto>
|
||||
*/
|
||||
List<BuildTaskDto> queryAll(BuildTaskQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id ID
|
||||
* @return BuildTaskDto
|
||||
*/
|
||||
BuildTaskDto findById(Integer id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
* @return BuildTaskDto
|
||||
*/
|
||||
BuildTaskDto create(BuildTask resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(BuildTask resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Integer[] ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<BuildTaskDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 检测是否有记录
|
||||
* @param recordId
|
||||
* @param now
|
||||
* @return
|
||||
*/
|
||||
BuildTask queryBuildTaskByBuildIdAndTime(Integer recordId, LocalTime now);
|
||||
|
||||
/**
|
||||
* 修改发送状态
|
||||
* @param buildTaskId
|
||||
* @return
|
||||
*/
|
||||
boolean updateSendBuildTaskById(Integer buildTaskId);
|
||||
|
||||
/**
|
||||
* 时间查询发送任务
|
||||
* @param offsetDay
|
||||
* @return
|
||||
*/
|
||||
List<BuildTask> getBuildTaskByTime(String offsetDay);
|
||||
|
||||
/**
|
||||
* 时间段查询发送任务
|
||||
* @param beginOfDay
|
||||
* @param endOfDay
|
||||
* @return
|
||||
*/
|
||||
List<BuildTask> getBuildTaskByTime(DateTime beginOfDay, DateTime endOfDay);
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.buildtask.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.sql.Timestamp;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description /
|
||||
* @author Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
@Data
|
||||
public class BuildTaskDto implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Timestamp gmtCreate;
|
||||
|
||||
private Timestamp gmtModified;
|
||||
|
||||
/** 发送id */
|
||||
private Long buildId;
|
||||
|
||||
/** 发送时间 */
|
||||
private Timestamp sendTime;
|
||||
|
||||
/** 发送状态 1成功 0失败 */
|
||||
private Integer isSend;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.buildtask.service.dto;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
@Data
|
||||
public class BuildTaskQueryCriteria{
|
||||
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<DateTime> createTime;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.buildtask.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import me.zhengjie.modules.buildtask.domain.BuildTask;
|
||||
import me.zhengjie.modules.common.consts.DefaultConstant;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.modules.buildtask.repository.BuildTaskRepository;
|
||||
import me.zhengjie.modules.buildtask.service.BuildTaskService;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskDto;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskQueryCriteria;
|
||||
import me.zhengjie.modules.buildtask.service.mapstruct.BuildTaskMapper;
|
||||
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.time.LocalTime;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description 服务实现
|
||||
* @author Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BuildTaskServiceImpl implements BuildTaskService {
|
||||
|
||||
private final BuildTaskRepository buildTaskRepository;
|
||||
private final BuildTaskMapper buildTaskMapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(BuildTaskQueryCriteria criteria, Pageable pageable){
|
||||
Page<BuildTask> page = buildTaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(buildTaskMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BuildTaskDto> queryAll(BuildTaskQueryCriteria criteria){
|
||||
return buildTaskMapper.toDto(buildTaskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public BuildTaskDto findById(Integer id) {
|
||||
BuildTask buildTask = buildTaskRepository.findById(id).orElseGet(BuildTask::new);
|
||||
ValidationUtil.isNull(buildTask.getId(),"BuildTask","id",id);
|
||||
return buildTaskMapper.toDto(buildTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public BuildTaskDto create(BuildTask resources) {
|
||||
return buildTaskMapper.toDto(buildTaskRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(BuildTask resources) {
|
||||
BuildTask buildTask = buildTaskRepository.findById(resources.getId()).orElseGet(BuildTask::new);
|
||||
ValidationUtil.isNull( buildTask.getId(),"BuildTask","id",resources.getId());
|
||||
buildTask.copy(resources);
|
||||
buildTaskRepository.save(buildTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
buildTaskRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<BuildTaskDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (BuildTaskDto buildTask : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put(" gmtCreate", buildTask.getGmtCreate());
|
||||
map.put(" gmtModified", buildTask.getGmtModified());
|
||||
map.put("发送id", buildTask.getBuildId());
|
||||
map.put("发送时间", buildTask.getSendTime());
|
||||
map.put("发送状态 1成功 0失败", buildTask.getIsSend());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildTask queryBuildTaskByBuildIdAndTime(Integer recordId, LocalTime now) {
|
||||
|
||||
return buildTaskRepository.findBuildByRecordIdAndDate(recordId, now);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSendBuildTaskById(Integer buildTaskId) {
|
||||
return buildTaskRepository.updateSendStatusById(buildTaskId) > DefaultConstant.ZERO_NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BuildTask> getBuildTaskByTime(String offsetDay) {
|
||||
return buildTaskRepository.findBuildTaskByTime(offsetDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BuildTask> getBuildTaskByTime(DateTime beginOfDay, DateTime endOfDay) {
|
||||
return buildTaskRepository.findBuildTaskByTime(beginOfDay,endOfDay);
|
||||
}
|
||||
|
||||
}
|
@ -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.buildtask.service.mapstruct;
|
||||
|
||||
import me.zhengjie.base.BaseMapper;
|
||||
import me.zhengjie.modules.buildtask.domain.BuildTask;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author Enzo
|
||||
* @date 2021-04-30
|
||||
**/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface BuildTaskMapper extends BaseMapper<BuildTaskDto, BuildTask> {
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package me.zhengjie.modules.common.consts;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Minus;
|
||||
|
||||
/**
|
||||
* @author E
|
||||
* @date
|
||||
*/
|
||||
public class DefaultConstant {
|
||||
|
||||
|
||||
/**
|
||||
* -1
|
||||
*/
|
||||
public static final int MINUS_ONE_NUMBER = -1;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 0
|
||||
*/
|
||||
public static final int ZERO_NUMBER = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 1
|
||||
*/
|
||||
public static final int ONE_NUMBER = 1;
|
||||
|
||||
/**
|
||||
* 2
|
||||
*/
|
||||
public static final int TWO_NUMBER = 2;
|
||||
|
||||
/**
|
||||
* 3
|
||||
*/
|
||||
public static final int THREE_NUMBER = 3;
|
||||
|
||||
|
||||
/**
|
||||
* 5
|
||||
*/
|
||||
public static final int FIVE_NUMBER = 5;
|
||||
|
||||
/**
|
||||
* 10
|
||||
*/
|
||||
public static final int TEN_NUMBER = 10;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package me.zhengjie.modules.common.handler;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.distance.DistanceUtils;
|
||||
import com.spatial4j.core.shape.Rectangle;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.convert.BuildTaskQueryParamJsonConvert;
|
||||
import me.zhengjie.modules.buildtask.domain.BuildTask;
|
||||
import me.zhengjie.modules.buildtask.service.BuildTaskService;
|
||||
import me.zhengjie.modules.buildtask.service.dto.BuildTaskDto;
|
||||
import me.zhengjie.modules.common.consts.DefaultConstant;
|
||||
import me.zhengjie.modules.tag.service.TagService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2021/4/29
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BuildRecordScheduled {
|
||||
|
||||
@Resource
|
||||
private TagService tagService;
|
||||
|
||||
@Resource
|
||||
private BuildTaskService buildTaskService;
|
||||
|
||||
@Resource
|
||||
private BuildRecordService buildRecordService;
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 22 * * ?")
|
||||
//@Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void runBuildRecordTask() {
|
||||
log.info("scheduled runBuildRecordTask start time [{}]", LocalTime.now());
|
||||
// 获取所有开启定时任务开关
|
||||
List<BuildRecord> buildRecords = buildRecordService.getBuildRecordByIsTimedTask(Boolean.TRUE);
|
||||
if (!CollectionUtils.isEmpty(buildRecords)) {
|
||||
for (BuildRecord record : buildRecords) {
|
||||
/* 发送时间为空 状态不等于0设置发送状态
|
||||
BuildTask buildTask = buildTaskService.queryBuildTaskByBuildIdAndTime(record.getId(), LocalTime.now());
|
||||
if (buildTask == null) {*/
|
||||
BuildTask buildTask = new BuildTask();
|
||||
buildTask.setBuildId(record.getId());
|
||||
buildTask.setIsSend(DefaultConstant.ZERO_NUMBER);
|
||||
buildTask.setGmtCreate(new Timestamp(System.currentTimeMillis()));
|
||||
BuildTaskDto buildTaskDto = buildTaskService.create(buildTask);
|
||||
if (buildTaskDto != null) {
|
||||
deleteBuildTaskAndSendBuildTask(record, buildTaskDto.getId());
|
||||
}
|
||||
log.info(" ========================== insert buildTask id as [{}] ===========================", buildTaskDto != null ? buildTaskDto.getId() : null);
|
||||
/*}*/
|
||||
}
|
||||
log.info("scheduled runBuildRecordTask end time [{}] task size as [{}]", LocalTime.now(), buildRecords.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Async(value = "buildTaskExecutor")
|
||||
void deleteBuildTaskAndSendBuildTask(BuildRecord record, Integer buildTaskId) {
|
||||
// 解析数据
|
||||
BuildTaskQueryParamJsonConvert convert = getBuildTaskQueryParamJsonConvert(record.getParams());
|
||||
Rectangle rectangle = null;
|
||||
// 地图点进行计算,获取选点范围
|
||||
Integer range = convert.getRange();
|
||||
String localCode = convert.getLocalCode();
|
||||
if (StringUtils.isNotBlank(localCode) && range != null) {
|
||||
rectangle = calculateLocalPoint(localCode, range);
|
||||
}
|
||||
if (rectangle == null && StringUtils.isBlank(localCode)) {
|
||||
log.error(" ====================== {please check localPoint calculate is ok ! } ==========================");
|
||||
return;
|
||||
}
|
||||
// 删除并新增任务
|
||||
boolean deleteTagByParam = tagService.deleteAndInsertTagByParam
|
||||
(record.getId(), buildTaskId,
|
||||
convert.getCityCode(),
|
||||
convert.getStuGrade(),
|
||||
rectangle);
|
||||
log.info("buildRecordTask taskName as [{}] result as [{}] result time as [{}]", record.getTaskName(), deleteTagByParam, LocalTime.now());
|
||||
}
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 4 * * ?")
|
||||
// @Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void resendBuildRecordTask() {
|
||||
log.info("scheduled resendBuildRecordTask start time [{}]", LocalTime.now());
|
||||
// 偏移天数
|
||||
DateTime dateTime = DateUtil.offsetDay(DateUtil.date(),
|
||||
DefaultConstant.MINUS_ONE_NUMBER);
|
||||
// 当天开始时间
|
||||
DateTime beginOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 当天结束时间
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
// 查询前一天定时任务
|
||||
List<BuildTask> buildRecords = buildTaskService.getBuildTaskByTime(beginOfDay, endOfDay);
|
||||
if (!CollectionUtils.isEmpty(buildRecords)) {
|
||||
for (BuildTask task : buildRecords) {
|
||||
if (task.getBuildId() != null) {
|
||||
BuildRecordDto buildRecordDto = buildRecordService.findById(task.getBuildId());
|
||||
if (buildRecordDto != null) {
|
||||
resendDeleteBuildTaskAndSendBuildTask(buildRecordDto, task.getId());
|
||||
}
|
||||
log.info(" ========================== insert resendBuildRecordTask id as [{}] ===========================", buildRecordDto != null ? buildRecordDto.getId() : null);
|
||||
}
|
||||
}
|
||||
log.info("scheduled runBuildRecordTask end time [{}] task size as [{}]", LocalTime.now(), buildRecords.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Rectangle calculateLocalPoint(String localCode, Integer range) {
|
||||
// 处理切割横纵坐标字符串
|
||||
String[] split = StringUtils.split(localCode.trim(), StrUtil.COMMA);
|
||||
if (split.length != DefaultConstant.TWO_NUMBER) {
|
||||
return null;
|
||||
}
|
||||
// 转换类型
|
||||
double x = Double.parseDouble(split[0]);
|
||||
double y = Double.parseDouble(split[1]);
|
||||
// 坐标计算
|
||||
SpatialContext geo = SpatialContext.GEO;
|
||||
return geo.getDistCalc().
|
||||
calcBoxByDistFromPt
|
||||
(geo.makePoint(x, y),
|
||||
range * DistanceUtils.KM_TO_DEG,
|
||||
geo, null);
|
||||
}
|
||||
|
||||
|
||||
@Async(value = "resendBuildTaskExecutor")
|
||||
void resendDeleteBuildTaskAndSendBuildTask(BuildRecordDto record, Integer buildTaskId) {
|
||||
BuildTaskQueryParamJsonConvert convert = getBuildTaskQueryParamJsonConvert(record.getParams());
|
||||
Rectangle rectangle = null;
|
||||
// 地图点进行计算,获取选点范围
|
||||
Integer range = convert.getRange();
|
||||
String localCode = convert.getLocalCode();
|
||||
if (StringUtils.isNotBlank(localCode) && range != null) {
|
||||
rectangle = calculateLocalPoint(localCode, range);
|
||||
}
|
||||
if (rectangle == null && StringUtils.isNotBlank(localCode)) {
|
||||
log.error(" ====================== {please check localPoint calculate is ok ! } ==========================");
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除并新增任务
|
||||
boolean deleteTagByParam = tagService.deleteAndInsertTagByParam
|
||||
(record.getId(), buildTaskId,
|
||||
convert.getCityCode(),
|
||||
convert.getStuGrade(), rectangle);
|
||||
log.info("buildRecordTask taskName as [{}] result as [{}] result time as [{}]", record.getTaskName(), deleteTagByParam, LocalTime.now());
|
||||
}
|
||||
|
||||
private BuildTaskQueryParamJsonConvert getBuildTaskQueryParamJsonConvert(String params) {
|
||||
// 解析数据
|
||||
JSONObject jsonObject1 =
|
||||
JSONUtil.parseObj(params, true);
|
||||
// 构建解析类对Json进行解析
|
||||
return JSONUtil.toBean(jsonObject1, BuildTaskQueryParamJsonConvert.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,19 +1,104 @@
|
||||
package me.zhengjie;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import me.zhengjie.modules.buildrecord.domain.BuildRecord;
|
||||
import me.zhengjie.modules.buildrecord.repository.BuildRecordRepository;
|
||||
import me.zhengjie.modules.buildrecord.rest.vo.BuildRecordBuildVO;
|
||||
import me.zhengjie.modules.buildrecord.service.BuildRecordService;
|
||||
import me.zhengjie.modules.buildrecord.service.dto.BuildRecordDto;
|
||||
import me.zhengjie.modules.buildrecord.task.ProduceBigDataTask;
|
||||
import me.zhengjie.modules.edu.domain.Edu;
|
||||
import me.zhengjie.modules.edu.service.EduService;
|
||||
import me.zhengjie.modules.school.domain.School;
|
||||
import me.zhengjie.modules.school.service.SchoolService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Random;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class EladminSystemApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private SchoolService schoolService;
|
||||
|
||||
@Autowired
|
||||
private BuildRecordService buildRecordService;
|
||||
|
||||
@Autowired
|
||||
private ProduceBigDataTask produceBigDataTask;
|
||||
|
||||
|
||||
@Autowired
|
||||
private BuildRecordRepository buildRecordRepository;
|
||||
|
||||
@Autowired
|
||||
private EduService eduService;
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertBuildRecord(){
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
School school = new School();
|
||||
int oldId = RandomUtil.randomInt(4);
|
||||
school.setCityCode(RandomUtil.randomInt(4));
|
||||
school.setLng(randomLonLat(105,125,25,50,"Lon"));
|
||||
school.setLat(randomLonLat(105,125,25,50,""));
|
||||
school.setOldid(oldId);
|
||||
school.setType(1);
|
||||
schoolService.create(school);
|
||||
Edu edu = new Edu();
|
||||
edu.setLevel(i + 1);
|
||||
edu.setMid(oldId);
|
||||
edu.setUid(Base64.encode(RandomUtil.randomNumbers(11)));
|
||||
eduService.create(edu);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertTag(){
|
||||
BuildRecord buildRecord = new BuildRecord();
|
||||
buildRecord.setTaskName("商圈珠江中路" + StrUtil.UNDERLINE);
|
||||
buildRecord.setTimePeriod(100);
|
||||
buildRecord.setIsBuild(1);
|
||||
buildRecord.setDescription("11.4");
|
||||
buildRecord.setParams("{\"stuGrade\":[\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"],\"cityCode\":[3205],\"localCode\":\"110.979626,36.38156\",\"range\":\"3\"}");
|
||||
buildRecord.setTotal(2000L);
|
||||
buildRecord.setLevel(3);
|
||||
buildRecord.setParentId(99);
|
||||
buildRecord.setIsTimedTask(true);
|
||||
|
||||
// produceBigDataTask.runTask(buildRecord);
|
||||
}
|
||||
|
||||
|
||||
public static String randomLonLat(double MinLon, double MaxLon, double MinLat, double MaxLat, String type) {
|
||||
|
||||
BigDecimal db = new BigDecimal(Math.random() * (MaxLon - MinLon) + MinLon);
|
||||
String lon = db.setScale(6, BigDecimal.ROUND_HALF_UP).toString();// 小数后6位
|
||||
db = new BigDecimal(Math.random() * (MaxLat - MinLat) + MinLat);
|
||||
String lat = db.setScale(6, BigDecimal.ROUND_HALF_UP).toString();
|
||||
if (type.equals("Lon")) {
|
||||
return lon;
|
||||
} else {
|
||||
return lat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue